Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/isdn/isdnd Fix a stupid bug when setting authentica...



details:   https://anonhg.NetBSD.org/src/rev/13e0960323c2
branches:  trunk
changeset: 525409:13e0960323c2
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Apr 10 23:35:07 2002 +0000

description:
Fix a stupid bug when setting authentication for multiple PPP interfaces.

Add some magic to UP/DOWN interface using ISDN on startup/exit and a
configuration entry (autoupdown=yes/no) to prevent this.

diffstat:

 usr.sbin/isdn/isdnd/isdnd.h     |    7 +-
 usr.sbin/isdn/isdnd/isdnd.rc.5  |   21 +++++-
 usr.sbin/isdn/isdnd/rc_config.c |  147 ++++++++++++++++++++++++++++-----------
 usr.sbin/isdn/isdnd/rc_parse.y  |    8 +-
 usr.sbin/isdn/isdnd/rc_scan.l   |    3 +-
 usr.sbin/isdn/isdnd/support.c   |   21 +++++-
 6 files changed, 158 insertions(+), 49 deletions(-)

diffs (truncated from 411 to 300 lines):

diff -r 36b3d098d256 -r 13e0960323c2 usr.sbin/isdn/isdnd/isdnd.h
--- a/usr.sbin/isdn/isdnd/isdnd.h       Wed Apr 10 22:35:17 2002 +0000
+++ b/usr.sbin/isdn/isdnd/isdnd.h       Wed Apr 10 23:35:07 2002 +0000
@@ -27,7 +27,7 @@
  *     i4b daemon - main header file
  *     -----------------------------
  *
- *     $Id: isdnd.h,v 1.7 2002/03/30 07:12:41 martin Exp $ 
+ *     $Id: isdnd.h,v 1.8 2002/04/10 23:35:07 martin Exp $ 
  *
  * $FreeBSD$
  *
@@ -350,6 +350,11 @@
 #define DIR_INONLY     1
 #define DIR_OUTONLY    2
 
+       int     autoupdown;             /* do we handle interface up/down? */
+#define        AUTOUPDOWN_NO   0
+#define        AUTOUPDOWN_YES  1
+#define        AUTOUPDOWN_DONE 2
+
        int     budget_callbackperiod;  /* length of a budget period (s)*/
        int     budget_callbackncalls;  /* call budget for a period     */
        char    *budget_callbacks_file; /* filename to store callback stats */
diff -r 36b3d098d256 -r 13e0960323c2 usr.sbin/isdn/isdnd/isdnd.rc.5
--- a/usr.sbin/isdn/isdnd/isdnd.rc.5    Wed Apr 10 22:35:17 2002 +0000
+++ b/usr.sbin/isdn/isdnd/isdnd.rc.5    Wed Apr 10 23:35:07 2002 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: isdnd.rc.5,v 1.6 2002/02/08 01:38:49 ross Exp $
+.\" $NetBSD: isdnd.rc.5,v 1.7 2002/04/10 23:35:07 martin Exp $
 .\"
 .\" Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
 .\"
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"    $Id: isdnd.rc.5,v 1.6 2002/02/08 01:38:49 ross Exp $
+.\"    $Id: isdnd.rc.5,v 1.7 2002/04/10 23:35:07 martin Exp $
 .\"
 .\" $FreeBSD$
 .\"
@@ -295,6 +295,23 @@
 the answering machine starts to run. The minimum value for the alert parameter
 is 5 seconds and the maximum parameter allowed is 180 seconds.
 (optional)
+.It Li autoupdown
+For network interfaces using ISDN as a transport medium it does not make
+sense to mark the interfaces UP before running
+.Nm isdnd .
+Typicaly this interfaces are configured, but marked down, in the respective
+.Pa ifconfig.*
+file. When starting,
+.Nm isdnd
+recognizes this interfaces (configured with some address, marked down, and
+having a matching config entry) and marks them up. On shutdown,
+.Nm isdnd
+marks all interfaces changed at startup DOWN again.
+.Pp
+In rare circumstances you might not want this automatic handling. 
+In this cases add a
+.Em autoupdown=no
+line to the config file entry.
 .It Li b1protocol
 The B channel layer 1 protocol used for this connection. The keyword is mandatory.
 The currently configurable values are:
diff -r 36b3d098d256 -r 13e0960323c2 usr.sbin/isdn/isdnd/rc_config.c
--- a/usr.sbin/isdn/isdnd/rc_config.c   Wed Apr 10 22:35:17 2002 +0000
+++ b/usr.sbin/isdn/isdnd/rc_config.c   Wed Apr 10 23:35:07 2002 +0000
@@ -27,7 +27,7 @@
  *     i4b daemon - config file processing
  *     -----------------------------------
  *
- *     $Id: rc_config.c,v 1.11 2002/04/05 15:26:59 martin Exp $ 
+ *     $Id: rc_config.c,v 1.12 2002/04/10 23:35:07 martin Exp $ 
  *
  * $FreeBSD$
  *
@@ -42,6 +42,7 @@
 
 #include <sys/callout.h>
 #include <sys/ioctl.h>
+#include <ifaddrs.h>
 
 #include "isdnd.h"
 #include "rc_parse.h"
@@ -60,7 +61,8 @@
 static void parse_valid(char *dt);
 static int lookup_l4_driver(const char *name);
 void init_currrent_cfg_state(void);
-static void set_isppp_auth(void);
+static void set_isppp_auth(struct cfg_entry*);
+static void set_autoupdown(struct cfg_entry*);
 void flush_config(void);
 
 static int nregexpr = 0;
@@ -82,7 +84,6 @@
 
        if(reread)
        {
-               remove_all_cfg_entries();
                reset_scanner(yyin);
        }
        
@@ -158,6 +159,7 @@
        current_cfe->cdid = CDID_UNUSED;
        current_cfe->state = ST_IDLE;
        current_cfe->aoc_valid = AOC_INVALID;
+       current_cfe->autoupdown = AUTOUPDOWN_YES;
 }
 
 /*---------------------------------------------------------------------------*
@@ -196,29 +198,77 @@
 }
 
 static void
-set_isppp_auth()
+set_autoupdown(struct cfg_entry *cep)
+{
+        struct ifaddrs *res = NULL, *p;
+       struct ifreq ifr;
+       int r, s, cnt, in6;
+
+       s = socket(AF_INET, SOCK_DGRAM, 0);
+       memset(&ifr, 0, sizeof ifr);
+       snprintf(ifr.ifr_name, sizeof ifr.ifr_name, "%s%d", cep->usrdevicename, cep->usrdeviceunit);
+       r = ioctl(s, SIOCGIFFLAGS, &ifr);
+
+       /*
+        * See if this interface has got any valid addresses - if not,
+        * leave it alone.
+        */
+       if (r >= 0 && !(ifr.ifr_flags & IFF_UP)) {
+               cnt = in6 = 0;
+               if (getifaddrs(&res) == 0) {
+                       for (p = res; p; p = p->ifa_next) {
+                               if (p->ifa_addr == NULL)
+                                       continue;
+                               if (p->ifa_addr->sa_family == AF_LINK)
+                                       continue;
+                               if (strcmp(p->ifa_name, ifr.ifr_name) != 0)
+                                       continue;
+                               if (p->ifa_addr->sa_family == AF_INET6)
+                                       in6 = 1;
+                               cnt++;
+                       }
+                       freeifaddrs(res);
+               }
+
+               if (in6)
+                       cnt--;  /* XXX - heuristic to adjust for INET6 local scope */
+
+               /* Ok, we have some addres - so UP the interface */
+               if (cnt > 0) {
+                       ifr.ifr_flags |= IFF_UP;
+                       r = ioctl(s, SIOCSIFFLAGS, &ifr);
+                       if (r >= 0)
+                               cep->autoupdown |= AUTOUPDOWN_DONE;
+               }
+       }
+
+       close(s);
+}
+
+static void
+set_isppp_auth(struct cfg_entry *cep)
 {
        struct spppauthcfg spcfg;
        int s;
        int doioctl = 0;
 
-       if(current_cfe->ppp_expect_auth == AUTH_UNDEF 
-          && current_cfe->ppp_send_auth == AUTH_UNDEF)
+       if(cep->ppp_expect_auth == AUTH_UNDEF 
+          && cep->ppp_send_auth == AUTH_UNDEF)
                return;
 
-       if(current_cfe->ppp_expect_auth == AUTH_NONE 
-          || current_cfe->ppp_send_auth == AUTH_NONE)
+       if(cep->ppp_expect_auth == AUTH_NONE 
+          || cep->ppp_send_auth == AUTH_NONE)
                doioctl = 1;
 
-       if ((current_cfe->ppp_expect_auth == AUTH_CHAP 
-            || current_cfe->ppp_expect_auth == AUTH_PAP)
-           && current_cfe->ppp_expect_name != NULL
-           && current_cfe->ppp_expect_password != NULL)
+       if ((cep->ppp_expect_auth == AUTH_CHAP 
+            || cep->ppp_expect_auth == AUTH_PAP)
+           && cep->ppp_expect_name != NULL
+           && cep->ppp_expect_password != NULL)
                doioctl = 1;
 
-       if ((current_cfe->ppp_send_auth == AUTH_CHAP || current_cfe->ppp_send_auth == AUTH_PAP)
-                       && current_cfe->ppp_send_name != NULL
-                       && current_cfe->ppp_send_password != NULL)
+       if ((cep->ppp_send_auth == AUTH_CHAP || cep->ppp_send_auth == AUTH_PAP)
+                       && cep->ppp_send_name != NULL
+                       && cep->ppp_send_password != NULL)
                doioctl = 1;
 
        if(!doioctl)
@@ -226,7 +276,7 @@
 
        memset(&spcfg, 0, sizeof spcfg);
        snprintf(spcfg.ifname, sizeof(spcfg.ifname), "%s%d",
-               current_cfe->usrdevicename, current_cfe->usrdeviceunit);
+               cep->usrdevicename, cep->usrdeviceunit);
 
        /* use a random AF to create the socket */
        if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
@@ -241,47 +291,47 @@
                config_error_flag++;
                return;
        }
-       if (current_cfe->ppp_expect_auth != AUTH_UNDEF)
+       if (cep->ppp_expect_auth != AUTH_UNDEF)
        {
-               if(current_cfe->ppp_expect_auth == AUTH_NONE)
+               if(cep->ppp_expect_auth == AUTH_NONE)
                {
                        spcfg.hisauth = SPPP_AUTHPROTO_NONE;
                }
-               else if ((current_cfe->ppp_expect_auth == AUTH_CHAP 
-                         || current_cfe->ppp_expect_auth == AUTH_PAP)
-                        && current_cfe->ppp_expect_name != NULL
-                        && current_cfe->ppp_expect_password != NULL)
+               else if ((cep->ppp_expect_auth == AUTH_CHAP 
+                         || cep->ppp_expect_auth == AUTH_PAP)
+                        && cep->ppp_expect_name != NULL
+                        && cep->ppp_expect_password != NULL)
                {
-                       spcfg.hisauth = current_cfe->ppp_expect_auth == AUTH_PAP ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP;
-                       spcfg.hisname = current_cfe->ppp_expect_name;
-                       spcfg.hisname_length = strlen(current_cfe->ppp_expect_name)+1;
-                       spcfg.hissecret = current_cfe->ppp_expect_password;
-                       spcfg.hissecret_length = strlen(current_cfe->ppp_expect_password)+1;
+                       spcfg.hisauth = cep->ppp_expect_auth == AUTH_PAP ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP;
+                       spcfg.hisname = cep->ppp_expect_name;
+                       spcfg.hisname_length = strlen(cep->ppp_expect_name)+1;
+                       spcfg.hissecret = cep->ppp_expect_password;
+                       spcfg.hissecret_length = strlen(cep->ppp_expect_password)+1;
                }
        }
-       if (current_cfe->ppp_send_auth != AUTH_UNDEF)
+       if (cep->ppp_send_auth != AUTH_UNDEF)
        {
-               if(current_cfe->ppp_send_auth == AUTH_NONE)
+               if(cep->ppp_send_auth == AUTH_NONE)
                {
                        spcfg.myauth = SPPP_AUTHPROTO_NONE;
                }
-               else if ((current_cfe->ppp_send_auth == AUTH_CHAP 
-                         || current_cfe->ppp_send_auth == AUTH_PAP)
-                        && current_cfe->ppp_send_name != NULL
-                        && current_cfe->ppp_send_password != NULL)
+               else if ((cep->ppp_send_auth == AUTH_CHAP 
+                         || cep->ppp_send_auth == AUTH_PAP)
+                        && cep->ppp_send_name != NULL
+                        && cep->ppp_send_password != NULL)
                {
-                       spcfg.myauth = current_cfe->ppp_send_auth == AUTH_PAP ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP;
-                       spcfg.myname = current_cfe->ppp_send_name;
-                       spcfg.myname_length = strlen(current_cfe->ppp_send_name)+1;
-                       spcfg.mysecret = current_cfe->ppp_send_password;
-                       spcfg.mysecret_length = strlen(current_cfe->ppp_send_password)+1;
+                       spcfg.myauth = cep->ppp_send_auth == AUTH_PAP ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP;
+                       spcfg.myname = cep->ppp_send_name;
+                       spcfg.myname_length = strlen(cep->ppp_send_name)+1;
+                       spcfg.mysecret = cep->ppp_send_password;
+                       spcfg.mysecret_length = strlen(cep->ppp_send_password)+1;
 
-                       if(current_cfe->ppp_auth_flags & AUTH_REQUIRED)
+                       if(cep->ppp_auth_flags & AUTH_REQUIRED)
                                spcfg.hisauthflags &= ~SPPP_AUTHFLAG_NOCALLOUT;
                        else
                                spcfg.hisauthflags |= SPPP_AUTHFLAG_NOCALLOUT;
 
-                       if(current_cfe->ppp_auth_flags & AUTH_RECHALLENGE)
+                       if(cep->ppp_auth_flags & AUTH_RECHALLENGE)
                                spcfg.hisauthflags &= ~SPPP_AUTHFLAG_NORECHALLENGE;
                        else
                                spcfg.hisauthflags |= SPPP_AUTHFLAG_NORECHALLENGE;
@@ -389,6 +439,11 @@
                        current_cfe->budget_calloutncalls = yylval.num;
                        break;
 
+               case AUTOUPDOWN:
+                       current_cfe->autoupdown = yylval.booln;
+                       DBGL(DL_RCCF, (log(LL_DBG, "entry %s: autoupdown = %d", current_cfe->name, yylval.booln)));
+                       break;
+
                case BUDGETCALLBACKSFILEROTATE:
                        current_cfe->budget_callbacksfile_rotate = yylval.booln;
                        DBGL(DL_RCCF, (log(LL_DBG, "entry %s: budget-callbacksfile-rotate = %d", current_cfe->name, yylval.booln)));
@@ -1233,7 +1288,14 @@
 
                if(cep->ppp_expect_auth != AUTH_UNDEF 
                   || cep->ppp_send_auth != AUTH_UNDEF)
-                       set_isppp_auth();



Home | Main Index | Thread Index | Old Index