From owner-svn-src-head@freebsd.org Mon Jul 20 06:58:34 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0BE099A5D12; Mon, 20 Jul 2015 06:58:34 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D262A14BE; Mon, 20 Jul 2015 06:58:33 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6K6wXmV012122; Mon, 20 Jul 2015 06:58:33 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6K6wXjo012121; Mon, 20 Jul 2015 06:58:33 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201507200658.t6K6wXjo012121@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Mon, 20 Jul 2015 06:58:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285711 - head/sys/netinet6 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jul 2015 06:58:34 -0000 Author: ae Date: Mon Jul 20 06:58:32 2015 New Revision: 285711 URL: https://svnweb.freebsd.org/changeset/base/285711 Log: Add LLE event handler to report ND6 events to userland via rtsock. Obtained from: Yandex LLC MFC after: 2 weeks Sponsored by: Yandex LLC Modified: head/sys/netinet6/nd6.c Modified: head/sys/netinet6/nd6.c ============================================================================== --- head/sys/netinet6/nd6.c Mon Jul 20 06:54:50 2015 (r285710) +++ head/sys/netinet6/nd6.c Mon Jul 20 06:58:32 2015 (r285711) @@ -112,6 +112,8 @@ VNET_DEFINE(int, nd6_debug) = 1; VNET_DEFINE(int, nd6_debug) = 0; #endif +static eventhandler_tag lle_event_eh; + /* for debugging? */ #if 0 static int nd6_inuse, nd6_allocated; @@ -144,6 +146,58 @@ static VNET_DEFINE(struct callout, nd6_s VNET_DEFINE(struct callout, nd6_timer_ch); +static void +nd6_lle_event(void *arg __unused, struct llentry *lle, int evt) +{ + struct rt_addrinfo rtinfo; + struct sockaddr_in6 dst, *sa6; + struct sockaddr_dl gw; + struct ifnet *ifp; + int type; + + LLE_WLOCK_ASSERT(lle); + + switch (evt) { + case LLENTRY_RESOLVED: + type = RTM_ADD; + KASSERT(lle->la_flags & LLE_VALID, + ("%s: %p resolved but not valid?", __func__, lle)); + break; + case LLENTRY_EXPIRED: + type = RTM_DELETE; + break; + default: + return; + } + + sa6 = L3_ADDR_SIN6(lle); + if (sa6->sin6_family != AF_INET6) + return; + ifp = lle->lle_tbl->llt_ifp; + + bzero(&dst, sizeof(dst)); + bzero(&gw, sizeof(gw)); + bzero(&rtinfo, sizeof(rtinfo)); + dst.sin6_len = sizeof(struct sockaddr_in6); + dst.sin6_family = AF_INET6; + dst.sin6_addr = sa6->sin6_addr; + dst.sin6_scope_id = in6_getscopezone(ifp, + in6_addrscope(&sa6->sin6_addr)); + in6_clearscope(&dst.sin6_addr); /* XXX */ + gw.sdl_len = sizeof(struct sockaddr_dl); + gw.sdl_family = AF_LINK; + gw.sdl_alen = ifp->if_addrlen; + gw.sdl_index = ifp->if_index; + gw.sdl_type = ifp->if_type; + if (evt == LLENTRY_RESOLVED) + bcopy(&lle->ll_addr, gw.sdl_data, ifp->if_addrlen); + rtinfo.rti_info[RTAX_DST] = (struct sockaddr *)&dst; + rtinfo.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&gw; + rtinfo.rti_addrs = RTA_DST | RTA_GATEWAY; + rt_missmsg_fib(type, &rtinfo, RTF_HOST | RTF_LLDATA | ( + type == RTM_ADD ? RTF_UP: 0), 0, RT_DEFAULT_FIB); +} + void nd6_init(void) { @@ -159,6 +213,9 @@ nd6_init(void) nd6_slowtimo, curvnet); nd6_dad_init(); + if (IS_DEFAULT_VNET(curvnet)) + lle_event_eh = EVENTHANDLER_REGISTER(lle_event, nd6_lle_event, + NULL, EVENTHANDLER_PRI_ANY); } #ifdef VIMAGE @@ -168,6 +225,8 @@ nd6_destroy() callout_drain(&V_nd6_slowtimo_ch); callout_drain(&V_nd6_timer_ch); + if (IS_DEFAULT_VNET(curvnet)) + EVENTHANDLER_DEREGISTER(lle_event, lle_event_eh); } #endif