[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. "ip \
rule" now supports "not" keyword.</div>2. "ip" 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 \
<linux/fib_rules.h>: */<br> #define FRA_SUPPRESS_IFGROUP 13<br> #define \
FRA_SUPPRESS_PREFIXLEN 14<br>+#define FIB_RULE_INVERT 0x00000002<br><br> \
#include "ip_common.h" /* #include "libbb.h" is inside */<br> \
#include "rt_names.h"<br>@@ -31,18 +32,18 @@<br><br> /* If you add stuff \
here, update iprule_full_usage */<br> static const char keywords[] ALIGN1 \
=<br>- "from\0""to\0""preference\0""order\0"&q \
uot;priority\0"<br>+ "not\0""from\0""to\0""preference\0""order\0""priority\0"<br> \
"tos\0""fwmark\0""realms\0""table\0""lookup\0"<br> \
"suppress_prefixlength\0""suppress_ifgroup\0"<br> \
"dev\0""iif\0""nat\0""map-to\0""type\0""help\0"<br> \
;<br>-#define keyword_preference (keywords + \
sizeof("from") + sizeof("to"))<br>+#define keyword_preference \
(keywords + sizeof("not") + sizeof("from") + \
sizeof("to"))<br> #define keyword_fwmark \
(keyword_preference + sizeof("preference") + sizeof("order") + \
sizeof("priority") + sizeof("tos"))<br> #define keyword_realms \
(keyword_fwmark + sizeof("fwmark"))<br> #define \
keyword_suppress_prefixlength (keyword_realms + sizeof("realms") + \
sizeof("table") + sizeof("lookup"))<br> #define \
keyword_suppress_ifgroup (keyword_suppress_prefixlength + \
sizeof("suppress_prefixlength"))<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("%u:\t", tb[RTA_PRIORITY] ?<br> \
*(unsigned*)RTA_DATA(tb[RTA_PRIORITY])<br> : 0);<br>+<br>+ if (r->rtm_flags \
& FIB_RULE_INVERT)<br>+ printf("not ");<br>+<br> printf("from \
");<br> if (tb[RTA_SRC]) {<br> if (r->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(&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 > 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