]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv6/sit.c
net: use the macros defined for the members of flowi
[net-next-2.6.git] / net / ipv6 / sit.c
index 6822481ff766ea4105b46f4c29889cf78e6ee9a3..6e48a80d0f25a234551226b3b62719822fe74e84 100644 (file)
@@ -63,8 +63,9 @@
 #define HASH_SIZE  16
 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
 
-static void ipip6_tunnel_init(struct net_device *dev);
+static int ipip6_tunnel_init(struct net_device *dev);
 static void ipip6_tunnel_setup(struct net_device *dev);
+static void ipip6_dev_free(struct net_device *dev);
 
 static int sit_net_id __read_mostly;
 struct sit_net {
@@ -84,6 +85,33 @@ struct sit_net {
 #define for_each_ip_tunnel_rcu(start) \
        for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
 
+/* often modified stats are per cpu, other are shared (netdev->stats) */
+struct pcpu_tstats {
+       unsigned long   rx_packets;
+       unsigned long   rx_bytes;
+       unsigned long   tx_packets;
+       unsigned long   tx_bytes;
+};
+
+static struct net_device_stats *ipip6_get_stats(struct net_device *dev)
+{
+       struct pcpu_tstats sum = { 0 };
+       int i;
+
+       for_each_possible_cpu(i) {
+               const struct pcpu_tstats *tstats = per_cpu_ptr(dev->tstats, i);
+
+               sum.rx_packets += tstats->rx_packets;
+               sum.rx_bytes   += tstats->rx_bytes;
+               sum.tx_packets += tstats->tx_packets;
+               sum.tx_bytes   += tstats->tx_bytes;
+       }
+       dev->stats.rx_packets = sum.rx_packets;
+       dev->stats.rx_bytes   = sum.rx_bytes;
+       dev->stats.tx_packets = sum.tx_packets;
+       dev->stats.tx_bytes   = sum.tx_bytes;
+       return &dev->stats;
+}
 /*
  * Must be invoked with rcu_read_lock
  */
@@ -214,7 +242,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,
        if (parms->name[0])
                strlcpy(name, parms->name, IFNAMSIZ);
        else
-               sprintf(name, "sit%%d");
+               strcpy(name, "sit%d");
 
        dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup);
        if (dev == NULL)
@@ -230,7 +258,8 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,
        nt = netdev_priv(dev);
 
        nt->parms = *parms;
-       ipip6_tunnel_init(dev);
+       if (ipip6_tunnel_init(dev) < 0)
+               goto failed_free;
        ipip6_tunnel_clone_6rd(dev, sitn);
 
        if (parms->i_flags & SIT_ISATAP)
@@ -245,7 +274,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,
        return nt;
 
 failed_free:
-       free_netdev(dev);
+       ipip6_dev_free(dev);
 failed:
        return NULL;
 }
@@ -546,6 +575,8 @@ static int ipip6_rcv(struct sk_buff *skb)
        tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev,
                                     iph->saddr, iph->daddr);
        if (tunnel != NULL) {
+               struct pcpu_tstats *tstats;
+
                secpath_reset(skb);
                skb->mac_header = skb->network_header;
                skb_reset_network_header(skb);
@@ -561,10 +592,16 @@ static int ipip6_rcv(struct sk_buff *skb)
                        return 0;
                }
 
-               skb_tunnel_rx(skb, tunnel->dev);
+               tstats = this_cpu_ptr(tunnel->dev->tstats);
+               tstats->rx_packets++;
+               tstats->rx_bytes += skb->len;
+
+               __skb_tunnel_rx(skb, tunnel->dev);
 
                ipip6_ecn_decapsulate(iph, skb);
+
                netif_rx(skb);
+
                rcu_read_unlock();
                return 0;
        }
@@ -623,14 +660,13 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
                                     struct net_device *dev)
 {
        struct ip_tunnel *tunnel = netdev_priv(dev);
-       struct net_device_stats *stats = &dev->stats;
-       struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
+       struct pcpu_tstats *tstats;
        struct iphdr  *tiph = &tunnel->parms.iph;
        struct ipv6hdr *iph6 = ipv6_hdr(skb);
        u8     tos = tunnel->parms.iph.tos;
        __be16 df = tiph->frag_off;
        struct rtable *rt;                      /* Route to the other host */
-       struct net_device *tdev;                        /* Device to other host */
+       struct net_device *tdev;                /* Device to other host */
        struct iphdr  *iph;                     /* Our new IP header */
        unsigned int max_headroom;              /* The extra header space needed */
        __be32 dst = tiph->daddr;
@@ -694,27 +730,26 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
        }
 
        {
-               struct flowi fl = { .nl_u = { .ip4_u =
-                                             { .daddr = dst,
-                                               .saddr = tiph->saddr,
-                                               .tos = RT_TOS(tos) } },
+               struct flowi fl = { .fl4_dst = dst,
+                                   .fl4_src = tiph->saddr,
+                                   .fl4_tos = RT_TOS(tos),
                                    .oif = tunnel->parms.link,
                                    .proto = IPPROTO_IPV6 };
                if (ip_route_output_key(dev_net(dev), &rt, &fl)) {
-                       stats->tx_carrier_errors++;
+                       dev->stats.tx_carrier_errors++;
                        goto tx_error_icmp;
                }
        }
        if (rt->rt_type != RTN_UNICAST) {
                ip_rt_put(rt);
-               stats->tx_carrier_errors++;
+               dev->stats.tx_carrier_errors++;
                goto tx_error_icmp;
        }
        tdev = rt->dst.dev;
 
        if (tdev == dev) {
                ip_rt_put(rt);
-               stats->collisions++;
+               dev->stats.collisions++;
                goto tx_error;
        }
 
@@ -722,7 +757,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
                mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
 
                if (mtu < 68) {
-                       stats->collisions++;
+                       dev->stats.collisions++;
                        ip_rt_put(rt);
                        goto tx_error;
                }
@@ -761,7 +796,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
                struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
                if (!new_skb) {
                        ip_rt_put(rt);
-                       txq->tx_dropped++;
+                       dev->stats.tx_dropped++;
                        dev_kfree_skb(skb);
                        return NETDEV_TX_OK;
                }
@@ -797,14 +832,14 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
                iph->ttl        =       iph6->hop_limit;
 
        nf_reset(skb);
-
-       IPTUNNEL_XMIT();
+       tstats = this_cpu_ptr(dev->tstats);
+       __IPTUNNEL_XMIT(tstats, &dev->stats);
        return NETDEV_TX_OK;
 
 tx_error_icmp:
        dst_link_failure(skb);
 tx_error:
-       stats->tx_errors++;
+       dev->stats.tx_errors++;
        dev_kfree_skb(skb);
        return NETDEV_TX_OK;
 }
@@ -819,10 +854,9 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev)
        iph = &tunnel->parms.iph;
 
        if (iph->daddr) {
-               struct flowi fl = { .nl_u = { .ip4_u =
-                                             { .daddr = iph->daddr,
-                                               .saddr = iph->saddr,
-                                               .tos = RT_TOS(iph->tos) } },
+               struct flowi fl = { .fl4_dst = iph->daddr,
+                                   .fl4_src = iph->saddr,
+                                   .fl4_tos = RT_TOS(iph->tos),
                                    .oif = tunnel->parms.link,
                                    .proto = IPPROTO_IPV6 };
                struct rtable *rt;
@@ -927,6 +961,7 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
                                }
                                t = netdev_priv(dev);
                                ipip6_tunnel_unlink(sitn, t);
+                               synchronize_net();
                                t->parms.iph.saddr = p.iph.saddr;
                                t->parms.iph.daddr = p.iph.daddr;
                                memcpy(dev->dev_addr, &p.iph.saddr, 4);
@@ -1081,12 +1116,19 @@ static const struct net_device_ops ipip6_netdev_ops = {
        .ndo_start_xmit = ipip6_tunnel_xmit,
        .ndo_do_ioctl   = ipip6_tunnel_ioctl,
        .ndo_change_mtu = ipip6_tunnel_change_mtu,
+       .ndo_get_stats  = ipip6_get_stats,
 };
 
+static void ipip6_dev_free(struct net_device *dev)
+{
+       free_percpu(dev->tstats);
+       free_netdev(dev);
+}
+
 static void ipip6_tunnel_setup(struct net_device *dev)
 {
        dev->netdev_ops         = &ipip6_netdev_ops;
-       dev->destructor         = free_netdev;
+       dev->destructor         = ipip6_dev_free;
 
        dev->type               = ARPHRD_SIT;
        dev->hard_header_len    = LL_MAX_HEADER + sizeof(struct iphdr);
@@ -1096,9 +1138,10 @@ static void ipip6_tunnel_setup(struct net_device *dev)
        dev->iflink             = 0;
        dev->addr_len           = 4;
        dev->features           |= NETIF_F_NETNS_LOCAL;
+       dev->features           |= NETIF_F_LLTX;
 }
 
-static void ipip6_tunnel_init(struct net_device *dev)
+static int ipip6_tunnel_init(struct net_device *dev)
 {
        struct ip_tunnel *tunnel = netdev_priv(dev);
 
@@ -1109,9 +1152,14 @@ static void ipip6_tunnel_init(struct net_device *dev)
        memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
 
        ipip6_tunnel_bind_dev(dev);
+       dev->tstats = alloc_percpu(struct pcpu_tstats);
+       if (!dev->tstats)
+               return -ENOMEM;
+
+       return 0;
 }
 
-static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)
+static int __net_init ipip6_fb_tunnel_init(struct net_device *dev)
 {
        struct ip_tunnel *tunnel = netdev_priv(dev);
        struct iphdr *iph = &tunnel->parms.iph;
@@ -1126,8 +1174,12 @@ static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)
        iph->ihl                = 5;
        iph->ttl                = 64;
 
+       dev->tstats = alloc_percpu(struct pcpu_tstats);
+       if (!dev->tstats)
+               return -ENOMEM;
        dev_hold(dev);
        sitn->tunnels_wc[0]     = tunnel;
+       return 0;
 }
 
 static struct xfrm_tunnel sit_handler __read_mostly = {
@@ -1171,7 +1223,10 @@ static int __net_init sit_init_net(struct net *net)
        }
        dev_net_set(sitn->fb_tunnel_dev, net);
 
-       ipip6_fb_tunnel_init(sitn->fb_tunnel_dev);
+       err = ipip6_fb_tunnel_init(sitn->fb_tunnel_dev);
+       if (err)
+               goto err_dev_free;
+
        ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn);
 
        if ((err = register_netdev(sitn->fb_tunnel_dev)))
@@ -1181,7 +1236,8 @@ static int __net_init sit_init_net(struct net *net)
 
 err_reg_dev:
        dev_put(sitn->fb_tunnel_dev);
-       free_netdev(sitn->fb_tunnel_dev);
+err_dev_free:
+       ipip6_dev_free(sitn->fb_tunnel_dev);
 err_alloc_dev:
        return err;
 }