From: Steven Barth Date: Thu, 17 Oct 2013 14:51:49 +0000 (+0200) Subject: Add protocol update notifications and hotplug legacy calls X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=81a3b50ef7fad3096a8d164c871521e6e6b55aa1;p=oweals%2Fnetifd.git Add protocol update notifications and hotplug legacy calls --- diff --git a/interface-event.c b/interface-event.c index c6fe1ca..fe4759e 100644 --- a/interface-event.c +++ b/interface-event.c @@ -33,7 +33,7 @@ static struct uloop_process task = { }; static void -run_cmd(const char *ifname, const char *device, bool up) +run_cmd(const char *ifname, const char *device, enum interface_event event) { char *argv[3]; int pid; @@ -48,7 +48,8 @@ run_cmd(const char *ifname, const char *device, bool up) return; } - setenv("ACTION", up ? "ifup" : "ifdown", 1); + char *eventnames[] = {"ifdown", "ifup", "ifupdate"}; + setenv("ACTION", eventnames[event], 1); setenv("INTERFACE", ifname, 1); if (device) setenv("DEVICE", device, 1); @@ -74,7 +75,7 @@ call_hotplug(void) device = current->l3_dev.dev->ifname; D(SYSTEM, "Call hotplug handler for interface '%s' (%s)\n", current->name, device ? device : "none"); - run_cmd(current->name, device, current_ev == IFEV_UP); + run_cmd(current->name, device, current_ev); } static void @@ -99,7 +100,11 @@ interface_queue_event(struct interface *iface, enum interface_event ev) enum interface_event last_ev; D(SYSTEM, "Queue hotplug handler for interface '%s'\n", iface->name); - netifd_ubus_interface_event(iface, ev == IFEV_UP); + if (ev == IFEV_UP || ev == IFEV_DOWN) + netifd_ubus_interface_event(iface, ev == IFEV_UP); + + netifd_ubus_interface_notify(iface, ev != IFEV_DOWN); + if (current == iface) last_ev = current_ev; else @@ -130,6 +135,7 @@ static void interface_event_cb(struct interface_user *dep, struct interface *ifa { switch (ev) { case IFEV_UP: + case IFEV_UPDATE: case IFEV_DOWN: interface_queue_event(iface, ev); break; diff --git a/interface.c b/interface.c index 49fc830..a79de4a 100644 --- a/interface.c +++ b/interface.c @@ -378,6 +378,7 @@ interface_alias_cb(struct interface_user *dep, struct interface *iface, enum int interface_remove_user(dep); break; case IFEV_RELOAD: + case IFEV_UPDATE: break; } } @@ -483,8 +484,10 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve switch (ev) { case IFPEV_UP: - if (iface->state != IFS_SETUP) + if (iface->state != IFS_SETUP) { + interface_event(iface, IFEV_UPDATE); return; + } interface_ip_set_enabled(&iface->config_ip, true); system_flush_routes(); diff --git a/interface.h b/interface.h index e4d92aa..8c69958 100644 --- a/interface.h +++ b/interface.h @@ -23,6 +23,7 @@ struct interface_proto_state; enum interface_event { IFEV_DOWN, IFEV_UP, + IFEV_UPDATE, IFEV_FREE, IFEV_RELOAD, }; diff --git a/proto-shell.c b/proto-shell.c index 4bb0744..38d3871 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -225,7 +225,7 @@ proto_shell_if_down_cb(struct interface_user *dep, struct interface *iface, struct proto_shell_dependency *pdep; struct proto_shell_state *state; - if (ev == IFEV_UP) + if (ev == IFEV_UP || ev == IFEV_UPDATE) return; pdep = container_of(dep, struct proto_shell_dependency, dep); diff --git a/ubus.c b/ubus.c index d245541..a26c3dd 100644 --- a/ubus.c +++ b/ubus.c @@ -630,7 +630,6 @@ netifd_dump_status(struct interface *iface) struct device *dev; void *a, *inactive; - blobmsg_add_string(&b, "name", iface->name); 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); @@ -739,6 +738,7 @@ netifd_handle_dump(struct ubus_context *ctx, struct ubus_object *obj, struct interface *iface; 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); blobmsg_close_table(&b, i); } @@ -996,6 +996,17 @@ netifd_ubus_interface_event(struct interface *iface, bool up) ubus_send_event(ctx, "network.interface", b.head); } +void +netifd_ubus_interface_notify(struct interface *iface, bool up) +{ + const char *event = (up) ? "update" : "down"; + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "interface", iface->name); + netifd_dump_status(iface); + ubus_notify(ctx, &iface_object, event, b.head, -1); + ubus_notify(ctx, &iface->ubus, event, b.head, -1); +} + void netifd_ubus_add_interface(struct interface *iface) { diff --git a/ubus.h b/ubus.h index 05bf391..553faef 100644 --- a/ubus.h +++ b/ubus.h @@ -19,5 +19,6 @@ void netifd_ubus_done(void); void netifd_ubus_add_interface(struct interface *iface); void netifd_ubus_remove_interface(struct interface *iface); void netifd_ubus_interface_event(struct interface *iface, bool up); +void netifd_ubus_interface_notify(struct interface *iface, bool up); #endif