Re: [linux-vrf-core] [PATCH] Lets get rid of vrfctl :)
Status: Beta
Brought to you by:
jleu
From: James R. L. <jl...@mi...> - 2002-10-25 17:59:20
|
I will apply this patch so as to kill vrfctl, but I want to move to a netlink interface for creating/deleting VRFs and for gathering info about them. I won't have time to work on it this weekend, but if someone else were to implement before I get to it next week, I would gladly accept the patch ;-) Laters On Fri, Oct 25, 2002 at 07:33:39PM +0200, Jorge Boncompte [DTI2] wrote: > diff -uNr --exclude *.o iproute-20010824/ip/Makefile > iproute-20010824-jorge/ip/Makefile > --- iproute-20010824/ip/Makefile Wed Oct 23 15:03:17 2002 > +++ iproute-20010824-jorge/ip/Makefile Wed Oct 23 15:03:28 2002 > @@ -1,6 +1,6 @@ > IPOBJ=ip.o ipaddress.o iproute.o iprule.o \ > rtm_map.o iptunnel.o ipneigh.o iplink.o ipmaddr.o \ > - ipmonitor.o ipmroute.o > + ipmonitor.o ipmroute.o ipvrf.o > > RTMONOBJ=rtmon.o > > diff -uNr --exclude *.o iproute-20010824/ip/ip.c > iproute-20010824-jorge/ip/ip.c > --- iproute-20010824/ip/ip.c Wed Oct 23 15:09:18 2002 > +++ iproute-20010824-jorge/ip/ip.c Wed Oct 23 15:09:42 2002 > @@ -39,7 +39,7 @@ > { > fprintf(stderr, > "Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n" > -"where OBJECT := { link | addr | route | rule | neigh | tunnel |\n" > +"where OBJECT := { link | addr | route | rule | neigh | tunnel | vrf |\n" > " maddr | mroute | monitor }\n" > " OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] |\n" > " -f[amily] { inet | inet6 | ipx | dnet | link } > | -o[neline] }\n"); > @@ -132,6 +132,8 @@ > return do_ipneigh(argc-1, argv+1); > if (strcmp(basename, "iplink") == 0) > return do_iplink(argc-1, argv+1); > + if (strcmp(basename, "ipvrf") == 0) > + return do_ipvrf(argc-1, argv+1); > if (strcmp(basename, "iptunnel") == 0) > return do_iptunnel(argc-1, argv+1); > if (strcmp(basename, "ipmonitor") == 0) > @@ -153,6 +155,8 @@ > return do_ipneigh(argc-2, argv+2); > if (matches(argv[1], "link") == 0) > return do_iplink(argc-2, argv+2); > + if (matches(argv[1], "vrf") == 0) > + return do_ipvrf(argc-2, argv+2); > if (matches(argv[1], "tunnel") == 0 || > strcmp(argv[1], "tunl") == 0) > return do_iptunnel(argc-2, argv+2); > diff -uNr --exclude *.o iproute-20010824/ip/ip_common.h > iproute-20010824-jorge/ip/ip_common.h > --- iproute-20010824/ip/ip_common.h Sun Apr 16 19:42:50 2000 > +++ iproute-20010824-jorge/ip/ip_common.h Wed Oct 23 15:07:39 2002 > @@ -5,6 +5,7 @@ > extern int ipaddr_list_link(int argc, char **argv); > extern int iproute_monitor(int argc, char **argv); > extern void iplink_usage(void) __attribute__((noreturn)); > +extern void ipvrf_usage(void) __attribute__((noreturn)); > extern void iproute_reset_filter(void); > extern void ipaddr_reset_filter(int); > extern void ipneigh_reset_filter(void); > @@ -15,6 +16,7 @@ > extern int do_ipneigh(int argc, char **argv); > extern int do_iptunnel(int argc, char **argv); > extern int do_iplink(int argc, char **argv); > +extern int do_ipvrf(int argc, char **argv); > extern int do_ipmonitor(int argc, char **argv); > extern int do_multiaddr(int argc, char **argv); > extern int do_multiroute(int argc, char **argv); > --- iproute-20010824/ip/ipvrf.c Thu Jan 1 01:00:00 1970 > +++ iproute-20010824-jorge/ip/ipvrf.c Fri Oct 25 19:27:18 2002 > @@ -0,0 +1,106 @@ > +/* > + * ipvrf.c "ip vrf". > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; either version > + * 2 of the License, or (at your option) any later version. > + * > + * Authors: Alexey Kuznetsov, <ku...@ms...> > + * Hacked by: Jorge Boncompte, <jo...@dt...> > + * > + */ > + > +#include <stdio.h> > +#include <stdlib.h> > +#include <unistd.h> > +#include <errno.h> > +#include <sys/socket.h> > +#include <linux/sockios.h> > +#include <sys/ioctl.h> > + > +#include "utils.h" > + > +void ipvrf_usage(void) > +{ > + fprintf(stderr, "Usage: ip vrf list\n"); > + fprintf(stderr, " ip vrf {add | del} VRFID\n"); > + fprintf(stderr, " ip vrf show\n"); > + exit(-1); > +} > + > +static void usage(void) > +{ > + ipvrf_usage(); > +} > + > +static int do_vrf(int action, int argc, char **argv) > +{ > + int fd=0; > + int vrf=-1; > + > + if (vrf != -1) > + duparg("vrf", *argv); > + if (get_integer(&vrf, *argv, 0)) > + invarg("Invalid \"vrf\" value\n", *argv); > + > + if (vrf > VRF_MAX) { > + fprintf(stderr, "VRF ID out of range (1-%d)\n", VRF_MAX); > + exit(-1); > + } > + if (vrf != -1) { > + if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ > + perror("opening socket"); > + exit(-1); > + } > + if(ioctl(fd, action, vrf) < 0){ > + perror("ioctl"); > + exit(-1); > + } > + } > + close(fd); > + return 0; > +} > + > +int ipvrf_list(int argc, char **argv) > +{ > + int fd=0, vrf; > + > + if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ > + perror("opening socket"); > + exit(-1); > + } > + for (vrf=1;vrf<=VRF_MAX;vrf++){ > + if(ioctl(fd, SIOCGETVRF, vrf) < 0){ > + if (errno != ENOENT){ > + perror("ioctl"); > + exit(-1); > + } > + } else { > + /* FIXME: List the interfaces attached to the VRF */ > + printf("VRF ID=%d\n", vrf); > + } > + } > + close(fd); > + return 0; > +} > + > +int do_ipvrf(int argc, char **argv) > +{ > + if (argc > 0) { > + if (matches(*argv, "add") == 0) > + return do_vrf(SIOCADDVRF, argc-1, argv+1); > + if (matches(*argv, "del") == 0) > + return do_vrf(SIOCDELVRF, argc-1, argv+1); > + if (matches(*argv, "show") == 0 || > + matches(*argv, "lst") == 0 || > + matches(*argv, "list") == 0) > + return ipvrf_list(argc-1, argv+1); > + if (matches(*argv, "help") == 0) > + usage(); > + } else > + return ipvrf_list(0, NULL); > + > + fprintf(stderr, "Command \"%s\" is unknown, try \"ip vrf help\".\n", > *argv); > + exit(-1); > +} > > -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. > ============================================================== > > > > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0004en > _______________________________________________ > linux-vrf-core mailing list > lin...@li... > https://lists.sourceforge.net/lists/listinfo/linux-vrf-core -- James R. Leu |