[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] add ip sub commands needed by wg-quick script
From:       Konstantin Koshelev <kkoshelev () gmail ! com>
Date:       2022-05-11 21:47:51
Message-ID: CACNitXAOjDZsSfRLiEDTmf59qQc+TtNYTa6eqXuDa_rtU_DpyA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


1. "ip rule" now supports "not" keyword.
2. "ip" command now supports arbitrary numeric routing tables above 1024.

--- a/networking/libiproute/iprule.c 2021-01-01 05:30:02.000000000 -0800
+++ b/iprule.c 2022-05-10 16:32:10.781087924 -0700
@@ -19,6 +19,7 @@
 /* from <linux/fib_rules.h>: */
 #define FRA_SUPPRESS_IFGROUP   13
 #define FRA_SUPPRESS_PREFIXLEN 14
+#define FIB_RULE_INVERT     0x00000002

 #include "ip_common.h"  /* #include "libbb.h" is inside */
 #include "rt_names.h"
@@ -31,18 +32,18 @@

 /* If you add stuff here, update iprule_full_usage */
 static const char keywords[] ALIGN1 =
- "from\0""to\0""preference\0""order\0""priority\0"
+ "not\0""from\0""to\0""preference\0""order\0""priority\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"
  ;
-#define keyword_preference            (keywords           + sizeof("from")
+ sizeof("to"))
+#define keyword_preference            (keywords           + sizeof("not")
+ sizeof("from") + sizeof("to"))
 #define keyword_fwmark                (keyword_preference +
sizeof("preference") + sizeof("order") + sizeof("priority") + sizeof("tos"))
 #define keyword_realms                (keyword_fwmark     +
sizeof("fwmark"))
 #define keyword_suppress_prefixlength (keyword_realms     +
sizeof("realms") + sizeof("table") + sizeof("lookup"))
 #define keyword_suppress_ifgroup      (keyword_suppress_prefixlength +
sizeof("suppress_prefixlength"))
 enum {
- ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
+ ARG_not = 1, ARG_from, ARG_to, ARG_preference, ARG_order, ARG_priority,
  ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup,
  ARG_suppress_prefixlength, ARG_suppress_ifgroup,
  ARG_dev, ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help,
@@ -78,6 +79,10 @@
  printf("%u:\t", tb[RTA_PRIORITY] ?
  *(unsigned*)RTA_DATA(tb[RTA_PRIORITY])
  : 0);
+
+ if (r->rtm_flags & FIB_RULE_INVERT)
+ printf("not ");
+
  printf("from ");
  if (tb[RTA_SRC]) {
  if (r->rtm_src_len != host_len) {
@@ -230,7 +235,9 @@
  key = index_in_substrings(keywords, *argv) + 1;
  if (key == 0) /* no match found in keywords array, bail out. */
  invarg_1_to_2(*argv, applet_name);
- if (key == ARG_from) {
+ if (key == ARG_not) {
+ req.r.rtm_flags |= FIB_RULE_INVERT;
+ } else if (key == ARG_from) {
  inet_prefix dst;
  NEXT_ARG();
  get_prefix(&dst, *argv, req.r.rtm_family);
--- a/networking/libiproute/rt_names.c 2021-01-01 05:30:02.000000000 -0800
+++ b/rt_names.c 2022-05-10 16:50:30.298597124 -0700
@@ -251,7 +251,14 @@
 int FAST_FUNC rtnl_rttable_a2n(uint32_t *id, char *arg)
 {
  rtnl_rttable_initialize();
- return rtnl_a2n(rtnl_rttable_tab, id, arg, 0);
+    if (!rtnl_a2n(rtnl_rttable_tab, id, arg, 0)) return 0;
+
+ unsigned i = bb_strtou(arg, NULL, 0);
+ if (i > RT_TABLE_MAX) {
+ *id = i;
+ return 0;
+ }
+ return -1;
 }

 #endif

[Attachment #5 (text/html)]

<div dir="ltr"><div class="gmail_default" style="font-size:small">1. &quot;ip \
rule&quot; now supports &quot;not&quot; keyword.</div>2. &quot;ip&quot; command now \
supports arbitrary numeric routing tables above 1024.<br><br>--- \
a/networking/libiproute/iprule.c	2021-01-01 05:30:02.000000000 -0800<br>+++ \
b/iprule.c	2022-05-10 16:32:10.781087924 -0700<br>@@ -19,6 +19,7 @@<br>  /* from \
&lt;linux/fib_rules.h&gt;: */<br>  #define FRA_SUPPRESS_IFGROUP    13<br>  #define \
FRA_SUPPRESS_PREFIXLEN 14<br>+#define FIB_RULE_INVERT       0x00000002<br><br>  \
#include &quot;ip_common.h&quot;   /* #include &quot;libbb.h&quot; is inside */<br>  \
#include &quot;rt_names.h&quot;<br>@@ -31,18 +32,18 @@<br><br>  /* If you add stuff \
here, update iprule_full_usage */<br>  static const char keywords[] ALIGN1 \
=<br>-	&quot;from\0&quot;&quot;to\0&quot;&quot;preference\0&quot;&quot;order\0&quot;&q \
uot;priority\0&quot;<br>+	&quot;not\0&quot;&quot;from\0&quot;&quot;to\0&quot;&quot;preference\0&quot;&quot;order\0&quot;&quot;priority\0&quot;<br> \
&quot;tos\0&quot;&quot;fwmark\0&quot;&quot;realms\0&quot;&quot;table\0&quot;&quot;lookup\0&quot;<br> \
&quot;suppress_prefixlength\0&quot;&quot;suppress_ifgroup\0&quot;<br>  \
&quot;dev\0&quot;&quot;iif\0&quot;&quot;nat\0&quot;&quot;map-to\0&quot;&quot;type\0&quot;&quot;help\0&quot;<br> \
;<br>-#define keyword_preference                  (keywords                + \
sizeof(&quot;from&quot;) + sizeof(&quot;to&quot;))<br>+#define keyword_preference     \
(keywords                + sizeof(&quot;not&quot;) + sizeof(&quot;from&quot;) + \
sizeof(&quot;to&quot;))<br>  #define keyword_fwmark                        \
(keyword_preference + sizeof(&quot;preference&quot;) + sizeof(&quot;order&quot;) + \
sizeof(&quot;priority&quot;) + sizeof(&quot;tos&quot;))<br>  #define keyword_realms   \
(keyword_fwmark       + sizeof(&quot;fwmark&quot;))<br>  #define \
keyword_suppress_prefixlength (keyword_realms       + sizeof(&quot;realms&quot;) + \
sizeof(&quot;table&quot;) + sizeof(&quot;lookup&quot;))<br>  #define \
keyword_suppress_ifgroup         (keyword_suppress_prefixlength + \
sizeof(&quot;suppress_prefixlength&quot;))<br>  enum {<br>-	ARG_from = 1, ARG_to, \
ARG_preference, ARG_order, ARG_priority,<br>+	ARG_not = 1, ARG_from, ARG_to, \
ARG_preference, ARG_order, ARG_priority,<br>  	ARG_tos, ARG_fwmark, ARG_realms, \
ARG_table, ARG_lookup,<br>  	ARG_suppress_prefixlength, ARG_suppress_ifgroup,<br>  \
ARG_dev, ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help,<br>@@ -78,6 +79,10 @@<br>  \
printf(&quot;%u:\t&quot;, tb[RTA_PRIORITY] ?<br>  \
*(unsigned*)RTA_DATA(tb[RTA_PRIORITY])<br>  					: 0);<br>+<br>+	if (r-&gt;rtm_flags \
&amp; FIB_RULE_INVERT)<br>+		printf(&quot;not &quot;);<br>+<br>  	printf(&quot;from \
&quot;);<br>  	if (tb[RTA_SRC]) {<br>  		if (r-&gt;rtm_src_len != host_len) {<br>@@ \
-230,7 +235,9 @@<br>  		key = index_in_substrings(keywords, *argv) + 1;<br>  		if \
(key == 0) /* no match found in keywords array, bail out. */<br>  \
invarg_1_to_2(*argv, applet_name);<br>-		if (key == ARG_from) {<br>+		if (key == \
ARG_not) {<br>+			req.r.rtm_flags |= FIB_RULE_INVERT;<br>+		} else if (key == \
ARG_from) {<br>  			inet_prefix dst;<br>  			NEXT_ARG();<br>  			get_prefix(&amp;dst, \
*argv, req.r.rtm_family);<br>--- a/networking/libiproute/rt_names.c	2021-01-01 \
05:30:02.000000000 -0800<br>+++ b/rt_names.c	2022-05-10 16:50:30.298597124 \
-0700<br>@@ -251,7 +251,14 @@<br>  int FAST_FUNC rtnl_rttable_a2n(uint32_t *id, char \
*arg)<br>  {<br>  	rtnl_rttable_initialize();<br>-	return rtnl_a2n(rtnl_rttable_tab, \
id, arg, 0);<br>+      if (!rtnl_a2n(rtnl_rttable_tab, id, arg, 0)) return \
0;<br>+<br>+	unsigned i = bb_strtou(arg, NULL, 0);<br>+	if (i &gt; RT_TABLE_MAX) \
{<br>+		*id = i;<br>+		return 0;<br>+	}<br>+	return -1;<br>  }<br><br>  #endif<br>  \
<br></div>



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic