/* -*-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.
*
/*----- 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).
*
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");
/* --- 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 --- */
if ((e = unet_setup(u, seq)) != 0)
goto tidy_1;
u->f |= UNIF_TRANS;
+ unet_nif++;
/* --- Link the block into the list --- */
D( printk(KERN_DEBUG "unet: opened transient %d\n", seq);
unet_dumpBlock(u); )
- }
+ } else
+ return (-ENODEV);
/* --- Done --- */
/* --- 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 --- */
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" :
#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
/* --- @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;
goto tidy_2;
}
}
+ unet_nif = unet_npersist;
/* --- Done --- */
\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
@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
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
/* -*-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.
*
/*----- 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).
*
{ "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,