2 * route This file contains an implementation of the command
3 * that manages the IP routing table in the kernel.
5 * Version: $Id: route.c,v 1.6 1999/04/18 20:28:41 philip Exp $
7 * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
9 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10 * (derived from FvK's 'route.c 1.70 01/04/94')
13 * Johannes Stille: for Net-2Debugged by
14 * <johannes@titan.os.open.de>
15 * Linus Torvalds: Misc Changes
16 * Alan Cox: add the new mtu/window stuff
17 * Miquel van Smoorenburg: rt_add and rt_del
18 * {1.79} Bernd Eckenfels: route_info
19 * {1.80} Bernd Eckenfels: reject, metric, irtt, 1.2.x support.
20 * {1.81} Bernd Eckenfels: reject routes need a dummy device
21 *960127 {1.82} Bernd Eckenfels: 'mod' and 'dyn' 'reinstate' added
22 *960129 {1.83} Bernd Eckenfels: resolve and getsock now in lib/,
23 * REJECT displays '-' as gatway.
24 *960202 {1.84} Bernd Eckenfels: net-features support added
25 *960203 {1.85} Bernd Eckenfels: "#ifdef' in '#if' for net-features
26 * -A (aftrans) support, get_longopts
27 *960206 {1.86} Bernd Eckenfels: route_init();
28 *960218 {1.87} Bernd Eckenfels: netinet/in.h added
29 *960221 {1.88} Bernd Eckenfels: aftrans_dfl support
30 *960222 {1.90} Bernd Eckenfels: moved all AF specific code to lib/.
31 *960413 {1.91} Bernd Eckenfels: new RTACTION support+FLAG_CACHE/FIB
32 *960426 {1.92} Bernd Eckenfels: FLAG_SYM/-N support
33 *960823 {x.xx} Frank Strauss: INET6 stuff
34 *980629 {1.95} Arnaldo Carvalho de Melo: gettext instead of catgets
35 *990101 {1.96} Bernd Eckenfels: fixed usage and FLAG_CACHE Output
38 #include <sys/types.h>
39 #include <sys/ioctl.h>
40 #include <sys/socket.h>
42 /* #include <net/route.h> realy broken */
43 #include <netinet/in.h>
45 #include <netinet/in.h>
46 #include <arpa/nameser.h>
48 #include <linux/param.h>
57 #include "net-support.h"
60 #include "pathnames.h"
63 #define DFLT_AF "inet"
66 #include "lib/net-features.h" /* needs some of the system includes above! */
68 char *Release
= RELEASE
, *Version
= "route 1.96 (1999-01-01)";
70 int opt_n
= 0; /* numerical output flag */
71 int opt_v
= 0; /* debugging output flag */
72 int opt_e
= 1; /* 1,2,3=type of routetable */
73 int opt_fc
= 0; /* routing cache/FIB */
74 int opt_h
= 0; /* help selected */
75 struct aftype
*ap
; /* current address family */
77 static void usage(void)
79 fprintf(stderr
, _("Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables\n"));
80 fprintf(stderr
, _(" route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.\n\n"));
82 fprintf(stderr
, _(" route {-h|--help} [<AF>] Detailed usage syntax for specified AF.\n"));
83 fprintf(stderr
, _(" route {-V|--version} Display version/author and exit.\n\n"));
85 fprintf(stderr
, _(" -v, --verbose be verbose\n"));
86 fprintf(stderr
, _(" -n, --numeric dont resolve names\n"));
87 fprintf(stderr
, _(" -N, --symbolic resolve hardware names\n"));
88 fprintf(stderr
, _(" -e, --extend display other/more information\n"));
89 fprintf(stderr
, _(" -F, --fib display Forwarding Information Base (default)\n"));
90 fprintf(stderr
, _(" -C, --cache display routing cache instead of FIB\n\n"));
92 fprintf(stderr
, _(" <AF>=Use '-A <af>' or '--<af>' Default: %s\n"), DFLT_AF
);
93 fprintf(stderr
, _(" List of possible address families (which support routing):\n"));
94 print_aflist(1); /* 1 = routeable */
99 static void version(void)
101 fprintf(stderr
, "%s\n%s\n%s\n", Release
, Version
, Features
);
106 int main(int argc
, char **argv
)
108 int i
, lop
, what
= 0;
109 struct option longopts
[] =
112 {"extend", 0, 0, 'e'},
113 {"verbose", 0, 0, 'v'},
114 {"version", 0, 0, 'V'},
115 {"numeric", 0, 0, 'n'},
116 {"symbolic", 0, 0, 'N'},
117 {"protocol", 1, 0, 'A'},
118 {"cache", 0, 0, 'C'},
127 bindtextdomain("net-tools", "/usr/share/locale");
128 textdomain("net-tools");
130 getroute_init(); /* Set up AF routing support */
135 /* getopts and -net wont work :-/ */
136 for (tmp
= argv
; *tmp
; tmp
++) {
137 if (!strcmp(*tmp
, "-net"))
138 strcpy(*tmp
, "#net");
139 else if (!strcmp(*tmp
, "-host"))
140 strcpy(*tmp
, "#host");
143 /* Fetch the command-line arguments. */
144 while ((i
= getopt_long(argc
, argv
, "A:eCFhnNVv?", longopts
, &lop
)) != EOF
)
155 opt_v
|= FLAG_VERBOSE
;
161 if (lop
< 0 || lop
>= AFTRANS_CNT
) {
162 EINTERN("route.c", "longopts 1 range");
165 if ((i
= aftrans_opt(longopts
[lop
].name
)))
169 opt_fc
|= FLAG_CACHE
;
175 if ((i
= aftrans_opt(optarg
)))
195 what
= RTACTION_HELP
;
198 /* this will initialise afname[] */
199 aftrans_def("route", progname
, DFLT_AF
);
201 /* Do we have to show the contents of the routing table? */
203 what
= RTACTION_SHOW
;
205 if (!strcmp(*argv
, "add"))
207 else if (!strcmp(*argv
, "del") || !strcmp(*argv
, "delete"))
209 else if (!strcmp(*argv
, "flush"))
210 what
= RTACTION_FLUSH
;
216 options
= (opt_e
& FLAG_EXT
) | opt_n
| opt_fc
| opt_v
;
220 if (what
== RTACTION_SHOW
)
221 i
= route_info(afname
, options
);
223 i
= route_edit(what
, afname
, options
, ++argv
);