blob: 81b22a180aad379562d62b9376e2010905591518 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * DLCI Implementation of Frame Relay protocol for Linux, according to
3 * RFC 1490. This generic device provides en/decapsulation for an
4 * underlying hardware driver. Routes & IPs are assigned to these
5 * interfaces. Requires 'dlcicfg' program to create usable
6 * interfaces, the initial one, 'dlci' is for IOCTL use only.
7 *
8 * Version: @(#)dlci.c 0.35 4 Jan 1997
9 *
10 * Author: Mike McLagan <mike.mclagan@linux.org>
11 *
12 * Changes:
13 *
14 * 0.15 Mike Mclagan Packet freeing, bug in kmalloc call
15 * DLCI_RET handling
16 * 0.20 Mike McLagan More conservative on which packets
17 * are returned for retry and which are
18 * are dropped. If DLCI_RET_DROP is
19 * returned from the FRAD, the packet is
20 * sent back to Linux for re-transmission
21 * 0.25 Mike McLagan Converted to use SIOC IOCTL calls
22 * 0.30 Jim Freeman Fixed to allow IPX traffic
23 * 0.35 Michael Elizabeth Fixed incorrect memcpy_fromfs
24 *
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version
28 * 2 of the License, or (at your option) any later version.
29 */
30
Joe Perches86fb0cc2011-06-26 19:01:31 +000031#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/types.h>
36#include <linux/fcntl.h>
37#include <linux/interrupt.h>
38#include <linux/ptrace.h>
39#include <linux/ioport.h>
40#include <linux/in.h>
41#include <linux/init.h>
42#include <linux/slab.h>
43#include <linux/string.h>
44#include <linux/errno.h>
45#include <linux/netdevice.h>
46#include <linux/skbuff.h>
47#include <linux/if_arp.h>
48#include <linux/if_frad.h>
49#include <linux/bitops.h>
50
51#include <net/sock.h>
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/io.h>
54#include <asm/dma.h>
55#include <asm/uaccess.h>
56
57static const char version[] = "DLCI driver v0.35, 4 Jan 1997, mike.mclagan@linux.org";
58
59static LIST_HEAD(dlci_devs);
60
61static void dlci_setup(struct net_device *);
62
63/*
64 * these encapsulate the RFC 1490 requirements as well as
65 * deal with packet transmission and reception, working with
66 * the upper network layers
67 */
68
69static int dlci_header(struct sk_buff *skb, struct net_device *dev,
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -070070 unsigned short type, const void *daddr,
71 const void *saddr, unsigned len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 struct frhdr hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 unsigned int hlen;
75 char *dest;
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 hdr.control = FRAD_I_UI;
Rudy Matela48b3d3e2009-11-29 23:42:14 -080078 switch (type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 {
80 case ETH_P_IP:
81 hdr.IP_NLPID = FRAD_P_IP;
82 hlen = sizeof(hdr.control) + sizeof(hdr.IP_NLPID);
83 break;
84
85 /* feel free to add other types, if necessary */
86
87 default:
88 hdr.pad = FRAD_P_PADDING;
89 hdr.NLPID = FRAD_P_SNAP;
90 memset(hdr.OUI, 0, sizeof(hdr.OUI));
91 hdr.PID = htons(type);
92 hlen = sizeof(hdr);
93 break;
94 }
95
96 dest = skb_push(skb, hlen);
97 if (!dest)
Eric Dumazet807540b2010-09-23 05:40:09 +000098 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 memcpy(dest, &hdr, hlen);
101
Eric Dumazet807540b2010-09-23 05:40:09 +0000102 return hlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
105static void dlci_receive(struct sk_buff *skb, struct net_device *dev)
106{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 struct frhdr *hdr;
108 int process, header;
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 if (!pskb_may_pull(skb, sizeof(*hdr))) {
Joe Perches86fb0cc2011-06-26 19:01:31 +0000111 netdev_notice(dev, "invalid data no header\n");
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000112 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 kfree_skb(skb);
114 return;
115 }
116
117 hdr = (struct frhdr *) skb->data;
118 process = 0;
119 header = 0;
120 skb->dev = dev;
121
122 if (hdr->control != FRAD_I_UI)
123 {
Joe Perches86fb0cc2011-06-26 19:01:31 +0000124 netdev_notice(dev, "Invalid header flag 0x%02X\n",
125 hdr->control);
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000126 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128 else
Rudy Matela48b3d3e2009-11-29 23:42:14 -0800129 switch (hdr->IP_NLPID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 {
131 case FRAD_P_PADDING:
132 if (hdr->NLPID != FRAD_P_SNAP)
133 {
Joe Perches86fb0cc2011-06-26 19:01:31 +0000134 netdev_notice(dev, "Unsupported NLPID 0x%02X\n",
135 hdr->NLPID);
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000136 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 break;
138 }
139
140 if (hdr->OUI[0] + hdr->OUI[1] + hdr->OUI[2] != 0)
141 {
Joe Perches86fb0cc2011-06-26 19:01:31 +0000142 netdev_notice(dev, "Unsupported organizationally unique identifier 0x%02X-%02X-%02X\n",
143 hdr->OUI[0],
144 hdr->OUI[1],
145 hdr->OUI[2]);
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000146 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 break;
148 }
149
150 /* at this point, it's an EtherType frame */
151 header = sizeof(struct frhdr);
152 /* Already in network order ! */
153 skb->protocol = hdr->PID;
154 process = 1;
155 break;
156
157 case FRAD_P_IP:
158 header = sizeof(hdr->control) + sizeof(hdr->IP_NLPID);
159 skb->protocol = htons(ETH_P_IP);
160 process = 1;
161 break;
162
163 case FRAD_P_SNAP:
164 case FRAD_P_Q933:
165 case FRAD_P_CLNP:
Joe Perches86fb0cc2011-06-26 19:01:31 +0000166 netdev_notice(dev, "Unsupported NLPID 0x%02X\n",
167 hdr->pad);
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000168 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 break;
170
171 default:
Joe Perches86fb0cc2011-06-26 19:01:31 +0000172 netdev_notice(dev, "Invalid pad byte 0x%02X\n",
173 hdr->pad);
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000174 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 break;
176 }
177
178 if (process)
179 {
180 /* we've set up the protocol, so discard the header */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700181 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 skb_pull(skb, header);
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000183 dev->stats.rx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 netif_rx(skb);
Stephen Hemminger07d117c2009-03-20 19:36:14 +0000185 dev->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187 else
188 dev_kfree_skb(skb);
189}
190
Stephen Hemminger38482422009-09-04 05:33:46 +0000191static netdev_tx_t dlci_transmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Stephen Hemminger38482422009-09-04 05:33:46 +0000193 struct dlci_local *dlp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Stephen Hemminger38482422009-09-04 05:33:46 +0000195 if (skb)
David S. Miller47982482014-08-22 16:21:53 -0700196 netdev_start_xmit(skb, dlp->slave);
Stephen Hemminger38482422009-09-04 05:33:46 +0000197 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
200static int dlci_config(struct net_device *dev, struct dlci_conf __user *conf, int get)
201{
202 struct dlci_conf config;
203 struct dlci_local *dlp;
204 struct frad_local *flp;
205 int err;
206
Wang Chen8f15ea42008-11-12 23:38:36 -0800207 dlp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Wang Chen8f15ea42008-11-12 23:38:36 -0800209 flp = netdev_priv(dlp->slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 if (!get)
212 {
Rudy Matela48b3d3e2009-11-29 23:42:14 -0800213 if (copy_from_user(&config, conf, sizeof(struct dlci_conf)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return -EFAULT;
215 if (config.flags & ~DLCI_VALID_FLAGS)
Eric Dumazet807540b2010-09-23 05:40:09 +0000216 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 memcpy(&dlp->config, &config, sizeof(struct dlci_conf));
218 dlp->configured = 1;
219 }
220
221 err = (*flp->dlci_conf)(dlp->slave, dev, get);
222 if (err)
Eric Dumazet807540b2010-09-23 05:40:09 +0000223 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 if (get)
226 {
Rudy Matela48b3d3e2009-11-29 23:42:14 -0800227 if (copy_to_user(conf, &dlp->config, sizeof(struct dlci_conf)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return -EFAULT;
229 }
230
Eric Dumazet807540b2010-09-23 05:40:09 +0000231 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
234static int dlci_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
235{
236 struct dlci_local *dlp;
237
238 if (!capable(CAP_NET_ADMIN))
Eric Dumazet807540b2010-09-23 05:40:09 +0000239 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Wang Chen8f15ea42008-11-12 23:38:36 -0800241 dlp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Rudy Matela48b3d3e2009-11-29 23:42:14 -0800243 switch (cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 {
245 case DLCI_GET_SLAVE:
246 if (!*(short *)(dev->dev_addr))
Eric Dumazet807540b2010-09-23 05:40:09 +0000247 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 strncpy(ifr->ifr_slave, dlp->slave->name, sizeof(ifr->ifr_slave));
250 break;
251
252 case DLCI_GET_CONF:
253 case DLCI_SET_CONF:
254 if (!*(short *)(dev->dev_addr))
Eric Dumazet807540b2010-09-23 05:40:09 +0000255 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Eric Dumazet807540b2010-09-23 05:40:09 +0000257 return dlci_config(dev, ifr->ifr_data, cmd == DLCI_GET_CONF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 default:
Eric Dumazet807540b2010-09-23 05:40:09 +0000260 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
Eric Dumazet807540b2010-09-23 05:40:09 +0000262 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
265static int dlci_change_mtu(struct net_device *dev, int new_mtu)
266{
Stephen Hemminger49e8aba2009-03-20 19:36:15 +0000267 struct dlci_local *dlp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Stephen Hemminger49e8aba2009-03-20 19:36:15 +0000269 return dev_set_mtu(dlp->slave, new_mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
272static int dlci_open(struct net_device *dev)
273{
274 struct dlci_local *dlp;
275 struct frad_local *flp;
276 int err;
277
Wang Chen8f15ea42008-11-12 23:38:36 -0800278 dlp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 if (!*(short *)(dev->dev_addr))
Eric Dumazet807540b2010-09-23 05:40:09 +0000281 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 if (!netif_running(dlp->slave))
Eric Dumazet807540b2010-09-23 05:40:09 +0000284 return -ENOTCONN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Wang Chen8f15ea42008-11-12 23:38:36 -0800286 flp = netdev_priv(dlp->slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 err = (*flp->activate)(dlp->slave, dev);
288 if (err)
Eric Dumazet807540b2010-09-23 05:40:09 +0000289 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 netif_start_queue(dev);
292
293 return 0;
294}
295
296static int dlci_close(struct net_device *dev)
297{
298 struct dlci_local *dlp;
299 struct frad_local *flp;
300 int err;
301
302 netif_stop_queue(dev);
303
Wang Chen8f15ea42008-11-12 23:38:36 -0800304 dlp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Wang Chen8f15ea42008-11-12 23:38:36 -0800306 flp = netdev_priv(dlp->slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 err = (*flp->deactivate)(dlp->slave, dev);
308
309 return 0;
310}
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312static int dlci_add(struct dlci_add *dlci)
313{
314 struct net_device *master, *slave;
315 struct dlci_local *dlp;
316 struct frad_local *flp;
317 int err = -EINVAL;
318
319
320 /* validate slave device */
Eric W. Biederman881d9662007-09-17 11:56:21 -0700321 slave = dev_get_by_name(&init_net, dlci->devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (!slave)
323 return -ENODEV;
324
Wang Chen8f15ea42008-11-12 23:38:36 -0800325 if (slave->type != ARPHRD_FRAD || netdev_priv(slave) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 goto err1;
327
328 /* create device name */
Tom Gundersenc835a672014-07-14 16:37:24 +0200329 master = alloc_netdev(sizeof(struct dlci_local), "dlci%d",
330 NET_NAME_UNKNOWN, dlci_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (!master) {
332 err = -ENOMEM;
333 goto err1;
334 }
335
336 /* make sure same slave not already registered */
337 rtnl_lock();
338 list_for_each_entry(dlp, &dlci_devs, list) {
339 if (dlp->slave == slave) {
340 err = -EBUSY;
341 goto err2;
342 }
343 }
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 *(short *)(master->dev_addr) = dlci->dlci;
346
Wang Chen8f15ea42008-11-12 23:38:36 -0800347 dlp = netdev_priv(master);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 dlp->slave = slave;
349 dlp->master = master;
350
Wang Chen8f15ea42008-11-12 23:38:36 -0800351 flp = netdev_priv(slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 err = (*flp->assoc)(slave, master);
353 if (err < 0)
354 goto err2;
355
356 err = register_netdevice(master);
357 if (err < 0)
358 goto err2;
359
360 strcpy(dlci->devname, master->name);
361
362 list_add(&dlp->list, &dlci_devs);
363 rtnl_unlock();
364
Eric Dumazet807540b2010-09-23 05:40:09 +0000365 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 err2:
368 rtnl_unlock();
369 free_netdev(master);
370 err1:
371 dev_put(slave);
Eric Dumazet807540b2010-09-23 05:40:09 +0000372 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
375static int dlci_del(struct dlci_add *dlci)
376{
377 struct dlci_local *dlp;
378 struct frad_local *flp;
379 struct net_device *master, *slave;
380 int err;
Zefan Li578a1312013-06-26 15:31:58 +0800381 bool found = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Zefan Li11eb2642013-06-26 15:29:54 +0800383 rtnl_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 /* validate slave device */
Eric W. Biederman881d9662007-09-17 11:56:21 -0700386 master = __dev_get_by_name(&init_net, dlci->devname);
Zefan Li11eb2642013-06-26 15:29:54 +0800387 if (!master) {
388 err = -ENODEV;
389 goto out;
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Zefan Li578a1312013-06-26 15:31:58 +0800392 list_for_each_entry(dlp, &dlci_devs, list) {
393 if (dlp->master == master) {
394 found = true;
395 break;
396 }
397 }
398 if (!found) {
399 err = -ENODEV;
400 goto out;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 if (netif_running(master)) {
Zefan Li11eb2642013-06-26 15:29:54 +0800404 err = -EBUSY;
405 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
Wang Chen8f15ea42008-11-12 23:38:36 -0800408 dlp = netdev_priv(master);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 slave = dlp->slave;
Wang Chen8f15ea42008-11-12 23:38:36 -0800410 flp = netdev_priv(slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 err = (*flp->deassoc)(slave, master);
413 if (!err) {
414 list_del(&dlp->list);
415
416 unregister_netdevice(master);
417
418 dev_put(slave);
419 }
Zefan Li11eb2642013-06-26 15:29:54 +0800420out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 rtnl_unlock();
Eric Dumazet807540b2010-09-23 05:40:09 +0000422 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
425static int dlci_ioctl(unsigned int cmd, void __user *arg)
426{
427 struct dlci_add add;
428 int err;
429
430 if (!capable(CAP_NET_ADMIN))
Eric Dumazet807540b2010-09-23 05:40:09 +0000431 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Rudy Matela48b3d3e2009-11-29 23:42:14 -0800433 if (copy_from_user(&add, arg, sizeof(struct dlci_add)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return -EFAULT;
435
436 switch (cmd)
437 {
438 case SIOCADDDLCI:
439 err = dlci_add(&add);
440
441 if (!err)
Rudy Matela48b3d3e2009-11-29 23:42:14 -0800442 if (copy_to_user(arg, &add, sizeof(struct dlci_add)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return -EFAULT;
444 break;
445
446 case SIOCDELDLCI:
447 err = dlci_del(&add);
448 break;
449
450 default:
451 err = -EINVAL;
452 }
453
Eric Dumazet807540b2010-09-23 05:40:09 +0000454 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700457static const struct header_ops dlci_header_ops = {
458 .create = dlci_header,
459};
460
Stephen Hemminger49e8aba2009-03-20 19:36:15 +0000461static const struct net_device_ops dlci_netdev_ops = {
462 .ndo_open = dlci_open,
463 .ndo_stop = dlci_close,
464 .ndo_do_ioctl = dlci_dev_ioctl,
465 .ndo_start_xmit = dlci_transmit,
466 .ndo_change_mtu = dlci_change_mtu,
467};
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469static void dlci_setup(struct net_device *dev)
470{
Wang Chen8f15ea42008-11-12 23:38:36 -0800471 struct dlci_local *dlp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473 dev->flags = 0;
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700474 dev->header_ops = &dlci_header_ops;
Stephen Hemminger49e8aba2009-03-20 19:36:15 +0000475 dev->netdev_ops = &dlci_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 dev->destructor = free_netdev;
477
478 dlp->receive = dlci_receive;
479
480 dev->type = ARPHRD_DLCI;
481 dev->hard_header_len = sizeof(struct frhdr);
482 dev->addr_len = sizeof(short);
483
484}
485
486/* if slave is unregistering, then cleanup master */
487static int dlci_dev_event(struct notifier_block *unused,
488 unsigned long event, void *ptr)
489{
Jiri Pirko351638e2013-05-28 01:30:21 +0000490 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +0900492 if (dev_net(dev) != &init_net)
Eric W. Biedermane9dc8652007-09-12 13:02:17 +0200493 return NOTIFY_DONE;
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (event == NETDEV_UNREGISTER) {
496 struct dlci_local *dlp;
497
498 list_for_each_entry(dlp, &dlci_devs, list) {
499 if (dlp->slave == dev) {
500 list_del(&dlp->list);
501 unregister_netdevice(dlp->master);
502 dev_put(dlp->slave);
503 break;
504 }
505 }
506 }
507 return NOTIFY_DONE;
508}
509
510static struct notifier_block dlci_notifier = {
511 .notifier_call = dlci_dev_event,
512};
513
514static int __init init_dlci(void)
515{
516 dlci_ioctl_set(dlci_ioctl);
517 register_netdevice_notifier(&dlci_notifier);
518
519 printk("%s.\n", version);
520
521 return 0;
522}
523
524static void __exit dlci_exit(void)
525{
526 struct dlci_local *dlp, *nxt;
527
528 dlci_ioctl_set(NULL);
529 unregister_netdevice_notifier(&dlci_notifier);
530
531 rtnl_lock();
532 list_for_each_entry_safe(dlp, nxt, &dlci_devs, list) {
533 unregister_netdevice(dlp->master);
534 dev_put(dlp->slave);
535 }
536 rtnl_unlock();
537}
538
539module_init(init_dlci);
540module_exit(dlci_exit);
541
542MODULE_AUTHOR("Mike McLagan");
543MODULE_DESCRIPTION("Frame Relay DLCI layer");
544MODULE_LICENSE("GPL");