-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add DHCPv6 Relay Agent #8251
Merged
Merged
Add DHCPv6 Relay Agent #8251
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f1db17f
Added DHCPv6 Relay
kellyyeh 18a598b
Added DHCPv6 Relay
kellyyeh eccb093
Deleted argument parser and fixed port naming and indentation
kellyyeh 4ba13b9
Added server listening to libevent loop
kellyyeh 429e752
Added operation key to configInterface
kellyyeh 6c4ed48
Support multi vlans
kellyyeh 3e9093d
Added DHCPv6 Counter and addressed PR comments
kellyyeh 56dcedc
Addressed PR comments, removed arg_config
kellyyeh c339272
Updated counter to support multi-vlan
kellyyeh 96664c5
Updated update_counter
kellyyeh 308658f
Changed counter table name
kellyyeh f61c7db
Use specified intf address instead of ipv6 auto selection for now
kellyyeh 99f91c0
Updated counter table name
kellyyeh e345890
Updated option parsing
kellyyeh f7b7d4a
Updated option parsing
kellyyeh 6a42ef2
Updated relay.cpp
kellyyeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
debian/* | ||
!debian/changelog | ||
!debian/compat | ||
!debian/control | ||
!debian/rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
RM := rm -rf | ||
DHCP6RELAY_TARGET := dhcp6relay | ||
CP := cp | ||
MKDIR := mkdir | ||
CC := g++ | ||
MV := mv | ||
LIBS := -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboost_system -I $(PWD)/../sonic-swss-common/common | ||
CFLAGS = -g -Wall -std=gnu11 | ||
PWD := $(shell pwd) | ||
|
||
ifneq ($(MAKECMDGOALS),clean) | ||
ifneq ($(strip $(C_DEPS)),) | ||
-include $(C_DEPS) $(OBJS) | ||
endif | ||
endif | ||
|
||
-include src/subdir.mk | ||
|
||
all: sonic-dhcp6relay | ||
|
||
sonic-dhcp6relay: $(OBJS) | ||
@echo 'Building target: $@' | ||
@echo 'Invoking: G++ Linker' | ||
$(CC) -o $(DHCP6RELAY_TARGET) $(OBJS) $(LIBS) | ||
@echo 'Finished building target: $@' | ||
@echo ' ' | ||
|
||
install: | ||
$(MKDIR) -p $(DESTDIR)/usr/sbin | ||
$(MV) $(DHCP6RELAY_TARGET) $(DESTDIR)/usr/sbin | ||
|
||
deinstall: | ||
$(RM) $(DESTDIR)/usr/sbin/$(DHCP6RELAY_TARGET) | ||
$(RM) -rf $(DESTDIR)/usr/sbin | ||
|
||
clean: | ||
-$(RM) $(EXECUTABLES) $(C_DEPS) $(OBJS) $(DHCP6RELAY_TARGET) | ||
-@echo ' ' | ||
|
||
.PHONY: all clean dependents | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sonic-dhcp6relay (1.0.0-0) UNRELEASED; urgency=medium | ||
|
||
* Initial release. | ||
|
||
-- Kelly Yeh <kellyyeh@microsoft.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Source: sonic-dhcp6relay | ||
Section: devel | ||
Priority: optional | ||
Maintainer: Kelly Yeh <kellyyeh@microsoft.com> | ||
Build-Depends: debhelper (>= 8.0.0), | ||
dh-systemd | ||
Standards-Version: 3.9.3 | ||
Homepage: https://github.com/Azure/sonic-buildimage | ||
XS-Go-Import-Path: github.com/Azure/sonic-buildimage | ||
|
||
Package: sonic-dhcp6relay | ||
Architecture: any | ||
Built-Using: ${misc:Built-Using} | ||
Depends: libevent-2.1-6, | ||
libboost-thread1.71.0, | ||
libboost-system1.71.0 | ||
Description: SONiC DHCPv6 Relay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/make -f | ||
|
||
%: | ||
dh $@ --parallel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#include <sstream> | ||
#include <syslog.h> | ||
#include <algorithm> | ||
#include "configInterface.h" | ||
|
||
constexpr auto DEFAULT_TIMEOUT_MSEC = 1000; | ||
|
||
bool pollSwssNotifcation = true; | ||
std::shared_ptr<boost::thread> mSwssThreadPtr; | ||
|
||
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0); | ||
swss::SubscriberStateTable ipHelpersTable(configDbPtr.get(), "DHCP_RELAY"); | ||
swss::Select swssSelect; | ||
|
||
/** | ||
* @code void deinitialize_swss() | ||
* | ||
* @brief initialize DB tables and start SWSS listening thread | ||
* | ||
* @return none | ||
*/ | ||
void initialize_swss(std::vector<relay_config> *vlans, swss::DBConnector *db) | ||
{ | ||
try { | ||
swssSelect.addSelectable(&ipHelpersTable); | ||
get_dhcp(vlans); | ||
mSwssThreadPtr = std::make_shared<boost::thread> (&handleSwssNotification, vlans); | ||
} | ||
catch (const std::bad_alloc &e) { | ||
syslog(LOG_ERR, "Failed allocate memory. Exception details: %s", e.what()); | ||
} | ||
} | ||
|
||
/** | ||
* @code void deinitialize_swss() | ||
* | ||
* @brief deinitialize DB interface and join SWSS listening thread | ||
* | ||
* @return none | ||
*/ | ||
void deinitialize_swss() | ||
{ | ||
stopSwssNotificationPoll(); | ||
mSwssThreadPtr->interrupt(); | ||
} | ||
|
||
|
||
/** | ||
* @code void get_dhcp(std::vector<relay_config> *vlans) | ||
* | ||
* @brief initialize and get vlan table information from DHCP_RELAY | ||
* | ||
* @return none | ||
*/ | ||
void get_dhcp(std::vector<relay_config> *vlans) { | ||
swss::Selectable *selectable; | ||
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC); | ||
if (ret == swss::Select::ERROR) { | ||
syslog(LOG_WARNING, "Select: returned ERROR"); | ||
} else if (ret == swss::Select::TIMEOUT) { | ||
} | ||
if (selectable == static_cast<swss::Selectable *> (&ipHelpersTable)) { | ||
handleRelayNotification(ipHelpersTable, vlans); | ||
} | ||
} | ||
/** | ||
* @code void handleSwssNotification(std::vector<relay_config> *vlans) | ||
* | ||
* @brief main thread for handling SWSS notification | ||
* | ||
* @param context list of vlans/argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void handleSwssNotification(std::vector<relay_config> *vlans) | ||
{ | ||
while (pollSwssNotifcation) { | ||
get_dhcp(vlans); | ||
} | ||
} | ||
|
||
/** | ||
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans) | ||
* | ||
* @brief handles DHCPv6 relay configuration change notification | ||
* | ||
* @param ipHelpersTable DHCP table | ||
* @param context list of vlans/argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans) | ||
{ | ||
std::deque<swss::KeyOpFieldsValuesTuple> entries; | ||
|
||
ipHelpersTable.pops(entries); | ||
processRelayNotification(entries, vlans); | ||
} | ||
|
||
/** | ||
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans) | ||
* | ||
* @brief process DHCPv6 relay servers and options configuration change notification | ||
* | ||
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table | ||
* @param context list of vlans/argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans) | ||
{ | ||
std::vector<std::string> servers; | ||
|
||
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.interface = vlan; | ||
for (auto &fieldValue: fieldValues) { | ||
std::string f = fvField(fieldValue); | ||
std::string v = fvValue(fieldValue); | ||
if(f == "dhcpv6_servers") { | ||
std::stringstream ss(v); | ||
while (ss.good()) { | ||
std::string substr; | ||
getline(ss, substr, ','); | ||
intf.servers.push_back(substr); | ||
} | ||
syslog(LOG_DEBUG, "key: %s, Operation: %s, f: %s, v: %s", vlan.c_str(), operation.c_str(), f.c_str(), v.c_str()); | ||
} | ||
if(f == "options") { | ||
std::stringstream ss(v); | ||
while (ss.good()) { | ||
std::string substr; | ||
getline(ss, substr, ','); | ||
if(substr == "dhcpv6_option|rfc6939_support") | ||
intf.is_option_79 = true; | ||
} | ||
} | ||
} | ||
vlans->push_back(intf); | ||
} | ||
} | ||
|
||
/** | ||
*@code stopSwssNotificationPoll | ||
* | ||
*@brief stop SWSS listening thread | ||
* | ||
*@return none | ||
*/ | ||
void stopSwssNotificationPoll() { | ||
pollSwssNotifcation = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <boost/thread.hpp> | ||
#include "subscriberstatetable.h" | ||
#include "select.h" | ||
#include "relay.h" | ||
|
||
/** | ||
* @code void deinitialize_swss() | ||
* | ||
* @brief initialize DB tables and start SWSS listening thread | ||
* | ||
* @return none | ||
*/ | ||
void initialize_swss(std::vector<relay_config> *vlans, swss::DBConnector *db); | ||
|
||
/** | ||
* @code void deinitialize_swss() | ||
* | ||
* @brief deinitialize DB interface and join SWSS listening thread | ||
* | ||
* @return none | ||
*/ | ||
void deinitialize_swss(); | ||
|
||
/** | ||
* @code void get_dhcp(std::vector<relay_config> *vlans) | ||
* | ||
* @brief initialize and get vlan information from DHCP_RELAY | ||
* | ||
* @return none | ||
*/ | ||
void get_dhcp(std::vector<relay_config> *vlans); | ||
|
||
/** | ||
* @code void handleSwssNotification(std::vector<relay_config> *vlans) | ||
* | ||
* @brief main thread for handling SWSS notification | ||
* | ||
* @param context list of vlans/argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void handleSwssNotification(std::vector<relay_config> *vlans); | ||
|
||
/** | ||
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans) | ||
* | ||
* @brief handles DHCPv6 relay configuration change notification | ||
* | ||
* @param ipHelpersTable DHCP table | ||
* @param context list of vlans/argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void handleRelayNotification(swss::SubscriberStateTable &configMuxTable, std::vector<relay_config> *vlans); | ||
|
||
/** | ||
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans) | ||
* | ||
* @brief process DHCPv6 relay servers and options configuration change notification | ||
* | ||
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table | ||
* @param context list of vlans/argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans); | ||
|
||
/** | ||
*@code stopSwssNotificationPoll | ||
* | ||
*@brief stop SWSS listening thread | ||
* | ||
*@return none | ||
*/ | ||
void stopSwssNotificationPoll(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdlib.h> | ||
#include <syslog.h> | ||
#include "configInterface.h" | ||
|
||
int main(int argc, char *argv[]) { | ||
try { | ||
std::vector<relay_config> vlans; | ||
swss::DBConnector state_db("STATE_DB", 0); | ||
initialize_swss(&vlans, &state_db); | ||
loop_relay(&vlans, &state_db); | ||
} | ||
catch (std::exception &e) | ||
{ | ||
syslog(LOG_ERR, "An exception occurred.\n"); | ||
return 1; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to check the operation here if it is ADD/DEL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dhcpv6 server address are type string value. e.g.: "fc02:2000::1,fc02:2000::2"
HDEL would delete the entire string of addresses. HSET updates the list of server addresses.
When config_db updates the list of server addresses, all addresses are properly fetched and processed regardless new addresses are added/deleted. Therefore, I don't think there is a need to check for add/del
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get the operation using
std::string operation = kfvOp(entry);
. This way we can tell the type of the record updates. I think they areSET/DEL
operation.