Extending EVFILT_NETDEV to support ip-address changes

Fredrik Lindberg fli+freebsd-current at shapeshifter.se
Tue Jul 25 12:54:23 UTC 2006


Hi,

I have a suggestion to add support for ip-address changes to the
kqueue (EVFILT_NETDEV) system.
The infrastructure for EVFILT_NETDEV is already in place and this
only introduce NOTE_NEWADDR and NOTE_DELADDR and minor modifications
to the interface ioctl handler.

The purpose is not to replicate the functionality of the
routing socket, but to provide a low overhead mechanism for
monitoring a given interface for address changes.
No information about the event is sent through the kqueue system,
instead it will be up to the caller to query the system (if wanted)
to obtain information about the current state of the interface
that is being monitored.

I have attached a suggested patch, any thoughts?

Fredrik Lindberg
-------------- next part --------------
Index: sys/event.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/event.h,v
retrieving revision 1.36
diff -u -r1.36 event.h
--- sys/event.h	16 Mar 2006 11:19:36 -0000	1.36
+++ sys/event.h	25 Jul 2006 12:18:16 -0000
@@ -115,6 +115,8 @@
 #define NOTE_LINKUP	0x0001			/* link is up */
 #define NOTE_LINKDOWN	0x0002			/* link is down */
 #define NOTE_LINKINV	0x0004			/* link state is invalid */
+#define NOTE_NEWADDR	0x0008			/* ip-address added */
+#define NOTE_DELADDR	0x0010			/* ip-address removed */
 
 struct knote;
 SLIST_HEAD(klist, knote);
Index: netinet/in.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/in.c,v
retrieving revision 1.93
diff -u -r1.93 in.c
--- netinet/in.c	24 Jan 2006 16:19:31 -0000	1.93
+++ netinet/in.c	25 Jul 2006 12:18:16 -0000
@@ -399,8 +399,10 @@
 		    (struct sockaddr_in *) &ifr->ifr_addr, 1);
 		if (error != 0 && iaIsNew)
 			break;
-		if (error == 0)
+		if (error == 0) {
 			EVENTHANDLER_INVOKE(ifaddr_event, ifp);
+			KNOTE_UNLOCKED(&ifp->if_klist, NOTE_NEWADDR);
+		}
 		return (0);
 
 	case SIOCSIFNETMASK:
@@ -443,8 +445,10 @@
 		if ((ifp->if_flags & IFF_BROADCAST) &&
 		    (ifra->ifra_broadaddr.sin_family == AF_INET))
 			ia->ia_broadaddr = ifra->ifra_broadaddr;
-		if (error == 0)
+		if (error == 0) {
 			EVENTHANDLER_INVOKE(ifaddr_event, ifp);
+			KNOTE_UNLOCKED(&ifp->if_klist, NOTE_NEWADDR);
+		}
 		return (error);
 
 	case SIOCDIFADDR:
@@ -460,6 +464,7 @@
 		 */
 		in_ifadown(&ia->ia_ifa, 1);
 		EVENTHANDLER_INVOKE(ifaddr_event, ifp);
+		KNOTE_UNLOCKED(&ifp->if_klist, NOTE_DELADDR);
 		error = 0;
 		break;
 


More information about the freebsd-current mailing list