diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-06-30 16:36:35 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-06-30 17:12:08 -0400 |
commit | bcd76111178ebccedd46a9b3eaff65c78e5a70af (patch) | |
tree | b0f059f3cb19d425d30cf42b2088aca4cae12a0a | |
parent | adcfc7d0b4d7bc3c7edac6fdde9f3ae510bd6054 (diff) |
[NET]: Generalise TSO-specific bits from skb_setup_caps
This patch generalises the TSO-specific bits from sk_setup_caps by adding
the sk_gso_type member to struct sock. This makes sk_setup_caps generic
so that it can be used by TCPv6 or UFO.
The only catch is that whoever uses this must provide a GSO implementation
for their protocol which I think is a fair deal :) For now UFO continues to
live without a GSO implementation which is OK since it doesn't use the sock
caps field at the moment.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/netdevice.h | 12 | ||||
-rw-r--r-- | include/net/sock.h | 13 | ||||
-rw-r--r-- | include/net/tcp.h | 2 | ||||
-rw-r--r-- | net/ipv4/tcp.c | 2 | ||||
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 2 | ||||
-rw-r--r-- | net/ipv4/tcp_output.c | 9 |
6 files changed, 26 insertions, 14 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index aa2d3c12c4d8..6db03ab7cec8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -313,6 +313,7 @@ struct net_device | |||
313 | 313 | ||
314 | /* Segmentation offload features */ | 314 | /* Segmentation offload features */ |
315 | #define NETIF_F_GSO_SHIFT 16 | 315 | #define NETIF_F_GSO_SHIFT 16 |
316 | #define NETIF_F_GSO_MASK 0xffff0000 | ||
316 | #define NETIF_F_TSO (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT) | 317 | #define NETIF_F_TSO (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT) |
317 | #define NETIF_F_UFO (SKB_GSO_UDPV4 << NETIF_F_GSO_SHIFT) | 318 | #define NETIF_F_UFO (SKB_GSO_UDPV4 << NETIF_F_GSO_SHIFT) |
318 | #define NETIF_F_GSO_ROBUST (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT) | 319 | #define NETIF_F_GSO_ROBUST (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT) |
@@ -991,13 +992,18 @@ extern void dev_seq_stop(struct seq_file *seq, void *v); | |||
991 | 992 | ||
992 | extern void linkwatch_run_queue(void); | 993 | extern void linkwatch_run_queue(void); |
993 | 994 | ||
994 | static inline int skb_gso_ok(struct sk_buff *skb, int features) | 995 | static inline int net_gso_ok(int features, int gso_type) |
995 | { | 996 | { |
996 | int feature = skb_shinfo(skb)->gso_size ? | 997 | int feature = gso_type << NETIF_F_GSO_SHIFT; |
997 | skb_shinfo(skb)->gso_type << NETIF_F_GSO_SHIFT : 0; | ||
998 | return (features & feature) == feature; | 998 | return (features & feature) == feature; |
999 | } | 999 | } |
1000 | 1000 | ||
1001 | static inline int skb_gso_ok(struct sk_buff *skb, int features) | ||
1002 | { | ||
1003 | return net_gso_ok(features, skb_shinfo(skb)->gso_size ? | ||
1004 | skb_shinfo(skb)->gso_type : 0); | ||
1005 | } | ||
1006 | |||
1001 | static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) | 1007 | static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) |
1002 | { | 1008 | { |
1003 | return !skb_gso_ok(skb, dev->features); | 1009 | return !skb_gso_ok(skb, dev->features); |
diff --git a/include/net/sock.h b/include/net/sock.h index 7136bae48c2f..7b3d6b856946 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -140,6 +140,7 @@ struct sock_common { | |||
140 | * @sk_flags: %SO_LINGER (l_onoff), %SO_BROADCAST, %SO_KEEPALIVE, %SO_OOBINLINE settings | 140 | * @sk_flags: %SO_LINGER (l_onoff), %SO_BROADCAST, %SO_KEEPALIVE, %SO_OOBINLINE settings |
141 | * @sk_no_check: %SO_NO_CHECK setting, wether or not checkup packets | 141 | * @sk_no_check: %SO_NO_CHECK setting, wether or not checkup packets |
142 | * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO) | 142 | * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO) |
143 | * @sk_gso_type: GSO type (e.g. %SKB_GSO_TCPV4) | ||
143 | * @sk_lingertime: %SO_LINGER l_linger setting | 144 | * @sk_lingertime: %SO_LINGER l_linger setting |
144 | * @sk_backlog: always used with the per-socket spinlock held | 145 | * @sk_backlog: always used with the per-socket spinlock held |
145 | * @sk_callback_lock: used with the callbacks in the end of this struct | 146 | * @sk_callback_lock: used with the callbacks in the end of this struct |
@@ -211,6 +212,7 @@ struct sock { | |||
211 | gfp_t sk_allocation; | 212 | gfp_t sk_allocation; |
212 | int sk_sndbuf; | 213 | int sk_sndbuf; |
213 | int sk_route_caps; | 214 | int sk_route_caps; |
215 | int sk_gso_type; | ||
214 | int sk_rcvlowat; | 216 | int sk_rcvlowat; |
215 | unsigned long sk_flags; | 217 | unsigned long sk_flags; |
216 | unsigned long sk_lingertime; | 218 | unsigned long sk_lingertime; |
@@ -1025,15 +1027,20 @@ extern struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie); | |||
1025 | 1027 | ||
1026 | extern struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie); | 1028 | extern struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie); |
1027 | 1029 | ||
1030 | static inline int sk_can_gso(const struct sock *sk) | ||
1031 | { | ||
1032 | return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type); | ||
1033 | } | ||
1034 | |||
1028 | static inline void sk_setup_caps(struct sock *sk, struct dst_entry *dst) | 1035 | static inline void sk_setup_caps(struct sock *sk, struct dst_entry *dst) |
1029 | { | 1036 | { |
1030 | __sk_dst_set(sk, dst); | 1037 | __sk_dst_set(sk, dst); |
1031 | sk->sk_route_caps = dst->dev->features; | 1038 | sk->sk_route_caps = dst->dev->features; |
1032 | if (sk->sk_route_caps & NETIF_F_GSO) | 1039 | if (sk->sk_route_caps & NETIF_F_GSO) |
1033 | sk->sk_route_caps |= NETIF_F_TSO; | 1040 | sk->sk_route_caps |= NETIF_F_GSO_MASK; |
1034 | if (sk->sk_route_caps & NETIF_F_TSO) { | 1041 | if (sk_can_gso(sk)) { |
1035 | if (dst->header_len) | 1042 | if (dst->header_len) |
1036 | sk->sk_route_caps &= ~NETIF_F_TSO; | 1043 | sk->sk_route_caps &= ~NETIF_F_GSO_MASK; |
1037 | else | 1044 | else |
1038 | sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM; | 1045 | sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM; |
1039 | } | 1046 | } |
diff --git a/include/net/tcp.h b/include/net/tcp.h index 624921e76332..3cd803b0d7a5 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h | |||
@@ -751,7 +751,7 @@ static inline int tcp_is_cwnd_limited(const struct sock *sk, u32 in_flight) | |||
751 | if (in_flight >= tp->snd_cwnd) | 751 | if (in_flight >= tp->snd_cwnd) |
752 | return 1; | 752 | return 1; |
753 | 753 | ||
754 | if (!(sk->sk_route_caps & NETIF_F_TSO)) | 754 | if (!sk_can_gso(sk)) |
755 | return 0; | 755 | return 0; |
756 | 756 | ||
757 | left = tp->snd_cwnd - in_flight; | 757 | left = tp->snd_cwnd - in_flight; |
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index b7cf26e0e5c2..59e30bab0606 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -643,7 +643,7 @@ static inline int select_size(struct sock *sk, struct tcp_sock *tp) | |||
643 | int tmp = tp->mss_cache; | 643 | int tmp = tp->mss_cache; |
644 | 644 | ||
645 | if (sk->sk_route_caps & NETIF_F_SG) { | 645 | if (sk->sk_route_caps & NETIF_F_SG) { |
646 | if (sk->sk_route_caps & NETIF_F_TSO) | 646 | if (sk_can_gso(sk)) |
647 | tmp = 0; | 647 | tmp = 0; |
648 | else { | 648 | else { |
649 | int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER); | 649 | int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER); |
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 4c6ef47eb1c3..38e001076a5f 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -242,6 +242,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
242 | goto failure; | 242 | goto failure; |
243 | 243 | ||
244 | /* OK, now commit destination to socket. */ | 244 | /* OK, now commit destination to socket. */ |
245 | sk->sk_gso_type = SKB_GSO_TCPV4; | ||
245 | sk_setup_caps(sk, &rt->u.dst); | 246 | sk_setup_caps(sk, &rt->u.dst); |
246 | 247 | ||
247 | if (!tp->write_seq) | 248 | if (!tp->write_seq) |
@@ -884,6 +885,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
884 | if (!newsk) | 885 | if (!newsk) |
885 | goto exit; | 886 | goto exit; |
886 | 887 | ||
888 | newsk->sk_gso_type = SKB_GSO_TCPV4; | ||
887 | sk_setup_caps(newsk, dst); | 889 | sk_setup_caps(newsk, dst); |
888 | 890 | ||
889 | newtp = tcp_sk(newsk); | 891 | newtp = tcp_sk(newsk); |
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 5a7cb4a9c867..5c08ea20a18d 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c | |||
@@ -510,8 +510,7 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb) | |||
510 | 510 | ||
511 | static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, unsigned int mss_now) | 511 | static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, unsigned int mss_now) |
512 | { | 512 | { |
513 | if (skb->len <= mss_now || | 513 | if (skb->len <= mss_now || !sk_can_gso(sk)) { |
514 | !(sk->sk_route_caps & NETIF_F_TSO)) { | ||
515 | /* Avoid the costly divide in the normal | 514 | /* Avoid the costly divide in the normal |
516 | * non-TSO case. | 515 | * non-TSO case. |
517 | */ | 516 | */ |
@@ -525,7 +524,7 @@ static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, unsigned | |||
525 | factor /= mss_now; | 524 | factor /= mss_now; |
526 | skb_shinfo(skb)->gso_segs = factor; | 525 | skb_shinfo(skb)->gso_segs = factor; |
527 | skb_shinfo(skb)->gso_size = mss_now; | 526 | skb_shinfo(skb)->gso_size = mss_now; |
528 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; | 527 | skb_shinfo(skb)->gso_type = sk->sk_gso_type; |
529 | } | 528 | } |
530 | } | 529 | } |
531 | 530 | ||
@@ -824,9 +823,7 @@ unsigned int tcp_current_mss(struct sock *sk, int large_allowed) | |||
824 | 823 | ||
825 | mss_now = tp->mss_cache; | 824 | mss_now = tp->mss_cache; |
826 | 825 | ||
827 | if (large_allowed && | 826 | if (large_allowed && sk_can_gso(sk) && !tp->urg_mode) |
828 | (sk->sk_route_caps & NETIF_F_TSO) && | ||
829 | !tp->urg_mode) | ||
830 | doing_tso = 1; | 827 | doing_tso = 1; |
831 | 828 | ||
832 | if (dst) { | 829 | if (dst) { |