Skip to content

Commit 8ffbe8a

Browse files
author
jcaiMR
committed
# This is a combination of 5 commits.
# This is the 1st commit message: fix multi-vlan relay issue # This is the commit message sonic-net#2: issue fix # This is the commit message sonic-net#3: code refine in UT # This is the commit message sonic-net#4: fix counter rollback issue # This is the commit message sonic-net#5: Use github code scanning instead of LGTM (sonic-net#26) * Use github code scanning instead of LGTM * fi libyang libyang1 * remove libyang1 * add python * add libpython
1 parent 1e846f6 commit 8ffbe8a

File tree

8 files changed

+350
-268
lines changed

8 files changed

+350
-268
lines changed

.github/codeql/codeql-config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: "CodeQL config"
2+
queries:
3+
- uses: security-and-quality
4+
- uses: security-extended

.github/workflows/codeql-analysis.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# For more infomation, please visit: https://github.com/github/codeql-action
2+
3+
name: "CodeQL"
4+
5+
on:
6+
push:
7+
branches:
8+
- 'master'
9+
- '202[0-9][0-9][0-9]'
10+
pull_request_target:
11+
branches:
12+
- 'master'
13+
- '202[0-9][0-9][0-9]'
14+
workflow_dispatch:
15+
16+
jobs:
17+
analyze:
18+
name: Analyze
19+
runs-on: ubuntu-20.04
20+
permissions:
21+
actions: read
22+
contents: read
23+
security-events: write
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
language: [ 'cpp' ]
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v3
33+
34+
# Initializes the CodeQL tools for scanning.
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/[email protected]
37+
with:
38+
config-file: ./.github/codeql/codeql-config.yml
39+
languages: ${{ matrix.language }}
40+
41+
- name: prepare
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install -y libboost-system-dev \
45+
libboost-thread-dev \
46+
libevent-dev \
47+
libhiredis-dev \
48+
libnl-3-dev \
49+
libnl-route-3-dev \
50+
libnl-nf-3-dev \
51+
libnl-genl-3-dev \
52+
libgmock-dev \
53+
dh-exec \
54+
swig3.0 \
55+
uuid-dev \
56+
libzmq3-dev \
57+
libyang-dev \
58+
libpython2.7-dev \
59+
python
60+
61+
- name: build-swss-common
62+
run: |
63+
set -x
64+
cd ..
65+
git clone https://github.com/sonic-net/sonic-swss-common
66+
pushd sonic-swss-common
67+
./autogen.sh
68+
fakeroot dpkg-buildpackage -us -uc -b
69+
popd
70+
dpkg-deb -x libswsscommon_1.0.0_amd64.deb $(dirname $GITHUB_WORKSPACE)
71+
dpkg-deb -x libswsscommon-dev_1.0.0_amd64.deb $(dirname $GITHUB_WORKSPACE)
72+
73+
- name: build
74+
run: |
75+
make all LDFLAGS="-L$(dirname $GITHUB_WORKSPACE)/usr/lib/x86_64-linux-gnu" CPPFLAGS="-I$(dirname $GITHUB_WORKSPACE)/usr/include -I$(dirname $GITHUB_WORKSPACE)/usr/include/swss"
76+
77+
- name: Perform CodeQL Analysis
78+
uses: github/codeql-action/[email protected]
79+
with:
80+
category: "/language:${{matrix.language}}"

src/configInterface.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ swss::Select swssSelect;
1616
*
1717
* @return none
1818
*/
19-
void initialize_swss(std::vector<relay_config> *vlans)
19+
void initialize_swss(std::unordered_map<std::string, relay_config> &vlans)
2020
{
2121
try {
2222
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
@@ -48,13 +48,14 @@ void deinitialize_swss()
4848

4949

5050
/**
51-
* @code void get_dhcp(std::vector<relay_config> *vlans)
51+
* @code void get_dhcp(std::unordered_map<std::string, relay_config> vlans)
5252
*
5353
* @brief initialize and get vlan table information from DHCP_RELAY
5454
*
5555
* @return none
5656
*/
57-
void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable) {
57+
void get_dhcp(std::unordered_map<std::string, relay_config> &vlans, swss::SubscriberStateTable *ipHelpersTable)
58+
{
5859
swss::Selectable *selectable;
5960
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC);
6061
if (ret == swss::Select::ERROR) {
@@ -70,7 +71,7 @@ void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHe
7071
*
7172
* @brief main thread for handling SWSS notification
7273
*
73-
* @param context list of vlans/argument config that contains strings of server and option
74+
* @param context map of vlans/argument config that contains strings of server and option
7475
*
7576
* @return none
7677
*/
@@ -82,16 +83,16 @@ void handleSwssNotification(swssNotification test)
8283
}
8384

8485
/**
85-
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
86+
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans)
8687
*
8788
* @brief handles DHCPv6 relay configuration change notification
8889
*
8990
* @param ipHelpersTable DHCP table
90-
* @param vlans list of vlans/argument config that contains strings of server and option
91+
* @param vlans map of vlans/argument config that contains strings of server and option
9192
*
9293
* @return none
9394
*/
94-
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
95+
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans)
9596
{
9697
std::deque<swss::KeyOpFieldsValuesTuple> entries;
9798

@@ -100,16 +101,16 @@ void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::ve
100101
}
101102

102103
/**
103-
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
104+
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> vlans)
104105
*
105106
* @brief process DHCPv6 relay servers and options configuration change notification
106107
*
107108
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table
108-
* @param vlans list of vlans/argument config that contains strings of server and option
109+
* @param vlans map of vlans/argument config that contains strings of server and option
109110
*
110111
* @return none
111112
*/
112-
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
113+
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> &vlans)
113114
{
114115
std::vector<std::string> servers;
115116

@@ -143,7 +144,9 @@ void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries,
143144
intf.is_interface_id = true;
144145
}
145146
}
146-
vlans->push_back(intf);
147+
syslog(LOG_INFO, "add %s relay config, option79 %s interface-id %s\n", vlan.c_str(),
148+
intf.is_option_79 ? "enable" : "disable", intf.is_interface_id ? "enable" : "disable");
149+
vlans[vlan] = intf;
147150
}
148151
}
149152

src/configInterface.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#pragma once
22

3+
#include <string>
4+
#include <unordered_map>
35
#include <boost/thread.hpp>
46
#include "subscriberstatetable.h"
57
#include "select.h"
68
#include "relay.h"
79

810
struct swssNotification {
9-
std::vector<relay_config> *vlans;
11+
std::unordered_map<std::string, relay_config> vlans;
1012
swss::SubscriberStateTable *ipHelpersTable;
1113
};
1214
/**
@@ -16,7 +18,7 @@ struct swssNotification {
1618
*
1719
* @return none
1820
*/
19-
void initialize_swss(std::vector<relay_config> *vlans);
21+
void initialize_swss(std::unordered_map<std::string, relay_config> &vlans);
2022

2123
/**
2224
* @code void deinitialize_swss()
@@ -28,13 +30,13 @@ void initialize_swss(std::vector<relay_config> *vlans);
2830
void deinitialize_swss();
2931

3032
/**
31-
* @code void get_dhcp(std::vector<relay_config> *vlans)
33+
* @code void get_dhcp(std::unordered_map<std::string, relay_config> vlans)
3234
*
3335
* @brief initialize and get vlan information from DHCP_RELAY
3436
*
3537
* @return none
3638
*/
37-
void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable);
39+
void get_dhcp(std::unordered_map<std::string, relay_config> &vlans, swss::SubscriberStateTable *ipHelpersTable);
3840

3941
/**
4042
* @code void swssNotification test
@@ -48,28 +50,28 @@ void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHe
4850
void handleSwssNotification(swssNotification test);
4951

5052
/**
51-
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
53+
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans)
5254
*
5355
* @brief handles DHCPv6 relay configuration change notification
5456
*
5557
* @param ipHelpersTable DHCP table
56-
* @param vlans list of vlans/argument config that contains strings of server and option
58+
* @param vlans map of vlans/argument config that contains strings of server and option
5759
*
5860
* @return none
5961
*/
60-
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans);
62+
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans);
6163

6264
/**
63-
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
65+
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> &vlans)
6466
*
6567
* @brief process DHCPv6 relay servers and options configuration change notification
6668
*
6769
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table
68-
* @param context list of vlans/argument config that contains strings of server and option
70+
* @param context map of vlans/argument config that contains strings of server and option
6971
*
7072
* @return none
7173
*/
72-
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans);
74+
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> &vlans);
7375

7476
/**
7577
*@code stopSwssNotificationPoll

src/main.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdlib.h>
22
#include <syslog.h>
3+
#include <unordered_map>
34
#include "configInterface.h"
45

56
bool dual_tor_sock = false;
@@ -23,9 +24,9 @@ int main(int argc, char *argv[]) {
2324
}
2425
}
2526
try {
26-
std::vector<relay_config> vlans;
27-
initialize_swss(&vlans);
28-
loop_relay(&vlans);
27+
std::unordered_map<std::string, relay_config> vlans;
28+
initialize_swss(vlans);
29+
loop_relay(vlans);
2930
}
3031
catch (std::exception &e)
3132
{

0 commit comments

Comments
 (0)