From owner-freebsd-current@FreeBSD.ORG Tue Jul 25 12:54:22 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 D5CD516A4DA; Tue, 25 Jul 2006 12:54:22 +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 60CAE43D46; Tue, 25 Jul 2006 12:54:21 +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 7383C1A734; Tue, 25 Jul 2006 14:54:19 +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 47256-05; Tue, 25 Jul 2006 14:54:16 +0200 (CEST) Received: from [192.168.1.100] (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 3BDB21A720; Tue, 25 Jul 2006 14:54:16 +0200 (CEST) Message-ID: <44C61470.3070005@shapeshifter.se> Date: Tue, 25 Jul 2006 14:54:08 +0200 From: Fredrik Lindberg User-Agent: Thunderbird 1.5.0.2 (X11/20060423) MIME-Version: 1.0 To: freebsd-current@freebsd.org Content-Type: multipart/mixed; boundary="------------080406040804030105080707" X-Virus-Scanned: amavisd-new at h3q.net Cc: jmg@freebsd.org Subject: 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: Tue, 25 Jul 2006 12:54:23 -0000 This is a multi-part message in MIME format. --------------080406040804030105080707 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------080406040804030105080707 Content-Type: text/plain; name="kqueue-netdev-20060725.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kqueue-netdev-20060725.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 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; --------------080406040804030105080707--