ipv6: udp: make short packet logging consistent with ipv4
[safe/jmp/linux-2.6] / net / ipv6 / ip6mr.c
index 3c51b2d..3e33326 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <net/protocol.h>
 #include <linux/skbuff.h>
 #include <net/sock.h>
@@ -48,6 +49,7 @@
 #include <linux/pim.h>
 #include <net/addrconf.h>
 #include <linux/netfilter_ipv6.h>
+#include <net/ip6_checksum.h>
 
 /* Big lock, protecting vif table, mrt cache and mroute socket state.
    Note that the changes are semaphored via rtnl_lock.
@@ -82,10 +84,6 @@ static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt,
 static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm);
 static void mroute_clean_tables(struct net *net);
 
-#ifdef CONFIG_IPV6_PIMSM_V2
-static struct inet6_protocol pim6_protocol;
-#endif
-
 static struct timer_list ipmr_expire_timer;
 
 
@@ -203,7 +201,7 @@ static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations ip6mr_vif_seq_ops = {
+static const struct seq_operations ip6mr_vif_seq_ops = {
        .start = ip6mr_vif_seq_start,
        .next  = ip6mr_vif_seq_next,
        .stop  = ip6mr_vif_seq_stop,
@@ -216,7 +214,7 @@ static int ip6mr_vif_open(struct inode *inode, struct file *file)
                            sizeof(struct ipmr_vif_iter));
 }
 
-static struct file_operations ip6mr_vif_fops = {
+static const struct file_operations ip6mr_vif_fops = {
        .owner   = THIS_MODULE,
        .open    = ip6mr_vif_open,
        .read    = seq_read,
@@ -327,7 +325,7 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations ipmr_mfc_seq_ops = {
+static const struct seq_operations ipmr_mfc_seq_ops = {
        .start = ipmr_mfc_seq_start,
        .next  = ipmr_mfc_seq_next,
        .stop  = ipmr_mfc_seq_stop,
@@ -340,7 +338,7 @@ static int ipmr_mfc_open(struct inode *inode, struct file *file)
                            sizeof(struct ipmr_mfc_iter));
 }
 
-static struct file_operations ip6mr_mfc_fops = {
+static const struct file_operations ip6mr_mfc_fops = {
        .owner   = THIS_MODULE,
        .open    = ipmr_mfc_open,
        .read    = seq_read,
@@ -365,7 +363,9 @@ static int pim6_rcv(struct sk_buff *skb)
        pim = (struct pimreghdr *)skb_transport_header(skb);
        if (pim->type != ((PIM_VERSION << 4) | PIM_REGISTER) ||
            (pim->flags & PIM_NULL_REGISTER) ||
-           (ip_compute_csum((void *)pim, sizeof(*pim)) != 0 &&
+           (csum_ipv6_magic(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
+                            sizeof(*pim), IPPROTO_PIM,
+                            csum_partial((void *)pim, sizeof(*pim), 0)) &&
             csum_fold(skb_checksum(skb, 0, skb->len, 0))))
                goto drop;
 
@@ -392,13 +392,12 @@ static int pim6_rcv(struct sk_buff *skb)
        skb_pull(skb, (u8 *)encap - skb->data);
        skb_reset_network_header(skb);
        skb->dev = reg_dev;
-       skb->protocol = htons(ETH_P_IP);
+       skb->protocol = htons(ETH_P_IPV6);
        skb->ip_summed = 0;
        skb->pkt_type = PACKET_HOST;
-       dst_release(skb->dst);
+       skb_dst_drop(skb);
        reg_dev->stats.rx_bytes += skb->len;
        reg_dev->stats.rx_packets++;
-       skb->dst = NULL;
        nf_reset(skb);
        netif_rx(skb);
        dev_put(reg_dev);
@@ -408,13 +407,14 @@ static int pim6_rcv(struct sk_buff *skb)
        return 0;
 }
 
-static struct inet6_protocol pim6_protocol = {
+static const struct inet6_protocol pim6_protocol = {
        .handler        =       pim6_rcv,
 };
 
 /* Service routines creating virtual interfaces: PIMREG */
 
-static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t reg_vif_xmit(struct sk_buff *skb,
+                                     struct net_device *dev)
 {
        struct net *net = dev_net(dev);
 
@@ -425,7 +425,7 @@ static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
                           MRT6MSG_WHOLEPKT);
        read_unlock(&mrt_lock);
        kfree_skb(skb);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static const struct net_device_ops reg_vif_netdev_ops = {
@@ -439,6 +439,7 @@ static void reg_vif_setup(struct net_device *dev)
        dev->flags              = IFF_NOARP;
        dev->netdev_ops         = &reg_vif_netdev_ops;
        dev->destructor         = free_netdev;
+       dev->features           |= NETIF_F_NETNS_LOCAL;
 }
 
 static struct net_device *ip6mr_reg_vif(struct net *net)
@@ -477,10 +478,11 @@ failure:
  *     Delete a VIF entry
  */
 
-static int mif6_delete(struct net *net, int vifi)
+static int mif6_delete(struct net *net, int vifi, struct list_head *head)
 {
        struct mif_device *v;
        struct net_device *dev;
+       struct inet6_dev *in6_dev;
        if (vifi < 0 || vifi >= net->ipv6.maxvif)
                return -EADDRNOTAVAIL;
 
@@ -513,8 +515,12 @@ static int mif6_delete(struct net *net, int vifi)
 
        dev_set_allmulti(dev, -1);
 
+       in6_dev = __in6_dev_get(dev);
+       if (in6_dev)
+               in6_dev->cnf.mc_forwarding--;
+
        if (v->flags & MIFF_REGISTER)
-               unregister_netdevice(dev);
+               unregister_netdevice_queue(dev, head);
 
        dev_put(dev);
        return 0;
@@ -622,6 +628,7 @@ static int mif6_add(struct net *net, struct mif6ctl *vifc, int mrtsock)
        int vifi = vifc->mif6c_mifi;
        struct mif_device *v = &net->ipv6.vif6_table[vifi];
        struct net_device *dev;
+       struct inet6_dev *in6_dev;
        int err;
 
        /* Is vif busy ? */
@@ -662,6 +669,10 @@ static int mif6_add(struct net *net, struct mif6ctl *vifc, int mrtsock)
                return -EINVAL;
        }
 
+       in6_dev = __in6_dev_get(dev);
+       if (in6_dev)
+               in6_dev->cnf.mc_forwarding++;
+
        /*
         *      Fill in the VIF structures
         */
@@ -836,10 +847,8 @@ static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi,
        ipv6_addr_copy(&msg->im6_src, &ipv6_hdr(pkt)->saddr);
        ipv6_addr_copy(&msg->im6_dst, &ipv6_hdr(pkt)->daddr);
 
-       skb->dst = dst_clone(pkt->dst);
+       skb_dst_set(skb, dst_clone(skb_dst(pkt)));
        skb->ip_summed = CHECKSUM_UNNECESSARY;
-
-       skb_pull(skb, sizeof(struct ipv6hdr));
        }
 
        if (net->ipv6.mroute6_sk == NULL) {
@@ -968,6 +977,7 @@ static int ip6mr_device_event(struct notifier_block *this,
        struct net *net = dev_net(dev);
        struct mif_device *v;
        int ct;
+       LIST_HEAD(list);
 
        if (event != NETDEV_UNREGISTER)
                return NOTIFY_DONE;
@@ -975,8 +985,10 @@ static int ip6mr_device_event(struct notifier_block *this,
        v = &net->ipv6.vif6_table[0];
        for (ct = 0; ct < net->ipv6.maxvif; ct++, v++) {
                if (v->dev == dev)
-                       mif6_delete(net, ct);
+                       mif6_delete(net, ct, &list);
        }
+       unregister_netdevice_many(&list);
+
        return NOTIFY_DONE;
 }
 
@@ -1067,7 +1079,18 @@ int __init ip6_mr_init(void)
        err = register_netdevice_notifier(&ip6_mr_notifier);
        if (err)
                goto reg_notif_fail;
+#ifdef CONFIG_IPV6_PIMSM_V2
+       if (inet6_add_protocol(&pim6_protocol, IPPROTO_PIM) < 0) {
+               printk(KERN_ERR "ip6_mr_init: can't add PIM protocol\n");
+               err = -EAGAIN;
+               goto add_proto_fail;
+       }
+#endif
        return 0;
+#ifdef CONFIG_IPV6_PIMSM_V2
+add_proto_fail:
+       unregister_netdevice_notifier(&ip6_mr_notifier);
+#endif
 reg_notif_fail:
        del_timer(&ipmr_expire_timer);
        unregister_pernet_subsys(&ip6mr_net_ops);
@@ -1091,6 +1114,9 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
        unsigned char ttls[MAXMIFS];
        int i;
 
+       if (mfc->mf6cc_parent >= MAXMIFS)
+               return -ENFILE;
+
        memset(ttls, 255, MAXMIFS);
        for (i = 0; i < MAXMIFS; i++) {
                if (IF_ISSET(i, &mfc->mf6cc_ifset))
@@ -1169,14 +1195,16 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
 static void mroute_clean_tables(struct net *net)
 {
        int i;
+       LIST_HEAD(list);
 
        /*
         *      Shut down all active vif entries
         */
        for (i = 0; i < net->ipv6.maxvif; i++) {
                if (!(net->ipv6.vif6_table[i].flags & VIFF_STATIC))
-                       mif6_delete(net, i);
+                       mif6_delete(net, i, &list);
        }
+       unregister_netdevice_many(&list);
 
        /*
         *      Wipe the cache
@@ -1222,8 +1250,10 @@ static int ip6mr_sk_init(struct sock *sk)
 
        rtnl_lock();
        write_lock_bh(&mrt_lock);
-       if (likely(net->ipv6.mroute6_sk == NULL))
+       if (likely(net->ipv6.mroute6_sk == NULL)) {
                net->ipv6.mroute6_sk = sk;
+               net->ipv6.devconf_all->mc_forwarding++;
+       }
        else
                err = -EADDRINUSE;
        write_unlock_bh(&mrt_lock);
@@ -1242,6 +1272,7 @@ int ip6mr_sk_done(struct sock *sk)
        if (sk == net->ipv6.mroute6_sk) {
                write_lock_bh(&mrt_lock);
                net->ipv6.mroute6_sk = NULL;
+               net->ipv6.devconf_all->mc_forwarding--;
                write_unlock_bh(&mrt_lock);
 
                mroute_clean_tables(net);
@@ -1259,7 +1290,7 @@ int ip6mr_sk_done(struct sock *sk)
  *     MOSPF/PIM router set up we can clean this up.
  */
 
-int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int optlen)
+int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsigned int optlen)
 {
        int ret;
        struct mif6ctl vif;
@@ -1275,7 +1306,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
        switch (optname) {
        case MRT6_INIT:
                if (sk->sk_type != SOCK_RAW ||
-                   inet_sk(sk)->num != IPPROTO_ICMPV6)
+                   inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
                        return -EOPNOTSUPP;
                if (optlen < sizeof(int))
                        return -EINVAL;
@@ -1303,7 +1334,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
                if (copy_from_user(&mifi, optval, sizeof(mifi_t)))
                        return -EFAULT;
                rtnl_lock();
-               ret = mif6_delete(net, mifi);
+               ret = mif6_delete(net, mifi, NULL);
                rtnl_unlock();
                return ret;
 
@@ -1350,14 +1381,6 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
                if (v != net->ipv6.mroute_do_pim) {
                        net->ipv6.mroute_do_pim = v;
                        net->ipv6.mroute_do_assert = v;
-                       if (net->ipv6.mroute_do_pim)
-                               ret = inet6_add_protocol(&pim6_protocol,
-                                                        IPPROTO_PIM);
-                       else
-                               ret = inet6_del_protocol(&pim6_protocol,
-                                                        IPPROTO_PIM);
-                       if (ret < 0)
-                               ret = -EAGAIN;
                }
                rtnl_unlock();
                return ret;
@@ -1473,7 +1496,7 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
 
 static inline int ip6mr_forward2_finish(struct sk_buff *skb)
 {
-       IP6_INC_STATS_BH(dev_net(skb->dst->dev), ip6_dst_idev(skb->dst),
+       IP6_INC_STATS_BH(dev_net(skb_dst(skb)->dev), ip6_dst_idev(skb_dst(skb)),
                         IPSTATS_MIB_OUTFORWDATAGRAMS);
        return dst_output(skb);
 }
@@ -1518,8 +1541,8 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
        if (!dst)
                goto out_free;
 
-       dst_release(skb->dst);
-       skb->dst = dst;
+       skb_dst_drop(skb);
+       skb_dst_set(skb, dst);
 
        /*
         * RFC1584 teaches, that DVMRP/PIM router must deliver packets locally
@@ -1673,17 +1696,20 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm)
        int ct;
        struct rtnexthop *nhp;
        struct net *net = mfc6_net(c);
-       struct net_device *dev = net->ipv6.vif6_table[c->mf6c_parent].dev;
        u8 *b = skb_tail_pointer(skb);
        struct rtattr *mp_head;
 
-       if (dev)
-               RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex);
+       /* If cache is unresolved, don't try to parse IIF and OIF */
+       if (c->mf6c_parent > MAXMIFS)
+               return -ENOENT;
+
+       if (MIF_EXISTS(net, c->mf6c_parent))
+               RTA_PUT(skb, RTA_IIF, 4, &net->ipv6.vif6_table[c->mf6c_parent].dev->ifindex);
 
        mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
 
        for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
-               if (c->mfc_un.res.ttls[ct] < 255) {
+               if (MIF_EXISTS(net, ct) && c->mfc_un.res.ttls[ct] < 255) {
                        if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
                                goto rtattr_failure;
                        nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
@@ -1708,7 +1734,7 @@ int ip6mr_get_route(struct net *net,
 {
        int err;
        struct mfc6_cache *cache;
-       struct rt6_info *rt = (struct rt6_info *)skb->dst;
+       struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
 
        read_lock(&mrt_lock);
        cache = ip6mr_cache_find(net, &rt->rt6i_src.addr, &rt->rt6i_dst.addr);