Skip to content

Commit fe90cb1

Browse files
authored
Adding support for filtering by destination IP and/or incoming interface to caclmgrd. (sonic-net#195)
This feature - filtering by destination IP and/or incoming interface - can be useful to limit certain traffic from reaching the control plane via unwanted interfaces, such as VLAN interfaces or P2Ps.
1 parent 6006e05 commit fe90cb1

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

scripts/caclmgrd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,14 @@ class ControlPlaneAclManager(logger.Logger):
774774
if rule_props["PACKET_ACTION"] == "ACCEPT":
775775
ipv4_src_ip_set.add(rule_props["SRC_IP"])
776776

777+
if "DST_IPV6" in rule_props and rule_props["DST_IPV6"]:
778+
rule_cmd += ["-d", str(rule_props["DST_IPV6"])]
779+
elif "DST_IP" in rule_props and rule_props["DST_IP"]:
780+
rule_cmd += ["-d", str(rule_props["DST_IP"])]
781+
782+
if "IN_PORTS" in rule_props and rule_props["IN_PORTS"]:
783+
rule_cmd += ["-i", str(rule_props["IN_PORTS"])]
784+
777785
# Destination port 0 is reserved/unused port, so, using it to apply the rule to all ports.
778786
if dst_port != "0":
779787
rule_cmd += ["--dport", str(dst_port)]

tests/caclmgrd/test_external_client_acl_vectors.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,83 @@
7777
],
7878
}
7979
],
80+
[
81+
"Test single IPv4 dst port + dst ip for EXTERNAL_CLIENT_ACL",
82+
{
83+
"config_db": {
84+
"ACL_TABLE": {
85+
"EXTERNAL_CLIENT_ACL": {
86+
"stage": "INGRESS",
87+
"type": "CTRLPLANE",
88+
"services": [
89+
"EXTERNAL_CLIENT"
90+
]
91+
}
92+
},
93+
"ACL_RULE": {
94+
"EXTERNAL_CLIENT_ACL|DEFAULT_RULE": {
95+
"ETHER_TYPE": "2048",
96+
"PACKET_ACTION": "DROP",
97+
"PRIORITY": "1"
98+
},
99+
"EXTERNAL_CLIENT_ACL|RULE_1": {
100+
"L4_DST_PORT": "8081",
101+
"PACKET_ACTION": "ACCEPT",
102+
"PRIORITY": "9998",
103+
"DST_IP": "20.0.0.66/32"
104+
},
105+
},
106+
"DEVICE_METADATA": {
107+
"localhost": {
108+
}
109+
},
110+
"FEATURE": {},
111+
},
112+
"return": [
113+
['iptables', '-A', 'INPUT', '-p', 'tcp', '-d', '20.0.0.66/32', '--dport', '8081', '-j', 'ACCEPT'],
114+
['iptables', '-A', 'INPUT', '-p', 'tcp', '--dport', '8081', '-j', 'DROP']
115+
],
116+
}
117+
],
118+
[
119+
"Test single IPv4 dst port + incoming interface for EXTERNAL_CLIENT_ACL",
120+
{
121+
"config_db": {
122+
"ACL_TABLE": {
123+
"EXTERNAL_CLIENT_ACL": {
124+
"stage": "INGRESS",
125+
"type": "CTRLPLANE",
126+
"services": [
127+
"EXTERNAL_CLIENT"
128+
]
129+
}
130+
},
131+
"ACL_RULE": {
132+
"EXTERNAL_CLIENT_ACL|DEFAULT_RULE": {
133+
"ETHER_TYPE": "2048",
134+
"PACKET_ACTION": "DROP",
135+
"PRIORITY": "1"
136+
},
137+
"EXTERNAL_CLIENT_ACL|RULE_1": {
138+
"L4_DST_PORT": "8081",
139+
"PACKET_ACTION": "ACCEPT",
140+
"PRIORITY": "9998",
141+
"DST_IP": "0.0.0.0/0",
142+
"IN_PORTS": "mgmt"
143+
},
144+
},
145+
"DEVICE_METADATA": {
146+
"localhost": {
147+
}
148+
},
149+
"FEATURE": {},
150+
},
151+
"return": [
152+
['iptables', '-A', 'INPUT', '-p', 'tcp', '-d', '0.0.0.0/0', '-i', 'mgmt', '--dport', '8081', '-j', 'ACCEPT'],
153+
['iptables', '-A', 'INPUT', '-p', 'tcp', '--dport', '8081', '-j', 'DROP']
154+
],
155+
}
156+
],
80157
[
81158
"Test IPv4 dst port range + src ip forEXTERNAL_CLIENT_ACL",
82159
{
@@ -157,6 +234,44 @@
157234
],
158235
}
159236
],
237+
[
238+
"Test IPv6 single dst port range + dst ip forEXTERNAL_CLIENT_ACL",
239+
{
240+
"config_db": {
241+
"ACL_TABLE": {
242+
"EXTERNAL_CLIENT_ACL": {
243+
"stage": "INGRESS",
244+
"type": "CTRLPLANE",
245+
"services": [
246+
"EXTERNAL_CLIENT"
247+
]
248+
}
249+
},
250+
"ACL_RULE": {
251+
"EXTERNAL_CLIENT_ACL|DEFAULT_RULE": {
252+
"ETHER_TYPE": "2048",
253+
"PACKET_ACTION": "DROP",
254+
"PRIORITY": "1"
255+
},
256+
"EXTERNAL_CLIENT_ACL|RULE_1": {
257+
"L4_DST_PORT": "8081",
258+
"PACKET_ACTION": "ACCEPT",
259+
"PRIORITY": "9998",
260+
"DST_IP": "2001::6/128"
261+
},
262+
},
263+
"DEVICE_METADATA": {
264+
"localhost": {
265+
}
266+
},
267+
"FEATURE": {},
268+
},
269+
"return": [
270+
['iptables', '-A', 'INPUT', '-p', 'tcp', '-d', '2001::6/128', '--dport', '8081', '-j', 'ACCEPT'],
271+
['iptables', '-A', 'INPUT', '-p', 'tcp', '--dport', '8081', '-j', 'DROP']
272+
],
273+
}
274+
],
160275
[
161276
"Test IPv6 dst port range + src ip forEXTERNAL_CLIENT_ACL",
162277
{

0 commit comments

Comments
 (0)