struct ubus_context *ubus_ctx = NULL;
static struct blob_buf b;
static const char *ubus_path;
+static struct udebug_ubus udebug;
/* global object */
HR_TARGET,
HR_V6,
HR_INTERFACE,
+ HR_EXCLUDE,
__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
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])
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);
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;
enum {
NETNS_UPDOWN_JAIL,
- NETNS_UPDOWN_PID,
NETNS_UPDOWN_START,
__NETNS_UPDOWN_MAX
};
static const struct blobmsg_policy netns_updown_policy[__NETNS_UPDOWN_MAX] = {
[NETNS_UPDOWN_JAIL] = { .name = "jail", .type = BLOBMSG_TYPE_STRING },
- [NETNS_UPDOWN_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 },
[NETNS_UPDOWN_START] = { .name = "start", .type = BLOBMSG_TYPE_BOOL },
};
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
+ int target_netns_fd = ubus_request_get_caller_fd(req);
struct blob_attr *tb[__NETNS_UPDOWN_MAX];
- char *jail;
- pid_t netns_pid;
bool start;
- blobmsg_parse(netns_updown_policy, __NETNS_UPDOWN_MAX, tb, blob_data(msg), blob_len(msg));
- if (!tb[NETNS_UPDOWN_JAIL] || !tb[NETNS_UPDOWN_PID])
+ if (target_netns_fd < 0)
return UBUS_STATUS_INVALID_ARGUMENT;
+ blobmsg_parse(netns_updown_policy, __NETNS_UPDOWN_MAX, tb, blob_data(msg), blob_len(msg));
+
start = tb[NETNS_UPDOWN_START] && blobmsg_get_bool(tb[NETNS_UPDOWN_START]);
- jail = blobmsg_get_string(tb[NETNS_UPDOWN_JAIL]);
- netns_pid = blobmsg_get_u32(tb[NETNS_UPDOWN_PID]);
- if (start)
- interface_start_jail(jail, netns_pid);
- else
- interface_stop_jail(jail, netns_pid);
+ if (start) {
+ if (!tb[NETNS_UPDOWN_JAIL])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ interface_start_jail(target_netns_fd, blobmsg_get_string(tb[NETNS_UPDOWN_JAIL]));
+ } else {
+ interface_stop_jail(target_netns_fd);
+ }
+ close(target_netns_fd);
return UBUS_STATUS_OK;
}
struct device *dev = NULL;
struct blob_attr *tb[__ALIAS_ATTR_MAX];
struct blob_attr *cur;
- int rem;
+ size_t rem;
blobmsg_parse(alias_attrs, __ALIAS_ATTR_MAX, tb, blob_data(msg), blob_len(msg));
return 0;
error:
- device_free_unused(dev);
+ device_free_unused();
return UBUS_STATUS_INVALID_ARGUMENT;
}
enum {
DEV_STATE_NAME,
DEV_STATE_DEFER,
+ DEV_STATE_AUTH_STATUS,
+ DEV_STATE_AUTH_VLANS,
__DEV_STATE_MAX,
};
static const struct blobmsg_policy dev_state_policy[__DEV_STATE_MAX] = {
[DEV_STATE_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
[DEV_STATE_DEFER] = { .name = "defer", .type = BLOBMSG_TYPE_BOOL },
+ [DEV_STATE_AUTH_STATUS] = { .name = "auth_status", .type = BLOBMSG_TYPE_BOOL },
+ [DEV_STATE_AUTH_VLANS] = { .name = "auth_vlans", BLOBMSG_TYPE_ARRAY },
};
static int
struct device *dev = NULL;
struct blob_attr *tb[__DEV_STATE_MAX];
struct blob_attr *cur;
+ bool auth_status;
blobmsg_parse(dev_state_policy, __DEV_STATE_MAX, tb, blob_data(msg), blob_len(msg));
if (cur)
device_set_deferred(dev, !!blobmsg_get_u8(cur));
+ if ((cur = tb[DEV_STATE_AUTH_STATUS]) != NULL)
+ auth_status = blobmsg_get_bool(cur);
+ else
+ auth_status = dev->auth_status;
+ if (tb[DEV_STATE_AUTH_STATUS] || tb[DEV_STATE_AUTH_VLANS])
+ device_set_auth_status(dev, auth_status, tb[DEV_STATE_AUTH_VLANS]);
+
+ return 0;
+}
+
+#ifdef DUMMY_MODE
+enum {
+ DEV_HOTPLUG_ATTR_NAME,
+ DEV_HOTPLUG_ATTR_ADD,
+ __DEV_HOTPLUG_ATTR_MAX,
+};
+
+static const struct blobmsg_policy dev_hotplug_policy[__DEV_HOTPLUG_ATTR_MAX] = {
+ [DEV_HOTPLUG_ATTR_NAME] = { "name", BLOBMSG_TYPE_STRING },
+ [DEV_HOTPLUG_ATTR_ADD] = { "add", BLOBMSG_TYPE_BOOL },
+};
+
+static int
+netifd_handle_dev_hotplug(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct blob_attr *tb[__DEV_HOTPLUG_ATTR_MAX];
+ const char *name;
+
+ blobmsg_parse(dev_hotplug_policy, __DEV_HOTPLUG_ATTR_MAX, tb,
+ blob_data(msg), blob_len(msg));
+
+ if (!tb[DEV_HOTPLUG_ATTR_NAME] || !tb[DEV_HOTPLUG_ATTR_ADD])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ name = blobmsg_get_string(tb[DEV_HOTPLUG_ATTR_NAME]);
+ device_hotplug_event(name, blobmsg_get_bool(tb[DEV_HOTPLUG_ATTR_ADD]));
+
+ return 0;
+}
+#endif
+
+static int
+netifd_handle_stp_init(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ device_stp_init();
+
return 0;
}
UBUS_METHOD("status", netifd_dev_status, dev_policy),
UBUS_METHOD("set_alias", netifd_handle_alias, alias_attrs),
UBUS_METHOD("set_state", netifd_handle_set_state, dev_state_policy),
+#ifdef DUMMY_MODE
+ UBUS_METHOD("hotplug_event", netifd_handle_dev_hotplug, dev_hotplug_policy),
+#endif
+ UBUS_METHOD_NOARG("stp_init", netifd_handle_stp_init)
};
static struct ubus_object_type dev_object_type =
system_fd_set_cloexec(ubus_ctx->sock.fd);
}
+void netifd_ubus_device_notify(const char *event, struct blob_attr *data, int timeout)
+{
+ ubus_notify(ubus_ctx, &dev_object, event, data, timeout);
+}
+
static void
netifd_ubus_reconnect_timer(struct uloop_timeout *timeout)
{
int t = 2;
if (ubus_reconnect(ubus_ctx, ubus_path) != 0) {
- DPRINTF("failed to reconnect, trying again in %d seconds\n", t);
+ D(SYSTEM, "failed to reconnect, trying again in %d seconds", t);
uloop_timeout_set(&retry, t * 1000);
return;
}
- DPRINTF("reconnected to ubus, new id: %08x\n", ubus_ctx->local_id);
+ D(SYSTEM, "reconnected to ubus, new id: %08x", ubus_ctx->local_id);
netifd_ubus_add_fd();
}
if (iface->jail)
blobmsg_add_string(&b, "jail", iface->jail);
- if (iface->jail_ifname)
- blobmsg_add_string(&b, "jail_ifname", iface->jail_ifname);
+ if (iface->jail_device)
+ blobmsg_add_string(&b, "jail_device", iface->jail_device);
if (iface->state == IFS_UP) {
if (iface->updated) {
}
a = blobmsg_open_table(&b, "data");
+
+ if (iface->zone)
+ blobmsg_add_string(&b, "zone", iface->zone);
avl_for_each_element(&iface->data, data, node)
blobmsg_add_blob(&b, data->data);
enum {
DEV_LINK_NAME,
DEV_LINK_EXT,
+ DEV_LINK_VLAN,
__DEV_LINK_MAX,
};
static const struct blobmsg_policy dev_link_policy[__DEV_LINK_MAX] = {
[DEV_LINK_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
[DEV_LINK_EXT] = { .name = "link-ext", .type = BLOBMSG_TYPE_BOOL },
+ [DEV_LINK_VLAN] = { .name = "vlan", .type = BLOBMSG_TYPE_ARRAY },
};
static int
if (cur)
link_ext = blobmsg_get_bool(cur);
- return interface_handle_link(iface, blobmsg_data(tb[DEV_LINK_NAME]), add, link_ext);
+ return interface_handle_link(iface, blobmsg_data(tb[DEV_LINK_NAME]),
+ tb[DEV_LINK_VLAN], add, link_ext);
}
struct blob_attr *msg)
{
struct interface *iface;
- struct device *dev;
+ struct device *dev, *bridge_dev = NULL;
const struct device_hotplug_ops *ops;
iface = container_of(obj, struct interface, ubus);
dev = iface->main_dev.dev;
if (!dev)
- return 0;
+ goto out;
ops = dev->hotplug_ops;
if (!ops)
- return 0;
+ goto out;
+
+ ops->prepare(dev, &bridge_dev);
+
+out:
+ blob_buf_init(&b, 0);
+ if (bridge_dev)
+ blobmsg_add_string(&b, "bridge", bridge_dev->ifname);
+ ubus_send_reply(ctx, req, b.head);
- return ops->prepare(dev);
+ return 0;
}
static int
{
struct interface *iface;
struct blob_attr *tb;
- int i;
+ size_t i;
blobmsg_parse(&iface_policy, 1, &tb, blob_data(msg), blob_len(msg));
if (!tb)
static void netifd_add_iface_object(void)
{
struct ubus_method *methods;
- int i;
+ size_t i;
methods = calloc(1, sizeof(iface_object_methods));
if (!methods)
.n_methods = ARRAY_SIZE(wireless_object_methods),
};
+int
+netifd_extdev_invoke(uint32_t id, const char *method, struct blob_attr *msg,
+ ubus_data_handler_t data_cb, void *data)
+{
+ return ubus_invoke(ubus_ctx, id, method, msg, data_cb, data, 3000);
+}
+
int
netifd_ubus_init(const char *path)
{
- uloop_init();
ubus_path = path;
ubus_ctx = ubus_connect(path);
if (!ubus_ctx)
return -EIO;
- DPRINTF("connected as %08x\n", ubus_ctx->local_id);
+ D(SYSTEM, "connected as %08x", ubus_ctx->local_id);
ubus_ctx->connection_lost = netifd_ubus_connection_lost;
netifd_ubus_add_fd();
netifd_add_object(&wireless_object);
netifd_add_iface_object();
+ udebug_ubus_init(&udebug, ubus_ctx, "netifd", netifd_udebug_config);
+
return 0;
}
void
netifd_ubus_done(void)
{
+ udebug_ubus_free(&udebug);
ubus_free(ubus_ctx);
}
obj->methods = iface_object_methods;
obj->n_methods = ARRAY_SIZE(iface_object_methods);
if (ubus_add_object(ubus_ctx, &iface->ubus)) {
- DPRINTF("failed to publish ubus object for interface '%s'\n", iface->name);
+ D(SYSTEM, "failed to publish ubus object for interface '%s'", iface->name);
free(name);
obj->name = NULL;
}
ubus_remove_object(ubus_ctx, &iface->ubus);
free((void *) iface->ubus.name);
}
+
+static void
+netifd_ubus_data_cb(struct ubus_request *req, int type, struct blob_attr *msg)
+{
+ struct blob_attr *srv, *in, *t, *data;
+ procd_data_cb cb = req->priv;
+ int rem, rem2, rem3, rem4;
+
+ blobmsg_for_each_attr(srv, msg, rem) {
+ if (!blobmsg_check_attr(srv, true) ||
+ blobmsg_type(srv) != BLOBMSG_TYPE_TABLE)
+ continue;
+ blobmsg_for_each_attr(in, srv, rem2) {
+ if (!blobmsg_check_attr(in , true) ||
+ blobmsg_type(in) != BLOBMSG_TYPE_TABLE)
+ continue;
+ blobmsg_for_each_attr(t, in, rem3) {
+ if (!blobmsg_check_attr(t, true) ||
+ blobmsg_type(t) != BLOBMSG_TYPE_TABLE)
+ continue;
+ blobmsg_for_each_attr(data, t, rem4) {
+ if (!blobmsg_check_attr(t, true) ||
+ blobmsg_type(t) != BLOBMSG_TYPE_TABLE)
+ continue;
+ cb(data);
+ }
+ }
+ }
+ }
+}
+
+void netifd_ubus_get_procd_data(const char *type, procd_data_cb cb)
+{
+ uint32_t id;
+
+ if (ubus_lookup_id(ubus_ctx, "service", &id))
+ return;
+
+ blob_buf_init(&b, 0);
+ blobmsg_add_string(&b, "type", type);
+ ubus_invoke(ubus_ctx, id, "get_data", b.head, netifd_ubus_data_cb, cb, 30000);
+}