aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Tomanek <stefan.tomanek@wertarbyte.de>2017-06-13 19:06:09 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-06-13 19:06:09 +0200
commit192dce4b84fb32346ebc5194de7daa5da3b8d1b4 (patch)
tree3d199093c6aaaf51d250abccd2e1d023c393479b
parent6683d1cbb44859f549f87f882545b84b9369585c (diff)
downloadbusybox-w32-192dce4b84fb32346ebc5194de7daa5da3b8d1b4.tar.gz
busybox-w32-192dce4b84fb32346ebc5194de7daa5da3b8d1b4.tar.bz2
busybox-w32-192dce4b84fb32346ebc5194de7daa5da3b8d1b4.zip
ip rule: add suppress_{prefixlength,ifgroup} options
function old new delta iprule_modify 816 887 +71 print_rule 610 680 +70 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 141/0) Total: 141 bytes Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/libiproute/iprule.c73
1 files changed, 46 insertions, 27 deletions
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index 8f3f86286..1bb5e759e 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -17,25 +17,32 @@
17#include <netinet/ip.h> 17#include <netinet/ip.h>
18#include <arpa/inet.h> 18#include <arpa/inet.h>
19 19
20/* from <linux/fib_rules.h>: */
21#define FRA_SUPPRESS_IFGROUP 13
22#define FRA_SUPPRESS_PREFIXLEN 14
23
20#include "ip_common.h" /* #include "libbb.h" is inside */ 24#include "ip_common.h" /* #include "libbb.h" is inside */
21#include "rt_names.h" 25#include "rt_names.h"
22#include "utils.h" 26#include "utils.h"
23 27
24/* 28/* If you add stuff here, update iprule_full_usage */
25static void usage(void) __attribute__((noreturn)); 29static const char keywords[] ALIGN1 =
26 30 "from\0""to\0""preference\0""order\0""priority\0"
27static void usage(void) 31 "tos\0""fwmark\0""realms\0""table\0""lookup\0"
28{ 32 "suppress_prefixlength\0""suppress_ifgroup\0"
29 fprintf(stderr, "Usage: ip rule [ list | add | del ] SELECTOR ACTION\n"); 33 "dev\0""iif\0""nat\0""map-to\0""type\0""help\0"
30 fprintf(stderr, "SELECTOR := [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK ]\n"); 34 ;
31 fprintf(stderr, " [ dev STRING ] [ pref NUMBER ]\n"); 35#define keyword_preference (keywords + sizeof("from") + sizeof("to"))
32 fprintf(stderr, "ACTION := [ table TABLE_ID ] [ nat ADDRESS ]\n"); 36#define keyword_fwmark (keyword_preference + sizeof("preference") + sizeof("order") + sizeof("priority") + sizeof("tos"))
33 fprintf(stderr, " [ prohibit | reject | unreachable ]\n"); 37#define keyword_realms (keyword_fwmark + sizeof("fwmark"))
34 fprintf(stderr, " [ realms [SRCREALM/]DSTREALM ]\n"); 38#define keyword_suppress_prefixlength (keyword_realms + sizeof("realms") + sizeof("table") + sizeof("lookup"))
35 fprintf(stderr, "TABLE_ID := [ local | main | default | NUMBER ]\n"); 39#define keyword_suppress_ifgroup (keyword_suppress_prefixlength + sizeof("suppress_prefixlength"))
36 exit(-1); 40enum {
37} 41 ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
38*/ 42 ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup,
43 ARG_suppress_prefixlength, ARG_suppress_ifgroup,
44 ARG_dev, ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help,
45};
39 46
40static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, 47static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
41 struct nlmsghdr *n, void *arg UNUSED_PARAM) 48 struct nlmsghdr *n, void *arg UNUSED_PARAM)
@@ -119,6 +126,17 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
119 else if (r->rtm_table) 126 else if (r->rtm_table)
120 printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table)); 127 printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table));
121 128
129 if (tb[FRA_SUPPRESS_PREFIXLEN]) {
130 int pl = *(uint32_t*)RTA_DATA(tb[FRA_SUPPRESS_PREFIXLEN]);
131 if (pl != -1)
132 printf("%s %d ", keyword_suppress_prefixlength, pl);
133 }
134 if (tb[FRA_SUPPRESS_IFGROUP]) {
135 int grp = *(uint32_t*)RTA_DATA(tb[FRA_SUPPRESS_IFGROUP]);
136 if (grp != -1)
137 printf("%s %d ", keyword_suppress_ifgroup, grp);
138 }
139
122 if (tb[RTA_FLOW]) { 140 if (tb[RTA_FLOW]) {
123 uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]); 141 uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]);
124 uint32_t from = to>>16; 142 uint32_t from = to>>16;
@@ -174,15 +192,6 @@ static int iprule_list(char **argv)
174/* Return value becomes exitcode. It's okay to not return at all */ 192/* Return value becomes exitcode. It's okay to not return at all */
175static int iprule_modify(int cmd, char **argv) 193static int iprule_modify(int cmd, char **argv)
176{ 194{
177 static const char keywords[] ALIGN1 =
178 "from\0""to\0""preference\0""order\0""priority\0"
179 "tos\0""fwmark\0""realms\0""table\0""lookup\0""dev\0"
180 "iif\0""nat\0""map-to\0""type\0""help\0";
181 enum {
182 ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
183 ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup, ARG_dev,
184 ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help
185 };
186 bool table_ok = 0; 195 bool table_ok = 0;
187 struct rtnl_handle rth; 196 struct rtnl_handle rth;
188 struct { 197 struct {
@@ -232,7 +241,7 @@ static int iprule_modify(int cmd, char **argv)
232 ) { 241 ) {
233 uint32_t pref; 242 uint32_t pref;
234 NEXT_ARG(); 243 NEXT_ARG();
235 pref = get_u32(*argv, "preference"); 244 pref = get_u32(*argv, keyword_preference);
236 addattr32(&req.n, sizeof(req), RTA_PRIORITY, pref); 245 addattr32(&req.n, sizeof(req), RTA_PRIORITY, pref);
237 } else if (key == ARG_tos) { 246 } else if (key == ARG_tos) {
238 uint32_t tos; 247 uint32_t tos;
@@ -243,13 +252,13 @@ static int iprule_modify(int cmd, char **argv)
243 } else if (key == ARG_fwmark) { 252 } else if (key == ARG_fwmark) {
244 uint32_t fwmark; 253 uint32_t fwmark;
245 NEXT_ARG(); 254 NEXT_ARG();
246 fwmark = get_u32(*argv, "fwmark"); 255 fwmark = get_u32(*argv, keyword_fwmark);
247 addattr32(&req.n, sizeof(req), RTA_PROTOINFO, fwmark); 256 addattr32(&req.n, sizeof(req), RTA_PROTOINFO, fwmark);
248 } else if (key == ARG_realms) { 257 } else if (key == ARG_realms) {
249 uint32_t realm; 258 uint32_t realm;
250 NEXT_ARG(); 259 NEXT_ARG();
251 if (get_rt_realms(&realm, *argv)) 260 if (get_rt_realms(&realm, *argv))
252 invarg_1_to_2(*argv, "realms"); 261 invarg_1_to_2(*argv, keyword_realms);
253 addattr32(&req.n, sizeof(req), RTA_FLOW, realm); 262 addattr32(&req.n, sizeof(req), RTA_FLOW, realm);
254 } else if (key == ARG_table || 263 } else if (key == ARG_table ||
255 key == ARG_lookup 264 key == ARG_lookup
@@ -265,6 +274,16 @@ static int iprule_modify(int cmd, char **argv)
265 addattr32(&req.n, sizeof(req), RTA_TABLE, tid); 274 addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
266 } 275 }
267 table_ok = 1; 276 table_ok = 1;
277 } else if (key == ARG_suppress_prefixlength) {
278 int prefix_length;
279 NEXT_ARG();
280 prefix_length = get_u32(*argv, keyword_suppress_prefixlength);
281 addattr32(&req.n, sizeof(req), FRA_SUPPRESS_PREFIXLEN, prefix_length);
282 } else if (key == ARG_suppress_ifgroup) {
283 int grp;
284 NEXT_ARG();
285 grp = get_u32(*argv, keyword_suppress_ifgroup);
286 addattr32(&req.n, sizeof(req), FRA_SUPPRESS_IFGROUP, grp);
268 } else if (key == ARG_dev || 287 } else if (key == ARG_dev ||
269 key == ARG_iif 288 key == ARG_iif
270 ) { 289 ) {