[TCP]: Create tcp_sacktag_one().
[safe/jmp/linux-2.6] / net / ipv4 / arp.c
index e6e196c..54a76b8 100644 (file)
 #include <linux/sysctl.h>
 #endif
 
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/icmp.h>
 #include <net/route.h>
 #include <net/tcp.h>
 #include <net/sock.h>
 #include <net/arp.h>
-#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
 #include <net/ax25.h>
-#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
 #include <net/netrom.h>
-#endif
-#endif
 #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
 #include <net/atmclip.h>
 struct neigh_table *clip_tbl_hook;
@@ -214,7 +211,7 @@ int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir)
                ip_tr_mc_map(addr, haddr);
                return 0;
        case ARPHRD_INFINIBAND:
-               ip_ib_mc_map(addr, haddr);
+               ip_ib_mc_map(addr, dev->broadcast, haddr);
                return 0;
        default:
                if (dir) {
@@ -252,7 +249,7 @@ static int arp_constructor(struct neighbour *neigh)
        neigh->parms = neigh_parms_clone(parms);
        rcu_read_unlock();
 
-       if (dev->hard_header == NULL) {
+       if (!dev->header_ops) {
                neigh->nud_state = NUD_NOARP;
                neigh->ops = &arp_direct_ops;
                neigh->output = neigh->ops->queue_xmit;
@@ -309,10 +306,12 @@ static int arp_constructor(struct neighbour *neigh)
                        neigh->nud_state = NUD_NOARP;
                        memcpy(neigh->ha, dev->broadcast, dev->addr_len);
                }
-               if (dev->hard_header_cache)
+
+               if (dev->header_ops->cache)
                        neigh->ops = &arp_hh_ops;
                else
                        neigh->ops = &arp_generic_ops;
+
                if (neigh->nud_state&NUD_VALID)
                        neigh->output = neigh->ops->connected_output;
                else
@@ -342,13 +341,13 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb)
        switch (IN_DEV_ARP_ANNOUNCE(in_dev)) {
        default:
        case 0:         /* By default announce any local IP */
-               if (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL)
-                       saddr = skb->nh.iph->saddr;
+               if (skb && inet_addr_type(ip_hdr(skb)->saddr) == RTN_LOCAL)
+                       saddr = ip_hdr(skb)->saddr;
                break;
        case 1:         /* Restrict announcements of saddr in same subnet */
                if (!skb)
                        break;
-               saddr = skb->nh.iph->saddr;
+               saddr = ip_hdr(skb)->saddr;
                if (inet_addr_type(saddr) == RTN_LOCAL) {
                        /* saddr should be known to target */
                        if (inet_addr_onlink(in_dev, target, saddr))
@@ -578,7 +577,7 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
                return NULL;
 
        skb_reserve(skb, LL_RESERVED_SPACE(dev));
-       skb->nh.raw = skb->data;
+       skb_reset_network_header(skb);
        arp = (struct arphdr *) skb_put(skb,sizeof(struct arphdr) + 2*(dev->addr_len+4));
        skb->dev = dev;
        skb->protocol = htons(ETH_P_ARP);
@@ -590,8 +589,7 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
        /*
         *      Fill the device header for the ARP frame
         */
-       if (dev->hard_header &&
-           dev->hard_header(skb,dev,ptype,dest_hw,src_hw,skb->len) < 0)
+       if (dev_hard_header(skb, dev, ptype, dest_hw, src_hw, skb->len) < 0)
                goto out;
 
        /*
@@ -708,7 +706,7 @@ static int arp_process(struct sk_buff *skb)
        struct arphdr *arp;
        unsigned char *arp_ptr;
        struct rtable *rt;
-       unsigned char *sha, *tha;
+       unsigned char *sha;
        __be32 sip, tip;
        u16 dev_type = dev->type;
        int addr_type;
@@ -721,7 +719,7 @@ static int arp_process(struct sk_buff *skb)
        if (in_dev == NULL)
                goto out;
 
-       arp = skb->nh.arph;
+       arp = arp_hdr(skb);
 
        switch (dev_type) {
        default:
@@ -729,20 +727,10 @@ static int arp_process(struct sk_buff *skb)
                    htons(dev_type) != arp->ar_hrd)
                        goto out;
                break;
-#ifdef CONFIG_NET_ETHERNET
        case ARPHRD_ETHER:
-#endif
-#ifdef CONFIG_TR
        case ARPHRD_IEEE802_TR:
-#endif
-#ifdef CONFIG_FDDI
        case ARPHRD_FDDI:
-#endif
-#ifdef CONFIG_NET_FC
        case ARPHRD_IEEE802:
-#endif
-#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_TR) || \
-    defined(CONFIG_FDDI)        || defined(CONFIG_NET_FC)
                /*
                 * ETHERNET, Token Ring and Fibre Channel (which are IEEE 802
                 * devices, according to RFC 2625) devices will accept ARP
@@ -757,21 +745,16 @@ static int arp_process(struct sk_buff *skb)
                    arp->ar_pro != htons(ETH_P_IP))
                        goto out;
                break;
-#endif
-#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
        case ARPHRD_AX25:
                if (arp->ar_pro != htons(AX25_P_IP) ||
                    arp->ar_hrd != htons(ARPHRD_AX25))
                        goto out;
                break;
-#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
        case ARPHRD_NETROM:
                if (arp->ar_pro != htons(AX25_P_IP) ||
                    arp->ar_hrd != htons(ARPHRD_NETROM))
                        goto out;
                break;
-#endif
-#endif
        }
 
        /* Understand only these message types */
@@ -788,7 +771,6 @@ static int arp_process(struct sk_buff *skb)
        arp_ptr += dev->addr_len;
        memcpy(&sip, arp_ptr, 4);
        arp_ptr += 4;
-       tha     = arp_ptr;
        arp_ptr += dev->addr_len;
        memcpy(&tip, arp_ptr, 4);
 /*
@@ -826,7 +808,8 @@ static int arp_process(struct sk_buff *skb)
                if (arp->ar_op == htons(ARPOP_REQUEST) &&
                    inet_addr_type(tip) == RTN_LOCAL &&
                    !arp_ignore(in_dev,dev,sip,tip))
-                       arp_send(ARPOP_REPLY,ETH_P_ARP,tip,dev,tip,sha,dev->dev_addr,dev->dev_addr);
+                       arp_send(ARPOP_REPLY, ETH_P_ARP, sip, dev, tip, sha,
+                                dev->dev_addr, sha);
                goto out;
        }
 
@@ -877,7 +860,7 @@ static int arp_process(struct sk_buff *skb)
 
        n = __neigh_lookup(&arp_tbl, &sip, dev, 0);
 
-       if (ipv4_devconf.arp_accept) {
+       if (IPV4_DEVCONF_ALL(ARP_ACCEPT)) {
                /* Unsolicited ARP is not accepted by default.
                   It is possible, that this option should be enabled for some
                   devices (strip is candidate)
@@ -885,7 +868,7 @@ static int arp_process(struct sk_buff *skb)
                if (n == NULL &&
                    arp->ar_op == htons(ARPOP_REPLY) &&
                    inet_addr_type(sip) == RTN_UNICAST)
-                       n = __neigh_lookup(&arp_tbl, &sip, dev, -1);
+                       n = __neigh_lookup(&arp_tbl, &sip, dev, 1);
        }
 
        if (n) {
@@ -931,13 +914,16 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,
 {
        struct arphdr *arp;
 
+       if (dev->nd_net != &init_net)
+               goto freeskb;
+
        /* ARP header, plus 2 device addresses, plus 2 IP addresses.  */
        if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
                                 (2 * dev->addr_len) +
                                 (2 * sizeof(u32)))))
                goto freeskb;
 
-       arp = skb->nh.arph;
+       arp = arp_hdr(skb);
        if (arp->ar_hln != dev->addr_len ||
            dev->flags & IFF_NOARP ||
            skb->pkt_type == PACKET_OTHERHOST ||
@@ -977,7 +963,7 @@ static int arp_req_set(struct arpreq *r, struct net_device * dev)
                if (mask && mask != htonl(0xFFFFFFFF))
                        return -EINVAL;
                if (!dev && (r->arp_flags & ATF_COM)) {
-                       dev = dev_getbyhwaddr(r->arp_ha.sa_family, r->arp_ha.sa_data);
+                       dev = dev_getbyhwaddr(&init_net, r->arp_ha.sa_family, r->arp_ha.sa_data);
                        if (!dev)
                                return -ENODEV;
                }
@@ -987,11 +973,11 @@ static int arp_req_set(struct arpreq *r, struct net_device * dev)
                        return 0;
                }
                if (dev == NULL) {
-                       ipv4_devconf.proxy_arp = 1;
+                       IPV4_DEVCONF_ALL(PROXY_ARP) = 1;
                        return 0;
                }
                if (__in_dev_get_rtnl(dev)) {
-                       __in_dev_get_rtnl(dev)->cnf.proxy_arp = 1;
+                       IN_DEV_CONF_SET(__in_dev_get_rtnl(dev), PROXY_ARP, 1);
                        return 0;
                }
                return -ENXIO;
@@ -1093,11 +1079,12 @@ static int arp_req_delete(struct arpreq *r, struct net_device * dev)
                        return pneigh_delete(&arp_tbl, &ip, dev);
                if (mask == 0) {
                        if (dev == NULL) {
-                               ipv4_devconf.proxy_arp = 0;
+                               IPV4_DEVCONF_ALL(PROXY_ARP) = 0;
                                return 0;
                        }
                        if (__in_dev_get_rtnl(dev)) {
-                               __in_dev_get_rtnl(dev)->cnf.proxy_arp = 0;
+                               IN_DEV_CONF_SET(__in_dev_get_rtnl(dev),
+                                               PROXY_ARP, 0);
                                return 0;
                        }
                        return -ENXIO;
@@ -1164,7 +1151,7 @@ int arp_ioctl(unsigned int cmd, void __user *arg)
        rtnl_lock();
        if (r.arp_dev[0]) {
                err = -ENODEV;
-               if ((dev = __dev_get_by_name(r.arp_dev)) == NULL)
+               if ((dev = __dev_get_by_name(&init_net, r.arp_dev)) == NULL)
                        goto out;
 
                /* Mmmm... It is wrong... ARPHRD_NETROM==0 */
@@ -1200,6 +1187,9 @@ static int arp_netdev_event(struct notifier_block *this, unsigned long event, vo
 {
        struct net_device *dev = ptr;
 
+       if (dev->nd_net != &init_net)
+               return NOTIFY_DONE;
+
        switch (event) {
        case NETDEV_CHANGEADDR:
                neigh_changeaddr(&arp_tbl, dev);
@@ -1360,7 +1350,7 @@ static void *arp_seq_start(struct seq_file *seq, loff_t *pos)
 
 /* ------------------------------------------------------------------------ */
 
-static struct seq_operations arp_seq_ops = {
+static const struct seq_operations arp_seq_ops = {
        .start  = arp_seq_start,
        .next   = neigh_seq_next,
        .stop   = neigh_seq_stop,
@@ -1369,24 +1359,8 @@ static struct seq_operations arp_seq_ops = {
 
 static int arp_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct neigh_seq_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
-
-       if (!s)
-               goto out;
-
-       rc = seq_open(file, &arp_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, &arp_seq_ops,
+                       sizeof(struct neigh_seq_state));
 }
 
 static const struct file_operations arp_seq_fops = {
@@ -1399,7 +1373,7 @@ static const struct file_operations arp_seq_fops = {
 
 static int __init arp_proc_init(void)
 {
-       if (!proc_net_fops_create("arp", S_IRUGO, &arp_seq_fops))
+       if (!proc_net_fops_create(&init_net, "arp", S_IRUGO, &arp_seq_fops))
                return -ENOMEM;
        return 0;
 }