Refresh patches, delete patches that have been applied upstream. Signed-off-by: Magnus Kroken <mkroken@gmail.com> Tested-by: Koen Vandeputte <koen.vandeputte@ncentric.com> Signed-off-by: Felix Fietkau <nbd@nbd.name> [fix defaults]master
parent
5d2a9d2a3a
commit
84da2a677a
File diff suppressed because it is too large
Load Diff
@ -1,37 +0,0 @@ |
||||
From 7cef4817d6d6d61a1166ed7dfc13537b95c65970 Mon Sep 17 00:00:00 2001
|
||||
From: Denys Vlasenko <vda.linux@googlemail.com>
|
||||
Date: Thu, 15 Sep 2016 13:20:51 +0200
|
||||
Subject: [PATCH] libbb:/send_to_from: do not require that "to" should have the
|
||||
same AF. Closes 9146
|
||||
|
||||
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
||||
---
|
||||
libbb/udp_io.c | 10 ++++++++--
|
||||
1 file changed, 8 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/libbb/udp_io.c
|
||||
+++ b/libbb/udp_io.c
|
||||
@@ -70,7 +70,13 @@ send_to_from(int fd, void *buf, size_t l
|
||||
msg.msg_flags = flags;
|
||||
|
||||
cmsgptr = CMSG_FIRSTHDR(&msg);
|
||||
- if (to->sa_family == AF_INET && from->sa_family == AF_INET) {
|
||||
+ /*
|
||||
+ * Users report that to->sa_family can be AF_INET6 too,
|
||||
+ * if "to" was acquired by recv_from_to(). IOW: recv_from_to()
|
||||
+ * was seen showing IPv6 "from" even when the destination
|
||||
+ * of received packet (our local address) was IPv4.
|
||||
+ */
|
||||
+ if (/* to->sa_family == AF_INET && */ from->sa_family == AF_INET) {
|
||||
struct in_pktinfo *pktptr;
|
||||
cmsgptr->cmsg_level = IPPROTO_IP;
|
||||
cmsgptr->cmsg_type = IP_PKTINFO;
|
||||
@@ -86,7 +92,7 @@ send_to_from(int fd, void *buf, size_t l
|
||||
pktptr->ipi_spec_dst = ((struct sockaddr_in*)from)->sin_addr;
|
||||
}
|
||||
# if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO)
|
||||
- else if (to->sa_family == AF_INET6 && from->sa_family == AF_INET6) {
|
||||
+ else if (/* to->sa_family == AF_INET6 && */ from->sa_family == AF_INET6) {
|
||||
struct in6_pktinfo *pktptr;
|
||||
cmsgptr->cmsg_level = IPPROTO_IPV6;
|
||||
cmsgptr->cmsg_type = IPV6_PKTINFO;
|
@ -1,20 +0,0 @@ |
||||
--- a/scripts/trylink
|
||||
+++ b/scripts/trylink
|
||||
@@ -46,7 +46,7 @@ try() {
|
||||
}
|
||||
|
||||
check_cc() {
|
||||
- local tempname="$(mktemp)"
|
||||
+ local tempname="$(mktemp /tmp/tmp.XXXXXXXXXX)"
|
||||
local r
|
||||
echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c
|
||||
# Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :(
|
||||
@@ -61,7 +61,7 @@ check_cc() {
|
||||
}
|
||||
|
||||
check_libc_is_glibc() {
|
||||
- local tempname="$(mktemp)"
|
||||
+ local tempname="$(mktemp /tmp/tmp.XXXXXXXXXX)"
|
||||
local r
|
||||
echo "\
|
||||
#include <stdlib.h>
|
@ -1,100 +0,0 @@ |
||||
From a843f09a4d4428cf11ca02307e60058251b05743 Mon Sep 17 00:00:00 2001
|
||||
From: Hauke Mehrtens <hauke@hauke-m.de>
|
||||
Date: Fri, 16 Sep 2016 21:52:03 +0200
|
||||
Subject: [PATCH] libnetlink: fix alignment of netlink messages
|
||||
|
||||
An padding to align a message should not only be added between
|
||||
different attributes of a netlink message, but also at the end of the
|
||||
message to pad it to the correct size.
|
||||
|
||||
Without this patch the following command does not work and returns an
|
||||
error code:
|
||||
ip link add type nlmon
|
||||
|
||||
Without this ip from busybox sends this:
|
||||
sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=45, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK|0x600, seq=1474057401, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon"}, iov_len=45}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 45
|
||||
return value: 2
|
||||
|
||||
The normal ip utile from iproute2 sends this:
|
||||
sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=48, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK|0x600, seq=1473716938, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
|
||||
return value: 0
|
||||
|
||||
With this patch ip from busybox sends this:
|
||||
sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=48, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK|0x600, seq=1473716908, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
|
||||
return value: 0
|
||||
|
||||
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
|
||||
---
|
||||
networking/libiproute/libnetlink.c | 16 ++++++++--------
|
||||
1 file changed, 8 insertions(+), 8 deletions(-)
|
||||
|
||||
--- a/networking/libiproute/libnetlink.c
|
||||
+++ b/networking/libiproute/libnetlink.c
|
||||
@@ -338,14 +338,14 @@ int FAST_FUNC addattr32(struct nlmsghdr
|
||||
int len = RTA_LENGTH(4);
|
||||
struct rtattr *rta;
|
||||
|
||||
- if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) {
|
||||
+ if ((int)(NLMSG_ALIGN(n->nlmsg_len + len)) > maxlen) {
|
||||
return -1;
|
||||
}
|
||||
rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
|
||||
rta->rta_type = type;
|
||||
rta->rta_len = len;
|
||||
move_to_unaligned32(RTA_DATA(rta), data);
|
||||
- n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
|
||||
+ n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len + len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -354,14 +354,14 @@ int FAST_FUNC addattr_l(struct nlmsghdr
|
||||
int len = RTA_LENGTH(alen);
|
||||
struct rtattr *rta;
|
||||
|
||||
- if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) {
|
||||
+ if ((int)(NLMSG_ALIGN(n->nlmsg_len + len)) > maxlen) {
|
||||
return -1;
|
||||
}
|
||||
rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
|
||||
rta->rta_type = type;
|
||||
rta->rta_len = len;
|
||||
memcpy(RTA_DATA(rta), data, alen);
|
||||
- n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
|
||||
+ n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len + len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -370,14 +370,14 @@ int FAST_FUNC rta_addattr32(struct rtatt
|
||||
int len = RTA_LENGTH(4);
|
||||
struct rtattr *subrta;
|
||||
|
||||
- if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
|
||||
+ if (RTA_ALIGN(rta->rta_len + len) > maxlen) {
|
||||
return -1;
|
||||
}
|
||||
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
|
||||
subrta->rta_type = type;
|
||||
subrta->rta_len = len;
|
||||
move_to_unaligned32(RTA_DATA(subrta), data);
|
||||
- rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
|
||||
+ rta->rta_len = NLMSG_ALIGN(rta->rta_len + len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -386,14 +386,14 @@ int FAST_FUNC rta_addattr_l(struct rtatt
|
||||
struct rtattr *subrta;
|
||||
int len = RTA_LENGTH(alen);
|
||||
|
||||
- if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
|
||||
+ if (RTA_ALIGN(rta->rta_len + len) > maxlen) {
|
||||
return -1;
|
||||
}
|
||||
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
|
||||
subrta->rta_type = type;
|
||||
subrta->rta_len = len;
|
||||
memcpy(RTA_DATA(subrta), data, alen);
|
||||
- rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
|
||||
+ rta->rta_len = NLMSG_ALIGN(rta->rta_len + len);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,486 +0,0 @@ |
||||
From 485fcc89b99eae9cc7501eaff344b104e52ab7bf Mon Sep 17 00:00:00 2001
|
||||
From: Jo-Philipp Wich <jo@mein.io>
|
||||
Date: Mon, 26 Sep 2016 17:48:22 +0200
|
||||
Subject: [PATCH] iproute: properly support high routing table IDs
|
||||
|
||||
The Linux kernel uses two distinct fields to denote the routing table ID in
|
||||
use by network routes; the 8 bit `rtm_table` member of `struct rtmsg` and the
|
||||
32 bit `RTA_TABLE` netlink attribute.
|
||||
|
||||
If a routing table ID is larger than 255, the `RT_TABLE` attribute must be used
|
||||
and the `rtm_table` field has to be set to the special `RT_TABLE_UNSPEC` value.
|
||||
|
||||
This commit ...
|
||||
- switches the *_n2a() and *_a2n() functions of rt_names.c to use dynamically
|
||||
sized, name-sorted arrays instead of fixed arrays limited to 1024 slots in
|
||||
order to support IDs up to 65535
|
||||
- adds proper handling of high table IDs to iprule.c and iproute.c when
|
||||
adding, removing and dumping ip rules and network routes
|
||||
|
||||
After this change, the Busybox ip applet fully supports IP rules with high ID
|
||||
numbers, using the same logic as the full iproute2.
|
||||
|
||||
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
||||
---
|
||||
networking/libiproute/iproute.c | 75 ++++++++------
|
||||
networking/libiproute/iprule.c | 4 +-
|
||||
networking/libiproute/rt_names.c | 204 +++++++++++++++++++++++----------------
|
||||
3 files changed, 169 insertions(+), 114 deletions(-)
|
||||
|
||||
--- a/networking/libiproute/iproute.c
|
||||
+++ b/networking/libiproute/iproute.c
|
||||
@@ -66,6 +66,7 @@ static int FAST_FUNC print_route(const s
|
||||
inet_prefix dst;
|
||||
inet_prefix src;
|
||||
int host_len = -1;
|
||||
+ uint32_t rtable;
|
||||
|
||||
if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
|
||||
fprintf(stderr, "Not a route: %08x %08x %08x\n",
|
||||
@@ -83,34 +84,6 @@ static int FAST_FUNC print_route(const s
|
||||
else if (r->rtm_family == AF_INET)
|
||||
host_len = 32;
|
||||
|
||||
- if (r->rtm_family == AF_INET6) {
|
||||
- if (G_filter.tb) {
|
||||
- if (G_filter.tb < 0) {
|
||||
- if (!(r->rtm_flags & RTM_F_CLONED)) {
|
||||
- return 0;
|
||||
- }
|
||||
- } else {
|
||||
- if (r->rtm_flags & RTM_F_CLONED) {
|
||||
- return 0;
|
||||
- }
|
||||
- if (G_filter.tb == RT_TABLE_LOCAL) {
|
||||
- if (r->rtm_type != RTN_LOCAL) {
|
||||
- return 0;
|
||||
- }
|
||||
- } else if (G_filter.tb == RT_TABLE_MAIN) {
|
||||
- if (r->rtm_type == RTN_LOCAL) {
|
||||
- return 0;
|
||||
- }
|
||||
- } else {
|
||||
- return 0;
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- } else {
|
||||
- if (G_filter.tb > 0 && G_filter.tb != r->rtm_table) {
|
||||
- return 0;
|
||||
- }
|
||||
- }
|
||||
if (G_filter.rdst.family
|
||||
&& (r->rtm_family != G_filter.rdst.family || G_filter.rdst.bitlen > r->rtm_dst_len)
|
||||
) {
|
||||
@@ -141,6 +114,37 @@ static int FAST_FUNC print_route(const s
|
||||
memset(&dst, 0, sizeof(dst));
|
||||
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
|
||||
|
||||
+ rtable = tb[RTA_TABLE] ? *(uint32_t*)RTA_DATA(tb[RTA_TABLE]) : r->rtm_table;
|
||||
+
|
||||
+ if (G_filter.tb) {
|
||||
+ if (r->rtm_family == AF_INET6) {
|
||||
+ if (G_filter.tb < 0) {
|
||||
+ if (!(r->rtm_flags & RTM_F_CLONED)) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (r->rtm_flags & RTM_F_CLONED) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ if (G_filter.tb == RT_TABLE_LOCAL) {
|
||||
+ if (r->rtm_type != RTN_LOCAL) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ } else if (G_filter.tb == RT_TABLE_MAIN) {
|
||||
+ if (r->rtm_type == RTN_LOCAL) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ } else if (G_filter.tb != rtable) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (G_filter.tb != rtable) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
if (tb[RTA_SRC]) {
|
||||
src.bitlen = r->rtm_src_len;
|
||||
src.bytelen = (r->rtm_family == AF_INET6 ? 16 : 4);
|
||||
@@ -349,7 +353,9 @@ IF_FEATURE_IP_RULE(ARG_table,)
|
||||
smalluint ok = 0;
|
||||
smalluint scope_ok = 0;
|
||||
int arg;
|
||||
-
|
||||
+#if ENABLE_FEATURE_IP_RULE
|
||||
+ uint32_t rtable = 0;
|
||||
+#endif
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
||||
@@ -419,7 +425,7 @@ IF_FEATURE_IP_RULE(ARG_table,)
|
||||
NEXT_ARG();
|
||||
if (rtnl_rttable_a2n(&tid, *argv))
|
||||
invarg_1_to_2(*argv, "table");
|
||||
- req.r.rtm_table = tid;
|
||||
+ rtable = tid;
|
||||
#endif
|
||||
} else if (arg == ARG_dev || arg == ARG_oif) {
|
||||
NEXT_ARG();
|
||||
@@ -475,6 +481,15 @@ IF_FEATURE_IP_RULE(ARG_table,)
|
||||
}
|
||||
}
|
||||
|
||||
+#if ENABLE_FEATURE_IP_RULE
|
||||
+ if (rtable >= 256) {
|
||||
+ addattr32(&req.n, sizeof(req), RTA_TABLE, rtable);
|
||||
+ req.r.rtm_table = RT_TABLE_UNSPEC;
|
||||
+ } else if (rtable > 0) {
|
||||
+ req.r.rtm_table = rtable;
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
if (mxrta->rta_len > RTA_LENGTH(0)) {
|
||||
if (mxlock) {
|
||||
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_LOCK, mxlock);
|
||||
--- a/networking/libiproute/iprule.c
|
||||
+++ b/networking/libiproute/iprule.c
|
||||
@@ -114,7 +114,9 @@ static int FAST_FUNC print_rule(const st
|
||||
printf("iif %s ", (char*)RTA_DATA(tb[RTA_IIF]));
|
||||
}
|
||||
|
||||
- if (r->rtm_table)
|
||||
+ if (tb[RTA_TABLE])
|
||||
+ printf("lookup %s ", rtnl_rttable_n2a(*(uint32_t*)RTA_DATA(tb[RTA_TABLE])));
|
||||
+ else if (r->rtm_table)
|
||||
printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table));
|
||||
|
||||
if (tb[RTA_FLOW]) {
|
||||
--- a/networking/libiproute/rt_names.c
|
||||
+++ b/networking/libiproute/rt_names.c
|
||||
@@ -11,21 +11,26 @@
|
||||
#include "rt_names.h"
|
||||
|
||||
#define CONFDIR CONFIG_FEATURE_IP_ROUTE_DIR
|
||||
+#define RT_TABLE_MAX 65535
|
||||
+
|
||||
+struct rtnl_tab_entry {
|
||||
+ unsigned int id;
|
||||
+ const char *name;
|
||||
+};
|
||||
|
||||
typedef struct rtnl_tab_t {
|
||||
- const char *cached_str;
|
||||
- unsigned cached_result;
|
||||
- /* upstream version switched to a hash table and removed
|
||||
- * id < 256 limit. For now bbox bumps this array size from 256
|
||||
- * to 1024. If you plan to change this to a hash table,
|
||||
- * consider merging several hash tables we have (for example,
|
||||
- * awk has resizable one!
|
||||
- */
|
||||
-#define RT_TABLE_MAX 1023
|
||||
- const char *tab[RT_TABLE_MAX+1];
|
||||
+ struct rtnl_tab_entry *tab;
|
||||
+ size_t length;
|
||||
} rtnl_tab_t;
|
||||
|
||||
-static void rtnl_tab_initialize(const char *file, const char **tab)
|
||||
+static int tabcmp(const void *p1, const void *p2)
|
||||
+{
|
||||
+ const struct rtnl_tab_entry *e1 = p1;
|
||||
+ const struct rtnl_tab_entry *e2 = p2;
|
||||
+ return strcmp(e1->name, e2->name);
|
||||
+}
|
||||
+
|
||||
+static void rtnl_tab_initialize(const char *file, rtnl_tab_t *tab)
|
||||
{
|
||||
char *token[2];
|
||||
char fullname[sizeof(CONFDIR"/rt_dsfield") + 8];
|
||||
@@ -40,34 +45,42 @@ static void rtnl_tab_initialize(const ch
|
||||
file, parser->lineno);
|
||||
break;
|
||||
}
|
||||
- tab[id] = xstrdup(token[1]);
|
||||
+
|
||||
+ tab->tab = xrealloc(tab->tab, (tab->length + 1) * sizeof(*tab->tab));
|
||||
+ tab->tab[tab->length].id = id;
|
||||
+ tab->tab[tab->length].name = xstrdup(token[1]);
|
||||
+ tab->length++;
|
||||
}
|
||||
config_close(parser);
|
||||
+ qsort(tab->tab, tab->length, sizeof(*tab->tab), tabcmp);
|
||||
}
|
||||
|
||||
static int rtnl_a2n(rtnl_tab_t *tab, uint32_t *id, const char *arg, int base)
|
||||
{
|
||||
- unsigned i;
|
||||
-
|
||||
- if (tab->cached_str && strcmp(tab->cached_str, arg) == 0) {
|
||||
- *id = tab->cached_result;
|
||||
- return 0;
|
||||
- }
|
||||
+ int delta;
|
||||
+ ssize_t l = 0;
|
||||
+ ssize_t r = tab->length - 1;
|
||||
+ ssize_t m;
|
||||
+ uint32_t i;
|
||||
+
|
||||
+ while (l <= r) {
|
||||
+ m = l + (r - l) / 2;
|
||||
+ delta = strcmp(tab->tab[m].name, arg);
|
||||
|
||||
- for (i = 0; i <= RT_TABLE_MAX; i++) {
|
||||
- if (tab->tab[i]
|
||||
- && strcmp(tab->tab[i], arg) == 0
|
||||
- ) {
|
||||
- tab->cached_str = tab->tab[i];
|
||||
- tab->cached_result = i;
|
||||
- *id = i;
|
||||
+ if (delta == 0) {
|
||||
+ *id = tab->tab[m].id;
|
||||
return 0;
|
||||
+ } else if (delta < 0) {
|
||||
+ l = m + 1;
|
||||
+ } else {
|
||||
+ r = m - 1;
|
||||
}
|
||||
}
|
||||
|
||||
i = bb_strtou(arg, NULL, base);
|
||||
if (i > RT_TABLE_MAX)
|
||||
return -1;
|
||||
+
|
||||
*id = i;
|
||||
return 0;
|
||||
}
|
||||
@@ -77,40 +90,39 @@ static rtnl_tab_t *rtnl_rtprot_tab;
|
||||
|
||||
static void rtnl_rtprot_initialize(void)
|
||||
{
|
||||
- static const char *const init_tab[] = {
|
||||
- "none",
|
||||
- "redirect",
|
||||
- "kernel",
|
||||
- "boot",
|
||||
- "static",
|
||||
- NULL,
|
||||
- NULL,
|
||||
- NULL,
|
||||
- "gated",
|
||||
- "ra",
|
||||
- "mrt",
|
||||
- "zebra",
|
||||
- "bird",
|
||||
+ static const struct rtnl_tab_entry init_tab[] = {
|
||||
+ { 0, "none" },
|
||||
+ { 1, "redirect" },
|
||||
+ { 2, "kernel" },
|
||||
+ { 3, "boot" },
|
||||
+ { 4, "static" },
|
||||
+ { 8, "gated" },
|
||||
+ { 9, "ra" },
|
||||
+ { 10, "mrt" },
|
||||
+ { 11, "zebra" },
|
||||
+ { 12, "bird" }
|
||||
};
|
||||
|
||||
if (rtnl_rtprot_tab)
|
||||
return;
|
||||
rtnl_rtprot_tab = xzalloc(sizeof(*rtnl_rtprot_tab));
|
||||
+ rtnl_rtprot_tab->tab = xzalloc(sizeof(init_tab));
|
||||
+ rtnl_rtprot_tab->length = sizeof(init_tab) / sizeof(init_tab[0]);
|
||||
memcpy(rtnl_rtprot_tab->tab, init_tab, sizeof(init_tab));
|
||||
- rtnl_tab_initialize("protos", rtnl_rtprot_tab->tab);
|
||||
+ rtnl_tab_initialize("protos", rtnl_rtprot_tab);
|
||||
}
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
const char* FAST_FUNC rtnl_rtprot_n2a(int id)
|
||||
{
|
||||
- if (id < 0 || id > RT_TABLE_MAX) {
|
||||
- return itoa(id);
|
||||
- }
|
||||
+ size_t i;
|
||||
|
||||
rtnl_rtprot_initialize();
|
||||
|
||||
- if (rtnl_rtprot_tab->tab[id])
|
||||
- return rtnl_rtprot_tab->tab[id];
|
||||
+ for (i = 0; i < rtnl_rtprot_tab->length; i++)
|
||||
+ if (rtnl_rtprot_tab->tab[i].id == id)
|
||||
+ return rtnl_rtprot_tab->tab[i].name;
|
||||
+
|
||||
return itoa(id);
|
||||
}
|
||||
#endif
|
||||
@@ -126,27 +138,33 @@ static rtnl_tab_t *rtnl_rtscope_tab;
|
||||
|
||||
static void rtnl_rtscope_initialize(void)
|
||||
{
|
||||
+ static const struct rtnl_tab_entry init_tab[] = {
|
||||
+ { 0, "global" },
|
||||
+ { 200, "site" },
|
||||
+ { 253, "link" },
|
||||
+ { 254, "host" },
|
||||
+ { 255, "nowhere" }
|
||||
+ };
|
||||
+
|
||||
if (rtnl_rtscope_tab)
|
||||
return;
|
||||
rtnl_rtscope_tab = xzalloc(sizeof(*rtnl_rtscope_tab));
|
||||
- rtnl_rtscope_tab->tab[0] = "global";
|
||||
- rtnl_rtscope_tab->tab[255] = "nowhere";
|
||||
- rtnl_rtscope_tab->tab[254] = "host";
|
||||
- rtnl_rtscope_tab->tab[253] = "link";
|
||||
- rtnl_rtscope_tab->tab[200] = "site";
|
||||
- rtnl_tab_initialize("scopes", rtnl_rtscope_tab->tab);
|
||||
+ rtnl_rtscope_tab->tab = xzalloc(sizeof(init_tab));
|
||||
+ rtnl_rtscope_tab->length = sizeof(init_tab) / sizeof(init_tab[0]);
|
||||
+ memcpy(rtnl_rtscope_tab->tab, init_tab, sizeof(init_tab));
|
||||
+ rtnl_tab_initialize("scopes", rtnl_rtscope_tab);
|
||||
}
|
||||
|
||||
const char* FAST_FUNC rtnl_rtscope_n2a(int id)
|
||||
{
|
||||
- if (id < 0 || id > RT_TABLE_MAX) {
|
||||
- return itoa(id);
|
||||
- }
|
||||
+ size_t i;
|
||||
|
||||
rtnl_rtscope_initialize();
|
||||
|
||||
- if (rtnl_rtscope_tab->tab[id])
|
||||
- return rtnl_rtscope_tab->tab[id];
|
||||
+ for (i = 0; i < rtnl_rtscope_tab->length; i++)
|
||||
+ if (rtnl_rtscope_tab->tab[i].id == id)
|
||||
+ return rtnl_rtscope_tab->tab[i].name;
|
||||
+
|
||||
return itoa(id);
|
||||
}
|
||||
|
||||
@@ -161,10 +179,17 @@ static rtnl_tab_t *rtnl_rtrealm_tab;
|
||||
|
||||
static void rtnl_rtrealm_initialize(void)
|
||||
{
|
||||
- if (rtnl_rtrealm_tab) return;
|
||||
+ static const struct rtnl_tab_entry init_tab[] = {
|
||||
+ { 0, "unknown" }
|
||||
+ };
|
||||
+
|
||||
+ if (rtnl_rtrealm_tab)
|
||||
+ return;
|
||||
rtnl_rtrealm_tab = xzalloc(sizeof(*rtnl_rtrealm_tab));
|
||||
- rtnl_rtrealm_tab->tab[0] = "unknown";
|
||||
- rtnl_tab_initialize("realms", rtnl_rtrealm_tab->tab);
|
||||
+ rtnl_rtrealm_tab->tab = xzalloc(sizeof(init_tab));
|
||||
+ rtnl_rtrealm_tab->length = sizeof(init_tab) / sizeof(init_tab[0]);
|
||||
+ memcpy(rtnl_rtrealm_tab->tab, init_tab, sizeof(init_tab));
|
||||
+ rtnl_tab_initialize("realms", rtnl_rtrealm_tab);
|
||||
}
|
||||
|
||||
int FAST_FUNC rtnl_rtrealm_a2n(uint32_t *id, char *arg)
|
||||
@@ -176,14 +201,14 @@ int FAST_FUNC rtnl_rtrealm_a2n(uint32_t
|
||||
#if ENABLE_FEATURE_IP_RULE
|
||||
const char* FAST_FUNC rtnl_rtrealm_n2a(int id)
|
||||
{
|
||||
- if (id < 0 || id > RT_TABLE_MAX) {
|
||||
- return itoa(id);
|
||||
- }
|
||||
+ size_t i;
|
||||
|
||||
rtnl_rtrealm_initialize();
|
||||
|
||||
- if (rtnl_rtrealm_tab->tab[id])
|
||||
- return rtnl_rtrealm_tab->tab[id];
|
||||
+ for (i = 0; i < rtnl_rtrealm_tab->length; i++)
|
||||
+ if (rtnl_rtrealm_tab->tab[i].id == id)
|
||||
+ return rtnl_rtrealm_tab->tab[i].name;
|
||||
+
|
||||
return itoa(id);
|
||||
}
|
||||
#endif
|
||||
@@ -193,22 +218,29 @@ static rtnl_tab_t *rtnl_rtdsfield_tab;
|
||||
|
||||
static void rtnl_rtdsfield_initialize(void)
|
||||
{
|
||||
- if (rtnl_rtdsfield_tab) return;
|
||||
+ static const struct rtnl_tab_entry init_tab[] = {
|
||||
+ { 0, "0" }
|
||||
+ };
|
||||
+
|
||||
+ if (rtnl_rtdsfield_tab)
|
||||
+ return;
|
||||
rtnl_rtdsfield_tab = xzalloc(sizeof(*rtnl_rtdsfield_tab));
|
||||
- rtnl_rtdsfield_tab->tab[0] = "0";
|
||||
- rtnl_tab_initialize("dsfield", rtnl_rtdsfield_tab->tab);
|
||||
+ rtnl_rtdsfield_tab->tab = xzalloc(sizeof(init_tab));
|
||||
+ rtnl_rtdsfield_tab->length = sizeof(init_tab) / sizeof(init_tab[0]);
|
||||
+ memcpy(rtnl_rtdsfield_tab->tab, init_tab, sizeof(init_tab));
|
||||
+ rtnl_tab_initialize("dsfield", rtnl_rtdsfield_tab);
|
||||
}
|
||||
|
||||
const char* FAST_FUNC rtnl_dsfield_n2a(int id)
|
||||
{
|
||||
- if (id < 0 || id > RT_TABLE_MAX) {
|
||||
- return itoa(id);
|
||||
- }
|
||||
+ size_t i;
|
||||
|
||||
rtnl_rtdsfield_initialize();
|
||||
|
||||
- if (rtnl_rtdsfield_tab->tab[id])
|
||||
- return rtnl_rtdsfield_tab->tab[id];
|
||||
+ for (i = 0; i < rtnl_rtdsfield_tab->length; i++)
|
||||
+ if (rtnl_rtdsfield_tab->tab[i].id == id)
|
||||
+ return rtnl_rtdsfield_tab->tab[i].name;
|
||||
+
|
||||
return itoa(id);
|
||||
}
|
||||
|
||||
@@ -224,27 +256,33 @@ static rtnl_tab_t *rtnl_rttable_tab;
|
||||
|
||||
static void rtnl_rttable_initialize(void)
|
||||
{
|
||||
+ static const struct rtnl_tab_entry tab_init[] = {
|
||||
+ { 0, "unspec" },
|
||||
+ { 253, "default" },
|
||||
+ { 254, "main" },
|
||||
+ { 255, "local" }
|
||||
+ };
|
||||
+
|
||||
if (rtnl_rttable_tab)
|
||||
return;
|
||||
|
||||
rtnl_rttable_tab = xzalloc(sizeof(*rtnl_rttable_tab));
|
||||
- rtnl_rttable_tab->tab[0] = "unspec";
|
||||
- rtnl_rttable_tab->tab[255] = "local";
|
||||
- rtnl_rttable_tab->tab[254] = "main";
|
||||
- rtnl_rttable_tab->tab[253] = "default";
|
||||
- rtnl_tab_initialize("tables", rtnl_rttable_tab->tab);
|
||||
+ rtnl_rttable_tab->tab = xzalloc(sizeof(tab_init));
|
||||
+ rtnl_rttable_tab->length = sizeof(tab_init) / sizeof(tab_init[0]);
|
||||
+ memcpy(rtnl_rttable_tab->tab, tab_init, sizeof(tab_init));
|
||||
+ rtnl_tab_initialize("tables", rtnl_rttable_tab);
|
||||
}
|
||||
|
||||
const char* FAST_FUNC rtnl_rttable_n2a(int id)
|
||||
{
|
||||
- if (id < 0 || id > RT_TABLE_MAX) {
|
||||
- return itoa(id);
|
||||
- }
|
||||
+ size_t i;
|
||||
|
||||
rtnl_rttable_initialize();
|
||||
|
||||
- if (rtnl_rttable_tab->tab[id])
|
||||
- return rtnl_rttable_tab->tab[id];
|
||||
+ for (i = 0; i < rtnl_rttable_tab->length; i++)
|
||||
+ if (rtnl_rttable_tab->tab[i].id == id)
|
||||
+ return rtnl_rttable_tab->tab[i].name;
|
||||
+
|
||||
return itoa(id);
|
||||
}
|
||||
|
Loading…
Reference in new issue