From 8034a36a9cedc95f6762bf0a07f6617d0bf69bfe Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Wed, 11 Aug 2021 13:54:14 +0200 Subject: ip: source address selection Implement a simple source address selection algorithm for IPv4 and IPv6. IPv6 does not yet implement RFC6724 but supports link-locals. ping now chooses correct source address for link-local destination. Added ping support for link-local multicast (e.g. allnodes). Type: feature Signed-off-by: Ole Troan Change-Id: I1a3382c1f7d4ace0386c2c19e4e47b045b73a3ed Signed-off-by: Ole Troan --- src/vnet/ip/icmp6.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/vnet/ip/icmp6.c') diff --git a/src/vnet/ip/icmp6.c b/src/vnet/ip/icmp6.c index 4bba430fadc..b6ed3ea0ec9 100644 --- a/src/vnet/ip/icmp6.c +++ b/src/vnet/ip/icmp6.c @@ -40,6 +40,7 @@ #include #include #include +#include static u8 * format_ip6_icmp_type_and_code (u8 * s, va_list * args) @@ -475,8 +476,6 @@ ip6_icmp_error (vlib_main_t * vm, u32 *from, *to_next; uword n_left_from, n_left_to_next; ip6_icmp_error_next_t next_index; - ip6_main_t *im = &ip6_main; - ip_lookup_main_t *lm = &im->lookup_main; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; @@ -507,7 +506,7 @@ ip6_icmp_error (vlib_main_t * vm, vlib_buffer_t *p0, *org_p0; ip6_header_t *ip0, *out_ip0; icmp46_header_t *icmp0; - u32 sw_if_index0, if_add_index0; + u32 sw_if_index0; int bogus_length; org_p0 = vlib_get_buffer (vm, org_pi0); @@ -547,18 +546,10 @@ ip6_icmp_error (vlib_main_t * vm, out_ip0->protocol = IP_PROTOCOL_ICMP6; out_ip0->hop_limit = 0xff; out_ip0->dst_address = ip0->src_address; - if_add_index0 = - lm->if_address_pool_index_by_sw_if_index[sw_if_index0]; - if (PREDICT_TRUE (if_add_index0 != ~0)) - { - ip_interface_address_t *if_add = - pool_elt_at_index (lm->if_address_pool, if_add_index0); - ip6_address_t *if_ip = - ip_interface_address_get_address (lm, if_add); - out_ip0->src_address = *if_ip; - } - else /* interface has no IP6 address - should not happen */ - { + /* Prefer a source address from "offending interface" */ + if (!ip6_sas_by_sw_if_index (sw_if_index0, &out_ip0->dst_address, + &out_ip0->src_address)) + { /* interface has no IP6 address - should not happen */ next0 = IP6_ICMP_ERROR_NEXT_DROP; error0 = ICMP6_ERROR_DROP; } -- cgit 1.2.3-korg