}
}
+static bool
+enable_route(struct interface_ip_settings *ip, struct device_route *route)
+{
+ if (ip->no_defaultroute && !route->mask)
+ return false;
+
+ return true;
+}
+
static void
interface_update_proto_route(struct vlist_tree *tree,
struct vlist_node *node_new,
}
if (node_new) {
- if (!(route_new->flags & DEVADDR_EXTERNAL) && !keep)
+ bool _enabled = enable_route(ip, route_new);
+
+ if (!(route_new->flags & DEVADDR_EXTERNAL) && !keep && _enabled)
system_add_route(dev, route_new);
- route_new->enabled = true;
+
+ route_new->enabled = _enabled;
}
}
}
vlist_for_each_element(&ip->route, route, node) {
- if (route->enabled == enabled)
+ bool _enabled = enabled;
+
+ if (!enable_route(ip, route))
+ _enabled = false;
+
+ if (route->enabled == _enabled)
continue;
- if (enabled)
+ if (_enabled)
system_add_route(dev, route);
else
system_del_route(dev, route);
- route->enabled = enabled;
+ route->enabled = _enabled;
}
}
IFACE_ATTR_IFNAME,
IFACE_ATTR_PROTO,
IFACE_ATTR_AUTO,
+ IFACE_ATTR_DEFAULTROUTE,
IFACE_ATTR_MAX
};
[IFACE_ATTR_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_AUTO] = { .name = "auto", .type = BLOBMSG_TYPE_BOOL },
+ [IFACE_ATTR_DEFAULTROUTE] = { .name = "defaultroute", .type = BLOBMSG_TYPE_BOOL },
};
const struct config_param_list interface_attr_list = {
proto_attach_interface(iface, proto_name);
- if ((cur = tb[IFACE_ATTR_AUTO]))
- iface->autostart = blobmsg_get_bool(cur);
- else
- iface->autostart = true;
+ iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
+ iface->proto_ip.no_defaultroute =
+ !blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true);
+
iface->config_autostart = iface->autostart;
}
goto reload;
}
+ if (if_old->proto_ip.no_defaultroute != if_new->proto_ip.no_defaultroute) {
+ if_old->proto_ip.no_defaultroute = if_new->proto_ip.no_defaultroute;
+ interface_ip_set_enabled(&if_old->proto_ip, if_old->proto_ip.enabled);
+ }
+
goto out;
reload:
struct interface_ip_settings {
struct interface *iface;
bool enabled;
+ bool no_defaultroute;
struct vlist_tree addr;
struct vlist_tree route;
#include <libubox/list.h>
#include <libubox/avl.h>
+#include <libubox/blobmsg.h>
+
+static inline bool blobmsg_get_bool_default(struct blob_attr *attr, bool val)
+{
+ if (!attr)
+ return val;
+
+ return blobmsg_get_bool(attr);
+}
#define __init __attribute__((constructor))