Skip to content

Commit

Permalink
[202012] fix dual-tor relay-reply handing issue (sonic-net#40)
Browse files Browse the repository at this point in the history
* 202012 dhcpv6 relay dual tor issue fix
  • Loading branch information
jcaiMR authored Jul 11, 2023
1 parent a4b15d8 commit 3578eb3
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .azure-pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
sudo apt-get install -y dotnet-sdk-6.0
displayName: install .Net
- script: |
set -ex
sudo apt-get update
sudo apt-get install -y \
libboost-system1.71-dev \
libboost-thread1.71-dev \
Expand Down
12 changes: 10 additions & 2 deletions src/configInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ bool pollSwssNotifcation = true;
std::shared_ptr<boost::thread> mSwssThreadPtr;
swss::Select swssSelect;

extern bool dual_tor_sock;

/**
* @code void initialize_swss()
*
Expand Down Expand Up @@ -116,15 +118,21 @@ void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::un
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> &vlans)
{
std::vector<std::string> servers;
bool option_79_default = true;
bool interface_id_default = false;

if (dual_tor_sock) {
interface_id_default = true;
}

for (auto &entry: entries) {
std::string vlan = kfvKey(entry);
std::string operation = kfvOp(entry);
std::vector<swss::FieldValueTuple> fieldValues = kfvFieldsValues(entry);

relay_config intf;
intf.is_option_79 = true;
intf.is_interface_id = false;
intf.is_option_79 = option_79_default;
intf.is_interface_id = interface_id_default;
intf.interface = vlan;
intf.mux_key = "";
intf.state_db = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/configInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct swssNotification {
std::unordered_map<std::string, relay_config> vlans;
swss::SubscriberStateTable *ipHelpersTable;
};

/**
* @code void initialize_swss()
*
Expand Down
17 changes: 13 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@
#include "configInterface.h"

bool dual_tor_sock = false;
char loopback[IF_NAMESIZE] = "Loopback0";

static void usage()
{
printf("Usage: ./dhcp6relay {-d}\n");
printf("\t-d: enable dual tor option\n");
printf("Usage: ./dhcp6relay [-u <loopback interface>]\n");
printf("\tloopback interface: is the loopback interface for dual tor setup\n");
}

int main(int argc, char *argv[]) {
if (argc > 1) {
if (argc > 2) {
switch (argv[1][1])
{
case 'd':
case 'u':
if (strlen(argv[2]) != 0 && strlen(argv[2]) < IF_NAMESIZE) {
std::memset(loopback, 0, IF_NAMESIZE);
std::memcpy(loopback, argv[2], strlen(argv[2]));
} else {
syslog(LOG_ERR, "loopback interface name over length %d.\n", IF_NAMESIZE);
return 1;
}
dual_tor_sock = true;
break;
default:
fprintf(stderr, "%s: Unknown option\n", basename(argv[0]));
usage();
return 0;
}
}
try {
Expand Down
Loading

0 comments on commit 3578eb3

Please sign in to comment.