From be2286b0a4ff0cd31791b86d38a5e72b06bc17c2 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Sun, 9 Dec 2018 12:54:51 -0800 Subject: [PATCH] IP-local: any IP can appear as the source (VPP-1522) Change-Id: Ib0d9b533d72c899b77c9a7bd1daa9b4a55b7221c Signed-off-by: Neale Ranns --- src/vnet/ip/ip4_forward.c | 18 +++++++++++++++--- test/test_ip4.py | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/vnet/ip/ip4_forward.c b/src/vnet/ip/ip4_forward.c index 1911f088008..1ca4f9309e6 100644 --- a/src/vnet/ip/ip4_forward.c +++ b/src/vnet/ip/ip4_forward.c @@ -1334,6 +1334,7 @@ typedef struct ip4_address_t src; u32 lbi; u8 error; + u8 first; } ip4_local_last_check_t; static inline void @@ -1350,7 +1351,8 @@ ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0, vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0 ? vnet_buffer (b)->sw_if_index[VLIB_TX] : vnet_buffer (b)->ip.fib_index; - if (PREDICT_FALSE (last_check->src.as_u32 != ip0->src_address.as_u32)) + if (PREDICT_FALSE (last_check->first || + (last_check->src.as_u32 != ip0->src_address.as_u32))) { mtrie0 = &ip4_fib_get (vnet_buffer (b)->ip.fib_index)->mtrie; leaf0 = ip4_fib_mtrie_lookup_step_one (mtrie0, &ip0->src_address); @@ -1392,6 +1394,7 @@ ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0, vnet_buffer (b)->ip.adj_index[VLIB_TX] = last_check->lbi; vnet_buffer (b)->ip.adj_index[VLIB_RX] = last_check->lbi; *error0 = last_check->error; + last_check->first = 0; } } @@ -1403,9 +1406,10 @@ ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip, ip4_fib_mtrie_t *mtrie[2]; const dpo_id_t *dpo[2]; load_balance_t *lb[2]; - u32 not_last_hit = 0; + u32 not_last_hit; u32 lbi[2]; + not_last_hit = last_check->first; not_last_hit |= ip[0]->src_address.as_u32 ^ last_check->src.as_u32; not_last_hit |= ip[1]->src_address.as_u32 ^ last_check->src.as_u32; @@ -1482,6 +1486,7 @@ ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip, error[0] = last_check->error; error[1] = last_check->error; + last_check->first = 0; } } @@ -1532,9 +1537,16 @@ ip4_local_inline (vlib_main_t * vm, u8 error[2], pt[2]; ip4_local_last_check_t last_check = { + /* + * 0.0.0.0 can appear as the source address of an IP packet, + * as can any other address, hence the need to use the 'first' + * member to make sure the .lbi is initialised for the first + * packet. + */ .src = {.as_u32 = 0}, .lbi = ~0, - .error = IP4_ERROR_UNKNOWN_PROTOCOL + .error = IP4_ERROR_UNKNOWN_PROTOCOL, + .first = 1, }; from = vlib_frame_vector_args (frame); diff --git a/test/test_ip4.py b/test/test_ip4.py index c13024115e0..54090445dac 100644 --- a/test/test_ip4.py +++ b/test/test_ip4.py @@ -1470,6 +1470,25 @@ class TestIPInput(VppTestCase): # Reset MTU for subsequent tests self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [9000, 0, 0, 0]) + # + # source address 0.0.0.0 and 25.255.255.255 and for-us + # + p_s0 = (Ether(src=self.pg0.remote_mac, + dst=self.pg0.local_mac) / + IP(src="0.0.0.0", + dst=self.pg0.local_ip4) / + ICMP(id=4, seq=4) / + Raw(load='\x0a' * 18)) + rx = self.send_and_assert_no_replies(self.pg0, p_s0 * 17) + + p_s0 = (Ether(src=self.pg0.remote_mac, + dst=self.pg0.local_mac) / + IP(src="255.255.255.255", + dst=self.pg0.local_ip4) / + ICMP(id=4, seq=4) / + Raw(load='\x0a' * 18)) + rx = self.send_and_assert_no_replies(self.pg0, p_s0 * 17) + class TestIPDirectedBroadcast(VppTestCase): """ IPv4 Directed Broadcast """ -- 2.16.6