]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[NET]: Wrap netdevice hardware header creation.
authorStephen Hemminger <shemminger@linux-foundation.org>
Tue, 9 Oct 2007 08:36:32 +0000 (01:36 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Wed, 10 Oct 2007 23:52:50 +0000 (16:52 -0700)
Add inline for common usage of hardware header creation, and
fix bug in IPV6 mcast where the assumption about negative return is
an errno. Negative return from hard_header means not enough space
was available,(ie -N bytes).

Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
19 files changed:
drivers/net/hamradio/bpqether.c
drivers/net/macvlan.c
drivers/net/pppoe.c
drivers/net/wan/lapbether.c
include/linux/netdevice.h
include/net/dn_route.h
net/802/p8023.c
net/8021q/vlan_dev.c
net/core/neighbour.c
net/core/netpoll.c
net/decnet/dn_neigh.c
net/econet/af_econet.c
net/ethernet/pe2.c
net/ipv4/arp.c
net/ipv4/ipconfig.c
net/ipv6/mcast.c
net/packet/af_packet.c
net/sched/sch_teql.c
net/tipc/eth_media.c

index c05bc37df356cbbf4c52f8b79db040df719f3195..4bff23e3b970c71bf4e8f840aa22861b76e5ca27 100644 (file)
@@ -286,7 +286,7 @@ static int bpq_xmit(struct sk_buff *skb, struct net_device *dev)
 
        skb->protocol = ax25_type_trans(skb, dev);
        skb_reset_network_header(skb);
-       dev->hard_header(skb, dev, ETH_P_BPQ, bpq->dest_addr, NULL, 0);
+       dev_hard_header(skb, dev, ETH_P_BPQ, bpq->dest_addr, NULL, 0);
        bpq->stats.tx_packets++;
        bpq->stats.tx_bytes+=skb->len;
   
index 2f6cdaa88729169a3e623d843f65adba82969da8..a22087ca968d869dd334bca799a84660cccc24a9 100644 (file)
@@ -170,8 +170,8 @@ static int macvlan_hard_header(struct sk_buff *skb, struct net_device *dev,
        const struct macvlan_dev *vlan = netdev_priv(dev);
        struct net_device *lowerdev = vlan->lowerdev;
 
-       return lowerdev->hard_header(skb, lowerdev, type, daddr,
-                                    saddr ? : dev->dev_addr, len);
+       return dev_hard_header(skb, lowerdev, type, daddr,
+                              saddr ? : dev->dev_addr, len);
 }
 
 static int macvlan_open(struct net_device *dev)
index d48b7b73d896cd87cdee9b343ca4d7c5fff7a089..8936ed3469cf0744a68ace9e205ea6a804ce3b85 100644 (file)
@@ -834,8 +834,8 @@ static int pppoe_sendmsg(struct kiocb *iocb, struct socket *sock,
        }
 
        error = total_len;
-       dev->hard_header(skb, dev, ETH_P_PPP_SES,
-                        po->pppoe_pa.remote, NULL, total_len);
+       dev_hard_header(skb, dev, ETH_P_PPP_SES,
+                       po->pppoe_pa.remote, NULL, total_len);
 
        memcpy(ph, &hdr, sizeof(struct pppoe_hdr));
 
@@ -886,8 +886,8 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
        skb->protocol = __constant_htons(ETH_P_PPP_SES);
        skb->dev = dev;
 
-       dev->hard_header(skb, dev, ETH_P_PPP_SES,
-                        po->pppoe_pa.remote, NULL, data_len);
+       dev_hard_header(skb, dev, ETH_P_PPP_SES,
+                       po->pppoe_pa.remote, NULL, data_len);
 
        dev_queue_xmit(skb);
 
index 36e683ccae5e9896af3e589a58200c423f7d2314..fb37b809523150d2424710d7cdfdb5c1bff206e7 100644 (file)
@@ -216,7 +216,7 @@ static void lapbeth_data_transmit(struct net_device *ndev, struct sk_buff *skb)
 
        skb->dev = dev = lapbeth->ethdev;
 
-       dev->hard_header(skb, dev, ETH_P_DEC, bcast_addr, NULL, 0);
+       dev_hard_header(skb, dev, ETH_P_DEC, bcast_addr, NULL, 0);
 
        dev_queue_xmit(skb);
 }
index 71cf409ad17e1d44fd5df770ad76fb7fd5335493..b33d084712fa410b7c8348f4bb628c65447fb07b 100644 (file)
@@ -800,6 +800,15 @@ extern int         dev_restart(struct net_device *dev);
 extern int             netpoll_trap(void);
 #endif
 
+static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
+                                 unsigned short type,
+                                 void *daddr, void *saddr, unsigned len)
+{
+       if (!dev->hard_header)
+               return 0;
+       return dev->hard_header(skb, dev, type, daddr, saddr, len);
+}
+
 typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len);
 extern int             register_gifconf(unsigned int family, gifconf_func_t * gifconf);
 static inline int unregister_gifconf(unsigned int family)
index c10e8e7e59a7a2b0a5c3aa4adc28f2b79d20036b..60c9f22d86943f0aa19ecdc18d513a24e763b9b1 100644 (file)
@@ -100,8 +100,7 @@ static inline void dn_rt_finish_output(struct sk_buff *skb, char *dst, char *src
        if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
                dst = NULL;
 
-       if (!dev->hard_header || (dev->hard_header(skb, dev, ETH_P_DNA_RT,
-                       dst, src, skb->len) >= 0))
+       if (dev_hard_header(skb, dev, ETH_P_DNA_RT, dst, src, skb->len) >= 0)
                dn_rt_send(skb);
        else
                kfree_skb(skb);
index 53cf05709283662f16578fab5cd06972c07eec16..6ab1835041a7485f1d4e23cadb7e3b35f6fcc631 100644 (file)
@@ -31,7 +31,7 @@ static int p8023_request(struct datalink_proto *dl,
 {
        struct net_device *dev = skb->dev;
 
-       dev->hard_header(skb, dev, ETH_P_802_3, dest_node, NULL, skb->len);
+       dev_hard_header(skb, dev, ETH_P_802_3, dest_node, NULL, skb->len);
        return dev_queue_xmit(skb);
 }
 
index 6644e8f5f19992a62010bd3f9810fa39bdf8be7c..ca8090fdabbbd20129dab913cfe66d5aec21ede1 100644 (file)
@@ -434,21 +434,19 @@ int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
 
        if (build_vlan_header) {
                /* Now make the underlying real hard header */
-               rc = dev->hard_header(skb, dev, ETH_P_8021Q, daddr, saddr, len + VLAN_HLEN);
-
-               if (rc > 0) {
+               rc = dev_hard_header(skb, dev, ETH_P_8021Q, daddr, saddr,
+                                    len + VLAN_HLEN);
+               if (rc > 0)
                        rc += VLAN_HLEN;
-               } else if (rc < 0) {
+               else if (rc < 0)
                        rc -= VLAN_HLEN;
-               }
-       } else {
+       } else
                /* If here, then we'll just make a normal looking ethernet frame,
                 * but, the hard_start_xmit method will insert the tag (it has to
                 * be able to do this for bridged and other skbs that don't come
                 * down the protocol stack in an orderly manner.
                 */
-               rc = dev->hard_header(skb, dev, type, daddr, saddr, len);
-       }
+               rc = dev_hard_header(skb, dev, type, daddr, saddr, len);
 
        return rc;
 }
index 2c6577c1eedd7947dbb5d0ae147dc759eba02710..10bcb9f8da5ce65abf9c62b65a2c1ae556b6d066 100644 (file)
@@ -1125,9 +1125,8 @@ int neigh_compat_output(struct sk_buff *skb)
 
        __skb_pull(skb, skb_network_offset(skb));
 
-       if (dev->hard_header &&
-           dev->hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL,
-                            skb->len) < 0 &&
+       if (dev_hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL,
+                           skb->len) < 0 &&
            dev->rebuild_header(skb))
                return 0;
 
@@ -1154,13 +1153,13 @@ int neigh_resolve_output(struct sk_buff *skb)
                        write_lock_bh(&neigh->lock);
                        if (!dst->hh)
                                neigh_hh_init(neigh, dst, dst->ops->protocol);
-                       err = dev->hard_header(skb, dev, ntohs(skb->protocol),
-                                              neigh->ha, NULL, skb->len);
+                       err = dev_hard_header(skb, dev, ntohs(skb->protocol),
+                                             neigh->ha, NULL, skb->len);
                        write_unlock_bh(&neigh->lock);
                } else {
                        read_lock_bh(&neigh->lock);
-                       err = dev->hard_header(skb, dev, ntohs(skb->protocol),
-                                              neigh->ha, NULL, skb->len);
+                       err = dev_hard_header(skb, dev, ntohs(skb->protocol),
+                                             neigh->ha, NULL, skb->len);
                        read_unlock_bh(&neigh->lock);
                }
                if (err >= 0)
@@ -1191,8 +1190,8 @@ int neigh_connected_output(struct sk_buff *skb)
        __skb_pull(skb, skb_network_offset(skb));
 
        read_lock_bh(&neigh->lock);
-       err = dev->hard_header(skb, dev, ntohs(skb->protocol),
-                              neigh->ha, NULL, skb->len);
+       err = dev_hard_header(skb, dev, ntohs(skb->protocol),
+                             neigh->ha, NULL, skb->len);
        read_unlock_bh(&neigh->lock);
        if (err >= 0)
                err = neigh->ops->queue_xmit(skb);
index e13602d8154db3b3b02042ffc7c0081d1c04f76e..95daba6249676dc8e466303279cadc1223e57d81 100644 (file)
@@ -415,11 +415,9 @@ static void arp_reply(struct sk_buff *skb)
        send_skb->protocol = htons(ETH_P_ARP);
 
        /* Fill the device header for the ARP frame */
-
-       if (np->dev->hard_header &&
-           np->dev->hard_header(send_skb, skb->dev, ptype,
-                                sha, np->local_mac,
-                                send_skb->len) < 0) {
+       if (dev_hard_header(send_skb, skb->dev, ptype,
+                           sha, np->local_mac,
+                           send_skb->len) < 0) {
                kfree_skb(send_skb);
                return;
        }
index a424a8ddbaf74d210626135a6fd6800e0c24eb00..b66e3be3eb84a224fa188d101ff7f297760104ee 100644 (file)
@@ -211,7 +211,8 @@ static int dn_neigh_output_packet(struct sk_buff *skb)
        char mac_addr[ETH_ALEN];
 
        dn_dn2eth(mac_addr, rt->rt_local_src);
-       if (!dev->hard_header || dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha, mac_addr, skb->len) >= 0)
+       if (dev_hard_header(skb, dev, ntohs(skb->protocol), neigh->ha,
+                           mac_addr, skb->len) >= 0)
                return neigh->ops->queue_xmit(skb);
 
        if (net_ratelimit())
index 9938e76a8ff62a6f9854e61a169ea63fb316dd34..9cae16b4e0b7cea737c88a763d34a8eb49d079a8 100644 (file)
@@ -336,6 +336,7 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
                /* Real hardware Econet.  We're not worthy etc. */
 #ifdef CONFIG_ECONET_NATIVE
                unsigned short proto = 0;
+               int res;
 
                dev_hold(dev);
 
@@ -354,12 +355,12 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
                eb->sec = *saddr;
                eb->sent = ec_tx_done;
 
-               if (dev->hard_header) {
-                       int res;
+               err = -EINVAL;
+               res = dev_hard_header(skb, dev, ntohs(proto), &addr, NULL, len);
+               if (res < 0)
+                       goto out_free;
+               if (res > 0) {
                        struct ec_framehdr *fh;
-                       err = -EINVAL;
-                       res = dev->hard_header(skb, dev, ntohs(proto),
-                                              &addr, NULL, len);
                        /* Poke in our control byte and
                           port number.  Hack, hack.  */
                        fh = (struct ec_framehdr *)(skb->data);
@@ -368,8 +369,7 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
                        if (sock->type != SOCK_DGRAM) {
                                skb_reset_tail_pointer(skb);
                                skb->len = 0;
-                       } else if (res < 0)
-                               goto out_free;
+                       }
                }
 
                /* Copy the data. Returns -EFAULT on error */
index 9d57b4fb6440c74532856b9fc4160821aa19d2b8..d60e15d9365e720b56f823c1842170d12de8a218 100644 (file)
@@ -12,9 +12,7 @@ static int pEII_request(struct datalink_proto *dl,
        struct net_device *dev = skb->dev;
 
        skb->protocol = htons(ETH_P_IPX);
-       if (dev->hard_header)
-               dev->hard_header(skb, dev, ETH_P_IPX,
-                                dest_node, NULL, skb->len);
+       dev_hard_header(skb, dev, ETH_P_IPX, dest_node, NULL, skb->len);
        return dev_queue_xmit(skb);
 }
 
index 3a683006d761ea10d64ca2d926b5b3c122b5f315..5b24c65b13c6fa5fced2eb4b0f98127b3c232ca7 100644 (file)
@@ -591,8 +591,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;
 
        /*
index af5d5b39fc139d9f4c4fc673a755a4bda521e32c..c5c107a01823097120b21698ed24021647abb24e 100644 (file)
@@ -757,8 +757,8 @@ static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_d
        /* Chain packet down the line... */
        skb->dev = dev;
        skb->protocol = htons(ETH_P_IP);
-       if ((dev->hard_header &&
-            dev->hard_header(skb, dev, ntohs(skb->protocol), dev->broadcast, dev->dev_addr, skb->len) < 0) ||
+       if (dev_hard_header(skb, dev, ntohs(skb->protocol),
+                           dev->broadcast, dev->dev_addr, skb->len) < 0 ||
            dev_queue_xmit(skb) < 0)
                printk("E");
 }
index 86d908b1caea1ac0c9bbbe6d78f8ea7fff05663d..8668ab3af32e9c613c14bfb6fea16a0adb6b4fee 100644 (file)
@@ -1438,17 +1438,12 @@ static struct sk_buff *mld_newpack(struct net_device *dev, int size)
 static inline int mld_dev_queue_xmit2(struct sk_buff *skb)
 {
        struct net_device *dev = skb->dev;
+       unsigned char ha[MAX_ADDR_LEN];
 
-       if (dev->hard_header) {
-               unsigned char ha[MAX_ADDR_LEN];
-               int err;
-
-               ndisc_mc_map(&ipv6_hdr(skb)->daddr, ha, dev, 1);
-               err = dev->hard_header(skb, dev, ETH_P_IPV6, ha, NULL, skb->len);
-               if (err < 0) {
-                       kfree_skb(skb);
-                       return err;
-               }
+       ndisc_mc_map(&ipv6_hdr(skb)->daddr, ha, dev, 1);
+       if (dev_hard_header(skb, dev, ETH_P_IPV6, ha, NULL, skb->len) < 0) {
+               kfree_skb(skb);
+               return -EINVAL;
        }
        return dev_queue_xmit(skb);
 }
index 745e2cb87c96a236b844f12f32f5c8e4fbd38d9e..c5244b3096403e510f49a24d087eb9fed49d0dbb 100644 (file)
@@ -765,16 +765,10 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
        skb_reserve(skb, LL_RESERVED_SPACE(dev));
        skb_reset_network_header(skb);
 
-       if (dev->hard_header) {
-               int res;
-               err = -EINVAL;
-               res = dev->hard_header(skb, dev, ntohs(proto), addr, NULL, len);
-               if (sock->type != SOCK_DGRAM) {
-                       skb_reset_tail_pointer(skb);
-                       skb->len = 0;
-               } else if (res < 0)
-                       goto out_free;
-       }
+       err = -EINVAL;
+       if (sock->type == SOCK_DGRAM &&
+           dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len) < 0)
+               goto out_free;
 
        /* Returns -EFAULT on error */
        err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
index 146f453d73784cd5e139ff49f613f2877f908012..d13970f3c7b121ddf28c9c6560aae3ef9acbcab1 100644 (file)
@@ -232,9 +232,12 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res, struct net_device *
        }
        if (neigh_event_send(n, skb_res) == 0) {
                int err;
+
                read_lock(&n->lock);
-               err = dev->hard_header(skb, dev, ntohs(skb->protocol), n->ha, NULL, skb->len);
+               err = dev_hard_header(skb, dev, ntohs(skb->protocol),
+                                     n->ha, NULL, skb->len);
                read_unlock(&n->lock);
+
                if (err < 0) {
                        neigh_release(n);
                        return -EINVAL;
index 1a99e294714508de2693d381b9de60eb8388b53e..3bbef2ab22ae8c6ead19093ee0bcebbf0efc04c1 100644 (file)
@@ -77,7 +77,7 @@ static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr,
                skb_reset_network_header(clone);
                dev = ((struct eth_bearer *)(tb_ptr->usr_handle))->dev;
                clone->dev = dev;
-               dev->hard_header(clone, dev, ETH_P_TIPC,
+               dev_hard_header(clone, dev, ETH_P_TIPC,
                                 &dest->dev_addr.eth_addr,
                                 dev->dev_addr, clone->len);
                dev_queue_xmit(clone);