From d9768348d5f23ec2125a19194237fbc086bad09f Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Sat, 4 Oct 2014 21:09:11 -0500 Subject: [PATCH] monitor: Always try to find an existing interface Duplicate detection will happen when we try to create a new link. The newlink flags were updated to fail if the device already exists. --- monitor/main.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/monitor/main.c b/monitor/main.c index 2634654f..93b1f5f8 100644 --- a/monitor/main.c +++ b/monitor/main.c @@ -242,7 +242,7 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl, case RTM_NEWLINK: rtmmsg->ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP; - l_netlink_send(rtnl, RTM_NEWLINK, NLM_F_CREATE, + l_netlink_send(rtnl, RTM_NEWLINK, NLM_F_CREATE|NLM_F_EXCL, rtmmsg, rta_buf - (void *) rtmmsg, callback, user_data, destroy); break; @@ -290,15 +290,14 @@ static void iwmon_interface_enable_callback(int error, uint16_t type, struct iwmon_interface *monitor_interface = user_data; if (error) { - fprintf(stderr, "Failed to create monitor interface %s %d\n", - monitor_interface->ifname, error); + fprintf(stderr, "Failed to create monitor interface %s: %s\n", + monitor_interface->ifname, strerror(error)); l_main_quit(); - return; } - fprintf(stderr, "Created interface %s\n", monitor_interface->ifname); + printf("Created interface %s\n", monitor_interface->ifname); monitor_interface->genl = genl_lookup(monitor_interface->ifname); } @@ -318,6 +317,9 @@ static void iwmon_interface_lookup_done(void *user_data) struct iwmon_interface *monitor_interface = user_data; if (monitor_interface->exists && monitor_interface->ifname) { + printf("Using %s as Monitor interface\n", + monitor_interface->ifname); + monitor_interface->genl = genl_lookup(monitor_interface->ifname); @@ -368,22 +370,9 @@ static void iwmon_interface_lookup_callback(int error, uint16_t type, if (!ifname) return; - if (monitor_interface->ifname && - strncmp(ifname, monitor_interface->ifname, ifname_len)) + if (!nlmon) return; - if (!nlmon) { - if (monitor_interface->ifname) { - fprintf(stderr, "Interface %s already in use\n", - ifname); - - l_main_quit(); - - } - - return; - } - if ((rtmmsg->ifi_flags & (IFF_UP | IFF_ALLMULTI | IFF_NOARP)) != (IFF_UP | IFF_ALLMULTI | IFF_NOARP)) return;