~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv6/xfrm6_output.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * xfrm6_output.c - Common IPsec encapsulation code for IPv6.
  4  * Copyright (C) 2002 USAGI/WIDE Project
  5  * Copyright (c) 2004 Herbert Xu <herbert@gondor.apana.org.au>
  6  */
  7 
  8 #include <linux/if_ether.h>
  9 #include <linux/kernel.h>
 10 #include <linux/module.h>
 11 #include <linux/skbuff.h>
 12 #include <linux/icmpv6.h>
 13 #include <linux/netfilter_ipv6.h>
 14 #include <net/dst.h>
 15 #include <net/ipv6.h>
 16 #include <net/ip6_route.h>
 17 #include <net/xfrm.h>
 18 
 19 void xfrm6_local_rxpmtu(struct sk_buff *skb, u32 mtu)
 20 {
 21         struct flowi6 fl6;
 22         struct sock *sk = skb->sk;
 23 
 24         fl6.flowi6_oif = sk->sk_bound_dev_if;
 25         fl6.daddr = ipv6_hdr(skb)->daddr;
 26 
 27         ipv6_local_rxpmtu(sk, &fl6, mtu);
 28 }
 29 
 30 void xfrm6_local_error(struct sk_buff *skb, u32 mtu)
 31 {
 32         struct flowi6 fl6;
 33         const struct ipv6hdr *hdr;
 34         struct sock *sk = skb->sk;
 35 
 36         hdr = skb->encapsulation ? inner_ipv6_hdr(skb) : ipv6_hdr(skb);
 37         fl6.fl6_dport = inet_sk(sk)->inet_dport;
 38         fl6.daddr = hdr->daddr;
 39 
 40         ipv6_local_error(sk, EMSGSIZE, &fl6, mtu);
 41 }
 42 
 43 static int __xfrm6_output_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
 44 {
 45         return xfrm_output(sk, skb);
 46 }
 47 
 48 static int xfrm6_noneed_fragment(struct sk_buff *skb)
 49 {
 50         struct frag_hdr *fh;
 51         u8 prevhdr = ipv6_hdr(skb)->nexthdr;
 52 
 53         if (prevhdr != NEXTHDR_FRAGMENT)
 54                 return 0;
 55         fh = (struct frag_hdr *)(skb->data + sizeof(struct ipv6hdr));
 56         if (fh->nexthdr == NEXTHDR_ESP || fh->nexthdr == NEXTHDR_AUTH)
 57                 return 1;
 58         return 0;
 59 }
 60 
 61 static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
 62 {
 63         struct dst_entry *dst = skb_dst(skb);
 64         struct xfrm_state *x = dst->xfrm;
 65         unsigned int mtu;
 66         bool toobig;
 67 
 68 #ifdef CONFIG_NETFILTER
 69         if (!x) {
 70                 IP6CB(skb)->flags |= IP6SKB_REROUTED;
 71                 return dst_output(net, sk, skb);
 72         }
 73 #endif
 74 
 75         if (x->props.mode != XFRM_MODE_TUNNEL)
 76                 goto skip_frag;
 77 
 78         if (skb->protocol == htons(ETH_P_IPV6))
 79                 mtu = ip6_skb_dst_mtu(skb);
 80         else
 81                 mtu = dst_mtu(skb_dst(skb));
 82 
 83         toobig = skb->len > mtu && !skb_is_gso(skb);
 84 
 85         if (toobig && xfrm6_local_dontfrag(skb->sk)) {
 86                 xfrm6_local_rxpmtu(skb, mtu);
 87                 kfree_skb(skb);
 88                 return -EMSGSIZE;
 89         } else if (toobig && xfrm6_noneed_fragment(skb)) {
 90                 skb->ignore_df = 1;
 91                 goto skip_frag;
 92         } else if (!skb->ignore_df && toobig && skb->sk) {
 93                 xfrm_local_error(skb, mtu);
 94                 kfree_skb(skb);
 95                 return -EMSGSIZE;
 96         }
 97 
 98         if (toobig)
 99                 return ip6_fragment(net, sk, skb,
100                                     __xfrm6_output_finish);
101 
102 skip_frag:
103         return xfrm_output(sk, skb);
104 }
105 
106 int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
107 {
108         return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING,
109                             net, sk, skb,  skb->dev, skb_dst(skb)->dev,
110                             __xfrm6_output,
111                             !(IP6CB(skb)->flags & IP6SKB_REROUTED));
112 }
113 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php