Skip to content

Commit

Permalink
fix dhcpv6 relay dual tor source interface selection issue (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaiMR authored Jul 17, 2023
1 parent c36b8e3 commit 6a6ce24
Show file tree
Hide file tree
Showing 7 changed files with 556 additions and 204 deletions.
10 changes: 8 additions & 2 deletions src/config_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,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
3 changes: 3 additions & 0 deletions src/config_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include "select.h"
#include "relay.h"

extern bool dual_tor_sock;

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 "config_interface.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 6a6ce24

Please sign in to comment.