3 * $Id: unet.c,v 1.3 2001/02/19 19:10:28 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.3 2001/02/19 19:10:28 mdw
33 * New option to allow changing interface flags.
35 * Revision 1.2 2001/02/03 18:39:59 mdw
36 * Setting the maximum interface count now does the right thing.
38 * Revision 1.1 2001/01/25 22:03:39 mdw
39 * Initial check-in (somewhat belated).
43 /*----- Include files -----------------------------------------------------*/
45 #include <linux/module.h>
47 #include <asm/byteorder.h>
48 #include <asm/segment.h>
50 #include <linux/types.h>
51 #include <linux/kernel.h>
52 #include <linux/wait.h>
53 #include <linux/sched.h>
55 #include <linux/poll.h>
56 #include <linux/netdevice.h>
57 #include <linux/etherdevice.h>
58 #include <linux/if_arp.h>
59 #include <linux/malloc.h>
60 #include <linux/errno.h>
61 #include <linux/init.h>
66 MODULE_AUTHOR("Mark Wooding");
67 MODULE_DESCRIPTION("Allows userland handling of a network interface");
69 /*----- Debugging macros --------------------------------------------------*/
71 #define UNET_DEBUGALWAYS 1
72 #define UNET_DEBUGRUNTIME 0
73 #define UNET_DEBUGNEVER -1
75 /* --- If the macro isn't defined then be switchable at runtime --- */
78 # define UNET_DEBUG UNET_DEBUGRUNTIME
81 /* --- Define the base macro @D@ according to the debug setting --- */
83 #if UNET_DEBUG == UNET_DEBUGALWAYS
85 # define DIF(u, x) if ((u)->f & UNIF_DEBUG) { x }
86 #elif UNET_DEBUG == UNET_DEBUGRUNTIME
87 # define D(x) if (unet_debug) { x }
88 # define DIF(u, x) if ((u)->f & UNIF_DEBUG) { x }
89 #elif UNET_DEBUG == UNET_DEBUGNEVER
93 # error UNET_DEBUG set to invalid value (bug in configure script?)
96 /*----- Type definitions --------------------------------------------------*/
98 /* --- Unet connection status --- *
100 * Records are stored in a slightly strange doubly linked list. The list
101 * exists so that I can find the next unused sequence number when creating
102 * new connections. It's odd because of the type of the @prev@ node;
103 * rather than being the address of the previous item, it's the address of
104 * the previous item's pointer to me, which among other good things means
105 * that it works on the list head too.
109 struct unet *next, **prev; /* List of unet blocks */
110 struct device nif; /* Network interface block */
111 int seq; /* Sequence number for connection */
112 char name[UNET_NAMEMAX]; /* Buffer for my interface name */
113 struct wait_queue *q; /* Wait list for device reads */
114 struct sk_buff_head skbq; /* Queue of packets waiting */
115 struct enet_statistics e; /* Pointer to statistics block */
116 unsigned short protocol; /* Protocol for outgoing packets */
117 unsigned f; /* Userful flags */
120 /*----- Static variables --------------------------------------------------*/
122 #if UNET_DEBUG == UNET_DEBUGRUNTIME
123 static int unet_debug = 0;
124 MODULE_PARM(unet_debug, "i");
127 static int unet_npersist = UNET_NPERSIST;
128 static int unet_maxif = UNET_MAXIF;
129 static struct unet *unet_persistent;
130 static struct unet *unet_list = 0;
131 static int unet_nif = 0;
133 MODULE_PARM(unet_npersist, "i");
134 MODULE_PARM(unet_maxif, "i");
136 /*----- Debugging code ----------------------------------------------------*/
138 #if UNET_DEBUG != UNET_DEBUGNEVER
140 /* --- @unet_dumpBlock@ --- *
142 * Arguments: @struct unet *u@ = pointer to block to dump
146 * Use: Dumps a unet object to syslogd.
149 static void unet_dumpBlock(struct unet *u)
151 printk(KERN_DEBUG "unet: dumping unet block at %p\n", u);
152 printk(KERN_DEBUG " sequence number = %d\n", u->seq);
153 printk(KERN_DEBUG " interface name = `%s'\n", u->name);
154 printk(KERN_DEBUG " flags =%s%s%s\n",
155 u->f & UNIF_TRANS ? " TRANS" : "",
156 u->f & UNIF_OPEN ? " OPEN" : "",
157 u->f & UNIF_DEBUG ? " DEBUG" : "");
158 printk(KERN_DEBUG " interface type = %d\n", u->nif.type);
159 printk(KERN_DEBUG " header len = %d\n", u->nif.hard_header_len);
160 printk(KERN_DEBUG " mtu = %d\n", u->nif.mtu);
161 printk(KERN_DEBUG " protocol = %d\n", ntohs(u->protocol));
162 printk(KERN_DEBUG " address len = %d\n", u->nif.addr_len);
165 /* --- @unet_dump@ --- *
171 * Use: Dumps the entire unet state to syslogd.
174 static void unet_dump(void)
179 for (i = 0; i < unet_npersist; i++)
180 unet_dumpBlock(&unet_persistent[i]);
181 for (u = unet_list; u; u = u->next)
185 /* --- @unet_hexdump@ --- *
187 * Arguments: @const char *prefix@ = prefix to print on output lines
188 * @const void *b@ = pointer to block to dump
189 * @size_t sz@ = size of block to dump
193 * Use: Dumps a hex block to the kernel log.
196 #define UNET_HEXROWSZ 16
198 static void unet_hexdump(const char *prefix, const char *b, size_t sz)
200 const unsigned char *p = b;
207 /* --- Now start work --- */
211 q += sprintf(q, "%s%08lx : ", prefix, o);
212 for (i = 0; i < UNET_HEXROWSZ; i++) {
214 q += sprintf(q, "%02x ", p[i]);
216 q += sprintf(q, "** ");
218 *q++ = ':'; *q++ = ' ';
219 for (i = 0; i < UNET_HEXROWSZ; i++) {
221 *q++ = (p[i] >= 32 && p[i] < 127) ? p[i] : '.';
228 c = (sz >= UNET_HEXROWSZ) ? UNET_HEXROWSZ : sz;
229 sz -= c, p += c, o += c;
235 /*----- The unet network interfaces ---------------------------------------*/
237 /* --- @unet_ifopen@ --- *
239 * Arguments: @struct device *nif@ = pointer to network interface
241 * Returns: Zero or error condition.
243 * Use: Turns on the network interface ready for action. Oh, yes.
246 static int unet_ifopen(struct device *nif)
248 D( struct unet *u = nif->priv;
249 if (u->f & UNIF_DEBUG)
250 printk(KERN_DEBUG "unet: opening interface %s\n", u->name); )
255 /* --- @unet_ifclose@ --- *
257 * Arguments: @struct device *nif@ = pointer to network interface
259 * Returns: Zero or error condition.
261 * Use: Turns off the network interface.
264 static int unet_ifclose(struct device *nif)
266 D( struct unet *u = nif->priv;
267 if (u->f & UNIF_DEBUG)
268 printk(KERN_DEBUG "unet: closing interface %d\n", u->seq); )
273 /* --- @unet_iftx@ --- *
275 * Arguments: @struct sk_buff *skb@ = incoming network packet
276 * @struct device *nif@ = pointer to network interface
278 * Returns: Zero or error condition.
280 * Use: Queues a network packet ready for collection by the user
281 * end of the business.
284 static int unet_iftx(struct sk_buff *skb, struct device *nif)
286 struct unet *u = nif->priv;
290 printk(KERN_DEBUG "unet: packet received on if %s\n", u->name);
291 unet_hexdump(KERN_DEBUG " ", skb->data, skb->len); )
293 /* --- Discard packets when nobody's listening --- */
295 if ((u->f & UNIF_OPEN) == 0) {
296 DIF(u, printk(KERN_DEBUG "unet: dropped packet: nobody's listening\n"); )
302 /* --- Discard packets when the queue's too long --- */
304 if (u->skbq.qlen >= UNET_QMAXLEN) {
305 DIF(u, printk(KERN_DEBUG "unet: refused packet: queue overflow\n"); )
309 /* --- Attach the buffer to the waiting list --- */
312 skb_queue_tail(&u->skbq, skb);
314 DIF(u, printk(KERN_DEBUG "unet: queued packet OK\n"); )
316 /* --- If there are waiting processes, give 'em a kick --- */
319 DIF(u, printk(KERN_DEBUG "unet: waking up sleeping listeners\n"); )
320 wake_up_interruptible(&u->q);
325 /* --- @unet_ifgetstats@ --- *
327 * Arguments: @struct device *nif@ = pointer to network interface
329 * Returns: Pointer to a statistics buffer.
331 * Use: Returns a block of interface statistics.
334 static struct enet_statistics *unet_ifgetstats(struct device *nif)
336 struct unet *u = nif->priv;
337 DIF(u, printk(KERN_DEBUG "unet: stats request for if %s\n", u->name); )
341 /* --- @unet_ifinit@ --- *
343 * Arguments: @struct device *nif@ = pointer to network interface
345 * Returns: Zero or error condition.
347 * Use: Initialises a unet network interface.
350 static int unet_ifinit(struct device *nif)
352 struct unet *u = nif->priv;
354 DIF(u, printk(KERN_DEBUG "unet: initialise interface %s\n", u->name); )
356 /* --- Initialise statistics gathering --- */
358 memset(&u->e, 0, sizeof(u->e));
359 u->nif.get_stats = unet_ifgetstats;
361 /* --- Opening and closing interfaces --- */
363 u->nif.open = unet_ifopen;
364 u->nif.stop = unet_ifclose;
366 /* --- Sending packets to the `outside world' --- */
368 u->nif.hard_start_xmit = unet_iftx;
370 /* --- Some initialisation magic --- */
373 for (i = 0; i < DEV_NUMBUFFS; i++)
374 skb_queue_head_init(&u->nif.buffs[i]);
377 /* --- Configure other grotty bits of the interface --- */
379 u->nif.hard_header = 0;
380 u->nif.rebuild_header = 0;
381 u->nif.set_mac_address = 0;
383 u->nif.type = ARPHRD_TUNNEL; /* Got a better idea? */
384 u->nif.hard_header_len = 0;
385 u->nif.mtu = 1500 - MAX_HEADER;
387 u->nif.tx_queue_len = 16; /* I keep my own queue */
389 memset(u->nif.broadcast, 0xFFu, MAX_ADDR_LEN);
391 u->nif.flags = IFF_NOARP;
393 /* --- Finished! --- */
398 /*----- Attachment management ---------------------------------------------*/
400 /* --- @unet_setup@ --- *
402 * Arguments: @struct unet *u@ = pointer to a unet block
403 * @int seq@ = sequence number to allocate
405 * Returns: Zero or error condition.
407 * Use: Initialises a unet block ready for action.
410 static int unet_setup(struct unet *u, int seq)
412 static struct device tpl;
415 D( printk(KERN_DEBUG "unet: setting up unet block %d\n", seq); )
417 /* --- A little bit of initialisation --- */
423 /* --- Inherit device debug flag from global flag --- */
425 #if UNET_DEBUG == UNET_DEBUGRUNTIME
428 #elif UNET_DEBUG == UNET_DEBUGALWAYS
432 /* --- Set up the network device --- */
435 sprintf(u->name, "unet%d", seq);
436 u->nif.name = u->name;
438 u->nif.init = unet_ifinit;
439 u->protocol = htons(ETH_P_IP);
441 if ((e = register_netdev(&u->nif)) != 0) {
442 printk(KERN_ERR "unet: couldn't register net interface\n");
446 /* --- Empty the skbuff list --- */
448 skb_queue_head_init(&u->skbq);
450 /* --- We're only finished, that's all --- */
455 /* --- @unet_flush@ --- *
457 * Arguments: @struct unet *u@ = pointer to a unet block
461 * Use: Releases all the packets waiting for transmission.
464 static void unet_flush(struct unet *u)
468 #if UNET_DEBUG != UNET_DEBUGNEVER
472 DIF(u, printk(KERN_DEBUG "unet: flushing packets on %s\n", u->name); )
474 while ((skb = skb_dequeue(&u->skbq)) != 0) {
478 DIF(u, printk(KERN_DEBUG "unet: released %d waiting packets\n", i); )
481 /* --- @unet_kill@ --- *
483 * Arguments: @struct unet *u@ = pointer to a unet block
487 * Use: Kills and decommissions a Usernet block.
490 static void unet_kill(struct unet *u)
493 unregister_netdev(&u->nif);
496 /*----- Handling the unet device ------------------------------------------*/
498 /* --- @unet_devopen@ --- *
500 * Arguments: @struct inode *ino@ = inode block to open
501 * @struct file *f@ = file block to play with
503 * Returns: Zero or error condition.
505 * Use: Handles the opening of a unet device.
508 static int unet_devopen(struct inode *ino, struct file *f)
510 struct unet *u, **up;
514 D( printk(KERN_DEBUG "unet: device open request\n"); )
516 /* --- Decide whether this is a persistent unet --- */
518 if ((seq = MINOR(ino->i_rdev)) < unet_npersist) {
519 u = &unet_persistent[seq];
520 if (u->f & UNIF_OPEN) {
524 D( printk(KERN_DEBUG "unet: opened persistent %s\n", u->name); )
527 /* --- Otherwise we've got to create a new one --- */
529 else if (seq == UNET_TRANSMINOR) {
531 /* --- Try to find a spare sequence number --- */
533 if (unet_nif >= unet_maxif) {
534 printk(KERN_NOTICE "unet: no interfaces left\n");
538 for (seq = unet_npersist, up = &unet_list; *up != 0;
539 seq++, up = &(*up)->next) {
540 if ((*up)->seq > seq)
543 D( printk(KERN_DEBUG "unet: allocated sequence number %d\n", seq); )
545 /* --- Allocate a new block --- */
547 if ((u = kmalloc(sizeof(*u), GFP_KERNEL)) == 0) {
548 printk(KERN_ERR "unet: couldn't allocate a unet block\n");
553 /* --- Initialise the block --- */
555 if ((e = unet_setup(u, seq)) != 0)
560 /* --- Link the block into the list --- */
565 (*up)->prev = &u->next;
568 D( printk(KERN_DEBUG "unet: opened transient %d\n", seq);
580 /* --- Tidy up after little disasters --- */
588 /* --- @unet_devclose@ --- *
590 * Arguments: @struct inode *ino@ = pointer to inode block
591 * @struct file *f@ = pointer to file block
595 * Use: Frees up a unet connection.
598 static int unet_devclose(struct inode *ino, struct file *f)
600 struct unet *u = f->private_data;
602 DIF(u, printk(KERN_DEBUG "unet: closing %s\n", u->name); )
604 /* --- A transient unet needs to be destroyed --- */
606 if (u->f & UNIF_TRANS) {
610 u->next->prev = u->prev;
614 D( printk(KERN_DEBUG "unet: released transient %d\n", seq); )
617 /* --- A persistent unet needs to be shutdown --- */
622 DIF(u, printk(KERN_DEBUG "unet: unblocked persistent unet\n"); )
629 /* --- @unet_devpoll@ --- *
631 * Arguments: @struct file *f@ = pointer to my file block
632 * @struct poll_table_struct *p@ = poll table to wait on
634 * Returns: Nonzero if OK to continue, zero if waiting.
636 * Use: Plays a unet device's part in a @poll@(2) call.
639 static unsigned unet_devpoll(struct file *f, struct poll_table_struct *p)
641 struct unet *u = f->private_data;
644 DIF(u, printk(KERN_DEBUG "unet: poll request for %s\n", u->name); )
646 poll_wait(f, &u->q, p);
647 if (skb_peek(&u->skbq))
648 m |= POLLIN | POLLRDNORM;
649 m |= POLLOUT | POLLWRNORM;
653 /* --- @unet_devwrite@ --- *
655 * Arguments: @struct file *f@ = pointer to the file block
656 * @char *buf@ = pointer to caller's buffer
657 * @size_t sz@ = size of data to send
658 * @loff_t *off@ = offset to set (ignored)
660 * Returns: Number of bytes written, or error condition.
662 * Use: Sends a packet of data. No buffering is done.
665 static ssize_t unet_devwrite(struct file *f, const char *buf, size_t sz,
668 struct unet *u = f->private_data;
671 DIF(u, printk(KERN_DEBUG "unet: write request for %s\n", u->name); )
673 /* --- Dump the packet we're meant to send --- */
676 if (u->f & UNIF_DEBUG) {
677 void *b = kmalloc(sz, GFP_KERNEL);
679 copy_from_user(b, buf, sz);
680 unet_hexdump(KERN_DEBUG " ", b, sz);
683 printk(KERN_NOTICE "unet: not enough memory to dump block");
687 /* --- Allocate an skbuff for the block --- */
689 if ((skb = dev_alloc_skb(sz)) == 0) {
690 printk(KERN_ERR "unet: failed to allocate skbuff\n");
695 /* --- Copy my data into the skbuff --- */
697 copy_from_user(skb_put(skb, sz), buf, sz);
699 skb->mac.raw = skb->data;
700 skb->protocol = u->protocol;
706 /* --- @unet_devread@ --- *
708 * Arguments: @struct file *f@ = pointer to the file block
709 * @char *buf@ = pointer to caller's buffer
710 * @size_t sz@ = size of caller's buffer
711 * @loff_t *off@ = offset to set (ignored)
713 * Returns: Number of bytes read, or error condition.
715 * Use: Reads the next packet waiting for the device.
718 static ssize_t unet_devread(struct file *f, char *buf, size_t sz,
721 struct unet *u = f->private_data;
724 DIF(u, printk(KERN_DEBUG "unet: read request for %s\n", u->name); )
726 /* --- Is the user sane? --- *
728 * The UDP protocol returns immediately in response to a zero-length read,
729 * and following this behaviour seems to cause `least surprise'.
735 /* --- Make sure there's a packet waiting for me --- */
737 if ((skb = skb_dequeue(&u->skbq)) == 0) {
738 struct wait_queue wq = { current, 0 };
740 DIF(u, printk(KERN_DEBUG "unet: no packets waiting\n"); )
742 /* --- Check for nonblocking I/O --- */
744 if (f->f_flags & O_NONBLOCK) {
745 DIF(u, printk(KERN_DEBUG "unet: nonblocking read: fail\n"); )
746 return (-EWOULDBLOCK);
749 /* --- Otherwise block until there's a packet --- */
751 current->state = TASK_INTERRUPTIBLE;
752 add_wait_queue(&u->q, &wq);
756 if (signal_pending(current)) {
758 DIF(u, printk(KERN_DEBUG "unet: interrupted by signal\n"); )
760 remove_wait_queue(&u->q, &wq);
761 current->state = TASK_RUNNING;
762 return (-ERESTARTSYS);
765 DIF(u, printk(KERN_DEBUG "unet: blocking until packet arrives\n"); )
769 } while ((skb = skb_dequeue(&u->skbq)) == 0);
771 remove_wait_queue(&u->q, &wq);
772 current->state = TASK_RUNNING;
775 DIF(u, printk(KERN_DEBUG "unet: found a packet\n"); )
777 /* --- There is now a packet waiting --- */
781 copy_to_user(buf, skb->data, sz);
784 DIF(u, printk(KERN_DEBUG "unet: passed packet on to user\n"); )
789 /* --- @unet_devioctl@ --- *
791 * Arguments: @struct inode *ino@ = pointer to inode block
792 * @struct file *f@ = pointer to file block
793 * @unsigned int c@ = command code to execute
794 * @unsigned long arg@ = argument passed to me
796 * Returns: Positive return value, or negative error condition.
798 * Use: Performs miscellaneous operations on a unet device.
801 static int unet_devioctl(struct inode *ino,
806 struct unet *u = f->private_data;
809 DIF(u, printk(KERN_DEBUG "unet: ioctl request for %s\n", u->name); )
813 /* --- @FIONREAD@ --- *
815 * Caller wants to know how big the next packet will be. Don't
820 struct sk_buff *skb = skb_peek(&u->skbq);
822 DIF(u, printk(KERN_DEBUG "unet: FIONREAD found %d bytes\n",
823 skb ? skb->len : 0); )
829 /* --- @UNIOCGINFO@ --- *
831 * Caller wants information about me.
835 struct unet_info uni, *unip;
837 DIF(u, printk(KERN_DEBUG "unet: UNIOCGINFO called\n"); )
839 unip = (struct unet_info *)arg;
841 /* --- Special case --- *
843 * If the pointer is null, this call means `are you there?' and can
844 * be used to check for a Usernet attachment.
850 /* --- Ensure that the area can be written to --- */
852 if ((e = verify_area(VERIFY_WRITE, unip, sizeof(*unip))) != 0)
855 /* --- Build the information block in memory --- */
857 memset(&uni, 0, sizeof(uni)); /* Paranoia */
858 strncpy(uni.uni_ifname, u->name, UNET_NAMEMAX);
859 uni.uni_mtu = u->nif.mtu;
860 uni.uni_family = AF_INET;
861 uni.uni_proto = ntohs(u->protocol);
862 uni.uni_flags = u->f;
864 /* --- Copy it to the user and return --- */
866 copy_to_user(unip, &uni, sizeof(uni));
869 /* --- @UNIOCSDEBUG@ --- */
871 #if UNET_DEBUG != UNET_DEBUGNEVER
874 int o = !!(u->f & UNIF_DEBUG);
876 if (!capable(CAP_SYS_ADMIN))
879 printk(KERN_DEBUG "unet: UNIOCSDEBUG on %s: %s\n", u->name,
880 (o && n) ? "debugging still on" :
881 (!o && n) ? "debugging turned on" :
882 (o && !n) ? "debugging turned off" :
883 (!o && !n) ? "you can't see this message" :
884 "Logic failure: universe exploding");
893 /* --- @UNIOCGPROTO@ and @UNIOCSPROTO@ --- */
896 D( printk(KERN_DEBUG "unet: UNIOCGPROTO on %s: read protocol: %d\n",
897 u->name, ntohs(u->protocol)); )
898 e = ntohs(u->protocol);
901 D( printk(KERN_DEBUG "unet: UNIOCSPROTO on %s: set protocol: %d\n",
902 u->name, (int)arg); )
903 u->protocol = htons(arg);
906 /* --- @UNIOCGGDEBUG@ and @UNIOCSGDEBUG@ --- */
909 D( printk(KERN_DEBUG "unet: UNIOCGGDEBUG: get global debug: on\n"); )
910 #if UNET_DEBUG == UNET_DEBUGRUNTIME
912 #elif UNET_DEBUG == UNET_DEBUGALWAYS
914 #elif UNET_DEBUG == UNET_DEBUGNEVER
919 #if UNET_DEBUG == UNET_DEBUGRUNTIME
921 if (!capable(CAP_SYS_ADMIN))
923 if (arg || unet_debug) {
924 printk(KERN_DEBUG "unet: UNIOCSGDEBUG: set global debug: %s\n",
925 (arg && unet_debug) ? "debugging still on" :
926 (!arg && unet_debug) ? "debugging turned off" :
927 (arg && !unet_debug) ? "debugging turned on" :
928 (!arg && !unet_debug) ? "you can't see this message" :
929 "Logic failure: universe exploding");
935 /* --- @UNIOCDUMP@ --- */
937 #if UNET_DEBUG != UNET_DEBUGNEVER
939 D( unet_dumpBlock(u); )
943 /* --- @UNIOCGMAXIF@ --- */
946 D( printk(KERN_DEBUG "unet: UNIOCGMAXIF: unet_maxif = %d\n",
951 /* --- @UNIOCSMAXIF@ --- */
954 if (!capable(CAP_SYS_ADMIN))
956 D( printk(KERN_DEBUG "unet: UNIOCSMAXIF: "
957 "arg = %ld; npersist = %d; nif = %d\n",
958 arg, unet_npersist, unet_nif); )
959 if (arg < unet_npersist || arg > INT_MAX)
965 D( printk(KERN_DEBUG "unet: UNIOCSMAXIF: set unet_maxif = %d\n",
969 /* --- @UNIOCFIFFLAGS@ and @UNIOCSIFFLAGS@ --- */
972 D( printk(KERN_DEBUG "unet: UNIOCGIFFFLAGS\n"); )
976 D( printk(KERN_DEBUG "unet: UNIOCSIFFFLAGS: arg = %ld\n", arg); )
977 if ((u->nif.flags ^ arg) & ~IFF_VOLATILE)
982 /* --- Everything else --- *
988 D( printk(KERN_DEBUG "unet: unknown ioctl %08x\n", c); )
995 /*----- The unet device ---------------------------------------------------*/
997 /* --- Device operations --- */
999 struct file_operations unet_fops = {
1000 0, /* unet_devlseek */
1003 0, /* unet_devreaddir */
1006 0, /* unet_devmmap */
1012 /*----- Initaliseation and shutdown ---------------------------------------*/
1014 /* --- @unet_init@ --- *
1018 * Returns: Zero or error condition.
1020 * Use: Registers the unet device.
1023 __initfunc(int unet_init(void))
1028 /* --- Register my character device --- */
1030 if ((e = register_chrdev(UNET_MAJOR, "unet", &unet_fops)) != 0) {
1031 printk(KERN_ERR "unet: can't claim major device %d\n", UNET_MAJOR);
1035 /* --- Make the persistent unet devices --- */
1037 if ((unet_persistent = kmalloc(unet_npersist * sizeof(struct unet),
1038 GFP_KERNEL)) == 0) {
1039 printk(KERN_ERR "unet: can't allocate %i persistent unet blocks",
1045 for (i = 0; i < unet_npersist; i++) {
1046 if ((e = unet_setup(&unet_persistent[i], i)) != 0) {
1047 printk(KERN_ERR "unet: can't create persistent unet %d\n", i);
1051 unet_nif = unet_npersist;
1058 /* --- Some bad stuff happened --- */
1063 unregister_netdev(&unet_persistent[i].nif);
1065 kfree(unet_persistent);
1068 unregister_chrdev(UNET_MAJOR, "unet");
1076 /* --- @init_module@ --- *
1080 * Returns: Zero or error condition.
1082 * Use: Initialises the unet kernel module.
1085 int init_module(void)
1087 if (unet_npersist < 0 || unet_maxif < unet_npersist
1088 #if UNET_DEBUG == UNET_DEBUGRUNTIME
1089 || (unet_debug != 0 && unet_debug != 1)
1093 return (unet_init());
1096 /* --- @cleanup_module@ --- *
1102 * Use: Tidies up the unet module ready for it to be killed.
1105 void cleanup_module(void)
1109 for (i = 0; i < unet_npersist; i++) {
1110 D( printk(KERN_DEBUG "unet: releasing persistent unet %d\n", i); )
1111 unet_kill(&unet_persistent[i]);
1113 kfree(unet_persistent);
1115 unregister_chrdev(UNET_MAJOR, "unet");
1120 /*----- That's all, folks -------------------------------------------------*/