9 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
11 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/list.h>
15 #include <linux/netdevice.h>
18 #include <linux/rtnetlink.h>
21 #include <linux/slab.h>
23 #include <linux/atm.h>
24 #include <linux/atmdev.h>
25 #include <linux/capability.h>
32 static void skb_debug(
const struct sk_buff *
skb)
37 16, 1, skb->
data,
min(NUM2PRINT, skb->
len),
true);
41 #define BR2684_ETHERTYPE_LEN 2
42 #define BR2684_PAD_LEN 2
44 #define LLC 0xaa, 0xaa, 0x03
45 #define SNAP_BRIDGED 0x00, 0x80, 0xc2
46 #define SNAP_ROUTED 0x00, 0x00, 0x00
47 #define PID_ETHERNET 0x00, 0x07
48 #define ETHERTYPE_IPV4 0x08, 0x00
49 #define ETHERTYPE_IPV6 0x86, 0xdd
50 #define PAD_BRIDGED 0x00, 0x00
54 static const unsigned char llc_oui_pid_pad[] =
73 #ifdef CONFIG_ATM_BR2684_IPFILTER
101 return netdev_priv(net_dev);
127 net_dev = list_entry_brdev(lh);
128 if (BRPRIV(net_dev)->number == s->
spec.
devnum)
134 net_dev = list_entry_brdev(lh);
153 pr_debug(
"event=%ld dev=%p\n", event, atm_dev);
157 net_dev = list_entry_brdev(lh);
161 if (atm_vcc && brvcc->
atmvcc->dev == atm_dev) {
177 .notifier_call = atm_dev_event,
181 static void br2684_pop(
struct atm_vcc *
vcc,
struct sk_buff *
skb)
186 pr_debug(
"(vcc %p ; net_dev %p )\n", vcc, net_dev);
192 if (atm_may_send(vcc, 0))
193 netif_wake_queue(net_dev);
205 struct atm_vcc *atmvcc;
208 sizeof(llc_oui_pid_pad) :
sizeof(llc_oui_ipv4)) :
211 if (skb_headroom(skb) < minheadroom) {
224 skb_push(skb,
sizeof(llc_oui_pid_pad));
225 skb_copy_to_linear_data(skb, llc_oui_pid_pad,
226 sizeof(llc_oui_pid_pad));
230 skb_push(skb,
sizeof(llc_oui_ipv4));
233 skb_copy_to_linear_data(skb, llc_oui_ipv4,
234 sizeof(llc_oui_ipv4));
237 skb_copy_to_linear_data(skb, llc_oui_ipv6,
238 sizeof(llc_oui_ipv6));
254 pr_debug(
"atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->
dev);
257 dev->
stats.tx_packets++;
259 atmvcc->
send(atmvcc, skb);
261 if (!atm_may_send(atmvcc, 0)) {
262 netif_stop_queue(brvcc->
device);
264 if (atm_may_send(atmvcc, 0))
265 netif_start_queue(brvcc->
device);
274 return list_empty(&brdev->
brvccs) ?
NULL : list_entry_brvcc(brdev->
brvccs.next);
283 pr_debug(
"skb_dst(skb)=%p\n", skb_dst(skb));
285 brvcc = pick_outgoing_vcc(skb, brdev);
288 dev->
stats.tx_errors++;
289 dev->
stats.tx_carrier_errors++;
295 if (!br2684_xmit_vcc(skb, dev, brvcc)) {
303 dev->
stats.tx_errors++;
304 dev->
stats.tx_fifo_errors++;
314 static int br2684_mac_addr(
struct net_device *dev,
void *
p)
318 BRPRIV(dev)->mac_was_set = 1;
322 #ifdef CONFIG_ATM_BR2684_IPFILTER
324 static int br2684_setfilt(
struct atm_vcc *atmvcc,
void __user * arg)
338 brdev = BRPRIV(br2684_find_dev(&
fs.ifspec));
339 if (brdev ==
NULL || list_empty(&brdev->
brvccs) ||
343 brvcc = list_entry_brvcc(brdev->
brvccs.next);
348 brvcc = BR2684_VCC(atmvcc);
349 memcpy(&brvcc->filter, &
fs.filter,
sizeof(brvcc->filter));
357 if (brvcc->filter.netmask == 0)
360 (((
struct iphdr *)(skb->
data))->daddr & brvcc->filter.
361 netmask) == brvcc->filter.prefix)
373 static void br2684_close_vcc(
struct br2684_vcc *brvcc)
386 static void br2684_push(
struct atm_vcc *atmvcc,
struct sk_buff *skb)
388 struct br2684_vcc *brvcc = BR2684_VCC(atmvcc);
396 br2684_close_vcc(brvcc);
397 if (list_empty(&brdev->
brvccs)) {
409 pr_debug(
"skb from brdev %p\n", brdev);
412 if (skb->
len > 7 && skb->
data[7] == 0x01)
413 __skb_trim(skb, skb->
len - 4);
416 if ((skb->
len >= (
sizeof(llc_oui_ipv4))) &&
420 sizeof(ethertype_ipv6)) == 0)
422 else if (
memcmp(skb->
data + 6, ethertype_ipv4,
423 sizeof(ethertype_ipv4)) == 0)
427 skb_pull(skb,
sizeof(llc_oui_ipv4));
428 skb_reset_network_header(skb);
435 }
else if ((skb->
len >=
sizeof(llc_oui_pid_pad)) &&
436 (
memcmp(skb->
data, llc_oui_pid_pad, 7) == 0)) {
437 skb_pull(skb,
sizeof(llc_oui_pid_pad));
446 skb_reset_network_header(skb);
448 if (iph->version == 4)
450 else if (iph->version == 6)
464 #ifdef CONFIG_ATM_BR2684_IPFILTER
475 net_dev->
stats.rx_packets++;
476 net_dev->
stats.rx_bytes += skb->
len;
482 net_dev->
stats.rx_dropped++;
485 net_dev->
stats.rx_errors++;
494 static int br2684_regvcc(
struct atm_vcc *atmvcc,
void __user * arg)
508 net_dev = br2684_find_dev(&be.ifspec);
509 if (net_dev ==
NULL) {
510 pr_err(
"tried to attach to non-existent device\n");
514 brdev = BRPRIV(net_dev);
519 if (!list_empty(&brdev->
brvccs)) {
526 be.fcs_auto || be.has_vpiid || be.send_padding ||
533 pr_debug(
"vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, be.encaps, brvcc);
535 unsigned char *esi = atmvcc->
dev->esi;
536 if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5])
550 atmvcc->
push = br2684_push;
551 atmvcc->
pop = br2684_pop;
573 .ndo_start_xmit = br2684_start_xmit,
574 .ndo_set_mac_address = br2684_mac_addr,
580 .ndo_start_xmit = br2684_start_xmit,
581 .ndo_set_mac_address = br2684_mac_addr,
585 static void br2684_setup(
struct net_device *netdev)
595 INIT_LIST_HEAD(&brdev->
brvccs);
598 static void br2684_setup_routed(
struct net_device *netdev)
604 netdev->
netdev_ops = &br2684_netdev_ops_routed;
610 INIT_LIST_HEAD(&brdev->
brvccs);
613 static int br2684_create(
void __user *arg)
636 ni.ifname[0] ? ni.ifname :
"nas%d",
638 br2684_setup_routed : br2684_setup);
642 brdev = BRPRIV(netdev);
648 pr_err(
"register_netdev failed\n");
657 if (list_empty(&br2684_devs)) {
661 brdev->
number = BRPRIV(list_entry_brdev(br2684_devs.prev))->number + 1;
672 static int br2684_ioctl(
struct socket *
sock,
unsigned int cmd,
675 struct atm_vcc *atmvcc = ATM_SD(sock);
691 return br2684_regvcc(atmvcc, argp);
693 return br2684_create(argp);
694 #ifdef CONFIG_ATM_BR2684_IPFILTER
696 if (atmvcc->
push != br2684_push)
700 err = br2684_setfilt(atmvcc, argp);
708 static struct atm_ioctl br2684_ioctl_ops = {
710 .ioctl = br2684_ioctl,
713 #ifdef CONFIG_PROC_FS
714 static void *br2684_seq_start(
struct seq_file *seq, loff_t *
pos)
721 static void *br2684_seq_next(
struct seq_file *seq,
void *
v, loff_t *
pos)
726 static void br2684_seq_stop(
struct seq_file *seq,
void *
v)
732 static int br2684_seq_show(
struct seq_file *seq,
void *
v)
739 seq_printf(seq,
"dev %.16s: num=%d, mac=%pM (%s)\n",
746 seq_printf(seq,
" vcc %d.%d.%d: encaps=%s payload=%s"
747 ", failed copies %u/%u"
748 "\n", brvcc->
atmvcc->dev->number,
753 #ifdef CONFIG_ATM_BR2684_IPFILTER
754 #define b1(var, byte) ((u8 *) &brvcc->filter.var)[byte]
755 #define bs(var) b1(var, 0), b1(var, 1), b1(var, 2), b1(var, 3)
756 if (brvcc->filter.netmask != 0)
758 "%d.%d.%d.%d\n", bs(
prefix), bs(netmask));
767 .
start = br2684_seq_start,
768 .next = br2684_seq_next,
769 .stop = br2684_seq_stop,
770 .show = br2684_seq_show,
775 return seq_open(file, &br2684_seq_ops);
780 .open = br2684_proc_open,
789 static int __init br2684_init(
void)
791 #ifdef CONFIG_PROC_FS
793 p = proc_create(
"br2684", 0, atm_proc_root, &br2684_proc_ops);
802 static void __exit br2684_exit(
void)
809 #ifdef CONFIG_PROC_FS
816 while (!list_empty(&br2684_devs)) {
817 net_dev = list_entry_brdev(br2684_devs.next);
818 brdev = BRPRIV(net_dev);
819 while (!list_empty(&brdev->
brvccs)) {
820 brvcc = list_entry_brvcc(brdev->
brvccs.next);
821 br2684_close_vcc(brvcc);