From owner-freebsd-current@FreeBSD.ORG Sun Jul 30 11:30:35 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 16BFE16A4DE for ; Sun, 30 Jul 2006 11:30:35 +0000 (UTC) (envelope-from fli+freebsd-current@shapeshifter.se) Received: from mx1.h3q.net (manticore.shapeshifter.se [212.37.5.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id 255E143D45 for ; Sun, 30 Jul 2006 11:30:29 +0000 (GMT) (envelope-from fli+freebsd-current@shapeshifter.se) Received: from localhost (localhost [127.0.0.1]) by mx1.h3q.net (Postfix) with ESMTP id 0DD1B1A789; Sun, 30 Jul 2006 13:30:26 +0200 (CEST) Received: from mx1.h3q.net ([127.0.0.1]) by localhost (mx1.h3q.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 63554-09; Sun, 30 Jul 2006 13:30:24 +0200 (CEST) Received: from [192.168.1.89] (217-208-33-252-o926.tbon.telia.com [217.208.33.252]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.h3q.net (Postfix) with ESMTP id C65E61A74E; Sun, 30 Jul 2006 13:30:23 +0200 (CEST) Message-ID: <44CC984C.1010908@shapeshifter.se> Date: Sun, 30 Jul 2006 13:30:20 +0200 From: Fredrik Lindberg User-Agent: Thunderbird 1.5.0.4 (X11/20060727) MIME-Version: 1.0 To: gurney_j@resnet.uoregon.edu References: <44C61470.3070005@shapeshifter.se> <20060725173924.GR96589@funkthat.com> <44C79A66.6000204@shapeshifter.se> In-Reply-To: <44C79A66.6000204@shapeshifter.se> Content-Type: multipart/mixed; boundary="------------020503090300040103040502" X-Virus-Scanned: amavisd-new at h3q.net Cc: freebsd-current@freebsd.org Subject: Re: Extending EVFILT_NETDEV to support ip-address changes X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jul 2006 11:30:35 -0000 This is a multi-part message in MIME format. --------------020503090300040103040502 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Fredrik Lindberg wrote: > The documented way of using EVFILT_NETDEV according to kqueue(2) is to > obtain the status from fflags, but as it apparently sets data too > somebody is using it, that's for sure. > > Users of EVFILT_NETDEV are required to pass a mask of > NOTE_LINK{UP,DOWN,INV} in fflags with the initial kevent call, otherwise > no events will fire. > > What if we add NOTE_ADDR{NEW,DEL} as bit masks and change filt_netdev to > only set kn_data when a monitored event occurs instead of just setting > it regardless of if the event is being monitored or not. > If we also restrict the values of kn_data to NOTE_LINK{UP,DOWN,INV}, > existing applications shouldn't break as they would only receive the > events they subscribed to and both data and fflags would be > intact. NOTE_ADDR{NEW,DEL} would be obtain only through fflags and > kn_data would be left as it is in these cases (0 with EV_CLEAR set). > > Doing it this way shouldn't break the API, as no fields would be touched > because kn_sfflags & hint would fail for ADDR{NEW,DEL} on existing > applications as they would only be subscribed to one or more of the > NOTE_LINK{UP,DOWN,INV} events. > But maybe I'm missing some rare edge case... > Replying to myself here, but anyway. I've attached a complete patch with the modified filt_netdev as described above. Fredrik Lindberg --------------020503090300040103040502 Content-Type: text/plain; name="kqueue-netdev-20060730.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kqueue-netdev-20060730.patch" 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 30 Jul 2006 10:54:31 -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_ADDRNEW 0x0008 /* ip-address added */ +#define NOTE_ADDRDEL 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 30 Jul 2006 10:54:31 -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_ADDRNEW); + } 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_ADDRNEW); + } 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_ADDRDEL); error = 0; break; Index: net/if.c =================================================================== RCS file: /home/ncvs/src/sys/net/if.c,v retrieving revision 1.261 diff -u -r1.261 if.c --- net/if.c 9 Jul 2006 06:04:00 -0000 1.261 +++ net/if.c 30 Jul 2006 10:54:31 -0000 @@ -265,10 +265,12 @@ knlist_remove_inevent(klist, kn); return (1); } - if (hint != 0) - kn->kn_data = hint; /* current status */ - if (kn->kn_sfflags & hint) + + if (kn->kn_sfflags & hint) { kn->kn_fflags |= hint; + if (hint & (NOTE_LINKUP | NOTE_LINKDOWN)) + kn->kn_data = hint; /* current link status */ + } return (kn->kn_fflags != 0); } --------------020503090300040103040502--