summaryrefslogtreecommitdiffhomepage
path: root/system-linux.c
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2017-01-19 15:59:54 +0100
committerFelix Fietkau <nbd@nbd.name>2017-01-25 09:35:27 +0100
commit650758b16e5185505a3fbc1307949340af70b611 (patch)
treeb8fdadfb813f45d8f96186c8f71ba61edba14e64 /system-linux.c
parenta057f6e48f383c7e81cb22aa806216878d87947b (diff)
interface-ip: route proto config support (FS#170)
Route proto support is usefull when using route distribution via a routing daemon. The route proto parameter can be specified via the route proto uci config parameter, it can hold a numerical value or the string values unspec, kernel, boot, static or a string present in /etc/iproute2/rt_protos. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'system-linux.c')
-rw-r--r--system-linux.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/system-linux.c b/system-linux.c
index 2f15bf1..fcd1b2e 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -52,7 +52,6 @@
#define IFA_FLAGS (IFA_MULTICAST + 1)
#endif
-
#include <string.h>
#include <fcntl.h>
#include <glob.h>
@@ -1782,7 +1781,7 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
.rtm_dst_len = route->mask,
.rtm_src_len = route->sourcemask,
.rtm_table = (table < 256) ? table : RT_TABLE_UNSPEC,
- .rtm_protocol = (route->flags & DEVADDR_KERNEL) ? RTPROT_KERNEL : RTPROT_STATIC,
+ .rtm_protocol = (route->flags & DEVROUTE_PROTO) ? route->proto : RTPROT_STATIC,
.rtm_scope = RT_SCOPE_NOWHERE,
.rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST,
.rtm_flags = (route->flags & DEVROUTE_ONLINK) ? RTNH_F_ONLINK : 0,
@@ -1900,6 +1899,45 @@ bool system_resolve_rt_type(const char *type, unsigned int *id)
return system_rtn_aton(type, id);
}
+bool system_resolve_rt_proto(const char *type, unsigned int *id)
+{
+ FILE *f;
+ char *e, buf[128];
+ unsigned int n, proto = 256;
+
+ if ((n = strtoul(type, &e, 0)) >= 0 && !*e && e != type)
+ proto = n;
+ else if (!strcmp(type, "unspec"))
+ proto = RTPROT_UNSPEC;
+ else if (!strcmp(type, "kernel"))
+ proto = RTPROT_KERNEL;
+ else if (!strcmp(type, "boot"))
+ proto = RTPROT_BOOT;
+ else if (!strcmp(type, "static"))
+ proto = RTPROT_STATIC;
+ else if ((f = fopen("/etc/iproute2/rt_protos", "r")) != NULL) {
+ while (fgets(buf, sizeof(buf) - 1, f) != NULL) {
+ if ((e = strtok(buf, " \t\n")) == NULL || *e == '#')
+ continue;
+
+ n = strtoul(e, NULL, 10);
+ e = strtok(NULL, " \t\n");
+
+ if (e && !strcmp(e, type)) {
+ proto = n;
+ break;
+ }
+ }
+ fclose(f);
+ }
+
+ if (proto > 255)
+ return false;
+
+ *id = proto;
+ return true;
+}
+
bool system_resolve_rt_table(const char *name, unsigned int *id)
{
FILE *f;