seg6: add support for IPv4 decapsulation in ipv6_srh_rcv()
authorJulien Massonneau <julien.massonneau@6wind.com>
Thu, 11 Mar 2021 15:53:18 +0000 (16:53 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 12 Mar 2021 00:09:21 +0000 (16:09 -0800)
As specified in IETF RFC 8754, section 4.3.1.2, if the upper layer
header is IPv4 or IPv6, perform IPv6 decapsulation and resubmit the
decapsulated packet to the IPv4 or IPv6 module.
Only IPv6 decapsulation was implemented. This patch adds support for IPv4
decapsulation.

Link: https://tools.ietf.org/html/rfc8754#section-4.3.1.2
Signed-off-by: Julien Massonneau <julien.massonneau@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ipv6.h
net/ipv6/exthdrs.c

index bd1f396cc9c729d734fbf9132335266dfddec5f9..448bf2b34759e9642a7caa70d55e78e67e515b15 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #define NEXTHDR_HOP            0       /* Hop-by-hop option header. */
+#define NEXTHDR_IPV4           4       /* IPv4 in IPv6 */
 #define NEXTHDR_TCP            6       /* TCP segment. */
 #define NEXTHDR_UDP            17      /* UDP message. */
 #define NEXTHDR_IPV6           41      /* IPv6 in IPv6 */
index 6126f8bf94b3992f75648adbcf37c7cdbd2425be..56e479d158b7c069000f77db88f468d9414ff7e5 100644 (file)
@@ -381,7 +381,7 @@ static int ipv6_srh_rcv(struct sk_buff *skb)
 
 looped_back:
        if (hdr->segments_left == 0) {
-               if (hdr->nexthdr == NEXTHDR_IPV6) {
+               if (hdr->nexthdr == NEXTHDR_IPV6 || hdr->nexthdr == NEXTHDR_IPV4) {
                        int offset = (hdr->hdrlen + 1) << 3;
 
                        skb_postpull_rcsum(skb, skb_network_header(skb),
@@ -397,7 +397,8 @@ looped_back:
                        skb_reset_network_header(skb);
                        skb_reset_transport_header(skb);
                        skb->encapsulation = 0;
-
+                       if (hdr->nexthdr == NEXTHDR_IPV4)
+                               skb->protocol = htons(ETH_P_IP);
                        __skb_tunnel_rx(skb, skb->dev, net);
 
                        netif_rx(skb);