-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add DHCPv6 Relay Agent #8251
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
Changes from 4 commits
f1db17f
18a598b
eccb093
4ba13b9
429e752
6c4ed48
3e9093d
56dcedc
c339272
96664c5
308658f
f61c7db
99f91c0
e345890
f7b7d4a
6a42ef2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
debian/* | ||
!debian/changelog | ||
!debian/compat | ||
!debian/control | ||
!debian/rules |
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 | ||
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 | ||
|
||
|
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 <[email protected]> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Source: sonic-dhcp6relay | ||
Section: devel | ||
Priority: optional | ||
Maintainer: Kelly Yeh <[email protected]> | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/make -f | ||
|
||
DEB_CFLAGS_APPEND=-std=gnu11 | ||
export DEB_CFLAGS_APPEND | ||
|
||
%: | ||
dh $@ --parallel |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#include <sstream> | ||
#include <syslog.h> | ||
#include <algorithm> | ||
#include "configInterface.h" | ||
|
||
constexpr auto DEFAULT_TIMEOUT_MSEC = 1000; | ||
|
||
bool mPollSwssNotifcation = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can drop the letter |
||
std::shared_ptr<boost::thread> mSwssThreadPtr; | ||
|
||
// | ||
// ---> initialize(); | ||
// | ||
// initialize DB tables and start SWSS listening thread | ||
// | ||
void initialize_swss(arg_config *context) | ||
{ | ||
try { | ||
mSwssThreadPtr = std::make_shared<boost::thread> (&handleSwssNotification, context); | ||
} | ||
catch (const std::bad_alloc &e) { | ||
syslog(LOG_ERR, "Failed allocate memory. Exception details: %s", e.what()); | ||
} | ||
} | ||
|
||
// | ||
// ---> deinitialize(); | ||
// | ||
// deinitialize DB interface and join SWSS listening thread | ||
// | ||
void deinitialize_swss() | ||
{ | ||
stopSwssNotificationPoll(); | ||
mSwssThreadPtr->interrupt(); | ||
} | ||
|
||
/** | ||
* @code void handleSwssNotification(arg_config *context) | ||
* | ||
* @brief main thread for handling SWSS notification | ||
* | ||
* @param context argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void handleSwssNotification(arg_config *context) | ||
{ | ||
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0); | ||
swss::SubscriberStateTable ipHelpersTable(configDbPtr.get(), "DHCP"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add |
||
|
||
swss::Select swssSelect; | ||
swssSelect.addSelectable(&ipHelpersTable); | ||
while (mPollSwssNotifcation) { | ||
swss::Selectable *selectable; | ||
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC); | ||
if (ret == swss::Select::ERROR) { | ||
syslog(LOG_WARNING, "Select: returned ERROR"); | ||
continue; | ||
} else if (ret == swss::Select::TIMEOUT) { | ||
continue; | ||
} | ||
if (selectable == static_cast<swss::Selectable *> (&ipHelpersTable)) { | ||
handleRelayNotification(ipHelpersTable, context); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, arg_config context) | ||
* | ||
* @brief handles DHCPv6 relay configuration change notification | ||
* | ||
* @param ipHelpersTable DHCP table | ||
* @param context argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, arg_config *context) | ||
{ | ||
std::deque<swss::KeyOpFieldsValuesTuple> entries; | ||
|
||
ipHelpersTable.pops(entries); | ||
processRelayNotification(entries, context); | ||
} | ||
|
||
/** | ||
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, arg_config context) | ||
* | ||
* @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 argument config that contains strings of server and option | ||
* | ||
* @return none | ||
*/ | ||
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, arg_config *context) | ||
{ | ||
std::vector<std::string> servers; | ||
|
||
for (auto &entry: entries) { | ||
std::string vlan = kfvKey(entry); | ||
std::vector<swss::FieldValueTuple> fieldValues = kfvFieldsValues(entry); | ||
|
||
for (auto &fieldValue: fieldValues) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can get the operation using |
||
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, ','); | ||
context->servers.push_back(substr); | ||
} | ||
} | ||
if(f == "options") { | ||
std::stringstream ss(v); | ||
while (ss.good()) { | ||
std::string substr; | ||
getline(ss, substr, ','); | ||
if(substr == "79") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the option 79 name up-to-date? |
||
context->is_option_79 = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
*@code stopSwssNotificationPoll | ||
* | ||
*@brief stop SWSS listening thread | ||
* | ||
*@return none | ||
*/ | ||
void stopSwssNotificationPoll() { | ||
mPollSwssNotifcation = false; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <boost/thread.hpp> | ||
#include "subscriberstatetable.h" | ||
#include "select.h" | ||
#include "relay.h" | ||
|
||
void initialize_swss(arg_config *context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add doxygen comments to functions in this file. |
||
|
||
void deinitialize_swss(); | ||
|
||
void handleSwssNotification(arg_config *context); | ||
|
||
void handleRelayNotification(swss::SubscriberStateTable &configMuxTable, arg_config *context); | ||
|
||
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, arg_config *context); | ||
|
||
void stopSwssNotificationPoll(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdlib.h> | ||
#include "configInterface.h" | ||
|
||
int main(int argc, char *argv[]) { | ||
try { | ||
arg_config context; | ||
tahmed-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
initialize_swss(&context); | ||
loop_relay(&context); | ||
} | ||
catch (std::exception &e) | ||
{ | ||
printf("Usage: -i <interface> -o <option>\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we are not using cli args anymore. |
||
return 1; | ||
} | ||
return 0; | ||
} |
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 add this flag to
CFLAGS
inMakefile
above.