diff options
Diffstat (limited to 'net/atm/br2684.c')
-rw-r--r-- | net/atm/br2684.c | 90 |
1 files changed, 40 insertions, 50 deletions
diff --git a/net/atm/br2684.c b/net/atm/br2684.c index c9230c398697..4d64d87e7578 100644 --- a/net/atm/br2684.c +++ b/net/atm/br2684.c | |||
@@ -6,6 +6,8 @@ | |||
6 | * Eric Kinzie, 2006-2007, US Naval Research Laboratory | 6 | * Eric Kinzie, 2006-2007, US Naval Research Laboratory |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ | ||
10 | |||
9 | #include <linux/module.h> | 11 | #include <linux/module.h> |
10 | #include <linux/init.h> | 12 | #include <linux/init.h> |
11 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
@@ -15,7 +17,7 @@ | |||
15 | #include <linux/etherdevice.h> | 17 | #include <linux/etherdevice.h> |
16 | #include <linux/rtnetlink.h> | 18 | #include <linux/rtnetlink.h> |
17 | #include <linux/ip.h> | 19 | #include <linux/ip.h> |
18 | #include <asm/uaccess.h> | 20 | #include <linux/uaccess.h> |
19 | #include <net/arp.h> | 21 | #include <net/arp.h> |
20 | #include <linux/atm.h> | 22 | #include <linux/atm.h> |
21 | #include <linux/atmdev.h> | 23 | #include <linux/atmdev.h> |
@@ -26,20 +28,14 @@ | |||
26 | 28 | ||
27 | #include "common.h" | 29 | #include "common.h" |
28 | 30 | ||
29 | #ifdef SKB_DEBUG | ||
30 | static void skb_debug(const struct sk_buff *skb) | 31 | static void skb_debug(const struct sk_buff *skb) |
31 | { | 32 | { |
33 | #ifdef SKB_DEBUG | ||
32 | #define NUM2PRINT 50 | 34 | #define NUM2PRINT 50 |
33 | char buf[NUM2PRINT * 3 + 1]; /* 3 chars per byte */ | 35 | print_hex_dump(KERN_DEBUG, "br2684: skb: ", DUMP_OFFSET, |
34 | int i = 0; | 36 | 16, 1, skb->data, min(NUM2PRINT, skb->len), true); |
35 | for (i = 0; i < skb->len && i < NUM2PRINT; i++) { | ||
36 | sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); | ||
37 | } | ||
38 | printk(KERN_DEBUG "br2684: skb: %s\n", buf); | ||
39 | } | ||
40 | #else | ||
41 | #define skb_debug(skb) do {} while (0) | ||
42 | #endif | 37 | #endif |
38 | } | ||
43 | 39 | ||
44 | #define BR2684_ETHERTYPE_LEN 2 | 40 | #define BR2684_ETHERTYPE_LEN 2 |
45 | #define BR2684_PAD_LEN 2 | 41 | #define BR2684_PAD_LEN 2 |
@@ -68,7 +64,7 @@ struct br2684_vcc { | |||
68 | struct atm_vcc *atmvcc; | 64 | struct atm_vcc *atmvcc; |
69 | struct net_device *device; | 65 | struct net_device *device; |
70 | /* keep old push, pop functions for chaining */ | 66 | /* keep old push, pop functions for chaining */ |
71 | void (*old_push) (struct atm_vcc * vcc, struct sk_buff * skb); | 67 | void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb); |
72 | void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb); | 68 | void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb); |
73 | enum br2684_encaps encaps; | 69 | enum br2684_encaps encaps; |
74 | struct list_head brvccs; | 70 | struct list_head brvccs; |
@@ -148,7 +144,7 @@ static void br2684_pop(struct atm_vcc *vcc, struct sk_buff *skb) | |||
148 | struct br2684_vcc *brvcc = BR2684_VCC(vcc); | 144 | struct br2684_vcc *brvcc = BR2684_VCC(vcc); |
149 | struct net_device *net_dev = skb->dev; | 145 | struct net_device *net_dev = skb->dev; |
150 | 146 | ||
151 | pr_debug("br2684_pop(vcc %p ; net_dev %p )\n", vcc, net_dev); | 147 | pr_debug("(vcc %p ; net_dev %p )\n", vcc, net_dev); |
152 | brvcc->old_pop(vcc, skb); | 148 | brvcc->old_pop(vcc, skb); |
153 | 149 | ||
154 | if (!net_dev) | 150 | if (!net_dev) |
@@ -244,7 +240,7 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb, | |||
244 | struct br2684_dev *brdev = BRPRIV(dev); | 240 | struct br2684_dev *brdev = BRPRIV(dev); |
245 | struct br2684_vcc *brvcc; | 241 | struct br2684_vcc *brvcc; |
246 | 242 | ||
247 | pr_debug("br2684_start_xmit, skb_dst(skb)=%p\n", skb_dst(skb)); | 243 | pr_debug("skb_dst(skb)=%p\n", skb_dst(skb)); |
248 | read_lock(&devs_lock); | 244 | read_lock(&devs_lock); |
249 | brvcc = pick_outgoing_vcc(skb, brdev); | 245 | brvcc = pick_outgoing_vcc(skb, brdev); |
250 | if (brvcc == NULL) { | 246 | if (brvcc == NULL) { |
@@ -300,7 +296,8 @@ static int br2684_setfilt(struct atm_vcc *atmvcc, void __user * arg) | |||
300 | struct br2684_dev *brdev; | 296 | struct br2684_dev *brdev; |
301 | read_lock(&devs_lock); | 297 | read_lock(&devs_lock); |
302 | brdev = BRPRIV(br2684_find_dev(&fs.ifspec)); | 298 | brdev = BRPRIV(br2684_find_dev(&fs.ifspec)); |
303 | if (brdev == NULL || list_empty(&brdev->brvccs) || brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */ | 299 | if (brdev == NULL || list_empty(&brdev->brvccs) || |
300 | brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */ | ||
304 | brvcc = NULL; | 301 | brvcc = NULL; |
305 | else | 302 | else |
306 | brvcc = list_entry_brvcc(brdev->brvccs.next); | 303 | brvcc = list_entry_brvcc(brdev->brvccs.next); |
@@ -352,7 +349,7 @@ static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb) | |||
352 | struct net_device *net_dev = brvcc->device; | 349 | struct net_device *net_dev = brvcc->device; |
353 | struct br2684_dev *brdev = BRPRIV(net_dev); | 350 | struct br2684_dev *brdev = BRPRIV(net_dev); |
354 | 351 | ||
355 | pr_debug("br2684_push\n"); | 352 | pr_debug("\n"); |
356 | 353 | ||
357 | if (unlikely(skb == NULL)) { | 354 | if (unlikely(skb == NULL)) { |
358 | /* skb==NULL means VCC is being destroyed */ | 355 | /* skb==NULL means VCC is being destroyed */ |
@@ -376,29 +373,25 @@ static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb) | |||
376 | __skb_trim(skb, skb->len - 4); | 373 | __skb_trim(skb, skb->len - 4); |
377 | 374 | ||
378 | /* accept packets that have "ipv[46]" in the snap header */ | 375 | /* accept packets that have "ipv[46]" in the snap header */ |
379 | if ((skb->len >= (sizeof(llc_oui_ipv4))) | 376 | if ((skb->len >= (sizeof(llc_oui_ipv4))) && |
380 | && | 377 | (memcmp(skb->data, llc_oui_ipv4, |
381 | (memcmp | 378 | sizeof(llc_oui_ipv4) - BR2684_ETHERTYPE_LEN) == 0)) { |
382 | (skb->data, llc_oui_ipv4, | 379 | if (memcmp(skb->data + 6, ethertype_ipv6, |
383 | sizeof(llc_oui_ipv4) - BR2684_ETHERTYPE_LEN) == 0)) { | 380 | sizeof(ethertype_ipv6)) == 0) |
384 | if (memcmp | ||
385 | (skb->data + 6, ethertype_ipv6, | ||
386 | sizeof(ethertype_ipv6)) == 0) | ||
387 | skb->protocol = htons(ETH_P_IPV6); | 381 | skb->protocol = htons(ETH_P_IPV6); |
388 | else if (memcmp | 382 | else if (memcmp(skb->data + 6, ethertype_ipv4, |
389 | (skb->data + 6, ethertype_ipv4, | 383 | sizeof(ethertype_ipv4)) == 0) |
390 | sizeof(ethertype_ipv4)) == 0) | ||
391 | skb->protocol = htons(ETH_P_IP); | 384 | skb->protocol = htons(ETH_P_IP); |
392 | else | 385 | else |
393 | goto error; | 386 | goto error; |
394 | skb_pull(skb, sizeof(llc_oui_ipv4)); | 387 | skb_pull(skb, sizeof(llc_oui_ipv4)); |
395 | skb_reset_network_header(skb); | 388 | skb_reset_network_header(skb); |
396 | skb->pkt_type = PACKET_HOST; | 389 | skb->pkt_type = PACKET_HOST; |
397 | /* | 390 | /* |
398 | * Let us waste some time for checking the encapsulation. | 391 | * Let us waste some time for checking the encapsulation. |
399 | * Note, that only 7 char is checked so frames with a valid FCS | 392 | * Note, that only 7 char is checked so frames with a valid FCS |
400 | * are also accepted (but FCS is not checked of course). | 393 | * are also accepted (but FCS is not checked of course). |
401 | */ | 394 | */ |
402 | } else if ((skb->len >= sizeof(llc_oui_pid_pad)) && | 395 | } else if ((skb->len >= sizeof(llc_oui_pid_pad)) && |
403 | (memcmp(skb->data, llc_oui_pid_pad, 7) == 0)) { | 396 | (memcmp(skb->data, llc_oui_pid_pad, 7) == 0)) { |
404 | skb_pull(skb, sizeof(llc_oui_pid_pad)); | 397 | skb_pull(skb, sizeof(llc_oui_pid_pad)); |
@@ -479,8 +472,7 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg) | |||
479 | write_lock_irq(&devs_lock); | 472 | write_lock_irq(&devs_lock); |
480 | net_dev = br2684_find_dev(&be.ifspec); | 473 | net_dev = br2684_find_dev(&be.ifspec); |
481 | if (net_dev == NULL) { | 474 | if (net_dev == NULL) { |
482 | printk(KERN_ERR | 475 | pr_err("tried to attach to non-existant device\n"); |
483 | "br2684: tried to attach to non-existant device\n"); | ||
484 | err = -ENXIO; | 476 | err = -ENXIO; |
485 | goto error; | 477 | goto error; |
486 | } | 478 | } |
@@ -494,17 +486,16 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg) | |||
494 | err = -EEXIST; | 486 | err = -EEXIST; |
495 | goto error; | 487 | goto error; |
496 | } | 488 | } |
497 | if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO || | 489 | if (be.fcs_in != BR2684_FCSIN_NO || |
498 | be.fcs_auto || be.has_vpiid || be.send_padding || (be.encaps != | 490 | be.fcs_out != BR2684_FCSOUT_NO || |
499 | BR2684_ENCAPS_VC | 491 | be.fcs_auto || be.has_vpiid || be.send_padding || |
500 | && be.encaps != | 492 | (be.encaps != BR2684_ENCAPS_VC && |
501 | BR2684_ENCAPS_LLC) | 493 | be.encaps != BR2684_ENCAPS_LLC) || |
502 | || be.min_size != 0) { | 494 | be.min_size != 0) { |
503 | err = -EINVAL; | 495 | err = -EINVAL; |
504 | goto error; | 496 | goto error; |
505 | } | 497 | } |
506 | pr_debug("br2684_regvcc vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, | 498 | pr_debug("vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, be.encaps, brvcc); |
507 | be.encaps, brvcc); | ||
508 | if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) { | 499 | if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) { |
509 | unsigned char *esi = atmvcc->dev->esi; | 500 | unsigned char *esi = atmvcc->dev->esi; |
510 | if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5]) | 501 | if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5]) |
@@ -541,7 +532,8 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg) | |||
541 | } | 532 | } |
542 | __module_get(THIS_MODULE); | 533 | __module_get(THIS_MODULE); |
543 | return 0; | 534 | return 0; |
544 | error: | 535 | |
536 | error: | ||
545 | write_unlock_irq(&devs_lock); | 537 | write_unlock_irq(&devs_lock); |
546 | kfree(brvcc); | 538 | kfree(brvcc); |
547 | return err; | 539 | return err; |
@@ -587,7 +579,7 @@ static void br2684_setup_routed(struct net_device *netdev) | |||
587 | INIT_LIST_HEAD(&brdev->brvccs); | 579 | INIT_LIST_HEAD(&brdev->brvccs); |
588 | } | 580 | } |
589 | 581 | ||
590 | static int br2684_create(void __user * arg) | 582 | static int br2684_create(void __user *arg) |
591 | { | 583 | { |
592 | int err; | 584 | int err; |
593 | struct net_device *netdev; | 585 | struct net_device *netdev; |
@@ -595,11 +587,10 @@ static int br2684_create(void __user * arg) | |||
595 | struct atm_newif_br2684 ni; | 587 | struct atm_newif_br2684 ni; |
596 | enum br2684_payload payload; | 588 | enum br2684_payload payload; |
597 | 589 | ||
598 | pr_debug("br2684_create\n"); | 590 | pr_debug("\n"); |
599 | 591 | ||
600 | if (copy_from_user(&ni, arg, sizeof ni)) { | 592 | if (copy_from_user(&ni, arg, sizeof ni)) |
601 | return -EFAULT; | 593 | return -EFAULT; |
602 | } | ||
603 | 594 | ||
604 | if (ni.media & BR2684_FLAG_ROUTED) | 595 | if (ni.media & BR2684_FLAG_ROUTED) |
605 | payload = p_routed; | 596 | payload = p_routed; |
@@ -607,9 +598,8 @@ static int br2684_create(void __user * arg) | |||
607 | payload = p_bridged; | 598 | payload = p_bridged; |
608 | ni.media &= 0xffff; /* strip flags */ | 599 | ni.media &= 0xffff; /* strip flags */ |
609 | 600 | ||
610 | if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500) { | 601 | if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500) |
611 | return -EINVAL; | 602 | return -EINVAL; |
612 | } | ||
613 | 603 | ||
614 | netdev = alloc_netdev(sizeof(struct br2684_dev), | 604 | netdev = alloc_netdev(sizeof(struct br2684_dev), |
615 | ni.ifname[0] ? ni.ifname : "nas%d", | 605 | ni.ifname[0] ? ni.ifname : "nas%d", |
@@ -624,7 +614,7 @@ static int br2684_create(void __user * arg) | |||
624 | /* open, stop, do_ioctl ? */ | 614 | /* open, stop, do_ioctl ? */ |
625 | err = register_netdev(netdev); | 615 | err = register_netdev(netdev); |
626 | if (err < 0) { | 616 | if (err < 0) { |
627 | printk(KERN_ERR "br2684_create: register_netdev failed\n"); | 617 | pr_err("register_netdev failed\n"); |
628 | free_netdev(netdev); | 618 | free_netdev(netdev); |
629 | return err; | 619 | return err; |
630 | } | 620 | } |