Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

udp6: Use Segment Routing Header for dest address if present

When finding the socket to report an error on, if the invoking packet
is using Segment Routing, the IPv6 destination address is that of an
intermediate router, not the end destination. Extract the ultimate
destination address from the segment address.

This change allows traceroute to function in the presence of Segment
Routing.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Andrew Lunn and committed by
David S. Miller
222a011e e4129440

+21 -1
+19
include/net/seg6.h
··· 65 65 extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh); 66 66 extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr, 67 67 u32 tbl_id); 68 + 69 + /* If the packet which invoked an ICMP error contains an SRH return 70 + * the true destination address from within the SRH, otherwise use the 71 + * destination address in the IP header. 72 + */ 73 + static inline const struct in6_addr *seg6_get_daddr(struct sk_buff *skb, 74 + struct inet6_skb_parm *opt) 75 + { 76 + struct ipv6_sr_hdr *srh; 77 + 78 + if (opt->flags & IP6SKB_SEG6) { 79 + srh = (struct ipv6_sr_hdr *)(skb->data + opt->srhoff); 80 + return &srh->segments[0]; 81 + } 82 + 83 + return NULL; 84 + } 85 + 86 + 68 87 #endif
+2 -1
net/ipv6/udp.c
··· 40 40 #include <net/transp_v6.h> 41 41 #include <net/ip6_route.h> 42 42 #include <net/raw.h> 43 + #include <net/seg6.h> 43 44 #include <net/tcp_states.h> 44 45 #include <net/ip6_checksum.h> 45 46 #include <net/ip6_tunnel.h> ··· 562 561 struct ipv6_pinfo *np; 563 562 const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data; 564 563 const struct in6_addr *saddr = &hdr->saddr; 565 - const struct in6_addr *daddr = &hdr->daddr; 564 + const struct in6_addr *daddr = seg6_get_daddr(skb, opt) ? : &hdr->daddr; 566 565 struct udphdr *uh = (struct udphdr *)(skb->data+offset); 567 566 bool tunnel = false; 568 567 struct sock *sk;