Skip to content

Commit 4546372

Browse files
authored
[config/acl] Get ACL config from DHCP and load it in swss container (#432)
Get ACL config from DHCP and load it in swss container
1 parent 4359f13 commit 4546372

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

dockers/docker-orchagent/start.sh

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ function start_app {
1212
done
1313
}
1414

15+
function config_acl {
16+
if [ -f "/etc/sonic/acl.json" ]; then
17+
mkdir -p /etc/swss/config.d/acl
18+
rm -rf /etc/swss/config.d/acl/*
19+
translate_acl -m /etc/sonic/minigraph.xml -o /etc/swss/config.d/acl /etc/sonic/acl.json
20+
for filename in /etc/swss/config.d/acl/*.json; do
21+
[ -e "$filename" ] || break
22+
swssconfig $filename
23+
done
24+
fi
25+
}
26+
1527
function clean_up {
1628
pkill -9 orchagent
1729
pkill -9 portsyncd
@@ -60,6 +72,7 @@ while true; do
6072
result=`echo -en "SELECT 1\nHLEN HIDDEN" | redis-cli | sed -n 2p`
6173
if [ "$result" != "0" ]; then
6274
start_app
75+
config_acl
6376
read
6477
fi
6578
sleep 1

files/dhcp/dhclient.conf

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
1515
option snmp-community code 224 = text;
1616
option minigraph-url code 225 = text;
17+
option acl-url code 226 = text;
1718

1819
send host-name = gethostname();
1920
request subnet-mask, broadcast-address, time-offset, routers,
2021
domain-name, domain-name-servers, domain-search, host-name,
2122
dhcp6.name-servers, dhcp6.domain-search,
2223
netbios-name-servers, netbios-scope, interface-mtu,
23-
rfc3442-classless-static-routes, ntp-servers, snmp-community, minigraph-url;
24+
rfc3442-classless-static-routes, ntp-servers, snmp-community, minigraph-url, acl-url;
2425

files/dhcp/graphserviceurl

+3
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ case $reason in
55
else
66
echo "N/A" > /tmp/dhcp_graph_url
77
fi
8+
if [ -n "$new_acl_url" ]; then
9+
echo $new_acl_url > /tmp/dhcp_acl_url
10+
fi
811
;;
912
esac

files/image_config/updategraph/updategraph

+30
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if [ "$enabled" != "true" ]; then
1212
exit 0
1313
fi
1414

15+
ACL_URL=$acl_src
16+
1517
if [ "$src" = "dhcp" ]; then
1618
while [ ! -f /tmp/dhcp_graph_url ]; do
1719
echo "Waiting for DHCP response..."
@@ -38,6 +40,18 @@ if [ "$src" = "dhcp" ]; then
3840
sed -i "/src=/d" /etc/sonic/updategraph.conf
3941
echo "src=\"$GRAPH_URL\"" >> /etc/sonic/updategraph.conf
4042
fi
43+
44+
if [ -f /tmp/dhcp_acl_url ]; then
45+
ACL_URL=`sonic-cfggen -t /tmp/dhcp_acl_url -a "{\"hostname\": \"$HOSTNAME\"}"`
46+
if [[ ! $ACL_URL =~ $URL_REGEX ]]; then
47+
echo "\"$ACL_URL\" is not a valid url. Skipping acl update."
48+
ACL_URL=""
49+
fi
50+
if [ "$dhcp_as_static" = "true" ]; then
51+
sed -i "/acl_src=/d" /etc/sonic/updategraph.conf
52+
echo "acl_src=\"$ACL_URL\"" >> /etc/sonic/updategraph.conf
53+
fi
54+
fi
4155
else
4256
GRAPH_URL=$src
4357
fi
@@ -53,3 +67,19 @@ while true; do
5367
curl -f $GRAPH_URL -o /etc/sonic/minigraph.xml --connect-timeout 15 && break
5468
sleep 5
5569
done
70+
71+
if [ -n "$ACL_URL" ]; then
72+
if [ -f /etc/sonic/acl.json ]; then
73+
echo "Renaming acl.json to acl.json.old"
74+
mv /etc/sonic/acl.json /etc/sonic/acl.json.old
75+
fi
76+
echo "Getting ACL config from $ACL_URL"
77+
78+
while true; do
79+
curl -f $ACL_URL -o /etc/sonic/acl.json --connect-timeout 15 && break
80+
sleep 5
81+
done
82+
else
83+
echo "Skip ACL config download."
84+
fi
85+

src/sonic-config-engine/translate_acl

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ def translate_acl_fixed_port(filename, output_path, port, max_priority):
129129

130130
def translate_acl(filename, output_path, attach_to, max_priority):
131131
yang_acl = pybindJSON.load(filename, openconfig_acl, "openconfig_acl")
132-
print attach_to.keys()
133132
for aclsetname in yang_acl.acl.acl_sets.acl_set:
134133
tablename = aclsetname.replace(" ", "_").replace("-", "_")
135134
if attach_to.has_key(tablename):
@@ -151,7 +150,8 @@ def main():
151150
translate_acl_fixed_port(args.input, args.output_path, args.port, args.max_priority)
152151
elif args.minigraph:
153152
mini_data = parse_xml(args.minigraph)
154-
translate_acl(args.input, args.output_path, mini_data['minigraph_acls'], args.max_priority)
153+
if mini_data['minigraph_acls']:
154+
translate_acl(args.input, args.output_path, mini_data['minigraph_acls'], args.max_priority)
155155

156156
if __name__ == "__main__":
157157
main()

0 commit comments

Comments
 (0)