diff options
Diffstat (limited to 'networking/route.c')
-rw-r--r-- | networking/route.c | 84 |
1 files changed, 40 insertions, 44 deletions
diff --git a/networking/route.c b/networking/route.c index 4d9aad6cc..ff5daa8a7 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -34,14 +34,6 @@ | |||
34 | 34 | ||
35 | //kbuild:lib-$(CONFIG_ROUTE) += route.o | 35 | //kbuild:lib-$(CONFIG_ROUTE) += route.o |
36 | 36 | ||
37 | //usage:#define route_trivial_usage | ||
38 | //usage: "[{add|del|delete}]" | ||
39 | //usage:#define route_full_usage "\n\n" | ||
40 | //usage: "Edit kernel routing tables\n" | ||
41 | //usage: "\n -n Don't resolve names" | ||
42 | //usage: "\n -e Display other/more information" | ||
43 | //usage: "\n -A inet" IF_FEATURE_IPV6("{6}") " Select address family" | ||
44 | |||
45 | #include <net/route.h> | 37 | #include <net/route.h> |
46 | #include <net/if.h> | 38 | #include <net/if.h> |
47 | 39 | ||
@@ -83,17 +75,15 @@ | |||
83 | #define RTACTION_ADD 1 | 75 | #define RTACTION_ADD 1 |
84 | #define RTACTION_DEL 2 | 76 | #define RTACTION_DEL 2 |
85 | 77 | ||
86 | /* For the various tbl_*[] arrays, the 1st byte is the offset to | 78 | /* For the various tbl_*[] arrays, the 1st byte is return value. */ |
87 | * the next entry and the 2nd byte is return value. */ | ||
88 | 79 | ||
89 | #define NET_FLAG 1 | 80 | #define NET_FLAG 1 |
90 | #define HOST_FLAG 2 | 81 | #define HOST_FLAG 2 |
91 | 82 | ||
92 | /* We remap '-' to '#' to avoid problems with getopt. */ | 83 | /* We remap '-' to '#' to avoid problems with getopt. */ |
93 | static const char tbl_hash_net_host[] ALIGN1 = | 84 | static const char tbl_hash_net_host[] ALIGN1 = |
94 | "\007\001#net\0" | 85 | "\001#net\0" |
95 | /* "\010\002#host\0" */ | 86 | "\002#host\0" |
96 | "\007\002#host" /* Since last, we can save a byte. */ | ||
97 | ; | 87 | ; |
98 | 88 | ||
99 | #define KW_TAKES_ARG 020 | 89 | #define KW_TAKES_ARG 020 |
@@ -116,29 +106,28 @@ static const char tbl_hash_net_host[] ALIGN1 = | |||
116 | static const char tbl_ipvx[] ALIGN1 = | 106 | static const char tbl_ipvx[] ALIGN1 = |
117 | /* 020 is the "takes an arg" bit */ | 107 | /* 020 is the "takes an arg" bit */ |
118 | #if HAVE_NEW_ADDRT | 108 | #if HAVE_NEW_ADDRT |
119 | "\011\020metric\0" | 109 | "\020metric\0" |
120 | #endif | 110 | #endif |
121 | "\012\021netmask\0" | 111 | "\021netmask\0" |
122 | "\005\022gw\0" | 112 | "\022gw\0" |
123 | "\012\022gateway\0" | 113 | "\022gateway\0" |
124 | "\006\023mss\0" | 114 | "\023mss\0" |
125 | "\011\024window\0" | 115 | "\024window\0" |
126 | #ifdef RTF_IRTT | 116 | #ifdef RTF_IRTT |
127 | "\007\025irtt\0" | 117 | "\025irtt\0" |
128 | #endif | 118 | #endif |
129 | "\006\026dev\0" | 119 | "\026dev\0" |
130 | "\011\026device\0" | 120 | "\026device\0" |
131 | /* 040 is the "sets a flag" bit - MUST match flags_ipvx[] values below. */ | 121 | /* 040 is the "sets a flag" bit - MUST match flags_ipvx[] values below. */ |
132 | #ifdef RTF_REJECT | 122 | #ifdef RTF_REJECT |
133 | "\011\040reject\0" | 123 | "\040reject\0" |
134 | #endif | 124 | #endif |
135 | "\006\041mod\0" | 125 | "\041mod\0" |
136 | "\006\042dyn\0" | 126 | "\042dyn\0" |
137 | /* "\014\043reinstate\0" */ | 127 | "\043reinstate\0" |
138 | "\013\043reinstate" /* Since last, we can save a byte. */ | ||
139 | ; | 128 | ; |
140 | 129 | ||
141 | static const uint16_t flags_ipvx[] = { /* MUST match tbl_ipvx[] values above. */ | 130 | static const uint16_t flags_ipvx[] ALIGN2 = { /* MUST match tbl_ipvx[] values above. */ |
142 | #ifdef RTF_REJECT | 131 | #ifdef RTF_REJECT |
143 | RTF_REJECT, | 132 | RTF_REJECT, |
144 | #endif | 133 | #endif |
@@ -151,17 +140,17 @@ static int kw_lookup(const char *kwtbl, char ***pargs) | |||
151 | { | 140 | { |
152 | if (**pargs) { | 141 | if (**pargs) { |
153 | do { | 142 | do { |
154 | if (strcmp(kwtbl+2, **pargs) == 0) { /* Found a match. */ | 143 | if (strcmp(kwtbl + 1, **pargs) == 0) { /* Found a match. */ |
155 | *pargs += 1; | 144 | *pargs += 1; |
156 | if (kwtbl[1] & KW_TAKES_ARG) { | 145 | if (kwtbl[0] & KW_TAKES_ARG) { |
157 | if (!**pargs) { /* No more args! */ | 146 | if (!**pargs) { /* No more args! */ |
158 | bb_show_usage(); | 147 | bb_show_usage(); |
159 | } | 148 | } |
160 | *pargs += 1; /* Calling routine will use args[-1]. */ | 149 | *pargs += 1; /* Calling routine will use args[-1]. */ |
161 | } | 150 | } |
162 | return kwtbl[1]; | 151 | return kwtbl[0]; |
163 | } | 152 | } |
164 | kwtbl += *kwtbl; | 153 | kwtbl += strlen(kwtbl) + 1; |
165 | } while (*kwtbl); | 154 | } while (*kwtbl); |
166 | } | 155 | } |
167 | return 0; | 156 | return 0; |
@@ -208,7 +197,7 @@ static NOINLINE void INET_setroute(int action, char **args) | |||
208 | /* Default netmask. */ | 197 | /* Default netmask. */ |
209 | netmask = "default"; | 198 | netmask = "default"; |
210 | } | 199 | } |
211 | /* Prefer hostname lookup is -host flag (xflag==1) was given. */ | 200 | /* Prefer hostname lookup if -host flag (xflag==1) was given. */ |
212 | isnet = INET_resolve(target, (struct sockaddr_in *) &rt->rt_dst, | 201 | isnet = INET_resolve(target, (struct sockaddr_in *) &rt->rt_dst, |
213 | (xflag & HOST_FLAG)); | 202 | (xflag & HOST_FLAG)); |
214 | if (isnet < 0) { | 203 | if (isnet < 0) { |
@@ -460,9 +449,9 @@ static NOINLINE void INET6_setroute(int action, char **args) | |||
460 | #endif | 449 | #endif |
461 | 450 | ||
462 | static const | 451 | static const |
463 | IF_NOT_FEATURE_IPV6(uint16_t) | 452 | IF_NOT_FEATURE_IPV6(uint16_t flagvals[] ALIGN2 = ) |
464 | IF_FEATURE_IPV6(unsigned) | 453 | IF_FEATURE_IPV6(uint32_t flagvals[] ALIGN4 = ) |
465 | flagvals[] = { /* Must agree with flagchars[]. */ | 454 | { /* Must agree with flagchars[]. */ |
466 | RTF_UP, | 455 | RTF_UP, |
467 | RTF_GATEWAY, | 456 | RTF_GATEWAY, |
468 | RTF_HOST, | 457 | RTF_HOST, |
@@ -544,7 +533,6 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) | |||
544 | flags[0] = '!'; | 533 | flags[0] = '!'; |
545 | } | 534 | } |
546 | #endif | 535 | #endif |
547 | |||
548 | memset(&s_addr, 0, sizeof(struct sockaddr_in)); | 536 | memset(&s_addr, 0, sizeof(struct sockaddr_in)); |
549 | s_addr.sin_family = AF_INET; | 537 | s_addr.sin_family = AF_INET; |
550 | s_addr.sin_addr.s_addr = d; | 538 | s_addr.sin_addr.s_addr = d; |
@@ -634,7 +622,6 @@ static void INET6_displayroutes(void) | |||
634 | naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6, | 622 | naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6, |
635 | 0x0fff /* Apparently, upstream never resolves. */ | 623 | 0x0fff /* Apparently, upstream never resolves. */ |
636 | ); | 624 | ); |
637 | |||
638 | if (!r) { /* 1st pass */ | 625 | if (!r) { /* 1st pass */ |
639 | snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len); | 626 | snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len); |
640 | r += 40; | 627 | r += 40; |
@@ -653,18 +640,27 @@ static void INET6_displayroutes(void) | |||
653 | 640 | ||
654 | #endif | 641 | #endif |
655 | 642 | ||
643 | //usage:#define route_trivial_usage | ||
644 | ///////: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del|delete} [-net|-host] TARGET [netmask MASK] [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [irtt MSEC] [reject] [mod] [dyn] [reinstate] [[dev] IFACE]]" | ||
645 | ///////too wordy | ||
646 | //usage: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del} [-net|-host] TARGET [netmask MASK]\n" | ||
647 | //usage: " [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [reject] [IFACE]]" | ||
648 | //usage:#define route_full_usage "\n\n" | ||
649 | //usage: "Show or edit kernel routing tables\n" | ||
650 | //usage: "\n -n Don't resolve names" | ||
651 | //usage: "\n -e Display other/more information" | ||
652 | //usage: "\n -A inet" IF_FEATURE_IPV6("[6]") " Select address family" | ||
653 | |||
656 | #define ROUTE_OPT_A 0x01 | 654 | #define ROUTE_OPT_A 0x01 |
657 | #define ROUTE_OPT_n 0x02 | 655 | #define ROUTE_OPT_n 0x02 |
658 | #define ROUTE_OPT_e 0x04 | 656 | #define ROUTE_OPT_e 0x04 |
659 | #define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */ | 657 | #define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */ |
660 | 658 | ||
661 | /* 1st byte is offset to next entry offset. 2nd byte is return value. */ | 659 | /* 1st byte is return value, matches RTACTION_* code */ |
662 | /* 2nd byte matches RTACTION_* code */ | ||
663 | static const char tbl_verb[] ALIGN1 = | 660 | static const char tbl_verb[] ALIGN1 = |
664 | "\006\001add\0" | 661 | "\001add\0" |
665 | "\006\002del\0" | 662 | "\002del\0" |
666 | /* "\011\002delete\0" */ | 663 | "\002delete\0" |
667 | "\010\002delete" /* Since it's last, we can save a byte. */ | ||
668 | ; | 664 | ; |
669 | 665 | ||
670 | int route_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 666 | int route_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |