Skip to content

Commit e412944

Browse files
lunndavem330
authored andcommitted
icmp: ICMPV6: Examine invoking packet for Segment Route Headers.
RFC8754 says: ICMP error packets generated within the SR domain are sent to source nodes within the SR domain. The invoking packet in the ICMP error message may contain an SRH. Since the destination address of a packet with an SRH changes as each segment is processed, it may not be the destination used by the socket or application that generated the invoking packet. For the source of an invoking packet to process the ICMP error message, the ultimate destination address of the IPv6 header may be required. The following logic is used to determine the destination address for use by protocol-error handlers. * Walk all extension headers of the invoking IPv6 packet to the routing extension header preceding the upper-layer header. - If routing header is type 4 Segment Routing Header (SRH) o The SID at Segment List[0] may be used as the destination address of the invoking packet. Mangle the skb so the network header points to the invoking packet inside the ICMP packet. The seg6 helpers can then be used on the skb to find any segment routing headers. If found, mark this fact in the IPv6 control block of the skb, and store the offset into the packet of the SRH. Then restore the skb back to its old state. Signed-off-by: Andrew Lunn <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fa55a7d commit e412944

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

include/linux/ipv6.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ struct inet6_skb_parm {
133133
__u16 dsthao;
134134
#endif
135135
__u16 frag_max_size;
136+
__u16 srhoff;
136137

137138
#define IP6SKB_XFRM_TRANSFORMED 1
138139
#define IP6SKB_FORWARDED 2
@@ -142,6 +143,7 @@ struct inet6_skb_parm {
142143
#define IP6SKB_HOPBYHOP 32
143144
#define IP6SKB_L3SLAVE 64
144145
#define IP6SKB_JUMBOGRAM 128
146+
#define IP6SKB_SEG6 256
145147
};
146148

147149
#if defined(CONFIG_NET_L3_MASTER_DEV)

include/net/seg6.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern void seg6_local_exit(void);
5959

6060
extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced);
6161
extern struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags);
62+
extern void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt);
6263
extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh,
6364
int proto);
6465
extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);

net/ipv6/icmp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <net/protocol.h>
5858
#include <net/raw.h>
5959
#include <net/rawv6.h>
60+
#include <net/seg6.h>
6061
#include <net/transp_v6.h>
6162
#include <net/ip6_route.h>
6263
#include <net/addrconf.h>
@@ -820,6 +821,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
820821

821822
void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
822823
{
824+
struct inet6_skb_parm *opt = IP6CB(skb);
823825
const struct inet6_protocol *ipprot;
824826
int inner_offset;
825827
__be16 frag_off;
@@ -829,6 +831,8 @@ void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
829831
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
830832
goto out;
831833

834+
seg6_icmp_srh(skb, opt);
835+
832836
nexthdr = ((struct ipv6hdr *)skb->data)->nexthdr;
833837
if (ipv6_ext_hdr(nexthdr)) {
834838
/* now skip over extension headers */
@@ -853,7 +857,7 @@ void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
853857

854858
ipprot = rcu_dereference(inet6_protos[nexthdr]);
855859
if (ipprot && ipprot->err_handler)
856-
ipprot->err_handler(skb, NULL, type, code, inner_offset, info);
860+
ipprot->err_handler(skb, opt, type, code, inner_offset, info);
857861

858862
raw6_icmp_error(skb, nexthdr, type, code, inner_offset, info);
859863
return;

net/ipv6/seg6.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,36 @@ struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags)
104104
return srh;
105105
}
106106

107+
/* Determine if an ICMP invoking packet contains a segment routing
108+
* header. If it does, extract the offset to the true destination
109+
* address, which is in the first segment address.
110+
*/
111+
void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt)
112+
{
113+
__u16 network_header = skb->network_header;
114+
struct ipv6_sr_hdr *srh;
115+
116+
/* Update network header to point to the invoking packet
117+
* inside the ICMP packet, so we can use the seg6_get_srh()
118+
* helper.
119+
*/
120+
skb_reset_network_header(skb);
121+
122+
srh = seg6_get_srh(skb, 0);
123+
if (!srh)
124+
goto out;
125+
126+
if (srh->type != IPV6_SRCRT_TYPE_4)
127+
goto out;
128+
129+
opt->flags |= IP6SKB_SEG6;
130+
opt->srhoff = (unsigned char *)srh - skb->data;
131+
132+
out:
133+
/* Restore the network header back to the ICMP packet */
134+
skb->network_header = network_header;
135+
}
136+
107137
static struct genl_family seg6_genl_family;
108138

109139
static const struct nla_policy seg6_genl_policy[SEG6_ATTR_MAX + 1] = {

0 commit comments

Comments
 (0)