LCOV - code coverage report
Current view: top level - net/ipv6 - xfrm6_output.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 0 79 0.0 %
Date: 2020-09-30 20:25:40 Functions: 0 11 0.0 %
Branches: 0 52 0.0 %

           Branch data     Line data    Source code
       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                 :          0 : int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
      20                 :            :                           u8 **prevhdr)
      21                 :            : {
      22                 :          0 :         return ip6_find_1stfragopt(skb, prevhdr);
      23                 :            : }
      24                 :            : EXPORT_SYMBOL(xfrm6_find_1stfragopt);
      25                 :            : 
      26                 :          0 : static int xfrm6_local_dontfrag(struct sk_buff *skb)
      27                 :            : {
      28                 :            :         int proto;
      29                 :          0 :         struct sock *sk = skb->sk;
      30                 :            : 
      31         [ #  # ]:          0 :         if (sk) {
      32         [ #  # ]:          0 :                 if (sk->sk_family != AF_INET6)
      33                 :            :                         return 0;
      34                 :            : 
      35                 :          0 :                 proto = sk->sk_protocol;
      36         [ #  # ]:          0 :                 if (proto == IPPROTO_UDP || proto == IPPROTO_RAW)
      37                 :          0 :                         return inet6_sk(sk)->dontfrag;
      38                 :            :         }
      39                 :            : 
      40                 :            :         return 0;
      41                 :            : }
      42                 :            : 
      43                 :          0 : static void xfrm6_local_rxpmtu(struct sk_buff *skb, u32 mtu)
      44                 :            : {
      45                 :            :         struct flowi6 fl6;
      46                 :          0 :         struct sock *sk = skb->sk;
      47                 :            : 
      48                 :          0 :         fl6.flowi6_oif = sk->sk_bound_dev_if;
      49                 :          0 :         fl6.daddr = ipv6_hdr(skb)->daddr;
      50                 :            : 
      51                 :          0 :         ipv6_local_rxpmtu(sk, &fl6, mtu);
      52                 :          0 : }
      53                 :            : 
      54                 :          0 : void xfrm6_local_error(struct sk_buff *skb, u32 mtu)
      55                 :            : {
      56                 :            :         struct flowi6 fl6;
      57                 :            :         const struct ipv6hdr *hdr;
      58                 :          0 :         struct sock *sk = skb->sk;
      59                 :            : 
      60         [ #  # ]:          0 :         hdr = skb->encapsulation ? inner_ipv6_hdr(skb) : ipv6_hdr(skb);
      61                 :          0 :         fl6.fl6_dport = inet_sk(sk)->inet_dport;
      62                 :          0 :         fl6.daddr = hdr->daddr;
      63                 :            : 
      64                 :          0 :         ipv6_local_error(sk, EMSGSIZE, &fl6, mtu);
      65                 :          0 : }
      66                 :            : 
      67                 :          0 : static int xfrm6_tunnel_check_size(struct sk_buff *skb)
      68                 :            : {
      69                 :            :         int mtu, ret = 0;
      70                 :            :         struct dst_entry *dst = skb_dst(skb);
      71                 :            : 
      72         [ #  # ]:          0 :         if (skb->ignore_df)
      73                 :            :                 goto out;
      74                 :            : 
      75                 :          0 :         mtu = dst_mtu(dst);
      76         [ #  # ]:          0 :         if (mtu < IPV6_MIN_MTU)
      77                 :            :                 mtu = IPV6_MIN_MTU;
      78                 :            : 
      79   [ #  #  #  #  :          0 :         if ((!skb_is_gso(skb) && skb->len > mtu) ||
                   #  # ]
      80         [ #  # ]:          0 :             (skb_is_gso(skb) &&
      81                 :          0 :              !skb_gso_validate_network_len(skb, ip6_skb_dst_mtu(skb)))) {
      82                 :          0 :                 skb->dev = dst->dev;
      83                 :          0 :                 skb->protocol = htons(ETH_P_IPV6);
      84                 :            : 
      85         [ #  # ]:          0 :                 if (xfrm6_local_dontfrag(skb))
      86                 :          0 :                         xfrm6_local_rxpmtu(skb, mtu);
      87         [ #  # ]:          0 :                 else if (skb->sk)
      88                 :          0 :                         xfrm_local_error(skb, mtu);
      89                 :            :                 else
      90                 :          0 :                         icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
      91                 :            :                 ret = -EMSGSIZE;
      92                 :            :         }
      93                 :            : out:
      94                 :          0 :         return ret;
      95                 :            : }
      96                 :            : 
      97                 :          0 : int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb)
      98                 :            : {
      99                 :            :         int err;
     100                 :            : 
     101                 :          0 :         err = xfrm6_tunnel_check_size(skb);
     102         [ #  # ]:          0 :         if (err)
     103                 :            :                 return err;
     104                 :            : 
     105                 :          0 :         XFRM_MODE_SKB_CB(skb)->protocol = ipv6_hdr(skb)->nexthdr;
     106                 :            : 
     107                 :          0 :         return xfrm6_extract_header(skb);
     108                 :            : }
     109                 :            : 
     110                 :          0 : int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb)
     111                 :            : {
     112                 :          0 :         memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
     113                 :            : 
     114                 :          0 :         IP6CB(skb)->flags |= IP6SKB_XFRM_TRANSFORMED;
     115                 :            : 
     116                 :          0 :         return xfrm_output(sk, skb);
     117                 :            : }
     118                 :            : 
     119                 :          0 : static int __xfrm6_output_state_finish(struct xfrm_state *x, struct sock *sk,
     120                 :            :                                        struct sk_buff *skb)
     121                 :            : {
     122                 :            :         const struct xfrm_state_afinfo *afinfo;
     123                 :            :         int ret = -EAFNOSUPPORT;
     124                 :            : 
     125                 :            :         rcu_read_lock();
     126                 :          0 :         afinfo = xfrm_state_afinfo_get_rcu(x->outer_mode.family);
     127         [ #  # ]:          0 :         if (likely(afinfo))
     128                 :          0 :                 ret = afinfo->output_finish(sk, skb);
     129                 :            :         else
     130                 :          0 :                 kfree_skb(skb);
     131                 :            :         rcu_read_unlock();
     132                 :            : 
     133                 :          0 :         return ret;
     134                 :            : }
     135                 :            : 
     136                 :          0 : static int __xfrm6_output_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
     137                 :            : {
     138                 :          0 :         struct xfrm_state *x = skb_dst(skb)->xfrm;
     139                 :            : 
     140                 :          0 :         return __xfrm6_output_state_finish(x, sk, skb);
     141                 :            : }
     142                 :            : 
     143                 :          0 : static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
     144                 :            : {
     145                 :            :         struct dst_entry *dst = skb_dst(skb);
     146                 :          0 :         struct xfrm_state *x = dst->xfrm;
     147                 :            :         int mtu;
     148                 :            :         bool toobig;
     149                 :            : 
     150                 :            : #ifdef CONFIG_NETFILTER
     151         [ #  # ]:          0 :         if (!x) {
     152                 :          0 :                 IP6CB(skb)->flags |= IP6SKB_REROUTED;
     153                 :          0 :                 return dst_output(net, sk, skb);
     154                 :            :         }
     155                 :            : #endif
     156                 :            : 
     157         [ #  # ]:          0 :         if (x->props.mode != XFRM_MODE_TUNNEL)
     158                 :            :                 goto skip_frag;
     159                 :            : 
     160         [ #  # ]:          0 :         if (skb->protocol == htons(ETH_P_IPV6))
     161                 :          0 :                 mtu = ip6_skb_dst_mtu(skb);
     162                 :            :         else
     163                 :          0 :                 mtu = dst_mtu(skb_dst(skb));
     164                 :            : 
     165   [ #  #  #  # ]:          0 :         toobig = skb->len > mtu && !skb_is_gso(skb);
     166                 :            : 
     167   [ #  #  #  # ]:          0 :         if (toobig && xfrm6_local_dontfrag(skb)) {
     168                 :          0 :                 xfrm6_local_rxpmtu(skb, mtu);
     169                 :          0 :                 kfree_skb(skb);
     170                 :          0 :                 return -EMSGSIZE;
     171   [ #  #  #  #  :          0 :         } else if (!skb->ignore_df && toobig && skb->sk) {
                   #  # ]
     172                 :          0 :                 xfrm_local_error(skb, mtu);
     173                 :          0 :                 kfree_skb(skb);
     174                 :          0 :                 return -EMSGSIZE;
     175                 :            :         }
     176                 :            : 
     177   [ #  #  #  # ]:          0 :         if (toobig || dst_allfrag(skb_dst(skb)))
     178                 :          0 :                 return ip6_fragment(net, sk, skb,
     179                 :            :                                     __xfrm6_output_finish);
     180                 :            : 
     181                 :            : skip_frag:
     182                 :          0 :         return __xfrm6_output_state_finish(x, sk, skb);
     183                 :            : }
     184                 :            : 
     185                 :          0 : int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
     186                 :            : {
     187                 :          0 :         return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING,
     188                 :            :                             net, sk, skb,  NULL, skb_dst(skb)->dev,
     189                 :            :                             __xfrm6_output,
     190                 :          0 :                             !(IP6CB(skb)->flags & IP6SKB_REROUTED));
     191                 :            : }

Generated by: LCOV version 1.14