blob: 8eb6fbe8d8dd681fd36e4897d98d9105bca59ea3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Chas Williamsfb64c732007-12-30 23:18:29 -08002 * Ethernet netdevice using ATM AAL5 as underlying carrier
3 * (RFC1483 obsoleted by RFC2684) for Linux
4 *
5 * Authors: Marcell GAL, 2000, XDSL Ltd, Hungary
6 * Eric Kinzie, 2006-2007, US Naval Research Laboratory
7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Joe Perches99824462010-01-26 11:40:00 +00009#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/list.h>
15#include <linux/netdevice.h>
16#include <linux/skbuff.h>
17#include <linux/etherdevice.h>
18#include <linux/rtnetlink.h>
19#include <linux/ip.h>
Joe Perches641d7292010-01-26 11:40:04 +000020#include <linux/uaccess.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <net/arp.h>
23#include <linux/atm.h>
24#include <linux/atmdev.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080025#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/seq_file.h>
27
28#include <linux/atmbr2684.h>
29
30#include "common.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static void skb_debug(const struct sk_buff *skb)
33{
Joe Perches641d7292010-01-26 11:40:04 +000034#ifdef SKB_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define NUM2PRINT 50
Joe Perches641d7292010-01-26 11:40:04 +000036 print_hex_dump(KERN_DEBUG, "br2684: skb: ", DUMP_OFFSET,
37 16, 1, skb->data, min(NUM2PRINT, skb->len), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#endif
Joe Perches641d7292010-01-26 11:40:04 +000039}
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Eric Kinzie097b19a2007-12-30 23:17:53 -080041#define BR2684_ETHERTYPE_LEN 2
42#define BR2684_PAD_LEN 2
43
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
51
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070052static const unsigned char ethertype_ipv4[] = { ETHERTYPE_IPV4 };
53static const unsigned char ethertype_ipv6[] = { ETHERTYPE_IPV6 };
54static const unsigned char llc_oui_pid_pad[] =
Chas Williamsfb64c732007-12-30 23:18:29 -080055 { LLC, SNAP_BRIDGED, PID_ETHERNET, PAD_BRIDGED };
Pascal Hambourgbefc93f2011-08-17 08:37:52 +020056static const unsigned char pad[] = { PAD_BRIDGED };
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070057static const unsigned char llc_oui_ipv4[] = { LLC, SNAP_ROUTED, ETHERTYPE_IPV4 };
58static const unsigned char llc_oui_ipv6[] = { LLC, SNAP_ROUTED, ETHERTYPE_IPV6 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60enum br2684_encaps {
Chas Williamsfb64c732007-12-30 23:18:29 -080061 e_vc = BR2684_ENCAPS_VC,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 e_llc = BR2684_ENCAPS_LLC,
63};
64
65struct br2684_vcc {
Chas Williamsfb64c732007-12-30 23:18:29 -080066 struct atm_vcc *atmvcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct net_device *device;
Chas Williamsfb64c732007-12-30 23:18:29 -080068 /* keep old push, pop functions for chaining */
Joe Perches641d7292010-01-26 11:40:04 +000069 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb);
Karl Hiramoto137742c2009-09-02 23:26:39 -070070 void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 enum br2684_encaps encaps;
72 struct list_head brvccs;
73#ifdef CONFIG_ATM_BR2684_IPFILTER
74 struct br2684_filter filter;
75#endif /* CONFIG_ATM_BR2684_IPFILTER */
Eric Dumazet95c96172012-04-15 05:58:06 +000076 unsigned int copies_needed, copies_failed;
David Woodhouseae088d62012-11-25 12:06:52 +000077 atomic_t qspace;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80struct br2684_dev {
81 struct net_device *net_dev;
82 struct list_head br2684_devs;
83 int number;
Chas Williamsfb64c732007-12-30 23:18:29 -080084 struct list_head brvccs; /* one device <=> one vcc (before xmas) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 int mac_was_set;
Eric Kinzie097b19a2007-12-30 23:17:53 -080086 enum br2684_payload payload;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087};
88
89/*
90 * This lock should be held for writing any time the list of devices or
91 * their attached vcc's could be altered. It should be held for reading
92 * any time these are being queried. Note that we sometimes need to
93 * do read-locking under interrupt context, so write locking must block
94 * the current CPU's interrupts
95 */
96static DEFINE_RWLOCK(devs_lock);
97
98static LIST_HEAD(br2684_devs);
99
100static inline struct br2684_dev *BRPRIV(const struct net_device *net_dev)
101{
Joe Perches37d66802010-11-15 11:12:33 +0000102 return netdev_priv(net_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
105static inline struct net_device *list_entry_brdev(const struct list_head *le)
106{
107 return list_entry(le, struct br2684_dev, br2684_devs)->net_dev;
108}
109
110static inline struct br2684_vcc *BR2684_VCC(const struct atm_vcc *atmvcc)
111{
Chas Williamsfb64c732007-12-30 23:18:29 -0800112 return (struct br2684_vcc *)(atmvcc->user_back);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
115static inline struct br2684_vcc *list_entry_brvcc(const struct list_head *le)
116{
117 return list_entry(le, struct br2684_vcc, brvccs);
118}
119
120/* Caller should hold read_lock(&devs_lock) */
121static struct net_device *br2684_find_dev(const struct br2684_if_spec *s)
122{
123 struct list_head *lh;
124 struct net_device *net_dev;
125 switch (s->method) {
126 case BR2684_FIND_BYNUM:
127 list_for_each(lh, &br2684_devs) {
128 net_dev = list_entry_brdev(lh);
129 if (BRPRIV(net_dev)->number == s->spec.devnum)
130 return net_dev;
131 }
132 break;
133 case BR2684_FIND_BYIFNAME:
134 list_for_each(lh, &br2684_devs) {
135 net_dev = list_entry_brdev(lh);
136 if (!strncmp(net_dev->name, s->spec.ifname, IFNAMSIZ))
137 return net_dev;
138 }
139 break;
140 }
141 return NULL;
142}
143
Karl Hiramoto00506612010-07-08 20:55:31 +0000144static int atm_dev_event(struct notifier_block *this, unsigned long event,
145 void *arg)
146{
147 struct atm_dev *atm_dev = arg;
148 struct list_head *lh;
149 struct net_device *net_dev;
150 struct br2684_vcc *brvcc;
151 struct atm_vcc *atm_vcc;
152 unsigned long flags;
153
154 pr_debug("event=%ld dev=%p\n", event, atm_dev);
155
156 read_lock_irqsave(&devs_lock, flags);
157 list_for_each(lh, &br2684_devs) {
158 net_dev = list_entry_brdev(lh);
159
160 list_for_each_entry(brvcc, &BRPRIV(net_dev)->brvccs, brvccs) {
161 atm_vcc = brvcc->atmvcc;
162 if (atm_vcc && brvcc->atmvcc->dev == atm_dev) {
163
164 if (atm_vcc->dev->signal == ATM_PHY_SIG_LOST)
165 netif_carrier_off(net_dev);
166 else
167 netif_carrier_on(net_dev);
168
169 }
170 }
171 }
172 read_unlock_irqrestore(&devs_lock, flags);
173
174 return NOTIFY_DONE;
175}
176
177static struct notifier_block atm_dev_notifier = {
178 .notifier_call = atm_dev_event,
179};
180
Karl Hiramoto137742c2009-09-02 23:26:39 -0700181/* chained vcc->pop function. Check if we should wake the netif_queue */
182static void br2684_pop(struct atm_vcc *vcc, struct sk_buff *skb)
183{
184 struct br2684_vcc *brvcc = BR2684_VCC(vcc);
Karl Hiramoto137742c2009-09-02 23:26:39 -0700185
David Woodhouseae088d62012-11-25 12:06:52 +0000186 pr_debug("(vcc %p ; net_dev %p )\n", vcc, brvcc->device);
Karl Hiramoto137742c2009-09-02 23:26:39 -0700187 brvcc->old_pop(vcc, skb);
188
David Woodhouseae088d62012-11-25 12:06:52 +0000189 /* If the queue space just went up from zero, wake */
190 if (atomic_inc_return(&brvcc->qspace) == 1)
191 netif_wake_queue(brvcc->device);
Karl Hiramoto137742c2009-09-02 23:26:39 -0700192}
David Woodhouseae088d62012-11-25 12:06:52 +0000193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/*
195 * Send a packet out a particular vcc. Not to useful right now, but paves
196 * the way for multiple vcc's per itf. Returns true if we can send,
197 * otherwise false
198 */
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000199static int br2684_xmit_vcc(struct sk_buff *skb, struct net_device *dev,
Chas Williamsfb64c732007-12-30 23:18:29 -0800200 struct br2684_vcc *brvcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000202 struct br2684_dev *brdev = BRPRIV(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 struct atm_vcc *atmvcc;
Pascal Hambourg9e667b22011-08-17 08:37:18 +0200204 int minheadroom = (brvcc->encaps == e_llc) ?
205 ((brdev->payload == p_bridged) ?
206 sizeof(llc_oui_pid_pad) : sizeof(llc_oui_ipv4)) :
207 ((brdev->payload == p_bridged) ? BR2684_PAD_LEN : 0);
Eric Kinzie097b19a2007-12-30 23:17:53 -0800208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 if (skb_headroom(skb) < minheadroom) {
210 struct sk_buff *skb2 = skb_realloc_headroom(skb, minheadroom);
211 brvcc->copies_needed++;
212 dev_kfree_skb(skb);
213 if (skb2 == NULL) {
214 brvcc->copies_failed++;
215 return 0;
216 }
217 skb = skb2;
218 }
Eric Kinzie097b19a2007-12-30 23:17:53 -0800219
220 if (brvcc->encaps == e_llc) {
221 if (brdev->payload == p_bridged) {
222 skb_push(skb, sizeof(llc_oui_pid_pad));
Chas Williamsfb64c732007-12-30 23:18:29 -0800223 skb_copy_to_linear_data(skb, llc_oui_pid_pad,
224 sizeof(llc_oui_pid_pad));
Eric Kinzie097b19a2007-12-30 23:17:53 -0800225 } else if (brdev->payload == p_routed) {
226 unsigned short prot = ntohs(skb->protocol);
227
228 skb_push(skb, sizeof(llc_oui_ipv4));
229 switch (prot) {
Chas Williamsfb64c732007-12-30 23:18:29 -0800230 case ETH_P_IP:
231 skb_copy_to_linear_data(skb, llc_oui_ipv4,
232 sizeof(llc_oui_ipv4));
233 break;
234 case ETH_P_IPV6:
235 skb_copy_to_linear_data(skb, llc_oui_ipv6,
236 sizeof(llc_oui_ipv6));
237 break;
238 default:
239 dev_kfree_skb(skb);
240 return 0;
Eric Kinzie097b19a2007-12-30 23:17:53 -0800241 }
242 }
Eric Kinzie7e903c22008-06-16 17:18:18 -0700243 } else { /* e_vc */
244 if (brdev->payload == p_bridged) {
245 skb_push(skb, 2);
Eric Kinzie097b19a2007-12-30 23:17:53 -0800246 memset(skb->data, 0, 2);
Eric Kinzie7e903c22008-06-16 17:18:18 -0700247 }
Eric Kinzie097b19a2007-12-30 23:17:53 -0800248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 skb_debug(skb);
250
251 ATM_SKB(skb)->vcc = atmvcc = brvcc->atmvcc;
Stephen Hemminger52240062007-08-28 15:22:09 -0700252 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 atomic_add(skb->truesize, &sk_atm(atmvcc)->sk_wmem_alloc);
254 ATM_SKB(skb)->atm_options = atmvcc->atm_options;
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000255 dev->stats.tx_packets++;
256 dev->stats.tx_bytes += skb->len;
Karl Hiramoto137742c2009-09-02 23:26:39 -0700257
David Woodhouseae088d62012-11-25 12:06:52 +0000258 if (atomic_dec_return(&brvcc->qspace) < 1) {
259 /* No more please! */
Karl Hiramoto137742c2009-09-02 23:26:39 -0700260 netif_stop_queue(brvcc->device);
David Woodhouseae088d62012-11-25 12:06:52 +0000261 /* We might have raced with br2684_pop() */
262 if (unlikely(atomic_read(&brvcc->qspace) > 0))
263 netif_wake_queue(brvcc->device);
Karl Hiramoto137742c2009-09-02 23:26:39 -0700264 }
265
David Woodhouseae088d62012-11-25 12:06:52 +0000266 /* If this fails immediately, the skb will be freed and br2684_pop()
267 will wake the queue if appropriate. Just return an error so that
268 the stats are updated correctly */
269 return !atmvcc->send(atmvcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700272static inline struct br2684_vcc *pick_outgoing_vcc(const struct sk_buff *skb,
273 const struct br2684_dev *brdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Chas Williamsfb64c732007-12-30 23:18:29 -0800275 return list_empty(&brdev->brvccs) ? NULL : list_entry_brvcc(brdev->brvccs.next); /* 1 vcc/dev right now */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
Stephen Hemminger3c805a22009-08-31 19:50:42 +0000278static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
279 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281 struct br2684_dev *brdev = BRPRIV(dev);
282 struct br2684_vcc *brvcc;
283
Joe Perches99824462010-01-26 11:40:00 +0000284 pr_debug("skb_dst(skb)=%p\n", skb_dst(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 read_lock(&devs_lock);
286 brvcc = pick_outgoing_vcc(skb, brdev);
287 if (brvcc == NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700288 pr_debug("no vcc attached to dev %s\n", dev->name);
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000289 dev->stats.tx_errors++;
290 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /* netif_stop_queue(dev); */
292 dev_kfree_skb(skb);
293 read_unlock(&devs_lock);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000294 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000296 if (!br2684_xmit_vcc(skb, dev, brvcc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 /*
298 * We should probably use netif_*_queue() here, but that
299 * involves added complication. We need to walk before
Chas Williamsfb64c732007-12-30 23:18:29 -0800300 * we can run.
301 *
302 * Don't free here! this pointer might be no longer valid!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 */
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000304 dev->stats.tx_errors++;
305 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307 read_unlock(&devs_lock);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000308 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/*
312 * We remember when the MAC gets set, so we don't override it later with
313 * the ESI of the ATM card of the first VC
314 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315static int br2684_mac_addr(struct net_device *dev, void *p)
316{
Stephen Hemminger0ba25ff2009-01-09 13:00:59 +0000317 int err = eth_mac_addr(dev, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (!err)
319 BRPRIV(dev)->mac_was_set = 1;
320 return err;
321}
322
323#ifdef CONFIG_ATM_BR2684_IPFILTER
324/* this IOCTL is experimental. */
Chas Williamsfb64c732007-12-30 23:18:29 -0800325static int br2684_setfilt(struct atm_vcc *atmvcc, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 struct br2684_vcc *brvcc;
328 struct br2684_filter_set fs;
329
330 if (copy_from_user(&fs, arg, sizeof fs))
331 return -EFAULT;
332 if (fs.ifspec.method != BR2684_FIND_BYNOTHING) {
333 /*
334 * This is really a per-vcc thing, but we can also search
Chas Williamsfb64c732007-12-30 23:18:29 -0800335 * by device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 */
337 struct br2684_dev *brdev;
338 read_lock(&devs_lock);
339 brdev = BRPRIV(br2684_find_dev(&fs.ifspec));
Joe Perches641d7292010-01-26 11:40:04 +0000340 if (brdev == NULL || list_empty(&brdev->brvccs) ||
341 brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 brvcc = NULL;
343 else
344 brvcc = list_entry_brvcc(brdev->brvccs.next);
345 read_unlock(&devs_lock);
346 if (brvcc == NULL)
347 return -ESRCH;
348 } else
349 brvcc = BR2684_VCC(atmvcc);
350 memcpy(&brvcc->filter, &fs.filter, sizeof(brvcc->filter));
351 return 0;
352}
353
354/* Returns 1 if packet should be dropped */
355static inline int
Al Viro30d492d2006-11-14 21:11:29 -0800356packet_fails_filter(__be16 type, struct br2684_vcc *brvcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
358 if (brvcc->filter.netmask == 0)
Chas Williamsfb64c732007-12-30 23:18:29 -0800359 return 0; /* no filter in place */
YOSHIFUJI Hideakiacde4852007-03-25 20:12:32 -0700360 if (type == htons(ETH_P_IP) &&
Chas Williamsfb64c732007-12-30 23:18:29 -0800361 (((struct iphdr *)(skb->data))->daddr & brvcc->filter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 netmask) == brvcc->filter.prefix)
363 return 0;
YOSHIFUJI Hideakiacde4852007-03-25 20:12:32 -0700364 if (type == htons(ETH_P_ARP))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 return 0;
Chas Williamsfb64c732007-12-30 23:18:29 -0800366 /*
367 * TODO: we should probably filter ARPs too.. don't want to have
368 * them returning values that don't make sense, or is that ok?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 */
370 return 1; /* drop */
371}
372#endif /* CONFIG_ATM_BR2684_IPFILTER */
373
374static void br2684_close_vcc(struct br2684_vcc *brvcc)
375{
Stephen Hemminger52240062007-08-28 15:22:09 -0700376 pr_debug("removing VCC %p from dev %p\n", brvcc, brvcc->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 write_lock_irq(&devs_lock);
378 list_del(&brvcc->brvccs);
379 write_unlock_irq(&devs_lock);
380 brvcc->atmvcc->user_back = NULL; /* what about vcc->recvq ??? */
381 brvcc->old_push(brvcc->atmvcc, NULL); /* pass on the bad news */
382 kfree(brvcc);
383 module_put(THIS_MODULE);
384}
385
386/* when AAL5 PDU comes in: */
387static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
388{
389 struct br2684_vcc *brvcc = BR2684_VCC(atmvcc);
390 struct net_device *net_dev = brvcc->device;
391 struct br2684_dev *brdev = BRPRIV(net_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Joe Perches99824462010-01-26 11:40:00 +0000393 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 if (unlikely(skb == NULL)) {
396 /* skb==NULL means VCC is being destroyed */
397 br2684_close_vcc(brvcc);
398 if (list_empty(&brdev->brvccs)) {
Pavel Emelyanov1e0ba002008-05-04 18:00:36 -0700399 write_lock_irq(&devs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 list_del(&brdev->br2684_devs);
Pavel Emelyanov1e0ba002008-05-04 18:00:36 -0700401 write_unlock_irq(&devs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 unregister_netdev(net_dev);
David S. Miller5f6b1ea2008-05-06 00:00:16 -0700403 free_netdev(net_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405 return;
406 }
407
408 skb_debug(skb);
409 atm_return(atmvcc, skb->truesize);
Stephen Hemminger52240062007-08-28 15:22:09 -0700410 pr_debug("skb from brdev %p\n", brdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (brvcc->encaps == e_llc) {
Eric Kinzie097b19a2007-12-30 23:17:53 -0800412
413 if (skb->len > 7 && skb->data[7] == 0x01)
414 __skb_trim(skb, skb->len - 4);
415
416 /* accept packets that have "ipv[46]" in the snap header */
Joe Perches641d7292010-01-26 11:40:04 +0000417 if ((skb->len >= (sizeof(llc_oui_ipv4))) &&
418 (memcmp(skb->data, llc_oui_ipv4,
419 sizeof(llc_oui_ipv4) - BR2684_ETHERTYPE_LEN) == 0)) {
420 if (memcmp(skb->data + 6, ethertype_ipv6,
421 sizeof(ethertype_ipv6)) == 0)
Arnaldo Carvalho de Melo60678042008-09-20 22:20:49 -0700422 skb->protocol = htons(ETH_P_IPV6);
Joe Perches641d7292010-01-26 11:40:04 +0000423 else if (memcmp(skb->data + 6, ethertype_ipv4,
424 sizeof(ethertype_ipv4)) == 0)
Arnaldo Carvalho de Melo60678042008-09-20 22:20:49 -0700425 skb->protocol = htons(ETH_P_IP);
Eric Kinzie7e903c22008-06-16 17:18:18 -0700426 else
427 goto error;
Eric Kinzie097b19a2007-12-30 23:17:53 -0800428 skb_pull(skb, sizeof(llc_oui_ipv4));
429 skb_reset_network_header(skb);
430 skb->pkt_type = PACKET_HOST;
Joe Perches641d7292010-01-26 11:40:04 +0000431 /*
432 * Let us waste some time for checking the encapsulation.
433 * Note, that only 7 char is checked so frames with a valid FCS
434 * are also accepted (but FCS is not checked of course).
435 */
Eric Kinzie097b19a2007-12-30 23:17:53 -0800436 } else if ((skb->len >= sizeof(llc_oui_pid_pad)) &&
Chas Williamsfb64c732007-12-30 23:18:29 -0800437 (memcmp(skb->data, llc_oui_pid_pad, 7) == 0)) {
Eric Kinzie097b19a2007-12-30 23:17:53 -0800438 skb_pull(skb, sizeof(llc_oui_pid_pad));
439 skb->protocol = eth_type_trans(skb, net_dev);
Eric Kinzie7e903c22008-06-16 17:18:18 -0700440 } else
441 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Eric Kinzie7e903c22008-06-16 17:18:18 -0700443 } else { /* e_vc */
444 if (brdev->payload == p_routed) {
445 struct iphdr *iph;
446
447 skb_reset_network_header(skb);
448 iph = ip_hdr(skb);
449 if (iph->version == 4)
Arnaldo Carvalho de Melo60678042008-09-20 22:20:49 -0700450 skb->protocol = htons(ETH_P_IP);
Eric Kinzie7e903c22008-06-16 17:18:18 -0700451 else if (iph->version == 6)
Arnaldo Carvalho de Melo60678042008-09-20 22:20:49 -0700452 skb->protocol = htons(ETH_P_IPV6);
Eric Kinzie7e903c22008-06-16 17:18:18 -0700453 else
454 goto error;
455 skb->pkt_type = PACKET_HOST;
456 } else { /* p_bridged */
457 /* first 2 chars should be 0 */
Pascal Hambourgbefc93f2011-08-17 08:37:52 +0200458 if (memcmp(skb->data, pad, BR2684_PAD_LEN) != 0)
Eric Kinzie7e903c22008-06-16 17:18:18 -0700459 goto error;
460 skb_pull(skb, BR2684_PAD_LEN);
461 skb->protocol = eth_type_trans(skb, net_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#ifdef CONFIG_ATM_BR2684_IPFILTER
Eric Kinzie7e903c22008-06-16 17:18:18 -0700466 if (unlikely(packet_fails_filter(skb->protocol, brvcc, skb)))
467 goto dropped;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#endif /* CONFIG_ATM_BR2684_IPFILTER */
469 skb->dev = net_dev;
470 ATM_SKB(skb)->vcc = atmvcc; /* needed ? */
Stephen Hemminger52240062007-08-28 15:22:09 -0700471 pr_debug("received packet's protocol: %x\n", ntohs(skb->protocol));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 skb_debug(skb);
Eric Kinzie7e903c22008-06-16 17:18:18 -0700473 /* sigh, interface is down? */
474 if (unlikely(!(net_dev->flags & IFF_UP)))
475 goto dropped;
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000476 net_dev->stats.rx_packets++;
477 net_dev->stats.rx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
479 netif_rx(skb);
Eric Kinzie7e903c22008-06-16 17:18:18 -0700480 return;
481
482dropped:
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000483 net_dev->stats.rx_dropped++;
Eric Kinzie7e903c22008-06-16 17:18:18 -0700484 goto free_skb;
485error:
Stephen Hemminger410e9d82009-01-09 13:00:58 +0000486 net_dev->stats.rx_errors++;
Eric Kinzie7e903c22008-06-16 17:18:18 -0700487free_skb:
488 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
Chas Williamsfb64c732007-12-30 23:18:29 -0800491/*
492 * Assign a vcc to a dev
493 * Note: we do not have explicit unassign, but look at _push()
494 */
495static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 struct br2684_vcc *brvcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 struct br2684_dev *brdev;
499 struct net_device *net_dev;
500 struct atm_backend_br2684 be;
Jorge Boncompte [DTI2]4e55f572011-11-21 10:25:57 +0000501 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 if (copy_from_user(&be, arg, sizeof be))
504 return -EFAULT;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700505 brvcc = kzalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (!brvcc)
507 return -ENOMEM;
David Woodhouseae088d62012-11-25 12:06:52 +0000508 /*
509 * Allow two packets in the ATM queue. One actually being sent, and one
510 * for the ATM 'TX done' handler to send. It shouldn't take long to get
511 * the next one from the netdev queue, when we need it. More than that
512 * would be bufferbloat.
513 */
514 atomic_set(&brvcc->qspace, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 write_lock_irq(&devs_lock);
516 net_dev = br2684_find_dev(&be.ifspec);
517 if (net_dev == NULL) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300518 pr_err("tried to attach to non-existent device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 err = -ENXIO;
520 goto error;
521 }
522 brdev = BRPRIV(net_dev);
523 if (atmvcc->push == NULL) {
524 err = -EBADFD;
525 goto error;
526 }
527 if (!list_empty(&brdev->brvccs)) {
528 /* Only 1 VCC/dev right now */
529 err = -EEXIST;
530 goto error;
531 }
Joe Perches641d7292010-01-26 11:40:04 +0000532 if (be.fcs_in != BR2684_FCSIN_NO ||
533 be.fcs_out != BR2684_FCSOUT_NO ||
534 be.fcs_auto || be.has_vpiid || be.send_padding ||
535 (be.encaps != BR2684_ENCAPS_VC &&
536 be.encaps != BR2684_ENCAPS_LLC) ||
537 be.min_size != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 err = -EINVAL;
539 goto error;
540 }
Joe Perches99824462010-01-26 11:40:00 +0000541 pr_debug("vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, be.encaps, brvcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) {
543 unsigned char *esi = atmvcc->dev->esi;
544 if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5])
545 memcpy(net_dev->dev_addr, esi, net_dev->addr_len);
546 else
547 net_dev->dev_addr[2] = 1;
548 }
549 list_add(&brvcc->brvccs, &brdev->brvccs);
550 write_unlock_irq(&devs_lock);
551 brvcc->device = net_dev;
552 brvcc->atmvcc = atmvcc;
553 atmvcc->user_back = brvcc;
Chas Williamsfb64c732007-12-30 23:18:29 -0800554 brvcc->encaps = (enum br2684_encaps)be.encaps;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 brvcc->old_push = atmvcc->push;
Karl Hiramoto137742c2009-09-02 23:26:39 -0700556 brvcc->old_pop = atmvcc->pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 barrier();
558 atmvcc->push = br2684_push;
Karl Hiramoto137742c2009-09-02 23:26:39 -0700559 atmvcc->pop = br2684_pop;
David S. Millerc40a27f2006-11-30 21:05:23 -0800560
Karl Hiramoto00506612010-07-08 20:55:31 +0000561 /* initialize netdev carrier state */
562 if (atmvcc->dev->signal == ATM_PHY_SIG_LOST)
563 netif_carrier_off(net_dev);
564 else
565 netif_carrier_on(net_dev);
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 __module_get(THIS_MODULE);
Jorge Boncompte [DTI2]4e55f572011-11-21 10:25:57 +0000568
569 /* re-process everything received between connection setup and
570 backend setup */
571 vcc_process_recv_queue(atmvcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return 0;
Joe Perches641d7292010-01-26 11:40:04 +0000573
574error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 write_unlock_irq(&devs_lock);
576 kfree(brvcc);
577 return err;
578}
579
Stephen Hemminger0ba25ff2009-01-09 13:00:59 +0000580static const struct net_device_ops br2684_netdev_ops = {
581 .ndo_start_xmit = br2684_start_xmit,
582 .ndo_set_mac_address = br2684_mac_addr,
583 .ndo_change_mtu = eth_change_mtu,
584 .ndo_validate_addr = eth_validate_addr,
585};
586
chas williams - CONTRACTOR2e302eb2009-12-04 11:06:32 +0000587static const struct net_device_ops br2684_netdev_ops_routed = {
588 .ndo_start_xmit = br2684_start_xmit,
589 .ndo_set_mac_address = br2684_mac_addr,
590 .ndo_change_mtu = eth_change_mtu
591};
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593static void br2684_setup(struct net_device *netdev)
594{
595 struct br2684_dev *brdev = BRPRIV(netdev);
596
597 ether_setup(netdev);
Pascal Hambourg9e667b22011-08-17 08:37:18 +0200598 netdev->hard_header_len += sizeof(llc_oui_pid_pad); /* worst case */
Rabin Vincent902e5ea2009-05-02 13:49:36 -0700599 brdev->net_dev = netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Stephen Hemminger0ba25ff2009-01-09 13:00:59 +0000601 netdev->netdev_ops = &br2684_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 INIT_LIST_HEAD(&brdev->brvccs);
604}
605
Eric Kinzie097b19a2007-12-30 23:17:53 -0800606static void br2684_setup_routed(struct net_device *netdev)
607{
608 struct br2684_dev *brdev = BRPRIV(netdev);
chas williams - CONTRACTOR2e302eb2009-12-04 11:06:32 +0000609
Eric Kinzie097b19a2007-12-30 23:17:53 -0800610 brdev->net_dev = netdev;
Pascal Hambourg9e667b22011-08-17 08:37:18 +0200611 netdev->hard_header_len = sizeof(llc_oui_ipv4); /* worst case */
chas williams - CONTRACTOR2e302eb2009-12-04 11:06:32 +0000612 netdev->netdev_ops = &br2684_netdev_ops_routed;
Eric Kinzie097b19a2007-12-30 23:17:53 -0800613 netdev->addr_len = 0;
614 netdev->mtu = 1500;
615 netdev->type = ARPHRD_PPP;
616 netdev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
617 netdev->tx_queue_len = 100;
618 INIT_LIST_HEAD(&brdev->brvccs);
619}
620
Joe Perches641d7292010-01-26 11:40:04 +0000621static int br2684_create(void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
623 int err;
624 struct net_device *netdev;
625 struct br2684_dev *brdev;
626 struct atm_newif_br2684 ni;
Eric Kinzie097b19a2007-12-30 23:17:53 -0800627 enum br2684_payload payload;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Joe Perches99824462010-01-26 11:40:00 +0000629 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Joe Perches641d7292010-01-26 11:40:04 +0000631 if (copy_from_user(&ni, arg, sizeof ni))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return -EFAULT;
Eric Kinzie097b19a2007-12-30 23:17:53 -0800633
634 if (ni.media & BR2684_FLAG_ROUTED)
635 payload = p_routed;
636 else
637 payload = p_bridged;
Chas Williamsfb64c732007-12-30 23:18:29 -0800638 ni.media &= 0xffff; /* strip flags */
Eric Kinzie097b19a2007-12-30 23:17:53 -0800639
Joe Perches641d7292010-01-26 11:40:04 +0000640 if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643 netdev = alloc_netdev(sizeof(struct br2684_dev),
644 ni.ifname[0] ? ni.ifname : "nas%d",
Eric Kinzie097b19a2007-12-30 23:17:53 -0800645 (payload == p_routed) ?
Chas Williamsfb64c732007-12-30 23:18:29 -0800646 br2684_setup_routed : br2684_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (!netdev)
648 return -ENOMEM;
649
650 brdev = BRPRIV(netdev);
651
Stephen Hemminger52240062007-08-28 15:22:09 -0700652 pr_debug("registered netdev %s\n", netdev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* open, stop, do_ioctl ? */
654 err = register_netdev(netdev);
655 if (err < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000656 pr_err("register_netdev failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 free_netdev(netdev);
658 return err;
659 }
660
661 write_lock_irq(&devs_lock);
Karl Hiramoto00506612010-07-08 20:55:31 +0000662
Eric Kinzie097b19a2007-12-30 23:17:53 -0800663 brdev->payload = payload;
Karl Hiramoto00506612010-07-08 20:55:31 +0000664
665 if (list_empty(&br2684_devs)) {
666 /* 1st br2684 device */
Karl Hiramoto00506612010-07-08 20:55:31 +0000667 brdev->number = 1;
668 } else
669 brdev->number = BRPRIV(list_entry_brdev(br2684_devs.prev))->number + 1;
670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 list_add_tail(&brdev->br2684_devs, &br2684_devs);
672 write_unlock_irq(&devs_lock);
673 return 0;
674}
675
676/*
677 * This handles ioctls actually performed on our vcc - we must return
678 * -ENOIOCTLCMD for any unrecognized ioctl
679 */
680static int br2684_ioctl(struct socket *sock, unsigned int cmd,
Chas Williamsfb64c732007-12-30 23:18:29 -0800681 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
683 struct atm_vcc *atmvcc = ATM_SD(sock);
684 void __user *argp = (void __user *)arg;
Chas Williamsfb64c732007-12-30 23:18:29 -0800685 atm_backend_t b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 int err;
Chas Williamsfb64c732007-12-30 23:18:29 -0800688 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 case ATM_SETBACKEND:
Chas Williamsfb64c732007-12-30 23:18:29 -0800690 case ATM_NEWBACKENDIF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 err = get_user(b, (atm_backend_t __user *) argp);
692 if (err)
693 return -EFAULT;
694 if (b != ATM_BACKEND_BR2684)
695 return -ENOIOCTLCMD;
696 if (!capable(CAP_NET_ADMIN))
697 return -EPERM;
698 if (cmd == ATM_SETBACKEND)
699 return br2684_regvcc(atmvcc, argp);
700 else
701 return br2684_create(argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702#ifdef CONFIG_ATM_BR2684_IPFILTER
703 case BR2684_SETFILT:
704 if (atmvcc->push != br2684_push)
705 return -ENOIOCTLCMD;
706 if (!capable(CAP_NET_ADMIN))
707 return -EPERM;
708 err = br2684_setfilt(atmvcc, argp);
Chas Williamsfb64c732007-12-30 23:18:29 -0800709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return err;
711#endif /* CONFIG_ATM_BR2684_IPFILTER */
712 }
713 return -ENOIOCTLCMD;
714}
715
716static struct atm_ioctl br2684_ioctl_ops = {
Chas Williamsfb64c732007-12-30 23:18:29 -0800717 .owner = THIS_MODULE,
718 .ioctl = br2684_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719};
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#ifdef CONFIG_PROC_FS
Chas Williamsfb64c732007-12-30 23:18:29 -0800722static void *br2684_seq_start(struct seq_file *seq, loff_t * pos)
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800723 __acquires(devs_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 read_lock(&devs_lock);
Pavel Emelianov9af97182007-07-09 13:12:24 -0700726 return seq_list_start(&br2684_devs, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Chas Williamsfb64c732007-12-30 23:18:29 -0800729static void *br2684_seq_next(struct seq_file *seq, void *v, loff_t * pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Pavel Emelianov9af97182007-07-09 13:12:24 -0700731 return seq_list_next(v, &br2684_devs, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732}
733
734static void br2684_seq_stop(struct seq_file *seq, void *v)
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800735 __releases(devs_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
737 read_unlock(&devs_lock);
738}
739
740static int br2684_seq_show(struct seq_file *seq, void *v)
741{
Pavel Emelianov9af97182007-07-09 13:12:24 -0700742 const struct br2684_dev *brdev = list_entry(v, struct br2684_dev,
Chas Williamsfb64c732007-12-30 23:18:29 -0800743 br2684_devs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 const struct net_device *net_dev = brdev->net_dev;
745 const struct br2684_vcc *brvcc;
746
Johannes Berge1749612008-10-27 15:59:26 -0700747 seq_printf(seq, "dev %.16s: num=%d, mac=%pM (%s)\n",
Joe Perches0795af52007-10-03 17:59:30 -0700748 net_dev->name,
749 brdev->number,
Johannes Berge1749612008-10-27 15:59:26 -0700750 net_dev->dev_addr,
Joe Perches0795af52007-10-03 17:59:30 -0700751 brdev->mac_was_set ? "set" : "auto");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 list_for_each_entry(brvcc, &brdev->brvccs, brvccs) {
Eric Kinzie097b19a2007-12-30 23:17:53 -0800754 seq_printf(seq, " vcc %d.%d.%d: encaps=%s payload=%s"
Chas Williamsfb64c732007-12-30 23:18:29 -0800755 ", failed copies %u/%u"
756 "\n", brvcc->atmvcc->dev->number,
757 brvcc->atmvcc->vpi, brvcc->atmvcc->vci,
758 (brvcc->encaps == e_llc) ? "LLC" : "VC",
759 (brdev->payload == p_bridged) ? "bridged" : "routed",
760 brvcc->copies_failed, brvcc->copies_needed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761#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)
Chas Williamsfb64c732007-12-30 23:18:29 -0800764 if (brvcc->filter.netmask != 0)
765 seq_printf(seq, " filter=%d.%d.%d.%d/"
766 "%d.%d.%d.%d\n", bs(prefix), bs(netmask));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767#undef bs
768#undef b1
769#endif /* CONFIG_ATM_BR2684_IPFILTER */
770 }
771 return 0;
772}
773
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700774static const struct seq_operations br2684_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .start = br2684_seq_start,
Chas Williamsfb64c732007-12-30 23:18:29 -0800776 .next = br2684_seq_next,
777 .stop = br2684_seq_stop,
778 .show = br2684_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779};
780
781static int br2684_proc_open(struct inode *inode, struct file *file)
782{
783 return seq_open(file, &br2684_seq_ops);
784}
785
Arjan van de Ven9a321442007-02-12 00:55:35 -0800786static const struct file_operations br2684_proc_ops = {
Chas Williamsfb64c732007-12-30 23:18:29 -0800787 .owner = THIS_MODULE,
788 .open = br2684_proc_open,
789 .read = seq_read,
790 .llseek = seq_lseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .release = seq_release,
792};
793
794extern struct proc_dir_entry *atm_proc_root; /* from proc.c */
Chas Williamsfb64c732007-12-30 23:18:29 -0800795#endif /* CONFIG_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797static int __init br2684_init(void)
798{
799#ifdef CONFIG_PROC_FS
800 struct proc_dir_entry *p;
Wang Chen16e297b2008-02-28 13:55:45 -0800801 p = proc_create("br2684", 0, atm_proc_root, &br2684_proc_ops);
802 if (p == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804#endif
805 register_atm_ioctl(&br2684_ioctl_ops);
Karl Hiramotoa3d67132010-09-23 01:50:54 +0000806 register_atmdevice_notifier(&atm_dev_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 return 0;
808}
809
810static void __exit br2684_exit(void)
811{
812 struct net_device *net_dev;
813 struct br2684_dev *brdev;
814 struct br2684_vcc *brvcc;
815 deregister_atm_ioctl(&br2684_ioctl_ops);
816
817#ifdef CONFIG_PROC_FS
818 remove_proc_entry("br2684", atm_proc_root);
819#endif
820
Karl Hiramoto00506612010-07-08 20:55:31 +0000821
Karl Hiramotoa3d67132010-09-23 01:50:54 +0000822 unregister_atmdevice_notifier(&atm_dev_notifier);
Karl Hiramoto00506612010-07-08 20:55:31 +0000823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 while (!list_empty(&br2684_devs)) {
825 net_dev = list_entry_brdev(br2684_devs.next);
826 brdev = BRPRIV(net_dev);
827 while (!list_empty(&brdev->brvccs)) {
828 brvcc = list_entry_brvcc(brdev->brvccs.next);
829 br2684_close_vcc(brvcc);
830 }
831
832 list_del(&brdev->br2684_devs);
833 unregister_netdev(net_dev);
David S. Miller5f6b1ea2008-05-06 00:00:16 -0700834 free_netdev(net_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836}
837
838module_init(br2684_init);
839module_exit(br2684_exit);
840
841MODULE_AUTHOR("Marcell GAL");
842MODULE_DESCRIPTION("RFC2684 bridged protocols over ATM/AAL5");
843MODULE_LICENSE("GPL");