Date: Wed, 11 Jul 2001 20:34:55 +0300 From: Ruslan Ermilov <ru@FreeBSD.ORG> To: Brian Somers <brian@Awfulhak.org> Cc: Mark Blackman <mark.blackman@netscalibur.co.uk>, freebsd-net@FreeBSD.ORG Subject: Re: default route disappears on address changes for interface. Message-ID: <20010711203455.A99297@sunbay.com> In-Reply-To: <200107091041.f69AfbQ61858@hak.lan.Awfulhak.org>; from brian@Awfulhak.org on Mon, Jul 09, 2001 at 11:41:37AM %2B0100 References: <mark.blackman@netscalibur.co.uk> <200107091041.f69AfbQ61858@hak.lan.Awfulhak.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jul 09, 2001 at 11:41:37AM +0100, Brian Somers wrote:
> ifconfig(8) deletes and re-adds the given address. When the delete
> happens, the route (now) disappears.
>
> IMHO, ifconfig(8) should be smart enough to optimise out no-ops.
>
I found that using SIOCSIFADDR (though deprecated) to be beneficial
in this case. It simply "changes" the interface's address rather
than deleting an old address and adding a new one. This preserves
all routes holding on this address. Here is the hackish code that
does this.
Index: ifconfig.c
===================================================================
RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.64
diff -u -p -r1.64 ifconfig.c
--- ifconfig.c 2001/07/02 20:52:34 1.64
+++ ifconfig.c 2001/07/11 17:30:36
@@ -707,6 +707,12 @@ ifconfig(argc, argv, afp)
Perror("Encapsulation Routing");
}
#endif
+ if (clearaddr && newaddr && setaddr && afp->af_af == AF_INET) {
+ strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
+ if (ioctl(s, SIOCSIFADDR, afp->af_addreq) < 0)
+ Perror("ioctl (SIOCSIFADDR)");
+ goto out;
+ }
if (clearaddr) {
if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
warnx("interface %s cannot change %s addresses!",
@@ -736,6 +742,7 @@ ifconfig(argc, argv, afp)
if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
Perror("ioctl (SIOCAIFADDR)");
}
+out:
close(s);
return(0);
}
Cheers,
--
Ruslan Ermilov Oracle Developer/DBA,
ru@sunbay.com Sunbay Software AG,
ru@FreeBSD.org FreeBSD committer,
+380.652.512.251 Simferopol, Ukraine
http://www.FreeBSD.org The Power To Serve
http://www.oracle.com Enabling The Information Age
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010711203455.A99297>
