[PATCH] add suppress_{prefixlength,ifgroup} options to 'ip rule' applet

Stefan Tomanek stefan.tomanek at wertarbyte.de
Tue Jun 13 07:00:25 UTC 2017


Signed-off-by: Stefan Tomanek <stefan.tomanek at wertarbyte.de>
---
 networking/libiproute/iprule.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index 8f3f862..3b096fa 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -17,6 +17,8 @@
 #include <netinet/ip.h>
 #include <arpa/inet.h>
 
+#include <linux/fib_rules.h>
+
 #include "ip_common.h"  /* #include "libbb.h" is inside */
 #include "rt_names.h"
 #include "utils.h"
@@ -119,6 +121,17 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
 	else if (r->rtm_table)
 		printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table));
 
+	if (tb[FRA_SUPPRESS_PREFIXLEN]) {
+		int pl = *(uint32_t*)RTA_DATA(tb[FRA_SUPPRESS_PREFIXLEN]);
+		if (pl != -1)
+			printf("suppress_prefixlength %d ", pl);
+	}
+	if (tb[FRA_SUPPRESS_IFGROUP]) {
+		int grp = *(uint32_t*)RTA_DATA(tb[FRA_SUPPRESS_IFGROUP]);
+		if (grp != -1)
+			printf("suppress_ifgroup %d ", grp);
+	}
+
 	if (tb[RTA_FLOW]) {
 		uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]);
 		uint32_t from = to>>16;
@@ -176,12 +189,15 @@ static int iprule_modify(int cmd, char **argv)
 {
 	static const char keywords[] ALIGN1 =
 		"from\0""to\0""preference\0""order\0""priority\0"
-		"tos\0""fwmark\0""realms\0""table\0""lookup\0""dev\0"
-		"iif\0""nat\0""map-to\0""type\0""help\0";
+		"tos\0""fwmark\0""realms\0""table\0""lookup\0"
+		"suppress_prefixlength\0""suppress_ifgroup\0"
+		"dev\0""iif\0""nat\0""map-to\0""type\0""help\0"
+		;
 	enum {
 		ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
-		ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup, ARG_dev,
-		ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help
+		ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup,
+		ARG_sup_pl, ARG_sup_ifgrp,
+		ARG_dev,ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help,
 	};
 	bool table_ok = 0;
 	struct rtnl_handle rth;
@@ -265,6 +281,16 @@ static int iprule_modify(int cmd, char **argv)
 				addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
 			}
 			table_ok = 1;
+		} else if (key == ARG_sup_pl) {
+			int prefix_length;
+			NEXT_ARG();
+			prefix_length = get_u32(*argv, "suppress_prefixlength");
+			addattr32(&req.n, sizeof(req), FRA_SUPPRESS_PREFIXLEN, prefix_length);
+		} else if (key == ARG_sup_ifgrp) {
+			int grp;
+			NEXT_ARG();
+			grp = get_u32(*argv, "suppress_ifgroup");
+			addattr32(&req.n, sizeof(req), FRA_SUPPRESS_IFGROUP, grp);
 		} else if (key == ARG_dev ||
 			   key == ARG_iif
 		) {
-- 
2.1.4


More information about the busybox mailing list