Module Name:    src
Committed By:   roy
Date:           Wed Sep 21 20:31:32 UTC 2016

Modified Files:
        src/usr.sbin/ifwatchd: ifwatchd.c

Log Message:
We should always know the interface the address message was for.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.sbin/ifwatchd/ifwatchd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ifwatchd/ifwatchd.c
diff -u src/usr.sbin/ifwatchd/ifwatchd.c:1.31 src/usr.sbin/ifwatchd/ifwatchd.c:1.32
--- src/usr.sbin/ifwatchd/ifwatchd.c:1.31	Wed Sep 21 18:18:10 2016
+++ src/usr.sbin/ifwatchd/ifwatchd.c	Wed Sep 21 20:31:31 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ifwatchd.c,v 1.31 2016/09/21 18:18:10 roy Exp $	*/
+/*	$NetBSD: ifwatchd.c,v 1.32 2016/09/21 20:31:31 roy Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@ static void check_announce(const struct 
 static void check_carrier(const struct if_msghdr *ifm);
 static void rescan_interfaces(void);
 static void free_interfaces(void);
-static int find_interface(int index);
+static struct interface_data * find_interface(int index);
 static void run_initial_ups(void);
 
 #ifdef SPPP_IF_SUPPORT
@@ -298,10 +298,8 @@ check_addrs(const struct ifa_msghdr *ifa
 {
 	const char *cp = (const char *)(ifam + 1);
 	const struct sockaddr *sa, *ifa = NULL, *brd = NULL;
-	char ifname_buf[IFNAMSIZ];
-	const char *ifname;
-	int ifndx = 0;
 	unsigned i;
+	struct interface_data *ifd = NULL;
 	enum event ev;
 
 	if (ifam->ifam_addrs == 0)
@@ -314,10 +312,11 @@ check_addrs(const struct ifa_msghdr *ifa
 			const struct sockaddr_dl *li;
 
 			li = (const struct sockaddr_dl *)sa;
-			ifndx = li->sdl_index;
-			if (!find_interface(ifndx)) {
+			if ((ifd = find_interface(li->sdl_index)) == NULL) {
 				if (verbose)
-					printf("ignoring change on interface #%d\n", ifndx);
+					printf("ignoring change"
+					    " on interface #%d\n",
+					    li->sdl_index);
 				return;
 			}
 		} else if (i == RTA_IFA)
@@ -326,18 +325,11 @@ check_addrs(const struct ifa_msghdr *ifa
 			brd = sa;
 		RT_ADVANCE(cp, sa);
 	}
-	if (ifa != NULL) {
+	if (ifa != NULL && ifd != NULL) {
 		ev = ifam->ifam_type == RTM_DELADDR ? DOWN : UP;
-		ifname = if_indextoname(ifndx, ifname_buf);
-		if (ifname == NULL)
-			invoke_script(ifa, brd, ev, ifndx, ifname);
-		else if (ev == UP) {
-			if (if_is_connected(ifname))
-				invoke_script(ifa, brd, ev, ifndx, ifname);
-		} else if (ev == DOWN) {
-			if (if_is_not_connected(ifname))
-				invoke_script(ifa, brd, ev, ifndx, ifname);
-		}
+		if ((ev == UP && if_is_connected(ifd->ifname)) ||
+		    (ev == DOWN && if_is_not_connected(ifd->ifname)))
+			invoke_script(ifa, brd, ev, ifd->index, ifd->ifname);
 	}
 }
 
@@ -532,15 +524,15 @@ free_interfaces(void)
 	}
 }
 
-static int
+static struct interface_data *
 find_interface(int idx)
 {
 	struct interface_data * p;
 
 	SLIST_FOREACH(p, &ifs, next)
 		if (p->index == idx)
-			return 1;
-	return 0;
+			return p;
+	return NULL;
 }
 
 static void

Reply via email to