Enable ip commands to be compiled seperate from ip, modifed patch from Bastian Blank
authorGlenn L McGrath <bug1@ihug.co.nz>
Sun, 1 Dec 2002 23:04:06 +0000 (23:04 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Sun, 1 Dec 2002 23:04:06 +0000 (23:04 -0000)
13 files changed:
include/applets.h
include/usage.h
networking/Makefile.in
networking/config.in
networking/ip.c
networking/ipaddr.c [new file with mode: 0644]
networking/iplink.c [new file with mode: 0644]
networking/iproute.c [new file with mode: 0644]
networking/iptunnel.c [new file with mode: 0644]
networking/libiproute/Makefile.in
networking/libiproute/ip_common.h
networking/libiproute/ip_parse_common_args.c [new file with mode: 0644]
networking/libiproute/ipaddress.c

index a85a8bfcb2ed0e31ff5dec09030749321dc2cc91..d8c4b38a08ae0b158c2eaccbad1c0443d4366ae9 100644 (file)
        APPLET(insmod, insmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
 #endif
 #ifdef CONFIG_IP
-       APPLET(ip, ip_main, _BB_DIR_BIN, _BB_SUID_NEVER)
+       APPLET(ip, ip_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
 #endif
 #ifdef CONFIG_IPCALC
        APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER)
 #endif
+#ifdef CONFIG_IPADDRESS
+       APPLET(ipaddr, ipaddr_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
+#endif
+#ifdef CONFIG_IPLINK
+       APPLET(iplink, iplink_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
+#endif
+#ifdef CONFIG_IPROUTE
+       APPLET(iproute, iproute_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
+#endif
+#ifdef CONFIG_IPTUNNEL
+       APPLET(iptunnel, iptunnel_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
+#endif
 #ifdef CONFIG_KILL
        APPLET(kill, kill_main, _BB_DIR_BIN, _BB_SUID_NEVER)
 #endif
index c676754e3c19413df24e031c41130ddf9309a011..eca05446f3ae06f25987eea8f475d0f523c7e814 100644 (file)
        "\t-x\tdo not export externs"
 
 #define ip_trivial_usage \
-       "not written yet"
+       "[ OPTIONS ] { address | link | route | tunnel } { COMMAND | help }"
 #define ip_full_usage \
-       "not written yet"
+       "ip [ OPTIONS ] OBJECT { COMMAND | help }\n" \
+       "where  OBJECT := { link | addr | route | tunnel }\n" \
+       "OPTIONS := { -f[amily] { inet | inet6 | link } | -o[neline] }\n"
+
+#define ipaddr_trivial_usage \
+       "{ {add|del} IFADDR dev STRING | {show|flush} [ dev STRING ] [ to PREFIX ] }"
+#define ipaddr_full_usage \
+       "ipaddr {add|del} IFADDR dev STRING\n" \
+       "ipaddr {show|flush} [ dev STRING ] [ scope SCOPE-ID ]\n" \
+       "                    [ to PREFIX ] [ label PATTERN ]\n" \
+       "IFADDR := PREFIX | ADDR peer PREFIX\n" \
+       "          [ broadcast ADDR ] [ anycast ADDR ]\n" \
+       "          [ label STRING ] [ scope SCOPE-ID ]\n" \
+       "SCOPE-ID := [ host | link | global | NUMBER ]\n"
 
 #ifndef CONFIG_FEATURE_IPCALC_FANCY
-#define ipcalc_trivial_usage \
+# define ipcalc_trivial_usage \
        "[--broadcast] [--netmask] [--network] ipaddr <netmask>"
 
-#define ipcalc_full_usage \
+# define ipcalc_full_usage \
        "Calculate IP network settings from a IP address\n\n" \
        "Options:\n" \
        "\t-b\t--broadcast\tDisplay calculated broadcast address.\n" \
        "\t-n\t--netmask\tDisplay default netmask for IP.\n" \
        "\t-w\t--network\tDisplay calculated network address." 
 #else
-#define ipcalc_trivial_usage \
+# define ipcalc_trivial_usage \
        "[OPTION]... ipaddr <netmask>"
 
-#define ipcalc_full_usage \
+# define ipcalc_full_usage \
        "Calculate IP network settings from a IP address\n\n" \
        "Options:\n" \
        "\t-b\t--broadcast\tDisplay calculated broadcast address.\n" \
        "should display on standard out. Multiple options may be\n" \
        "specified.\n"
 
+#define iplink_trivial_usage \
+       "{ set DEVICE { up | down | arp { on | off } | show [ DEVICE ] }"
+#define iplink_full_usage \
+       "iplink set DEVICE { up | down | arp { on | off } |\n" \
+       "                     dynamic { on | off } |\n" \
+       "                     mtu MTU }\n" \
+       "iplink show [ DEVICE ]\n"
+
+#define iproute_trivial_usage \
+       "{ list | flush | { add | del | change | append | replace | monitor } ROUTE }"
+#define iproute_full_usage \
+       "iproute { list | flush } SELECTOR\n" \
+       "iproute get ADDRESS [ from ADDRESS iif STRING ]\n" \
+       "                     [ oif STRING ]  [ tos TOS ]\n" \
+       "iproute { add | del | change | append | replace | monitor } ROUTE\n" \
+       "SELECTOR := [ root PREFIX ] [ match PREFIX ] [ proto RTPROTO ]\n" \
+       "ROUTE := [ TYPE ] PREFIX [ tos TOS ] [ proto RTPROTO ]\n"
+
+#define iptunnel_trivial_usage \
+       "{ add | change | del | show } [ NAME ] [ mode { ipip | gre | sit } ] [ remote ADDR ] [ local ADDR ] [ ttl TTL ]"
+#define iptunnel_full_usage \
+       "iptunnel { add | change | del | show } [ NAME ]\n" \
+       "          [ mode { ipip | gre | sit } ] [ remote ADDR ] [ local ADDR ]\n" \
+       "          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n" \
+       "          [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n"
+
 #define kill_trivial_usage \
        "[-signal] process-id [process-id ...]"
 #define kill_full_usage \
index 7404b041d805fdbf70a3a89b05c9f54290df33d8..fc6a3b7e0e34637eb3dc1015102b6744beb50221 100644 (file)
@@ -23,21 +23,25 @@ NETWORKING_DIR:=$(TOPDIR)networking/
 endif
 
 NETWORKING-y:=
-NETWORKING-$(CONFIG_HOSTNAME)          += hostname.o
-NETWORKING-$(CONFIG_IFCONFIG)          += ifconfig.o
-NETWORKING-$(CONFIG_IFUPDOWN)          += ifupdown.o
-NETWORKING-$(CONFIG_IP)                    += ip.o
-NETWORKING-$(CONFIG_IPCALC)             += ipcalc.o
+NETWORKING-$(CONFIG_HOSTNAME)  += hostname.o
+NETWORKING-$(CONFIG_IFCONFIG)  += ifconfig.o
+NETWORKING-$(CONFIG_IFUPDOWN)  += ifupdown.o
+NETWORKING-$(CONFIG_IP)                        += ip.o
+NETWORKING-$(CONFIG_IPCALC)            += ipcalc.o
+NETWORKING-$(CONFIG_IPADDR)            += ipaddr.o
+NETWORKING-$(CONFIG_IPLINK)            += iplink.o
+NETWORKING-$(CONFIG_IPROUTE)   += iproute.o
+NETWORKING-$(CONFIG_IPTUNNEL)  += iptunnel.o
 NETWORKING-$(CONFIG_NC)                    += nc.o
-NETWORKING-$(CONFIG_NETSTAT)           += netstat.o
-NETWORKING-$(CONFIG_NSLOOKUP)          += nslookup.o
+NETWORKING-$(CONFIG_NETSTAT)   += netstat.o
+NETWORKING-$(CONFIG_NSLOOKUP)  += nslookup.o
 NETWORKING-$(CONFIG_PING)              += ping.o
 NETWORKING-$(CONFIG_PING6)             += ping6.o
 NETWORKING-$(CONFIG_ROUTE)             += route.o
 NETWORKING-$(CONFIG_TELNET)            += telnet.o
-NETWORKING-$(CONFIG_TELNETD)           += telnetd.o
+NETWORKING-$(CONFIG_TELNETD)   += telnetd.o
 NETWORKING-$(CONFIG_TFTP)              += tftp.o
-NETWORKING-$(CONFIG_TRACEROUTE)                += traceroute.o
+NETWORKING-$(CONFIG_TRACEROUTE)        += traceroute.o
 NETWORKING-$(CONFIG_WGET)              += wget.o
 
 libraries-y+=$(NETWORKING_DIR)$(NETWORKING_AR)
index d62a6e425ff50ab71064e6238b7ca58b964b7daa..de5b920648a5835f0a55f65ebe4be1a2695681c9 100644 (file)
@@ -33,10 +33,26 @@ bool 'ipcalc'           CONFIG_IPCALC
 if [ "$CONFIG_IPCALC" = "y" ]; then
     bool '  Fancy IPCALC, more options, adds 300 bytes'        CONFIG_FEATURE_IPCALC_FANCY
 fi
-bool 'nc'          CONFIG_NC
+bool 'ipaddr'          CONFIG_IPADDR
+if [ "$CONFIG_IP" = "y" ] && [ "$CONFIG_IPADDR" = "y" ]; then
+       define_bool     CONFIG_FEATURE_IP_ADDRESS       y
+fi
+bool 'iplink'          CONFIG_IPLINK
+if [ "$CONFIG_IP" = "y" ] && [ "$CONFIG_IPLINK" = "y" ]; then
+       define_bool     CONFIG_FEATURE_IP_LINK  y
+fi
+bool 'iproute'         CONFIG_IPROUTE
+if [ "$CONFIG_IP" = "y" ] && [ "$CONFIG_IPROUTE" = "y" ]; then
+       define_bool     CONFIG_FEATURE_IP_ROUTE y
+fi
+bool 'iptunnel'                CONFIG_IPTUNNEL
+if [ "$CONFIG_IP" = "y" ] && [ "$CONFIG_IPTUNNEL" = "y" ]; then
+       define_bool     CONFIG_FEATURE_IP_TUNNEL        y
+fi
+bool 'nc'                      CONFIG_NC
 bool 'netstat'     CONFIG_NETSTAT
 bool 'nslookup'            CONFIG_NSLOOKUP
-bool 'ping'        CONFIG_PING
+bool 'ping'                    CONFIG_PING
 if [ "$CONFIG_PING" = "y" ]; then
     bool '  Enable fancy ping output'          CONFIG_FEATURE_FANCY_PING
 fi
index f045f5f78de085d2478efe10ccb8eafbe7e09568..e7cab74c93a886f2501c105416d59d1b7a697052 100644 (file)
 
 #include "busybox.h"
 
+#if 0
 int preferred_family = AF_UNSPEC;
 int oneline = 0;
 char * _SL_ = NULL;
 
-int ip_main(int argc, char **argv)
+void ip_parse_common_args(int *argcp, char ***argvp)
 {
-       char *basename;
+       int argc = *argcp;
+       char **argv = *argvp;
 
-       basename = strrchr(argv[0], '/');
-       if (basename == NULL)
-               basename = argv[0];
-       else
-               basename++;
-       
        while (argc > 1) {
                char *opt = argv[1];
+
                if (strcmp(opt,"--") == 0) {
                        argc--; argv++;
                        break;
                }
+
                if (opt[0] != '-')
                        break;
+
                if (opt[1] == '-')
                        opt++;
+
                if (matches(opt, "-family") == 0) {
                        argc--;
                        argv++;
@@ -72,33 +72,44 @@ int ip_main(int argc, char **argv)
                } else if (matches(opt, "-oneline") == 0) {
                        ++oneline;
                } else {
-                       fprintf(stderr, "Option \"%s\" is unknown, try \"ip -help\".\n", opt);
-                       exit(-1);
+                       show_usage();
                }
                argc--; argv++;
        }
-
        _SL_ = oneline ? "\\" : "\n" ;
+}
+#endif
+
+int ip_main(int argc, char **argv)
+{
+       int ret = EXIT_FAILURE;
+
+       ip_parse_common_args(&argc, &argv);
 
        if (argc > 1) {
 #ifdef CONFIG_FEATURE_IP_ADDRESS
-               if (matches(argv[1], "address") == 0)
-                       return do_ipaddr(argc-2, argv+2);
+               if (matches(argv[1], "address") == 0) {
+                       ret = do_ipaddr(argc-2, argv+2);
+               }
 #endif
 #ifdef CONFIG_FEATURE_IP_ROUTE
-               if (matches(argv[1], "route") == 0)
-                       return do_iproute(argc-2, argv+2);
+               else if (matches(argv[1], "route") == 0) {
+                       ret = do_iproute(argc-2, argv+2);
+               }
 #endif
 #ifdef CONFIG_FEATURE_IP_LINK
-               if (matches(argv[1], "link") == 0)
-                       return do_iplink(argc-2, argv+2);
+               else if (matches(argv[1], "link") == 0) {
+                       ret = do_iplink(argc-2, argv+2);
+               }
 #endif
 #ifdef CONFIG_FEATURE_IP_TUNNEL
-               if (matches(argv[1], "tunnel") == 0 ||
-                   strcmp(argv[1], "tunl") == 0)
-                       return do_iptunnel(argc-2, argv+2);
+               else if (matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0) {
+                       ret = do_iptunnel(argc-2, argv+2);
+               }
 #endif
-               fprintf(stderr, "Object \"%s\" is unknown, try \"ip help\".\n", argv[1]);
-               exit(-1);
        }
+       if (ret) {
+               show_usage();
+       }
+       return(EXIT_SUCCESS);
 }
diff --git a/networking/ipaddr.c b/networking/ipaddr.c
new file mode 100644 (file)
index 0000000..7826194
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * ip.c                "ip" utility frontend.
+ *
+ *             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, <kuznet@ms2.inr.ac.ru>
+ *
+ *
+ * Changes:
+ *
+ * Rani Assaf <rani@magic.metawire.com> 980929:        resolve addresses
+ */
+
+#include "./libiproute/utils.h"
+#include "./libiproute/ip_common.h"
+
+#include "busybox.h"
+
+int ipaddr_main(int argc, char **argv)
+{
+       ip_parse_common_args(&argc, &argv);
+
+       return do_ipaddr(argc-1, argv+1);
+}
diff --git a/networking/iplink.c b/networking/iplink.c
new file mode 100644 (file)
index 0000000..7207e17
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * ip.c                "ip" utility frontend.
+ *
+ *             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, <kuznet@ms2.inr.ac.ru>
+ *
+ *
+ * Changes:
+ *
+ * Rani Assaf <rani@magic.metawire.com> 980929:        resolve addresses
+ */
+
+#include "./libiproute/utils.h"
+#include "./libiproute/ip_common.h"
+
+#include "busybox.h"
+
+int iplink_main(int argc, char **argv)
+{
+       ip_parse_common_args(&argc, &argv);
+
+       return do_iplink(argc-1, argv+1);
+}
diff --git a/networking/iproute.c b/networking/iproute.c
new file mode 100644 (file)
index 0000000..d049a87
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * ip.c                "ip" utility frontend.
+ *
+ *             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, <kuznet@ms2.inr.ac.ru>
+ *
+ *
+ * Changes:
+ *
+ * Rani Assaf <rani@magic.metawire.com> 980929:        resolve addresses
+ */
+
+#include "./libiproute/utils.h"
+#include "./libiproute/ip_common.h"
+
+#include "busybox.h"
+
+int iproute_main(int argc, char **argv)
+{
+       ip_parse_common_args(&argc, &argv);
+
+       return do_iproute(argc-1, argv+1);
+}
diff --git a/networking/iptunnel.c b/networking/iptunnel.c
new file mode 100644 (file)
index 0000000..f2b2e8a
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * ip.c                "ip" utility frontend.
+ *
+ *             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, <kuznet@ms2.inr.ac.ru>
+ *
+ *
+ * Changes:
+ *
+ * Rani Assaf <rani@magic.metawire.com> 980929:        resolve addresses
+ */
+
+#include "./libiproute/utils.h"
+#include "./libiproute/ip_common.h"
+
+#include "busybox.h"
+
+int iptunnel_main(int argc, char **argv)
+{
+       ip_parse_common_args(&argc, &argv);
+
+       return do_iptunnel(argc-1, argv+1);
+}
index 6d35d7b3f319876b3ccc1cb690a5635b5c129d08..9fe14621573f5e37275563269c9bef86303f5268 100644 (file)
@@ -23,6 +23,7 @@ LIBIPROUTE_DIR:=$(TOPDIR)networking/libiproute/
 endif
 
 LIBIPROUTE-$(CONFIG_IP) += \
+       ip_parse_common_args.o \
        ipaddress.o \
        iplink.o \
        iproute.o \
index 5ac43218e2ffbabe1e022f592c20f53cdcb94a4a..771ca48bd477ef28d6c2d8f67e70fe6879168594 100644 (file)
@@ -1,3 +1,7 @@
+extern int preferred_family;
+extern char * _SL_;
+
+extern void ip_parse_common_args(int *argcp, char ***argvp);
 extern int print_linkinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
 extern int print_addrinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
 extern int print_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
diff --git a/networking/libiproute/ip_parse_common_args.c b/networking/libiproute/ip_parse_common_args.c
new file mode 100644 (file)
index 0000000..550d1dd
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * ip.c                "ip" utility frontend.
+ *
+ *             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, <kuznet@ms2.inr.ac.ru>
+ *
+ *
+ * Changes:
+ *
+ * Rani Assaf <rani@magic.metawire.com> 980929:        resolve addresses
+ */
+
+#include "utils.h"
+#include "ip_common.h"
+
+#include "busybox.h"
+
+int preferred_family = AF_UNSPEC;
+int oneline = 0;
+char * _SL_ = NULL;
+
+void ip_parse_common_args(int *argcp, char ***argvp)
+{
+       int argc = *argcp;
+       char **argv = *argvp;
+
+       while (argc > 1) {
+               char *opt = argv[1];
+
+               if (strcmp(opt,"--") == 0) {
+                       argc--; argv++;
+                       break;
+               }
+
+               if (opt[0] != '-')
+                       break;
+
+               if (opt[1] == '-')
+                       opt++;
+
+               if (matches(opt, "-family") == 0) {
+                       argc--;
+                       argv++;
+                       if (strcmp(argv[1], "inet") == 0)
+                               preferred_family = AF_INET;
+                       else if (strcmp(argv[1], "inet6") == 0)
+                               preferred_family = AF_INET6;
+                       else if (strcmp(argv[1], "link") == 0)
+                               preferred_family = AF_PACKET;
+                       else
+                               invarg(argv[1], "invalid protocol family");
+               } else if (strcmp(opt, "-4") == 0) {
+                       preferred_family = AF_INET;
+               } else if (strcmp(opt, "-6") == 0) {
+                       preferred_family = AF_INET6;
+               } else if (strcmp(opt, "-0") == 0) {
+                       preferred_family = AF_PACKET;
+               } else if (matches(opt, "-oneline") == 0) {
+                       ++oneline;
+               } else {
+                       show_usage();
+               }
+               argc--; argv++;
+       }
+       _SL_ = oneline ? "\\" : "\n" ;
+}
index dd5a914263269e6abae947d283e06421fee9b8ba..055aadfee05e570ac9461d3b9ab4912e7f7296ae 100644 (file)
@@ -230,7 +230,6 @@ int print_addrinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if ((filter.flags^ifa->ifa_flags)&filter.flagmask)
                return 0;
        if (filter.label) {
-               SPRINT_BUF(b1);
                const char *label;
                if (rta_tb[IFA_LABEL])
                        label = RTA_DATA(rta_tb[IFA_LABEL]);
@@ -541,10 +540,10 @@ int ipaddr_list_link(int argc, char **argv)
        return ipaddr_list(argc, argv);
 }
 
-void ipaddr_reset_filter(int oneline)
+void ipaddr_reset_filter(int _oneline)
 {
        memset(&filter, 0, sizeof(filter));
-       filter.oneline = oneline;
+       filter.oneline = _oneline;
 }
 
 int default_scope(inet_prefix *lcl)