From f15626a998bc86b79b45646ccaf3459abaed866c Mon Sep 17 00:00:00 2001 From: luethje Date: Wed, 23 Jul 1997 20:39:14 +0000 Subject: [PATCH] added the option "force" for the commands delif and reset --- isdnctrl/ctrlconf.c | 13 ++++++---- isdnctrl/isdnctrl.c | 54 ++++++++++++++++++++++++++++++---------- isdnctrl/isdnctrl.h | 13 +++++++--- isdnctrl/isdnctrl.man.in | 18 ++++++++------ lib/Makefile | 1 + 5 files changed, 70 insertions(+), 29 deletions(-) diff --git a/isdnctrl/ctrlconf.c b/isdnctrl/ctrlconf.c index e06fa017..e0576f4b 100644 --- a/isdnctrl/ctrlconf.c +++ b/isdnctrl/ctrlconf.c @@ -1,4 +1,4 @@ -/* $Id: ctrlconf.c,v 1.3 1997/07/22 22:36:08 luethje Exp $ +/* $Id: ctrlconf.c,v 1.4 1997/07/23 20:39:14 luethje Exp $ * * ISDN accounting for isdn4linux. (Utilities) * @@ -19,6 +19,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: ctrlconf.c,v $ + * Revision 1.4 1997/07/23 20:39:14 luethje + * added the option "force" for the commands delif and reset + * * Revision 1.3 1997/07/22 22:36:08 luethje * isdnrep: Use " " for blanks * isdnctrl: Add the option "reset" @@ -91,9 +94,9 @@ static int readinterfaces(int fd, section* CSec, section *PSec) char s[BUFSIZ]; char *p; - if ((iflst = fopen("/proc/net/dev", "r")) == NULL) + if ((iflst = fopen(FILE_PROC, "r")) == NULL) { - perror("/proc/net/dev"); + perror(FILE_PROC); return -1; } @@ -533,9 +536,9 @@ static int interface_exist(int fd, char *name) char *p; - if ((iflst = fopen("/proc/net/dev", "r")) == NULL) + if ((iflst = fopen(FILE_PROC, "r")) == NULL) { - perror("/proc/net/dev"); + perror(FILE_PROC); return -1; } diff --git a/isdnctrl/isdnctrl.c b/isdnctrl/isdnctrl.c index 6c7a31b4..e7937c48 100644 --- a/isdnctrl/isdnctrl.c +++ b/isdnctrl/isdnctrl.c @@ -1,4 +1,4 @@ -/* $Id: isdnctrl.c,v 1.6 1997/07/22 22:36:10 luethje Exp $ +/* $Id: isdnctrl.c,v 1.7 1997/07/23 20:39:15 luethje Exp $ * ISDN driver for Linux. (Control-Utility) * * Copyright 1994,95 by Fritz Elfert (fritz@wuemaus.franken.de) @@ -21,6 +21,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdnctrl.c,v $ + * Revision 1.7 1997/07/23 20:39:15 luethje + * added the option "force" for the commands delif and reset + * * Revision 1.6 1997/07/22 22:36:10 luethje * isdnrep: Use " " for blanks * isdnctrl: Add the option "reset" @@ -94,6 +97,7 @@ #undef ISDN_DEBUG_MODEM_SENDOPT #include +#include #include #include #include @@ -111,6 +115,9 @@ # include "ctrlconf.h" #endif /* I4L_CTRL_CONF */ +#define CMD_IFCONFIG "ifconfig" +#define CMD_OPT_IFCONFIG "down" + char nextlistif[10]; int exec_args(int fd, int argc, char **argv); @@ -123,8 +130,8 @@ void usage(void) fprintf(stderr, "where is one of the following:\n"); fprintf(stderr, "\n"); fprintf(stderr, " addif [name] add net-interface\n"); - fprintf(stderr, " delif name remove net-interface\n"); - fprintf(stderr, " reset remove all net-interfaces\n"); + fprintf(stderr, " delif name [force] remove net-interface\n"); + fprintf(stderr, " reset [force] remove all net-interfaces\n"); fprintf(stderr, " addphone name in|out num add phone-number to interface\n"); fprintf(stderr, " delphone name in|out num remove phone-number from interface\n"); fprintf(stderr, " eaz name [eaz|msn] get/set eaz for interface\n"); @@ -175,18 +182,24 @@ int key2num(char *key, char **keytable, int *numtable) return -1; } -int reset_interfaces(int fd) +int reset_interfaces(int fd, char *option) { FILE *iflst; char *p; char s[255]; char name[255]; - char *argv[3] = {cmds[DELIF].cmd, name, NULL}; + char *argv[4] = {cmds[DELIF].cmd, name, option, NULL}; isdn_net_ioctl_cfg cfg; - if ((iflst = fopen("/proc/net/dev", "r")) == NULL) { - perror("/proc/net/dev"); + if (option != NULL && strcmp(option, "force")) + { + usage(); + return -1; + } + + if ((iflst = fopen(FILE_PROC, "r")) == NULL) { + perror(FILE_PROC); return -1; } @@ -201,7 +214,8 @@ int reset_interfaces(int fd) if (ioctl(fd, IIOCNETGCF, &cfg) < 0) continue; - exec_args(fd, 2, argv); + if (exec_args(fd, 2 + (option?1:0), argv) == -2) + return -1; } } @@ -409,9 +423,9 @@ int exec_args(int fd, int argc, char **argv) } #ifdef I4L_CTRL_CONF - if (id != NULL && i != GETCONF && i != WRITECONF && i != READCONF) { + if (id != NULL && i != RESET && i != GETCONF && i != WRITECONF && i != READCONF) { #else - if (id != NULL && i != GETCONF) { + if (id != NULL && i != RESET && i != GETCONF) { #endif /* I4L_CTRL_CONF */ if (strlen(id) > 8) { fprintf(stderr, "Interface name must not exceed 8 characters!\n"); @@ -457,6 +471,18 @@ int exec_args(int fd, int argc, char **argv) break; case DELIF: + if (args == 2) + if (!strcmp(arg1, "force")) + { + char command[255]; + sprintf(command,"%s %s %s",CMD_IFCONFIG, id, CMD_OPT_IFCONFIG); + + if (system(command)) + return -2; + } + else + usage(); + if ((result = ioctl(fd, IIOCNETDIF, id)) < 0) { perror(id); return -1; @@ -648,8 +674,8 @@ int exec_args(int fd, int argc, char **argv) case LIST: if (!strcmp(id, "all")) { char name[10]; - if ((iflst = fopen("/proc/net/dev", "r")) == NULL) { - perror("/proc/net/dev"); + if ((iflst = fopen(FILE_PROC, "r")) == NULL) { + perror(FILE_PROC); return -1; } while (!feof(iflst)) { @@ -1045,7 +1071,7 @@ int exec_args(int fd, int argc, char **argv) break; case RESET: - reset_interfaces(fd); + reset_interfaces(fd, args?id:NULL); break; #ifdef I4L_CTRL_CONF case WRITECONF: @@ -1074,9 +1100,11 @@ int exec_args(int fd, int argc, char **argv) #endif /* I4L_CTRL_CONF */ } +#if DEBUG if (argc > 1) { printf("args=%d nextcmd %s\n",args, argv[1]); } +#endif /* DEBUG */ } return 0; diff --git a/isdnctrl/isdnctrl.h b/isdnctrl/isdnctrl.h index 50917ce3..55d332b5 100644 --- a/isdnctrl/isdnctrl.h +++ b/isdnctrl/isdnctrl.h @@ -1,4 +1,4 @@ -/* $Id: isdnctrl.h,v 1.3 1997/07/22 22:36:11 luethje Exp $ +/* $Id: isdnctrl.h,v 1.4 1997/07/23 20:39:16 luethje Exp $ * ISDN driver for Linux. (Control-Utility) * * Copyright 1994,95 by Fritz Elfert (fritz@wuemaus.franken.de) @@ -21,6 +21,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdnctrl.h,v $ + * Revision 1.4 1997/07/23 20:39:16 luethje + * added the option "force" for the commands delif and reset + * * Revision 1.3 1997/07/22 22:36:11 luethje * isdnrep: Use " " for blanks * isdnctrl: Add the option "reset" @@ -36,6 +39,10 @@ /*****************************************************************************/ +#define FILE_PROC "/proc/net/dev" + +/*****************************************************************************/ + enum { ADDIF, ADDSLAVE, DELIF, DIAL, BIND, UNBIND, PPPBIND, PPPUNBIND, @@ -65,7 +72,7 @@ cmd_struct cmds[] = { {"addif", "01"}, {"addslave", "2"}, - {"delif", "1"}, + {"delif", "12"}, {"dial", "1"}, {"bind", "123"}, {"unbind", "1"}, @@ -97,7 +104,7 @@ cmd_struct cmds[] = {"removelink", "1"}, {"encap", "12"}, {"trigger", "12"}, - {"reset", "0"}, + {"reset", "01"}, #ifdef I4L_CTRL_CONF {"writeconf", "01"}, {"readconf", "01"}, diff --git a/isdnctrl/isdnctrl.man.in b/isdnctrl/isdnctrl.man.in index 9ee8e0ba..844adb09 100755 --- a/isdnctrl/isdnctrl.man.in +++ b/isdnctrl/isdnctrl.man.in @@ -1,11 +1,14 @@ #!/bin/sh -# $Id: isdnctrl.man.in,v 1.4 1997/07/22 22:36:12 luethje Exp $ +# $Id: isdnctrl.man.in,v 1.5 1997/07/23 20:39:17 luethje Exp $ # # Generator for isdnctrl manpage # (C) 1997 Stefan Luethje # # # $Log: isdnctrl.man.in,v $ +# Revision 1.5 1997/07/23 20:39:17 luethje +# added the option "force" for the commands delif and reset +# # Revision 1.4 1997/07/22 22:36:12 luethje # isdnrep: Use " " for blanks # isdnctrl: Add the option "reset" @@ -47,7 +50,7 @@ BEGIN {printall=1} EOF awk -f $AWKFILE >$MANOUTFILE << EOF -.TH ISDNCTRL 8 "25. June 1997" +.TH ISDNCTRL 8 "23. July 1997" .UC 4 .SH NAME isdnctrl \- get/set ISDN device information @@ -76,14 +79,13 @@ Adds a new ISDN IP-interface "name" to the kernel. If "name" is omitted, the kernel will use "ethX", while X is an increasing number starting from 0. .TP 5 -.B delif name +.B delif name [force] Removes the ISDN IP-interface "name" from the kernel. +The option "force" starts at first for the interface the command "ifconfig down". .TP 5 -.B reset -Removes all ISDN IP-interfaces from the kernel if it possible. -At first all entries for ISDN of the command -.B ifconfig -have to be removed. +.B reset [force] +Removes all ISDN IP-interfaces from the kernel if it is possible. +The option "force" starts at first for each interface the command "ifconfig down". .TP 5 .B addphone name out num Set the phone number(s) of the remote site for the IP-interface diff --git a/lib/Makefile b/lib/Makefile index d863be81..413036b4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -94,6 +94,7 @@ deinstall: distclean libisdn.a: conffile.o isdntools.o libtools.o $(LIB_AREA) $(LIB_AVON) ar rs libisdn.a isdntools.o conffile.o libtools.o $(LIB_AREA) $(LIB_AVON) + ranlib libisdn.a ifeq (.depend,$(wildcard .depend)) include .depend