From 88613db413040344e358f2749f25a736b9beab9d Mon Sep 17 00:00:00 2001 Message-Id: <88613db413040344e358f2749f25a736b9beab9d.1715480305.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 3 Feb 2001 18:39:59 +0000 Subject: [PATCH] Setting the maximum interface count now does the right thing. Organization: Straylight/Edgeware From: mdw --- unet.c | 61 +++++++++++++++++++++++++++++++++++-------------------- unet.texi | 14 ++++++++++++- unetcfg.c | 8 +++++--- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/unet.c b/unet.c index 09020eb..7fdc317 100644 --- a/unet.c +++ b/unet.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: unet.c,v 1.1 2001/01/25 22:03:39 mdw Exp $ + * $Id: unet.c,v 1.2 2001/02/03 18:39:59 mdw Exp $ * * User-space network device support. * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: unet.c,v $ + * Revision 1.2 2001/02/03 18:39:59 mdw + * Setting the maximum interface count now does the right thing. + * * Revision 1.1 2001/01/25 22:03:39 mdw * Initial check-in (somewhat belated). * @@ -122,6 +125,7 @@ static int unet_npersist = UNET_NPERSIST; static int unet_maxif = UNET_MAXIF; static struct unet *unet_persistent; static struct unet *unet_list = 0; +static int unet_nif = 0; MODULE_PARM(unet_npersist, "i"); MODULE_PARM(unet_maxif, "i"); @@ -519,21 +523,20 @@ static int unet_devopen(struct inode *ino, struct file *f) /* --- Otherwise we've got to create a new one --- */ - else { + else if (seq == UNET_TRANSMINOR) { /* --- Try to find a spare sequence number --- */ + if (unet_nif >= unet_maxif) { + printk(KERN_NOTICE "unet: no interfaces left\n"); + e = -ENFILE; + goto tidy_0; + } for (seq = unet_npersist, up = &unet_list; *up != 0; seq++, up = &(*up)->next) { if ((*up)->seq > seq) break; - if (seq >= unet_maxif) { - printk("unet: all unets are occupied\n"); - e = -ENFILE; - goto tidy_0; - } } - D( printk(KERN_DEBUG "unet: allocated sequence number %d\n", seq); ) /* --- Allocate a new block --- */ @@ -549,6 +552,7 @@ static int unet_devopen(struct inode *ino, struct file *f) if ((e = unet_setup(u, seq)) != 0) goto tidy_1; u->f |= UNIF_TRANS; + unet_nif++; /* --- Link the block into the list --- */ @@ -560,7 +564,8 @@ static int unet_devopen(struct inode *ino, struct file *f) D( printk(KERN_DEBUG "unet: opened transient %d\n", seq); unet_dumpBlock(u); ) - } + } else + return (-ENODEV); /* --- Done --- */ @@ -596,12 +601,14 @@ static int unet_devclose(struct inode *ino, struct file *f) /* --- A transient unet needs to be destroyed --- */ if (u->f & UNIF_TRANS) { + int seq = u->seq; *u->prev = u->next; if (u->next) u->next->prev = u->prev; unet_kill(u); kfree(u); - D( printk(KERN_DEBUG "unet: released transient unet\n"); ) + unet_nif--; + D( printk(KERN_DEBUG "unet: released transient %d\n", seq); ) } /* --- A persistent unet needs to be shutdown --- */ @@ -863,6 +870,8 @@ static int unet_devioctl(struct inode *ino, int n = !!arg; int o = !!(u->f & UNIF_DEBUG); + if (!capable(CAP_SYS_ADMIN)) + return (-EPERM); if (n || o) { printk(KERN_DEBUG "unet: UNIOCSDEBUG on %s: %s\n", u->name, (o && n) ? "debugging still on" : @@ -906,12 +915,16 @@ static int unet_devioctl(struct inode *ino, #if UNET_DEBUG == UNET_DEBUGRUNTIME case UNIOCSGDEBUG: - printk(KERN_DEBUG "unet: UNIOCSGDEBUG: set global debug: %s\n", - (arg && unet_debug) ? "debugging still on" : - (!arg && unet_debug) ? "debugging turned off" : - (arg && !unet_debug) ? "debugging turned on" : - (!arg && !unet_debug) ? "you can't see this message" : - "Logic failure: universe exploding"); + if (!capable(CAP_SYS_ADMIN)) + return (-EPERM); + if (arg || unet_debug) { + printk(KERN_DEBUG "unet: UNIOCSGDEBUG: set global debug: %s\n", + (arg && unet_debug) ? "debugging still on" : + (!arg && unet_debug) ? "debugging turned off" : + (arg && !unet_debug) ? "debugging turned on" : + (!arg && !unet_debug) ? "you can't see this message" : + "Logic failure: universe exploding"); + } unet_debug = !!arg; break; #endif @@ -935,15 +948,18 @@ static int unet_devioctl(struct inode *ino, /* --- @UNIOCSMAXIF@ --- */ case UNIOCSMAXIF: - e = -EINVAL; + if (!capable(CAP_SYS_ADMIN)) + return (-EPERM); + D( printk(KERN_DEBUG "unet: UNIOCSMAXIF: " + "arg = %ld; npersist = %d; nif = %d\n", + arg, unet_npersist, unet_nif); ) if (arg < unet_npersist || arg > INT_MAX) return (-EINVAL); - for (u = unet_list; u; u = u->next) { - if (u->seq >= unet_npersist) - return (-EBUSY); - } + if (arg < unet_nif) + return (-EBUSY); unet_maxif = arg; - D( printk(KERN_DEBUG "unet: UNIOCSMAXIF: unet_maxif = %d\n", + e = 0; + D( printk(KERN_DEBUG "unet: UNIOCSMAXIF: set unet_maxif = %d\n", unet_maxif); ) break; @@ -1016,6 +1032,7 @@ __initfunc(int unet_init(void)) goto tidy_2; } } + unet_nif = unet_npersist; /* --- Done --- */ diff --git a/unet.texi b/unet.texi index 4dd7338..8ffff55 100644 --- a/unet.texi +++ b/unet.texi @@ -1,6 +1,6 @@ \input texinfo @c -*-texinfo-*- @c -@c $Id: unet.texi,v 1.1 2001/01/25 22:03:39 mdw Exp $ +@c $Id: unet.texi,v 1.2 2001/02/03 18:39:59 mdw Exp $ @c @c Manual for usernet device @c @@ -10,6 +10,9 @@ @c ----- Revision history --------------------------------------------------- @c @c $Log: unet.texi,v $ +@c Revision 1.2 2001/02/03 18:39:59 mdw +@c Setting the maximum interface count now does the right thing. +@c @c Revision 1.1 2001/01/25 22:03:39 mdw @c Initial check-in (somewhat belated). @c @@ -615,6 +618,15 @@ is set; if zero, the flag is cleared. Dumps an attachment's information to the kernel log device. @end deffn +@deffn {@code{ioctl} call} UNIOCGMAXIF +Returns the total number of attachments permitted. +@end deffn + +@deffn {@code{ioctl} call} UNIOCSMAXIF +Configures the total number of attachments permitted. It is an error to +reduce this below the number of attachments currently in existence. +@end deffn + @node Sending and receiving, , Configuring the interface, Programming @section Sending and receiving diff --git a/unetcfg.c b/unetcfg.c index dec5a9a..4b98e0e 100644 --- a/unetcfg.c +++ b/unetcfg.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: unetcfg.c,v 1.1 2001/01/25 22:03:39 mdw Exp $ + * $Id: unetcfg.c,v 1.2 2001/02/03 18:39:59 mdw Exp $ * * User-space network device support. * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: unetcfg.c,v $ + * Revision 1.2 2001/02/03 18:39:59 mdw + * Setting the maximum interface count now does the right thing. + * * Revision 1.1 2001/01/25 22:03:39 mdw * Initial check-in (somewhat belated). * @@ -607,8 +610,7 @@ attachments inherit their debug flags from the global flag.\n\ { "maxif", 0, cmd_maxif, "maxif [MAX]", "set maximum number of interfaces allowed", "\ -Configures the maximum number of interfaces allowed (actually, the highest\n\ -number of any interface).\n\ +Configures the maximum number of interfaces allowed.\n\ " }, { "help", 0, cmd_help, -- [mdw]