Thu Oct 6 10:33:05 2016 UTC ()
Simplify logic - invoke script when address is added and ready or
when removed.


(roy)
diff -r1.37 -r1.38 src/usr.sbin/ifwatchd/ifwatchd.c

cvs diff -r1.37 -r1.38 src/usr.sbin/ifwatchd/ifwatchd.c (expand / switch to unified diff)

--- src/usr.sbin/ifwatchd/ifwatchd.c 2016/10/06 10:30:31 1.37
+++ src/usr.sbin/ifwatchd/ifwatchd.c 2016/10/06 10:33:05 1.38
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: ifwatchd.c,v 1.37 2016/10/06 10:30:31 roy Exp $ */ 1/* $NetBSD: ifwatchd.c,v 1.38 2016/10/06 10:33:05 roy Exp $ */
2#include <sys/cdefs.h> 2#include <sys/cdefs.h>
3 __RCSID("$NetBSD: ifwatchd.c,v 1.37 2016/10/06 10:30:31 roy Exp $"); 3__RCSID("$NetBSD: ifwatchd.c,v 1.38 2016/10/06 10:33:05 roy Exp $");
4 4
5/*- 5/*-
6 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. 6 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * This code is derived from software contributed to The NetBSD Foundation 9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Martin Husemann <martin@NetBSD.org>. 10 * by Martin Husemann <martin@NetBSD.org>.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
15 * 1. Redistributions of source code must retain the above copyright 15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 16 * notice, this list of conditions and the following disclaimer.
@@ -328,34 +328,27 @@ check_addrs(const struct ifa_msghdr *ifa @@ -328,34 +328,27 @@ check_addrs(const struct ifa_msghdr *ifa
328 " on interface #%d\n", 328 " on interface #%d\n",
329 li->sdl_index); 329 li->sdl_index);
330 return; 330 return;
331 } 331 }
332 } else if (i == RTA_IFA) 332 } else if (i == RTA_IFA)
333 ifa = sa; 333 ifa = sa;
334 else if (i == RTA_BRD) 334 else if (i == RTA_BRD)
335 brd = sa; 335 brd = sa;
336 RT_ADVANCE(cp, sa); 336 RT_ADVANCE(cp, sa);
337 } 337 }
338 if (ifa != NULL && ifd != NULL) { 338 if (ifa != NULL && ifd != NULL) {
339 ev = ifam->ifam_type == RTM_DELADDR ? DOWN : UP; 339 ev = ifam->ifam_type == RTM_DELADDR ? DOWN : UP;
340 aflag = check_addrflags(ifa->sa_family, ifam->ifam_addrflags); 340 aflag = check_addrflags(ifa->sa_family, ifam->ifam_addrflags);
341 if (ev == UP) { 341 if ((ev == UP && aflag == READY) || ev == DOWN)
342 if (aflag == NOTREADY) 
343 return; 
344 if (aflag == DETACHED) 
345 return; /* XXX set ev to DOWN? */ 
346 } 
347 if ((ev == UP && aflag == READY) || 
348 (ev == DOWN && aflag == DETACHED /* XXX why DETACHED? */)) 
349 invoke_script(ifd->ifname, ev, ifa, brd); 342 invoke_script(ifd->ifname, ev, ifa, brd);
350 } 343 }
351} 344}
352 345
353static void 346static void
354invoke_script(const char *ifname, enum event ev, 347invoke_script(const char *ifname, enum event ev,
355 const struct sockaddr *sa, const struct sockaddr *dest) 348 const struct sockaddr *sa, const struct sockaddr *dest)
356{ 349{
357 char addr[NI_MAXHOST], daddr[NI_MAXHOST]; 350 char addr[NI_MAXHOST], daddr[NI_MAXHOST];
358 const char *script; 351 const char *script;
359 int status; 352 int status;
360 353
361 if (ifname == NULL) 354 if (ifname == NULL)