Skip to content

Commit d892214

Browse files
authored
Revert "[202012] Change dhcp6relay to be a submodule (#11922)" (#12028)
This reverts commit 9db2e21.
1 parent a668ccf commit d892214

19 files changed

+1586
-33
lines changed

.gitmodules

-7
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,3 @@
9090
path = src/linkmgrd
9191
url = https://github.com/Azure/sonic-linkmgrd.git
9292
branch = 202012
93-
[submodule "src/dhcprelay"]
94-
path = src/dhcprelay
95-
url = https://github.com/sonic-net/sonic-dhcp-relay.git
96-
branch = 202012
97-
[submodule "sonic-dhcp-relay"]
98-
path = sonic-dhcp-relay
99-
url = https://github.com/kellyyeh/sonic-dhcp-relay.git

rules/dhcp6relay.dep

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
SPATH := $($(SONIC_DHCP6RELAY)_SRC_PATH)
3+
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/dhcp6relay.mk rules/dhcp6relay.dep
4+
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
5+
DEP_FILES += $(shell git ls-files $(SPATH))
6+
7+
$(SONIC_DHCP6RELAY)_CACHE_MODE := GIT_CONTENT_SHA
8+
$(SONIC_DHCP6RELAY)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
9+
$(SONIC_DHCP6RELAY)_DEP_FILES := $(DEP_FILES)

rules/dhcp6relay.mk

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SONiC DHCPV6 RELAY Package
2+
3+
SONIC_DHCP6RELAY_VERSION = 1.0.0-0
4+
SONIC_DHCP6RELAY_PKG_NAME = dhcp6relay
5+
6+
SONIC_DHCP6RELAY = sonic-$(SONIC_DHCP6RELAY_PKG_NAME)_$(SONIC_DHCP6RELAY_VERSION)_$(CONFIGURED_ARCH).deb
7+
$(SONIC_DHCP6RELAY)_DEPENDS = $(LIBSWSSCOMMON) $(LIBHIREDIS) $(LIBSWSSCOMMON_DEV) $(LIBHIREDIS_DEV)
8+
$(SONIC_DHCP6RELAY)_SRC_PATH = $(SRC_PATH)/$(SONIC_DHCP6RELAY_PKG_NAME)
9+
SONIC_DPKG_DEBS += $(SONIC_DHCP6RELAY)
10+
11+
SONIC_DHCP6RELAY_DBG = sonic-$(SONIC_DHCP6RELAY_PKG_NAME)-dbgsym_$(SONIC_DHCP6RELAY_VERSION)_$(CONFIGURED_ARCH).deb
12+
$(eval $(call add_derived_package,$(SONIC_DHCP6RELAY),$(SONIC_DHCP6RELAY_DBG)))

rules/dhcprelay.dep

-11
This file was deleted.

rules/dhcprelay.mk

-12
This file was deleted.

rules/docker-dhcp-relay.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ DOCKER_DHCP_RELAY_DBG = $(DOCKER_DHCP_RELAY_STEM)-$(DBG_IMAGE_MARK).gz
66

77
$(DOCKER_DHCP_RELAY)_PATH = $(DOCKERS_PATH)/$(DOCKER_DHCP_RELAY_STEM)
88

9-
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(SONIC_DHCPMON) $(SONIC_DHCPRELAY) $(LIBSWSSCOMMON)
9+
$(DOCKER_DHCP_RELAY)_DEPENDS += $(ISC_DHCP_RELAY) $(SONIC_DHCPMON) $(SONIC_DHCP6RELAY) $(LIBSWSSCOMMON)
1010

1111
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS)
12-
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_RELAY_DBG) $(SONIC_DHCPRELAY_DBG) $(SONIC_DHCPMON_DBG)
12+
$(DOCKER_DHCP_RELAY)_DBG_DEPENDS += $(ISC_DHCP_RELAY_DBG) $(SONIC_DHCP6RELAY_DBG) $(SONIC_DHCPMON_DBG)
1313

1414
$(DOCKER_DHCP_RELAY)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_IMAGE_PACKAGES)
1515

src/dhcp6relay/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
debian/*
2+
!debian/changelog
3+
!debian/compat
4+
!debian/control
5+
!debian/rules

src/dhcp6relay/Makefile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
RM := rm -rf
2+
DHCP6RELAY_TARGET := dhcp6relay
3+
CP := cp
4+
MKDIR := mkdir
5+
CC := g++
6+
MV := mv
7+
LIBS := -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboost_system
8+
CFLAGS += -Wall -std=c++17 -fPIE -I$(PWD)/../sonic-swss-common/common
9+
PWD := $(shell pwd)
10+
11+
ifneq ($(MAKECMDGOALS),clean)
12+
ifneq ($(strip $(C_DEPS)),)
13+
-include $(C_DEPS) $(OBJS)
14+
endif
15+
endif
16+
17+
-include src/subdir.mk
18+
19+
all: sonic-dhcp6relay
20+
21+
sonic-dhcp6relay: $(OBJS)
22+
@echo 'Building target: $@'
23+
@echo 'Invoking: G++ Linker'
24+
$(CC) $(LDFLAGS) -o $(DHCP6RELAY_TARGET) $(OBJS) $(LIBS)
25+
@echo 'Finished building target: $@'
26+
@echo ' '
27+
28+
install:
29+
$(MKDIR) -p $(DESTDIR)/usr/sbin
30+
$(MV) $(DHCP6RELAY_TARGET) $(DESTDIR)/usr/sbin
31+
32+
deinstall:
33+
$(RM) $(DESTDIR)/usr/sbin/$(DHCP6RELAY_TARGET)
34+
$(RM) -rf $(DESTDIR)/usr/sbin
35+
36+
clean:
37+
-$(RM) $(EXECUTABLES) $(C_DEPS) $(OBJS) $(DHCP6RELAY_TARGET)
38+
-@echo ' '
39+
40+
.PHONY: all clean dependents
41+
42+

src/dhcp6relay/debian/changelog

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sonic-dhcp6relay (1.0.0-0) UNRELEASED; urgency=medium
2+
3+
* Initial release.
4+
5+
-- Kelly Yeh <[email protected]>

src/dhcp6relay/debian/compat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9

src/dhcp6relay/debian/control

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Source: sonic-dhcp6relay
2+
Section: devel
3+
Priority: optional
4+
Maintainer: Kelly Yeh <[email protected]>
5+
Build-Depends: debhelper (>= 8.0.0),
6+
dh-systemd
7+
Standards-Version: 3.9.3
8+
Homepage: https://github.com/Azure/sonic-buildimage
9+
XS-Go-Import-Path: github.com/Azure/sonic-buildimage
10+
11+
Package: sonic-dhcp6relay
12+
Architecture: any
13+
Built-Using: ${misc:Built-Using}
14+
Depends: libevent-2.1-6,
15+
libboost-thread1.71.0,
16+
libboost-system1.71.0
17+
Description: SONiC DHCPv6 Relay

src/dhcp6relay/debian/rules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/make -f
2+
3+
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
4+
5+
%:
6+
dh $@ --parallel
+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#include <sstream>
2+
#include <syslog.h>
3+
#include <algorithm>
4+
#include "configInterface.h"
5+
6+
constexpr auto DEFAULT_TIMEOUT_MSEC = 1000;
7+
8+
bool pollSwssNotifcation = true;
9+
std::shared_ptr<boost::thread> mSwssThreadPtr;
10+
11+
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
12+
swss::SubscriberStateTable ipHelpersTable(configDbPtr.get(), "DHCP_RELAY");
13+
swss::Select swssSelect;
14+
15+
/**
16+
* @code void initialize_swss()
17+
*
18+
* @brief initialize DB tables and start SWSS listening thread
19+
*
20+
* @return none
21+
*/
22+
void initialize_swss(std::vector<relay_config> *vlans)
23+
{
24+
try {
25+
swssSelect.addSelectable(&ipHelpersTable);
26+
get_dhcp(vlans);
27+
mSwssThreadPtr = std::make_shared<boost::thread> (&handleSwssNotification, vlans);
28+
}
29+
catch (const std::bad_alloc &e) {
30+
syslog(LOG_ERR, "Failed allocate memory. Exception details: %s", e.what());
31+
}
32+
}
33+
34+
/**
35+
* @code void deinitialize_swss()
36+
*
37+
* @brief deinitialize DB interface and join SWSS listening thread
38+
*
39+
* @return none
40+
*/
41+
void deinitialize_swss()
42+
{
43+
stopSwssNotificationPoll();
44+
mSwssThreadPtr->interrupt();
45+
}
46+
47+
48+
/**
49+
* @code void get_dhcp(std::vector<relay_config> *vlans)
50+
*
51+
* @brief initialize and get vlan table information from DHCP_RELAY
52+
*
53+
* @return none
54+
*/
55+
void get_dhcp(std::vector<relay_config> *vlans) {
56+
swss::Selectable *selectable;
57+
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC);
58+
if (ret == swss::Select::ERROR) {
59+
syslog(LOG_WARNING, "Select: returned ERROR");
60+
} else if (ret == swss::Select::TIMEOUT) {
61+
}
62+
if (selectable == static_cast<swss::Selectable *> (&ipHelpersTable)) {
63+
handleRelayNotification(ipHelpersTable, vlans);
64+
}
65+
}
66+
/**
67+
* @code void handleSwssNotification(std::vector<relay_config> *vlans)
68+
*
69+
* @brief main thread for handling SWSS notification
70+
*
71+
* @param context list of vlans/argument config that contains strings of server and option
72+
*
73+
* @return none
74+
*/
75+
void handleSwssNotification(std::vector<relay_config> *vlans)
76+
{
77+
while (pollSwssNotifcation) {
78+
get_dhcp(vlans);
79+
}
80+
}
81+
82+
/**
83+
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
84+
*
85+
* @brief handles DHCPv6 relay configuration change notification
86+
*
87+
* @param ipHelpersTable DHCP table
88+
* @param vlans list of vlans/argument config that contains strings of server and option
89+
*
90+
* @return none
91+
*/
92+
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
93+
{
94+
std::deque<swss::KeyOpFieldsValuesTuple> entries;
95+
96+
ipHelpersTable.pops(entries);
97+
processRelayNotification(entries, vlans);
98+
}
99+
100+
/**
101+
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
102+
*
103+
* @brief process DHCPv6 relay servers and options configuration change notification
104+
*
105+
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table
106+
* @param vlans list of vlans/argument config that contains strings of server and option
107+
*
108+
* @return none
109+
*/
110+
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
111+
{
112+
std::vector<std::string> servers;
113+
114+
for (auto &entry: entries) {
115+
std::string vlan = kfvKey(entry);
116+
std::string operation = kfvOp(entry);
117+
std::vector<swss::FieldValueTuple> fieldValues = kfvFieldsValues(entry);
118+
119+
relay_config intf;
120+
intf.is_option_79 = true;
121+
intf.interface = vlan;
122+
intf.db = nullptr;
123+
for (auto &fieldValue: fieldValues) {
124+
std::string f = fvField(fieldValue);
125+
std::string v = fvValue(fieldValue);
126+
if(f == "dhcpv6_servers") {
127+
std::stringstream ss(v);
128+
while (ss.good()) {
129+
std::string substr;
130+
getline(ss, substr, ',');
131+
intf.servers.push_back(substr);
132+
}
133+
syslog(LOG_DEBUG, "key: %s, Operation: %s, f: %s, v: %s", vlan.c_str(), operation.c_str(), f.c_str(), v.c_str());
134+
}
135+
if(f == "dhcpv6_option|rfc6939_support" && v == "false") {
136+
intf.is_option_79 = false;
137+
}
138+
}
139+
vlans->push_back(intf);
140+
}
141+
}
142+
143+
/**
144+
*@code stopSwssNotificationPoll
145+
*
146+
*@brief stop SWSS listening thread
147+
*
148+
*@return none
149+
*/
150+
void stopSwssNotificationPoll() {
151+
pollSwssNotifcation = false;
152+
};

src/dhcp6relay/src/configInterface.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <boost/thread.hpp>
2+
#include "subscriberstatetable.h"
3+
#include "select.h"
4+
#include "relay.h"
5+
6+
/**
7+
* @code void initialize_swss()
8+
*
9+
* @brief initialize DB tables and start SWSS listening thread
10+
*
11+
* @return none
12+
*/
13+
void initialize_swss(std::vector<relay_config> *vlans);
14+
15+
/**
16+
* @code void deinitialize_swss()
17+
*
18+
* @brief deinitialize DB interface and join SWSS listening thread
19+
*
20+
* @return none
21+
*/
22+
void deinitialize_swss();
23+
24+
/**
25+
* @code void get_dhcp(std::vector<relay_config> *vlans)
26+
*
27+
* @brief initialize and get vlan information from DHCP_RELAY
28+
*
29+
* @return none
30+
*/
31+
void get_dhcp(std::vector<relay_config> *vlans);
32+
33+
/**
34+
* @code void handleSwssNotification(std::vector<relay_config> *vlans)
35+
*
36+
* @brief main thread for handling SWSS notification
37+
*
38+
* @param vlans list of vlans/argument config that contains strings of server and option
39+
*
40+
* @return none
41+
*/
42+
void handleSwssNotification(std::vector<relay_config> *vlans);
43+
44+
/**
45+
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
46+
*
47+
* @brief handles DHCPv6 relay configuration change notification
48+
*
49+
* @param ipHelpersTable DHCP table
50+
* @param vlans list of vlans/argument config that contains strings of server and option
51+
*
52+
* @return none
53+
*/
54+
void handleRelayNotification(swss::SubscriberStateTable &configMuxTable, std::vector<relay_config> *vlans);
55+
56+
/**
57+
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
58+
*
59+
* @brief process DHCPv6 relay servers and options configuration change notification
60+
*
61+
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table
62+
* @param context list of vlans/argument config that contains strings of server and option
63+
*
64+
* @return none
65+
*/
66+
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans);
67+
68+
/**
69+
*@code stopSwssNotificationPoll
70+
*
71+
*@brief stop SWSS listening thread
72+
*
73+
*@return none
74+
*/
75+
void stopSwssNotificationPoll();

0 commit comments

Comments
 (0)