aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/libiproute/iproute.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index d232ee6fd..82827488f 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -313,12 +313,13 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
313static int iproute_modify(int cmd, unsigned flags, char **argv) 313static int iproute_modify(int cmd, unsigned flags, char **argv)
314{ 314{
315 static const char keywords[] ALIGN1 = 315 static const char keywords[] ALIGN1 =
316 "src\0""via\0""mtu\0""lock\0""protocol\0"IF_FEATURE_IP_RULE("table\0") 316 "src\0""via\0""mtu\0""lock\0""scope\0""protocol\0"IF_FEATURE_IP_RULE("table\0")
317 "dev\0""oif\0""to\0""metric\0""onlink\0"; 317 "dev\0""oif\0""to\0""metric\0""onlink\0";
318 enum { 318 enum {
319 ARG_src, 319 ARG_src,
320 ARG_via, 320 ARG_via,
321 ARG_mtu, PARM_lock, 321 ARG_mtu, PARM_lock,
322 ARG_scope,
322 ARG_protocol, 323 ARG_protocol,
323IF_FEATURE_IP_RULE(ARG_table,) 324IF_FEATURE_IP_RULE(ARG_table,)
324 ARG_dev, 325 ARG_dev,
@@ -344,6 +345,7 @@ IF_FEATURE_IP_RULE(ARG_table,)
344 unsigned mxlock = 0; 345 unsigned mxlock = 0;
345 char *d = NULL; 346 char *d = NULL;
346 smalluint ok = 0; 347 smalluint ok = 0;
348 smalluint scope_ok = 0;
347 int arg; 349 int arg;
348 350
349 memset(&req, 0, sizeof(req)); 351 memset(&req, 0, sizeof(req));
@@ -352,15 +354,18 @@ IF_FEATURE_IP_RULE(ARG_table,)
352 req.n.nlmsg_flags = NLM_F_REQUEST | flags; 354 req.n.nlmsg_flags = NLM_F_REQUEST | flags;
353 req.n.nlmsg_type = cmd; 355 req.n.nlmsg_type = cmd;
354 req.r.rtm_family = preferred_family; 356 req.r.rtm_family = preferred_family;
355 if (RT_TABLE_MAIN) /* if it is zero, memset already did it */ 357 if (RT_TABLE_MAIN != 0) /* if it is zero, memset already did it */
356 req.r.rtm_table = RT_TABLE_MAIN; 358 req.r.rtm_table = RT_TABLE_MAIN;
357 if (RT_SCOPE_NOWHERE) 359 if (RT_SCOPE_NOWHERE != 0)
358 req.r.rtm_scope = RT_SCOPE_NOWHERE; 360 req.r.rtm_scope = RT_SCOPE_NOWHERE;
359 361
360 if (cmd != RTM_DELROUTE) { 362 if (cmd != RTM_DELROUTE) {
361 req.r.rtm_protocol = RTPROT_BOOT; 363 if (RTPROT_BOOT != 0)
362 req.r.rtm_scope = RT_SCOPE_UNIVERSE; 364 req.r.rtm_protocol = RTPROT_BOOT;
363 req.r.rtm_type = RTN_UNICAST; 365 if (RT_SCOPE_UNIVERSE != 0)
366 req.r.rtm_scope = RT_SCOPE_UNIVERSE;
367 if (RTN_UNICAST != 0)
368 req.r.rtm_type = RTN_UNICAST;
364 } 369 }
365 370
366 mxrta->rta_type = RTA_METRICS; 371 mxrta->rta_type = RTA_METRICS;
@@ -393,6 +398,13 @@ IF_FEATURE_IP_RULE(ARG_table,)
393 } 398 }
394 mtu = get_unsigned(*argv, "mtu"); 399 mtu = get_unsigned(*argv, "mtu");
395 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu); 400 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu);
401 } else if (arg == ARG_scope) {
402 uint32_t scope;
403 NEXT_ARG();
404 if (rtnl_rtscope_a2n(&scope, *argv))
405 invarg_1_to_2(*argv, "scope");
406 req.r.rtm_scope = scope;
407 scope_ok = 1;
396 } else if (arg == ARG_protocol) { 408 } else if (arg == ARG_protocol) {
397 uint32_t prot; 409 uint32_t prot;
398 NEXT_ARG(); 410 NEXT_ARG();
@@ -469,20 +481,22 @@ IF_FEATURE_IP_RULE(ARG_table,)
469 addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta)); 481 addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta));
470 } 482 }
471 483
472 if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT) 484 if (!scope_ok) {
473 req.r.rtm_scope = RT_SCOPE_HOST; 485 if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT)
474 else 486 req.r.rtm_scope = RT_SCOPE_HOST;
475 if (req.r.rtm_type == RTN_BROADCAST 487 else
476 || req.r.rtm_type == RTN_MULTICAST 488 if (req.r.rtm_type == RTN_BROADCAST
477 || req.r.rtm_type == RTN_ANYCAST 489 || req.r.rtm_type == RTN_MULTICAST
478 ) { 490 || req.r.rtm_type == RTN_ANYCAST
479 req.r.rtm_scope = RT_SCOPE_LINK; 491 ) {
480 }
481 else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) {
482 if (cmd == RTM_DELROUTE)
483 req.r.rtm_scope = RT_SCOPE_NOWHERE;
484 else if (!(ok & gw_ok))
485 req.r.rtm_scope = RT_SCOPE_LINK; 492 req.r.rtm_scope = RT_SCOPE_LINK;
493 }
494 else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) {
495 if (cmd == RTM_DELROUTE)
496 req.r.rtm_scope = RT_SCOPE_NOWHERE;
497 else if (!(ok & gw_ok))
498 req.r.rtm_scope = RT_SCOPE_LINK;
499 }
486 } 500 }
487 501
488 if (req.r.rtm_family == AF_UNSPEC) { 502 if (req.r.rtm_family == AF_UNSPEC) {