Install a handler to flush routes and release devices when the program is terminating.
Signed-off-by: Flavio Leitner <f...@redhat.com> --- lib/ovs-router.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/ovs-router.c b/lib/ovs-router.c index 96871d1..dd23c88 100644 --- a/lib/ovs-router.c +++ b/lib/ovs-router.c @@ -33,6 +33,7 @@ #include "command-line.h" #include "compiler.h" #include "dpif.h" +#include "fatal-signal.h" #include "openvswitch/dynamic-string.h" #include "netdev.h" #include "packets.h" @@ -484,16 +485,33 @@ ovs_router_flush(void) seq_change(tnl_conf_seq); } +static void +ovs_router_flush_handler(void *aux OVS_UNUSED) +{ + ovs_router_flush(); +} + /* May not be called more than once. */ void ovs_router_init(void) { - classifier_init(&cls, NULL); - unixctl_command_register("ovs/route/add", "ip_addr/prefix_len out_br_name [gw] [pkt_mark=mark]", 2, 4, - ovs_router_add, NULL); - unixctl_command_register("ovs/route/show", "", 0, 0, ovs_router_show, NULL); - unixctl_command_register("ovs/route/del", "ip_addr/prefix_len [pkt_mark=mark]", 1, 2, - ovs_router_del, NULL); - unixctl_command_register("ovs/route/lookup", "ip_addr [pkt_mark=mark]", 1, 2, - ovs_router_lookup_cmd, NULL); + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + + if (ovsthread_once_start(&once)) { + fatal_signal_add_hook(ovs_router_flush_handler, NULL, NULL, true); + classifier_init(&cls, NULL); + unixctl_command_register("ovs/route/add", + "ip_addr/prefix_len out_br_name [gw] " + "[pkt_mark=mark]", + 2, 4, ovs_router_add, NULL); + unixctl_command_register("ovs/route/show", "", 0, 0, + ovs_router_show, NULL); + unixctl_command_register("ovs/route/del", "ip_addr/prefix_len " + "[pkt_mark=mark]", 1, 2, ovs_router_del, + NULL); + unixctl_command_register("ovs/route/lookup", "ip_addr " + "[pkt_mark=mark]", 1, 2, + ovs_router_lookup_cmd, NULL); + ovsthread_once_done(&once); + } } -- 2.9.4 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev