Subject: bin/4145: pppd unable to change interface addr when demand dialing w/unspecified local addr
To: None <gnats-bugs@gnats.netbsd.org>
From: Dave Huang <khym@bga.com>
List: netbsd-bugs
Date: 09/23/1997 15:25:08
>Number:         4145
>Category:       bin
>Synopsis:       pppd unable to change interface addr when demand dialing w/unspecified local addr
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 23 13:35:00 1997
>Last-Modified:
>Originator:     Dave Huang
>Organization:
Name: Dave Huang     |   Mammal, mammal / their names are called /
INet: khym@bga.com   |   they raise a paw / the bat, the cat /
FurryMUCK: Dahan     |   dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 21 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Release:        NetBSD-current as of September 23, 1997
>Environment:
	
System: NetBSD dahan.metonymy.com 1.2G NetBSD 1.2G (SPIFF) #127: Mon Sep 22 15:16:56 CDT 1997 khym@dahan.metonymy.com:/usr/src.local/sys/arch/i386/compile/SPIFF i386


>Description:
If when demand-dialing (with pppd's "demand" option), only the remote
IP address is specified and not the local one, pppd is unable to
change the ppp interface's address to the correct one when IPCP comes
up:

Sep 22 21:19:19 sloth pppd[242]: pppd 2.3.0b5 started by khym, uid 0
Sep 22 21:19:19 sloth pppd[242]: Using interface ppp1
Sep 22 21:19:19 sloth pppd[242]: local  IP address 10.1.1.67
Sep 22 21:19:19 sloth pppd[242]: remote IP address 130.210.252.254
Sep 22 21:19:51 sloth pppd[242]: Starting link
Sep 22 21:20:11 sloth pppd[242]: Serial connection established.
Sep 22 21:20:12 sloth pppd[242]: Connect: ppp1 <--> /dev/tty05
Sep 22 21:20:16 sloth pppd[242]: Local IP address changed to 130.210.252.28
Sep 22 21:20:16 sloth pppd[242]: Couldn't set interface address: Address 130.210.252.28 already exists

Apparently, this is because pppd fails to clear out the interface's
old address before trying to set the new one.

>How-To-Repeat:
Run pppd with the following options:

:130.210.252.254
demand

>Fix:
This seems to make it work... I kinda lifted the code from ifconfig,
but I couldn't find any place in the documentation that said that
SIOCDIFADDR with an all zero ifreq (except for the interface name)
would remove all addresses from the interface. That's what ifconfig
does though...

--- /usr/src/usr.sbin/pppd/pppd/sys-bsd.c	Sun May 18 06:28:18 1997
+++ sys-bsd.c	Mon Sep 22 22:37:38 1997
@@ -961,6 +961,7 @@
     u_int32_t o, h, m;
 {
     struct ifaliasreq ifra;
+    struct ifreq ifr;
 
     strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name));
     SET_SA_FAMILY(ifra.ifra_addr, AF_INET);
@@ -972,6 +973,12 @@
 	((struct sockaddr_in *) &ifra.ifra_mask)->sin_addr.s_addr = m;
     } else
 	BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
+    BZERO(&ifr, sizeof(ifr));
+    strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+    if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
+	if (errno != EADDRNOTAVAIL)
+	    syslog(LOG_WARNING, "Couldn't remove interface address: %m");
+    }
     if (ioctl(sockfd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
 	if (errno != EEXIST) {
 	    syslog(LOG_ERR, "Couldn't set interface address: %m");

>Audit-Trail:
>Unformatted: