[NETFILTER]: nf_nat: add DCCP protocol support
[safe/jmp/linux-2.6] / net / ipv4 / ipmr.c
index 3578942..11700a4 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/mroute.h>
 #include <linux/init.h>
 #include <linux/if_ether.h>
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/protocol.h>
 #include <linux/skbuff.h>
@@ -62,6 +63,7 @@
 #include <linux/netfilter_ipv4.h>
 #include <net/ipip.h>
 #include <net/checksum.h>
+#include <net/netlink.h>
 
 #if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2)
 #define CONFIG_IP_PIMSM        1
@@ -123,7 +125,7 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v)
 {
        struct net_device  *dev;
 
-       dev = __dev_get_by_name("tunl0");
+       dev = __dev_get_by_name(&init_net, "tunl0");
 
        if (dev) {
                int err;
@@ -139,7 +141,7 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v)
                p.iph.ihl = 5;
                p.iph.protocol = IPPROTO_IPIP;
                sprintf(p.name, "dvmrp%d", v->vifc_vifi);
-               ifr.ifr_ifru.ifru_data = (void*)&p;
+               ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
 
                oldfs = get_fs(); set_fs(KERNEL_DS);
                err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
@@ -147,13 +149,15 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v)
 
                dev = NULL;
 
-               if (err == 0 && (dev = __dev_get_by_name(p.name)) != NULL) {
+               if (err == 0 && (dev = __dev_get_by_name(&init_net, p.name)) != NULL) {
                        dev->flags |= IFF_MULTICAST;
 
                        in_dev = __in_dev_get_rtnl(dev);
-                       if (in_dev == NULL && (in_dev = inetdev_init(dev)) == NULL)
+                       if (in_dev == NULL)
                                goto failure;
-                       in_dev->cnf.rp_filter = 0;
+
+                       ipv4_devconf_setall(in_dev);
+                       IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;
 
                        if (dev_open(dev))
                                goto failure;
@@ -217,10 +221,15 @@ static struct net_device *ipmr_reg_vif(void)
        }
        dev->iflink = 0;
 
-       if ((in_dev = inetdev_init(dev)) == NULL)
+       rcu_read_lock();
+       if ((in_dev = __in_dev_get_rcu(dev)) == NULL) {
+               rcu_read_unlock();
                goto failure;
+       }
 
-       in_dev->cnf.rp_filter = 0;
+       ipv4_devconf_setall(in_dev);
+       IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;
+       rcu_read_unlock();
 
        if (dev_open(dev))
                goto failure;
@@ -280,7 +289,7 @@ static int vif_delete(int vifi)
        dev_set_allmulti(dev, -1);
 
        if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
-               in_dev->cnf.mc_forwarding--;
+               IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)--;
                ip_rt_multicast_event(in_dev);
        }
 
@@ -312,7 +321,7 @@ static void ipmr_destroy_unres(struct mfc_cache *c)
                        e->error = -ETIMEDOUT;
                        memset(&e->msg, 0, sizeof(e->msg));
 
-                       rtnl_unicast(skb, NETLINK_CB(skb).pid);
+                       rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid);
                } else
                        kfree_skb(skb);
        }
@@ -414,7 +423,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
                        return -ENOBUFS;
                break;
        case 0:
-               dev = ip_dev_find(vifc->vifc_lcl_addr.s_addr);
+               dev = ip_dev_find(&init_net, vifc->vifc_lcl_addr.s_addr);
                if (!dev)
                        return -EADDRNOTAVAIL;
                dev_put(dev);
@@ -425,7 +434,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
 
        if ((in_dev = __in_dev_get_rtnl(dev)) == NULL)
                return -EADDRNOTAVAIL;
-       in_dev->cnf.mc_forwarding++;
+       IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)++;
        dev_set_allmulti(dev, +1);
        ip_rt_multicast_event(in_dev);
 
@@ -513,7 +522,8 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
                        struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr));
 
                        if (ipmr_fill_mroute(skb, c, NLMSG_DATA(nlh)) > 0) {
-                               nlh->nlmsg_len = skb->tail - (u8*)nlh;
+                               nlh->nlmsg_len = (skb_tail_pointer(skb) -
+                                                 (u8 *)nlh);
                        } else {
                                nlh->nlmsg_type = NLMSG_ERROR;
                                nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr));
@@ -523,7 +533,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
                                memset(&e->msg, 0, sizeof(e->msg));
                        }
 
-                       rtnl_unicast(skb, NETLINK_CB(skb).pid);
+                       rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid);
                } else
                        ip_mr_forward(skb, c, 0);
        }
@@ -580,9 +590,9 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
         *      Copy the IP header
         */
 
-       skb_set_network_header(skb, skb->tail - skb->data);
+       skb->network_header = skb->tail;
        skb_put(skb, ihl);
-       memcpy(skb->data,pkt->data,ihl);
+       skb_copy_to_linear_data(skb, pkt->data, ihl);
        ip_hdr(skb)->protocol = 0;                      /* Flag to the kernel this is a route add */
        msg = (struct igmpmsg *)skb_network_header(skb);
        msg->im_vif = vifi;
@@ -597,7 +607,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
        msg->im_msgtype = assert;
        igmp->code      =       0;
        ip_hdr(skb)->tot_len = htons(skb->len);                 /* Fix the length */
-       skb->h.raw = skb->nh.raw;
+       skb->transport_header = skb->network_header;
        }
 
        if (mroute_socket == NULL) {
@@ -739,7 +749,7 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock)
                return 0;
        }
 
-       if (!MULTICAST(mfc->mfcc_mcastgrp.s_addr))
+       if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr))
                return -EINVAL;
 
        c=ipmr_cache_alloc();
@@ -839,7 +849,7 @@ static void mrtsock_destruct(struct sock *sk)
 {
        rtnl_lock();
        if (sk == mroute_socket) {
-               ipv4_devconf.mc_forwarding--;
+               IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)--;
 
                write_lock_bh(&mrt_lock);
                mroute_socket=NULL;
@@ -888,7 +898,7 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
                        mroute_socket=sk;
                        write_unlock_bh(&mrt_lock);
 
-                       ipv4_devconf.mc_forwarding++;
+                       IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)++;
                }
                rtnl_unlock();
                return ret;
@@ -944,10 +954,12 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
 #ifdef CONFIG_IP_PIMSM
        case MRT_PIM:
        {
-               int v, ret;
+               int v;
+
                if (get_user(v,(int __user *)optval))
                        return -EFAULT;
-               v = (v)?1:0;
+               v = (v) ? 1 : 0;
+
                rtnl_lock();
                ret = 0;
                if (v != mroute_do_pim) {
@@ -1073,13 +1085,18 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
 
 static int ipmr_device_event(struct notifier_block *this, unsigned long event, void *ptr)
 {
+       struct net_device *dev = ptr;
        struct vif_device *v;
        int ct;
+
+       if (dev_net(dev) != &init_net)
+               return NOTIFY_DONE;
+
        if (event != NETDEV_UNREGISTER)
                return NOTIFY_DONE;
        v=&vif_table[0];
        for (ct=0;ct<maxvif;ct++,v++) {
-               if (v->dev==ptr)
+               if (v->dev==dev)
                        vif_delete(ct);
        }
        return NOTIFY_DONE;
@@ -1102,7 +1119,7 @@ static void ip_encap(struct sk_buff *skb, __be32 saddr, __be32 daddr)
        struct iphdr *old_iph = ip_hdr(skb);
 
        skb_push(skb, sizeof(struct iphdr));
-       skb->h.raw = skb->nh.raw;
+       skb->transport_header = skb->network_header;
        skb_reset_network_header(skb);
        iph = ip_hdr(skb);
 
@@ -1168,7 +1185,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
                                                .saddr = vif->local,
                                                .tos = RT_TOS(iph->tos) } },
                                    .proto = IPPROTO_IPIP };
-               if (ip_route_output_key(&rt, &fl))
+               if (ip_route_output_key(&init_net, &rt, &fl))
                        goto out_free;
                encap = sizeof(struct iphdr);
        } else {
@@ -1177,7 +1194,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
                                              { .daddr = iph->daddr,
                                                .tos = RT_TOS(iph->tos) } },
                                    .proto = IPPROTO_IPIP };
-               if (ip_route_output_key(&rt, &fl))
+               if (ip_route_output_key(&init_net, &rt, &fl))
                        goto out_free;
        }
 
@@ -1230,7 +1247,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
         * not mrouter) cannot join to more than one interface - it will
         * result in receiving multiple packets.
         */
-       NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, dev,
+       NF_HOOK(PF_INET, NF_INET_FORWARD, skb, skb->dev, dev,
                ipmr_forward_finish);
        return;
 
@@ -1266,7 +1283,7 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
        if (vif_table[vif].dev != skb->dev) {
                int true_vifi;
 
-               if (((struct rtable*)skb->dst)->fl.iif == 0) {
+               if (skb->rtable->fl.iif == 0) {
                        /* It is our own packet, looped back.
                           Very complicated situation...
 
@@ -1340,7 +1357,7 @@ dont_forward:
 int ip_mr_input(struct sk_buff *skb)
 {
        struct mfc_cache *cache;
-       int local = ((struct rtable*)skb->dst)->rt_flags&RTCF_LOCAL;
+       int local = skb->rtable->rt_flags&RTCF_LOCAL;
 
        /* Packet is looped back after forward, it should not be
           forwarded second time, but still can be delivered locally.
@@ -1446,7 +1463,7 @@ int pim_rcv_v1(struct sk_buff * skb)
           b. packet is not a NULL-REGISTER
           c. packet is not truncated
         */
-       if (!MULTICAST(encap->daddr) ||
+       if (!ipv4_is_multicast(encap->daddr) ||
            encap->tot_len == 0 ||
            ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
                goto drop;
@@ -1461,7 +1478,7 @@ int pim_rcv_v1(struct sk_buff * skb)
        if (reg_dev == NULL)
                goto drop;
 
-       skb->mac.raw = skb->nh.raw;
+       skb->mac_header = skb->network_header;
        skb_pull(skb, (u8*)encap - skb->data);
        skb_reset_network_header(skb);
        skb->dev = reg_dev;
@@ -1502,7 +1519,7 @@ static int pim_rcv(struct sk_buff * skb)
        /* check if the inner packet is destined to mcast group */
        encap = (struct iphdr *)(skb_transport_header(skb) +
                                 sizeof(struct pimreghdr));
-       if (!MULTICAST(encap->daddr) ||
+       if (!ipv4_is_multicast(encap->daddr) ||
            encap->tot_len == 0 ||
            ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
                goto drop;
@@ -1517,7 +1534,7 @@ static int pim_rcv(struct sk_buff * skb)
        if (reg_dev == NULL)
                goto drop;
 
-       skb->mac.raw = skb->nh.raw;
+       skb->mac_header = skb->network_header;
        skb_pull(skb, (u8*)encap - skb->data);
        skb_reset_network_header(skb);
        skb->dev = reg_dev;
@@ -1544,7 +1561,7 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm)
        int ct;
        struct rtnexthop *nhp;
        struct net_device *dev = vif_table[c->mfc_parent].dev;
-       u8 *b = skb->tail;
+       u8 *b = skb_tail_pointer(skb);
        struct rtattr *mp_head;
 
        if (dev)
@@ -1564,12 +1581,12 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm)
                }
        }
        mp_head->rta_type = RTA_MULTIPATH;
-       mp_head->rta_len = skb->tail - (u8*)mp_head;
+       mp_head->rta_len = skb_tail_pointer(skb) - (u8 *)mp_head;
        rtm->rtm_type = RTN_MULTICAST;
        return 1;
 
 rtattr_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -EMSGSIZE;
 }
 
@@ -1577,7 +1594,7 @@ int ipmr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait)
 {
        int err;
        struct mfc_cache *cache;
-       struct rtable *rt = (struct rtable*)skb->dst;
+       struct rtable *rt = skb->rtable;
 
        read_lock(&mrt_lock);
        cache = ipmr_cache_find(rt->rt_src, rt->rt_dst);
@@ -1644,6 +1661,7 @@ static struct vif_device *ipmr_vif_seq_idx(struct ipmr_vif_iter *iter,
 }
 
 static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(mrt_lock)
 {
        read_lock(&mrt_lock);
        return *pos ? ipmr_vif_seq_idx(seq->private, *pos - 1)
@@ -1667,6 +1685,7 @@ static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void ipmr_vif_seq_stop(struct seq_file *seq, void *v)
+       __releases(mrt_lock)
 {
        read_unlock(&mrt_lock);
 }
@@ -1699,26 +1718,8 @@ static const struct seq_operations ipmr_vif_seq_ops = {
 
 static int ipmr_vif_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct ipmr_vif_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
-
-       if (!s)
-               goto out;
-
-       rc = seq_open(file, &ipmr_vif_seq_ops);
-       if (rc)
-               goto out_kfree;
-
-       s->ct = 0;
-       seq = file->private_data;
-       seq->private = s;
-out:
-       return rc;
-out_kfree:
-       kfree(s);
-       goto out;
-
+       return seq_open_private(file, &ipmr_vif_seq_ops,
+                       sizeof(struct ipmr_vif_iter));
 }
 
 static const struct file_operations ipmr_vif_fops = {
@@ -1862,25 +1863,8 @@ static const struct seq_operations ipmr_mfc_seq_ops = {
 
 static int ipmr_mfc_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct ipmr_mfc_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
-
-       if (!s)
-               goto out;
-
-       rc = seq_open(file, &ipmr_mfc_seq_ops);
-       if (rc)
-               goto out_kfree;
-
-       seq = file->private_data;
-       seq->private = s;
-out:
-       return rc;
-out_kfree:
-       kfree(s);
-       goto out;
-
+       return seq_open_private(file, &ipmr_mfc_seq_ops,
+                       sizeof(struct ipmr_mfc_iter));
 }
 
 static const struct file_operations ipmr_mfc_fops = {
@@ -1908,12 +1892,11 @@ void __init ip_mr_init(void)
        mrt_cachep = kmem_cache_create("ip_mrt_cache",
                                       sizeof(struct mfc_cache),
                                       0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
-                                      NULL, NULL);
-       init_timer(&ipmr_expire_timer);
-       ipmr_expire_timer.function=ipmr_expire_process;
+                                      NULL);
+       setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
        register_netdevice_notifier(&ip_mr_notifier);
 #ifdef CONFIG_PROC_FS
-       proc_net_fops_create("ip_mr_vif", 0, &ipmr_vif_fops);
-       proc_net_fops_create("ip_mr_cache", 0, &ipmr_mfc_fops);
+       proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops);
+       proc_net_fops_create(&init_net, "ip_mr_cache", 0, &ipmr_mfc_fops);
 #endif
 }