Skip to content

Add interface-id option #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/configInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries,

relay_config intf;
intf.is_option_79 = true;
intf.is_interface_id = false;
intf.interface = vlan;
intf.db = nullptr;
for (auto &fieldValue: fieldValues) {
Expand All @@ -135,6 +136,9 @@ void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries,
if(f == "dhcpv6_option|rfc6939_support" && v == "false") {
intf.is_option_79 = false;
}
if(f == "dhcpv6_option|interface_id" && v == "true") { // interface-id is off by default on non-Dual-ToR, unless specified in config db
intf.is_interface_id = true;
}
}
vlans->push_back(intf);
}
Expand Down
18 changes: 17 additions & 1 deletion src/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,30 @@ void relay_client(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *ip_h
option79.link_layer_type = htons(1);
option79.option_code = htons(OPTION_CLIENT_LINKLAYER_ADDR);
option79.option_length = htons(2 + 6); // link_layer_type field + address


if ((unsigned)(current_buffer_position + sizeof(linklayer_addr_option) - buffer) > sizeof(buffer)) {
return;
}
memcpy(current_buffer_position, &option79, sizeof(linklayer_addr_option));
current_buffer_position += sizeof(linklayer_addr_option);

memcpy(current_buffer_position, &ether_hdr->ether_shost, sizeof(ether_hdr->ether_shost));
current_buffer_position += sizeof(ether_hdr->ether_shost);
}

if(config->is_interface_id) {
interface_id_option intf_id;
intf_id.option_code = htons(OPTION_INTERFACE_ID);
intf_id.option_length = htons(sizeof(in6_addr));
intf_id.interface_id = config->link_address.sin6_addr;

if ((unsigned)(current_buffer_position + sizeof(linklayer_addr_option) - buffer) > sizeof(buffer)) {
return;
}
memcpy(current_buffer_position, &intf_id, sizeof(interface_id_option));
current_buffer_position += sizeof(interface_id_option);
}

auto dhcp_message_length = len;
relay_forward(current_buffer_position, parse_dhcpv6_hdr(msg), dhcp_message_length);
current_buffer_position += dhcp_message_length + sizeof(dhcpv6_option);
Expand Down
8 changes: 8 additions & 0 deletions src/relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define lengthof(A) (sizeof (A) / sizeof (A)[0])

#define OPTION_RELAY_MSG 9
#define OPTION_INTERFACE_ID 18
#define OPTION_CLIENT_LINKLAYER_ADDR 79

/* DHCPv6 message types */
Expand Down Expand Up @@ -55,6 +56,7 @@ struct relay_config {
std::vector<std::string> servers;
std::vector<sockaddr_in6> servers_sock;
bool is_option_79;
bool is_interface_id;
};


Expand Down Expand Up @@ -84,6 +86,12 @@ struct linklayer_addr_option {
uint16_t link_layer_type;
};

struct interface_id_option {
uint16_t option_code;
uint16_t option_length;
in6_addr interface_id; // to accomodate dual-tor, this opaque value is set to carry relay interface's global ipv6 address
};

/**
* @code sock_open(int ifindex, const struct sock_fprog *fprog);
*
Expand Down