Bug#327031: ifdown routine only works on Linux

Robert Millan rmh at aybabtu.com
Thu Sep 15 08:44:55 UTC 2005


On Mon, Sep 12, 2005 at 11:41:43PM +0200, Petter Reinholdtsen wrote:
> [Robert Millan]
> > It seems on kFreeBSD, some interfaces are "phantom" ones.  They
> > exist, and are detected by the numif assignment in ifdown.c, but
> > their ifr_name component only contains trash (on my system, there
> > are 2 normal interfaces, and 8 "phantom" ones).
> 
> Are these interfaces up?  Perhaps this patch solve the problem, by
> limiting the 'ifconfig down' to the interfaces currently up?
> 
> Index: src/ifdown.c
> ===================================================================
> --- src/ifdown.c        (revisjon 70)
> +++ src/ifdown.c        (arbeidskopi)
> @@ -61,10 +61,12 @@
>                                 continue;
>                         if (strchr(ifr[i].ifr_name, ':') != NULL)
>                                 continue;
> -                       ifr[i].ifr_flags &= ~(IFF_UP);
> -                       if (ioctl(fd, SIOCSIFFLAGS, &ifr[i]) < 0) {
> -                               fprintf(stderr, "ifdown: shutdown ");
> -                               perror(ifr[i].ifr_name);
> +                       if (ifr[i].ifr_flags & IFF_UP) {
> +                               ifr[i].ifr_flags &= ~(IFF_UP);
> +                               if (ioctl(fd, SIOCSIFFLAGS, &ifr[i]) < 0) {
> +                                       fprintf(stderr, "ifdown: shutdown ");
> +                                       perror(ifr[i].ifr_name);
> +                               }
>                         }
>                 }
>         }

This works, but only if you replace "ifr_flags" with "ifr_flagshigh".  It seems
the system declaration is different, and kFreeBSD defines different macros for
the high and low 16-bits of the flags int.

The attached patch (mostly like yours but with a pre-processor check) fixes the
problem.

I have tested it and it's known to work.

-- 
Robert Millan
-------------- next part --------------
diff -ur sysvinit-2.86.ds1.old/src/ifdown.c sysvinit-2.86.ds1/src/ifdown.c
--- sysvinit-2.86.ds1.old/src/ifdown.c	1998-06-02 22:41:47.000000000 +0200
+++ sysvinit-2.86.ds1/src/ifdown.c	2005-09-12 20:30:36.000000000 +0200
@@ -57,14 +57,14 @@
 			if ((strncmp(ifr[i].ifr_name, "shaper", 6) == 0)
 			    != shaper) continue;
 
-			if (strcmp(ifr[i].ifr_name, "lo") == 0)
+			if ((strcmp(ifr[i].ifr_name, "lo") == 0) || (strcmp(ifr[i].ifr_name, "lo0") == 0))
 				continue;
 			if (strchr(ifr[i].ifr_name, ':') != NULL)
 				continue;
 			ifr[i].ifr_flags &= ~(IFF_UP);
 			if (ioctl(fd, SIOCSIFFLAGS, &ifr[i]) < 0) {
-				fprintf(stderr, "ifdown: shutdown ");
-				perror(ifr[i].ifr_name);
+				perror ("ifdown: SIOCSIFFLAGS");
+				break;
 			}
 		}
 	}


More information about the Glibc-bsd-devel mailing list