proto_add_host_dependency() {
local interface="$1"
local host="$2"
+ local ifname="$3"
# execute in subshell to not taint callers env
# see tickets #11046, #11545, #11570
json_init
json_add_int action 6
json_add_string host "$host"
+ [ -n "$ifname" ] && json_add_string ifname "$ifname"
_proto_notify "$interface" -S
)
}
}
struct interface *
-interface_ip_add_target_route(union if_addr *addr, bool v6)
+interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface)
{
- struct interface *iface;
struct device_route *route, *r_next = NULL;
bool defaultroute_target = false;
int addrsize = v6 ? sizeof(addr->in6) : sizeof(addr->in);
else
memcpy(&route->addr, addr, addrsize);
- vlist_for_each_element(&interfaces, iface, node) {
+ if (iface) {
/* look for locally addressable target first */
if (interface_ip_find_addr_target(iface, addr, v6))
goto done;
/* do not stop at the first route, let the lookup compare
* masks to find the best match */
interface_ip_find_route_target(iface, addr, v6, &r_next);
+ } else {
+ vlist_for_each_element(&interfaces, iface, node) {
+ /* look for locally addressable target first */
+ if (interface_ip_find_addr_target(iface, addr, v6))
+ goto done;
+
+ /* do not stop at the first route, let the lookup compare
+ * masks to find the best match */
+ interface_ip_find_route_target(iface, addr, v6, &r_next);
+ }
}
if (!r_next) {
void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled);
void interface_ip_update_metric(struct interface_ip_settings *ip, int metric);
-struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6);
+struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface);
struct device_prefix* interface_ip_add_device_prefix(struct interface *iface,
struct in6_addr *addr, uint8_t length, time_t valid_until, time_t preferred_until,
union if_addr host;
bool v6;
+
+ char interface[];
};
struct proto_shell_state {
static void
proto_shell_update_host_dep(struct proto_shell_dependency *dep)
{
- struct interface *iface;
+ struct interface *iface = NULL;
if (dep->dep.iface)
goto out;
- iface = interface_ip_add_target_route(&dep->host, dep->v6);
+ if (dep->interface[0])
+ iface = vlist_find(&interfaces, dep->interface, iface, node);
+
+ iface = interface_ip_add_target_route(&dep->host, dep->v6, iface);
if (!iface)
goto out;
{
struct proto_shell_dependency *dep;
struct blob_attr *host = tb[NOTIFY_HOST];
+ struct blob_attr *ifname = tb[NOTIFY_IFNAME];
+ size_t ifnamelen = (ifname) ? blobmsg_data_len(ifname) : 1;
if (!host)
return UBUS_STATUS_INVALID_ARGUMENT;
- dep = calloc(1, sizeof(*dep));
- if (!inet_pton(AF_INET, blobmsg_data(host), &dep->host)) {
- free(dep);
- return UBUS_STATUS_INVALID_ARGUMENT;
+ dep = calloc(1, sizeof(*dep) + ifnamelen);
+ if (inet_pton(AF_INET, blobmsg_data(host), &dep->host) < 1) {
+ if (inet_pton(AF_INET6, blobmsg_data(host), &dep->host) < 1) {
+ free(dep);
+ return UBUS_STATUS_INVALID_ARGUMENT;
+ } else {
+ dep->v6 = true;
+ }
}
dep->proto = state;
+ if (ifname)
+ memcpy(dep->interface, blobmsg_data(ifname), ifnamelen);
+ else
+ dep->interface[0] = 0;
+
dep->dep.cb = proto_shell_if_up_cb;
interface_add_user(&dep->dep, NULL);
list_add(&dep->list, &state->deps);
enum {
HR_TARGET,
HR_V6,
+ HR_INTERFACE,
__HR_MAX
};
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 },
};
static int
struct blob_attr *msg)
{
struct blob_attr *tb[__HR_MAX];
- struct interface *iface;
+ struct interface *iface = NULL;
union if_addr a;
bool v6 = false;
if (tb[HR_V6])
v6 = blobmsg_get_bool(tb[HR_V6]);
+ if (tb[HR_INTERFACE])
+ iface = vlist_find(&interfaces, blobmsg_data(tb[HR_INTERFACE]), iface, node);
+
memset(&a, 0, sizeof(a));
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 = interface_ip_add_target_route(&a, v6, iface);
if (!iface)
return UBUS_STATUS_NOT_FOUND;