From dburr@donaldburr.dyn.ml.org  Sun Aug 10 03:45:10 1997
Received: from DonaldBurr.DonaldBurr.dyn.ml.org (ppp6229.la.inreach.net [199.107.160.229])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id DAA15852
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 10 Aug 1997 03:45:09 -0700 (PDT)
Received: (from dburr@localhost)
	by DonaldBurr.DonaldBurr.dyn.ml.org (8.8.5/8.8.5) id DAA07208;
	Sun, 10 Aug 1997 03:45:16 -0700 (PDT)
Message-Id: <199708101045.DAA07208@DonaldBurr.DonaldBurr.dyn.ml.org>
Date: Sun, 10 Aug 1997 03:45:16 -0700 (PDT)
From: Donald Burr <dburr@donaldburr.dyn.ml.org>
Reply-To: dburr@POBoxes.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: iijppp handles multiple phone numbers and redials in a weird manner
X-Send-Pr-Version: 3.2

>Number:         4262
>Category:       bin
>Synopsis:       iijppp handles multiple phone numbers and redials in a weird manner
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    brian
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 10 03:50:00 PDT 1997
>Closed-Date:    Sun Aug 17 13:39:05 PDT 1997
>Last-Modified:  Sun Aug 17 13:40:32 PDT 1997
>Originator:     Donald Burr
>Release:        FreeBSD 2.2.2-RELEASE i386
>Organization:
Starfleet Command
>Environment:

Stock 2.2.2-RELEASE system

>Description:

My ISP just installed some X2 (56k modem technology from USRobotics) lines
in our area.  Sicne I have an X2 modem, I naturally want to take
advantage of these lines.  But at this time they only have a limited
amount of lines, and so, sometimes I run into busy signals.  If I get a
busy signal on the X2 lines, I would like to have iijppp fall back onto
the 33.6 modem pool (which has jillions of modems on it, and I very
rarely, if ever, get a busy signal).  So, I set up my ppp.conf file with
multiple phone numbers (example below):

default:
 set device /dev/modem
 set speed 115200
 disable lqr
 deny lqr
 set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \"\" ATZ0 OK-AT-OK \\dATM1DT\\T TIMEOUT 120 CONNECT"
#enable this line for lots of debugging output
#set debug phase chat connect carrier lqm lcp link tcp/ip hdlc async

myisp:
 set phone 5551212:5551213
 set redial 5.5 0
 set login "TIMEOUT 5 ogin:-\\r-ogin: YEAH_RIGHT word: YEAH_RIGHT"
...

Initially, this seems to work great.  When establishing a PPP connection,
it first tries "555-1212" (the X2 modems).  If the line is busy or for
whatever other reason, it fails to connect, it falls back on the non-X2
modem pool (555-1213).

But here's the problem!  Let's say, that I successfully connect to the X2
modems (555-1212).  I use the net for a while, then I let the PPP
connection idle.  The next time I use the net, it dials "555-1213" (the
*non-X2* modem pool!!

You can see the problem clearer when you have more than 2 numbers in the
dial line.  For example:

set phone 5551212:5551213:5551214:5551215

The first invocation of PPP dials 5551212 as it should.  Let's say it
connects, then you let the PPP go idle.  Next dial it uses 5551213. Again,
let's say it connects, you use PPP for awhile, and let the connection go
idle.  Then, the next time it dials 5551214... and so on.

IMHO the proper behavior should be that, whenever a successful connect is
registered, PPP should start at the beginning of the dial list for the
next number, instead of going on to the next number in the list, which 
should only happen if the previous number were busy or otherwise
unreachable.

>How-To-Repeat:

	Set up an iijppp link with two or more phone numbers, create a
	situation that would require a redial (make one of the phone
	numbers point to a busy/nonexistent line, etc.), sit back, and
	watch the fun.

>Fix:
	
	none that I can think of
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->brian 
Responsible-Changed-By: brian 
Responsible-Changed-When: Wed Aug 13 17:51:46 PDT 1997 
Responsible-Changed-Why:  
I'll sort ppp out so that you can get this behaviour as 
well as the previous behaviour. 

From: Brian Somers <brian@awfulhak.org>
To: dburr@POBoxes.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/4262: iijppp handles multiple phone numbers and redials in a weird manner 
Date: Thu, 14 Aug 1997 01:50:12 +0100

 > >Synopsis:       iijppp handles multiple phone numbers and redials in a weird manner
 
 Can you try this patch?  Use the pipe (|) sign to seperate numbers 
 that should be used only if the login script fails.
 
 Let me know if it works ok and I'll commit the changes.  The patch 
 should be applied to the 970803 ppp sources found on
 
   http://www.freebsd.org/~brian
 
 Cheers.
 -- 
 Brian <brian@awfulhak.org>, <brian@freebsd.org>
       <http://www.awfulhak.org>
 Don't _EVER_ lose your sense of humour....
 
 Index: modem.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/ppp/modem.c,v
 retrieving revision 1.46
 diff -c -r1.46 modem.c
 *** modem.c	1997/07/24 02:42:34	1.46
 --- modem.c	1997/08/14 00:24:57
 ***************
 *** 726,731 ****
 --- 726,732 ----
     strncpy(ScriptBuffer, VarDialScript,sizeof(ScriptBuffer)-1);
     ScriptBuffer[sizeof(ScriptBuffer)-1] = '\0';
     if ((excode = DoChat(ScriptBuffer)) > 0) {
 +     VarAltPhone = NULL;
       if (VarTerm)
         fprintf(VarTerm, "dial OK!\n");
       strncpy(ScriptBuffer, VarLoginScript,sizeof(ScriptBuffer)-1);
 Index: chat.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/ppp/chat.c,v
 retrieving revision 1.29
 diff -c -r1.29 chat.c
 *** chat.c	1997/07/14 01:41:24	1.29
 --- chat.c	1997/08/14 00:19:23
 ***************
 *** 164,174 ****
   	result += strlen(result);
   	break;
         case 'T':
 ! 	if (VarNextPhone == NULL) {
 ! 	  strcpy(VarPhoneCopy, VarPhoneList);
 ! 	  VarNextPhone = VarPhoneCopy;
   	}
 ! 	phone = strsep(&VarNextPhone, ":");
   	strncpy(result, phone, reslen);
   	reslen -= strlen(result);
   	result += strlen(result);
 --- 164,177 ----
   	result += strlen(result);
   	break;
         case 'T':
 ! 	if (VarAltPhone == NULL) {
 ! 	  if (VarNextPhone == NULL) {
 ! 	    strcpy(VarPhoneCopy, VarPhoneList);
 ! 	    VarNextPhone = VarPhoneCopy;
 ! 	  }
 ! 	  VarAltPhone = strsep(&VarNextPhone, ":");
   	}
 ! 	phone = strsep(&VarAltPhone, "|");
   	strncpy(result, phone, reslen);
   	reslen -= strlen(result);
   	result += strlen(result);
 Index: vars.h
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/ppp/vars.h,v
 retrieving revision 1.20
 diff -c -r1.20 vars.h
 *** vars.h	1997/07/14 01:41:35	1.20
 --- vars.h	1997/08/14 00:22:09
 ***************
 *** 84,89 ****
 --- 85,91 ----
     char   phone_numbers[200];    /* Telephone Numbers */
     char   phone_copy[200];       /* copy for strsep() */
     char   *next_phone;           /* Next phone from the list */
 +   char   *alt_phone;           /* Next phone from the list */
     char   shostname[MAXHOSTNAMELEN];/* Local short Host Name */
     char hangup_script[200];      /* Hangup script before modem is closed */
     struct aliasHandlers handler; /* Alias function pointers */
 ***************
 *** 110,115 ****
 --- 112,118 ----
   #define VarPhoneList    pppVars.phone_numbers
   #define VarPhoneCopy    pppVars.phone_copy
   #define VarNextPhone    pppVars.next_phone
 + #define VarAltPhone    pppVars.alt_phone
   #define	VarShortHost	pppVars.shostname
   #define VarReconnectTimer pppVars.reconnect_timer
   #define VarReconnectTries pppVars.reconnect_tries
 Index: ppp.8
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/ppp/ppp.8,v
 retrieving revision 1.46
 diff -c -r1.46 ppp.8
 *** ppp.8	1997/08/10 22:03:20	1.46
 --- ppp.8	1997/08/14 00:44:34
 ***************
 *** 1013,1027 ****
   Describe your provider's phone number(s) in the dial script using the
   .Dq set phone
   command.  This command allows you to set multiple phone numbers for
 ! dialing and redialing separated by a colon (:).  For example:
   .Bd -literal -offset indent
 ! set phone "1234567:2345678"
   .Ed
   .Pp
 ! Here, the first number is attempted.  If the connection fails, the second
 ! number is attempted after the next number redial period.  If the second number
 ! also fails, the first is tried again after the redial period has expired.
 ! The selected phone number is substituted for the \\T string in the
   .Dq set dial
   command (see below).
   
 --- 1013,1041 ----
   Describe your provider's phone number(s) in the dial script using the
   .Dq set phone
   command.  This command allows you to set multiple phone numbers for
 ! dialing and redialing separated by either a pipe (|) or a colon (:)
 ! .Bd -literal -offset indent
 ! set phone "111[|222]...[:333[|444]...]...
 ! .Ed
 ! Numbers after the first in a pipe-seperated list are only used if the
 ! previous number was used in a failed login script.  Numbers seperated
 ! by a colon are used sequentially, irrespective of what happened as a
 ! result of using the previous number.  For example:
   .Bd -literal -offset indent
 ! set phone "1234567|2345678:3456789|4567890"
   .Ed
   .Pp
 ! Here, the 1234567 number is attempted.  If the login script fails, the
 ! 2345678 number is used next time, but *only* if the login script fails.
 ! On the dial after this, the 3456789 number is used.  The 4567890 number
 ! is only used if the login script using the 3456789 fails.  If the login
 ! script of the 2345678 number fails, the next number is still the 3456789
 ! number.  As many pipes and colons can be used as are necessary.
 ! The next number redial timeout is used between all numbers.  When the
 ! end of the list is reached, the normal redial period is used before
 ! starting at the beginning again.
 ! 
 ! The selected phone number is substituted for the \\\\T string in the
   .Dq set dial
   command (see below).
   
 ***************
 *** 1612,1621 ****
   .It set parity odd|even|none|mark
   This allows the line parity to be set.  The default value is none.
   
 ! .It set phone telno[:telno]...
   This allows the specification of the phone number to be used in
   place of the \\\\T string in the dial and login chat scripts.
 ! Multiple phone numbers may be given seperated by a colon (:).
   If multiple numbers are given,
   .Nm
   will dial them in rotation until a connection is made, retrying
 --- 1626,1638 ----
   .It set parity odd|even|none|mark
   This allows the line parity to be set.  The default value is none.
   
 ! .It set phone telno[|telno]...[:telno[|telno]...]...
   This allows the specification of the phone number to be used in
   place of the \\\\T string in the dial and login chat scripts.
 ! Multiple phone numbers may be given seperated by a colon (:) or
 ! a pipe (|).  Numbers after the pipe are only dialed if the login script
 ! for the previous number failed.  Numbers seperated by a colon are tried
 ! sequentially, irrespective of the reason the line was dropped.
   If multiple numbers are given,
   .Nm
   will dial them in rotation until a connection is made, retrying
 
 
State-Changed-From-To: open->closed 
State-Changed-By: brian 
State-Changed-When: Sun Aug 17 13:39:05 PDT 1997 
State-Changed-Why:  
Changes submitted to -current.  You can now use ``|'' 
(rather than ``:'') for this effect. 
>Unformatted:
