2 Experimental ethernet netdevice using ATM AAL5 as underlying carrier
3 (RFC1483 obsoleted by RFC2684) for Linux 2.4
4 Author: Marcell GAL, 2000, XDSL Ltd, Hungary
7 #include <linux/module.h>
8 #include <linux/config.h>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/list.h>
12 #include <linux/netdevice.h>
13 #include <linux/skbuff.h>
14 #include <linux/etherdevice.h>
15 #include <linux/rtnetlink.h>
17 #include <asm/uaccess.h>
19 #include <linux/atm.h>
20 #include <linux/atmdev.h>
21 #include <linux/seq_file.h>
23 #include <linux/atmbr2684.h>
29 * Define this to use a version of the code which interacts with the higher
30 * layers in a more intellegent way, by always reserving enough space for
31 * our header at the begining of the packet. However, there may still be
32 * some problems with programs like tcpdump. In 2.5 we'll sort out what
33 * we need to do to get this perfect. For now we just will copy the packet
34 * if we need space for the header
36 /* #define FASTER_VERSION */
41 #define DPRINTK(format, args...) printk(KERN_DEBUG "br2684: " format, ##args)
43 #define DPRINTK(format, args...)
47 static void skb_debug(const struct sk_buff *skb)
50 char buf[NUM2PRINT * 3 + 1]; /* 3 chars per byte */
52 for (i = 0; i < skb->len && i < NUM2PRINT; i++) {
53 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
55 printk(KERN_DEBUG "br2684: skb: %s\n", buf);
58 #define skb_debug(skb) do {} while (0)
61 static unsigned char llc_oui_pid_pad[] =
62 { 0xAA, 0xAA, 0x03, 0x00, 0x80, 0xC2, 0x00, 0x07, 0x00, 0x00 };
66 e_vc = BR2684_ENCAPS_VC,
67 e_llc = BR2684_ENCAPS_LLC,
71 struct atm_vcc *atmvcc;
72 struct net_device *device;
73 /* keep old push,pop functions for chaining */
74 void (*old_push)(struct atm_vcc *vcc,struct sk_buff *skb);
75 /* void (*old_pop)(struct atm_vcc *vcc,struct sk_buff *skb); */
76 enum br2684_encaps encaps;
77 struct list_head brvccs;
78 #ifdef CONFIG_ATM_BR2684_IPFILTER
79 struct br2684_filter filter;
80 #endif /* CONFIG_ATM_BR2684_IPFILTER */
81 #ifndef FASTER_VERSION
82 unsigned copies_needed, copies_failed;
83 #endif /* FASTER_VERSION */
84 #if defined(CONFIG_MIPS_BRCM)
85 /* Protocol filter flag, currently only PPPoE.
86 When turned on, all non-PPPoE traffic will be dropped
90 unsigned short vlan_id; /* vlan id (0-4096) */
91 #endif // SUPPORT_VLAN
98 struct net_device *net_dev;
99 struct list_head br2684_devs;
101 struct list_head brvccs; /* one device <=> one vcc (before xmas) */
102 struct net_device_stats stats;
106 #if defined(CONFIG_MIPS_BRCM)
107 #define MIN_PKT_SIZE 70
111 * This lock should be held for writing any time the list of devices or
112 * their attached vcc's could be altered. It should be held for reading
113 * any time these are being queried. Note that we sometimes need to
114 * do read-locking under interrupt context, so write locking must block
115 * the current CPU's interrupts
117 static rwlock_t devs_lock = RW_LOCK_UNLOCKED;
119 static LIST_HEAD(br2684_devs);
121 static inline struct br2684_dev *BRPRIV(const struct net_device *net_dev)
123 return (struct br2684_dev *) net_dev->priv;
126 static inline struct net_device *list_entry_brdev(const struct list_head *le)
128 return list_entry(le, struct br2684_dev, br2684_devs)->net_dev;
131 static inline struct br2684_vcc *BR2684_VCC(const struct atm_vcc *atmvcc)
133 return (struct br2684_vcc *) (atmvcc->user_back);
136 static inline struct br2684_vcc *list_entry_brvcc(const struct list_head *le)
138 return list_entry(le, struct br2684_vcc, brvccs);
141 /* Caller should hold read_lock(&devs_lock) */
142 static struct net_device *br2684_find_dev(const struct br2684_if_spec *s)
144 struct list_head *lh;
145 struct net_device *net_dev;
147 case BR2684_FIND_BYNUM:
148 list_for_each(lh, &br2684_devs) {
149 net_dev = list_entry_brdev(lh);
150 if (BRPRIV(net_dev)->number == s->spec.devnum)
154 case BR2684_FIND_BYIFNAME:
155 list_for_each(lh, &br2684_devs) {
156 net_dev = list_entry_brdev(lh);
157 if (!strncmp(net_dev->name, s->spec.ifname, IFNAMSIZ))
166 #include <linux/if_vlan.h>
168 * vlan_tag_insert - regular VLAN tag inserting
169 * @skb: skbuff to tag
170 * @tag: VLAN tag to insert
172 * Inserts the VLAN tag into @skb as part of the payload
173 * Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
175 * Following the skb_unshare() example, in case of error, the calling function
176 * doesn't have to worry about freeing the original skb.
178 #define ATM_HEADER_LEN 10
179 #define ATM_AND_MAC_LEN ((ATM_HEADER_LEN) + (2 * VLAN_ETH_ALEN))
181 struct atm_vlan_ethhdr {
182 unsigned char h_atm_stuff[ATM_HEADER_LEN]; /* atm stuff 10 bytes */
183 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
184 unsigned char h_source[ETH_ALEN]; /* source ether addr */
185 unsigned short h_vlan_proto; /* Should always be 0x8100 */
186 unsigned short h_vlan_TCI; /* Encapsulates priority and VLAN ID */
187 unsigned short h_vlan_encapsulated_proto; /* packet type ID field (or len) */
190 static inline struct sk_buff *vlan_tag_insert(struct sk_buff *skb, unsigned short tag)
192 struct atm_vlan_ethhdr *veth;
194 if (skb_headroom(skb) < VLAN_HLEN) {
195 struct sk_buff *sk_tmp = skb;
196 skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
199 printk(KERN_ERR "vlan: failed to realloc headroom\n");
203 skb = skb_unshare(skb, GFP_ATOMIC);
205 printk(KERN_ERR "vlan: failed to unshare skbuff\n");
210 veth = (struct atm_vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
212 /* Move the mac addresses to the beginning of the new header. */
213 memmove(skb->data, skb->data + VLAN_HLEN, (2 * VLAN_ETH_ALEN) + ATM_HEADER_LEN);
215 /* first, the ethernet type */
216 veth->h_vlan_proto = __constant_htons(ETH_P_8021Q);
219 veth->h_vlan_TCI = htons(tag);
221 skb->protocol = __constant_htons(ETH_P_8021Q);
222 skb->mac.raw -= VLAN_HLEN;
223 skb->nh.raw -= VLAN_HLEN;
227 #endif // SUPPORT_VLAN
230 * Send a packet out a particular vcc. Not to useful right now, but paves
231 * the way for multiple vcc's per itf. Returns true if we can send,
234 static int br2684_xmit_vcc(struct sk_buff *skb, struct br2684_dev *brdev,
235 struct br2684_vcc *brvcc)
237 struct atm_vcc *atmvcc;
239 #ifdef FASTER_VERSION
240 if (brvcc->encaps == e_llc)
241 memcpy(skb_push(skb, 8), llc_oui_pid_pad, 8);
242 /* last 2 bytes of llc_oui_pid_pad are managed by header routines;
243 yes, you got it: 8 + 2 = sizeof(llc_oui_pid_pad)
246 int minheadroom = (brvcc->encaps == e_llc) ? 10 : 2;
247 if (skb_headroom(skb) < minheadroom) {
248 struct sk_buff *skb2 = skb_realloc_headroom(skb, minheadroom);
249 brvcc->copies_needed++;
252 brvcc->copies_failed++;
257 skb_push(skb, minheadroom);
258 if (brvcc->encaps == e_llc)
259 memcpy(skb->data, llc_oui_pid_pad, 10);
261 memset(skb->data, 0, 2);
262 #endif /* FASTER_VERSION */
264 #if defined(CONFIG_MIPS_BRCM)
265 if (skb->len < MIN_PKT_SIZE)
267 struct sk_buff *skb2=skb_copy_expand(skb, 0, MIN_PKT_SIZE - skb->len, GFP_ATOMIC);
270 brvcc->copies_failed++;
274 memset(skb->tail, 0, MIN_PKT_SIZE - skb->len);
275 skb_put(skb, MIN_PKT_SIZE - skb->len);
281 printk("=====> br2684_xmit_vcc bef add vlan tag, skb->len=0x%04x\n", skb->len);
285 /* Construct the second two bytes. This field looks something
287 * usr_priority: 3 bits (high bits)
289 * VLAN ID 12 bits (low bits)
291 //brvcc->vlan_id |= vlan_dev_get_egress_qos_mask(dev, skb);
292 /* bit 3-0 of the 32-bit nfmark is the atm priority, set by iptables
293 * bit 7-4 is the Ethernet switch physical port number, set by lan port drivers.
294 * bit 8-11 is the wanVlan priority bits
296 if (brvcc->vlan_id != 0xffff) {
297 brvcc->vlan_id &= 0xffff0fff; // clear the priority bits first
298 // if bit 8-11 is set (none zeros), add in the priority bits
299 if (skb->nfmark & 0x0000f000) {
300 brvcc->vlan_id |= (skb->nfmark & 0x0000f000);
302 skb = vlan_tag_insert(skb, brvcc->vlan_id);
304 brdev->stats.tx_dropped++;
308 printk("=====> br2684_xmit_vcc aft add vlan tag, skb->len=%d\n", skb->len);
312 #endif // SUPPORT_VLAN
314 ATM_SKB(skb)->vcc = atmvcc = brvcc->atmvcc;
315 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->dev);
316 if (!atm_may_send(atmvcc, skb->truesize)) {
317 /* we free this here for now, because we cannot know in a higher
318 layer whether the skb point it supplied wasn't freed yet.
324 atomic_add(skb->truesize, &atmvcc->sk->sk_wmem_alloc);
325 ATM_SKB(skb)->atm_options = atmvcc->atm_options;
326 brdev->stats.tx_packets++;
327 brdev->stats.tx_bytes += skb->len;
328 #if defined(CONFIG_MIPS_BRCM)
329 if (atmvcc->send(atmvcc, skb) != 0)
330 brdev->stats.tx_dropped++;
332 atmvcc->send(atmvcc, skb);
338 static inline struct br2684_vcc *pick_outgoing_vcc(struct sk_buff *skb,
339 struct br2684_dev *brdev)
341 return list_empty(&brdev->brvccs) ? NULL :
342 list_entry_brvcc(brdev->brvccs.next); /* 1 vcc/dev right now */
345 static int br2684_start_xmit(struct sk_buff *skb, struct net_device *dev)
347 struct br2684_dev *brdev = BRPRIV(dev);
348 struct br2684_vcc *brvcc;
349 DPRINTK("br2684_start_xmit, skb->dst=%p\n", skb->dst);
350 read_lock(&devs_lock);
351 brvcc = pick_outgoing_vcc(skb, brdev);
353 DPRINTK("no vcc attached to dev %s\n", dev->name);
354 brdev->stats.tx_errors++;
355 brdev->stats.tx_carrier_errors++;
356 /* netif_stop_queue(dev); */
358 read_unlock(&devs_lock);
362 #if defined(CONFIG_MIPS_BRCM)
363 if (brvcc->proto_filter & FILTER_PPPOE) {
364 if ((skb->protocol != htons(ETH_P_PPP_DISC)) && (skb->protocol != htons(ETH_P_PPP_SES))) {
365 DPRINTK("non-PPPOE packet dropped on TX dev %s\n", dev->name);
367 read_unlock(&devs_lock);
374 if (brvcc->vlan_id != 0xffff)
375 printk("=====> br2684_start_xmit vlan_id=0x%04x\n", brvcc->vlan_id);
378 if (!br2684_xmit_vcc(skb, brdev, brvcc)) {
380 * We should probably use netif_*_queue() here, but that
381 * involves added complication. We need to walk before
384 /* don't free here! this pointer might be no longer valid!
387 brdev->stats.tx_errors++;
388 brdev->stats.tx_fifo_errors++;
390 read_unlock(&devs_lock);
394 static struct net_device_stats *br2684_get_stats(struct net_device *dev)
396 DPRINTK("br2684_get_stats\n");
397 return &BRPRIV(dev)->stats;
400 #ifdef FASTER_VERSION
402 * These mirror eth_header and eth_header_cache. They are not usually
403 * exported for use in modules, so we grab them from net_device
404 * after ether_setup() is done with it. Bit of a hack.
406 static int (*my_eth_header)(struct sk_buff *, struct net_device *,
407 unsigned short, void *, void *, unsigned);
408 static int (*my_eth_header_cache)(struct neighbour *, struct hh_cache *);
411 br2684_header(struct sk_buff *skb, struct net_device *dev,
412 unsigned short type, void *daddr, void *saddr, unsigned len)
415 int t = my_eth_header(skb, dev, type, daddr, saddr, len);
417 pad_before_eth = (u16 *) skb_push(skb, 2);
419 return dev->hard_header_len; /* or return 16; ? */
425 br2684_header_cache(struct neighbour *neigh, struct hh_cache *hh)
427 /* hh_data is 16 bytes long. if encaps is ether-llc we need 24, so
428 xmit will add the additional header part in that case */
429 u16 *pad_before_eth = (u16 *)(hh->hh_data);
430 int t = my_eth_header_cache(neigh, hh);
431 DPRINTK("br2684_header_cache, neigh=%p, hh_cache=%p\n", neigh, hh);
436 hh->hh_len = PADLEN + ETH_HLEN;
442 * This is similar to eth_type_trans, which cannot be used because of
443 * our dev->hard_header_len
445 static inline unsigned short br_type_trans(struct sk_buff *skb,
446 struct net_device *dev)
450 eth = skb->mac.ethernet;
452 if (*eth->h_dest & 1) {
453 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
454 skb->pkt_type = PACKET_BROADCAST;
456 skb->pkt_type = PACKET_MULTICAST;
459 else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
460 skb->pkt_type = PACKET_OTHERHOST;
462 if (ntohs(eth->h_proto) >= 1536)
468 * This is a magic hack to spot IPX packets. Older Novell breaks
469 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
470 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
471 * won't work for fault tolerant netware but does for the rest.
473 if (*(unsigned short *) rawp == 0xFFFF)
474 return htons(ETH_P_802_3);
479 return htons(ETH_P_802_2);
481 #endif /* FASTER_VERSION */
484 * We remember when the MAC gets set, so we don't override it later with
485 * the ESI of the ATM card of the first VC
487 static int (*my_eth_mac_addr)(struct net_device *, void *);
488 static int br2684_mac_addr(struct net_device *dev, void *p)
490 int err = my_eth_mac_addr(dev, p);
492 BRPRIV(dev)->mac_was_set = 1;
496 #ifdef CONFIG_ATM_BR2684_IPFILTER
497 /* this IOCTL is experimental. */
498 static int br2684_setfilt(struct atm_vcc *atmvcc, void __user *arg)
500 struct br2684_vcc *brvcc;
501 struct br2684_filter_set fs;
503 if (copy_from_user(&fs, arg, sizeof fs))
505 if (fs.ifspec.method != BR2684_FIND_BYNOTHING) {
507 * This is really a per-vcc thing, but we can also search
510 struct br2684_dev *brdev;
511 read_lock(&devs_lock);
512 brdev = BRPRIV(br2684_find_dev(&fs.ifspec));
513 if (brdev == NULL || list_empty(&brdev->brvccs) ||
514 brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */
517 brvcc = list_entry_brvcc(brdev->brvccs.next);
518 read_unlock(&devs_lock);
522 brvcc = BR2684_VCC(atmvcc);
523 memcpy(&brvcc->filter, &fs.filter, sizeof(brvcc->filter));
527 /* Returns 1 if packet should be dropped */
529 packet_fails_filter(u16 type, struct br2684_vcc *brvcc, struct sk_buff *skb)
531 if (brvcc->filter.netmask == 0)
532 return 0; /* no filter in place */
533 if (type == __constant_htons(ETH_P_IP) &&
534 (((struct iphdr *) (skb->data))->daddr & brvcc->filter.
535 netmask) == brvcc->filter.prefix)
537 if (type == __constant_htons(ETH_P_ARP))
539 /* TODO: we should probably filter ARPs too.. don't want to have
540 * them returning values that don't make sense, or is that ok?
544 #endif /* CONFIG_ATM_BR2684_IPFILTER */
546 static void br2684_close_vcc(struct br2684_vcc *brvcc)
548 DPRINTK("removing VCC %p from dev %p\n", brvcc, brvcc->device);
549 write_lock_irq(&devs_lock);
550 list_del(&brvcc->brvccs);
551 write_unlock_irq(&devs_lock);
552 brvcc->atmvcc->user_back = NULL; /* what about vcc->recvq ??? */
553 brvcc->old_push(brvcc->atmvcc, NULL); /* pass on the bad news */
555 module_put(THIS_MODULE);
558 /* when AAL5 PDU comes in: */
559 static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
561 struct br2684_vcc *brvcc = BR2684_VCC(atmvcc);
562 struct net_device *net_dev = brvcc->device;
563 struct br2684_dev *brdev = BRPRIV(net_dev);
564 int plen = sizeof(llc_oui_pid_pad) + ETH_HLEN;
566 DPRINTK("br2684_push\n");
568 if (unlikely(skb == NULL)) {
569 /* skb==NULL means VCC is being destroyed */
570 br2684_close_vcc(brvcc);
571 if (list_empty(&brdev->brvccs)) {
572 read_lock(&devs_lock);
573 list_del(&brdev->br2684_devs);
574 read_unlock(&devs_lock);
575 unregister_netdev(net_dev);
576 free_netdev(net_dev);
580 #if defined(CONFIG_MIPS_BRCM)
581 //skb->__unused=FROM_WAN;
584 atm_return(atmvcc, skb->truesize);
585 DPRINTK("skb from brdev %p\n", brdev);
586 if (brvcc->encaps == e_llc) {
587 /* let us waste some time for checking the encapsulation.
588 Note, that only 7 char is checked so frames with a valid FCS
589 are also accepted (but FCS is not checked of course) */
590 if (memcmp(skb->data, llc_oui_pid_pad, 7)) {
591 brdev->stats.rx_errors++;
596 /* Strip FCS if present */
597 if (skb->len > 7 && skb->data[7] == 0x01)
598 __skb_trim(skb, skb->len - 4);
600 plen = PADLEN + ETH_HLEN; /* pad, dstmac,srcmac, ethtype */
601 /* first 2 chars should be 0 */
602 if (*((u16 *) (skb->data)) != 0) {
603 brdev->stats.rx_errors++;
608 if (skb->len < plen) {
609 brdev->stats.rx_errors++;
610 dev_kfree_skb(skb); /* dev_ not needed? */
614 if (brvcc->vlan_id != 0xffff) { /* Vcc was configured to be vlan tagged*/
615 unsigned tmp[ATM_AND_MAC_LEN];
617 printk("=====> before removing vlan id\n");
621 ** There exist a situation where we tag vlan id upstream. But DSLAM sends untagged frame downstream. So we need to check this situation before we move data around
624 if ( skb->data[22] == 0x81 && skb->data[23] == 0x0) {
625 memcpy(tmp, skb->data, ATM_AND_MAC_LEN);
626 skb_pull(skb, VLAN_HLEN);
627 memcpy(skb->data, tmp, ATM_AND_MAC_LEN);
630 printk("=====> after removing vlan id\n");
634 #endif // SUPPORT_VLAN
636 #ifdef FASTER_VERSION
637 /* FIXME: tcpdump shows that pointer to mac header is 2 bytes earlier,
638 than should be. What else should I set? */
640 skb->mac.raw = ((char *) (skb->data)) - ETH_HLEN;
641 skb->pkt_type = PACKET_HOST;
642 #ifdef CONFIG_BR2684_FAST_TRANS
643 skb->protocol = ((u16 *) skb->data)[-1];
644 #else /* some protocols might require this: */
645 skb->protocol = br_type_trans(skb, net_dev);
646 #endif /* CONFIG_BR2684_FAST_TRANS */
648 skb_pull(skb, plen - ETH_HLEN);
649 skb->protocol = eth_type_trans(skb, net_dev);
650 #endif /* FASTER_VERSION */
651 #ifdef CONFIG_ATM_BR2684_IPFILTER
652 if (unlikely(packet_fails_filter(skb->protocol, brvcc, skb))) {
653 brdev->stats.rx_dropped++;
657 #endif /* CONFIG_ATM_BR2684_IPFILTER */
658 #if defined(CONFIG_MIPS_BRCM)
659 if (brvcc->proto_filter & FILTER_PPPOE) {
660 if ((skb->protocol != htons(ETH_P_PPP_DISC)) && (skb->protocol != htons(ETH_P_PPP_SES))) {
661 DPRINTK("non-PPPOE packet dropped on RX dev %s\n", net_dev->name);
669 ATM_SKB(skb)->vcc = atmvcc; /* needed ? */
670 DPRINTK("received packet's protocol: %x\n", ntohs(skb->protocol));
672 if (unlikely(!(net_dev->flags & IFF_UP))) {
673 /* sigh, interface is down */
674 brdev->stats.rx_dropped++;
678 brdev->stats.rx_packets++;
679 brdev->stats.rx_bytes += skb->len;
680 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
685 static int br2684_regvcc(struct atm_vcc *atmvcc, void __user *arg)
687 /* assign a vcc to a dev
688 Note: we do not have explicit unassign, but look at _push()
691 struct br2684_vcc *brvcc;
692 struct sk_buff_head copy;
694 struct br2684_dev *brdev;
695 struct net_device *net_dev;
696 struct atm_backend_br2684 be;
698 if (copy_from_user(&be, arg, sizeof be))
700 brvcc = kmalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
703 memset(brvcc, 0, sizeof(struct br2684_vcc));
704 write_lock_irq(&devs_lock);
705 net_dev = br2684_find_dev(&be.ifspec);
706 if (net_dev == NULL) {
708 "br2684: tried to attach to non-existant device\n");
712 brdev = BRPRIV(net_dev);
713 if (atmvcc->push == NULL) {
717 if (!list_empty(&brdev->brvccs)) {
718 /* Only 1 VCC/dev right now */
722 if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO ||
723 be.fcs_auto || be.has_vpiid || be.send_padding || (be.encaps !=
724 BR2684_ENCAPS_VC && be.encaps != BR2684_ENCAPS_LLC) ||
729 DPRINTK("br2684_regvcc vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, be.encaps,
731 if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) {
732 unsigned char *esi = atmvcc->dev->esi;
733 if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5])
734 memcpy(net_dev->dev_addr, esi, net_dev->addr_len);
736 net_dev->dev_addr[2] = 1;
738 list_add(&brvcc->brvccs, &brdev->brvccs);
739 write_unlock_irq(&devs_lock);
740 brvcc->device = net_dev;
741 brvcc->atmvcc = atmvcc;
742 atmvcc->user_back = brvcc;
743 brvcc->encaps = (enum br2684_encaps) be.encaps;
744 brvcc->old_push = atmvcc->push;
745 #if defined(CONFIG_MIPS_BRCM)
746 brvcc->proto_filter |= be.proto_filter;
748 brvcc->vlan_id = be.vlan_id;
749 #endif // SUPPORT_VLAN
752 atmvcc->push = br2684_push;
753 skb_queue_head_init(©);
754 skb_migrate(&atmvcc->sk->sk_receive_queue, ©);
755 while ((skb = skb_dequeue(©)) != NULL) {
756 BRPRIV(skb->dev)->stats.rx_bytes -= skb->len;
757 BRPRIV(skb->dev)->stats.rx_packets--;
758 br2684_push(atmvcc, skb);
760 __module_get(THIS_MODULE);
763 write_unlock_irq(&devs_lock);
768 static void br2684_setup(struct net_device *netdev)
770 struct br2684_dev *brdev = BRPRIV(netdev);
773 brdev->net_dev = netdev;
775 #ifdef FASTER_VERSION
776 my_eth_header = netdev->hard_header;
777 netdev->hard_header = br2684_header;
778 my_eth_header_cache = netdev->hard_header_cache;
779 netdev->hard_header_cache = br2684_header_cache;
780 netdev->hard_header_len = sizeof(llc_oui_pid_pad) + ETH_HLEN; /* 10 + 14 */
782 my_eth_mac_addr = netdev->set_mac_address;
783 netdev->set_mac_address = br2684_mac_addr;
784 netdev->hard_start_xmit = br2684_start_xmit;
785 netdev->get_stats = br2684_get_stats;
787 INIT_LIST_HEAD(&brdev->brvccs);
790 static int br2684_create(void __user *arg)
793 struct net_device *netdev;
794 struct br2684_dev *brdev;
795 struct atm_newif_br2684 ni;
797 DPRINTK("br2684_create\n");
799 if (copy_from_user(&ni, arg, sizeof ni)) {
802 if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500) {
806 netdev = alloc_netdev(sizeof(struct br2684_dev),
807 ni.ifname[0] ? ni.ifname : "nas%d",
812 brdev = BRPRIV(netdev);
814 DPRINTK("registered netdev %s\n", netdev->name);
815 /* open, stop, do_ioctl ? */
816 err = register_netdev(netdev);
818 printk(KERN_ERR "br2684_create: register_netdev failed\n");
823 write_lock_irq(&devs_lock);
824 brdev->number = list_empty(&br2684_devs) ? 1 :
825 BRPRIV(list_entry_brdev(br2684_devs.prev))->number + 1;
826 list_add_tail(&brdev->br2684_devs, &br2684_devs);
827 write_unlock_irq(&devs_lock);
832 * This handles ioctls actually performed on our vcc - we must return
833 * -ENOIOCTLCMD for any unrecognized ioctl
835 static int br2684_ioctl(struct socket *sock, unsigned int cmd,
838 struct atm_vcc *atmvcc = ATM_SD(sock);
839 void __user *argp = (void __user *)arg;
844 case ATM_NEWBACKENDIF: {
846 err = get_user(b, (atm_backend_t __user *) argp);
849 if (b != ATM_BACKEND_BR2684)
851 if (!capable(CAP_NET_ADMIN))
853 if (cmd == ATM_SETBACKEND)
854 return br2684_regvcc(atmvcc, argp);
856 return br2684_create(argp);
858 #ifdef CONFIG_ATM_BR2684_IPFILTER
860 if (atmvcc->push != br2684_push)
862 if (!capable(CAP_NET_ADMIN))
864 err = br2684_setfilt(atmvcc, argp);
866 #endif /* CONFIG_ATM_BR2684_IPFILTER */
871 static struct atm_ioctl br2684_ioctl_ops = {
872 .owner = THIS_MODULE,
873 .ioctl = br2684_ioctl,
877 #ifdef CONFIG_PROC_FS
878 static void *br2684_seq_start(struct seq_file *seq, loff_t *pos)
881 struct br2684_dev *brd;
883 read_lock(&devs_lock);
885 list_for_each_entry(brd, &br2684_devs, br2684_devs) {
893 static void *br2684_seq_next(struct seq_file *seq, void *v, loff_t *pos)
895 struct br2684_dev *brd = v;
899 brd = list_entry(brd->br2684_devs.next,
900 struct br2684_dev, br2684_devs);
901 return (&brd->br2684_devs != &br2684_devs) ? brd : NULL;
904 static void br2684_seq_stop(struct seq_file *seq, void *v)
906 read_unlock(&devs_lock);
909 static int br2684_seq_show(struct seq_file *seq, void *v)
911 const struct br2684_dev *brdev = v;
912 const struct net_device *net_dev = brdev->net_dev;
913 const struct br2684_vcc *brvcc;
915 seq_printf(seq, "dev %.16s: num=%d, mac=%02X:%02X:"
916 "%02X:%02X:%02X:%02X (%s)\n", net_dev->name,
918 net_dev->dev_addr[0],
919 net_dev->dev_addr[1],
920 net_dev->dev_addr[2],
921 net_dev->dev_addr[3],
922 net_dev->dev_addr[4],
923 net_dev->dev_addr[5],
924 brdev->mac_was_set ? "set" : "auto");
926 list_for_each_entry(brvcc, &brdev->brvccs, brvccs) {
927 seq_printf(seq, " vcc %d.%d.%d: encaps=%s"
928 #ifndef FASTER_VERSION
929 ", failed copies %u/%u"
930 #endif /* FASTER_VERSION */
931 "\n", brvcc->atmvcc->dev->number,
932 brvcc->atmvcc->vpi, brvcc->atmvcc->vci,
933 (brvcc->encaps == e_llc) ? "LLC" : "VC"
934 #ifndef FASTER_VERSION
935 , brvcc->copies_failed
936 , brvcc->copies_needed
937 #endif /* FASTER_VERSION */
939 #ifdef CONFIG_ATM_BR2684_IPFILTER
940 #define b1(var, byte) ((u8 *) &brvcc->filter.var)[byte]
941 #define bs(var) b1(var, 0), b1(var, 1), b1(var, 2), b1(var, 3)
942 if (brvcc->filter.netmask != 0)
943 seq_printf(seq, " filter=%d.%d.%d.%d/"
945 bs(prefix), bs(netmask));
948 #endif /* CONFIG_ATM_BR2684_IPFILTER */
953 static struct seq_operations br2684_seq_ops = {
954 .start = br2684_seq_start,
955 .next = br2684_seq_next,
956 .stop = br2684_seq_stop,
957 .show = br2684_seq_show,
960 static int br2684_proc_open(struct inode *inode, struct file *file)
962 return seq_open(file, &br2684_seq_ops);
965 static struct file_operations br2684_proc_ops = {
966 .owner = THIS_MODULE,
967 .open = br2684_proc_open,
970 .release = seq_release,
973 extern struct proc_dir_entry *atm_proc_root; /* from proc.c */
976 static int __init br2684_init(void)
978 #ifdef CONFIG_PROC_FS
979 struct proc_dir_entry *p;
980 if ((p = create_proc_entry("br2684", 0, atm_proc_root)) == NULL)
982 p->proc_fops = &br2684_proc_ops;
984 register_atm_ioctl(&br2684_ioctl_ops);
988 static void __exit br2684_exit(void)
990 struct net_device *net_dev;
991 struct br2684_dev *brdev;
992 struct br2684_vcc *brvcc;
993 deregister_atm_ioctl(&br2684_ioctl_ops);
995 #ifdef CONFIG_PROC_FS
996 remove_proc_entry("br2684", atm_proc_root);
999 while (!list_empty(&br2684_devs)) {
1000 net_dev = list_entry_brdev(br2684_devs.next);
1001 brdev = BRPRIV(net_dev);
1002 while (!list_empty(&brdev->brvccs)) {
1003 brvcc = list_entry_brvcc(brdev->brvccs.next);
1004 br2684_close_vcc(brvcc);
1007 list_del(&brdev->br2684_devs);
1008 unregister_netdev(net_dev);
1009 free_netdev(net_dev);
1013 module_init(br2684_init);
1014 module_exit(br2684_exit);
1016 MODULE_AUTHOR("Marcell GAL");
1017 MODULE_DESCRIPTION("RFC2684 bridged protocols over ATM/AAL5");
1018 MODULE_LICENSE("GPL");