diff options
author | Alexander Aring <alex.aring@gmail.com> | 2013-12-17 08:21:26 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2013-12-17 09:16:48 -0500 |
commit | 1672a36b73eb279910691359962aa999a7443aaf (patch) | |
tree | 4e42f0f8489154ba45581ecf8e84a54b9ae0bafc /net/ieee802154/6lowpan_iphc.c | |
parent | 573701ce3715434f01a8baea3255da8d04ad5979 (diff) |
6lowpan: udp use lowpan_fetch_skb function
Cleanup the lowpan_uncompress_udp_header function to use the
lowpan_fetch_skb function.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/ieee802154/6lowpan_iphc.c')
-rw-r--r-- | net/ieee802154/6lowpan_iphc.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c index a70fa66b5357..8857285b418b 100644 --- a/net/ieee802154/6lowpan_iphc.c +++ b/net/ieee802154/6lowpan_iphc.c | |||
@@ -265,40 +265,37 @@ lowpan_uncompress_multicast_daddr(struct sk_buff *skb, | |||
265 | static int | 265 | static int |
266 | uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh) | 266 | uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh) |
267 | { | 267 | { |
268 | u8 tmp; | 268 | bool fail; |
269 | u8 tmp = 0, val = 0; | ||
269 | 270 | ||
270 | if (!uh) | 271 | if (!uh) |
271 | goto err; | 272 | goto err; |
272 | 273 | ||
273 | if (lowpan_fetch_skb_u8(skb, &tmp)) | 274 | fail = lowpan_fetch_skb(skb, &tmp, 1); |
274 | goto err; | ||
275 | 275 | ||
276 | if ((tmp & LOWPAN_NHC_UDP_MASK) == LOWPAN_NHC_UDP_ID) { | 276 | if ((tmp & LOWPAN_NHC_UDP_MASK) == LOWPAN_NHC_UDP_ID) { |
277 | pr_debug("UDP header uncompression\n"); | 277 | pr_debug("UDP header uncompression\n"); |
278 | switch (tmp & LOWPAN_NHC_UDP_CS_P_11) { | 278 | switch (tmp & LOWPAN_NHC_UDP_CS_P_11) { |
279 | case LOWPAN_NHC_UDP_CS_P_00: | 279 | case LOWPAN_NHC_UDP_CS_P_00: |
280 | memcpy(&uh->source, &skb->data[0], 2); | 280 | fail |= lowpan_fetch_skb(skb, &uh->source, 2); |
281 | memcpy(&uh->dest, &skb->data[2], 2); | 281 | fail |= lowpan_fetch_skb(skb, &uh->dest, 2); |
282 | skb_pull(skb, 4); | ||
283 | break; | 282 | break; |
284 | case LOWPAN_NHC_UDP_CS_P_01: | 283 | case LOWPAN_NHC_UDP_CS_P_01: |
285 | memcpy(&uh->source, &skb->data[0], 2); | 284 | fail |= lowpan_fetch_skb(skb, &uh->source, 2); |
286 | uh->dest = htons(skb->data[2] + | 285 | fail |= lowpan_fetch_skb(skb, &val, 1); |
287 | LOWPAN_NHC_UDP_8BIT_PORT); | 286 | uh->dest = htons(val + LOWPAN_NHC_UDP_8BIT_PORT); |
288 | skb_pull(skb, 3); | ||
289 | break; | 287 | break; |
290 | case LOWPAN_NHC_UDP_CS_P_10: | 288 | case LOWPAN_NHC_UDP_CS_P_10: |
291 | uh->source = htons(skb->data[0] + | 289 | fail |= lowpan_fetch_skb(skb, &val, 1); |
292 | LOWPAN_NHC_UDP_8BIT_PORT); | 290 | uh->source = htons(val + LOWPAN_NHC_UDP_8BIT_PORT); |
293 | memcpy(&uh->dest, &skb->data[1], 2); | 291 | fail |= lowpan_fetch_skb(skb, &uh->dest, 2); |
294 | skb_pull(skb, 3); | ||
295 | break; | 292 | break; |
296 | case LOWPAN_NHC_UDP_CS_P_11: | 293 | case LOWPAN_NHC_UDP_CS_P_11: |
294 | fail |= lowpan_fetch_skb(skb, &val, 1); | ||
297 | uh->source = htons(LOWPAN_NHC_UDP_4BIT_PORT + | 295 | uh->source = htons(LOWPAN_NHC_UDP_4BIT_PORT + |
298 | (skb->data[0] >> 4)); | 296 | (val >> 4)); |
299 | uh->dest = htons(LOWPAN_NHC_UDP_4BIT_PORT + | 297 | uh->dest = htons(LOWPAN_NHC_UDP_4BIT_PORT + |
300 | (skb->data[0] & 0x0f)); | 298 | (val & 0x0f)); |
301 | skb_pull(skb, 1); | ||
302 | break; | 299 | break; |
303 | default: | 300 | default: |
304 | pr_debug("ERROR: unknown UDP format\n"); | 301 | pr_debug("ERROR: unknown UDP format\n"); |
@@ -314,8 +311,7 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh) | |||
314 | pr_debug_ratelimited("checksum elided currently not supported\n"); | 311 | pr_debug_ratelimited("checksum elided currently not supported\n"); |
315 | goto err; | 312 | goto err; |
316 | } else { | 313 | } else { |
317 | memcpy(&uh->check, &skb->data[0], 2); | 314 | fail |= lowpan_fetch_skb(skb, &uh->check, 2); |
318 | skb_pull(skb, 2); | ||
319 | } | 315 | } |
320 | 316 | ||
321 | /* | 317 | /* |
@@ -330,6 +326,9 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh) | |||
330 | goto err; | 326 | goto err; |
331 | } | 327 | } |
332 | 328 | ||
329 | if (fail) | ||
330 | goto err; | ||
331 | |||
333 | return 0; | 332 | return 0; |
334 | err: | 333 | err: |
335 | return -EINVAL; | 334 | return -EINVAL; |