Revert "backport: slub: fix possible NULL pointer dereference"
[linux-2.6.22.y-op.git] / net / atm / br2684.c
blob0e9f00c5c89942cfccbd5f76afa84e82f7afc4cc
1 /*
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
5 */
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/list.h>
11 #include <linux/netdevice.h>
12 #include <linux/skbuff.h>
13 #include <linux/etherdevice.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/ip.h>
16 #include <asm/uaccess.h>
17 #include <net/arp.h>
18 #include <linux/atm.h>
19 #include <linux/atmdev.h>
20 #include <linux/capability.h>
21 #include <linux/seq_file.h>
23 #include <linux/atmbr2684.h>
25 #include "common.h"
28 * Define this to use a version of the code which interacts with the higher
29 * layers in a more intellegent way, by always reserving enough space for
30 * our header at the begining of the packet. However, there may still be
31 * some problems with programs like tcpdump. In 2.5 we'll sort out what
32 * we need to do to get this perfect. For now we just will copy the packet
33 * if we need space for the header
35 /* #define FASTER_VERSION */
37 #ifdef DEBUG
38 #define DPRINTK(format, args...) printk(KERN_DEBUG "br2684: " format, ##args)
39 #else
40 #define DPRINTK(format, args...)
41 #endif
43 #ifdef SKB_DEBUG
44 static void skb_debug(const struct sk_buff *skb)
46 #define NUM2PRINT 50
47 char buf[NUM2PRINT * 3 + 1]; /* 3 chars per byte */
48 int i = 0;
49 for (i = 0; i < skb->len && i < NUM2PRINT; i++) {
50 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
52 printk(KERN_DEBUG "br2684: skb: %s\n", buf);
54 #else
55 #define skb_debug(skb) do {} while (0)
56 #endif
58 static unsigned char llc_oui_pid_pad[] =
59 { 0xAA, 0xAA, 0x03, 0x00, 0x80, 0xC2, 0x00, 0x07, 0x00, 0x00 };
60 #define PADLEN (2)
62 enum br2684_encaps {
63 e_vc = BR2684_ENCAPS_VC,
64 e_llc = BR2684_ENCAPS_LLC,
67 struct br2684_vcc {
68 struct atm_vcc *atmvcc;
69 struct net_device *device;
70 /* keep old push,pop functions for chaining */
71 void (*old_push)(struct atm_vcc *vcc,struct sk_buff *skb);
72 /* void (*old_pop)(struct atm_vcc *vcc,struct sk_buff *skb); */
73 enum br2684_encaps encaps;
74 struct list_head brvccs;
75 #ifdef CONFIG_ATM_BR2684_IPFILTER
76 struct br2684_filter filter;
77 #endif /* CONFIG_ATM_BR2684_IPFILTER */
78 #ifndef FASTER_VERSION
79 unsigned copies_needed, copies_failed;
80 #endif /* FASTER_VERSION */
83 struct br2684_dev {
84 struct net_device *net_dev;
85 struct list_head br2684_devs;
86 int number;
87 struct list_head brvccs; /* one device <=> one vcc (before xmas) */
88 struct net_device_stats stats;
89 int mac_was_set;
93 * This lock should be held for writing any time the list of devices or
94 * their attached vcc's could be altered. It should be held for reading
95 * any time these are being queried. Note that we sometimes need to
96 * do read-locking under interrupt context, so write locking must block
97 * the current CPU's interrupts
99 static DEFINE_RWLOCK(devs_lock);
101 static LIST_HEAD(br2684_devs);
103 static inline struct br2684_dev *BRPRIV(const struct net_device *net_dev)
105 return (struct br2684_dev *) net_dev->priv;
108 static inline struct net_device *list_entry_brdev(const struct list_head *le)
110 return list_entry(le, struct br2684_dev, br2684_devs)->net_dev;
113 static inline struct br2684_vcc *BR2684_VCC(const struct atm_vcc *atmvcc)
115 return (struct br2684_vcc *) (atmvcc->user_back);
118 static inline struct br2684_vcc *list_entry_brvcc(const struct list_head *le)
120 return list_entry(le, struct br2684_vcc, brvccs);
123 /* Caller should hold read_lock(&devs_lock) */
124 static struct net_device *br2684_find_dev(const struct br2684_if_spec *s)
126 struct list_head *lh;
127 struct net_device *net_dev;
128 switch (s->method) {
129 case BR2684_FIND_BYNUM:
130 list_for_each(lh, &br2684_devs) {
131 net_dev = list_entry_brdev(lh);
132 if (BRPRIV(net_dev)->number == s->spec.devnum)
133 return net_dev;
135 break;
136 case BR2684_FIND_BYIFNAME:
137 list_for_each(lh, &br2684_devs) {
138 net_dev = list_entry_brdev(lh);
139 if (!strncmp(net_dev->name, s->spec.ifname, IFNAMSIZ))
140 return net_dev;
142 break;
144 return NULL;
148 * Send a packet out a particular vcc. Not to useful right now, but paves
149 * the way for multiple vcc's per itf. Returns true if we can send,
150 * otherwise false
152 static int br2684_xmit_vcc(struct sk_buff *skb, struct br2684_dev *brdev,
153 struct br2684_vcc *brvcc)
155 struct atm_vcc *atmvcc;
156 #ifdef FASTER_VERSION
157 if (brvcc->encaps == e_llc)
158 memcpy(skb_push(skb, 8), llc_oui_pid_pad, 8);
159 /* last 2 bytes of llc_oui_pid_pad are managed by header routines;
160 yes, you got it: 8 + 2 = sizeof(llc_oui_pid_pad)
162 #else
163 int minheadroom = (brvcc->encaps == e_llc) ? 10 : 2;
164 if (skb_headroom(skb) < minheadroom) {
165 struct sk_buff *skb2 = skb_realloc_headroom(skb, minheadroom);
166 brvcc->copies_needed++;
167 dev_kfree_skb(skb);
168 if (skb2 == NULL) {
169 brvcc->copies_failed++;
170 return 0;
172 skb = skb2;
174 skb_push(skb, minheadroom);
175 if (brvcc->encaps == e_llc)
176 skb_copy_to_linear_data(skb, llc_oui_pid_pad, 10);
177 else
178 memset(skb->data, 0, 2);
179 #endif /* FASTER_VERSION */
180 skb_debug(skb);
182 ATM_SKB(skb)->vcc = atmvcc = brvcc->atmvcc;
183 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->dev);
184 if (!atm_may_send(atmvcc, skb->truesize)) {
185 /* we free this here for now, because we cannot know in a higher
186 layer whether the skb point it supplied wasn't freed yet.
187 now, it always is.
189 dev_kfree_skb(skb);
190 return 0;
192 atomic_add(skb->truesize, &sk_atm(atmvcc)->sk_wmem_alloc);
193 ATM_SKB(skb)->atm_options = atmvcc->atm_options;
194 brdev->stats.tx_packets++;
195 brdev->stats.tx_bytes += skb->len;
196 atmvcc->send(atmvcc, skb);
197 return 1;
200 static inline struct br2684_vcc *pick_outgoing_vcc(struct sk_buff *skb,
201 struct br2684_dev *brdev)
203 return list_empty(&brdev->brvccs) ? NULL :
204 list_entry_brvcc(brdev->brvccs.next); /* 1 vcc/dev right now */
207 static int br2684_start_xmit(struct sk_buff *skb, struct net_device *dev)
209 struct br2684_dev *brdev = BRPRIV(dev);
210 struct br2684_vcc *brvcc;
212 DPRINTK("br2684_start_xmit, skb->dst=%p\n", skb->dst);
213 read_lock(&devs_lock);
214 brvcc = pick_outgoing_vcc(skb, brdev);
215 if (brvcc == NULL) {
216 DPRINTK("no vcc attached to dev %s\n", dev->name);
217 brdev->stats.tx_errors++;
218 brdev->stats.tx_carrier_errors++;
219 /* netif_stop_queue(dev); */
220 dev_kfree_skb(skb);
221 read_unlock(&devs_lock);
222 return 0;
224 if (!br2684_xmit_vcc(skb, brdev, brvcc)) {
226 * We should probably use netif_*_queue() here, but that
227 * involves added complication. We need to walk before
228 * we can run
230 /* don't free here! this pointer might be no longer valid!
231 dev_kfree_skb(skb);
233 brdev->stats.tx_errors++;
234 brdev->stats.tx_fifo_errors++;
236 read_unlock(&devs_lock);
237 return 0;
240 static struct net_device_stats *br2684_get_stats(struct net_device *dev)
242 DPRINTK("br2684_get_stats\n");
243 return &BRPRIV(dev)->stats;
246 #ifdef FASTER_VERSION
248 * These mirror eth_header and eth_header_cache. They are not usually
249 * exported for use in modules, so we grab them from net_device
250 * after ether_setup() is done with it. Bit of a hack.
252 static int (*my_eth_header)(struct sk_buff *, struct net_device *,
253 unsigned short, void *, void *, unsigned);
254 static int (*my_eth_header_cache)(struct neighbour *, struct hh_cache *);
256 static int
257 br2684_header(struct sk_buff *skb, struct net_device *dev,
258 unsigned short type, void *daddr, void *saddr, unsigned len)
260 u16 *pad_before_eth;
261 int t = my_eth_header(skb, dev, type, daddr, saddr, len);
262 if (t > 0) {
263 pad_before_eth = (u16 *) skb_push(skb, 2);
264 *pad_before_eth = 0;
265 return dev->hard_header_len; /* or return 16; ? */
266 } else
267 return t;
270 static int
271 br2684_header_cache(struct neighbour *neigh, struct hh_cache *hh)
273 /* hh_data is 16 bytes long. if encaps is ether-llc we need 24, so
274 xmit will add the additional header part in that case */
275 u16 *pad_before_eth = (u16 *)(hh->hh_data);
276 int t = my_eth_header_cache(neigh, hh);
277 DPRINTK("br2684_header_cache, neigh=%p, hh_cache=%p\n", neigh, hh);
278 if (t < 0)
279 return t;
280 else {
281 *pad_before_eth = 0;
282 hh->hh_len = PADLEN + ETH_HLEN;
284 return 0;
288 * This is similar to eth_type_trans, which cannot be used because of
289 * our dev->hard_header_len
291 static inline __be16 br_type_trans(struct sk_buff *skb, struct net_device *dev)
293 struct ethhdr *eth;
294 unsigned char *rawp;
295 eth = eth_hdr(skb);
297 if (is_multicast_ether_addr(eth->h_dest)) {
298 if (!compare_ether_addr(eth->h_dest, dev->broadcast))
299 skb->pkt_type = PACKET_BROADCAST;
300 else
301 skb->pkt_type = PACKET_MULTICAST;
304 else if (compare_ether_addr(eth->h_dest, dev->dev_addr))
305 skb->pkt_type = PACKET_OTHERHOST;
307 if (ntohs(eth->h_proto) >= 1536)
308 return eth->h_proto;
310 rawp = skb->data;
313 * This is a magic hack to spot IPX packets. Older Novell breaks
314 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
315 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
316 * won't work for fault tolerant netware but does for the rest.
318 if (*(unsigned short *) rawp == 0xFFFF)
319 return htons(ETH_P_802_3);
322 * Real 802.2 LLC
324 return htons(ETH_P_802_2);
326 #endif /* FASTER_VERSION */
329 * We remember when the MAC gets set, so we don't override it later with
330 * the ESI of the ATM card of the first VC
332 static int (*my_eth_mac_addr)(struct net_device *, void *);
333 static int br2684_mac_addr(struct net_device *dev, void *p)
335 int err = my_eth_mac_addr(dev, p);
336 if (!err)
337 BRPRIV(dev)->mac_was_set = 1;
338 return err;
341 #ifdef CONFIG_ATM_BR2684_IPFILTER
342 /* this IOCTL is experimental. */
343 static int br2684_setfilt(struct atm_vcc *atmvcc, void __user *arg)
345 struct br2684_vcc *brvcc;
346 struct br2684_filter_set fs;
348 if (copy_from_user(&fs, arg, sizeof fs))
349 return -EFAULT;
350 if (fs.ifspec.method != BR2684_FIND_BYNOTHING) {
352 * This is really a per-vcc thing, but we can also search
353 * by device
355 struct br2684_dev *brdev;
356 read_lock(&devs_lock);
357 brdev = BRPRIV(br2684_find_dev(&fs.ifspec));
358 if (brdev == NULL || list_empty(&brdev->brvccs) ||
359 brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */
360 brvcc = NULL;
361 else
362 brvcc = list_entry_brvcc(brdev->brvccs.next);
363 read_unlock(&devs_lock);
364 if (brvcc == NULL)
365 return -ESRCH;
366 } else
367 brvcc = BR2684_VCC(atmvcc);
368 memcpy(&brvcc->filter, &fs.filter, sizeof(brvcc->filter));
369 return 0;
372 /* Returns 1 if packet should be dropped */
373 static inline int
374 packet_fails_filter(__be16 type, struct br2684_vcc *brvcc, struct sk_buff *skb)
376 if (brvcc->filter.netmask == 0)
377 return 0; /* no filter in place */
378 if (type == htons(ETH_P_IP) &&
379 (((struct iphdr *) (skb->data))->daddr & brvcc->filter.
380 netmask) == brvcc->filter.prefix)
381 return 0;
382 if (type == htons(ETH_P_ARP))
383 return 0;
384 /* TODO: we should probably filter ARPs too.. don't want to have
385 * them returning values that don't make sense, or is that ok?
387 return 1; /* drop */
389 #endif /* CONFIG_ATM_BR2684_IPFILTER */
391 static void br2684_close_vcc(struct br2684_vcc *brvcc)
393 DPRINTK("removing VCC %p from dev %p\n", brvcc, brvcc->device);
394 write_lock_irq(&devs_lock);
395 list_del(&brvcc->brvccs);
396 write_unlock_irq(&devs_lock);
397 brvcc->atmvcc->user_back = NULL; /* what about vcc->recvq ??? */
398 brvcc->old_push(brvcc->atmvcc, NULL); /* pass on the bad news */
399 kfree(brvcc);
400 module_put(THIS_MODULE);
403 /* when AAL5 PDU comes in: */
404 static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
406 struct br2684_vcc *brvcc = BR2684_VCC(atmvcc);
407 struct net_device *net_dev = brvcc->device;
408 struct br2684_dev *brdev = BRPRIV(net_dev);
409 int plen = sizeof(llc_oui_pid_pad) + ETH_HLEN;
411 DPRINTK("br2684_push\n");
413 if (unlikely(skb == NULL)) {
414 /* skb==NULL means VCC is being destroyed */
415 br2684_close_vcc(brvcc);
416 if (list_empty(&brdev->brvccs)) {
417 read_lock(&devs_lock);
418 list_del(&brdev->br2684_devs);
419 read_unlock(&devs_lock);
420 unregister_netdev(net_dev);
421 free_netdev(net_dev);
423 return;
426 skb_debug(skb);
427 atm_return(atmvcc, skb->truesize);
428 DPRINTK("skb from brdev %p\n", brdev);
429 if (brvcc->encaps == e_llc) {
430 /* let us waste some time for checking the encapsulation.
431 Note, that only 7 char is checked so frames with a valid FCS
432 are also accepted (but FCS is not checked of course) */
433 if (memcmp(skb->data, llc_oui_pid_pad, 7)) {
434 brdev->stats.rx_errors++;
435 dev_kfree_skb(skb);
436 return;
439 /* Strip FCS if present */
440 if (skb->len > 7 && skb->data[7] == 0x01)
441 __skb_trim(skb, skb->len - 4);
442 } else {
443 plen = PADLEN + ETH_HLEN; /* pad, dstmac,srcmac, ethtype */
444 /* first 2 chars should be 0 */
445 if (*((u16 *) (skb->data)) != 0) {
446 brdev->stats.rx_errors++;
447 dev_kfree_skb(skb);
448 return;
451 if (skb->len < plen) {
452 brdev->stats.rx_errors++;
453 dev_kfree_skb(skb); /* dev_ not needed? */
454 return;
457 #ifdef FASTER_VERSION
458 /* FIXME: tcpdump shows that pointer to mac header is 2 bytes earlier,
459 than should be. What else should I set? */
460 skb_pull(skb, plen);
461 skb_set_mac_header(skb, -ETH_HLEN);
462 skb->pkt_type = PACKET_HOST;
463 #ifdef CONFIG_BR2684_FAST_TRANS
464 skb->protocol = ((u16 *) skb->data)[-1];
465 #else /* some protocols might require this: */
466 skb->protocol = br_type_trans(skb, net_dev);
467 #endif /* CONFIG_BR2684_FAST_TRANS */
468 #else
469 skb_pull(skb, plen - ETH_HLEN);
470 skb->protocol = eth_type_trans(skb, net_dev);
471 #endif /* FASTER_VERSION */
472 #ifdef CONFIG_ATM_BR2684_IPFILTER
473 if (unlikely(packet_fails_filter(skb->protocol, brvcc, skb))) {
474 brdev->stats.rx_dropped++;
475 dev_kfree_skb(skb);
476 return;
478 #endif /* CONFIG_ATM_BR2684_IPFILTER */
479 skb->dev = net_dev;
480 ATM_SKB(skb)->vcc = atmvcc; /* needed ? */
481 DPRINTK("received packet's protocol: %x\n", ntohs(skb->protocol));
482 skb_debug(skb);
483 if (unlikely(!(net_dev->flags & IFF_UP))) {
484 /* sigh, interface is down */
485 brdev->stats.rx_dropped++;
486 dev_kfree_skb(skb);
487 return;
489 brdev->stats.rx_packets++;
490 brdev->stats.rx_bytes += skb->len;
491 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
492 netif_rx(skb);
495 static int br2684_regvcc(struct atm_vcc *atmvcc, void __user *arg)
497 /* assign a vcc to a dev
498 Note: we do not have explicit unassign, but look at _push()
500 int err;
501 struct br2684_vcc *brvcc;
502 struct sk_buff *skb;
503 struct sk_buff_head *rq;
504 struct br2684_dev *brdev;
505 struct net_device *net_dev;
506 struct atm_backend_br2684 be;
507 unsigned long flags;
509 if (copy_from_user(&be, arg, sizeof be))
510 return -EFAULT;
511 brvcc = kzalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
512 if (!brvcc)
513 return -ENOMEM;
514 write_lock_irq(&devs_lock);
515 net_dev = br2684_find_dev(&be.ifspec);
516 if (net_dev == NULL) {
517 printk(KERN_ERR
518 "br2684: tried to attach to non-existant device\n");
519 err = -ENXIO;
520 goto error;
522 brdev = BRPRIV(net_dev);
523 if (atmvcc->push == NULL) {
524 err = -EBADFD;
525 goto error;
527 if (!list_empty(&brdev->brvccs)) {
528 /* Only 1 VCC/dev right now */
529 err = -EEXIST;
530 goto error;
532 if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO ||
533 be.fcs_auto || be.has_vpiid || be.send_padding || (be.encaps !=
534 BR2684_ENCAPS_VC && be.encaps != BR2684_ENCAPS_LLC) ||
535 be.min_size != 0) {
536 err = -EINVAL;
537 goto error;
539 DPRINTK("br2684_regvcc vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, be.encaps,
540 brvcc);
541 if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) {
542 unsigned char *esi = atmvcc->dev->esi;
543 if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5])
544 memcpy(net_dev->dev_addr, esi, net_dev->addr_len);
545 else
546 net_dev->dev_addr[2] = 1;
548 list_add(&brvcc->brvccs, &brdev->brvccs);
549 write_unlock_irq(&devs_lock);
550 brvcc->device = net_dev;
551 brvcc->atmvcc = atmvcc;
552 atmvcc->user_back = brvcc;
553 brvcc->encaps = (enum br2684_encaps) be.encaps;
554 brvcc->old_push = atmvcc->push;
555 barrier();
556 atmvcc->push = br2684_push;
558 rq = &sk_atm(atmvcc)->sk_receive_queue;
560 spin_lock_irqsave(&rq->lock, flags);
561 if (skb_queue_empty(rq)) {
562 skb = NULL;
563 } else {
564 /* NULL terminate the list. */
565 rq->prev->next = NULL;
566 skb = rq->next;
568 rq->prev = rq->next = (struct sk_buff *)rq;
569 rq->qlen = 0;
570 spin_unlock_irqrestore(&rq->lock, flags);
572 while (skb) {
573 struct sk_buff *next = skb->next;
575 skb->next = skb->prev = NULL;
576 BRPRIV(skb->dev)->stats.rx_bytes -= skb->len;
577 BRPRIV(skb->dev)->stats.rx_packets--;
578 br2684_push(atmvcc, skb);
580 skb = next;
582 __module_get(THIS_MODULE);
583 return 0;
584 error:
585 write_unlock_irq(&devs_lock);
586 kfree(brvcc);
587 return err;
590 static void br2684_setup(struct net_device *netdev)
592 struct br2684_dev *brdev = BRPRIV(netdev);
594 ether_setup(netdev);
595 brdev->net_dev = netdev;
597 #ifdef FASTER_VERSION
598 my_eth_header = netdev->hard_header;
599 netdev->hard_header = br2684_header;
600 my_eth_header_cache = netdev->hard_header_cache;
601 netdev->hard_header_cache = br2684_header_cache;
602 netdev->hard_header_len = sizeof(llc_oui_pid_pad) + ETH_HLEN; /* 10 + 14 */
603 #endif
604 my_eth_mac_addr = netdev->set_mac_address;
605 netdev->set_mac_address = br2684_mac_addr;
606 netdev->hard_start_xmit = br2684_start_xmit;
607 netdev->get_stats = br2684_get_stats;
609 INIT_LIST_HEAD(&brdev->brvccs);
612 static int br2684_create(void __user *arg)
614 int err;
615 struct net_device *netdev;
616 struct br2684_dev *brdev;
617 struct atm_newif_br2684 ni;
619 DPRINTK("br2684_create\n");
621 if (copy_from_user(&ni, arg, sizeof ni)) {
622 return -EFAULT;
624 if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500) {
625 return -EINVAL;
628 netdev = alloc_netdev(sizeof(struct br2684_dev),
629 ni.ifname[0] ? ni.ifname : "nas%d",
630 br2684_setup);
631 if (!netdev)
632 return -ENOMEM;
634 brdev = BRPRIV(netdev);
636 DPRINTK("registered netdev %s\n", netdev->name);
637 /* open, stop, do_ioctl ? */
638 err = register_netdev(netdev);
639 if (err < 0) {
640 printk(KERN_ERR "br2684_create: register_netdev failed\n");
641 free_netdev(netdev);
642 return err;
645 write_lock_irq(&devs_lock);
646 brdev->number = list_empty(&br2684_devs) ? 1 :
647 BRPRIV(list_entry_brdev(br2684_devs.prev))->number + 1;
648 list_add_tail(&brdev->br2684_devs, &br2684_devs);
649 write_unlock_irq(&devs_lock);
650 return 0;
654 * This handles ioctls actually performed on our vcc - we must return
655 * -ENOIOCTLCMD for any unrecognized ioctl
657 static int br2684_ioctl(struct socket *sock, unsigned int cmd,
658 unsigned long arg)
660 struct atm_vcc *atmvcc = ATM_SD(sock);
661 void __user *argp = (void __user *)arg;
663 int err;
664 switch(cmd) {
665 case ATM_SETBACKEND:
666 case ATM_NEWBACKENDIF: {
667 atm_backend_t b;
668 err = get_user(b, (atm_backend_t __user *) argp);
669 if (err)
670 return -EFAULT;
671 if (b != ATM_BACKEND_BR2684)
672 return -ENOIOCTLCMD;
673 if (!capable(CAP_NET_ADMIN))
674 return -EPERM;
675 if (cmd == ATM_SETBACKEND)
676 return br2684_regvcc(atmvcc, argp);
677 else
678 return br2684_create(argp);
680 #ifdef CONFIG_ATM_BR2684_IPFILTER
681 case BR2684_SETFILT:
682 if (atmvcc->push != br2684_push)
683 return -ENOIOCTLCMD;
684 if (!capable(CAP_NET_ADMIN))
685 return -EPERM;
686 err = br2684_setfilt(atmvcc, argp);
687 return err;
688 #endif /* CONFIG_ATM_BR2684_IPFILTER */
690 return -ENOIOCTLCMD;
693 static struct atm_ioctl br2684_ioctl_ops = {
694 .owner = THIS_MODULE,
695 .ioctl = br2684_ioctl,
699 #ifdef CONFIG_PROC_FS
700 static void *br2684_seq_start(struct seq_file *seq, loff_t *pos)
702 loff_t offs = 0;
703 struct br2684_dev *brd;
705 read_lock(&devs_lock);
707 list_for_each_entry(brd, &br2684_devs, br2684_devs) {
708 if (offs == *pos)
709 return brd;
710 ++offs;
712 return NULL;
715 static void *br2684_seq_next(struct seq_file *seq, void *v, loff_t *pos)
717 struct br2684_dev *brd = v;
719 ++*pos;
721 brd = list_entry(brd->br2684_devs.next,
722 struct br2684_dev, br2684_devs);
723 return (&brd->br2684_devs != &br2684_devs) ? brd : NULL;
726 static void br2684_seq_stop(struct seq_file *seq, void *v)
728 read_unlock(&devs_lock);
731 static int br2684_seq_show(struct seq_file *seq, void *v)
733 const struct br2684_dev *brdev = v;
734 const struct net_device *net_dev = brdev->net_dev;
735 const struct br2684_vcc *brvcc;
737 seq_printf(seq, "dev %.16s: num=%d, mac=%02X:%02X:"
738 "%02X:%02X:%02X:%02X (%s)\n", net_dev->name,
739 brdev->number,
740 net_dev->dev_addr[0],
741 net_dev->dev_addr[1],
742 net_dev->dev_addr[2],
743 net_dev->dev_addr[3],
744 net_dev->dev_addr[4],
745 net_dev->dev_addr[5],
746 brdev->mac_was_set ? "set" : "auto");
748 list_for_each_entry(brvcc, &brdev->brvccs, brvccs) {
749 seq_printf(seq, " vcc %d.%d.%d: encaps=%s"
750 #ifndef FASTER_VERSION
751 ", failed copies %u/%u"
752 #endif /* FASTER_VERSION */
753 "\n", brvcc->atmvcc->dev->number,
754 brvcc->atmvcc->vpi, brvcc->atmvcc->vci,
755 (brvcc->encaps == e_llc) ? "LLC" : "VC"
756 #ifndef FASTER_VERSION
757 , brvcc->copies_failed
758 , brvcc->copies_needed
759 #endif /* FASTER_VERSION */
761 #ifdef CONFIG_ATM_BR2684_IPFILTER
762 #define b1(var, byte) ((u8 *) &brvcc->filter.var)[byte]
763 #define bs(var) b1(var, 0), b1(var, 1), b1(var, 2), b1(var, 3)
764 if (brvcc->filter.netmask != 0)
765 seq_printf(seq, " filter=%d.%d.%d.%d/"
766 "%d.%d.%d.%d\n",
767 bs(prefix), bs(netmask));
768 #undef bs
769 #undef b1
770 #endif /* CONFIG_ATM_BR2684_IPFILTER */
772 return 0;
775 static struct seq_operations br2684_seq_ops = {
776 .start = br2684_seq_start,
777 .next = br2684_seq_next,
778 .stop = br2684_seq_stop,
779 .show = br2684_seq_show,
782 static int br2684_proc_open(struct inode *inode, struct file *file)
784 return seq_open(file, &br2684_seq_ops);
787 static const struct file_operations br2684_proc_ops = {
788 .owner = THIS_MODULE,
789 .open = br2684_proc_open,
790 .read = seq_read,
791 .llseek = seq_lseek,
792 .release = seq_release,
795 extern struct proc_dir_entry *atm_proc_root; /* from proc.c */
796 #endif
798 static int __init br2684_init(void)
800 #ifdef CONFIG_PROC_FS
801 struct proc_dir_entry *p;
802 if ((p = create_proc_entry("br2684", 0, atm_proc_root)) == NULL)
803 return -ENOMEM;
804 p->proc_fops = &br2684_proc_ops;
805 #endif
806 register_atm_ioctl(&br2684_ioctl_ops);
807 return 0;
810 static void __exit br2684_exit(void)
812 struct net_device *net_dev;
813 struct br2684_dev *brdev;
814 struct br2684_vcc *brvcc;
815 deregister_atm_ioctl(&br2684_ioctl_ops);
817 #ifdef CONFIG_PROC_FS
818 remove_proc_entry("br2684", atm_proc_root);
819 #endif
821 while (!list_empty(&br2684_devs)) {
822 net_dev = list_entry_brdev(br2684_devs.next);
823 brdev = BRPRIV(net_dev);
824 while (!list_empty(&brdev->brvccs)) {
825 brvcc = list_entry_brvcc(brdev->brvccs.next);
826 br2684_close_vcc(brvcc);
829 list_del(&brdev->br2684_devs);
830 unregister_netdev(net_dev);
831 free_netdev(net_dev);
835 module_init(br2684_init);
836 module_exit(br2684_exit);
838 MODULE_AUTHOR("Marcell GAL");
839 MODULE_DESCRIPTION("RFC2684 bridged protocols over ATM/AAL5");
840 MODULE_LICENSE("GPL");