Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Aug 1996 07:26:06 -0400 (EDT)
From:      Andrew Webster <andrew@fortress.org>
To:        J Wunsch <j@uriah.heep.sax.de>
Cc:        FreeBSD hackers <freebsd-hackers@freebsd.org>
Subject:   Re: minor patch to ppp's route.c
Message-ID:  <Pine.BSF.3.91.960805072150.19849S-100000@guardian.fortress.org>
In-Reply-To: <199608022038.WAA24508@uriah.heep.sax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2 Aug 1996, J Wunsch wrote:

> As Joe Greco wrote:
> 
> > >   struct ifreq reqbuf[32];
> > > 
> > > and change 32 to something higher (at ~2 per interface, this runs out of 
> > > steam at about 15 interfaces).
> > 
> > I believe I posted a suggestion once to raise this to something like 1024
> > :-)  which I had done on several boxes.
> 
> Make it dynamic and i'll integrate it in less than an hour. :)


I made this change, along with a similar one to ifconfig quite a while 
ago.  Here are 2 patches to ppp.  One to route.c for a dynamic reqbuf, 
and the other to fix the inherent limit of 10 ppp interfaces.  There is 
probably a better way to set the maximum number of tun interfaces, I 
haven't figured it out yet.

--- cut here --- start of route.c.diff ---
*** route.c.orig	Mon Jun  3 22:44:34 1996
--- route.c	Mon Jun  3 22:56:58 1996
***************
*** 350,363 ****
--- 350,369 ----
    free(sp);
  }
  
+ 
+ /*
+  * 960603 - Modified to use dynamic buffer allocator as in ifconfig
+  */
  int
  GetIfIndex(name)
  char *name;
  {
+   char *buffer;
    struct ifreq *ifrp;
    int s, len, elen, index;
    struct ifconf ifconfs;
    struct ifreq reqbuf[256];
+   int oldbufsize, bufsize = sizeof(struct ifreq);
  
    s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s < 0) {
***************
*** 365,376 ****
      return(-1);
    }
  
!   ifconfs.ifc_len = sizeof(reqbuf);
!   ifconfs.ifc_buf = (caddr_t)reqbuf;
!   if (ioctl(s, SIOCGIFCONF, &ifconfs) < 0) {
!     perror("IFCONF");
!     return(-1);
!   }
  
    ifrp = ifconfs.ifc_req;
  
--- 371,397 ----
      return(-1);
    }
  
!   buffer = malloc(bufsize);	/* allocate first buffer */
!   ifconfs.ifc_len = bufsize;	/* Initial setting */
!   /*
!    * Iterate through here until we don't get many more data 
!    */
! 
!   do {
! 	oldbufsize = ifconfs.ifc_len;
! 	bufsize += 1+sizeof(struct ifreq);
! 	buffer = realloc((void *)buffer, bufsize);	/* Make it bigger */
! #ifdef DEBUG
! 	logprintf ("Growing buffer to %d\n", bufsize);
! #endif
! 	ifconfs.ifc_len = bufsize;
! 	ifconfs.ifc_buf = buffer;
!   	if (ioctl(s, SIOCGIFCONF, &ifconfs) < 0) {
! 	    perror("IFCONF");
! 	    free(buffer);
! 	    return(-1);
! 	}
!   } while (ifconfs.ifc_len > oldbufsize);
  
    ifrp = ifconfs.ifc_req;
  
***************
*** 384,389 ****
--- 405,411 ----
  #endif
        if (strcmp(ifrp->ifr_name, name) == 0) {
          IfIndex = index;
+ 	free(buffer);
          return(index);
        }
        index++;
***************
*** 395,399 ****
--- 417,422 ----
    }
  
    close(s);
+   free(buffer);
    return(-1);
  }
--- cut here --- end of route.c.diff ---


--- cut here --- start of os.c.diff ---
*** os.c	Mon May 29 23:50:52 1995
--- /usr/local/src/OS/RELEASE-2.0.5/usr.sbin/ppp/os.c	Tue Dec 26 12:28:02 1995
***************
*** 253,273 ****
  OpenTunnel(ptun)
  int *ptun;
  {
    int s;
!   char *cp;
!   char *suffix = "0123456789";
    char ifname[IFNAMSIZ];
!   char devname[12];
  
!   strcpy(devname, "/dev/tun0");
!   for (cp = suffix; *cp; cp++) {
!     devname[8] = *cp;
      tun_out = open(devname, O_RDWR);
      if (tun_out >= 0)
        break;
    }
!   *ptun = cp - suffix;
!   if (*cp == '\0') {
      fprintf(stderr, "No tunnel device is available.\n");
      return(-1);
    }
--- 253,272 ----
  OpenTunnel(ptun)
  int *ptun;
  {
+ #define MAXTUNDEV 16
    int s;
!   int cp;
    char ifname[IFNAMSIZ];
!   char devname[16];
  
!   for (cp = 0; cp < MAXTUNDEV; ++ cp) {
!     sprintf(devname, "/dev/tun%d", cp);
      tun_out = open(devname, O_RDWR);
      if (tun_out >= 0)
        break;
    }
!   *ptun = cp;
!   if (cp >= MAXTUNDEV) {
      fprintf(stderr, "No tunnel device is available.\n");
      return(-1);
    }
--- cut here --- end of os.c.diff ---



Andrew Webster  - andrew@pubnix.net - http://www.pubnix.net
PubNIX Montreal - Connected to the world - Branche au monde
 514-990-5911   - P.O. Box 147, Cote St-Luc, Quebec, H4V 2Y3




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.960805072150.19849S-100000>