X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=ubus.c;h=9a573c6019bfcf15fad4158ea7460c1a813f7a5b;hp=6a87c28d4cb80b9198d954994f7a8031c8976f7f;hb=07e9b542017c692ee2abe7a8689517b466150944;hpb=4d1a597f65bbb49aa843112812d5ca929478c706 diff --git a/ubus.c b/ubus.c index 6a87c28..9a573c6 100644 --- a/ubus.c +++ b/ubus.c @@ -147,13 +147,16 @@ netifd_add_dynamic(struct ubus_context *ctx, struct ubus_object *obj, goto error; interface_add(iface, config); - interface_set_dynamic(iface); - // need to look up the interface name again, in case of config update, + // need to look up the interface name again, in case of config update + // the pointer will have changed iface = vlist_find(&interfaces, name, iface, node); if (!iface) return UBUS_STATUS_UNKNOWN_ERROR; + // Set interface as dynamic + interface_set_dynamic(iface); + dev = iface->main_dev.dev; if (!dev || !dev->default_config) return UBUS_STATUS_UNKNOWN_ERROR; @@ -483,6 +486,9 @@ interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled) inet_ntop(af, &route->nexthop, buf, buflen); blobmsg_add_string_buffer(&b); + if (route->flags & DEVROUTE_TYPE) + blobmsg_add_u32(&b, "type", route->type); + if (route->flags & DEVROUTE_MTU) blobmsg_add_u32(&b, "mtu", route->mtu); @@ -636,13 +642,13 @@ interface_ip_dump_dns_search_list(struct interface_ip_settings *ip, } static void -netifd_dump_status(struct interface *iface, bool up) +netifd_dump_status(struct interface *iface) { struct interface_data *data; struct device *dev; void *a, *inactive; - blobmsg_add_u8(&b, "up", up && iface->state == IFS_UP); + blobmsg_add_u8(&b, "up", iface->state == IFS_UP); blobmsg_add_u8(&b, "pending", iface->state == IFS_SETUP); blobmsg_add_u8(&b, "available", iface->available); blobmsg_add_u8(&b, "autostart", iface->autostart); @@ -650,7 +656,8 @@ netifd_dump_status(struct interface *iface, bool up) if (iface->state == IFS_UP) { time_t cur = system_get_rtime(); blobmsg_add_u32(&b, "uptime", cur - iface->start_time); - blobmsg_add_string(&b, "l3_device", iface->l3_dev.dev->ifname); + if (iface->l3_dev.dev) + blobmsg_add_string(&b, "l3_device", iface->l3_dev.dev->ifname); } if (iface->proto_handler) @@ -737,11 +744,11 @@ netifd_dump_status(struct interface *iface, bool up) a = blobmsg_open_table(&b, "data"); avl_for_each_element(&iface->data, data, node) - blob_put(&b, blob_id(data->data), blob_data(data->data), blob_len(data->data)); + blobmsg_add_blob(&b, data->data); blobmsg_close_table(&b, a); - if (!list_is_empty(&iface->errors)) + if (!list_empty(&iface->errors)) netifd_add_interface_errors(&b, iface); } @@ -753,7 +760,7 @@ netifd_handle_status(struct ubus_context *ctx, struct ubus_object *obj, struct interface *iface = container_of(obj, struct interface, ubus); blob_buf_init(&b, 0); - netifd_dump_status(iface, true); + netifd_dump_status(iface); ubus_send_reply(ctx, req, b.head); return 0; @@ -772,7 +779,7 @@ netifd_handle_dump(struct ubus_context *ctx, struct ubus_object *obj, vlist_for_each_element(&interfaces, iface, node) { void *i = blobmsg_open_table(&b, NULL); blobmsg_add_string(&b, "interface", iface->name); - netifd_dump_status(iface, true); + netifd_dump_status(iface); blobmsg_close_table(&b, i); } @@ -1160,10 +1167,10 @@ netifd_ubus_interface_event(struct interface *iface, bool up) void netifd_ubus_interface_notify(struct interface *iface, bool up) { - const char *event = (up) ? "update" : "down"; + const char *event = (up) ? "interface.update" : "interface.down"; blob_buf_init(&b, 0); blobmsg_add_string(&b, "interface", iface->name); - netifd_dump_status(iface, up); + netifd_dump_status(iface); ubus_notify(ubus_ctx, &iface_object, event, b.head, -1); ubus_notify(ubus_ctx, &iface->ubus, event, b.head, -1); }