3 * $Id: unet.c,v 1.1 2001/01/25 22:03:39 mdw Exp $
5 * User-space network device support.
7 * (c) 1998 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Usernet.
14 * Usernet is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Usernet is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Usernet; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 2001/01/25 22:03:39 mdw
33 * Initial check-in (somewhat belated).
37 /*----- Include files -----------------------------------------------------*/
39 #include <linux/module.h>
41 #include <asm/byteorder.h>
42 #include <asm/segment.h>
44 #include <linux/types.h>
45 #include <linux/kernel.h>
46 #include <linux/wait.h>
47 #include <linux/sched.h>
49 #include <linux/poll.h>
50 #include <linux/netdevice.h>
51 #include <linux/etherdevice.h>
52 #include <linux/if_arp.h>
53 #include <linux/malloc.h>
54 #include <linux/errno.h>
55 #include <linux/init.h>
60 MODULE_AUTHOR("Mark Wooding");
61 MODULE_DESCRIPTION("Allows userland handling of a network interface");
63 /*----- Debugging macros --------------------------------------------------*/
65 #define UNET_DEBUGALWAYS 1
66 #define UNET_DEBUGRUNTIME 0
67 #define UNET_DEBUGNEVER -1
69 /* --- If the macro isn't defined then be switchable at runtime --- */
72 # define UNET_DEBUG UNET_DEBUGRUNTIME
75 /* --- Define the base macro @D@ according to the debug setting --- */
77 #if UNET_DEBUG == UNET_DEBUGALWAYS
79 # define DIF(u, x) if ((u)->f & UNIF_DEBUG) { x }
80 #elif UNET_DEBUG == UNET_DEBUGRUNTIME
81 # define D(x) if (unet_debug) { x }
82 # define DIF(u, x) if ((u)->f & UNIF_DEBUG) { x }
83 #elif UNET_DEBUG == UNET_DEBUGNEVER
87 # error UNET_DEBUG set to invalid value (bug in configure script?)
90 /*----- Type definitions --------------------------------------------------*/
92 /* --- Unet connection status --- *
94 * Records are stored in a slightly strange doubly linked list. The list
95 * exists so that I can find the next unused sequence number when creating
96 * new connections. It's odd because of the type of the @prev@ node;
97 * rather than being the address of the previous item, it's the address of
98 * the previous item's pointer to me, which among other good things means
99 * that it works on the list head too.
103 struct unet *next, **prev; /* List of unet blocks */
104 struct device nif; /* Network interface block */
105 int seq; /* Sequence number for connection */
106 char name[UNET_NAMEMAX]; /* Buffer for my interface name */
107 struct wait_queue *q; /* Wait list for device reads */
108 struct sk_buff_head skbq; /* Queue of packets waiting */
109 struct enet_statistics e; /* Pointer to statistics block */
110 unsigned short protocol; /* Protocol for outgoing packets */
111 unsigned f; /* Userful flags */
114 /*----- Static variables --------------------------------------------------*/
116 #if UNET_DEBUG == UNET_DEBUGRUNTIME
117 static int unet_debug = 0;
118 MODULE_PARM(unet_debug, "i");
121 static int unet_npersist = UNET_NPERSIST;
122 static int unet_maxif = UNET_MAXIF;
123 static struct unet *unet_persistent;
124 static struct unet *unet_list = 0;
126 MODULE_PARM(unet_npersist, "i");
127 MODULE_PARM(unet_maxif, "i");
129 /*----- Debugging code ----------------------------------------------------*/
131 #if UNET_DEBUG != UNET_DEBUGNEVER
133 /* --- @unet_dumpBlock@ --- *
135 * Arguments: @struct unet *u@ = pointer to block to dump
139 * Use: Dumps a unet object to syslogd.
142 static void unet_dumpBlock(struct unet *u)
144 printk(KERN_DEBUG "unet: dumping unet block at %p\n", u);
145 printk(KERN_DEBUG " sequence number = %d\n", u->seq);
146 printk(KERN_DEBUG " interface name = `%s'\n", u->name);
147 printk(KERN_DEBUG " flags =%s%s%s\n",
148 u->f & UNIF_TRANS ? " TRANS" : "",
149 u->f & UNIF_OPEN ? " OPEN" : "",
150 u->f & UNIF_DEBUG ? " DEBUG" : "");
151 printk(KERN_DEBUG " interface type = %d\n", u->nif.type);
152 printk(KERN_DEBUG " header len = %d\n", u->nif.hard_header_len);
153 printk(KERN_DEBUG " mtu = %d\n", u->nif.mtu);
154 printk(KERN_DEBUG " protocol = %d\n", ntohs(u->protocol));
155 printk(KERN_DEBUG " address len = %d\n", u->nif.addr_len);
158 /* --- @unet_dump@ --- *
164 * Use: Dumps the entire unet state to syslogd.
167 static void unet_dump(void)
172 for (i = 0; i < unet_npersist; i++)
173 unet_dumpBlock(&unet_persistent[i]);
174 for (u = unet_list; u; u = u->next)
178 /* --- @unet_hexdump@ --- *
180 * Arguments: @const char *prefix@ = prefix to print on output lines
181 * @const void *b@ = pointer to block to dump
182 * @size_t sz@ = size of block to dump
186 * Use: Dumps a hex block to the kernel log.
189 #define UNET_HEXROWSZ 16
191 static void unet_hexdump(const char *prefix, const char *b, size_t sz)
193 const unsigned char *p = b;
200 /* --- Now start work --- */
204 q += sprintf(q, "%s%08lx : ", prefix, o);
205 for (i = 0; i < UNET_HEXROWSZ; i++) {
207 q += sprintf(q, "%02x ", p[i]);
209 q += sprintf(q, "** ");
211 *q++ = ':'; *q++ = ' ';
212 for (i = 0; i < UNET_HEXROWSZ; i++) {
214 *q++ = (p[i] >= 32 && p[i] < 127) ? p[i] : '.';
221 c = (sz >= UNET_HEXROWSZ) ? UNET_HEXROWSZ : sz;
222 sz -= c, p += c, o += c;
228 /*----- The unet network interfaces ---------------------------------------*/
230 /* --- @unet_ifopen@ --- *
232 * Arguments: @struct device *nif@ = pointer to network interface
234 * Returns: Zero or error condition.
236 * Use: Turns on the network interface ready for action. Oh, yes.
239 static int unet_ifopen(struct device *nif)
241 D( struct unet *u = nif->priv;
242 if (u->f & UNIF_DEBUG)
243 printk(KERN_DEBUG "unet: opening interface %s\n", u->name); )
248 /* --- @unet_ifclose@ --- *
250 * Arguments: @struct device *nif@ = pointer to network interface
252 * Returns: Zero or error condition.
254 * Use: Turns off the network interface.
257 static int unet_ifclose(struct device *nif)
259 D( struct unet *u = nif->priv;
260 if (u->f & UNIF_DEBUG)
261 printk(KERN_DEBUG "unet: closing interface %d\n", u->seq); )
266 /* --- @unet_iftx@ --- *
268 * Arguments: @struct sk_buff *skb@ = incoming network packet
269 * @struct device *nif@ = pointer to network interface
271 * Returns: Zero or error condition.
273 * Use: Queues a network packet ready for collection by the user
274 * end of the business.
277 static int unet_iftx(struct sk_buff *skb, struct device *nif)
279 struct unet *u = nif->priv;
283 printk(KERN_DEBUG "unet: packet received on if %s\n", u->name);
284 unet_hexdump(KERN_DEBUG " ", skb->data, skb->len); )
286 /* --- Discard packets when nobody's listening --- */
288 if ((u->f & UNIF_OPEN) == 0) {
289 DIF(u, printk(KERN_DEBUG "unet: dropped packet: nobody's listening\n"); )
295 /* --- Discard packets when the queue's too long --- */
297 if (u->skbq.qlen >= UNET_QMAXLEN) {
298 DIF(u, printk(KERN_DEBUG "unet: refused packet: queue overflow\n"); )
302 /* --- Attach the buffer to the waiting list --- */
305 skb_queue_tail(&u->skbq, skb);
307 DIF(u, printk(KERN_DEBUG "unet: queued packet OK\n"); )
309 /* --- If there are waiting processes, give 'em a kick --- */
312 DIF(u, printk(KERN_DEBUG "unet: waking up sleeping listeners\n"); )
313 wake_up_interruptible(&u->q);
318 /* --- @unet_ifgetstats@ --- *
320 * Arguments: @struct device *nif@ = pointer to network interface
322 * Returns: Pointer to a statistics buffer.
324 * Use: Returns a block of interface statistics.
327 static struct enet_statistics *unet_ifgetstats(struct device *nif)
329 struct unet *u = nif->priv;
330 DIF(u, printk(KERN_DEBUG "unet: stats request for if %s\n", u->name); )
334 /* --- @unet_ifinit@ --- *
336 * Arguments: @struct device *nif@ = pointer to network interface
338 * Returns: Zero or error condition.
340 * Use: Initialises a unet network interface.
343 static int unet_ifinit(struct device *nif)
345 struct unet *u = nif->priv;
347 DIF(u, printk(KERN_DEBUG "unet: initialise interface %s\n", u->name); )
349 /* --- Initialise statistics gathering --- */
351 memset(&u->e, 0, sizeof(u->e));
352 u->nif.get_stats = unet_ifgetstats;
354 /* --- Opening and closing interfaces --- */
356 u->nif.open = unet_ifopen;
357 u->nif.stop = unet_ifclose;
359 /* --- Sending packets to the `outside world' --- */
361 u->nif.hard_start_xmit = unet_iftx;
363 /* --- Some initialisation magic --- */
366 for (i = 0; i < DEV_NUMBUFFS; i++)
367 skb_queue_head_init(&u->nif.buffs[i]);
370 /* --- Configure other grotty bits of the interface --- */
372 u->nif.hard_header = 0;
373 u->nif.rebuild_header = 0;
374 u->nif.set_mac_address = 0;
376 u->nif.type = ARPHRD_LOOPBACK; /* Got a better idea? */
377 u->nif.hard_header_len = 0;
378 u->nif.mtu = 1500 - MAX_HEADER;
380 u->nif.tx_queue_len = 16; /* I keep my own queue */
382 memset(u->nif.broadcast, 0xFFu, MAX_ADDR_LEN);
384 u->nif.flags = IFF_NOARP;
386 /* --- Finished! --- */
391 /*----- Attachment management ---------------------------------------------*/
393 /* --- @unet_setup@ --- *
395 * Arguments: @struct unet *u@ = pointer to a unet block
396 * @int seq@ = sequence number to allocate
398 * Returns: Zero or error condition.
400 * Use: Initialises a unet block ready for action.
403 static int unet_setup(struct unet *u, int seq)
405 static struct device tpl;
408 D( printk(KERN_DEBUG "unet: setting up unet block %d\n", seq); )
410 /* --- A little bit of initialisation --- */
416 /* --- Inherit device debug flag from global flag --- */
418 #if UNET_DEBUG == UNET_DEBUGRUNTIME
421 #elif UNET_DEBUG == UNET_DEBUGALWAYS
425 /* --- Set up the network device --- */
428 sprintf(u->name, "unet%d", seq);
429 u->nif.name = u->name;
431 u->nif.init = unet_ifinit;
432 u->protocol = htons(ETH_P_IP);
434 if ((e = register_netdev(&u->nif)) != 0) {
435 printk(KERN_ERR "unet: couldn't register net interface\n");
439 /* --- Empty the skbuff list --- */
441 skb_queue_head_init(&u->skbq);
443 /* --- We're only finished, that's all --- */
448 /* --- @unet_flush@ --- *
450 * Arguments: @struct unet *u@ = pointer to a unet block
454 * Use: Releases all the packets waiting for transmission.
457 static void unet_flush(struct unet *u)
461 #if UNET_DEBUG != UNET_DEBUGNEVER
465 DIF(u, printk(KERN_DEBUG "unet: flushing packets on %s\n", u->name); )
467 while ((skb = skb_dequeue(&u->skbq)) != 0) {
471 DIF(u, printk(KERN_DEBUG "unet: released %d waiting packets\n", i); )
474 /* --- @unet_kill@ --- *
476 * Arguments: @struct unet *u@ = pointer to a unet block
480 * Use: Kills and decommissions a Usernet block.
483 static void unet_kill(struct unet *u)
486 unregister_netdev(&u->nif);
489 /*----- Handling the unet device ------------------------------------------*/
491 /* --- @unet_devopen@ --- *
493 * Arguments: @struct inode *ino@ = inode block to open
494 * @struct file *f@ = file block to play with
496 * Returns: Zero or error condition.
498 * Use: Handles the opening of a unet device.
501 static int unet_devopen(struct inode *ino, struct file *f)
503 struct unet *u, **up;
507 D( printk(KERN_DEBUG "unet: device open request\n"); )
509 /* --- Decide whether this is a persistent unet --- */
511 if ((seq = MINOR(ino->i_rdev)) < unet_npersist) {
512 u = &unet_persistent[seq];
513 if (u->f & UNIF_OPEN) {
517 D( printk(KERN_DEBUG "unet: opened persistent %s\n", u->name); )
520 /* --- Otherwise we've got to create a new one --- */
524 /* --- Try to find a spare sequence number --- */
526 for (seq = unet_npersist, up = &unet_list; *up != 0;
527 seq++, up = &(*up)->next) {
528 if ((*up)->seq > seq)
530 if (seq >= unet_maxif) {
531 printk("unet: all unets are occupied\n");
537 D( printk(KERN_DEBUG "unet: allocated sequence number %d\n", seq); )
539 /* --- Allocate a new block --- */
541 if ((u = kmalloc(sizeof(*u), GFP_KERNEL)) == 0) {
542 printk(KERN_ERR "unet: couldn't allocate a unet block\n");
547 /* --- Initialise the block --- */
549 if ((e = unet_setup(u, seq)) != 0)
553 /* --- Link the block into the list --- */
558 (*up)->prev = &u->next;
561 D( printk(KERN_DEBUG "unet: opened transient %d\n", seq);
572 /* --- Tidy up after little disasters --- */
580 /* --- @unet_devclose@ --- *
582 * Arguments: @struct inode *ino@ = pointer to inode block
583 * @struct file *f@ = pointer to file block
587 * Use: Frees up a unet connection.
590 static int unet_devclose(struct inode *ino, struct file *f)
592 struct unet *u = f->private_data;
594 DIF(u, printk(KERN_DEBUG "unet: closing %s\n", u->name); )
596 /* --- A transient unet needs to be destroyed --- */
598 if (u->f & UNIF_TRANS) {
601 u->next->prev = u->prev;
604 D( printk(KERN_DEBUG "unet: released transient unet\n"); )
607 /* --- A persistent unet needs to be shutdown --- */
612 DIF(u, printk(KERN_DEBUG "unet: unblocked persistent unet\n"); )
619 /* --- @unet_devpoll@ --- *
621 * Arguments: @struct file *f@ = pointer to my file block
622 * @struct poll_table_struct *p@ = poll table to wait on
624 * Returns: Nonzero if OK to continue, zero if waiting.
626 * Use: Plays a unet device's part in a @poll@(2) call.
629 static unsigned unet_devpoll(struct file *f, struct poll_table_struct *p)
631 struct unet *u = f->private_data;
634 DIF(u, printk(KERN_DEBUG "unet: poll request for %s\n", u->name); )
636 poll_wait(f, &u->q, p);
637 if (skb_peek(&u->skbq))
638 m |= POLLIN | POLLRDNORM;
639 m |= POLLOUT | POLLWRNORM;
643 /* --- @unet_devwrite@ --- *
645 * Arguments: @struct file *f@ = pointer to the file block
646 * @char *buf@ = pointer to caller's buffer
647 * @size_t sz@ = size of data to send
648 * @loff_t *off@ = offset to set (ignored)
650 * Returns: Number of bytes written, or error condition.
652 * Use: Sends a packet of data. No buffering is done.
655 static ssize_t unet_devwrite(struct file *f, const char *buf, size_t sz,
658 struct unet *u = f->private_data;
661 DIF(u, printk(KERN_DEBUG "unet: write request for %s\n", u->name); )
663 /* --- Dump the packet we're meant to send --- */
666 if (u->f & UNIF_DEBUG) {
667 void *b = kmalloc(sz, GFP_KERNEL);
669 copy_from_user(b, buf, sz);
670 unet_hexdump(KERN_DEBUG " ", b, sz);
673 printk(KERN_NOTICE "unet: not enough memory to dump block");
677 /* --- Allocate an skbuff for the block --- */
679 if ((skb = dev_alloc_skb(sz)) == 0) {
680 printk(KERN_ERR "unet: failed to allocate skbuff\n");
685 /* --- Copy my data into the skbuff --- */
687 copy_from_user(skb_put(skb, sz), buf, sz);
689 skb->mac.raw = skb->data;
690 skb->protocol = u->protocol;
696 /* --- @unet_devread@ --- *
698 * Arguments: @struct file *f@ = pointer to the file block
699 * @char *buf@ = pointer to caller's buffer
700 * @size_t sz@ = size of caller's buffer
701 * @loff_t *off@ = offset to set (ignored)
703 * Returns: Number of bytes read, or error condition.
705 * Use: Reads the next packet waiting for the device.
708 static ssize_t unet_devread(struct file *f, char *buf, size_t sz,
711 struct unet *u = f->private_data;
714 DIF(u, printk(KERN_DEBUG "unet: read request for %s\n", u->name); )
716 /* --- Is the user sane? --- *
718 * The UDP protocol returns immediately in response to a zero-length read,
719 * and following this behaviour seems to cause `least surprise'.
725 /* --- Make sure there's a packet waiting for me --- */
727 if ((skb = skb_dequeue(&u->skbq)) == 0) {
728 struct wait_queue wq = { current, 0 };
730 DIF(u, printk(KERN_DEBUG "unet: no packets waiting\n"); )
732 /* --- Check for nonblocking I/O --- */
734 if (f->f_flags & O_NONBLOCK) {
735 DIF(u, printk(KERN_DEBUG "unet: nonblocking read: fail\n"); )
736 return (-EWOULDBLOCK);
739 /* --- Otherwise block until there's a packet --- */
741 current->state = TASK_INTERRUPTIBLE;
742 add_wait_queue(&u->q, &wq);
746 if (signal_pending(current)) {
748 DIF(u, printk(KERN_DEBUG "unet: interrupted by signal\n"); )
750 remove_wait_queue(&u->q, &wq);
751 current->state = TASK_RUNNING;
752 return (-ERESTARTSYS);
755 DIF(u, printk(KERN_DEBUG "unet: blocking until packet arrives\n"); )
759 } while ((skb = skb_dequeue(&u->skbq)) == 0);
761 remove_wait_queue(&u->q, &wq);
762 current->state = TASK_RUNNING;
765 DIF(u, printk(KERN_DEBUG "unet: found a packet\n"); )
767 /* --- There is now a packet waiting --- */
771 copy_to_user(buf, skb->data, sz);
774 DIF(u, printk(KERN_DEBUG "unet: passed packet on to user\n"); )
779 /* --- @unet_devioctl@ --- *
781 * Arguments: @struct inode *ino@ = pointer to inode block
782 * @struct file *f@ = pointer to file block
783 * @unsigned int c@ = command code to execute
784 * @unsigned long arg@ = argument passed to me
786 * Returns: Positive return value, or negative error condition.
788 * Use: Performs miscellaneous operations on a unet device.
791 static int unet_devioctl(struct inode *ino,
796 struct unet *u = f->private_data;
799 DIF(u, printk(KERN_DEBUG "unet: ioctl request for %s\n", u->name); )
803 /* --- @FIONREAD@ --- *
805 * Caller wants to know how big the next packet will be. Don't
810 struct sk_buff *skb = skb_peek(&u->skbq);
812 DIF(u, printk(KERN_DEBUG "unet: FIONREAD found %d bytes\n",
813 skb ? skb->len : 0); )
819 /* --- @UNIOCGINFO@ --- *
821 * Caller wants information about me.
825 struct unet_info uni, *unip;
827 DIF(u, printk(KERN_DEBUG "unet: UNIOCGINFO called\n"); )
829 unip = (struct unet_info *)arg;
831 /* --- Special case --- *
833 * If the pointer is null, this call means `are you there?' and can
834 * be used to check for a Usernet attachment.
840 /* --- Ensure that the area can be written to --- */
842 if ((e = verify_area(VERIFY_WRITE, unip, sizeof(*unip))) != 0)
845 /* --- Build the information block in memory --- */
847 memset(&uni, 0, sizeof(uni)); /* Paranoia */
848 strncpy(uni.uni_ifname, u->name, UNET_NAMEMAX);
849 uni.uni_mtu = u->nif.mtu;
850 uni.uni_family = AF_INET;
851 uni.uni_proto = ntohs(u->protocol);
852 uni.uni_flags = u->f;
854 /* --- Copy it to the user and return --- */
856 copy_to_user(unip, &uni, sizeof(uni));
859 /* --- @UNIOCSDEBUG@ --- */
861 #if UNET_DEBUG != UNET_DEBUGNEVER
864 int o = !!(u->f & UNIF_DEBUG);
867 printk(KERN_DEBUG "unet: UNIOCSDEBUG on %s: %s\n", u->name,
868 (o && n) ? "debugging still on" :
869 (!o && n) ? "debugging turned on" :
870 (o && !n) ? "debugging turned off" :
871 (!o && !n) ? "you can't see this message" :
872 "Logic failure: universe exploding");
881 /* --- @UNIOCGPROTO@ and @UNIOCSPROTO@ --- */
884 D( printk(KERN_DEBUG "unet: UNIOCGPROTO on %s: read protocol: %d\n",
885 u->name, ntohs(u->protocol)); )
886 e = ntohs(u->protocol);
889 D( printk(KERN_DEBUG "unet: UNIOCSPROTO on %s: set protocol: %d\n",
890 u->name, (int)arg); )
891 u->protocol = htons(arg);
894 /* --- @UNIOCGGDEBUG@ and @UNIOCSGDEBUG@ --- */
897 D( printk(KERN_DEBUG "unet: UNIOCGGDEBUG: get global debug: on\n"); )
898 #if UNET_DEBUG == UNET_DEBUGRUNTIME
900 #elif UNET_DEBUG == UNET_DEBUGALWAYS
902 #elif UNET_DEBUG == UNET_DEBUGNEVER
907 #if UNET_DEBUG == UNET_DEBUGRUNTIME
909 printk(KERN_DEBUG "unet: UNIOCSGDEBUG: set global debug: %s\n",
910 (arg && unet_debug) ? "debugging still on" :
911 (!arg && unet_debug) ? "debugging turned off" :
912 (arg && !unet_debug) ? "debugging turned on" :
913 (!arg && !unet_debug) ? "you can't see this message" :
914 "Logic failure: universe exploding");
919 /* --- @UNIOCDUMP@ --- */
921 #if UNET_DEBUG != UNET_DEBUGNEVER
923 D( unet_dumpBlock(u); )
927 /* --- @UNIOCGMAXIF@ --- */
930 D( printk(KERN_DEBUG "unet: UNIOCGMAXIF: unet_maxif = %d\n",
935 /* --- @UNIOCSMAXIF@ --- */
939 if (arg < unet_npersist || arg > INT_MAX)
941 for (u = unet_list; u; u = u->next) {
942 if (u->seq >= unet_npersist)
946 D( printk(KERN_DEBUG "unet: UNIOCSMAXIF: unet_maxif = %d\n",
950 /* --- Everything else --- *
956 D( printk(KERN_DEBUG "unet: unknown ioctl %08x\n", c); )
963 /*----- The unet device ---------------------------------------------------*/
965 /* --- Device operations --- */
967 struct file_operations unet_fops = {
968 0, /* unet_devlseek */
971 0, /* unet_devreaddir */
974 0, /* unet_devmmap */
980 /*----- Initaliseation and shutdown ---------------------------------------*/
982 /* --- @unet_init@ --- *
986 * Returns: Zero or error condition.
988 * Use: Registers the unet device.
991 __initfunc(int unet_init(void))
996 /* --- Register my character device --- */
998 if ((e = register_chrdev(UNET_MAJOR, "unet", &unet_fops)) != 0) {
999 printk(KERN_ERR "unet: can't claim major device %d\n", UNET_MAJOR);
1003 /* --- Make the persistent unet devices --- */
1005 if ((unet_persistent = kmalloc(unet_npersist * sizeof(struct unet),
1006 GFP_KERNEL)) == 0) {
1007 printk(KERN_ERR "unet: can't allocate %i persistent unet blocks",
1013 for (i = 0; i < unet_npersist; i++) {
1014 if ((e = unet_setup(&unet_persistent[i], i)) != 0) {
1015 printk(KERN_ERR "unet: can't create persistent unet %d\n", i);
1025 /* --- Some bad stuff happened --- */
1030 unregister_netdev(&unet_persistent[i].nif);
1032 kfree(unet_persistent);
1035 unregister_chrdev(UNET_MAJOR, "unet");
1043 /* --- @init_module@ --- *
1047 * Returns: Zero or error condition.
1049 * Use: Initialises the unet kernel module.
1052 int init_module(void)
1054 if (unet_npersist < 0 || unet_maxif < unet_npersist
1055 #if UNET_DEBUG == UNET_DEBUGRUNTIME
1056 || (unet_debug != 0 && unet_debug != 1)
1060 return (unet_init());
1063 /* --- @cleanup_module@ --- *
1069 * Use: Tidies up the unet module ready for it to be killed.
1072 void cleanup_module(void)
1076 for (i = 0; i < unet_npersist; i++) {
1077 D( printk(KERN_DEBUG "unet: releasing persistent unet %d\n", i); )
1078 unet_kill(&unet_persistent[i]);
1080 kfree(unet_persistent);
1082 unregister_chrdev(UNET_MAJOR, "unet");
1087 /*----- That's all, folks -------------------------------------------------*/