X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=device.c;h=aa5818f602082d07581275e4407026b533d6f086;hp=6a770aceee979849335fe7d0e691fb2d2734948e;hb=9d8dd091f8f336b111364ed211165b5ec9842a24;hpb=3d26347d0042313be3c9347f8d82c4ccea67fe68 diff --git a/device.c b/device.c index 6a770ac..aa5818f 100644 --- a/device.c +++ b/device.c @@ -37,6 +37,10 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = { [DEV_ATTR_MACADDR] = { .name = "macaddr", .type = BLOBMSG_TYPE_STRING }, [DEV_ATTR_TXQUEUELEN] = { .name = "txqueuelen", .type = BLOBMSG_TYPE_INT32 }, [DEV_ATTR_ENABLED] = { .name = "enabled", .type = BLOBMSG_TYPE_BOOL }, + [DEV_ATTR_IPV6] = { .name = "ipv6", .type = BLOBMSG_TYPE_BOOL }, + [DEV_ATTR_PROMISC] = { .name = "promisc", .type = BLOBMSG_TYPE_BOOL }, + [DEV_ATTR_RPFILTER] = { .name = "rpfilter", .type = BLOBMSG_TYPE_STRING }, + [DEV_ATTR_ACCEPTLOCAL] = { .name = "acceptlocal", .type = BLOBMSG_TYPE_BOOL }, }; const struct uci_blob_param_list device_attr_list = { @@ -60,6 +64,17 @@ void device_unlock(void) static int set_device_state(struct device *dev, bool state) { + if (state) { + /* Set ifindex for all devices being enabled so a valid */ + /* ifindex is in place avoiding possible race conditions */ + device_set_ifindex(dev, system_if_resolve(dev)); + if (!dev->ifindex) + return -1; + } + + if (dev->external) + return 0; + if (state) system_if_up(dev); else @@ -139,6 +154,10 @@ device_merge_settings(struct device *dev, struct device_settings *n) memcpy(n->macaddr, (s->flags & DEV_OPT_MACADDR ? s->macaddr : os->macaddr), sizeof(n->macaddr)); + n->ipv6 = s->flags & DEV_OPT_IPV6 ? s->ipv6 : os->ipv6; + n->promisc = s->flags & DEV_OPT_PROMISC ? s->promisc : os->promisc; + n->rpfilter = s->flags & DEV_OPT_RPFILTER ? s->rpfilter : os->rpfilter; + n->acceptlocal = s->flags & DEV_OPT_ACCEPTLOCAL ? s->acceptlocal : os->acceptlocal; n->flags = s->flags | os->flags; } @@ -172,6 +191,28 @@ device_init_settings(struct device *dev, struct blob_attr **tb) } } + if ((cur = tb[DEV_ATTR_IPV6])) { + s->ipv6 = blobmsg_get_bool(cur); + s->flags |= DEV_OPT_IPV6; + } + + if ((cur = tb[DEV_ATTR_PROMISC])) { + s->promisc = blobmsg_get_bool(cur); + s->flags |= DEV_OPT_PROMISC; + } + + if ((cur = tb[DEV_ATTR_RPFILTER])) { + if (system_resolve_rpfilter(blobmsg_data(cur), &s->rpfilter)) + s->flags |= DEV_OPT_RPFILTER; + else + DPRINTF("Failed to resolve rpfilter: %s\n", (char *) blobmsg_data(cur)); + } + + if ((cur = tb[DEV_ATTR_ACCEPTLOCAL])) { + s->acceptlocal = blobmsg_get_bool(cur); + s->flags |= DEV_OPT_ACCEPTLOCAL; + } + device_set_disabled(dev, disabled); } @@ -244,7 +285,7 @@ void device_release(struct device_user *dep) return; device_broadcast_event(dev, DEV_EVENT_TEARDOWN); - if (!dep->hotplug) + if (!dev->external) dev->set_state(dev, false); device_broadcast_event(dev, DEV_EVENT_DOWN); } @@ -252,7 +293,7 @@ void device_release(struct device_user *dep) int device_check_state(struct device *dev) { if (!dev->type->check_state) - return 0; + return simple_device_type.check_state(dev); return dev->type->check_state(dev); } @@ -623,7 +664,7 @@ device_create(const char *name, const struct device_type *type, odev->current_config = true; change = device_set_config(odev, type, config); if (odev->external) { - system_if_apply_settings(odev, &odev->settings); + system_if_apply_settings(odev, &odev->settings, odev->settings.flags); change = DEV_CONFIG_APPLIED; } switch (change) { @@ -705,6 +746,14 @@ device_dump_status(struct blob_buf *b, struct device *dev) blobmsg_add_string(b, "macaddr", format_macaddr(st.macaddr)); if (st.flags & DEV_OPT_TXQUEUELEN) blobmsg_add_u32(b, "txqueuelen", st.txqueuelen); + if (st.flags & DEV_OPT_IPV6) + blobmsg_add_u8(b, "ipv6", st.ipv6); + if (st.flags & DEV_OPT_PROMISC) + blobmsg_add_u8(b, "promisc", st.promisc); + if (st.flags & DEV_OPT_RPFILTER) + blobmsg_add_u32(b, "rpfilter", st.rpfilter); + if (st.flags & DEV_OPT_ACCEPTLOCAL) + blobmsg_add_u8(b, "acceptlocal", st.acceptlocal); } s = blobmsg_open_table(b, "statistics");