LCOV - code coverage report
Current view: top level - net/ipv6 - xfrm6_mode_beet.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 43 0.0 %
Date: 2014-04-07 Functions: 0 5 0.0 %
Branches: 0 18 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * xfrm6_mode_beet.c - BEET mode encapsulation for IPv6.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com>
       5                 :            :  *                    Miika Komu     <miika@iki.fi>
       6                 :            :  *                    Herbert Xu     <herbert@gondor.apana.org.au>
       7                 :            :  *                    Abhinav Pathak <abhinav.pathak@hiit.fi>
       8                 :            :  *                    Jeff Ahrenholz <ahrenholz@gmail.com>
       9                 :            :  */
      10                 :            : 
      11                 :            : #include <linux/init.h>
      12                 :            : #include <linux/kernel.h>
      13                 :            : #include <linux/module.h>
      14                 :            : #include <linux/skbuff.h>
      15                 :            : #include <linux/stringify.h>
      16                 :            : #include <net/dsfield.h>
      17                 :            : #include <net/dst.h>
      18                 :            : #include <net/inet_ecn.h>
      19                 :            : #include <net/ipv6.h>
      20                 :            : #include <net/xfrm.h>
      21                 :            : 
      22                 :          0 : static void xfrm6_beet_make_header(struct sk_buff *skb)
      23                 :            : {
      24                 :            :         struct ipv6hdr *iph = ipv6_hdr(skb);
      25                 :            : 
      26                 :          0 :         iph->version = 6;
      27                 :            : 
      28                 :          0 :         memcpy(iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
      29                 :            :                sizeof(iph->flow_lbl));
      30                 :          0 :         iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol;
      31                 :            : 
      32                 :          0 :         ipv6_change_dsfield(iph, 0, XFRM_MODE_SKB_CB(skb)->tos);
      33                 :          0 :         iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl;
      34                 :          0 : }
      35                 :            : 
      36                 :            : /* Add encapsulation header.
      37                 :            :  *
      38                 :            :  * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
      39                 :            :  */
      40                 :          0 : static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
      41                 :            : {
      42                 :            :         struct ipv6hdr *top_iph;
      43                 :            :         struct ip_beet_phdr *ph;
      44                 :            :         int optlen, hdr_len;
      45                 :            : 
      46                 :            :         hdr_len = 0;
      47                 :          0 :         optlen = XFRM_MODE_SKB_CB(skb)->optlen;
      48         [ #  # ]:          0 :         if (unlikely(optlen))
      49                 :          0 :                 hdr_len += IPV4_BEET_PHMAXLEN - (optlen & 4);
      50                 :            : 
      51                 :          0 :         skb_set_network_header(skb, -x->props.header_len - hdr_len);
      52         [ #  # ]:          0 :         if (x->sel.family != AF_INET6)
      53                 :          0 :                 skb->network_header += IPV4_BEET_PHMAXLEN;
      54                 :          0 :         skb->mac_header = skb->network_header +
      55                 :            :                           offsetof(struct ipv6hdr, nexthdr);
      56                 :          0 :         skb->transport_header = skb->network_header + sizeof(*top_iph);
      57                 :          0 :         ph = (struct ip_beet_phdr *)__skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl-hdr_len);
      58                 :            : 
      59                 :          0 :         xfrm6_beet_make_header(skb);
      60                 :            : 
      61                 :            :         top_iph = ipv6_hdr(skb);
      62         [ #  # ]:          0 :         if (unlikely(optlen)) {
      63                 :            : 
      64         [ #  # ]:          0 :                 BUG_ON(optlen < 0);
      65                 :            : 
      66                 :          0 :                 ph->padlen = 4 - (optlen & 4);
      67                 :          0 :                 ph->hdrlen = optlen / 8;
      68                 :          0 :                 ph->nexthdr = top_iph->nexthdr;
      69         [ #  # ]:          0 :                 if (ph->padlen)
      70         [ #  # ]:          0 :                         memset(ph + 1, IPOPT_NOP, ph->padlen);
      71                 :            : 
      72                 :          0 :                 top_iph->nexthdr = IPPROTO_BEETPH;
      73                 :            :         }
      74                 :            : 
      75                 :          0 :         top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
      76                 :          0 :         top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
      77                 :          0 :         return 0;
      78                 :            : }
      79                 :            : 
      80                 :          0 : static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb)
      81                 :            : {
      82                 :            :         struct ipv6hdr *ip6h;
      83                 :            :         int size = sizeof(struct ipv6hdr);
      84                 :            :         int err;
      85                 :            : 
      86                 :          0 :         err = skb_cow_head(skb, size + skb->mac_len);
      87         [ #  # ]:          0 :         if (err)
      88                 :            :                 goto out;
      89                 :            : 
      90                 :            :         __skb_push(skb, size);
      91                 :            :         skb_reset_network_header(skb);
      92                 :            :         skb_mac_header_rebuild(skb);
      93                 :            : 
      94                 :          0 :         xfrm6_beet_make_header(skb);
      95                 :            : 
      96                 :            :         ip6h = ipv6_hdr(skb);
      97         [ #  # ]:          0 :         ip6h->payload_len = htons(skb->len - size);
      98                 :          0 :         ip6h->daddr = *(struct in6_addr *)&x->sel.daddr.a6;
      99                 :          0 :         ip6h->saddr = *(struct in6_addr *)&x->sel.saddr.a6;
     100                 :            :         err = 0;
     101                 :            : out:
     102                 :          0 :         return err;
     103                 :            : }
     104                 :            : 
     105                 :            : static struct xfrm_mode xfrm6_beet_mode = {
     106                 :            :         .input2 = xfrm6_beet_input,
     107                 :            :         .input = xfrm_prepare_input,
     108                 :            :         .output2 = xfrm6_beet_output,
     109                 :            :         .output = xfrm6_prepare_output,
     110                 :            :         .owner = THIS_MODULE,
     111                 :            :         .encap = XFRM_MODE_BEET,
     112                 :            :         .flags = XFRM_MODE_FLAG_TUNNEL,
     113                 :            : };
     114                 :            : 
     115                 :          0 : static int __init xfrm6_beet_init(void)
     116                 :            : {
     117                 :          0 :         return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6);
     118                 :            : }
     119                 :            : 
     120                 :          0 : static void __exit xfrm6_beet_exit(void)
     121                 :            : {
     122                 :            :         int err;
     123                 :            : 
     124                 :          0 :         err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6);
     125         [ #  # ]:          0 :         BUG_ON(err);
     126                 :          0 : }
     127                 :            : 
     128                 :            : module_init(xfrm6_beet_init);
     129                 :            : module_exit(xfrm6_beet_exit);
     130                 :            : MODULE_LICENSE("GPL");
     131                 :            : MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_BEET);

Generated by: LCOV version 1.9