5 from framework import VppTestRunner
6 from template_ipsec import IPSecIPv4Fwd
9 When an IPSec SPD is configured on an interface, any inbound packets
10 not matching inbound policies, or outbound packets not matching outbound
11 policies, must be dropped by default as per RFC4301.
13 This test uses simple IPv4 forwarding on interfaces with IPSec enabled
14 to check if packets with no matching rules are dropped by default.
16 The basic setup is a single SPD bound to two interfaces, pg0 and pg1.
24 First, both inbound and outbound BYPASS policies are configured allowing
25 traffic to pass from pg0 -> pg1.
27 Packets are captured and verified at pg1.
29 Then either the inbound or outbound policies are removed and we verify
30 packets are dropped as expected.
35 class IPSecInboundDefaultDrop(IPSecIPv4Fwd):
36 """IPSec: inbound packets drop by default with no matching rule"""
38 def test_ipsec_inbound_default_drop(self):
39 # configure two interfaces and bind the same SPD to both
40 self.create_interfaces(2)
41 self.spd_create_and_intf_add(1, self.pg_interfaces)
44 # catch-all inbound BYPASS policy, all interfaces
45 inbound_policy = self.spd_add_rem_policy(
56 # outbound BYPASS policy allowing traffic from pg0->pg1
57 outbound_policy = self.spd_add_rem_policy(
67 # create a packet stream pg0->pg1 + add to pg0
68 packets0 = self.create_stream(self.pg0, self.pg1, pkt_count)
69 self.pg0.add_stream(packets0)
71 # with inbound BYPASS rule at pg0, we expect to see forwarded
73 self.pg_interfaces[1].enable_capture()
75 cap1 = self.pg1.get_capture()
78 self.logger.debug(ppp("SPD - Got packet:", packet))
80 self.logger.error(ppp("Unexpected or invalid packet:", packet))
82 self.logger.debug("SPD: Num packets: %s", len(cap1.res))
83 # verify captures on pg1
84 self.verify_capture(self.pg0, self.pg1, cap1)
85 # verify policies matched correct number of times
86 self.verify_policy_match(pkt_count, inbound_policy)
87 self.verify_policy_match(pkt_count, outbound_policy)
89 # remove inbound catch-all BYPASS rule, traffic should now be dropped
90 self.spd_add_rem_policy( # inbound, all interfaces
102 # create another packet stream pg0->pg1 + add to pg0
103 packets1 = self.create_stream(self.pg0, self.pg1, pkt_count)
104 self.pg0.add_stream(packets1)
105 self.pg_interfaces[1].enable_capture()
107 # confirm traffic has now been dropped
108 self.pg1.assert_nothing_captured(
109 remark="inbound pkts with no matching" "rules NOT dropped by default"
111 # both policies should not have matched any further packets
112 # since we've dropped at input stage
113 self.verify_policy_match(pkt_count, outbound_policy)
114 self.verify_policy_match(pkt_count, inbound_policy)
117 class IPSecOutboundDefaultDrop(IPSecIPv4Fwd):
118 """IPSec: outbound packets drop by default with no matching rule"""
120 def test_ipsec_inbound_default_drop(self):
121 # configure two interfaces and bind the same SPD to both
122 self.create_interfaces(2)
123 self.spd_create_and_intf_add(1, self.pg_interfaces)
126 # catch-all inbound BYPASS policy, all interfaces
127 inbound_policy = self.spd_add_rem_policy(
134 policy_type="bypass",
138 # outbound BYPASS policy allowing traffic from pg0->pg1
139 outbound_policy = self.spd_add_rem_policy(
146 policy_type="bypass",
149 # create a packet stream pg0->pg1 + add to pg0
150 packets0 = self.create_stream(self.pg0, self.pg1, pkt_count)
151 self.pg0.add_stream(packets0)
153 # with outbound BYPASS rule allowing pg0->pg1, we expect to see
154 # forwarded packets on pg1
155 self.pg_interfaces[1].enable_capture()
157 cap1 = self.pg1.get_capture()
160 self.logger.debug(ppp("SPD - Got packet:", packet))
162 self.logger.error(ppp("Unexpected or invalid packet:", packet))
164 self.logger.debug("SPD: Num packets: %s", len(cap1.res))
165 # verify captures on pg1
166 self.verify_capture(self.pg0, self.pg1, cap1)
167 # verify policies matched correct number of times
168 self.verify_policy_match(pkt_count, inbound_policy)
169 self.verify_policy_match(pkt_count, outbound_policy)
171 # remove outbound rule
172 self.spd_add_rem_policy(
179 policy_type="bypass",
183 # create another packet stream pg0->pg1 + add to pg0
184 packets1 = self.create_stream(self.pg0, self.pg1, pkt_count)
185 self.pg0.add_stream(packets1)
186 self.pg_interfaces[1].enable_capture()
188 # confirm traffic was dropped and not forwarded
189 self.pg1.assert_nothing_captured(
190 remark="outbound pkts with no matching rules NOT dropped " "by default"
192 # inbound rule should have matched twice the # of pkts now
193 self.verify_policy_match(pkt_count * 2, inbound_policy)
194 # as dropped at outbound, outbound policy is the same
195 self.verify_policy_match(pkt_count, outbound_policy)
198 if __name__ == "__main__":
199 unittest.main(testRunner=VppTestRunner)