diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2008-05-12 23:48:31 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-05-12 23:48:31 -0400 |
commit | f5184d267c1aedb9b7a8cc44e08ff6b8d382c3b5 (patch) | |
tree | 5ccce7558f9e1e53e5b189d6e2fe62a667988ac8 | |
parent | 8388e3da34edb141362bb42811ee487dfec15525 (diff) |
net: Allow netdevices to specify needed head/tailroom
This patch adds needed_headroom/needed_tailroom members to struct
net_device and updates many places that allocate sbks to use them. Not
all of them can be converted though, and I'm sure I missed some (I
mostly grepped for LL_RESERVED_SPACE)
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/netdevice.h | 16 | ||||
-rw-r--r-- | net/core/netpoll.c | 2 | ||||
-rw-r--r-- | net/econet/af_econet.c | 2 | ||||
-rw-r--r-- | net/ipv4/arp.c | 2 | ||||
-rw-r--r-- | net/ipv4/igmp.c | 4 | ||||
-rw-r--r-- | net/ipv4/ipconfig.c | 6 | ||||
-rw-r--r-- | net/ipv4/raw.c | 10 | ||||
-rw-r--r-- | net/ipv6/ip6_output.c | 2 | ||||
-rw-r--r-- | net/ipv6/mcast.c | 4 | ||||
-rw-r--r-- | net/ipv6/ndisc.c | 4 | ||||
-rw-r--r-- | net/ipv6/raw.c | 10 | ||||
-rw-r--r-- | net/packet/af_packet.c | 2 | ||||
-rw-r--r-- | net/xfrm/xfrm_output.c | 6 |
13 files changed, 39 insertions, 31 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index a3fb57fde623..b11e6e19e96c 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -246,11 +246,16 @@ struct hh_cache | |||
246 | * | 246 | * |
247 | * We could use other alignment values, but we must maintain the | 247 | * We could use other alignment values, but we must maintain the |
248 | * relationship HH alignment <= LL alignment. | 248 | * relationship HH alignment <= LL alignment. |
249 | * | ||
250 | * LL_ALLOCATED_SPACE also takes into account the tailroom the device | ||
251 | * may need. | ||
249 | */ | 252 | */ |
250 | #define LL_RESERVED_SPACE(dev) \ | 253 | #define LL_RESERVED_SPACE(dev) \ |
251 | (((dev)->hard_header_len&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) | 254 | ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) |
252 | #define LL_RESERVED_SPACE_EXTRA(dev,extra) \ | 255 | #define LL_RESERVED_SPACE_EXTRA(dev,extra) \ |
253 | ((((dev)->hard_header_len+extra)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) | 256 | ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) |
257 | #define LL_ALLOCATED_SPACE(dev) \ | ||
258 | ((((dev)->hard_header_len+(dev)->needed_headroom+(dev)->needed_tailroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) | ||
254 | 259 | ||
255 | struct header_ops { | 260 | struct header_ops { |
256 | int (*create) (struct sk_buff *skb, struct net_device *dev, | 261 | int (*create) (struct sk_buff *skb, struct net_device *dev, |
@@ -569,6 +574,13 @@ struct net_device | |||
569 | unsigned short type; /* interface hardware type */ | 574 | unsigned short type; /* interface hardware type */ |
570 | unsigned short hard_header_len; /* hardware hdr length */ | 575 | unsigned short hard_header_len; /* hardware hdr length */ |
571 | 576 | ||
577 | /* extra head- and tailroom the hardware may need, but not in all cases | ||
578 | * can this be guaranteed, especially tailroom. Some cases also use | ||
579 | * LL_MAX_HEADER instead to allocate the skb. | ||
580 | */ | ||
581 | unsigned short needed_headroom; | ||
582 | unsigned short needed_tailroom; | ||
583 | |||
572 | struct net_device *master; /* Pointer to master device of a group, | 584 | struct net_device *master; /* Pointer to master device of a group, |
573 | * which this device is member of. | 585 | * which this device is member of. |
574 | */ | 586 | */ |
diff --git a/net/core/netpoll.c b/net/core/netpoll.c index b04d643fc3c7..8fb134da0346 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c | |||
@@ -419,7 +419,7 @@ static void arp_reply(struct sk_buff *skb) | |||
419 | return; | 419 | return; |
420 | 420 | ||
421 | size = arp_hdr_len(skb->dev); | 421 | size = arp_hdr_len(skb->dev); |
422 | send_skb = find_skb(np, size + LL_RESERVED_SPACE(np->dev), | 422 | send_skb = find_skb(np, size + LL_ALLOCATED_SPACE(np->dev), |
423 | LL_RESERVED_SPACE(np->dev)); | 423 | LL_RESERVED_SPACE(np->dev)); |
424 | 424 | ||
425 | if (!send_skb) | 425 | if (!send_skb) |
diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c index 68d154480043..7c9bb13b1539 100644 --- a/net/econet/af_econet.c +++ b/net/econet/af_econet.c | |||
@@ -340,7 +340,7 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
340 | 340 | ||
341 | dev_hold(dev); | 341 | dev_hold(dev); |
342 | 342 | ||
343 | skb = sock_alloc_send_skb(sk, len+LL_RESERVED_SPACE(dev), | 343 | skb = sock_alloc_send_skb(sk, len+LL_ALLOCATED_SPACE(dev), |
344 | msg->msg_flags & MSG_DONTWAIT, &err); | 344 | msg->msg_flags & MSG_DONTWAIT, &err); |
345 | if (skb==NULL) | 345 | if (skb==NULL) |
346 | goto out_unlock; | 346 | goto out_unlock; |
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 68b72a7a1806..418862f1bf22 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c | |||
@@ -570,7 +570,7 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip, | |||
570 | * Allocate a buffer | 570 | * Allocate a buffer |
571 | */ | 571 | */ |
572 | 572 | ||
573 | skb = alloc_skb(arp_hdr_len(dev) + LL_RESERVED_SPACE(dev), GFP_ATOMIC); | 573 | skb = alloc_skb(arp_hdr_len(dev) + LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); |
574 | if (skb == NULL) | 574 | if (skb == NULL) |
575 | return NULL; | 575 | return NULL; |
576 | 576 | ||
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 6250f4239b61..2769dc4a4c84 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c | |||
@@ -292,7 +292,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size) | |||
292 | struct iphdr *pip; | 292 | struct iphdr *pip; |
293 | struct igmpv3_report *pig; | 293 | struct igmpv3_report *pig; |
294 | 294 | ||
295 | skb = alloc_skb(size + LL_RESERVED_SPACE(dev), GFP_ATOMIC); | 295 | skb = alloc_skb(size + LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); |
296 | if (skb == NULL) | 296 | if (skb == NULL) |
297 | return NULL; | 297 | return NULL; |
298 | 298 | ||
@@ -653,7 +653,7 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc, | |||
653 | return -1; | 653 | return -1; |
654 | } | 654 | } |
655 | 655 | ||
656 | skb=alloc_skb(IGMP_SIZE+LL_RESERVED_SPACE(dev), GFP_ATOMIC); | 656 | skb=alloc_skb(IGMP_SIZE+LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); |
657 | if (skb == NULL) { | 657 | if (skb == NULL) { |
658 | ip_rt_put(rt); | 658 | ip_rt_put(rt); |
659 | return -1; | 659 | return -1; |
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c index 89dee4346f60..ed45037ce9be 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c | |||
@@ -710,14 +710,14 @@ static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_d | |||
710 | struct net_device *dev = d->dev; | 710 | struct net_device *dev = d->dev; |
711 | struct sk_buff *skb; | 711 | struct sk_buff *skb; |
712 | struct bootp_pkt *b; | 712 | struct bootp_pkt *b; |
713 | int hh_len = LL_RESERVED_SPACE(dev); | ||
714 | struct iphdr *h; | 713 | struct iphdr *h; |
715 | 714 | ||
716 | /* Allocate packet */ | 715 | /* Allocate packet */ |
717 | skb = alloc_skb(sizeof(struct bootp_pkt) + hh_len + 15, GFP_KERNEL); | 716 | skb = alloc_skb(sizeof(struct bootp_pkt) + LL_ALLOCATED_SPACE(dev) + 15, |
717 | GFP_KERNEL); | ||
718 | if (!skb) | 718 | if (!skb) |
719 | return; | 719 | return; |
720 | skb_reserve(skb, hh_len); | 720 | skb_reserve(skb, LL_RESERVED_SPACE(dev)); |
721 | b = (struct bootp_pkt *) skb_put(skb, sizeof(struct bootp_pkt)); | 721 | b = (struct bootp_pkt *) skb_put(skb, sizeof(struct bootp_pkt)); |
722 | memset(b, 0, sizeof(struct bootp_pkt)); | 722 | memset(b, 0, sizeof(struct bootp_pkt)); |
723 | 723 | ||
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 11d7f753a820..fead049daf43 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -322,7 +322,6 @@ static int raw_send_hdrinc(struct sock *sk, void *from, size_t length, | |||
322 | unsigned int flags) | 322 | unsigned int flags) |
323 | { | 323 | { |
324 | struct inet_sock *inet = inet_sk(sk); | 324 | struct inet_sock *inet = inet_sk(sk); |
325 | int hh_len; | ||
326 | struct iphdr *iph; | 325 | struct iphdr *iph; |
327 | struct sk_buff *skb; | 326 | struct sk_buff *skb; |
328 | unsigned int iphlen; | 327 | unsigned int iphlen; |
@@ -336,13 +335,12 @@ static int raw_send_hdrinc(struct sock *sk, void *from, size_t length, | |||
336 | if (flags&MSG_PROBE) | 335 | if (flags&MSG_PROBE) |
337 | goto out; | 336 | goto out; |
338 | 337 | ||
339 | hh_len = LL_RESERVED_SPACE(rt->u.dst.dev); | 338 | skb = sock_alloc_send_skb(sk, |
340 | 339 | length + LL_ALLOCATED_SPACE(rt->u.dst.dev) + 15, | |
341 | skb = sock_alloc_send_skb(sk, length+hh_len+15, | 340 | flags & MSG_DONTWAIT, &err); |
342 | flags&MSG_DONTWAIT, &err); | ||
343 | if (skb == NULL) | 341 | if (skb == NULL) |
344 | goto error; | 342 | goto error; |
345 | skb_reserve(skb, hh_len); | 343 | skb_reserve(skb, LL_RESERVED_SPACE(rt->u.dst.dev)); |
346 | 344 | ||
347 | skb->priority = sk->sk_priority; | 345 | skb->priority = sk->sk_priority; |
348 | skb->mark = sk->sk_mark; | 346 | skb->mark = sk->sk_mark; |
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 0af2e055f883..48cdce9c696c 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c | |||
@@ -780,7 +780,7 @@ slow_path: | |||
780 | * Allocate buffer. | 780 | * Allocate buffer. |
781 | */ | 781 | */ |
782 | 782 | ||
783 | if ((frag = alloc_skb(len+hlen+sizeof(struct frag_hdr)+LL_RESERVED_SPACE(rt->u.dst.dev), GFP_ATOMIC)) == NULL) { | 783 | if ((frag = alloc_skb(len+hlen+sizeof(struct frag_hdr)+LL_ALLOCATED_SPACE(rt->u.dst.dev), GFP_ATOMIC)) == NULL) { |
784 | NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n"); | 784 | NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n"); |
785 | IP6_INC_STATS(ip6_dst_idev(skb->dst), | 785 | IP6_INC_STATS(ip6_dst_idev(skb->dst), |
786 | IPSTATS_MIB_FRAGFAILS); | 786 | IPSTATS_MIB_FRAGFAILS); |
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index 54f91efdae58..fd632dd7f98d 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c | |||
@@ -1411,7 +1411,7 @@ static struct sk_buff *mld_newpack(struct net_device *dev, int size) | |||
1411 | IPV6_TLV_PADN, 0 }; | 1411 | IPV6_TLV_PADN, 0 }; |
1412 | 1412 | ||
1413 | /* we assume size > sizeof(ra) here */ | 1413 | /* we assume size > sizeof(ra) here */ |
1414 | skb = sock_alloc_send_skb(sk, size + LL_RESERVED_SPACE(dev), 1, &err); | 1414 | skb = sock_alloc_send_skb(sk, size + LL_ALLOCATED_SPACE(dev), 1, &err); |
1415 | 1415 | ||
1416 | if (!skb) | 1416 | if (!skb) |
1417 | return NULL; | 1417 | return NULL; |
@@ -1790,7 +1790,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) | |||
1790 | payload_len = len + sizeof(ra); | 1790 | payload_len = len + sizeof(ra); |
1791 | full_len = sizeof(struct ipv6hdr) + payload_len; | 1791 | full_len = sizeof(struct ipv6hdr) + payload_len; |
1792 | 1792 | ||
1793 | skb = sock_alloc_send_skb(sk, LL_RESERVED_SPACE(dev) + full_len, 1, &err); | 1793 | skb = sock_alloc_send_skb(sk, LL_ALLOCATED_SPACE(dev) + full_len, 1, &err); |
1794 | 1794 | ||
1795 | if (skb == NULL) { | 1795 | if (skb == NULL) { |
1796 | rcu_read_lock(); | 1796 | rcu_read_lock(); |
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 2c74885f8355..a55fc05b8125 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c | |||
@@ -479,7 +479,7 @@ static void __ndisc_send(struct net_device *dev, | |||
479 | 479 | ||
480 | skb = sock_alloc_send_skb(sk, | 480 | skb = sock_alloc_send_skb(sk, |
481 | (MAX_HEADER + sizeof(struct ipv6hdr) + | 481 | (MAX_HEADER + sizeof(struct ipv6hdr) + |
482 | len + LL_RESERVED_SPACE(dev)), | 482 | len + LL_ALLOCATED_SPACE(dev)), |
483 | 1, &err); | 483 | 1, &err); |
484 | if (!skb) { | 484 | if (!skb) { |
485 | ND_PRINTK0(KERN_ERR | 485 | ND_PRINTK0(KERN_ERR |
@@ -1521,7 +1521,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh, | |||
1521 | 1521 | ||
1522 | buff = sock_alloc_send_skb(sk, | 1522 | buff = sock_alloc_send_skb(sk, |
1523 | (MAX_HEADER + sizeof(struct ipv6hdr) + | 1523 | (MAX_HEADER + sizeof(struct ipv6hdr) + |
1524 | len + LL_RESERVED_SPACE(dev)), | 1524 | len + LL_ALLOCATED_SPACE(dev)), |
1525 | 1, &err); | 1525 | 1, &err); |
1526 | if (buff == NULL) { | 1526 | if (buff == NULL) { |
1527 | ND_PRINTK0(KERN_ERR | 1527 | ND_PRINTK0(KERN_ERR |
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 396f0ea11090..232e0dc45bf5 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c | |||
@@ -609,7 +609,6 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length, | |||
609 | struct ipv6_pinfo *np = inet6_sk(sk); | 609 | struct ipv6_pinfo *np = inet6_sk(sk); |
610 | struct ipv6hdr *iph; | 610 | struct ipv6hdr *iph; |
611 | struct sk_buff *skb; | 611 | struct sk_buff *skb; |
612 | unsigned int hh_len; | ||
613 | int err; | 612 | int err; |
614 | 613 | ||
615 | if (length > rt->u.dst.dev->mtu) { | 614 | if (length > rt->u.dst.dev->mtu) { |
@@ -619,13 +618,12 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length, | |||
619 | if (flags&MSG_PROBE) | 618 | if (flags&MSG_PROBE) |
620 | goto out; | 619 | goto out; |
621 | 620 | ||
622 | hh_len = LL_RESERVED_SPACE(rt->u.dst.dev); | 621 | skb = sock_alloc_send_skb(sk, |
623 | 622 | length + LL_ALLOCATED_SPACE(rt->u.dst.dev) + 15, | |
624 | skb = sock_alloc_send_skb(sk, length+hh_len+15, | 623 | flags & MSG_DONTWAIT, &err); |
625 | flags&MSG_DONTWAIT, &err); | ||
626 | if (skb == NULL) | 624 | if (skb == NULL) |
627 | goto error; | 625 | goto error; |
628 | skb_reserve(skb, hh_len); | 626 | skb_reserve(skb, LL_RESERVED_SPACE(rt->u.dst.dev)); |
629 | 627 | ||
630 | skb->priority = sk->sk_priority; | 628 | skb->priority = sk->sk_priority; |
631 | skb->mark = sk->sk_mark; | 629 | skb->mark = sk->sk_mark; |
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 25070240d4ae..2cee87da4441 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -743,7 +743,7 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
743 | if (len > dev->mtu+reserve) | 743 | if (len > dev->mtu+reserve) |
744 | goto out_unlock; | 744 | goto out_unlock; |
745 | 745 | ||
746 | skb = sock_alloc_send_skb(sk, len + LL_RESERVED_SPACE(dev), | 746 | skb = sock_alloc_send_skb(sk, len + LL_ALLOCATED_SPACE(dev), |
747 | msg->msg_flags & MSG_DONTWAIT, &err); | 747 | msg->msg_flags & MSG_DONTWAIT, &err); |
748 | if (skb==NULL) | 748 | if (skb==NULL) |
749 | goto out_unlock; | 749 | goto out_unlock; |
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c index 09cd9c0c2d80..3f964db908a7 100644 --- a/net/xfrm/xfrm_output.c +++ b/net/xfrm/xfrm_output.c | |||
@@ -25,11 +25,11 @@ static int xfrm_state_check_space(struct xfrm_state *x, struct sk_buff *skb) | |||
25 | struct dst_entry *dst = skb->dst; | 25 | struct dst_entry *dst = skb->dst; |
26 | int nhead = dst->header_len + LL_RESERVED_SPACE(dst->dev) | 26 | int nhead = dst->header_len + LL_RESERVED_SPACE(dst->dev) |
27 | - skb_headroom(skb); | 27 | - skb_headroom(skb); |
28 | int ntail = dst->dev->needed_tailroom - skb_tailroom(skb); | ||
28 | 29 | ||
29 | if (nhead > 0) | 30 | if (nhead > 0 || ntail > 0) |
30 | return pskb_expand_head(skb, nhead, 0, GFP_ATOMIC); | 31 | return pskb_expand_head(skb, nhead, ntail, GFP_ATOMIC); |
31 | 32 | ||
32 | /* Check tail too... */ | ||
33 | return 0; | 33 | return 0; |
34 | } | 34 | } |
35 | 35 | ||