diff options
author | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2011-10-17 19:07:30 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-10-17 19:07:30 -0400 |
commit | f36c23bb9f822904dacf83a329518d0a5fde7968 (patch) | |
tree | fc7808103cdf00bb8a42247fccf638014798dd35 /include/net/udplite.h | |
parent | 4c41042d1d4c29e596b31e2d14b26d2940fb24b4 (diff) |
udplite: fast-path computation of checksum coverage
Commit 903ab86d195cca295379699299c5fc10beba31c7 of 1 March this year ("udp: Add
lockless transmit path") introduced a new fast TX path that broke the checksum
coverage computation of UDP-lite, which so far depended on up->len (only set
if the socket is locked and 0 in the fast path).
Fixed by providing both fast- and slow-path computation of checksum coverage.
The latter can be removed when UDP(-lite)v6 also uses a lockless transmit path.
Reported-by: Thomas Volkert <thomas@homer-conferencing.com>
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/udplite.h')
-rw-r--r-- | include/net/udplite.h | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/include/net/udplite.h b/include/net/udplite.h index 673a024c6b2a..5f097ca7d5c5 100644 --- a/include/net/udplite.h +++ b/include/net/udplite.h | |||
@@ -66,40 +66,34 @@ static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh) | |||
66 | return 0; | 66 | return 0; |
67 | } | 67 | } |
68 | 68 | ||
69 | static inline int udplite_sender_cscov(struct udp_sock *up, struct udphdr *uh) | 69 | /* Slow-path computation of checksum. Socket is locked. */ |
70 | static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb) | ||
70 | { | 71 | { |
72 | const struct udp_sock *up = udp_sk(skb->sk); | ||
71 | int cscov = up->len; | 73 | int cscov = up->len; |
74 | __wsum csum = 0; | ||
72 | 75 | ||
73 | /* | 76 | if (up->pcflag & UDPLITE_SEND_CC) { |
74 | * Sender has set `partial coverage' option on UDP-Lite socket | 77 | /* |
75 | */ | 78 | * Sender has set `partial coverage' option on UDP-Lite socket. |
76 | if (up->pcflag & UDPLITE_SEND_CC) { | 79 | * The special case "up->pcslen == 0" signifies full coverage. |
80 | */ | ||
77 | if (up->pcslen < up->len) { | 81 | if (up->pcslen < up->len) { |
78 | /* up->pcslen == 0 means that full coverage is required, | 82 | if (0 < up->pcslen) |
79 | * partial coverage only if 0 < up->pcslen < up->len */ | 83 | cscov = up->pcslen; |
80 | if (0 < up->pcslen) { | 84 | udp_hdr(skb)->len = htons(up->pcslen); |
81 | cscov = up->pcslen; | ||
82 | } | ||
83 | uh->len = htons(up->pcslen); | ||
84 | } | 85 | } |
85 | /* | 86 | /* |
86 | * NOTE: Causes for the error case `up->pcslen > up->len': | 87 | * NOTE: Causes for the error case `up->pcslen > up->len': |
87 | * (i) Application error (will not be penalized). | 88 | * (i) Application error (will not be penalized). |
88 | * (ii) Payload too big for send buffer: data is split | 89 | * (ii) Payload too big for send buffer: data is split |
89 | * into several packets, each with its own header. | 90 | * into several packets, each with its own header. |
90 | * In this case (e.g. last segment), coverage may | 91 | * In this case (e.g. last segment), coverage may |
91 | * exceed packet length. | 92 | * exceed packet length. |
92 | * Since packets with coverage length > packet length are | 93 | * Since packets with coverage length > packet length are |
93 | * illegal, we fall back to the defaults here. | 94 | * illegal, we fall back to the defaults here. |
94 | */ | 95 | */ |
95 | } | 96 | } |
96 | return cscov; | ||
97 | } | ||
98 | |||
99 | static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb) | ||
100 | { | ||
101 | int cscov = udplite_sender_cscov(udp_sk(sk), udp_hdr(skb)); | ||
102 | __wsum csum = 0; | ||
103 | 97 | ||
104 | skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */ | 98 | skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */ |
105 | 99 | ||
@@ -115,16 +109,21 @@ static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb) | |||
115 | return csum; | 109 | return csum; |
116 | } | 110 | } |
117 | 111 | ||
112 | /* Fast-path computation of checksum. Socket may not be locked. */ | ||
118 | static inline __wsum udplite_csum(struct sk_buff *skb) | 113 | static inline __wsum udplite_csum(struct sk_buff *skb) |
119 | { | 114 | { |
120 | struct sock *sk = skb->sk; | 115 | const struct udp_sock *up = udp_sk(skb->sk); |
121 | int cscov = udplite_sender_cscov(udp_sk(sk), udp_hdr(skb)); | ||
122 | const int off = skb_transport_offset(skb); | 116 | const int off = skb_transport_offset(skb); |
123 | const int len = skb->len - off; | 117 | int len = skb->len - off; |
124 | 118 | ||
119 | if ((up->pcflag & UDPLITE_SEND_CC) && up->pcslen < len) { | ||
120 | if (0 < up->pcslen) | ||
121 | len = up->pcslen; | ||
122 | udp_hdr(skb)->len = htons(up->pcslen); | ||
123 | } | ||
125 | skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */ | 124 | skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */ |
126 | 125 | ||
127 | return skb_checksum(skb, off, min(cscov, len), 0); | 126 | return skb_checksum(skb, off, len, 0); |
128 | } | 127 | } |
129 | 128 | ||
130 | extern void udplite4_register(void); | 129 | extern void udplite4_register(void); |