[linux-vrf-core] [PATCH] Another one
Status: Beta
Brought to you by:
jleu
From: Jorge B. [DTI2] <jo...@dt...> - 2002-10-25 17:41:32
|
Hi again, Kernel crash if you put an interface in a VRF that doesn't exist and the you try to add the VRF, I think that this check has to be done in the kernel in SIOCSIFVRF but fib_rules[vrf] is not accesible from core/dev.c and I think it hasn't so I check in userspace. James any idea on how to do this? I set the interface down and up after changing the VRF of an interface to move the routes between VRFs diff -uNr --exclude *.o iproute-20010824/ip/iplink.c iproute-20010824-jorge/ip/iplink.c --- iproute-20010824/ip/iplink.c Sat Oct 19 00:23:25 2002 +++ iproute-20010824-jorge/ip/iplink.c Fri Oct 25 19:27:40 2002 @@ -41,7 +41,7 @@ fprintf(stderr, " multicast { on | off } | txqueuelen PACKETS |\n"); fprintf(stderr, " name NEWNAME |\n"); fprintf(stderr, " address LLADDR | broadcast LLADDR |\n"); - fprintf(stderr, " mtu MTU | vrf NUMBER }\n"); + fprintf(stderr, " mtu MTU | vrf VRFID }\n"); fprintf(stderr, " ip link show [ DEVICE ]\n"); exit(-1); } @@ -181,10 +181,19 @@ memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, dev); ifr.ifr_flags = vrf; - if (ioctl(s, SIOCSIFVRF, &ifr) < 0) { - perror("SIOCSIFVRF"); - close(s); - return -1; + if(ioctl(s, SIOCGETVRF, vrf) == 0){ + if (ioctl(s, SIOCSIFVRF, &ifr) < 0) { + perror("SIOCSIFVRF"); + close(s); + return -1; + } + } else { + if (errno != ENOENT){ + perror("ioctl"); + exit(-1); + } else { + fprintf(stderr, "VRF %d does not exist.\n", vrf); + } } close(s); @@ -394,7 +403,16 @@ } if (vrf != -1) { if (set_vrf(dev, vrf) < 0) - return -1; + return -1; + /* HACK HACK HACK */ + /* Setting the interface down and up moves the routes + between the old and new VRF */ + mask |= IFF_UP; + flags &= ~IFF_UP; + do_chflags(dev, flags, mask); /* DOWN */ + mask |= IFF_UP; + flags |= IFF_UP; + do_chflags(dev, flags, mask); /* UP */ } if (newaddr || newbrd) { if (newbrd) { -Jorge ============================================================== Jorge Boncompte - Tecnico de sistemas DTI2 - Desarrollo de la Tecnologia de las Comunicaciones -------------------------------------------------------------- C/ Abogado Enriquez Barrios, 5 14004 CORDOBA (SPAIN) Tlf: +34 957 761395 / FAX: +34 957 450380 -------------------------------------------------------------- jo...@dt... _-_-_-_-_-_-_-_-_-_-_-_-_-_ http://www.dti2.net ============================================================== - Sin pistachos no hay Rock & Roll... - Without wicker a basket cannot be done. ============================================================== |