summaryrefslogtreecommitdiff
path: root/ubus.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2022-05-19 17:21:23 +0200
committerFelix Fietkau <nbd@nbd.name>2022-05-19 17:21:24 +0200
commit507c0513d1766757d969530c51fe7d368354538d (patch)
tree21aa6169dacb0e913139a7409672f7342670078d /ubus.c
parent4b4849cf5e5a784aca40be55158744811b172e76 (diff)
downloadnetifd-507c0513d1766757d969530c51fe7d368354538d.tar.gz
interface-ip: add support for excluding interfaces in host route lookup
When adding host routes needed for an interface to communicate, it may be necessary to skip the interface itself, in case it provides a default route. This helps with avoiding accidental loops Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'ubus.c')
-rw-r--r--ubus.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ubus.c b/ubus.c
index a386179..2876e7d 100644
--- a/ubus.c
+++ b/ubus.c
@@ -54,6 +54,7 @@ enum {
HR_TARGET,
HR_V6,
HR_INTERFACE,
+ HR_EXCLUDE,
__HR_MAX
};
@@ -61,6 +62,7 @@ static const struct blobmsg_policy route_policy[__HR_MAX] = {
[HR_TARGET] = { .name = "target", .type = BLOBMSG_TYPE_STRING },
[HR_V6] = { .name = "v6", .type = BLOBMSG_TYPE_BOOL },
[HR_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
+ [HR_EXCLUDE] = { .name = "exclude", .type = BLOBMSG_TYPE_BOOL },
};
static int
@@ -72,6 +74,7 @@ netifd_add_host_route(struct ubus_context *ctx, struct ubus_object *obj,
struct interface *iface = NULL;
union if_addr a;
bool v6 = false;
+ bool exclude = false;
blobmsg_parse(route_policy, __HR_MAX, tb, blob_data(msg), blob_len(msg));
if (!tb[HR_TARGET])
@@ -80,6 +83,9 @@ netifd_add_host_route(struct ubus_context *ctx, struct ubus_object *obj,
if (tb[HR_V6])
v6 = blobmsg_get_bool(tb[HR_V6]);
+ if (tb[HR_EXCLUDE])
+ exclude = blobmsg_get_bool(tb[HR_EXCLUDE]);
+
if (tb[HR_INTERFACE])
iface = vlist_find(&interfaces, blobmsg_data(tb[HR_INTERFACE]), iface, node);
@@ -87,8 +93,7 @@ netifd_add_host_route(struct ubus_context *ctx, struct ubus_object *obj,
if (!inet_pton(v6 ? AF_INET6 : AF_INET, blobmsg_data(tb[HR_TARGET]), &a))
return UBUS_STATUS_INVALID_ARGUMENT;
-
- iface = interface_ip_add_target_route(&a, v6, iface);
+ iface = interface_ip_add_target_route(&a, v6, iface, exclude);
if (!iface)
return UBUS_STATUS_NOT_FOUND;