LCOV - code coverage report
Current view: top level - net/ipv4 - ip_tunnel_core.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 71 33.8 %
Date: 2014-04-16 Functions: 1 4 25.0 %
Branches: 3 32 9.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2013 Nicira, Inc.
       3                 :            :  *
       4                 :            :  * This program is free software; you can redistribute it and/or
       5                 :            :  * modify it under the terms of version 2 of the GNU General Public
       6                 :            :  * License as published by the Free Software Foundation.
       7                 :            :  *
       8                 :            :  * This program is distributed in the hope that it will be useful, but
       9                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      10                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      11                 :            :  * General Public License for more details.
      12                 :            :  *
      13                 :            :  * You should have received a copy of the GNU General Public License
      14                 :            :  * along with this program; if not, write to the Free Software
      15                 :            :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
      16                 :            :  * 02110-1301, USA
      17                 :            :  */
      18                 :            : 
      19                 :            : #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
      20                 :            : 
      21                 :            : #include <linux/types.h>
      22                 :            : #include <linux/kernel.h>
      23                 :            : #include <linux/skbuff.h>
      24                 :            : #include <linux/netdevice.h>
      25                 :            : #include <linux/in.h>
      26                 :            : #include <linux/if_arp.h>
      27                 :            : #include <linux/mroute.h>
      28                 :            : #include <linux/init.h>
      29                 :            : #include <linux/in6.h>
      30                 :            : #include <linux/inetdevice.h>
      31                 :            : #include <linux/netfilter_ipv4.h>
      32                 :            : #include <linux/etherdevice.h>
      33                 :            : #include <linux/if_ether.h>
      34                 :            : #include <linux/if_vlan.h>
      35                 :            : 
      36                 :            : #include <net/ip.h>
      37                 :            : #include <net/icmp.h>
      38                 :            : #include <net/protocol.h>
      39                 :            : #include <net/ip_tunnels.h>
      40                 :            : #include <net/arp.h>
      41                 :            : #include <net/checksum.h>
      42                 :            : #include <net/dsfield.h>
      43                 :            : #include <net/inet_ecn.h>
      44                 :            : #include <net/xfrm.h>
      45                 :            : #include <net/net_namespace.h>
      46                 :            : #include <net/netns/generic.h>
      47                 :            : #include <net/rtnetlink.h>
      48                 :            : 
      49                 :          0 : int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb,
      50                 :            :                   __be32 src, __be32 dst, __u8 proto,
      51                 :            :                   __u8 tos, __u8 ttl, __be16 df, bool xnet)
      52                 :            : {
      53                 :          0 :         int pkt_len = skb->len;
      54                 :            :         struct iphdr *iph;
      55                 :            :         int err;
      56                 :            : 
      57                 :          0 :         skb_scrub_packet(skb, xnet);
      58                 :            : 
      59                 :            :         skb_clear_hash(skb);
      60                 :          0 :         skb_dst_set(skb, &rt->dst);
      61                 :          0 :         memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
      62                 :            : 
      63                 :            :         /* Push down and install the IP header. */
      64                 :          0 :         skb_push(skb, sizeof(struct iphdr));
      65                 :            :         skb_reset_network_header(skb);
      66                 :            : 
      67                 :            :         iph = ip_hdr(skb);
      68                 :            : 
      69                 :          0 :         iph->version =       4;
      70                 :          0 :         iph->ihl     =       sizeof(struct iphdr) >> 2;
      71                 :          0 :         iph->frag_off        =       df;
      72                 :          0 :         iph->protocol        =       proto;
      73                 :          0 :         iph->tos     =       tos;
      74                 :          0 :         iph->daddr   =       dst;
      75                 :          0 :         iph->saddr   =       src;
      76                 :          0 :         iph->ttl     =       ttl;
      77         [ #  # ]:          0 :         __ip_select_ident(iph, &rt->dst, (skb_shinfo(skb)->gso_segs ?: 1) - 1);
      78                 :            : 
      79                 :          0 :         err = ip_local_out(skb);
      80         [ #  # ]:          0 :         if (unlikely(net_xmit_eval(err)))
      81                 :            :                 pkt_len = 0;
      82                 :          0 :         return pkt_len;
      83                 :            : }
      84                 :            : EXPORT_SYMBOL_GPL(iptunnel_xmit);
      85                 :            : 
      86                 :          0 : int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)
      87                 :            : {
      88         [ #  # ]:          0 :         if (unlikely(!pskb_may_pull(skb, hdr_len)))
      89                 :            :                 return -ENOMEM;
      90                 :            : 
      91                 :          0 :         skb_pull_rcsum(skb, hdr_len);
      92                 :            : 
      93         [ #  # ]:          0 :         if (inner_proto == htons(ETH_P_TEB)) {
      94                 :          0 :                 struct ethhdr *eh = (struct ethhdr *)skb->data;
      95                 :            : 
      96         [ #  # ]:          0 :                 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
      97                 :            :                         return -ENOMEM;
      98                 :            : 
      99 [ #  # ][ #  # ]:          0 :                 if (likely(ntohs(eh->h_proto) >= ETH_P_802_3_MIN))
     100                 :          0 :                         skb->protocol = eh->h_proto;
     101                 :            :                 else
     102                 :          0 :                         skb->protocol = htons(ETH_P_802_2);
     103                 :            : 
     104                 :            :         } else {
     105                 :          0 :                 skb->protocol = inner_proto;
     106                 :            :         }
     107                 :            : 
     108                 :            :         nf_reset(skb);
     109                 :            :         secpath_reset(skb);
     110                 :            :         skb_clear_hash_if_not_l4(skb);
     111                 :            :         skb_dst_drop(skb);
     112                 :          0 :         skb->vlan_tci = 0;
     113                 :            :         skb_set_queue_mapping(skb, 0);
     114                 :          0 :         skb->pkt_type = PACKET_HOST;
     115                 :          0 :         return 0;
     116                 :            : }
     117                 :            : EXPORT_SYMBOL_GPL(iptunnel_pull_header);
     118                 :            : 
     119                 :          0 : struct sk_buff *iptunnel_handle_offloads(struct sk_buff *skb,
     120                 :            :                                          bool csum_help,
     121                 :            :                                          int gso_type_mask)
     122                 :            : {
     123                 :            :         int err;
     124                 :            : 
     125         [ #  # ]:          0 :         if (likely(!skb->encapsulation)) {
     126                 :            :                 skb_reset_inner_headers(skb);
     127                 :          0 :                 skb->encapsulation = 1;
     128                 :            :         }
     129                 :            : 
     130         [ #  # ]:          0 :         if (skb_is_gso(skb)) {
     131                 :            :                 err = skb_unclone(skb, GFP_ATOMIC);
     132         [ #  # ]:          0 :                 if (unlikely(err))
     133                 :            :                         goto error;
     134                 :          0 :                 skb_shinfo(skb)->gso_type |= gso_type_mask;
     135                 :          0 :                 return skb;
     136                 :            :         }
     137                 :            : 
     138 [ #  # ][ #  # ]:          0 :         if (skb->ip_summed == CHECKSUM_PARTIAL && csum_help) {
     139                 :          0 :                 err = skb_checksum_help(skb);
     140         [ #  # ]:          0 :                 if (unlikely(err))
     141                 :            :                         goto error;
     142         [ #  # ]:          0 :         } else if (skb->ip_summed != CHECKSUM_PARTIAL)
     143                 :          0 :                 skb->ip_summed = CHECKSUM_NONE;
     144                 :            : 
     145                 :          0 :         return skb;
     146                 :            : error:
     147                 :          0 :         kfree_skb(skb);
     148                 :          0 :         return ERR_PTR(err);
     149                 :            : }
     150                 :            : EXPORT_SYMBOL_GPL(iptunnel_handle_offloads);
     151                 :            : 
     152                 :            : /* Often modified stats are per cpu, other are shared (netdev->stats) */
     153                 :          0 : struct rtnl_link_stats64 *ip_tunnel_get_stats64(struct net_device *dev,
     154                 :            :                                                 struct rtnl_link_stats64 *tot)
     155                 :            : {
     156                 :            :         int i;
     157                 :            : 
     158         [ +  + ]:       3892 :         for_each_possible_cpu(i) {
     159                 :            :                 const struct pcpu_sw_netstats *tstats =
     160                 :       3336 :                                                    per_cpu_ptr(dev->tstats, i);
     161                 :            :                 u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
     162                 :            :                 unsigned int start;
     163                 :            : 
     164                 :            :                 do {
     165                 :            :                         start = u64_stats_fetch_begin_bh(&tstats->syncp);
     166                 :       2780 :                         rx_packets = tstats->rx_packets;
     167                 :       2780 :                         tx_packets = tstats->tx_packets;
     168                 :       2780 :                         rx_bytes = tstats->rx_bytes;
     169                 :       2780 :                         tx_bytes = tstats->tx_bytes;
     170         [ -  + ]:       2780 :                 } while (u64_stats_fetch_retry_bh(&tstats->syncp, start));
     171                 :            : 
     172                 :       2780 :                 tot->rx_packets += rx_packets;
     173                 :       2780 :                 tot->tx_packets += tx_packets;
     174                 :       2780 :                 tot->rx_bytes   += rx_bytes;
     175                 :       2780 :                 tot->tx_bytes   += tx_bytes;
     176                 :            :         }
     177                 :            : 
     178                 :        556 :         tot->multicast = dev->stats.multicast;
     179                 :            : 
     180                 :        556 :         tot->rx_crc_errors = dev->stats.rx_crc_errors;
     181                 :        556 :         tot->rx_fifo_errors = dev->stats.rx_fifo_errors;
     182                 :        556 :         tot->rx_length_errors = dev->stats.rx_length_errors;
     183                 :        556 :         tot->rx_frame_errors = dev->stats.rx_frame_errors;
     184                 :        556 :         tot->rx_errors = dev->stats.rx_errors;
     185                 :            : 
     186                 :        556 :         tot->tx_fifo_errors = dev->stats.tx_fifo_errors;
     187                 :        556 :         tot->tx_carrier_errors = dev->stats.tx_carrier_errors;
     188                 :        556 :         tot->tx_dropped = dev->stats.tx_dropped;
     189                 :        556 :         tot->tx_aborted_errors = dev->stats.tx_aborted_errors;
     190                 :        556 :         tot->tx_errors = dev->stats.tx_errors;
     191                 :            : 
     192                 :        556 :         tot->collisions  = dev->stats.collisions;
     193                 :            : 
     194                 :        556 :         return tot;
     195                 :            : }
     196                 :            : EXPORT_SYMBOL_GPL(ip_tunnel_get_stats64);

Generated by: LCOV version 1.9