CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Mar 22 18:07:38 UTC 2021 Modified Files: src/sys/net [netbsd-8]: if_l2tp.h Log Message: Pull up following revision(s) (requested by knakahara in ticket #1665): sys/net/if_l2tp.h: revision 1.10 Fix l2tp(4) ioctl type. Pointed out by yamaguchi@n.o, thanks. XXX pullup-[89] To generate a diff of this commit: cvs rdiff -u -r1.2.2.4 -r1.2.2.5 src/sys/net/if_l2tp.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_l2tp.h diff -u src/sys/net/if_l2tp.h:1.2.2.4 src/sys/net/if_l2tp.h:1.2.2.5 --- src/sys/net/if_l2tp.h:1.2.2.4 Tue Sep 24 18:27:09 2019 +++ src/sys/net/if_l2tp.h Mon Mar 22 18:07:38 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: if_l2tp.h,v 1.2.2.4 2019/09/24 18:27:09 martin Exp $ */ +/* $NetBSD: if_l2tp.h,v 1.2.2.5 2021/03/22 18:07:38 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -44,11 +44,11 @@ #include #include -#define SIOCSL2TPSESSION _IOW('i', 151, struct l2tp_req) -#define SIOCDL2TPSESSION _IOW('i', 152, struct l2tp_req) -#define SIOCSL2TPCOOKIE _IOW('i', 153, struct l2tp_req) -#define SIOCDL2TPCOOKIE _IOW('i', 154, struct l2tp_req) -#define SIOCSL2TPSTATE _IOW('i', 155, struct l2tp_req) +#define SIOCSL2TPSESSION _IOW('i', 151, struct ifreq) +#define SIOCDL2TPSESSION _IOW('i', 152, struct ifreq) +#define SIOCSL2TPCOOKIE _IOW('i', 153, struct ifreq) +#define SIOCDL2TPCOOKIE _IOW('i', 154, struct ifreq) +#define SIOCSL2TPSTATE _IOW('i', 155, struct ifreq) #define SIOCGL2TP SIOCGIFGENERIC struct l2tp_req {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Feb 13 19:37:39 UTC 2020 Modified Files: src/sys/net [netbsd-8]: if_pppoe.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #1505): sys/net/if_pppoe.c: revision 1.149 safely extract character sequences from packet for printing. To generate a diff of this commit: cvs rdiff -u -r1.125.6.9 -r1.125.6.10 src/sys/net/if_pppoe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.125.6.9 src/sys/net/if_pppoe.c:1.125.6.10 --- src/sys/net/if_pppoe.c:1.125.6.9 Thu Jul 12 15:11:56 2018 +++ src/sys/net/if_pppoe.c Thu Feb 13 19:37:39 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.125.6.9 2018/07/12 15:11:56 martin Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.125.6.10 2020/02/13 19:37:39 martin Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.9 2018/07/12 15:11:56 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.10 2020/02/13 19:37:39 martin Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -524,6 +524,7 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, const char *err_msg; char devname[IF_NAMESIZE]; char *error; + size_t dlen; uint8_t *ac_cookie; size_t ac_cookie_len; uint8_t *relay_sid; @@ -610,7 +611,8 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, break; /* ignored */ case PPPOE_TAG_ACNAME: if (len > 0) { -error = malloc(len + 1, M_TEMP, M_NOWAIT); +dlen = 4 * len + 1; +error = malloc(dlen, M_TEMP, M_NOWAIT); if (error == NULL) break; @@ -622,7 +624,9 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, goto done; } -strlcpy(error, mtod(n, char*) + noff, len + 1); +strnvisx(error, dlen, +mtod(n, char*) + noff, len, +VIS_SAFE | VIS_OCTAL); printf("pppoe: connected to %s\n", error); free(error, M_TEMP); } @@ -683,15 +687,17 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, if (err_msg) { error = NULL; if (errortag && len) { -error = malloc(len + 1, M_TEMP, +dlen = 4 * len + 1; +error = malloc(dlen, M_TEMP, M_NOWAIT|M_ZERO); n = m_pulldown(m, off + sizeof(*pt), len, ); if (!n) { m = NULL; } else if (error) { - strlcpy(error, mtod(n, char *) + noff, - len + 1); + strnvisx(error, dlen, + mtod(n, char*) + noff, len, + VIS_SAFE | VIS_OCTAL); } } if (error) {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Apr 22 09:06:49 UTC 2019 Modified Files: src/sys/net [netbsd-8]: if_gif.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1241): sys/net/if_gif.c: revision 1.146 fix a potential bug of gif(4) check for tunnel duplicate. This problem has not actualized thanks to check for duplicate in encap_attach(). To generate a diff of this commit: cvs rdiff -u -r1.126.2.13 -r1.126.2.14 src/sys/net/if_gif.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_gif.c diff -u src/sys/net/if_gif.c:1.126.2.13 src/sys/net/if_gif.c:1.126.2.14 --- src/sys/net/if_gif.c:1.126.2.13 Mon Nov 12 08:50:18 2018 +++ src/sys/net/if_gif.c Mon Apr 22 09:06:49 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_gif.c,v 1.126.2.13 2018/11/12 08:50:18 martin Exp $ */ +/* $NetBSD: if_gif.c,v 1.126.2.14 2019/04/22 09:06:49 martin Exp $ */ /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.13 2018/11/12 08:50:18 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.14 2019/04/22 09:06:49 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1031,7 +1031,7 @@ gif_set_tunnel(struct ifnet *ifp, struct if (sc2 == sc) continue; - var2 = gif_getref_variant(sc, ); + var2 = gif_getref_variant(sc2, ); if (!var2->gv_pdst || !var2->gv_psrc) { gif_putref_variant(var2, ); continue;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Fri Mar 15 14:47:22 UTC 2019 Modified Files: src/sys/net [netbsd-8]: if_ipsec.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1216): sys/net/if_ipsec.c: revision 1.21 Fix ipsecif(4) memory leak in some ioctl cases. To generate a diff of this commit: cvs rdiff -u -r1.3.2.10 -r1.3.2.11 src/sys/net/if_ipsec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ipsec.c diff -u src/sys/net/if_ipsec.c:1.3.2.10 src/sys/net/if_ipsec.c:1.3.2.11 --- src/sys/net/if_ipsec.c:1.3.2.10 Sun Oct 21 11:55:54 2018 +++ src/sys/net/if_ipsec.c Fri Mar 15 14:47:22 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ipsec.c,v 1.3.2.10 2018/10/21 11:55:54 martin Exp $ */ +/* $NetBSD: if_ipsec.c,v 1.3.2.11 2019/03/15 14:47:22 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.10 2018/10/21 11:55:54 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.11 2019/03/15 14:47:22 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1104,6 +1104,7 @@ if_ipsec_delete_tunnel(struct ifnet *ifp mutex_exit(>ipsec_lock); encap_lock_exit(); kmem_free(nvar, sizeof(*nvar)); + kmem_free(nullvar, sizeof(*nullvar)); return; } @@ -1191,6 +1192,8 @@ if_ipsec_ensure_flags(struct ifnet *ifp, /* nothing to do */ mutex_exit(>ipsec_lock); encap_lock_exit(); + kmem_free(nvar, sizeof(*nvar)); + kmem_free(nullvar, sizeof(*nullvar)); return 0; }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Fri Mar 15 14:44:05 UTC 2019 Modified Files: src/sys/net [netbsd-8]: route.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #1215): sys/net/route.c: revision 1.217 Add missing ifa_release on error paths To generate a diff of this commit: cvs rdiff -u -r1.194.6.12 -r1.194.6.13 src/sys/net/route.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/route.c diff -u src/sys/net/route.c:1.194.6.12 src/sys/net/route.c:1.194.6.13 --- src/sys/net/route.c:1.194.6.12 Tue Nov 6 14:38:58 2018 +++ src/sys/net/route.c Fri Mar 15 14:44:05 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.194.6.12 2018/11/06 14:38:58 martin Exp $ */ +/* $NetBSD: route.c,v 1.194.6.13 2019/03/15 14:44:05 martin Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.12 2018/11/06 14:38:58 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.13 2019/03/15 14:44:05 martin Exp $"); #include #ifdef RTFLUSH_DEBUG @@ -1504,6 +1504,8 @@ rt_update(struct rtentry *rt, struct rt_ } if (new_ifa == NULL) ifa_release(ifa, _ifa); + /* To avoid ifa_release below */ + ifa = NULL; } ifa_release(new_ifa, _new_ifa); if (new_ifp && rt->rt_ifp != new_ifp && !if_is_deactivated(new_ifp)) { @@ -1525,6 +1527,7 @@ rt_update(struct rtentry *rt, struct rt_ (void)ifp_changed; /* XXX gcc */ #endif out: + ifa_release(ifa, _ifa); if_put(new_ifp, _new_ifp); if_put(ifp, _ifp);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Mar 7 16:59:10 UTC 2019 Modified Files: src/sys/net [netbsd-8]: rtsock.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #1203): sys/net/rtsock.c: revision 1.247 Protect sysctl_rtable with KERNEL_LOCK and softnet_lock In the function the routing table could be accessed without any locks, which was unsafe. Actually, on netbsd-7, a kernel panic happened(*). The situation of locking hasn't changed since netbsd-7 so we still need to hold the big locks on -current (and netbsd-8) too. Note that if NET_MPSAFE is enabled, the routing table is protected by its own lock and we don't need the locks. Reported and tested on netbsd-7 by sborrill@ (*) http://mail-index.netbsd.org/tech-net/2018/11/08/msg007153.html To generate a diff of this commit: cvs rdiff -u -r1.213.2.11 -r1.213.2.12 src/sys/net/rtsock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/rtsock.c diff -u src/sys/net/rtsock.c:1.213.2.11 src/sys/net/rtsock.c:1.213.2.12 --- src/sys/net/rtsock.c:1.213.2.11 Wed Nov 21 12:01:11 2018 +++ src/sys/net/rtsock.c Thu Mar 7 16:59:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rtsock.c,v 1.213.2.11 2018/11/21 12:01:11 martin Exp $ */ +/* $NetBSD: rtsock.c,v 1.213.2.12 2019/03/07 16:59:10 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.11 2018/11/21 12:01:11 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.12 2019/03/07 16:59:10 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1873,6 +1873,7 @@ again: w.w_needed = 0 - w.w_given; w.w_where = where; + SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); s = splsoftnet(); switch (w.w_op) { @@ -1931,6 +1932,7 @@ again: break; } splx(s); + SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); /* check to see if we couldn't allocate memory with NOWAIT */ if (error == ENOBUFS && w.w_tmem == 0 && w.w_tmemneeded)
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Fri Jan 11 15:55:02 UTC 2019 Modified Files: src/sys/net [netbsd-8]: if_ppp.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1162): sys/net/if_ppp.c: revision 1.162 sys/net/if_ppp.c: revision 1.163 Fix missing mutex_exit in ppp_create(). Fix missing splx in ppp_inproc(). To generate a diff of this commit: cvs rdiff -u -r1.158.8.1 -r1.158.8.2 src/sys/net/if_ppp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ppp.c diff -u src/sys/net/if_ppp.c:1.158.8.1 src/sys/net/if_ppp.c:1.158.8.2 --- src/sys/net/if_ppp.c:1.158.8.1 Thu Jul 26 23:55:31 2018 +++ src/sys/net/if_ppp.c Fri Jan 11 15:55:01 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ppp.c,v 1.158.8.1 2018/07/26 23:55:31 snj Exp $ */ +/* $NetBSD: if_ppp.c,v 1.158.8.2 2019/01/11 15:55:01 martin Exp $ */ /* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */ /* @@ -102,7 +102,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.158.8.1 2018/07/26 23:55:31 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.158.8.2 2019/01/11 15:55:01 martin Exp $"); #ifdef _KERNEL_OPT #include "ppp.h" @@ -301,6 +301,7 @@ ppp_create(const char *name, int unit) break; else if (unit == sci->sc_unit) { free(sc, M_DEVBUF); +mutex_exit(_list_lock); return NULL; } } @@ -1722,6 +1723,7 @@ ppp_inproc(struct ppp_softc *sc, struct /* pktq: inet or inet6 cases */ if (__predict_true(pktq)) { if (__predict_false(!pktq_enqueue(pktq, m, 0))) { + splx(s); ifp->if_iqdrops++; goto bad; } @@ -1733,6 +1735,7 @@ ppp_inproc(struct ppp_softc *sc, struct /* ifq: other protocol cases */ if (!inq) { + splx(s); goto bad; } if (IF_QFULL(inq)) {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Nov 21 12:01:11 UTC 2018 Modified Files: src/sys/net [netbsd-8]: rtsock.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1101): sys/net/rtsock.c: revision 1.244 Fix kernel info leak. There are 2 bytes of padding in struct if_msghdr. [ 944.607323] kleak: Possible leak in copyout: [len=176, leaked=2] [ 944.617335] #0 0x80b7c44a in kleak_note [ 944.627332] #1 0x80b7c4ca in kleak_copyout [ 944.627332] #2 0x80c91698 in sysctl_iflist_if [ 944.637336] #3 0x80c91d3c in sysctl_iflist [ 944.647343] #4 0x80c93855 in sysctl_rtable [ 944.647343] #5 0x80b5b328 in sysctl_dispatch [ 944.657346] #6 0x80b5b62e in sys___sysctl [ 944.667354] #7 0x8025ab3c in sy_call [ 944.667354] #8 0x8025ad6e in sy_invoke [ 944.677365] #9 0x8025adf4 in syscall To generate a diff of this commit: cvs rdiff -u -r1.213.2.10 -r1.213.2.11 src/sys/net/rtsock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/rtsock.c diff -u src/sys/net/rtsock.c:1.213.2.10 src/sys/net/rtsock.c:1.213.2.11 --- src/sys/net/rtsock.c:1.213.2.10 Sat May 5 19:07:51 2018 +++ src/sys/net/rtsock.c Wed Nov 21 12:01:11 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: rtsock.c,v 1.213.2.10 2018/05/05 19:07:51 martin Exp $ */ +/* $NetBSD: rtsock.c,v 1.213.2.11 2018/11/21 12:01:11 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.10 2018/05/05 19:07:51 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.11 2018/11/21 12:01:11 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1294,7 +1294,7 @@ again: if (rw->w_tmemsize < len) { if (rw->w_tmem) kmem_free(rw->w_tmem, rw->w_tmemsize); -rw->w_tmem = kmem_alloc(len, KM_SLEEP); +rw->w_tmem = kmem_zalloc(len, KM_SLEEP); rw->w_tmemsize = len; } if (rw->w_tmem) { @@ -1863,7 +1863,7 @@ sysctl_rtable(SYSCTLFN_ARGS) again: /* we may return here if a later [re]alloc of the t_mem buffer fails */ if (w.w_tmemneeded) { - w.w_tmem = kmem_alloc(w.w_tmemneeded, KM_SLEEP); + w.w_tmem = kmem_zalloc(w.w_tmemneeded, KM_SLEEP); w.w_tmemsize = w.w_tmemneeded; w.w_tmemneeded = 0; }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Nov 12 08:50:18 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_gif.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1087): sys/net/if_gif.c: revision 1.145 Fix ALTQ on gif(4). Reported and tested by Anthony Mallet, advised by Greg Troxel, thanks. l2tp(4) and ipsecif(4) don't support ALTQ yet. So, they don't require this fix. XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.126.2.12 -r1.126.2.13 src/sys/net/if_gif.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_gif.c diff -u src/sys/net/if_gif.c:1.126.2.12 src/sys/net/if_gif.c:1.126.2.13 --- src/sys/net/if_gif.c:1.126.2.12 Sun Oct 21 11:55:54 2018 +++ src/sys/net/if_gif.c Mon Nov 12 08:50:18 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_gif.c,v 1.126.2.12 2018/10/21 11:55:54 martin Exp $ */ +/* $NetBSD: if_gif.c,v 1.126.2.13 2018/11/12 08:50:18 martin Exp $ */ /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.12 2018/10/21 11:55:54 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.13 2018/11/12 08:50:18 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -489,7 +489,8 @@ gif_output(struct ifnet *ifp, struct mbu m->m_pkthdr.csum_flags = 0; m->m_pkthdr.csum_data = 0; - error = gif_transmit_direct(var, m); + error = if_transmit_lock(ifp, m); + end: if (var != NULL) gif_putref_variant(var, );
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Oct 22 07:41:12 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Additionally pull up r1.131 for ticket #1066 (requested by knakahara): Use a different psz for a different lock. Patch from riastradh, reviewed by ozaki-r. To generate a diff of this commit: cvs rdiff -u -r1.97.2.15 -r1.97.2.16 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.15 src/sys/net/if_vlan.c:1.97.2.16 --- src/sys/net/if_vlan.c:1.97.2.15 Sun Oct 21 11:55:54 2018 +++ src/sys/net/if_vlan.c Mon Oct 22 07:41:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.15 2018/10/21 11:55:54 martin Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.16 2018/10/22 07:41:12 martin Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.15 2018/10/21 11:55:54 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.16 2018/10/22 07:41:12 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -161,6 +161,7 @@ struct ifvlan { * instead of direct dereference */ kmutex_t ifv_lock; /* writer lock for ifv_mib */ + pserialize_t ifv_psz; LIST_HEAD(__vlan_mchead, vlan_mc_entry) ifv_mc_listhead; LIST_ENTRY(ifvlan) ifv_list; @@ -350,6 +351,7 @@ vlan_clone_create(struct if_clone *ifc, psref_target_init(>ifvm_psref, ifvm_psref_class); mutex_init(>ifv_lock, MUTEX_DEFAULT, IPL_NONE); + ifv->ifv_psz = pserialize_create(); ifv->ifv_mib = mib; mutex_enter(_list.lock); @@ -788,7 +790,7 @@ vlan_linkmib_update(struct ifvlan *ifv, membar_producer(); ifv->ifv_mib = nmib; - pserialize_perform(vlan_psz); + pserialize_perform(ifv->ifv_psz); psref_target_destroy(>ifvm_psref, ifvm_psref_class); }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Sun Oct 21 11:55:54 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_gif.c if_gif.h if_ipsec.c if_ipsec.h if_l2tp.c if_l2tp.h if_vlan.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1066): sys/net/if_vlan.c: revision 1.133 sys/net/if_gif.h: revision 1.32 sys/net/if_ipsec.c: revision 1.18 sys/net/if_ipsec.h: revision 1.4 sys/net/if_gif.c: revision 1.144 sys/net/if_l2tp.h: revision 1.6 sys/net/if_l2tp.c: revision 1.30 Fix panic when doing ioctl to multiple pseudo interfaces. Pointed out by k-goda@IIJ. XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.126.2.11 -r1.126.2.12 src/sys/net/if_gif.c cvs rdiff -u -r1.25.8.3 -r1.25.8.4 src/sys/net/if_gif.h cvs rdiff -u -r1.3.2.9 -r1.3.2.10 src/sys/net/if_ipsec.c cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/sys/net/if_ipsec.h cvs rdiff -u -r1.11.2.9 -r1.11.2.10 src/sys/net/if_l2tp.c cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/net/if_l2tp.h cvs rdiff -u -r1.97.2.14 -r1.97.2.15 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_gif.c diff -u src/sys/net/if_gif.c:1.126.2.11 src/sys/net/if_gif.c:1.126.2.12 --- src/sys/net/if_gif.c:1.126.2.11 Thu Jun 7 17:42:25 2018 +++ src/sys/net/if_gif.c Sun Oct 21 11:55:54 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_gif.c,v 1.126.2.11 2018/06/07 17:42:25 martin Exp $ */ +/* $NetBSD: if_gif.c,v 1.126.2.12 2018/10/21 11:55:54 martin Exp $ */ /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.11 2018/06/07 17:42:25 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.12 2018/10/21 11:55:54 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -105,7 +105,6 @@ static struct { kmutex_t lock; } gif_softcs __cacheline_aligned; -pserialize_t gif_psz __read_mostly; struct psref_class *gv_psref_class __read_mostly; static void gif_ro_init_pc(void *, void *, struct cpu_info *); @@ -224,7 +223,6 @@ gifinit(void) LIST_INIT(_softcs.list); if_clone_attach(_cloner); - gif_psz = pserialize_create(); gv_psref_class = psref_class_create("gifvar", IPL_SOFTNET); gif_sysctl_setup(); @@ -243,7 +241,6 @@ gifdetach(void) if (error == 0) { psref_class_destroy(gv_psref_class); - pserialize_destroy(gif_psz); if_clone_detach(_cloner); sysctl_teardown(_sysctl); @@ -275,9 +272,10 @@ gif_clone_create(struct if_clone *ifc, i sc->gif_var = var; mutex_init(>gif_lock, MUTEX_DEFAULT, IPL_NONE); + sc->gif_psz = pserialize_create(); + sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro)); percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL); - mutex_enter(_softcs.lock); LIST_INSERT_HEAD(_softcs.list, sc, gif_list); mutex_exit(_softcs.lock); @@ -355,6 +353,7 @@ gif_clone_destroy(struct ifnet *ifp) percpu_foreach(sc->gif_ro_percpu, gif_ro_fini_pc, NULL); percpu_free(sc->gif_ro_percpu, sizeof(struct gif_ro)); + pserialize_destroy(sc->gif_psz); mutex_destroy(>gif_lock); var = sc->gif_var; @@ -1173,7 +1172,7 @@ gif_update_variant(struct gif_softc *sc, KASSERT(mutex_owned(>gif_lock)); sc->gif_var = nvar; - pserialize_perform(gif_psz); + pserialize_perform(sc->gif_psz); psref_target_destroy(>gv_psref, gv_psref_class); if (nvar->gv_psrc != NULL && nvar->gv_pdst != NULL) Index: src/sys/net/if_gif.h diff -u src/sys/net/if_gif.h:1.25.8.3 src/sys/net/if_gif.h:1.25.8.4 --- src/sys/net/if_gif.h:1.25.8.3 Thu May 17 14:07:03 2018 +++ src/sys/net/if_gif.h Sun Oct 21 11:55:54 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_gif.h,v 1.25.8.3 2018/05/17 14:07:03 martin Exp $ */ +/* $NetBSD: if_gif.h,v 1.25.8.4 2018/10/21 11:55:54 martin Exp $ */ /* $KAME: if_gif.h,v 1.23 2001/07/27 09:21:42 itojun Exp $ */ /* @@ -40,6 +40,7 @@ #include #include #ifdef _KERNEL +#include #include #endif @@ -78,6 +79,7 @@ struct gif_softc { * instead of direct dereference. */ kmutex_t gif_lock; /* writer lock for gif_var */ + pserialize_t gif_psz; LIST_ENTRY(gif_softc) gif_list; /* list of all gifs */ }; Index: src/sys/net/if_ipsec.c diff -u src/sys/net/if_ipsec.c:1.3.2.9 src/sys/net/if_ipsec.c:1.3.2.10 --- src/sys/net/if_ipsec.c:1.3.2.9 Thu Jun 7 16:22:43 2018 +++ src/sys/net/if_ipsec.c Sun Oct 21 11:55:54 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ipsec.c,v 1.3.2.9 2018/06/07 16:22:43 martin Exp $ */ +/* $NetBSD: if_ipsec.c,v 1.3.2.10 2018/10/21 11:55:54 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.9 2018/06/07 16:22:43 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.10 2018/10/21 11:55:54 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -145,7 +145,6
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Oct 3 17:57:39 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_bridge.c Log Message: Pull up following revision(s) (requested by msaitoh in ticket #1046): sys/net/if_bridge.c: revision 1.157 sys/net/if_bridge.c: revision 1.158 sys/net/if_bridge.c: revision 1.159 Fix a bug that bridge_enqueue() incorrectly cleared outgoing packet's offload flags. bridge_enqueue() is called from bridge_output() when a packet is spontaneous. Clear csum_flags before calling brige_enqueue() in bridge_forward() or bridge_broadcast() instead of in the beginning of bridge_enqueue(). Note that this change doesn't fix a problem on the following configuration: A bridge has two or more interfaces. An address is assigned to an bridge member interface and some offload flags are set. Another interface has no address and has no any offload flag. XXX pullup-[78] - Fix bridge_enqueue() which was broken by last commit. Use correct mbuf pointer. - Modify comment. Micro optimization. m_copym(M_COPYALL) -> m_copypacket(). To generate a diff of this commit: cvs rdiff -u -r1.134.6.11 -r1.134.6.12 src/sys/net/if_bridge.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_bridge.c diff -u src/sys/net/if_bridge.c:1.134.6.11 src/sys/net/if_bridge.c:1.134.6.12 --- src/sys/net/if_bridge.c:1.134.6.11 Thu Jun 7 17:42:25 2018 +++ src/sys/net/if_bridge.c Wed Oct 3 17:57:39 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_bridge.c,v 1.134.6.11 2018/06/07 17:42:25 martin Exp $ */ +/* $NetBSD: if_bridge.c,v 1.134.6.12 2018/10/03 17:57:39 martin Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -80,7 +80,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.11 2018/06/07 17:42:25 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.12 2018/10/03 17:57:39 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_bridge_ipf.h" @@ -1395,11 +1395,6 @@ bridge_enqueue(struct bridge_softc *sc, int len, error; short mflags; - /* - * Clear any in-bound checksum flags for this packet. - */ - m->m_pkthdr.csum_flags = 0; - if (runfilt) { if (pfil_run_hooks(sc->sc_if.if_pfil, , dst_ifp, PFIL_OUT) != 0) { @@ -1545,7 +1540,7 @@ bridge_output(struct ifnet *ifp, struct used = true; mc = m; } else { -mc = m_copym(m, 0, M_COPYALL, M_NOWAIT); +mc = m_copypacket(m, M_DONTWAIT); if (mc == NULL) { sc->sc_if.if_oerrors++; goto next; @@ -1563,8 +1558,7 @@ bridge_output(struct ifnet *ifp, struct used = true; mc = m; } else { - mc = m_copym(m, 0, M_COPYALL, - M_DONTWAIT); + mc = m_copypacket(m, M_DONTWAIT); if (mc == NULL) { sc->sc_if.if_oerrors++; goto next; @@ -1768,6 +1762,13 @@ bridge_forward(struct bridge_softc *sc, bridge_release_member(sc, bif, ); + /* + * Before enqueueing this packet to the destination interface, + * clear any in-bound checksum flags to prevent them from being + * misused as out-bound flags. + */ + m->m_pkthdr.csum_flags = 0; + ACQUIRE_GLOBAL_LOCKS(); bridge_enqueue(sc, dst_if, m, 1); RELEASE_GLOBAL_LOCKS(); @@ -1973,18 +1974,25 @@ bridge_broadcast(struct bridge_softc *sc goto next; if (dst_if != src_if) { - mc = m_copym(m, 0, M_COPYALL, M_DONTWAIT); + mc = m_copypacket(m, M_DONTWAIT); if (mc == NULL) { sc->sc_if.if_oerrors++; goto next; } + /* + * Before enqueueing this packet to the destination + * interface, clear any in-bound checksum flags to + * prevent them from being misused as out-bound flags. + */ + mc->m_pkthdr.csum_flags = 0; + ACQUIRE_GLOBAL_LOCKS(); bridge_enqueue(sc, dst_if, mc, 1); RELEASE_GLOBAL_LOCKS(); } if (bmcast) { - mc = m_copym(m, 0, M_COPYALL, M_DONTWAIT); + mc = m_copypacket(m, M_DONTWAIT); if (mc == NULL) { sc->sc_if.if_oerrors++; goto next;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Fri Sep 7 12:31:30 UTC 2018 Modified Files: src/sys/net [netbsd-8]: route.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #1012): sys/net/route.c: revision 1.212 sys/net/route.c: revision 1.213 route: don't take an extra reference of a rtentry for the delayed free mechanism Because a reference is already taken at that point. - route: avoid overwriting rt_free_global.enqueued unexpectedly rt_free_global.enqueued can be set to true by rt_free during rt_free_work because rt_free_work releases rt_free_global.lock. So rt_free_work must update it once and not update after releasing the lock. To generate a diff of this commit: cvs rdiff -u -r1.194.6.10 -r1.194.6.11 src/sys/net/route.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/route.c diff -u src/sys/net/route.c:1.194.6.10 src/sys/net/route.c:1.194.6.11 --- src/sys/net/route.c:1.194.6.10 Fri Jun 8 10:14:33 2018 +++ src/sys/net/route.c Fri Sep 7 12:31:30 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.194.6.10 2018/06/08 10:14:33 martin Exp $ */ +/* $NetBSD: route.c,v 1.194.6.11 2018/09/07 12:31:30 martin Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.10 2018/06/08 10:14:33 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.11 2018/09/07 12:31:30 martin Exp $"); #include #ifdef RTFLUSH_DEBUG @@ -702,8 +702,8 @@ rt_free_work(struct work *wk, void *arg) struct rtentry *rt; mutex_enter(_free_global.lock); - rt_free_global.enqueued = false; if ((rt = SLIST_FIRST(_free_global.queue)) == NULL) { + rt_free_global.enqueued = false; mutex_exit(_free_global.lock); return; } @@ -726,7 +726,7 @@ rt_free(struct rtentry *rt) } mutex_enter(_free_global.lock); - rt_ref(rt); + /* No need to add a reference here. */ SLIST_INSERT_HEAD(_free_global.queue, rt, rt_free); if (!rt_free_global.enqueued) { workqueue_enqueue(rt_free_global.wq, _free_global.wk, NULL);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Aug 27 07:49:11 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #991): sys/net/if.c: revision 1.434 Restore splx removed accidentally at v1.406 Pointed out by k-goda@IIJ To generate a diff of this commit: cvs rdiff -u -r1.394.2.13 -r1.394.2.14 src/sys/net/if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.394.2.13 src/sys/net/if.c:1.394.2.14 --- src/sys/net/if.c:1.394.2.13 Fri Jul 13 16:01:12 2018 +++ src/sys/net/if.c Mon Aug 27 07:49:11 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.394.2.13 2018/07/13 16:01:12 martin Exp $ */ +/* $NetBSD: if.c,v 1.394.2.14 2018/08/27 07:49:11 martin Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.13 2018/07/13 16:01:12 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.14 2018/08/27 07:49:11 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -2326,6 +2326,7 @@ if_link_state_change_softint(struct ifne /* Ensure the change is still valid. */ if (ifp->if_link_state == link_state) { IF_LINK_STATE_CHANGE_UNLOCK(ifp); + splx(s); return; }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Aug 15 12:07:30 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_tun.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #974): sys/net/if_tun.c: revision 1.145 sys/net/if_tun.c: revision 1.146 tun: fix locking against myself filt_tunread is called with tun_lock held from tun_output (via tun_output => selnotify => knote), so we must not take tun_lock in filt_tunread. The bug is triggered only if a tun is used through kqueue. Found by k-goda@IIJ Fix tun(4) kevent locking filt_tunread gets called in two contexts: - by calls to selnotify in if_tun.c (or knote, as the case may be, but not here), in which case tp->tun_lock is held; and - by internal logic in kevent, in which tp->tun_lock is not held. The standard convention to discriminate between these two cases is by setting the kernel-only NOTE_SUBMIT bit in the hint to selnotify or knote; then in filt_*: if (hint & NOTE_SUBMIT) KASSERT(mutex_owned(>tun_lock)); else mutex_enter(>tun_lock); ... if (hint & NOTE_SUBMIT) KASSERT(mutex_owned(>tun_lock)); else mutex_exit(>tun_lock); Pointed out by and patch from riastradh@ Tested by ozaki-r@ (only the former path) To generate a diff of this commit: cvs rdiff -u -r1.139.2.3 -r1.139.2.4 src/sys/net/if_tun.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_tun.c diff -u src/sys/net/if_tun.c:1.139.2.3 src/sys/net/if_tun.c:1.139.2.4 --- src/sys/net/if_tun.c:1.139.2.3 Sat Mar 17 11:26:44 2018 +++ src/sys/net/if_tun.c Wed Aug 15 12:07:30 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tun.c,v 1.139.2.3 2018/03/17 11:26:44 martin Exp $ */ +/* $NetBSD: if_tun.c,v 1.139.2.4 2018/08/15 12:07:30 martin Exp $ */ /* * Copyright (c) 1988, Julian Onions @@ -19,7 +19,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139.2.3 2018/03/17 11:26:44 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139.2.4 2018/08/15 12:07:30 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -288,7 +288,7 @@ tun_clone_destroy(struct ifnet *ifp) tp->tun_flags &= ~TUN_RWAIT; cv_broadcast(>tun_cv); } - selnotify(>tun_rsel, 0, 0); + selnotify(>tun_rsel, 0, NOTE_SUBMIT); mutex_exit(>tun_lock); @@ -381,7 +381,7 @@ tunclose(dev_t dev, int flag, int mode, tp->tun_flags &= ~TUN_OPEN; tp->tun_pgid = 0; - selnotify(>tun_rsel, 0, 0); + selnotify(>tun_rsel, 0, NOTE_SUBMIT); TUNDEBUG ("%s: closed\n", ifp->if_xname); mutex_exit(>tun_lock); @@ -625,7 +625,7 @@ tun_output(struct ifnet *ifp, struct mbu if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid) softint_schedule(tp->tun_isih); - selnotify(>tun_rsel, 0, 0); + selnotify(>tun_rsel, 0, NOTE_SUBMIT); mutex_exit(>tun_lock); out: @@ -996,7 +996,7 @@ tunstart(struct ifnet *ifp) if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid) softint_schedule(tp->tun_osih); - selnotify(>tun_rsel, 0, 0); + selnotify(>tun_rsel, 0, NOTE_SUBMIT); } mutex_exit(>tun_lock); } @@ -1057,20 +1057,24 @@ filt_tunread(struct knote *kn, long hint struct tun_softc *tp = kn->kn_hook; struct ifnet *ifp = >tun_if; struct mbuf *m; + int ready; - mutex_enter(>tun_lock); - IF_POLL(>if_snd, m); - if (m == NULL) { - mutex_exit(>tun_lock); - return 0; - } + if (hint & NOTE_SUBMIT) + KASSERT(mutex_owned(>tun_lock)); + else + mutex_enter(>tun_lock); + IF_POLL(>if_snd, m); + ready = (m != NULL); for (kn->kn_data = 0; m != NULL; m = m->m_next) kn->kn_data += m->m_len; - mutex_exit(>tun_lock); + if (hint & NOTE_SUBMIT) + KASSERT(mutex_owned(>tun_lock)); + else + mutex_exit(>tun_lock); - return 1; + return ready; } static const struct filterops tunread_filtops =
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Fri Jul 13 16:01:12 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if.c Log Message: Pull up following revision(s) (requested by msaitoh in ticket #915): sys/net/if.c: revision 1.424 Print "NET_MPSAFE enabled" if it's enabled. To generate a diff of this commit: cvs rdiff -u -r1.394.2.12 -r1.394.2.13 src/sys/net/if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.394.2.12 src/sys/net/if.c:1.394.2.13 --- src/sys/net/if.c:1.394.2.12 Fri Jul 13 15:49:55 2018 +++ src/sys/net/if.c Fri Jul 13 16:01:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.394.2.12 2018/07/13 15:49:55 martin Exp $ */ +/* $NetBSD: if.c,v 1.394.2.13 2018/07/13 16:01:12 martin Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.12 2018/07/13 15:49:55 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.13 2018/07/13 16:01:12 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -309,6 +309,11 @@ ifinit(void) void ifinit1(void) { + +#ifdef NET_MPSAFE + printf("NET_MPSAFE enabled\n"); +#endif + mutex_init(_clone_mtx, MUTEX_DEFAULT, IPL_NONE); TAILQ_INIT(_list);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Jul 12 15:11:56 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_pppoe.c Log Message: Pull up following revision(s) (requested by yamaguchi in ticket #890): sys/net/if_pppoe.c: revision 1.137 sys/net/if_pppoe.c: revision 1.139 sys/net/if_pppoe.c: revision 1.140 Drop early if there's no PPPoE interface. Otherwise it is easy for someone to flood dmesg over the local subnet. Fix not to use PPPOE_UNLOCK before acccess to pppoe_softc to avoid a race condition According to the locking order of pppoe(4), the access to pppoe_softc has to follow 5 steps as below. 1. aquire pppoe_softc_list_lock 2. aquire pppoe_softc lock 3. release pppoe_softc_list_lock 4. access to pppoe_softc 5. release pppoe_softc lock However, pppoe_dispatch_disc_pkt() releases the lock of pppoe_softc temporarily, and then re-aquires it before step 4 of the adove. So, it is possible for other contexts to destroy a pppoe_softc in the interim. To fix this condition, avoid PPPOE_UNLOCK with the problem. ok by knakahara@n.o Fix to aquire pppoe_softc_list_lock before read and write the list ok by knakahara@n.o To generate a diff of this commit: cvs rdiff -u -r1.125.6.8 -r1.125.6.9 src/sys/net/if_pppoe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.125.6.8 src/sys/net/if_pppoe.c:1.125.6.9 --- src/sys/net/if_pppoe.c:1.125.6.8 Thu Jun 7 17:42:25 2018 +++ src/sys/net/if_pppoe.c Thu Jul 12 15:11:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.125.6.8 2018/06/07 17:42:25 martin Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.125.6.9 2018/07/12 15:11:56 martin Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.8 2018/06/07 17:42:25 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.9 2018/07/12 15:11:56 martin Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -277,8 +277,11 @@ pppoedetach(void) { int error = 0; - if (!LIST_EMPTY(_softc_list)) + rw_enter(_softc_list_lock, RW_READER); + if (!LIST_EMPTY(_softc_list)) { + rw_exit(_softc_list_lock); error = EBUSY; + } if (error == 0) { if_clone_detach(_cloner); @@ -338,9 +341,12 @@ pppoe_clone_create(struct if_clone *ifc, sppp_attach(>sc_sppp.pp_if); bpf_attach(>sc_sppp.pp_if, DLT_PPP_ETHER, 0); + rw_enter(_softc_list_lock, RW_READER); if (LIST_EMPTY(_softc_list)) { pfil_add_ihook(pppoe_ifattach_hook, NULL, PFIL_IFNET, if_pfil); } + rw_exit(_softc_list_lock); + if_register(>sc_sppp.pp_if); rw_init(>sc_lock); @@ -424,14 +430,18 @@ pppoe_find_softc_by_hunique(uint8_t *tok { struct pppoe_softc *sc, *t; - if (LIST_EMPTY(_softc_list)) + rw_enter(_softc_list_lock, RW_READER); + if (LIST_EMPTY(_softc_list)) { + rw_exit(_softc_list_lock); return NULL; + } - if (len != sizeof sc) + if (len != sizeof sc) { + rw_exit(_softc_list_lock); return NULL; + } memcpy(, token, len); - rw_enter(_softc_list_lock, RW_READER); LIST_FOREACH(sc, _softc_list, sc_list) { if (sc == t) { PPPOE_LOCK(sc, lock); @@ -518,15 +528,15 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, size_t ac_cookie_len; uint8_t *relay_sid; size_t relay_sid_len; -#ifdef PPPOE_SERVER uint8_t *hunique; size_t hunique_len; -#endif struct pppoehdr *ph; struct pppoetag *pt; struct mbuf *n; int noff, err, errortag; struct ether_header *eh; + struct ifnet *rcvif; + struct psref psref; /* as long as we don't know which instance */ strlcpy(devname, "pppoe", sizeof(devname)); @@ -545,10 +555,8 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, ac_cookie_len = 0; relay_sid = NULL; relay_sid_len = 0; -#ifdef PPPOE_SERVER hunique = NULL; hunique_len = 0; -#endif session = 0; if (m->m_pkthdr.len - off <= PPPOE_HEADERLEN) { printf("pppoe: packet too short: %d\n", m->m_pkthdr.len); @@ -601,8 +609,7 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, case PPPOE_TAG_SNAME: break; /* ignored */ case PPPOE_TAG_ACNAME: - error = NULL; - if (sc != NULL && len > 0) { + if (len > 0) { error = malloc(len + 1, M_TEMP, M_NOWAIT); if (error == NULL) break; @@ -616,40 +623,24 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, } strlcpy(error, mtod(n, char*) + noff, len + 1); -printf("%s: connected to %s\n", devname, error); +printf("pppoe: connected to %s\n", error); free(error, M_TEMP); } break; /* ignored */ - case PPPOE_TAG_HUNIQUE: { - struct ifnet *rcvif; - struct psref psref; + case PPPOE_TAG_HUNIQUE: + if (hunique == NULL) { +n = m_pulldown(m, off + sizeof(*pt), len, +); +if (!n) { + m = NULL; + err_msg = "TAG HUNIQUE ERROR"; + break; +} - if (sc != NULL) -break; - n = m_pulldown(m, off + sizeof(*pt), len, ); - if (!n) { -m
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Jul 11 16:50:46 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_llatbl.c Log Message: Additionally pullup src/sys/net/if_llatbl.c r1.30 to fix build fallout from previous, requested by both ozaki-r (ticket #918) and kre (ticket #920): Update previous so that there is no unused (but assigned) variable left when there is no ARP. Thanks gcc! To generate a diff of this commit: cvs rdiff -u -r1.18.6.6 -r1.18.6.7 src/sys/net/if_llatbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_llatbl.c diff -u src/sys/net/if_llatbl.c:1.18.6.6 src/sys/net/if_llatbl.c:1.18.6.7 --- src/sys/net/if_llatbl.c:1.18.6.6 Tue Jul 10 15:31:33 2018 +++ src/sys/net/if_llatbl.c Wed Jul 11 16:50:46 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_llatbl.c,v 1.18.6.6 2018/07/10 15:31:33 martin Exp $ */ +/* $NetBSD: if_llatbl.c,v 1.18.6.7 2018/07/11 16:50:46 martin Exp $ */ /* * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved. * Copyright (c) 2004-2008 Qing Li. All rights reserved. @@ -695,12 +695,14 @@ lla_rt_output(const u_char rtm_type, con * conditions so remove it first. */ if (lle != NULL) { - size_t pkts_dropped = llentry_free(lle); #if defined(INET) && NARP > 0 + size_t pkts_dropped = llentry_free(lle); if (dst->sa_family == AF_INET) { arp_stat_add(ARP_STAT_DFRDROPPED, (uint64_t)pkts_dropped); } +#else + (void) llentry_free(lle); #endif }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Tue Jul 10 15:31:33 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_llatbl.c Log Message: Additionally pull up the following, requested by ozaki-r in ticket #918: src/sys/net/if_llatbl.c 1.29 Avoid attempting to call arp related functions if there is no arp in the kernel. To generate a diff of this commit: cvs rdiff -u -r1.18.6.5 -r1.18.6.6 src/sys/net/if_llatbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_llatbl.c diff -u src/sys/net/if_llatbl.c:1.18.6.5 src/sys/net/if_llatbl.c:1.18.6.6 --- src/sys/net/if_llatbl.c:1.18.6.5 Tue Jul 10 14:41:31 2018 +++ src/sys/net/if_llatbl.c Tue Jul 10 15:31:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_llatbl.c,v 1.18.6.5 2018/07/10 14:41:31 martin Exp $ */ +/* $NetBSD: if_llatbl.c,v 1.18.6.6 2018/07/10 15:31:33 martin Exp $ */ /* * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved. * Copyright (c) 2004-2008 Qing Li. All rights reserved. @@ -696,10 +696,12 @@ lla_rt_output(const u_char rtm_type, con */ if (lle != NULL) { size_t pkts_dropped = llentry_free(lle); +#if defined(INET) && NARP > 0 if (dst->sa_family == AF_INET) { arp_stat_add(ARP_STAT_DFRDROPPED, (uint64_t)pkts_dropped); } +#endif } lle = lla_create(llt, 0, dst, rt);
CVS commit: [netbsd-8] src/sys/net/npf
Module Name:src Committed By: martin Date: Tue Jul 10 14:44:05 UTC 2018 Modified Files: src/sys/net/npf [netbsd-8]: npf_handler.c Log Message: Pull up following revision(s) (requested by maxv in ticket #919): sys/net/npf/npf_handler.c: revision 1.41 Update the pointer when fast-kicking, because it may have been freed. Before my changes the nonsensical pointer ininitialization held, but when I started introducing sanity checks the whole thing collapsed. Need pullup-8. To generate a diff of this commit: cvs rdiff -u -r1.37.6.1 -r1.37.6.2 src/sys/net/npf/npf_handler.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/npf/npf_handler.c diff -u src/sys/net/npf/npf_handler.c:1.37.6.1 src/sys/net/npf/npf_handler.c:1.37.6.2 --- src/sys/net/npf/npf_handler.c:1.37.6.1 Wed May 9 15:35:37 2018 +++ src/sys/net/npf/npf_handler.c Tue Jul 10 14:44:05 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_handler.c,v 1.37.6.1 2018/05/09 15:35:37 martin Exp $ */ +/* $NetBSD: npf_handler.c,v 1.37.6.2 2018/07/10 14:44:05 martin Exp $ */ /*- * Copyright (c) 2009-2013 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: npf_handler.c,v 1.37.6.1 2018/05/09 15:35:37 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_handler.c,v 1.37.6.2 2018/07/10 14:44:05 martin Exp $"); #include #include @@ -159,6 +159,7 @@ npf_packet_handler(npf_t *npf, struct mb /* If error on the format, leave quickly. */ if (flags & NPC_FMTERR) { + *mp = nbuf_head_mbuf(); error = EINVAL; goto fastout; }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Tue Jul 10 14:41:31 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_llatbl.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #918): sys/net/if_llatbl.c: revision 1.28 Don't overwrite an existing llentry on RTM_ADD to avoid race conditions Reported and tested by christos@ To generate a diff of this commit: cvs rdiff -u -r1.18.6.4 -r1.18.6.5 src/sys/net/if_llatbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_llatbl.c diff -u src/sys/net/if_llatbl.c:1.18.6.4 src/sys/net/if_llatbl.c:1.18.6.5 --- src/sys/net/if_llatbl.c:1.18.6.4 Sat Jun 9 14:44:33 2018 +++ src/sys/net/if_llatbl.c Tue Jul 10 14:41:31 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_llatbl.c,v 1.18.6.4 2018/06/09 14:44:33 martin Exp $ */ +/* $NetBSD: if_llatbl.c,v 1.18.6.5 2018/07/10 14:41:31 martin Exp $ */ /* * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved. * Copyright (c) 2004-2008 Qing Li. All rights reserved. @@ -677,7 +677,7 @@ lla_rt_output(const u_char rtm_type, con /* Add static LLE */ IF_AFDATA_WLOCK(ifp); - lle = lla_lookup(llt, 0, dst); + lle = lla_lookup(llt, LLE_EXCLUSIVE, dst); /* Cannot overwrite an existing static entry */ if (lle != NULL && @@ -689,8 +689,18 @@ lla_rt_output(const u_char rtm_type, con error = EEXIST; goto out; } - if (lle != NULL) - LLE_RUNLOCK(lle); + + /* + * We can't overwrite an existing entry to avoid race + * conditions so remove it first. + */ + if (lle != NULL) { + size_t pkts_dropped = llentry_free(lle); + if (dst->sa_family == AF_INET) { +arp_stat_add(ARP_STAT_DFRDROPPED, +(uint64_t)pkts_dropped); + } + } lle = lla_create(llt, 0, dst, rt); if (lle == NULL) {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Sat Jun 9 14:44:33 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_llatbl.c Log Message: Pull up following revision(s) (requested by nonaka in ticket #862): sys/net/if_llatbl.c: revision 1.27 It is necessary to set wall time instead of monotonic time to rmx_expire. To generate a diff of this commit: cvs rdiff -u -r1.18.6.3 -r1.18.6.4 src/sys/net/if_llatbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_llatbl.c diff -u src/sys/net/if_llatbl.c:1.18.6.3 src/sys/net/if_llatbl.c:1.18.6.4 --- src/sys/net/if_llatbl.c:1.18.6.3 Tue Mar 13 13:27:10 2018 +++ src/sys/net/if_llatbl.c Sat Jun 9 14:44:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_llatbl.c,v 1.18.6.3 2018/03/13 13:27:10 martin Exp $ */ +/* $NetBSD: if_llatbl.c,v 1.18.6.4 2018/06/09 14:44:33 martin Exp $ */ /* * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved. * Copyright (c) 2004-2008 Qing Li. All rights reserved. @@ -112,8 +112,8 @@ lltable_dump_entry(struct lltable *llt, /* Need to copy by myself */ rtm->rtm_index = ifp->if_index; rtm->rtm_rmx.rmx_mtu = 0; - rtm->rtm_rmx.rmx_expire = - (lle->la_flags & LLE_STATIC) ? 0 : lle->la_expire; + rtm->rtm_rmx.rmx_expire = (lle->la_flags & LLE_STATIC) ? 0 : + time_mono_to_wall(lle->la_expire); rtm->rtm_flags = RTF_UP; rtm->rtm_flags |= RTF_HOST; /* For ndp */ /* For backward compatibility */
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Jun 7 17:50:54 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #844): sys/net/if.c: revision 1.425 Relax a lock check in if_mcast_op unless NET_MPSAFE It seems that there remain some paths that don't satisfy the constraint that is required only if NET_MPSAFE. So don't check it by default. One known path is nd6_rtrequest => in6_addmulti => if_mcast_op, which is not easy to address. To generate a diff of this commit: cvs rdiff -u -r1.394.2.10 -r1.394.2.11 src/sys/net/if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.394.2.10 src/sys/net/if.c:1.394.2.11 --- src/sys/net/if.c:1.394.2.10 Tue May 15 13:48:37 2018 +++ src/sys/net/if.c Thu Jun 7 17:50:54 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin Exp $ */ +/* $NetBSD: if.c,v 1.394.2.11 2018/06/07 17:50:54 martin Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.11 2018/06/07 17:50:54 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -3601,10 +3601,13 @@ if_mcast_op(ifnet_t *ifp, const unsigned int rc; struct ifreq ifr; + /* There remain some paths that don't hold IFNET_LOCK yet */ +#ifdef NET_MPSAFE /* CARP and MROUTING still don't deal with the lock yet */ #if (!defined(NCARP) || (NCARP == 0)) && !defined(MROUTING) KASSERT(IFNET_LOCKED(ifp)); #endif +#endif if (ifp->if_mcastop != NULL) rc = (*ifp->if_mcastop)(ifp, cmd, sa); else {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Jun 7 16:22:43 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_ipsec.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #840): sys/net/if_ipsec.c: revision 1.15,1.16 Fix panic when ipsecif(4) adds discard policy. Pointed out by ohishi@IIJ, thanks. Reviewd by ohishi@IIJ. Sorry, I jumped the gun and committed. Fix the following two issues. - remove extra padding of sizeof(xisr) when adding ipsec policy - add padding for xpl when adding discard policy To generate a diff of this commit: cvs rdiff -u -r1.3.2.8 -r1.3.2.9 src/sys/net/if_ipsec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ipsec.c diff -u src/sys/net/if_ipsec.c:1.3.2.8 src/sys/net/if_ipsec.c:1.3.2.9 --- src/sys/net/if_ipsec.c:1.3.2.8 Thu Jun 7 16:19:47 2018 +++ src/sys/net/if_ipsec.c Thu Jun 7 16:22:43 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ipsec.c,v 1.3.2.8 2018/06/07 16:19:47 martin Exp $ */ +/* $NetBSD: if_ipsec.c,v 1.3.2.9 2018/06/07 16:22:43 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.8 2018/06/07 16:19:47 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.9 2018/06/07 16:22:43 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1591,6 +1591,7 @@ if_ipsec_add_sp0(struct sockaddr *src, i if_ipsec_add_pad(m, padlen); if_ipsec_add_mbuf(m, , sizeof(xpl)); + padlen = PFKEY_UNUNIT64(xpl.sadb_x_policy_len) - sizeof(xpl); if (policy == IPSEC_POLICY_IPSEC) { if_ipsec_add_mbuf(m, , sizeof(xisr)); /* @@ -1599,10 +1600,9 @@ if_ipsec_add_sp0(struct sockaddr *src, i */ if_ipsec_add_mbuf_addr_port(m, src, sport, false); if_ipsec_add_mbuf_addr_port(m, dst, dport, false); - } - padlen = PFKEY_UNUNIT64(xpl.sadb_x_policy_len) - sizeof(xpl); - if (src != NULL && dst != NULL) + padlen -= PFKEY_ALIGN8(sizeof(xisr)); padlen -= PFKEY_ALIGN8(src->sa_len + dst->sa_len); + } if_ipsec_add_pad(m, padlen); /* key_kpi_spdadd() has already done KEY_SP_REF(). */
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Jun 7 16:19:47 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_ipsec.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #839): sys/net/if_ipsec.c: revision 1.14 ipsecif(4) must not set port number to spidx even if NAT-T. Pointed out by ohishi@IIJ, thanks. To generate a diff of this commit: cvs rdiff -u -r1.3.2.7 -r1.3.2.8 src/sys/net/if_ipsec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ipsec.c diff -u src/sys/net/if_ipsec.c:1.3.2.7 src/sys/net/if_ipsec.c:1.3.2.8 --- src/sys/net/if_ipsec.c:1.3.2.7 Thu May 17 14:07:03 2018 +++ src/sys/net/if_ipsec.c Thu Jun 7 16:19:47 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ipsec.c,v 1.3.2.7 2018/05/17 14:07:03 martin Exp $ */ +/* $NetBSD: if_ipsec.c,v 1.3.2.8 2018/06/07 16:19:47 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.7 2018/05/17 14:07:03 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.8 2018/06/07 16:19:47 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1574,13 +1574,18 @@ if_ipsec_add_sp0(struct sockaddr *src, i m_copyback(m, 0, sizeof(msg), ); if_ipsec_add_mbuf(m, , sizeof(xsrc)); - if_ipsec_add_mbuf_addr_port(m, src, sport, true); + /* + * secpolicy.spidx.{src, dst} must not be set port number, + * even if it is used for NAT-T. + */ + if_ipsec_add_mbuf_addr_port(m, src, 0, true); padlen = PFKEY_UNUNIT64(xsrc.sadb_address_len) - (sizeof(xsrc) + PFKEY_ALIGN8(src->sa_len)); if_ipsec_add_pad(m, padlen); if_ipsec_add_mbuf(m, , sizeof(xdst)); - if_ipsec_add_mbuf_addr_port(m, dst, dport, true); + /* ditto */ + if_ipsec_add_mbuf_addr_port(m, dst, 0, true); padlen = PFKEY_UNUNIT64(xdst.sadb_address_len) - (sizeof(xdst) + PFKEY_ALIGN8(dst->sa_len)); if_ipsec_add_pad(m, padlen); @@ -1588,6 +1593,10 @@ if_ipsec_add_sp0(struct sockaddr *src, i if_ipsec_add_mbuf(m, , sizeof(xpl)); if (policy == IPSEC_POLICY_IPSEC) { if_ipsec_add_mbuf(m, , sizeof(xisr)); + /* + * secpolicy.req->saidx.{src, dst} must be set port number, + * when it is used for NAT-T. + */ if_ipsec_add_mbuf_addr_port(m, src, sport, false); if_ipsec_add_mbuf_addr_port(m, dst, dport, false); }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu May 17 14:02:31 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_ipsec.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #828): sys/net/if_ipsec.c: revision 1.12 Fix "how" argument of MGET(). Pointed out by maxv@n.o, thanks. MGET() does not have M_ZERO flag, so add memset when it is required. To generate a diff of this commit: cvs rdiff -u -r1.3.2.5 -r1.3.2.6 src/sys/net/if_ipsec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ipsec.c diff -u src/sys/net/if_ipsec.c:1.3.2.5 src/sys/net/if_ipsec.c:1.3.2.6 --- src/sys/net/if_ipsec.c:1.3.2.5 Mon Apr 9 17:01:20 2018 +++ src/sys/net/if_ipsec.c Thu May 17 14:02:31 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ipsec.c,v 1.3.2.5 2018/04/09 17:01:20 martin Exp $ */ +/* $NetBSD: if_ipsec.c,v 1.3.2.6 2018/05/17 14:02:31 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.5 2018/04/09 17:01:20 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.6 2018/05/17 14:02:31 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1339,10 +1339,11 @@ if_ipsec_add_mbuf_optalign(struct mbuf * { struct mbuf *m; - MGET(m, M_WAITOK | M_ZERO, MT_DATA); - if (align) + MGET(m, M_WAIT, MT_DATA); + if (align) { m->m_len = PFKEY_ALIGN8(len); - else + memset(mtod(m, void *), 0, m->m_len); + } else m->m_len = len; m_copyback(m, 0, len, data); m_cat(m0, m); @@ -1378,8 +1379,9 @@ if_ipsec_add_pad(struct mbuf *m0, size_t if (len == 0) return; - MGET(m, M_WAITOK | M_ZERO, MT_DATA); + MGET(m, M_WAIT, MT_DATA); m->m_len = len; + memset(mtod(m, void *), 0, m->m_len); m_cat(m0, m); } @@ -1556,7 +1558,7 @@ if_ipsec_add_sp0(struct sockaddr *src, i memset(, 0, sizeof(xpl)); memset(, 0, sizeof(xisr)); - MGETHDR(m, M_WAITOK, MT_DATA); + MGETHDR(m, M_WAIT, MT_DATA); size = if_ipsec_set_sadb_src(, src, proto); ext_msg_len += PFKEY_UNIT64(size); @@ -1683,7 +1685,7 @@ if_ipsec_del_sp0(struct secpolicy *sp) memset(, 0, sizeof(msg)); memset(, 0, sizeof(xpl)); - MGETHDR(m, M_WAITOK, MT_DATA); + MGETHDR(m, M_WAIT, MT_DATA); size = if_ipsec_set_sadb_x_policy(, NULL, 0, 0, sp->id, 0, NULL, NULL); ext_msg_len += PFKEY_UNIT64(size);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Tue May 15 13:48:37 UTC 2018 Modified Files: src/sys/net [netbsd-8]: bpf.c if.c if_bridge.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #826): sys/net/if_bridge.c: revision 1.155 sys/net/if.c: revision 1.421 sys/net/bpf.c: revision 1.224 sys/net/if.c: revision 1.422 sys/net/if.c: revision 1.423 Use if_is_mpsafe (NFC) Protect packet input routines with KERNEL_LOCK and splsoftnet if_input, i.e, ether_input and friends, now runs in softint without any protections. It's ok for ether_input itself because it's already MP-safe, however, subsequent routines called from it such as carp_input and agr_input aren't safe because they're not MP-safe. Protect if_input with KERNEL_LOCK. if_input can be called from a normal LWP context. In that case we need to prevent interrupts (softint) from running by splsoftnet to protect non-MP-safe codes (e.g., carp_input and agr_input). Pointed out by mlelstv@ Protect if_deferred_start_softint with KERNEL_LOCK if the interface isn't MP-safe To generate a diff of this commit: cvs rdiff -u -r1.216.6.5 -r1.216.6.6 src/sys/net/bpf.c cvs rdiff -u -r1.394.2.9 -r1.394.2.10 src/sys/net/if.c cvs rdiff -u -r1.134.6.9 -r1.134.6.10 src/sys/net/if_bridge.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.216.6.5 src/sys/net/bpf.c:1.216.6.6 --- src/sys/net/bpf.c:1.216.6.5 Mon Feb 5 14:18:00 2018 +++ src/sys/net/bpf.c Tue May 15 13:48:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $ */ +/* $NetBSD: bpf.c,v 1.216.6.6 2018/05/15 13:48:37 martin Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.6 2018/05/15 13:48:37 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_bpf.h" @@ -836,9 +836,13 @@ bpf_write(struct file *fp, off_t *offp, error = if_output_lock(ifp, ifp, m, (struct sockaddr *) , NULL); if (mc != NULL) { - if (error == 0) + if (error == 0) { + int s = splsoftnet(); + KERNEL_LOCK_UNLESS_IFP_MPSAFE(ifp); ifp->_if_input(ifp, mc); - else + KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(ifp); + splx(s); + } else m_freem(mc); } /* Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.394.2.9 src/sys/net/if.c:1.394.2.10 --- src/sys/net/if.c:1.394.2.9 Wed Feb 28 18:54:43 2018 +++ src/sys/net/if.c Tue May 15 13:48:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.394.2.9 2018/02/28 18:54:43 martin Exp $ */ +/* $NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.9 2018/02/28 18:54:43 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -716,8 +716,7 @@ if_initialize(ifnet_t *ifp) if (if_is_link_state_changeable(ifp)) { u_int flags = SOFTINT_NET; - flags |= ISSET(ifp->if_extflags, IFEF_MPSAFE) ? - SOFTINT_MPSAFE : 0; + flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0; ifp->if_link_si = softint_establish(flags, if_link_state_change_si, ifp); if (ifp->if_link_si == NULL) { @@ -834,11 +833,13 @@ struct if_percpuq * if_percpuq_create(struct ifnet *ifp) { struct if_percpuq *ipq; + u_int flags = SOFTINT_NET; + + flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0; ipq = kmem_zalloc(sizeof(*ipq), KM_SLEEP); ipq->ipq_ifp = ifp; - ipq->ipq_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE, - if_percpuq_softint, ipq); + ipq->ipq_si = softint_establish(flags, if_percpuq_softint, ipq); ipq->ipq_ifqs = percpu_alloc(sizeof(struct ifqueue)); percpu_foreach(ipq->ipq_ifqs, _percpuq_init_ifq, NULL); @@ -1066,11 +1067,13 @@ void if_deferred_start_init(struct ifnet *ifp, void (*func)(struct ifnet *)) { struct if_deferred_start *ids; + u_int flags = SOFTINT_NET; + + flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0; ids = kmem_zalloc(sizeof(*ids), KM_SLEEP); ids->ids_ifp = ifp; - ids->ids_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE, - if_deferred_start_softint, ids); + ids->ids_si = softint_establish(flags, if_deferred_start_softint, ids); if (func != NULL) ids->ids_if_start = func; else Index: src/sys/net/if_bridge.c diff -u src/sys/net/if_bridge.c:1.134.6.9 src/sys/net/if_bridge.c:1.134.6.10 --- src/sys/net/if_bridge.c:1.134.6.9 Wed Apr 18 14:11:42 2018 +++ src/sys/net/if_bridge.c Tue May 15 13:48:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_bridge.c,v 1.134.6.9 2018/04/18 14:11:42 martin Exp $ */ +/* $NetBSD: if_bridge.c,v 1.134.6.10 2018/05/15 13:48:37 martin Exp $ */ /* * Copyright 2001
CVS commit: [netbsd-8] src/sys/net/npf
Module Name:src Committed By: martin Date: Mon May 14 19:22:30 UTC 2018 Modified Files: src/sys/net/npf [netbsd-8]: npf_alg_icmp.c npf_inet.c npf_sendpkt.c Log Message: Pull up following revision(s) (requested by maxv in ticket #823): sys/net/npf/npf_inet.c: revision 1.45-1.47 sys/net/npf/npf_alg_icmp.c: revision 1.27-1.30 sys/net/npf/npf_sendpkt.c: revision 1.19 Fix use-after-free. The nbuf can be reallocated as a result of caching 'enpc', so it is necessary to recache 'npc', otherwise it contains pointers to the freed mbuf - pointers which are then used in the ruleset machinery. We recache 'npc' when we are sure we won't use 'enpc' anymore, because 'enpc' can be clobbered as a result of caching 'npc' (in other words, only one of the two can be cached at the same time). Also, we recache 'npc' unconditionally, because there is no way to know whether the nbuf got clobbered relatively to it. We can't use the NBUF_DATAREF_RESET flag, because it is stored in the nbuf and not in the cache. Discussed with rmind@. Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later. Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly. In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf). This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free. Retrieve the complete IPv4 header right away, and make sure we did retrieve the IPv6 option header we were iterating on. Ah, fix compilation. I tested my previous change by loading the kernel module from the filesystem, but the Makefile didn't have DIAGNOSTIC enabled, and the two KASSERTs I added did not compile properly. If we fail to advance inside TCP/UDP/ICMPv4/ICMPv6, stop pretending L4 is unknown, and error out right away. This prevents bugs in machinery, if a place looks for L4 in 'npc_proto' without checking the cache too. I've seen a ~similar problem already. In addition to checking L4 in the cache, here we also need to check the protocol. The NPF entry point does not ensure that ICMPv6 can be set only in IPv6 ICMPv4 can be set only in IPv4 So we could have ICMPv6 in IPv4. apply some INET6 so this compiles in INET6-less kernels again. To generate a diff of this commit: cvs rdiff -u -r1.24.8.1 -r1.24.8.2 src/sys/net/npf/npf_alg_icmp.c cvs rdiff -u -r1.37.6.1 -r1.37.6.2 src/sys/net/npf/npf_inet.c cvs rdiff -u -r1.16.8.1 -r1.16.8.2 src/sys/net/npf/npf_sendpkt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/npf/npf_alg_icmp.c diff -u src/sys/net/npf/npf_alg_icmp.c:1.24.8.1 src/sys/net/npf/npf_alg_icmp.c:1.24.8.2 --- src/sys/net/npf/npf_alg_icmp.c:1.24.8.1 Wed May 9 15:35:37 2018 +++ src/sys/net/npf/npf_alg_icmp.c Mon May 14 19:22:30 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_alg_icmp.c,v 1.24.8.1 2018/05/09 15:35:37 martin Exp $ */ +/* $NetBSD: npf_alg_icmp.c,v 1.24.8.2 2018/05/14 19:22:30 martin Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: npf_alg_icmp.c,v 1.24.8.1 2018/05/09 15:35:37 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_alg_icmp.c,v 1.24.8.2 2018/05/14 19:22:30 martin Exp $"); #include #include @@ -120,13 +120,15 @@ npfa_icmp_match(npf_cache_t *npc, npf_na /* * npfa_icmp{4,6}_inspect: retrieve unique identifiers - either ICMP query * ID or TCP/UDP ports of the original packet, which is embedded. + * + * => Sets hasqid=true if the packet has a Query Id. In this case neither + *the nbuf nor npc is touched. */ static bool -npfa_icmp4_inspect(const int type, npf_cache_t *npc) +npfa_icmp4_inspect(const int type, npf_cache_t *npc, bool *hasqid) { nbuf_t *nbuf = npc->npc_nbuf; - u_int offby; /* Per RFC 792. */ switch (type) { @@ -147,12 +149,8 @@ npfa_icmp4_inspect(const int type, npf_c case ICMP_TSTAMPREPLY: case ICMP_IREQ: case ICMP_IREQREPLY: - /* Should contain ICMP query ID - ensure. */ - offby = offsetof(struct icmp, icmp_id); - if (!nbuf_advance(nbuf, offby, sizeof(uint16_t))) { - return false; - } - npc->npc_info |= NPC_ICMP_ID; + /* Contains ICMP query ID. */ + *hasqid = true; return true; default: break; @@ -161,10 +159,9 @@ npfa_icmp4_inspect(const int type, npf_c } static bool -npfa_icmp6_inspect(const int type, npf_cache_t *npc) +npfa_icmp6_inspect(const int type, npf_cache_t *npc, bool *hasqid) { nbuf_t *nbuf = npc->npc_nbuf; - u_int offby; /* Per RFC 4443. */ switch (type) { @@ -180,12 +177,8 @@ npfa_icmp6_inspect(const int type, npf_c case ICMP6_ECHO_REQUEST: case ICMP6_ECHO_REPLY: - /*
CVS commit: [netbsd-8] src/sys/net/npf
Module Name:src Committed By: martin Date: Wed May 9 15:35:37 UTC 2018 Modified Files: src/sys/net/npf [netbsd-8]: npf.h npf_alg_icmp.c npf_handler.c npf_inet.c npf_sendpkt.c Log Message: Pull up following revision(s) (requested by maxv in ticket #817): sys/net/npf/npf_inet.c: revision 1.38-1.44 sys/net/npf/npf_handler.c: revision 1.38-1.39 sys/net/npf/npf_alg_icmp.c: revision 1.26 sys/net/npf/npf.h: revision 1.56 sys/net/npf/npf_sendpkt.c: revision 1.17-1.18 Declare NPC_FMTERR, and use it to kick malformed packets. Several sanity checks are added in IPv6; after we see the first IPPROTO_FRAGMENT header, we are allowed to fail to advance, otherwise we kick the packet. Sent on tech-net@ a few days ago, no response, but I'm committing it now anyway. Switch nptr to uint8_t, and use nbuf_ensure_contig. Makes us use fewer magic values. Remove dead branches, 'npc' can't be NULL (and it is dereferenced earlier). Fix two consecutive mistakes. The first mistake was npf_inet.c rev1.37: "Don't reassemble ipv6 fragments, instead treat the first fragment as a regular packet (subject to filtering rules), and pass subsequent fragments in the same group unconditionally." Doing this was entirely wrong, because then a packet just had to push the L4 payload in a secondary fragment, and NPF wouldn't apply rules on it - meaning any IPv6 packet could bypass >=L4 filtering. This mistake was supposed to be a fix for the second mistake. The second mistake was that ip6_reass_packet (in npf_reassembly) was getting called with npc->npc_hlen. But npc_hlen pointed to the last encountered header in the IPv6 chain, which was not necessarily the fragment header. So ip6_reass_packet was given garbage, and would fail, resulting in the packet getting kicked. So basically IPv6 was broken by NPF. The first mistake is reverted, and the second one is fixed by doing: - hlen = sizeof(struct ip6_frag); + hlen = 0; Now the iteration stops on the fragment header, and the call to ip6_reass_packet is valid. My npf_inet.c rev1.38 is partially reverted: we don't need to worry about failing properly to advance; once the packet is reassembled npf_cache_ip gets called again, and this time the whole chain should be there. Tested with a simple UDPv6 server - send a 3000-byte-sized buffer, the packet gets correctly reassembled by NPF now. Mmh, put back the RFC6946 check (about dummy fragments), otherwise NPF is not happy in npf_reassembly, because NPC_IPFRAG is again returned after the packet was reassembled. I'm wondering whether it would not be better to just remove the fragment header in frag6_input directly. Fix the "return-rst" rule on IPv6 packets. The scopes needed to be set on the addresses before invoking ip6_output, because ip6_output needs them. The reason they are not here already is because pfil_run_hooks (in ip6_input) is called _before_ the kernel initializes the scopes. Until now ip6_output was always failing, and the IPv6-TCP-RST packet was never actually sent. Perhaps it would be better to have the kernel initialize the scopes before invoking pfil_run_hooks, but several things will need to be fixed in several places. Tested with a simple TCPv6 server. Until now the client would block waiting for an answer that never came; now it receives an RST right away and closes the connection, as expected. I believe that the same problem exists in the "return-icmp" rules, but I can't investigate this right now (some problems with wireshark). Fix the IPv6 payload computation in npf_tcpsaw. It was incorrect, and this caused the "return-rst" rules to send back an RST with the wrong ACK when the received SYN had an IPv6 option. Set the scopes before calling icmp6_error(). This fixes a bug similar to the one I fixed in rev1.17: since the scopes were not set the packet was never actually sent. Tested with wireshark, now the ICMPv6 reply is correctly sent, as expected. Don't read the L4 payload after IPPROTO_AH when handling IPv6 packets. AH must be considered as the payload, otherwise a block all pass in proto ah from any pass out proto ah from any configuration will actually block everything, because NPF checks the protocol against the one found after AH, and not AH itself. In addition it may have been a problem for stateful connections; an AH packet sent by an attacker with an incorrect authentication and a correct TCP/UDP/whatever payload from an active connection could manage to change NPF's FSM state, which would perhaps have altered the legitimate connection with the authenticated remote IPsec host. Note that IPv4 already doesn't go beyond AH, which is the correct behavior. Add XXX (we don't handle IPv6 Jumbograms), and whitespace. To generate a diff of this commit: cvs rdiff -u -r1.54.6.1 -r1.54.6.2 src/sys/net/npf/npf.h cvs rdiff -u -r1.24 -r1.24.8.1
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Sun May 6 13:09:06 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Pull up following revision(s) (requested by spz in ticket #813): sys/net/if_vlan.c: revision 1.122 If cnt == 0, don't kmem_alloc(0). Found by Mootja. Looking at the code, I also find it suspicious that we read ifv->ifv_mib->ifvm_p directly without making sure ifv_mib != NULL. To generate a diff of this commit: cvs rdiff -u -r1.97.2.12 -r1.97.2.13 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.12 src/sys/net/if_vlan.c:1.97.2.13 --- src/sys/net/if_vlan.c:1.97.2.12 Sat Apr 14 10:38:59 2018 +++ src/sys/net/if_vlan.c Sun May 6 13:09:05 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.12 2018/04/14 10:38:59 martin Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.13 2018/05/06 13:09:05 martin Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.12 2018/04/14 10:38:59 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.13 2018/05/06 13:09:05 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -800,6 +800,7 @@ vlan_ifdetach(struct ifnet *p) int i, cnt = 0; bound = curlwp_bind(); + mutex_enter(_list.lock); LIST_FOREACH(ifv, _list.list, ifv_list) { mib = vlan_getref_linkmib(ifv, ); @@ -813,13 +814,18 @@ vlan_ifdetach(struct ifnet *p) } mutex_exit(_list.lock); + if (cnt == 0) { + curlwp_bindx(bound); + return; + } + /* * The value of "cnt" does not increase while ifv_list.lock * and ifv->ifv_lock are released here, because the parent * interface is detaching. */ nmibs = kmem_alloc(sizeof(*nmibs) * cnt, KM_SLEEP); - for (i=0; i < cnt; i++) { + for (i = 0; i < cnt; i++) { nmibs[i] = kmem_alloc(sizeof(*nmibs[i]), KM_SLEEP); } @@ -847,9 +853,10 @@ vlan_ifdetach(struct ifnet *p) } mutex_exit(_list.lock); + curlwp_bindx(bound); - for (i=0; i < cnt; i++) { + for (i = 0; i < cnt; i++) { if (nmibs[i]) kmem_free(nmibs[i], sizeof(*nmibs[i])); }
CVS commit: [netbsd-8] src/sys/net/npf
Module Name:src Committed By: martin Date: Sat May 5 19:15:55 UTC 2018 Modified Files: src/sys/net/npf [netbsd-8]: npf_nat.c Log Message: Pull up following revision(s) (requested by prlw1 in ticket #795): sys/net/npf/npf_nat.c: revision 1.42 PR/53207: David Binderman: Use logical and To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.41.8.1 src/sys/net/npf/npf_nat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/npf/npf_nat.c diff -u src/sys/net/npf/npf_nat.c:1.41 src/sys/net/npf/npf_nat.c:1.41.8.1 --- src/sys/net/npf/npf_nat.c:1.41 Mon Dec 26 23:05:06 2016 +++ src/sys/net/npf/npf_nat.c Sat May 5 19:15:55 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_nat.c,v 1.41 2016/12/26 23:05:06 christos Exp $ */ +/* $NetBSD: npf_nat.c,v 1.41.8.1 2018/05/05 19:15:55 martin Exp $ */ /*- * Copyright (c) 2014 Mindaugas Rasiukevicius @@ -72,7 +72,7 @@ #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: npf_nat.c,v 1.41 2016/12/26 23:05:06 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_nat.c,v 1.41.8.1 2018/05/05 19:15:55 martin Exp $"); #include #include @@ -890,7 +890,7 @@ npf_nat_import(npf_t *npf, prop_dictiona prop_dictionary_get_uint16(natdict, "tport", >nt_tport); /* Take a specific port from port-map. */ - if ((np->n_flags & NPF_NAT_PORTMAP) != 0 && nt->nt_tport & + if ((np->n_flags & NPF_NAT_PORTMAP) != 0 && nt->nt_tport && !npf_nat_takeport(np, nt->nt_tport)) { pool_cache_put(nat_cache, nt); return NULL;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Sat May 5 19:07:52 UTC 2018 Modified Files: src/sys/net [netbsd-8]: rtsock.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #788): sys/net/rtsock.c: revision 1.241 Fix a deadlock (rt_free vs. route_intr on rt_so_mtx) It occurs only if NET_MPSAFE is enabled. To generate a diff of this commit: cvs rdiff -u -r1.213.2.9 -r1.213.2.10 src/sys/net/rtsock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/rtsock.c diff -u src/sys/net/rtsock.c:1.213.2.9 src/sys/net/rtsock.c:1.213.2.10 --- src/sys/net/rtsock.c:1.213.2.9 Sat Apr 14 10:16:19 2018 +++ src/sys/net/rtsock.c Sat May 5 19:07:51 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: rtsock.c,v 1.213.2.9 2018/04/14 10:16:19 martin Exp $ */ +/* $NetBSD: rtsock.c,v 1.213.2.10 2018/05/05 19:07:51 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.9 2018/04/14 10:16:19 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.10 2018/05/05 19:07:51 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -928,9 +928,19 @@ flush: if (old_rtm != NULL) Free(old_rtm); if (rt) { - if (do_rt_free) + if (do_rt_free) { +#ifdef NET_MPSAFE + /* + * Release rt_so_mtx to avoid a deadlock with + * route_intr. + */ + mutex_exit(rt_so_mtx); rt_free(rt); - else + mutex_enter(rt_so_mtx); +#else + rt_free(rt); +#endif + } else rt_unref(rt); } {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Apr 18 14:16:57 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_pppoe.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #779): sys/net/if_pppoe.c: revision 1.135,1.136 net.pppoe.term_unknown can be written safely now. Fix sending PADT to unexpected hosts when net.pppoe.term_unknown is enabled. To generate a diff of this commit: cvs rdiff -u -r1.125.6.6 -r1.125.6.7 src/sys/net/if_pppoe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.125.6.6 src/sys/net/if_pppoe.c:1.125.6.7 --- src/sys/net/if_pppoe.c:1.125.6.6 Thu Mar 8 13:22:25 2018 +++ src/sys/net/if_pppoe.c Wed Apr 18 14:16:57 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.125.6.6 2018/03/08 13:22:25 martin Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.125.6.7 2018/04/18 14:16:57 martin Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.6 2018/03/08 13:22:25 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.7 2018/04/18 14:16:57 martin Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v #include #include #include +#include #include @@ -236,6 +237,7 @@ static int pppoe_clone_create(struct if_ static int pppoe_clone_destroy(struct ifnet *); static bool pppoe_term_unknown = false; +static int pppoe_term_unknown_pps = 1; static struct sysctllog *pppoe_sysctl_clog; static void sysctl_net_pppoe_setup(struct sysctllog **); @@ -951,6 +953,16 @@ pppoe_disc_input(struct mbuf *m) m_freem(m); } +static bool +pppoe_is_my_frame(uint8_t *dhost, struct ifnet *rcvif) +{ + + if (memcmp(CLLADDR(rcvif->if_sadl), dhost, ETHER_ADDR_LEN) == 0) + return true; + + return false; +} + static void pppoe_data_input(struct mbuf *m) { @@ -960,12 +972,17 @@ pppoe_data_input(struct mbuf *m) struct ifnet *rcvif; struct psref psref; uint8_t shost[ETHER_ADDR_LEN]; + uint8_t dhost[ETHER_ADDR_LEN]; + bool term_unknown = pppoe_term_unknown; KASSERT(m->m_flags & M_PKTHDR); - if (pppoe_term_unknown) + if (term_unknown) { memcpy(shost, mtod(m, struct ether_header*)->ether_shost, ETHER_ADDR_LEN); + memcpy(dhost, mtod(m, struct ether_header*)->ether_dhost, + ETHER_ADDR_LEN); + } m_adj(m, sizeof(struct ether_header)); if (m->m_pkthdr.len <= PPPOE_HEADERLEN) { printf("pppoe (data): dropping too short packet: %d bytes\n", @@ -996,10 +1013,21 @@ pppoe_data_input(struct mbuf *m) goto drop; sc = pppoe_find_softc_by_session(session, rcvif, RW_READER); if (sc == NULL) { - if (pppoe_term_unknown) { - printf("pppoe: input for unknown session %#x, " - "sending PADT\n", session); - pppoe_send_padt(rcvif, session, shost); + if (term_unknown) { + static struct timeval lasttime = {0, 0}; + static int curpps = 0; + /* + * avoid to send wrong PADT which is response from + * session stage pakcets for other hosts when parent + * ethernet is promiscuous mode. + */ + if (pppoe_is_my_frame(dhost, rcvif) + && ppsratecheck(, , +pppoe_term_unknown_pps)) { +printf("pppoe: input for unknown session %#x, " +"sending PADT\n", session); +pppoe_send_padt(rcvif, session, shost); + } } m_put_rcvif_psref(rcvif, ); goto drop; @@ -1941,7 +1969,7 @@ sysctl_net_pppoe_setup(struct sysctllog return; sysctl_createv(clog, 0, , NULL, - CTLFLAG_PERMANENT | CTLFLAG_READONLY, + CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_BOOL, "term_unknown", SYSCTL_DESCR("Terminate unknown sessions"), NULL, 0, _term_unknown, sizeof(pppoe_term_unknown),
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Sat Apr 14 10:38:59 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Pull up following revision(s) (requested by ryo in ticket #752): sys/net/if_vlan.c: revision 1.125 Fix the handling of the state returned from pfil_run_hooks(). pfil_run_hooks() invokes any registered packet filters on the packet being handled. It may return a (non-zero) errno, indicating that a filter has decided that the packet should be discarded, and has freed the mbuf. While a non-error (0) return usually means that the packet should be processed normally, a filter may still free the mbuf if the packet is a fragment, and the filter is holding it for reassembly and future evaluation. Therefore, there must be separate tests for the return value and for a possible discarded packet. (See pfil(9).) OK: christos, martin To generate a diff of this commit: cvs rdiff -u -r1.97.2.11 -r1.97.2.12 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.11 src/sys/net/if_vlan.c:1.97.2.12 --- src/sys/net/if_vlan.c:1.97.2.11 Tue Jan 2 10:20:33 2018 +++ src/sys/net/if_vlan.c Sat Apr 14 10:38:59 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.11 2018/01/02 10:20:33 snj Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.12 2018/04/14 10:38:59 martin Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.11 2018/01/02 10:20:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.12 2018/04/14 10:38:59 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1419,12 +1419,10 @@ vlan_transmit(struct ifnet *ifp, struct bpf_mtap(ifp, m); - if (pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_OUT) != 0) { - if (m != NULL) - m_freem(m); - error = 0; + if ((error = pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_OUT)) != 0) + goto out; + if (m == NULL) goto out; - } /* * If the parent can insert the tag itself, just mark @@ -1610,11 +1608,10 @@ vlan_input(struct ifnet *ifp, struct mbu m_set_rcvif(m, >ifv_if); ifv->ifv_if.if_ipackets++; - if (pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_IN) != 0) { - if (m != NULL) - m_freem(m); + if (pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_IN) != 0) + goto out; + if (m == NULL) goto out; - } m->m_flags &= ~M_PROMISC; if_input(>ifv_if, m);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Sat Apr 14 10:16:19 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if.h route.c route.h rtsock.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #749): sys/net/if.h: revision 1.259 sys/net/route.c: revision 1.209 sys/net/route.h: revision 1.118 sys/net/rtsock.c: revision 1.240 Resolve tangled lock dependencies in route.c This change sweeps remaining lock decisions based on if locked or not by moving utility functions of rtentry updates from rtsock.c and ensuring holding the rt_lock. It also improves the atomicity of a update of a rtentry. To generate a diff of this commit: cvs rdiff -u -r1.239.2.4 -r1.239.2.5 src/sys/net/if.h cvs rdiff -u -r1.194.6.8 -r1.194.6.9 src/sys/net/route.c cvs rdiff -u -r1.112.4.3 -r1.112.4.4 src/sys/net/route.h cvs rdiff -u -r1.213.2.8 -r1.213.2.9 src/sys/net/rtsock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if.h diff -u src/sys/net/if.h:1.239.2.4 src/sys/net/if.h:1.239.2.5 --- src/sys/net/if.h:1.239.2.4 Sun Feb 11 21:17:34 2018 +++ src/sys/net/if.h Sat Apr 14 10:16:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.h,v 1.239.2.4 2018/02/11 21:17:34 snj Exp $ */ +/* $NetBSD: if.h,v 1.239.2.5 2018/04/14 10:16:19 martin Exp $ */ /*- * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. @@ -1145,8 +1145,6 @@ struct ifaddr *ifa_ifwithnet(const struc struct ifaddr *ifa_ifwithnet_psref(const struct sockaddr *, struct psref *); struct ifaddr *ifa_ifwithladdr(const struct sockaddr *); struct ifaddr *ifa_ifwithladdr_psref(const struct sockaddr *, struct psref *); -struct ifaddr *ifa_ifwithroute_psref(int, const struct sockaddr *, - const struct sockaddr *, struct psref *); struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); struct ifaddr *ifaof_ifpforaddr_psref(const struct sockaddr *, struct ifnet *, struct psref *); Index: src/sys/net/route.c diff -u src/sys/net/route.c:1.194.6.8 src/sys/net/route.c:1.194.6.9 --- src/sys/net/route.c:1.194.6.8 Thu Apr 5 14:41:07 2018 +++ src/sys/net/route.c Sat Apr 14 10:16:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.194.6.8 2018/04/05 14:41:07 martin Exp $ */ +/* $NetBSD: route.c,v 1.194.6.9 2018/04/14 10:16:19 martin Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.8 2018/04/05 14:41:07 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.9 2018/04/14 10:16:19 martin Exp $"); #include #ifdef RTFLUSH_DEBUG @@ -130,6 +130,8 @@ __KERNEL_RCSID(0, "$NetBSD: route.c,v 1. #include #include +#define PRESERVED_RTF (RTF_UP | RTF_GATEWAY | RTF_HOST | RTF_DONE | RTF_MASK) + #ifdef RTFLUSH_DEBUG #define rtcache_debug() __predict_false(_rtcache_debug) #else /* RTFLUSH_DEBUG */ @@ -224,13 +226,13 @@ static krwlock_t rt_lock __cacheline_al #define RT_RLOCK() rw_enter(_lock, RW_READER) #define RT_WLOCK() rw_enter(_lock, RW_WRITER) #define RT_UNLOCK() rw_exit(_lock) -#define RT_LOCKED() rw_lock_held(_lock) +#define RT_WLOCKED() rw_write_held(_lock) #define RT_ASSERT_WLOCK() KASSERT(rw_write_held(_lock)) #else #define RT_RLOCK() do {} while (0) #define RT_WLOCK() do {} while (0) #define RT_UNLOCK() do {} while (0) -#define RT_LOCKED() false +#define RT_WLOCKED() true #define RT_ASSERT_WLOCK() do {} while (0) #endif @@ -280,6 +282,11 @@ static void rt_ref(struct rtentry *); static struct rtentry * rtalloc1_locked(const struct sockaddr *, int, bool, bool); +static struct ifaddr *rt_getifa(struct rt_addrinfo *, struct psref *); +static struct ifnet *rt_getifp(struct rt_addrinfo *, struct psref *); +static struct ifaddr *ifa_ifwithroute_psref(int, const struct sockaddr *, +const struct sockaddr *, struct psref *); + static void rtcache_ref(struct rtentry *, struct route *); #ifdef NET_MPSAFE @@ -884,11 +891,13 @@ rtredirect(const struct sockaddr *dst, c error = rt_update_prepare(rt); if (error == 0) { #endif +RT_WLOCK(); error = rt_setgate(rt, gateway); if (error == 0) { rt->rt_flags |= RTF_MODIFIED; flags |= RTF_MODIFIED; } +RT_UNLOCK(); #ifdef NET_MPSAFE rt_update_finish(rt); } else { @@ -952,9 +961,9 @@ rtdeletemsg(struct rtentry *rt) return error; } -struct ifaddr * +static struct ifaddr * ifa_ifwithroute_psref(int flags, const struct sockaddr *dst, - const struct sockaddr *gateway, struct psref *psref) +const struct sockaddr *gateway, struct psref *psref) { struct ifaddr *ifa = NULL; @@ -984,11 +993,7 @@ ifa_ifwithroute_psref(int flags, const s int s; struct rtentry *rt; - /* XXX we cannot call rtalloc1 if holding the rt lock */ - if (RT_LOCKED()) - rt = rtalloc1_locked(gateway, 0, true, true); - else - rt = rtalloc1(gateway, 0); +
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Apr 11 14:15:45 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_l2tp.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #730): sys/net/if_l2tp.c: revision 1.22 sys/net/if_l2tp.c: revision 1.23 Improve comment. Pointed out by maxv@n.o, thanks. Fix previous my mistake and odd unaligned case. Pointed out by maxv@n.o, thanks. It must be rare case to be required this copy routine... To generate a diff of this commit: cvs rdiff -u -r1.11.2.6 -r1.11.2.7 src/sys/net/if_l2tp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_l2tp.c diff -u src/sys/net/if_l2tp.c:1.11.2.6 src/sys/net/if_l2tp.c:1.11.2.7 --- src/sys/net/if_l2tp.c:1.11.2.6 Mon Apr 9 13:40:20 2018 +++ src/sys/net/if_l2tp.c Wed Apr 11 14:15:45 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_l2tp.c,v 1.11.2.6 2018/04/09 13:40:20 bouyer Exp $ */ +/* $NetBSD: if_l2tp.c,v 1.11.2.7 2018/04/11 14:15:45 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.6 2018/04/09 13:40:20 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.7 2018/04/11 14:15:45 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -477,11 +477,16 @@ l2tp_input(struct mbuf *m, struct ifnet return; } + /* + * If the head of the payload is not aligned, align it. + */ addr = mtod(m, vaddr_t); - if ((addr & 0x03) == 0) { + if ((addr & 0x03) != 0x2) { /* copy and align head of payload */ struct mbuf *m_head; int copy_length; + u_int pad = roundup(sizeof(struct ether_header), 4) + - sizeof(struct ether_header); #define L2TP_COPY_LENGTH 60 @@ -504,7 +509,19 @@ l2tp_input(struct mbuf *m, struct ifnet } M_COPY_PKTHDR(m_head, m); - MH_ALIGN(m_head, L2TP_COPY_LENGTH); + /* + * m_head should be: + * L2TP_COPY_LENGTH + * <- + roundup(pad, 4) - pad -> + * +---++-+--+-+ + * | m_hdr | pkthdr | ... | ether header | payload | + * +---++-+--+-+ + * ^ ^ + * m_data 4 byte aligned + */ + MH_ALIGN(m_head, L2TP_COPY_LENGTH + roundup(pad, 4)); + m_head->m_data += pad; + memcpy(mtod(m_head, void *), mtod(m, void *), copy_length); m_head->m_len = copy_length; m->m_data += copy_length;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: bouyer Date: Mon Apr 9 13:40:21 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_l2tp.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #725): sys/net/if_l2tp.c: revision 1.21 Fix l2tp(4) alignment check. Pointed out and reviewed by k-goda@IIJ. The alignment check should be done for the address of m_data instead of the value of m_data. XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.11.2.5 -r1.11.2.6 src/sys/net/if_l2tp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_l2tp.c diff -u src/sys/net/if_l2tp.c:1.11.2.5 src/sys/net/if_l2tp.c:1.11.2.6 --- src/sys/net/if_l2tp.c:1.11.2.5 Thu Mar 8 13:41:40 2018 +++ src/sys/net/if_l2tp.c Mon Apr 9 13:40:20 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_l2tp.c,v 1.11.2.5 2018/03/08 13:41:40 martin Exp $ */ +/* $NetBSD: if_l2tp.c,v 1.11.2.6 2018/04/09 13:40:20 bouyer Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.5 2018/03/08 13:41:40 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.6 2018/04/09 13:40:20 bouyer Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -465,18 +465,20 @@ l2tpintr(struct l2tp_variant *var) void l2tp_input(struct mbuf *m, struct ifnet *ifp) { - u_long val; + vaddr_t addr; KASSERT(ifp != NULL); - if (m->m_pkthdr.len < sizeof(val)) { + /* + * Currently, l2tp(4) supports only ethernet as inner protocol. + */ + if (m->m_pkthdr.len < sizeof(struct ether_header)) { m_freem(m); return; } - m_copydata(m, 0, sizeof(val), ); - - if ((val & 0x03) == 0) { + addr = mtod(m, vaddr_t); + if ((addr & 0x03) == 0) { /* copy and align head of payload */ struct mbuf *m_head; int copy_length;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Apr 5 14:41:07 UTC 2018 Modified Files: src/sys/net [netbsd-8]: route.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #697): sys/net/route.c: revision 1.208 Kill remaining rt->rt_refcnt++ To generate a diff of this commit: cvs rdiff -u -r1.194.6.7 -r1.194.6.8 src/sys/net/route.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/route.c diff -u src/sys/net/route.c:1.194.6.7 src/sys/net/route.c:1.194.6.8 --- src/sys/net/route.c:1.194.6.7 Tue Mar 13 13:27:10 2018 +++ src/sys/net/route.c Thu Apr 5 14:41:07 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.194.6.7 2018/03/13 13:27:10 martin Exp $ */ +/* $NetBSD: route.c,v 1.194.6.8 2018/04/05 14:41:07 martin Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.7 2018/03/13 13:27:10 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.8 2018/04/05 14:41:07 martin Exp $"); #include #ifdef RTFLUSH_DEBUG @@ -2124,7 +2124,7 @@ rt_delete_matched_entries(sa_family_t fa RT_UNLOCK(); return; } - rt->rt_refcnt++; + rt_ref(rt); splx(s); RT_UNLOCK();
CVS commit: [netbsd-8] src/sys/net/npf
Module Name:src Committed By: martin Date: Wed Apr 4 16:40:42 UTC 2018 Modified Files: src/sys/net/npf [netbsd-8]: npf.h Log Message: Pull up following revision(s) (requested by maxv in ticket #693): sys/net/npf/npf.h: revision 1.55 Fix a vulnerability in NPF, that allows whatever incoming IPv6 packet to bypass a certain number of filtering rules. Basically there is an integer overflow in npf_cache_ip: npc_hlen is a 8bit unsigned int, and can wrap to zero if the IPv6 packet being processed has large extensions. As a result of an overflow, (mbuf + npc_hlen) won't point at the real protocol header, but instead at some garbage within the packet. That garbage, is what NPF applies its rules on. If these filtering rules allow the packet to enter, that packet is given to the main IPv6 entry point. This entry point, however, is not subject to an integer overflow, so it will actually parse the correct protocol header. The result is: NPF read a wrong header, allowed the packet to enter, the kernel read the correct header, and delivered the packet depending on this correct header. So the offending packet was supposed to be kicked, but still went through the firewall. Simple example, a packet with: packet + 0 = IP6 Header packet + 40 = IP6 Routing header (ip6r_len = 31) packet + 48 = Crafted UDP header (uh_dport = ) packet + 296 = IP6 Dest header (ip6e_len = 0) packet + 304 = Real UDP header (uh_dport = ) Will bypass a rule of the kind "block port ". Here NPF reads the crafted UDP header, sees , lets the packet in; later the kernel reads the real UDP header, and delivers it on port . Fix this by using uint32_t. While here, it seems to me there is also a memory overflow: still in npf_cache_ip, npc_hlen may be incremented with a value that goes beyond the mbuf. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.54.6.1 src/sys/net/npf/npf.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/npf/npf.h diff -u src/sys/net/npf/npf.h:1.54 src/sys/net/npf/npf.h:1.54.6.1 --- src/sys/net/npf/npf.h:1.54 Sun Jan 29 00:15:54 2017 +++ src/sys/net/npf/npf.h Wed Apr 4 16:40:42 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: npf.h,v 1.54 2017/01/29 00:15:54 christos Exp $ */ +/* $NetBSD: npf.h,v 1.54.6.1 2018/04/04 16:40:42 martin Exp $ */ /*- * Copyright (c) 2009-2014 The NetBSD Foundation, Inc. @@ -159,7 +159,7 @@ typedef struct { uint8_t npc_alen; /* IP header length and L4 protocol. */ - uint8_t npc_hlen; + uint32_t npc_hlen; uint16_t npc_proto; /* IPv4, IPv6. */
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Sat Mar 17 11:26:44 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_tun.c Log Message: Pull up following revision(s) (requested by tih in ticket #638): sys/net/if_tun.c: revision 1.143 Add packet filtering to tun(4) interfaces. Calls to pfil_run_hooks() were missing in if_tun.c. This meant that filtering configuration could be added to e.g. /etc/npf.conf, but would be ignored, because the filter never saw the packets. This change adds the required calls. While here, correct the return value from tun_output(): it's been returning 0 regardless of any error condition present, but will now correctly propagate such information upward. Thanks to maxv for guidance! OK: christos, martin To generate a diff of this commit: cvs rdiff -u -r1.139.2.2 -r1.139.2.3 src/sys/net/if_tun.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_tun.c diff -u src/sys/net/if_tun.c:1.139.2.2 src/sys/net/if_tun.c:1.139.2.3 --- src/sys/net/if_tun.c:1.139.2.2 Tue Jan 2 10:20:33 2018 +++ src/sys/net/if_tun.c Sat Mar 17 11:26:44 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tun.c,v 1.139.2.2 2018/01/02 10:20:33 snj Exp $ */ +/* $NetBSD: if_tun.c,v 1.139.2.3 2018/03/17 11:26:44 martin Exp $ */ /* * Copyright (c) 1988, Julian Onions@@ -19,7 +19,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139.2.2 2018/01/02 10:20:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139.2.3 2018/03/17 11:26:44 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -555,6 +555,11 @@ tun_output(struct ifnet *ifp, struct mbu bpf_mtap_af(ifp, dst->sa_family, m0); + if ((error = pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_OUT)) != 0) + goto out; + if (m0 == NULL) + goto out; + switch(dst->sa_family) { #ifdef INET6 case AF_INET6: @@ -624,10 +629,10 @@ tun_output(struct ifnet *ifp, struct mbu mutex_exit(>tun_lock); out: - if (error && m0) { + if (error && m0) m_freem(m0); - } - return 0; + + return error; } static void @@ -941,6 +946,11 @@ tunwrite(dev_t dev, struct uio *uio, int bpf_mtap_af(ifp, dst.sa_family, top); + if ((error = pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_IN)) != 0) + goto out0; + if (top == NULL) + goto out0; + mutex_enter(>tun_lock); if ((tp->tun_flags & TUN_INITED) == 0) { /* Interface was destroyed */
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Tue Mar 13 15:40:25 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_ethersubr.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #628): sys/net/if_ethersubr.c: revision 1.250 sys/net/if_ethersubr.c: revision 1.251 sys/net/if_ethersubr.c: revision 1.252 sys/net/if_ethersubr.c: revision 1.248 Use kmem_alloc instead of kmem_intr_alloc in ether_addmulti ether_addmulti is now not called in softint thanks to wqinput that pulled input routines of ICMP out of softint. style Fix the net.ether.multicast sysctl. If there is no multicast address don't kmem_alloc(0) (which panics the kernel), and if the number of multicast addresses has decreased don't copyout uninitialized kernel data. Several fixes: - Style and typos - Use kmem_zalloc, in case there is a padding between the fields of the structures - Use ETHER_ADDR_LEN instead of a hard-coded '6' - kmem_alloc(KM_SLEEP) can't fail - Simplify ether_aton_r - Use mutex_obj_free, not to leak memory To generate a diff of this commit: cvs rdiff -u -r1.242.6.4 -r1.242.6.5 src/sys/net/if_ethersubr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ethersubr.c diff -u src/sys/net/if_ethersubr.c:1.242.6.4 src/sys/net/if_ethersubr.c:1.242.6.5 --- src/sys/net/if_ethersubr.c:1.242.6.4 Thu Mar 8 14:37:58 2018 +++ src/sys/net/if_ethersubr.c Tue Mar 13 15:40:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ethersubr.c,v 1.242.6.4 2018/03/08 14:37:58 martin Exp $ */ +/* $NetBSD: if_ethersubr.c,v 1.242.6.5 2018/03/13 15:40:25 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.4 2018/03/08 14:37:58 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.5 2018/03/13 15:40:25 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -192,7 +192,7 @@ ether_output(struct ifnet * const ifp0, { uint16_t etype = 0; int error = 0, hdrcmplt = 0; - uint8_t esrc[6], edst[6]; + uint8_t esrc[6], edst[6]; struct mbuf *m = m0; struct mbuf *mcopy = NULL; struct ether_header *eh; @@ -301,7 +301,7 @@ ether_output(struct ifnet * const ifp0, break; #endif #ifdef NETATALK -case AF_APPLETALK: { + case AF_APPLETALK: { struct ifaddr *ifa; int s; @@ -347,7 +347,7 @@ ether_output(struct ifnet * const ifp0, pserialize_read_exit(s); KERNEL_UNLOCK_ONE(NULL); break; - } + } #endif /* NETATALK */ case pseudo_AF_HDRCMPLT: hdrcmplt = 1; @@ -357,7 +357,7 @@ ether_output(struct ifnet * const ifp0, /* FALLTHROUGH */ case AF_UNSPEC: - memcpy(edst, + memcpy(edst, ((const struct ether_header *)dst->sa_data)->ether_dhost, sizeof(edst)); /* AF_UNSPEC doesn't swap the byte order of the ether_type. */ @@ -401,7 +401,7 @@ ether_output(struct ifnet * const ifp0, eh = mtod(m, struct ether_header *); /* Note: etype is already in network byte order. */ (void)memcpy(>ether_type, , sizeof(eh->ether_type)); - memcpy(eh->ether_dhost, edst, sizeof(edst)); + memcpy(eh->ether_dhost, edst, sizeof(edst)); if (hdrcmplt) memcpy(eh->ether_shost, esrc, sizeof(eh->ether_shost)); else @@ -538,7 +538,7 @@ altq_etherclassify(struct ifaltq *ifq, s return; - bad: +bad: m->m_pkthdr.pattr_class = NULL; m->m_pkthdr.pattr_hdr = NULL; m->m_pkthdr.pattr_af = AF_UNSPEC; @@ -579,7 +579,7 @@ ether_input(struct ifnet *ifp, struct mb etype = ntohs(eh->ether_type); ehlen = sizeof(*eh); - if(__predict_false(earlypkts < 100 || !rnd_initial_entropy)) { + if (__predict_false(earlypkts < 100 || !rnd_initial_entropy)) { rnd_add_data(NULL, eh, ehlen, 0); earlypkts++; } @@ -640,6 +640,7 @@ ether_input(struct ifnet *ifp, struct mb return; } #endif /* NCARP > 0 */ + if ((m->m_flags & (M_BCAST | M_MCAST | M_PROMISC)) == 0 && (ifp->if_flags & IFF_PROMISC) != 0 && memcmp(CLLADDR(ifp->if_sadl), eh->ether_dhost, @@ -695,7 +696,7 @@ ether_input(struct ifnet *ifp, struct mb /* * If there is a tag of 0, then the VLAN header was probably * just being used to store the priority. Extract the ether - * type, and if IP or IPV6, let them deal with it. + * type, and if IP or IPV6, let them deal with it. */ if (m->m_len <= sizeof(*evl) && EVL_VLANOFTAG(evl->evl_tag) == 0) { @@ -804,7 +805,7 @@ ether_input(struct ifnet *ifp, struct mb m_freem(m); return; } -#ifdef GATEWAY +#ifdef GATEWAY if (ip6flow_fastforward()) return; #endif @@ -878,10 +879,10 @@ ether_input(struct ifnet *ifp, struct mb m_freem(m); return; } -#else /* ISO || LLC || NETATALK*/ +#else /* LLC || NETATALK */ m_freem(m); return; -#endif /* ISO || LLC || NETATALK*/ +#endif /* LLC || NETATALK */ } if (__predict_true(pktq)) { @@ -997,9
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Mar 8 14:37:58 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_ethersubr.c Log Message: Pull up following revision(s) (requested by msaitoh in ticket #618): sys/net/if_ethersubr.c: revision 1.245 sys/net/if_ethersubr.c: revision 1.247 Use macro(ETHER_LOCK() and ETHER_UNLOCK()). No functional change. - Modify ether_ioctl() for readability. No functional change. - KNF To generate a diff of this commit: cvs rdiff -u -r1.242.6.3 -r1.242.6.4 src/sys/net/if_ethersubr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ethersubr.c diff -u src/sys/net/if_ethersubr.c:1.242.6.3 src/sys/net/if_ethersubr.c:1.242.6.4 --- src/sys/net/if_ethersubr.c:1.242.6.3 Tue Jan 9 19:23:04 2018 +++ src/sys/net/if_ethersubr.c Thu Mar 8 14:37:58 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ethersubr.c,v 1.242.6.3 2018/01/09 19:23:04 snj Exp $ */ +/* $NetBSD: if_ethersubr.c,v 1.242.6.4 2018/03/08 14:37:58 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.3 2018/01/09 19:23:04 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.4 2018/03/08 14:37:58 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -226,13 +226,13 @@ ether_output(struct ifnet * const ifp0, ifp = ifp->if_carpdev; /* ac = (struct arpcom *)ifp; */ - if ((ifp0->if_flags & (IFF_UP|IFF_RUNNING)) != - (IFF_UP|IFF_RUNNING)) + if ((ifp0->if_flags & (IFF_UP | IFF_RUNNING)) != + (IFF_UP | IFF_RUNNING)) senderr(ENETDOWN); } #endif /* NCARP > 0 */ - if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) + if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) senderr(ENETDOWN); switch (dst->sa_family) { @@ -640,7 +640,7 @@ ether_input(struct ifnet *ifp, struct mb return; } #endif /* NCARP > 0 */ - if ((m->m_flags & (M_BCAST|M_MCAST|M_PROMISC)) == 0 && + if ((m->m_flags & (M_BCAST | M_MCAST | M_PROMISC)) == 0 && (ifp->if_flags & IFF_PROMISC) != 0 && memcmp(CLLADDR(ifp->if_sadl), eh->ether_dhost, ETHER_ADDR_LEN) != 0) { @@ -1005,13 +1005,13 @@ ether_ifdetach(struct ifnet *ifp) vlan_ifdetach(ifp); #endif - mutex_enter(ec->ec_lock); + ETHER_LOCK(ec); while ((enm = LIST_FIRST(>ec_multiaddrs)) != NULL) { LIST_REMOVE(enm, enm_list); kmem_intr_free(enm, sizeof(*enm)); ec->ec_multicnt--; } - mutex_exit(ec->ec_lock); + ETHER_UNLOCK(ec); mutex_destroy(ec->ec_lock); @@ -1231,7 +1231,7 @@ ether_addmulti(const struct sockaddr *sa if (enm == NULL) return ENOBUFS; - mutex_enter(ec->ec_lock); + ETHER_LOCK(ec); error = ether_multiaddr(sa, addrlo, addrhi); if (error != 0) goto out; @@ -1270,7 +1270,7 @@ ether_addmulti(const struct sockaddr *sa error = ENETRESET; enm = NULL; out: - mutex_exit(ec->ec_lock); + ETHER_UNLOCK(ec); if (enm != NULL) kmem_intr_free(enm, sizeof(*enm)); return error; @@ -1287,7 +1287,7 @@ ether_delmulti(const struct sockaddr *sa u_char addrhi[ETHER_ADDR_LEN]; int error; - mutex_enter(ec->ec_lock); + ETHER_LOCK(ec); error = ether_multiaddr(sa, addrlo, addrhi); if (error != 0) goto error; @@ -1312,7 +1312,7 @@ ether_delmulti(const struct sockaddr *sa */ LIST_REMOVE(enm, enm_list); ec->ec_multicnt--; - mutex_exit(ec->ec_lock); + ETHER_UNLOCK(ec); kmem_intr_free(enm, sizeof(*enm)); /* @@ -1321,7 +1321,7 @@ ether_delmulti(const struct sockaddr *sa */ return ENETRESET; error: - mutex_exit(ec->ec_lock); + ETHER_UNLOCK(ec); return error; } @@ -1351,8 +1351,8 @@ ether_ioctl(struct ifnet *ifp, u_long cm { struct ifaddr *ifa = (struct ifaddr *)data; if (ifa->ifa_addr->sa_family != AF_LINK - && (ifp->if_flags & (IFF_UP|IFF_RUNNING)) != - (IFF_UP|IFF_RUNNING)) { + && (ifp->if_flags & (IFF_UP | IFF_RUNNING)) != + (IFF_UP | IFF_RUNNING)) { ifp->if_flags |= IFF_UP; if ((error = (*ifp->if_init)(ifp)) != 0) return error; @@ -1387,7 +1387,7 @@ ether_ioctl(struct ifnet *ifp, u_long cm case SIOCSIFFLAGS: if ((error = ifioctl_common(ifp, cmd, data)) != 0) return error; - switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { + switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) { case IFF_RUNNING: /* * If interface is marked down and it is running, @@ -1401,18 +1401,21 @@ ether_ioctl(struct ifnet *ifp, u_long cm * start it. */ return (*ifp->if_init)(ifp); - case IFF_UP|IFF_RUNNING: + case IFF_UP | IFF_RUNNING: error = 0; - if (ec->ec_ifflags_cb == NULL || - (error = (*ec->ec_ifflags_cb)(ec)) == ENETRESET) { -/* - * Reset the interface to pick up - * changes in any other flags that - * affect the hardware state. - */ -return (*ifp->if_init)(ifp); - } else -return
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Mar 8 13:22:26 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_gif.c if_pppoe.c if_spppsubr.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #613): sys/net/if_pppoe.c: revision 1.130,1.134 sys/net/if_spppsubr.c: revision 1.172,1.175,1.179 sys/net/if_gif.c: revision 1.138,1.139 Mark callouts of pppoe(4) CALLOUT_MPSAFE. Suggested by ozaki-r@n.o. fix non-diagnostic compilation Fix spl leak. ifconfig gif0 create ifconfig gif0 destroy WARNING: SPL NOT LOWERED ON ... Fix breaking character limit. Pointed out by ozaki-r@n.o, thanks. Use m_freem instead of m_free. Otherwise we're leaking the next mbufs in the chain. To generate a diff of this commit: cvs rdiff -u -r1.126.2.8 -r1.126.2.9 src/sys/net/if_gif.c cvs rdiff -u -r1.125.6.5 -r1.125.6.6 src/sys/net/if_pppoe.c cvs rdiff -u -r1.169.6.4 -r1.169.6.5 src/sys/net/if_spppsubr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_gif.c diff -u src/sys/net/if_gif.c:1.126.2.8 src/sys/net/if_gif.c:1.126.2.9 --- src/sys/net/if_gif.c:1.126.2.8 Sun Feb 11 21:17:34 2018 +++ src/sys/net/if_gif.c Thu Mar 8 13:22:26 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_gif.c,v 1.126.2.8 2018/02/11 21:17:34 snj Exp $ */ +/* $NetBSD: if_gif.c,v 1.126.2.9 2018/03/08 13:22:26 martin Exp $ */ /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.8 2018/02/11 21:17:34 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.9 2018/03/08 13:22:26 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -458,7 +458,7 @@ gif_output(struct ifnet *ifp, struct mbu IFQ_CLASSIFY(>if_snd, m, dst->sa_family); if ((error = gif_check_nesting(ifp, m)) != 0) { - m_free(m); + m_freem(m); goto end; } @@ -1126,6 +1126,9 @@ gif_delete_tunnel(struct ifnet *ifp) mutex_exit(>gif_lock); encap_lock_exit(); kmem_free(nvar, sizeof(*nvar)); +#ifndef GIF_MPSAFE + splx(s); +#endif return; } Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.125.6.5 src/sys/net/if_pppoe.c:1.125.6.6 --- src/sys/net/if_pppoe.c:1.125.6.5 Tue Jan 2 10:20:33 2018 +++ src/sys/net/if_pppoe.c Thu Mar 8 13:22:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.125.6.5 2018/01/02 10:20:33 snj Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.125.6.6 2018/03/08 13:22:25 martin Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.5 2018/01/02 10:20:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.6 2018/03/08 13:22:25 martin Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -315,7 +315,7 @@ pppoe_clone_create(struct if_clone *ifc, /* changed to real address later */ memcpy(>sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest)); - callout_init(>sc_timeout, 0); + callout_init(>sc_timeout, CALLOUT_MPSAFE); sc->sc_sppp.pp_if.if_start = pppoe_start; #ifdef PPPOE_MPSAFE @@ -1795,7 +1795,7 @@ pppoe_transmit(struct ifnet *ifp, struct PPPOE_LOCK(sc, RW_READER); if (sc->sc_state < PPPOE_STATE_SESSION) { PPPOE_UNLOCK(sc); - m_free(m); + m_freem(m); return ENOBUFS; } @@ -1887,13 +1887,13 @@ static void pppoe_enqueue(struct ifqueue *inq, struct mbuf *m) { if (m->m_flags & M_PROMISC) { - m_free(m); + m_freem(m); return; } #ifndef PPPOE_SERVER if (m->m_flags & (M_MCAST | M_BCAST)) { - m_free(m); + m_freem(m); return; } #endif Index: src/sys/net/if_spppsubr.c diff -u src/sys/net/if_spppsubr.c:1.169.6.4 src/sys/net/if_spppsubr.c:1.169.6.5 --- src/sys/net/if_spppsubr.c:1.169.6.4 Tue Jan 16 13:01:10 2018 +++ src/sys/net/if_spppsubr.c Thu Mar 8 13:22:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_spppsubr.c,v 1.169.6.4 2018/01/16 13:01:10 martin Exp $ */ +/* $NetBSD: if_spppsubr.c,v 1.169.6.5 2018/03/08 13:22:25 martin Exp $ */ /* * Synchronous PPP/Cisco link level subroutines. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.169.6.4 2018/01/16 13:01:10 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.169.6.5 2018/03/08 13:22:25 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -999,7 +999,7 @@ sppp_attach(struct ifnet *ifp) /* Initialize keepalive handler. */ if (! spppq) { - callout_init(_ch, 0); + callout_init(_ch, CALLOUT_MPSAFE); callout_reset(_ch, hz * LCP_KEEPALIVE_INTERVAL, sppp_keepalive, NULL); } @@ -2205,7 +2205,7 @@ sppp_lcp_init(struct sppp *sp) sp->lcp.max_terminate = 2; sp->lcp.max_configure = 10; sp->lcp.max_failure = 10; - callout_init(>ch[IDX_LCP], 0); + callout_init(>ch[IDX_LCP], CALLOUT_MPSAFE); } static void @@ -2967,9 +2967,9 @@ sppp_ipcp_init(struct sppp *sp) sp->fail_counter[IDX_IPCP] =
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Feb 28 18:54:43 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if.c rtsock.c Log Message: Pull up following revision(s) (requested by mrg in ticket #595): sys/net/if.c: revision 1.398 sys/net/rtsock.c: revision 1.231 remove useless cast, initialize family. Avoid using a zero family mask. To generate a diff of this commit: cvs rdiff -u -r1.394.2.8 -r1.394.2.9 src/sys/net/if.c cvs rdiff -u -r1.213.2.6 -r1.213.2.7 src/sys/net/rtsock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.394.2.8 src/sys/net/if.c:1.394.2.9 --- src/sys/net/if.c:1.394.2.8 Sun Feb 11 21:17:34 2018 +++ src/sys/net/if.c Wed Feb 28 18:54:43 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.394.2.8 2018/02/11 21:17:34 snj Exp $ */ +/* $NetBSD: if.c,v 1.394.2.9 2018/02/28 18:54:43 martin Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.8 2018/02/11 21:17:34 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.9 2018/02/28 18:54:43 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -450,13 +450,14 @@ if_dl_create(const struct ifnet *ifp, co addrlen = ifp->if_addrlen; socksize = roundup(sockaddr_dl_measure(namelen, addrlen), sizeof(long)); ifasize = sizeof(*ifa) + 2 * socksize; - ifa = (struct ifaddr *)malloc(ifasize, M_IFADDR, M_WAITOK|M_ZERO); + ifa = malloc(ifasize, M_IFADDR, M_WAITOK|M_ZERO); sdl = (struct sockaddr_dl *)(ifa + 1); mask = (struct sockaddr_dl *)(socksize + (char *)sdl); sockaddr_dl_init(sdl, socksize, ifp->if_index, ifp->if_type, ifp->if_xname, namelen, NULL, addrlen); + mask->sdl_family = AF_LINK; mask->sdl_len = sockaddr_dl_measure(namelen, 0); memset(>sdl_data[0], 0xff, namelen); ifa->ifa_rtrequest = link_rtrequest; Index: src/sys/net/rtsock.c diff -u src/sys/net/rtsock.c:1.213.2.6 src/sys/net/rtsock.c:1.213.2.7 --- src/sys/net/rtsock.c:1.213.2.6 Sat Feb 3 22:07:26 2018 +++ src/sys/net/rtsock.c Wed Feb 28 18:54:43 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: rtsock.c,v 1.213.2.6 2018/02/03 22:07:26 snj Exp $ */ +/* $NetBSD: rtsock.c,v 1.213.2.7 2018/02/28 18:54:43 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.6 2018/02/03 22:07:26 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.7 2018/02/28 18:54:43 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -836,8 +836,13 @@ COMPATNAME(route_output)(struct mbuf *m, * (padded with 0's). We keep the original length of the sockaddr. */ if (info.rti_info[RTAX_NETMASK]) { + /* + * Use the family of RTAX_DST, because RTAX_NETMASK + * can have a zero family if it comes from the radix + * tree via rt_mask(). + */ socklen_t sa_len = sockaddr_getsize_by_family( - info.rti_info[RTAX_NETMASK]->sa_family); + info.rti_info[RTAX_DST]->sa_family); socklen_t masklen = sockaddr_getlen( info.rti_info[RTAX_NETMASK]); if (sa_len != 0 && sa_len > masklen) {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Feb 5 14:18:00 UTC 2018 Modified Files: src/sys/net [netbsd-8]: bpf.c bpfdesc.h Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #526): sys/net/bpfdesc.h: revision 1.45 sys/net/bpf.c: revision 1.223 Abandon unnecessary softint The softint was introduced to defer fownsignal that was called in bpf_wakeup to softint at v1.139, but now bpf_wakeup always runs in softint so we don't need the softint anymore. To generate a diff of this commit: cvs rdiff -u -r1.216.6.4 -r1.216.6.5 src/sys/net/bpf.c cvs rdiff -u -r1.44 -r1.44.6.1 src/sys/net/bpfdesc.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.216.6.4 src/sys/net/bpf.c:1.216.6.5 --- src/sys/net/bpf.c:1.216.6.4 Tue Jan 2 10:20:33 2018 +++ src/sys/net/bpf.c Mon Feb 5 14:18:00 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.216.6.4 2018/01/02 10:20:33 snj Exp $ */ +/* $NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.4 2018/01/02 10:20:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $"); #if defined(_KERNEL_OPT) #include "opt_bpf.h" @@ -268,7 +268,6 @@ static int bpf_poll(struct file *, int); static int bpf_stat(struct file *, struct stat *); static int bpf_close(struct file *); static int bpf_kqfilter(struct file *, struct knote *); -static void bpf_softintr(void *); static const struct fileops bpf_fileops = { .fo_read = bpf_read, @@ -562,8 +561,6 @@ bpfopen(dev_t dev, int flag, int mode, s d->bd_atime = d->bd_mtime = d->bd_btime; callout_init(>bd_callout, CALLOUT_MPSAFE); selinit(>bd_sel); - d->bd_sih = softint_establish(SOFTINT_CLOCK|SOFTINT_MPSAFE, - bpf_softintr, d); d->bd_jitcode = NULL; d->bd_filter = NULL; BPF_DLIST_ENTRY_INIT(d); @@ -620,7 +617,6 @@ bpf_close(struct file *fp) bpf_freed(d); callout_destroy(>bd_callout); seldestroy(>bd_sel); - softint_disestablish(d->bd_sih); mutex_obj_free(d->bd_mtx); mutex_obj_free(d->bd_buf_mtx); cv_destroy(>bd_cv); @@ -755,20 +751,8 @@ bpf_wakeup(struct bpf_d *d) mutex_exit(d->bd_buf_mtx); if (d->bd_async) - softint_schedule(d->bd_sih); - selnotify(>bd_sel, 0, 0); -} - -static void -bpf_softintr(void *cookie) -{ - struct bpf_d *d; - - d = cookie; - mutex_enter(d->bd_mtx); - if (d->bd_async) fownsignal(d->bd_pgid, SIGIO, 0, 0, NULL); - mutex_exit(d->bd_mtx); + selnotify(>bd_sel, 0, 0); } static void Index: src/sys/net/bpfdesc.h diff -u src/sys/net/bpfdesc.h:1.44 src/sys/net/bpfdesc.h:1.44.6.1 --- src/sys/net/bpfdesc.h:1.44 Thu Feb 9 09:30:26 2017 +++ src/sys/net/bpfdesc.h Mon Feb 5 14:18:00 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: bpfdesc.h,v 1.44 2017/02/09 09:30:26 ozaki-r Exp $ */ +/* $NetBSD: bpfdesc.h,v 1.44.6.1 2018/02/05 14:18:00 martin Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -113,6 +113,7 @@ struct bpf_d { pid_t bd_pid; /* corresponding PID */ /* DEPRECATED. Keep it to avoid breaking kvm(3) users */ LIST_ENTRY(bpf_d) _bd_list; /* list of all BPF's */ + /* DEPRECATED. Keep it to avoid breaking kvm(3) users */ void *bd_sih; /* soft interrupt handle */ struct timespec bd_atime; /* access time */ struct timespec bd_mtime; /* modification time */
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Sat Jan 13 22:10:55 UTC 2018 Modified Files: src/sys/net [netbsd-8]: route.c route.h Log Message: Pull up following revision(s) (requested by christos in ticket #496): sys/net/route.c: revision 1.202-1.203 sys/net/route.h: revision 1.117 Use a queue of deferred entries to delete routes instead of a fixed stack of 10. Otherwise we can overflow in route deletions from the rexmit timer. -- Don't stomp past the end of the array! need __arraycount not sizeof() Found by chuq, while debugging the sdf.org crashes Restructure a bit for readability. To generate a diff of this commit: cvs rdiff -u -r1.194.6.3 -r1.194.6.4 src/sys/net/route.c cvs rdiff -u -r1.112.4.2 -r1.112.4.3 src/sys/net/route.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/route.c diff -u src/sys/net/route.c:1.194.6.3 src/sys/net/route.c:1.194.6.4 --- src/sys/net/route.c:1.194.6.3 Tue Oct 24 08:55:55 2017 +++ src/sys/net/route.c Sat Jan 13 22:10:55 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.194.6.3 2017/10/24 08:55:55 snj Exp $ */ +/* $NetBSD: route.c,v 1.194.6.4 2018/01/13 22:10:55 snj Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.3 2017/10/24 08:55:55 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.4 2018/01/13 22:10:55 snj Exp $"); #include #ifdef RTFLUSH_DEBUG @@ -255,7 +255,7 @@ static struct { struct workqueue *wq; struct work wk; kmutex_t lock; - struct rtentry *queue[10]; + SLIST_HEAD(, rtentry) queue; } rt_free_global __cacheline_aligned; /* psref for rtentry */ @@ -458,6 +458,8 @@ rt_init(void) #endif mutex_init(_free_global.lock, MUTEX_DEFAULT, IPL_SOFTNET); + SLIST_INIT(_free_global.queue); + rt_psref_class = psref_class_create("rtentry", IPL_SOFTNET); error = workqueue_create(_free_global.wq, "rt_free", @@ -686,23 +688,20 @@ _rt_free(struct rtentry *rt) static void rt_free_work(struct work *wk, void *arg) { - int i; - struct rtentry *rt; -restart: - mutex_enter(_free_global.lock); - for (i = 0; i < sizeof(rt_free_global.queue); i++) { - if (rt_free_global.queue[i] == NULL) - continue; - rt = rt_free_global.queue[i]; - rt_free_global.queue[i] = NULL; - mutex_exit(_free_global.lock); + for (;;) { + struct rtentry *rt; + mutex_enter(_free_global.lock); + if ((rt = SLIST_FIRST(_free_global.queue)) == NULL) { + mutex_exit(_free_global.lock); + return; + } + SLIST_REMOVE_HEAD(_free_global.queue, rt_free); + mutex_exit(_free_global.lock); atomic_dec_uint(>rt_refcnt); _rt_free(rt); - goto restart; } - mutex_exit(_free_global.lock); } void @@ -710,23 +709,17 @@ rt_free(struct rtentry *rt) { KASSERT(rt->rt_refcnt > 0); - if (!rt_wait_ok()) { - int i; - mutex_enter(_free_global.lock); - for (i = 0; i < sizeof(rt_free_global.queue); i++) { - if (rt_free_global.queue[i] == NULL) { -rt_free_global.queue[i] = rt; -break; - } - } - KASSERT(i < sizeof(rt_free_global.queue)); - rt_ref(rt); - mutex_exit(_free_global.lock); - workqueue_enqueue(rt_free_global.wq, _free_global.wk, NULL); - } else { + if (rt_wait_ok()) { atomic_dec_uint(>rt_refcnt); _rt_free(rt); + return; } + + mutex_enter(_free_global.lock); + rt_ref(rt); + SLIST_INSERT_HEAD(_free_global.queue, rt, rt_free); + mutex_exit(_free_global.lock); + workqueue_enqueue(rt_free_global.wq, _free_global.wk, NULL); } #ifdef NET_MPSAFE Index: src/sys/net/route.h diff -u src/sys/net/route.h:1.112.4.2 src/sys/net/route.h:1.112.4.3 --- src/sys/net/route.h:1.112.4.2 Tue Oct 24 08:55:55 2017 +++ src/sys/net/route.h Sat Jan 13 22:10:55 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: route.h,v 1.112.4.2 2017/10/24 08:55:55 snj Exp $ */ +/* $NetBSD: route.h,v 1.112.4.3 2018/01/13 22:10:55 snj Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -124,7 +124,8 @@ struct rtentry { struct sockaddr *rt_tag; /* route tagging info */ #ifdef _KERNEL kcondvar_t rt_cv; - struct psref_target rt_psref; + struct psref_target rt_psref; + SLIST_ENTRY(rtentry) rt_free; /* queue of deferred frees */ #endif };
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Sat Jan 13 05:43:44 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #487): sys/net/if.c: revision 1.417 Suppress the assertion of IFNET_LOCK in if_mcast_op if MROUTING MROUTING doesn't deal with IFNET_LOCK yet. Reported by kardel@ To generate a diff of this commit: cvs rdiff -u -r1.394.2.5 -r1.394.2.6 src/sys/net/if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.394.2.5 src/sys/net/if.c:1.394.2.6 --- src/sys/net/if.c:1.394.2.5 Sat Jan 13 05:41:38 2018 +++ src/sys/net/if.c Sat Jan 13 05:43:44 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.394.2.5 2018/01/13 05:41:38 snj Exp $ */ +/* $NetBSD: if.c,v 1.394.2.6 2018/01/13 05:43:44 snj Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,16 +90,16 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.5 2018/01/13 05:41:38 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.6 2018/01/13 05:43:44 snj Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" #include "opt_ipsec.h" - #include "opt_atalk.h" #include "opt_natm.h" #include "opt_wlan.h" #include "opt_net_mpsafe.h" +#include "opt_mrouting.h" #endif #include @@ -3561,8 +3561,8 @@ if_mcast_op(ifnet_t *ifp, const unsigned int rc; struct ifreq ifr; - /* CARP still doesn't deal with the lock yet */ -#if !defined(NCARP) || (NCARP == 0) + /* CARP and MROUTING still don't deal with the lock yet */ +#if (!defined(NCARP) || (NCARP == 0)) && !defined(MROUTING) KASSERT(IFNET_LOCKED(ifp)); #endif if (ifp->if_mcastop != NULL)
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Sat Jan 13 05:41:39 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #486): sys/net/if.c: revision 1.418 Check MP-safety in ifa_insert and ifa_remove only for IFEF_MPSAFE drivers Eventually the assertions should pass for all drivers, however, at this point it's too eager. Fix PR kern/52895 To generate a diff of this commit: cvs rdiff -u -r1.394.2.4 -r1.394.2.5 src/sys/net/if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.394.2.4 src/sys/net/if.c:1.394.2.5 --- src/sys/net/if.c:1.394.2.4 Tue Jan 2 10:20:33 2018 +++ src/sys/net/if.c Sat Jan 13 05:41:38 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.394.2.4 2018/01/02 10:20:33 snj Exp $ */ +/* $NetBSD: if.c,v 1.394.2.5 2018/01/13 05:41:38 snj Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.4 2018/01/02 10:20:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.5 2018/01/13 05:41:38 snj Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -1792,12 +1792,13 @@ ifa_insert(struct ifnet *ifp, struct ifa ifa->ifa_ifp = ifp; /* + * Check MP-safety for IFEF_MPSAFE drivers. * Check !IFF_RUNNING for initialization routines that normally don't * take IFNET_LOCK but it's safe because there is no competitor. * XXX there are false positive cases because IFF_RUNNING can be off on * if_stop. */ - KASSERT(!ISSET(ifp->if_flags, IFF_RUNNING) || + KASSERT(!if_is_mpsafe(ifp) || !ISSET(ifp->if_flags, IFF_RUNNING) || IFNET_LOCKED(ifp)); TAILQ_INSERT_TAIL(>if_addrlist, ifa, ifa_list); @@ -1813,10 +1814,11 @@ ifa_remove(struct ifnet *ifp, struct ifa KASSERT(ifa->ifa_ifp == ifp); /* + * Check MP-safety for IFEF_MPSAFE drivers. * if_is_deactivated indicates ifa_remove is called form if_detach * where is safe even if IFNET_LOCK isn't held. */ - KASSERT(if_is_deactivated(ifp) || IFNET_LOCKED(ifp)); + KASSERT(!if_is_mpsafe(ifp) || if_is_deactivated(ifp) || IFNET_LOCKED(ifp)); TAILQ_REMOVE(>if_addrlist, ifa, ifa_list); IFADDR_WRITER_REMOVE(ifa);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Tue Jan 9 19:23:04 UTC 2018 Modified Files: src/sys/net [netbsd-8]: if_ethersubr.c Log Message: Pull up following revision(s) (requested by maxv in ticket #480): sys/net/if_ethersubr.c: revision 1.249 Make sure we have an llc structure in the packet, and don't read past the end of the mbuf if we don't. I'm wondering whether we should not pull up instead, but whatever. To generate a diff of this commit: cvs rdiff -u -r1.242.6.2 -r1.242.6.3 src/sys/net/if_ethersubr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ethersubr.c diff -u src/sys/net/if_ethersubr.c:1.242.6.2 src/sys/net/if_ethersubr.c:1.242.6.3 --- src/sys/net/if_ethersubr.c:1.242.6.2 Tue Jan 2 10:20:33 2018 +++ src/sys/net/if_ethersubr.c Tue Jan 9 19:23:04 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ethersubr.c,v 1.242.6.2 2018/01/02 10:20:33 snj Exp $ */ +/* $NetBSD: if_ethersubr.c,v 1.242.6.3 2018/01/09 19:23:04 snj Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.2 2018/01/02 10:20:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.3 2018/01/09 19:23:04 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -833,6 +833,9 @@ ether_input(struct ifnet *ifp, struct mb } } else { #if defined (LLC) || defined (NETATALK) + if (m->m_len < ehlen + sizeof(struct llc)) { + goto dropanyway; + } l = (struct llc *)(eh+1); switch (l->llc_dsap) { #ifdef NETATALK @@ -869,8 +872,8 @@ ether_input(struct ifnet *ifp, struct mb goto dropanyway; } break; - dropanyway: #endif + dropanyway: default: m_freem(m); return;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Tue Jan 2 10:30:10 UTC 2018 Modified Files: src/sys/net [netbsd-8]: rtsock.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #457): sys/net/rtsock.c: revision 1.233-1.234, 1.236 Protect ifp returned from route_output_get_ifa surely An ifp returned from route_output_get_ifa was supposed to be protected by a returned ifa; if the ifa belongs to ifp, holding the ifa prevents the ifp from being freed. However route_output_get_ifa can return an ifp to which a returned ifa doesn't belong. So we need to take a reference to a returning ifp separately. -- Fix a bug that tries to psref_acquire ifa with a psref used before This fixes ATF tests that started to fail by a recent change to psref. -- Fix compile error (may be used uninitialized) Hmm, __noinline had hidden this error. To generate a diff of this commit: cvs rdiff -u -r1.213.2.4 -r1.213.2.5 src/sys/net/rtsock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/rtsock.c diff -u src/sys/net/rtsock.c:1.213.2.4 src/sys/net/rtsock.c:1.213.2.5 --- src/sys/net/rtsock.c:1.213.2.4 Tue Jan 2 10:20:33 2018 +++ src/sys/net/rtsock.c Tue Jan 2 10:30:10 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: rtsock.c,v 1.213.2.4 2018/01/02 10:20:33 snj Exp $ */ +/* $NetBSD: rtsock.c,v 1.213.2.5 2018/01/02 10:30:10 snj Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.4 2018/01/02 10:20:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.5 2018/01/02 10:30:10 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -608,7 +608,7 @@ route_output_report(struct rtentry *rt, static struct ifaddr * route_output_get_ifa(const struct rt_addrinfo info, const struct rtentry *rt, -struct ifnet **ifp, struct psref *psref) +struct ifnet **ifp, struct psref *psref_ifp, struct psref *psref) { struct ifaddr *ifa = NULL; @@ -618,9 +618,11 @@ route_output_get_ifa(const struct rt_add if (ifa == NULL) goto next; *ifp = ifa->ifa_ifp; + if_acquire(*ifp, psref_ifp); if (info.rti_info[RTAX_IFA] == NULL && info.rti_info[RTAX_GATEWAY] == NULL) goto next; + ifa_release(ifa, psref); if (info.rti_info[RTAX_IFA] == NULL) { /* route change -ifp */ ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_GATEWAY], @@ -648,8 +650,14 @@ next: info.rti_info[RTAX_GATEWAY], psref); } out: - if (ifa != NULL && *ifp == NULL) + if (ifa != NULL && *ifp == NULL) { *ifp = ifa->ifa_ifp; + if_acquire(*ifp, psref_ifp); + } + if (ifa == NULL && *ifp != NULL) { + if_put(*ifp, psref_ifp); + *ifp = NULL; + } return ifa; } @@ -658,9 +666,9 @@ route_output_change(struct rtentry *rt, struct rt_xmsghdr *rtm) { int error = 0; - struct ifnet *ifp = NULL, *new_ifp; + struct ifnet *ifp = NULL, *new_ifp = NULL; struct ifaddr *ifa = NULL, *new_ifa; - struct psref psref_ifa, psref_new_ifa, psref_ifp; + struct psref psref_ifa, psref_new_ifa, psref_ifp, psref_new_ifp; bool newgw, ifp_changed = false; /* @@ -674,6 +682,7 @@ route_output_change(struct rtentry *rt, if (newgw || info->rti_info[RTAX_IFP] != NULL || info->rti_info[RTAX_IFA] != NULL) { ifp = rt_getifp(info, _ifp); + /* info refers ifp so we need to keep a reference */ ifa = rt_getifa(info, _ifa); if (ifa == NULL) { error = ENETUNREACH; @@ -698,7 +707,8 @@ route_output_change(struct rtentry *rt, * flags may also be different; ifp may be specified * by ll sockaddr when protocol address is ambiguous */ - new_ifa = route_output_get_ifa(*info, rt, _ifp, _new_ifa); + new_ifa = route_output_get_ifa(*info, rt, _ifp, _new_ifp, + _new_ifa); if (new_ifa != NULL) { ifa_release(ifa, _ifa); ifa = new_ifa; @@ -736,6 +746,7 @@ route_output_change(struct rtentry *rt, (void)ifp_changed; /* XXX gcc */ #endif out: + if_put(new_ifp, _new_ifp); if_put(ifp, _ifp); return error;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Thu Dec 21 21:51:37 UTC 2017 Modified Files: src/sys/net [netbsd-8]: bpf.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #454): sys/net/bpf.c: revision 1.222 Make softint and callout MP-safe To generate a diff of this commit: cvs rdiff -u -r1.216.6.2 -r1.216.6.3 src/sys/net/bpf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.216.6.2 src/sys/net/bpf.c:1.216.6.3 --- src/sys/net/bpf.c:1.216.6.2 Thu Dec 21 21:38:23 2017 +++ src/sys/net/bpf.c Thu Dec 21 21:51:37 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.216.6.2 2017/12/21 21:38:23 snj Exp $ */ +/* $NetBSD: bpf.c,v 1.216.6.3 2017/12/21 21:51:37 snj Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.2 2017/12/21 21:38:23 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.3 2017/12/21 21:51:37 snj Exp $"); #if defined(_KERNEL_OPT) #include "opt_bpf.h" @@ -564,9 +564,10 @@ bpfopen(dev_t dev, int flag, int mode, s #endif getnanotime(>bd_btime); d->bd_atime = d->bd_mtime = d->bd_btime; - callout_init(>bd_callout, 0); + callout_init(>bd_callout, CALLOUT_MPSAFE); selinit(>bd_sel); - d->bd_sih = softint_establish(SOFTINT_CLOCK, bpf_softintr, d); + d->bd_sih = softint_establish(SOFTINT_CLOCK|SOFTINT_MPSAFE, + bpf_softintr, d); d->bd_jitcode = NULL; d->bd_filter = NULL; BPF_DLIST_ENTRY_INIT(d); @@ -768,8 +769,10 @@ bpf_softintr(void *cookie) struct bpf_d *d; d = cookie; + mutex_enter(d->bd_mtx); if (d->bd_async) fownsignal(d->bd_pgid, SIGIO, 0, 0, NULL); + mutex_exit(d->bd_mtx); } static void @@ -1238,7 +1241,9 @@ bpf_ioctl(struct file *fp, u_long cmd, v break; case FIOASYNC: /* Send signal on receive packets */ + mutex_enter(d->bd_mtx); d->bd_async = *(int *)addr; + mutex_exit(d->bd_mtx); break; case TIOCSPGRP: /* Process or group to send signals to */
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Thu Dec 21 21:38:23 UTC 2017 Modified Files: src/sys/net [netbsd-8]: bpf.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #446): sys/net/bpf.c: revision 1.221 Fix panic in callout_halt (fix typo) Reported by wiz@ To generate a diff of this commit: cvs rdiff -u -r1.216.6.1 -r1.216.6.2 src/sys/net/bpf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.216.6.1 src/sys/net/bpf.c:1.216.6.2 --- src/sys/net/bpf.c:1.216.6.1 Wed Oct 25 07:14:09 2017 +++ src/sys/net/bpf.c Thu Dec 21 21:38:23 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.216.6.1 2017/10/25 07:14:09 snj Exp $ */ +/* $NetBSD: bpf.c,v 1.216.6.2 2017/12/21 21:38:23 snj Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.1 2017/10/25 07:14:09 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.2 2017/12/21 21:38:23 snj Exp $"); #if defined(_KERNEL_OPT) #include "opt_bpf.h" @@ -665,7 +665,7 @@ bpf_read(struct file *fp, off_t *offp, s mutex_enter(d->bd_mtx); if (d->bd_state == BPF_WAITING) - callout_halt(>bd_callout, d->bd_buf_mtx); + callout_halt(>bd_callout, d->bd_mtx); timed_out = (d->bd_state == BPF_TIMED_OUT); d->bd_state = BPF_IDLE; mutex_exit(d->bd_mtx);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: msaitoh Date: Fri Dec 8 06:12:35 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_pppoe.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #431): sys/net/if_pppoe.c: revision 1.133 Remove wrong assertions rw_lock_held() returns true when any context holds the lock. However, in if_pppoe.c, the function was used wrongly as it returns true only if the lock is held in the same context. >From s-yamaguchi@IIJ To generate a diff of this commit: cvs rdiff -u -r1.125.6.2 -r1.125.6.3 src/sys/net/if_pppoe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.125.6.2 src/sys/net/if_pppoe.c:1.125.6.3 --- src/sys/net/if_pppoe.c:1.125.6.2 Thu Nov 2 20:28:24 2017 +++ src/sys/net/if_pppoe.c Fri Dec 8 06:12:35 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.125.6.2 2017/11/02 20:28:24 snj Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.125.6.3 2017/12/08 06:12:35 msaitoh Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.2 2017/11/02 20:28:24 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.3 2017/12/08 06:12:35 msaitoh Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -135,9 +135,7 @@ struct pppoetag { #define PPPOE_LOCK(_sc, _op) rw_enter(&(_sc)->sc_lock, (_op)) #define PPPOE_UNLOCK(_sc) rw_exit(&(_sc)->sc_lock) -#define PPPOE_LOCKED(_sc) rw_lock_held(&(_sc)->sc_lock) #define PPPOE_WLOCKED(_sc) rw_write_held(&(_sc)->sc_lock) -#define PPPOE_RLOCKED(_sc) rw_read_held(&(_sc)->sc_lock) #ifdef PPPOE_MPSAFE #define DECLARE_SPLNET_VARIABLE @@ -1049,8 +1047,6 @@ pppoe_output(struct pppoe_softc *sc, str struct ether_header *eh; uint16_t etype; - KASSERT(PPPOE_LOCKED(sc)); - if (sc->sc_eth_if == NULL) { m_freem(m); return EIO; @@ -1253,8 +1249,6 @@ pppoe_send_padi(struct pppoe_softc *sc) int len, l1 = 0, l2 = 0; /* XXX: gcc */ uint8_t *p; - KASSERT(PPPOE_LOCKED(sc)); - if (sc->sc_state >PPPOE_STATE_PADI_SENT) panic("pppoe_send_padi in state %d", sc->sc_state); @@ -1529,8 +1523,6 @@ pppoe_send_padr(struct pppoe_softc *sc) uint8_t *p; size_t len, l1 = 0; /* XXX: gcc */ - KASSERT(PPPOE_LOCKED(sc)); - if (sc->sc_state != PPPOE_STATE_PADR_SENT) return EIO; @@ -1624,8 +1616,6 @@ pppoe_send_pado(struct pppoe_softc *sc) uint8_t *p; size_t len; - KASSERT(PPPOE_LOCKED(sc)); /* required by pppoe_output(). */ - if (sc->sc_state != PPPOE_STATE_PADO_SENT) return EIO; @@ -1699,8 +1689,6 @@ pppoe_tls(struct sppp *sp) struct pppoe_softc *sc = (void *)sp; int wtime; - KASSERT(!PPPOE_LOCKED(sc)); - PPPOE_LOCK(sc, RW_READER); if (sc->sc_state != PPPOE_STATE_INITIAL) { @@ -1730,8 +1718,6 @@ pppoe_tlf(struct sppp *sp) { struct pppoe_softc *sc = (void *)sp; - KASSERT(!PPPOE_LOCKED(sc)); - PPPOE_LOCK(sc, RW_WRITER); if (sc->sc_state < PPPOE_STATE_SESSION) {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Nov 27 14:11:17 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Pull up following revision(s) (requested by jmcneill in ticket #398): sys/net/if_vlan.c: revision 1.113 kern/52765: npf cannot do port forwarding on vlan interfaces Add pfil hooks support to vlan(4), from christos@ To generate a diff of this commit: cvs rdiff -u -r1.97.2.8 -r1.97.2.9 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.8 src/sys/net/if_vlan.c:1.97.2.9 --- src/sys/net/if_vlan.c:1.97.2.8 Fri Nov 24 08:39:09 2017 +++ src/sys/net/if_vlan.c Mon Nov 27 14:11:17 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.8 2017/11/24 08:39:09 martin Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.9 2017/11/27 14:11:17 martin Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.8 2017/11/24 08:39:09 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.9 2017/11/27 14:11:17 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1347,6 +1347,14 @@ vlan_transmit(struct ifnet *ifp, struct ec = (void *)mib->ifvm_p; bpf_mtap(ifp, m); + + if (pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_OUT) != 0) { + if (m != NULL) + m_freem(m); + error = 0; + goto out; + } + /* * If the parent can insert the tag itself, just mark * the tag in the mbuf header. @@ -1531,6 +1539,12 @@ vlan_input(struct ifnet *ifp, struct mbu m_set_rcvif(m, >ifv_if); ifv->ifv_if.if_ipackets++; + if (pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_IN) != 0) { + if (m != NULL) + m_freem(m); + goto out; + } + m->m_flags &= ~M_PROMISC; if_input(>ifv_if, m); out:
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Thu Nov 23 13:34:24 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_bridge.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #386): sys/net/if_bridge.c: revision 1.141 Add missing IFEF_NO_LINK_STATE_CHANGE to bridge To generate a diff of this commit: cvs rdiff -u -r1.134.6.2 -r1.134.6.3 src/sys/net/if_bridge.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_bridge.c diff -u src/sys/net/if_bridge.c:1.134.6.2 src/sys/net/if_bridge.c:1.134.6.3 --- src/sys/net/if_bridge.c:1.134.6.2 Thu Nov 23 02:13:31 2017 +++ src/sys/net/if_bridge.c Thu Nov 23 13:34:24 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_bridge.c,v 1.134.6.2 2017/11/23 02:13:31 snj Exp $ */ +/* $NetBSD: if_bridge.c,v 1.134.6.3 2017/11/23 13:34:24 martin Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -80,7 +80,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.2 2017/11/23 02:13:31 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.3 2017/11/23 13:34:24 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_bridge_ipf.h" @@ -424,7 +424,7 @@ bridge_clone_create(struct if_clone *ifc if_initname(ifp, ifc->ifc_name, unit); ifp->if_softc = sc; - ifp->if_extflags = IFEF_OUTPUT_MPSAFE; + ifp->if_extflags = IFEF_OUTPUT_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; ifp->if_mtu = ETHERMTU; ifp->if_ioctl = bridge_ioctl; ifp->if_output = bridge_output;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Thu Nov 23 02:13:31 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_bridge.c if_loop.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #382): sys/net/if_bridge.c: revision 1.139 sys/net/if_loop.c: revision 1.97 Don't take KERNEL_LOCK in looutput if NET_MPSAFE We can perhaps get rid of KERNEL_LOCK from looutput, but for now keep it for safe. -- Mark callouts of bridge CALLOUT_MPSAFE To generate a diff of this commit: cvs rdiff -u -r1.134.6.1 -r1.134.6.2 src/sys/net/if_bridge.c cvs rdiff -u -r1.94.6.1 -r1.94.6.2 src/sys/net/if_loop.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_bridge.c diff -u src/sys/net/if_bridge.c:1.134.6.1 src/sys/net/if_bridge.c:1.134.6.2 --- src/sys/net/if_bridge.c:1.134.6.1 Mon Oct 2 13:33:41 2017 +++ src/sys/net/if_bridge.c Thu Nov 23 02:13:31 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_bridge.c,v 1.134.6.1 2017/10/02 13:33:41 martin Exp $ */ +/* $NetBSD: if_bridge.c,v 1.134.6.2 2017/11/23 02:13:31 snj Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -80,7 +80,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.1 2017/10/02 13:33:41 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.2 2017/11/23 02:13:31 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_bridge_ipf.h" @@ -415,8 +415,8 @@ bridge_clone_create(struct if_clone *ifc if (error) panic("%s: workqueue_create %d\n", __func__, error); - callout_init(>sc_brcallout, 0); - callout_init(>sc_bstpcallout, 0); + callout_init(>sc_brcallout, CALLOUT_MPSAFE); + callout_init(>sc_bstpcallout, CALLOUT_MPSAFE); mutex_init(>sc_iflist_psref.bip_lock, MUTEX_DEFAULT, IPL_NONE); PSLIST_INIT(>sc_iflist_psref.bip_iflist); Index: src/sys/net/if_loop.c diff -u src/sys/net/if_loop.c:1.94.6.1 src/sys/net/if_loop.c:1.94.6.2 --- src/sys/net/if_loop.c:1.94.6.1 Tue Oct 24 08:50:44 2017 +++ src/sys/net/if_loop.c Thu Nov 23 02:13:31 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_loop.c,v 1.94.6.1 2017/10/24 08:50:44 snj Exp $ */ +/* $NetBSD: if_loop.c,v 1.94.6.2 2017/11/23 02:13:31 snj Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94.6.1 2017/10/24 08:50:44 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94.6.2 2017/11/23 02:13:31 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -242,7 +242,9 @@ looutput(struct ifnet *ifp, struct mbuf MCLAIM(m, ifp->if_mowner); +#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); +#endif if ((m->m_flags & M_PKTHDR) == 0) panic("looutput: no header mbuf"); @@ -368,7 +370,9 @@ looutput(struct ifnet *ifp, struct mbuf schednetisr(isr); splx(s); out: +#ifndef NET_MPSAFE KERNEL_UNLOCK_ONE(NULL); +#endif return error; }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Nov 22 14:36:55 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_media.c Log Message: Pull up following revision(s) (requested by msaitoh in ticket #370): sys/net/if_media.c: revision 1.33 sys/net/if_media.c: revision 1.34 No functional change: - Simplify ifmedia_removeall using with ifmedia_delete_instance(IFM_INST_ANY). - KNF. Clear ifm_cur and ifm_media after removing all ifmedia entries(IFM_INST_ANY) in ifmedia_delete_instance() like if_media.c rev. 1.32. Now if_media_delete_instance(IFM_INST_ANY) is the same as ifmedia_removeall(). To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.32.6.1 src/sys/net/if_media.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_media.c diff -u src/sys/net/if_media.c:1.32 src/sys/net/if_media.c:1.32.6.1 --- src/sys/net/if_media.c:1.32 Wed Jan 25 07:19:24 2017 +++ src/sys/net/if_media.c Wed Nov 22 14:36:55 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_media.c,v 1.32 2017/01/25 07:19:24 msaitoh Exp $ */ +/* $NetBSD: if_media.c,v 1.32.6.1 2017/11/22 14:36:55 martin Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -76,7 +76,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.32 2017/01/25 07:19:24 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.32.6.1 2017/11/22 14:36:55 martin Exp $"); #include #include @@ -206,9 +206,8 @@ ifmedia_set(struct ifmedia *ifm, int tar if (match == NULL) { ifmedia_add(ifm, target, 0, NULL); match = ifmedia_match(ifm, target, ifm->ifm_mask); - if (match == NULL) { + if (match == NULL) panic("ifmedia_set failed"); - } } } ifm->ifm_cur = match; @@ -265,7 +264,7 @@ ifmedia_ioctl(struct ifnet *ifp, struct newmedia); } #endif - return (EINVAL); + return EINVAL; } /* @@ -355,10 +354,10 @@ ifmedia_ioctl(struct ifnet *ifp, struct } default: - return (EINVAL); + return EINVAL; } - return (error); + return error; } /* @@ -398,8 +397,7 @@ ifmedia_delete_instance(struct ifmedia * { struct ifmedia_entry *ife, *nife; - for (ife = TAILQ_FIRST(>ifm_list); ife != NULL; - ife = nife) { + for (ife = TAILQ_FIRST(>ifm_list); ife != NULL; ife = nife) { nife = TAILQ_NEXT(ife, ifm_list); if (inst == IFM_INST_ANY || inst == IFM_INST(ife->ifm_media)) { @@ -407,20 +405,17 @@ ifmedia_delete_instance(struct ifmedia * free(ife, M_IFMEDIA); } } + if (inst == IFM_INST_ANY) { + ifm->ifm_cur = NULL; + ifm->ifm_media = IFM_NONE; + } } void ifmedia_removeall(struct ifmedia *ifm) { - struct ifmedia_entry *ife, *nife; - for (ife = TAILQ_FIRST(>ifm_list); ife != NULL; ife = nife) { - nife = TAILQ_NEXT(ife, ifm_list); - TAILQ_REMOVE(>ifm_list, ife, ifm_list); - free(ife, M_IFMEDIA); - } - ifm->ifm_cur = NULL; - ifm->ifm_media = IFM_NONE; + ifmedia_delete_instance(ifm, IFM_INST_ANY); } @@ -443,7 +438,7 @@ ifmedia_baudrate(int mword) } /* Not known. */ - return (0); + return 0; } #ifdef IFMEDIA_DEBUG
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Wed Nov 22 14:30:24 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Pull up following revision(s) (requested by msaitoh in ticket #368): sys/net/if_vlan.c: revision 1.101 sys/net/if_vlan.c: revision 1.102 Check if VLAN ID isn't duplicated on a same parent interface and return EEXIST if it failed. Remove accidentally added code (for VLAN hardware filter). To generate a diff of this commit: cvs rdiff -u -r1.97.2.6 -r1.97.2.7 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.6 src/sys/net/if_vlan.c:1.97.2.7 --- src/sys/net/if_vlan.c:1.97.2.6 Wed Nov 8 22:20:59 2017 +++ src/sys/net/if_vlan.c Wed Nov 22 14:30:23 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.6 2017/11/08 22:20:59 snj Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.7 2017/11/22 14:30:23 martin Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.6 2017/11/08 22:20:59 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.7 2017/11/22 14:30:23 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -379,10 +379,12 @@ vlan_config(struct ifvlan *ifv, struct i struct ifnet *ifp = >ifv_if; struct ifvlan_linkmib *nmib = NULL; struct ifvlan_linkmib *omib = NULL; + struct ifvlan_linkmib *checkmib = NULL; struct psref_target *nmib_psref = NULL; int error = 0; int idx; bool omib_cleanup = false; + struct psref psref; nmib = kmem_alloc(sizeof(*nmib), KM_SLEEP); @@ -394,6 +396,14 @@ vlan_config(struct ifvlan *ifv, struct i goto done; } + /* Duplicate check */ + checkmib = vlan_lookup_tag_psref(p, tag, ); + if (checkmib != NULL) { + vlan_putref_linkmib(checkmib, ); + error = EEXIST; + goto done; + } + *nmib = *omib; nmib_psref = >ifvm_psref;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Tue Nov 21 15:06:28 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_media.h Log Message: Pull up following revision(s) (requested by msaitoh in ticket #366): sys/net/if_media.h: revision 1.60 sys/net/if_media.h: revision 1.61 All Ethernet media more than 1000Mbps don't support half duplex. For the convinience, ifconfig without "mediaopt fullduplex" sets IFM_FDX automatically for those medias. Without this change, "ifconfig xxN mediaopt 10Gbase-T" (without "mediaopt fullduplex") returns EINVAL if a driver doesn't call ifmedia_add() without IFM_FDX because ifmedia_match() returns NULL. Add 2.5GBASE-T and 5GBASE-T. To generate a diff of this commit: cvs rdiff -u -r1.57.8.1 -r1.57.8.2 src/sys/net/if_media.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_media.h diff -u src/sys/net/if_media.h:1.57.8.1 src/sys/net/if_media.h:1.57.8.2 --- src/sys/net/if_media.h:1.57.8.1 Tue Jul 4 16:13:58 2017 +++ src/sys/net/if_media.h Tue Nov 21 15:06:27 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_media.h,v 1.57.8.1 2017/07/04 16:13:58 martin Exp $ */ +/* $NetBSD: if_media.h,v 1.57.8.2 2017/11/21 15:06:27 martin Exp $ */ /*- * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc. @@ -224,6 +224,8 @@ #define IFM_10G_T 26 /* 10GBase-T - RJ45 */ #define IFM_1000_KX 27 /* 1000base-KX backplane */ #define IFM_2500_KX 28 /* 2500base-KX backplane */ +#define IFM_2500_T 29 /* 2500base-T - RJ45 */ +#define IFM_5000_T 30 /* 5Gbase-T - RJ45 */ /* IFM_OMASK bits */ #define IFM_ETH_MASTER 0x0100 /* master mode (1000baseT) */ #define IFM_ETH_RXPAUSE 0x0200 /* receive PAUSE frames */ @@ -392,23 +394,27 @@ struct ifmedia_description { { IFM_ETHER | IFM_1000_T, "1000BASE-T" }, \ { IFM_ETHER | IFM_HPNA_1, "HomePNA1" }, \ { IFM_ETHER | IFM_HPNA_1, "HPNA1" }, \ - { IFM_ETHER | IFM_2500_KX, "2500BASE-KX" }, \ - { IFM_ETHER | IFM_2500_KX, "2500baseKX" }, \ - { IFM_ETHER | IFM_10G_LR, "10GbaseLR" }, \ - { IFM_ETHER | IFM_10G_LR, "10GLR" }, \ - { IFM_ETHER | IFM_10G_LR, "10GBASE-LR" }, \ - { IFM_ETHER | IFM_10G_SR, "10GbaseSR" }, \ - { IFM_ETHER | IFM_10G_SR, "10GSR" }, \ - { IFM_ETHER | IFM_10G_SR, "10GBASE-SR" }, \ - { IFM_ETHER | IFM_10G_LRM, "10Gbase-LRM" }, \ - { IFM_ETHER | IFM_10G_TWINAX, "10Gbase-Twinax" }, \ - { IFM_ETHER | IFM_10G_TWINAX_LONG, "10Gbase-Twinax-Long" },\ - { IFM_ETHER | IFM_10G_T, "10Gbase-T" }, \ - { IFM_ETHER | IFM_10G_CX4, "10GbaseCX4" }, \ - { IFM_ETHER | IFM_10G_CX4, "10GCX4" }, \ - { IFM_ETHER | IFM_10G_CX4, "10GBASE-CX4" }, \ - { IFM_ETHER | IFM_2500_SX, "2500baseSX" }, \ - { IFM_ETHER | IFM_2500_SX, "2500SX" }, \ + { IFM_ETHER | IFM_2500_KX | IFM_FDX, "2500BASE-KX" }, \ + { IFM_ETHER | IFM_2500_KX | IFM_FDX, "2500baseKX" }, \ + { IFM_ETHER | IFM_2500_T | IFM_FDX, "2.5GBASE-T" }, \ + { IFM_ETHER | IFM_2500_T | IFM_FDX, "2500baseT" }, \ + { IFM_ETHER | IFM_5000_T | IFM_FDX, "5GBASE-T" }, \ + { IFM_ETHER | IFM_5000_T | IFM_FDX, "5GbaseT" }, \ + { IFM_ETHER | IFM_10G_LR | IFM_FDX, "10GbaseLR" }, \ + { IFM_ETHER | IFM_10G_LR | IFM_FDX, "10GLR" }, \ + { IFM_ETHER | IFM_10G_LR | IFM_FDX, "10GBASE-LR" }, \ + { IFM_ETHER | IFM_10G_SR | IFM_FDX, "10GbaseSR" }, \ + { IFM_ETHER | IFM_10G_SR | IFM_FDX, "10GSR" }, \ + { IFM_ETHER | IFM_10G_SR | IFM_FDX, "10GBASE-SR" }, \ + { IFM_ETHER | IFM_10G_LRM | IFM_FDX, "10Gbase-LRM" }, \ + { IFM_ETHER | IFM_10G_TWINAX | IFM_FDX, "10Gbase-Twinax" }, \ + { IFM_ETHER | IFM_10G_TWINAX_LONG | IFM_FDX, "10Gbase-Twinax-Long" },\ + { IFM_ETHER | IFM_10G_T | IFM_FDX, "10Gbase-T" }, \ + { IFM_ETHER | IFM_10G_CX4 | IFM_FDX, "10GbaseCX4" }, \ + { IFM_ETHER | IFM_10G_CX4 | IFM_FDX, "10GCX4" }, \ + { IFM_ETHER | IFM_10G_CX4 | IFM_FDX, "10GBASE-CX4" }, \ + { IFM_ETHER | IFM_2500_SX | IFM_FDX, "2500baseSX" }, \ + { IFM_ETHER | IFM_2500_SX | IFM_FDX, "2500SX" }, \ \ { IFM_TOKEN | IFM_TOK_STP4, "DB9/4Mbit" }, \ { IFM_TOKEN | IFM_TOK_STP4, "4STP" }, \ @@ -549,6 +555,8 @@ struct ifmedia_baudrate { { IFM_ETHER | IFM_10G_T, IF_Gbps(10) }, \ { IFM_ETHER | IFM_1000_KX, IF_Mbps(1000ULL) }, \ { IFM_ETHER | IFM_2500_KX, IF_Mbps(2500ULL) }, \ + { IFM_ETHER | IFM_2500_T, IF_Mbps(2500ULL) }, \ + { IFM_ETHER | IFM_5000_T, IF_Mbps(5000ULL) }, \ \ { IFM_TOKEN | IFM_TOK_STP4, IF_Mbps(4) }, \ { IFM_TOKEN | IFM_TOK_STP16, IF_Mbps(16) }, \
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Wed Nov 8 22:20:59 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_l2tp.c if_tap.c if_tun.c if_vlan.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #349): sys/net/if_l2tp.c: revision 1.14 sys/net/if_tap.c: revision 1.101 sys/net/if_tun.c: revision 1.141 sys/net/if_vlan.c: revision 1.106 Set IFEF_NO_LINK_STATE_CHANGE flag to pseudo devices that don't use if_link_state_change To generate a diff of this commit: cvs rdiff -u -r1.11.2.1 -r1.11.2.2 src/sys/net/if_l2tp.c cvs rdiff -u -r1.99 -r1.99.6.1 src/sys/net/if_tap.c cvs rdiff -u -r1.139 -r1.139.2.1 src/sys/net/if_tun.c cvs rdiff -u -r1.97.2.5 -r1.97.2.6 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_l2tp.c diff -u src/sys/net/if_l2tp.c:1.11.2.1 src/sys/net/if_l2tp.c:1.11.2.2 --- src/sys/net/if_l2tp.c:1.11.2.1 Mon Nov 6 09:59:01 2017 +++ src/sys/net/if_l2tp.c Wed Nov 8 22:20:59 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_l2tp.c,v 1.11.2.1 2017/11/06 09:59:01 snj Exp $ */ +/* $NetBSD: if_l2tp.c,v 1.11.2.2 2017/11/08 22:20:59 snj Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.1 2017/11/06 09:59:01 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.2 2017/11/08 22:20:59 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -261,7 +261,8 @@ l2tpattach0(struct l2tp_softc *sc) sc->l2tp_ec.ec_if.if_addrlen = 0; sc->l2tp_ec.ec_if.if_mtu= L2TP_MTU; sc->l2tp_ec.ec_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST|IFF_SIMPLEX; - sc->l2tp_ec.ec_if.if_extflags = IFEF_OUTPUT_MPSAFE|IFEF_START_MPSAFE; + sc->l2tp_ec.ec_if.if_extflags = IFEF_OUTPUT_MPSAFE | + IFEF_START_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; sc->l2tp_ec.ec_if.if_ioctl = l2tp_ioctl; sc->l2tp_ec.ec_if.if_output = l2tp_output; sc->l2tp_ec.ec_if.if_type = IFT_L2TP; Index: src/sys/net/if_tap.c diff -u src/sys/net/if_tap.c:1.99 src/sys/net/if_tap.c:1.99.6.1 --- src/sys/net/if_tap.c:1.99 Sun Feb 12 09:47:31 2017 +++ src/sys/net/if_tap.c Wed Nov 8 22:20:59 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tap.c,v 1.99 2017/02/12 09:47:31 skrll Exp $ */ +/* $NetBSD: if_tap.c,v 1.99.6.1 2017/11/08 22:20:59 snj Exp $ */ /* * Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation. @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.99 2017/02/12 09:47:31 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.99.6.1 2017/11/08 22:20:59 snj Exp $"); #if defined(_KERNEL_OPT) @@ -370,6 +370,7 @@ tap_attach(device_t parent, device_t sel strcpy(ifp->if_xname, device_xname(self)); ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE; ifp->if_ioctl = tap_ioctl; ifp->if_start = tap_start; ifp->if_stop = tap_stop; Index: src/sys/net/if_tun.c diff -u src/sys/net/if_tun.c:1.139 src/sys/net/if_tun.c:1.139.2.1 --- src/sys/net/if_tun.c:1.139 Wed May 24 06:52:14 2017 +++ src/sys/net/if_tun.c Wed Nov 8 22:20:59 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tun.c,v 1.139 2017/05/24 06:52:14 pgoyette Exp $ */ +/* $NetBSD: if_tun.c,v 1.139.2.1 2017/11/08 22:20:59 snj Exp $ */ /* * Copyright (c) 1988, Julian Onions@@ -19,7 +19,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139 2017/05/24 06:52:14 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139.2.1 2017/11/08 22:20:59 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -247,6 +247,7 @@ tunattach0(struct tun_softc *tp) ifp->if_start = tunstart; #endif ifp->if_flags = IFF_POINTOPOINT; + ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE; ifp->if_type = IFT_TUNNEL; ifp->if_snd.ifq_maxlen = ifqmaxlen; ifp->if_collisions = 0; Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.5 src/sys/net/if_vlan.c:1.97.2.6 --- src/sys/net/if_vlan.c:1.97.2.5 Mon Nov 6 09:57:39 2017 +++ src/sys/net/if_vlan.c Wed Nov 8 22:20:59 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.5 2017/11/06 09:57:39 snj Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.6 2017/11/08 22:20:59 snj Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.5 2017/11/06 09:57:39 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.6 2017/11/08 22:20:59 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -337,7 +337,7 @@ vlan_clone_create(struct if_clone *ifc, if_initname(ifp, ifc->ifc_name, unit); ifp->if_softc = ifv; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_extflags = IFEF_START_MPSAFE; + ifp->if_extflags = IFEF_START_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; ifp->if_start = vlan_start; ifp->if_transmit
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Mon Nov 6 09:59:01 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_l2tp.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #341): sys/net/if_l2tp.c: revision 1.12 fix l2tp panic when l2tp session id is changed (same as if_vlan.c:r1.104) E.g. the following operation causes this panic. # ifconfig l2tp0 create # ifconfig l2tp0 session 140 140 # ifconfig l2tp1 create # ifconfig l2tp1 session 200 200 # ifconfig l2tp1 session 300 300 panic: kernel diagnostic assertion "new->ple_next == NULL" failed: file "/disk4/home/k-nakahara/repos/netbsd-src/sys/sys/pslist.h", line 118 Pointed out by s-yamaguchi@IIJ, thanks. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.11.2.1 src/sys/net/if_l2tp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_l2tp.c diff -u src/sys/net/if_l2tp.c:1.11 src/sys/net/if_l2tp.c:1.11.2.1 --- src/sys/net/if_l2tp.c:1.11 Thu Jun 1 02:45:14 2017 +++ src/sys/net/if_l2tp.c Mon Nov 6 09:59:01 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_l2tp.c,v 1.11 2017/06/01 02:45:14 chs Exp $ */ +/* $NetBSD: if_l2tp.c,v 1.11.2.1 2017/11/06 09:59:01 snj Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11 2017/06/01 02:45:14 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.1 2017/11/06 09:59:01 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1069,6 +1069,7 @@ l2tp_set_session(struct l2tp_softc *sc, pserialize_perform(l2tp_psz); } mutex_exit(_hash.lock); + PSLIST_ENTRY_DESTROY(sc, l2tp_hash); l2tp_variant_update(sc, nvar); mutex_exit(>l2tp_lock); @@ -1078,6 +1079,7 @@ l2tp_set_session(struct l2tp_softc *sc, log(LOG_DEBUG, "%s: add hash entry: sess_id=%" PRIu32 ", idx=%" PRIu32 "\n", sc->l2tp_ec.ec_if.if_xname, nvar->lv_my_sess_id, idx); + PSLIST_ENTRY_INIT(sc, l2tp_hash); mutex_enter(_hash.lock); PSLIST_WRITER_INSERT_HEAD(_hash.lists[idx], sc, l2tp_hash); mutex_exit(_hash.lock);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Mon Nov 6 09:57:39 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Pull up following revision(s) (requested by knahakara in ticket #340): sys/net/if_vlan.c: revision 1.104 fix vlan panic when vlan is re-configured without destroy. E.g. the following operation causes this panic. # ifconfig vlan0 create # ifconfig vlan0 vlan 1 vlanif ixg3 # ifconfig vlan1 create # ifconfig vlan1 vlan 1 vlanif ixg2 # ifconfig vlan1 -vlanif # ifconfig vlan1 vlan 1 vlanif ixg2 panic: kernel diagnostic assertion "new->ple_next == NULL" failed: file "/git/netbsd-src/sys/sys/pslist.h", line 118 Pointed out and tested by msaitoh@n.o, fixed by s-yamaguchi@IIJ, thanks. To generate a diff of this commit: cvs rdiff -u -r1.97.2.4 -r1.97.2.5 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.4 src/sys/net/if_vlan.c:1.97.2.5 --- src/sys/net/if_vlan.c:1.97.2.4 Wed Oct 25 07:12:33 2017 +++ src/sys/net/if_vlan.c Mon Nov 6 09:57:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.4 2017/10/25 07:12:33 snj Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.5 2017/11/06 09:57:39 snj Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.4 2017/10/25 07:12:33 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.5 2017/11/06 09:57:39 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -468,6 +468,7 @@ vlan_config(struct ifvlan *ifv, struct i */ ifv->ifv_if.if_type = p->if_type; + PSLIST_ENTRY_INIT(ifv, ifv_hash); idx = tag_hash_func(tag, ifv_hash.mask); mutex_enter(_hash.lock); @@ -572,6 +573,7 @@ vlan_unconfig_locked(struct ifvlan *ifv, PSLIST_WRITER_REMOVE(ifv, ifv_hash); pserialize_perform(vlan_psz); mutex_exit(_hash.lock); + PSLIST_ENTRY_DESTROY(ifv, ifv_hash); vlan_linkmib_update(ifv, nmib);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Thu Nov 2 20:28:24 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_pppoe.c if_pppoe.h if_spppsubr.c if_spppvar.h Log Message: Pull up following revision(s) (requested by knakahara in ticket #332): sys/net/if_pppoe.c: 1.127-1.128 sys/net/if_pppoe.h: 1.15 sys/net/if_spppsubr.c: 1.170-1.171 sys/net/if_spppvar.h: 1.21-1.22 Integrate two locks used to protect PPPoE softc. Contributed by s-yamaguchi@IIJ. PPPOE_SESSION_LOCK protects variables used in PPP packet processing, on the other hand PPPOE_PARAM_LOCK protects the other variables used to establish a PPPoE session id. Those locks isn't acquired in the same time because the PPP packet processing doesn't work without PPPoE session id. By the reason, the locks can be integrated into PPPOE_LOCK. Add locking notes later. -- sppp_lock is changed from mutex to rwlock now. Contributed by s-yamaguchi@IIJ. Add locking notes later. -- Add a locking notes for if_pppoe -- Add a locking notes for if_spppsubr -- fix no INET6 build. To generate a diff of this commit: cvs rdiff -u -r1.125.6.1 -r1.125.6.2 src/sys/net/if_pppoe.c cvs rdiff -u -r1.14 -r1.14.2.1 src/sys/net/if_pppoe.h cvs rdiff -u -r1.169 -r1.169.6.1 src/sys/net/if_spppsubr.c cvs rdiff -u -r1.20 -r1.20.8.1 src/sys/net/if_spppvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.125.6.1 src/sys/net/if_pppoe.c:1.125.6.2 --- src/sys/net/if_pppoe.c:1.125.6.1 Tue Jul 25 02:07:11 2017 +++ src/sys/net/if_pppoe.c Thu Nov 2 20:28:24 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.125.6.1 2017/07/25 02:07:11 snj Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.125.6.2 2017/11/02 20:28:24 snj Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.1 2017/07/25 02:07:11 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.2 2017/11/02 20:28:24 snj Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -133,18 +133,12 @@ struct pppoetag { #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */ #endif -#define PPPOE_SESSION_LOCK(_sc, _op) rw_enter(&(_sc)->sc_session_lock, (_op)) -#define PPPOE_SESSION_UNLOCK(_sc) rw_exit(&(_sc)->sc_session_lock) -#define PPPOE_SESSION_LOCKED(_sc) rw_lock_held(&(_sc)->sc_session_lock) -#define PPPOE_SESSION_WLOCKED(_sc) rw_write_held(&(_sc)->sc_session_lock) -#define PPPOE_SESSION_RLOCKED(_sc) rw_read_held(&(_sc)->sc_session_lock) - -#define PPPOE_PARAM_LOCK(_sc) if ((_sc)->sc_lock) \ - mutex_enter((_sc)->sc_lock) -#define PPPOE_PARAM_UNLOCK(_sc) if ((_sc)->sc_lock) \ - mutex_exit((_sc)->sc_lock) -#define PPPOE_PARAM_LOCKED(_sc) (!(_sc)->sc_lock || \ - mutex_owned((_sc)->sc_lock)) +#define PPPOE_LOCK(_sc, _op) rw_enter(&(_sc)->sc_lock, (_op)) +#define PPPOE_UNLOCK(_sc) rw_exit(&(_sc)->sc_lock) +#define PPPOE_LOCKED(_sc) rw_lock_held(&(_sc)->sc_lock) +#define PPPOE_WLOCKED(_sc) rw_write_held(&(_sc)->sc_lock) +#define PPPOE_RLOCKED(_sc) rw_read_held(&(_sc)->sc_lock) + #ifdef PPPOE_MPSAFE #define DECLARE_SPLNET_VARIABLE #define ACQUIRE_SPLNET() do { } while (0) @@ -165,7 +159,6 @@ struct pppoe_softc { struct ifnet *sc_eth_if; /* ethernet interface we are using */ int sc_state; /* discovery phase or session connected */ - bool sc_state_updating; /* state update in other components */ struct ether_addr sc_dest; /* hardware address of concentrator */ uint16_t sc_session; /* PPPoE session id */ @@ -182,8 +175,7 @@ struct pppoe_softc { callout_t sc_timeout; /* timeout while not in session state */ int sc_padi_retried; /* number of PADI retries already done */ int sc_padr_retried; /* number of PADR retries already done */ - krwlock_t sc_session_lock; /* lock of sc_state, sc_session, and sc_eth_if */ - kmutex_t *sc_lock; /* lock of other parameters */ + krwlock_t sc_lock; /* lock of sc_state, sc_session, and sc_eth_if */ }; /* incoming traffic will be queued here */ @@ -343,8 +335,7 @@ pppoe_clone_create(struct if_clone *ifc, pfil_add_ihook(pppoe_ifattach_hook, NULL, PFIL_IFNET, if_pfil); } - sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET); - rw_init(>sc_session_lock); + rw_init(>sc_lock); rw_enter(_softc_list_lock, RW_WRITER); LIST_INSERT_HEAD(_softc_list, sc, sc_list); @@ -359,7 +350,7 @@ pppoe_clone_destroy(struct ifnet *ifp) rw_enter(_softc_list_lock, RW_WRITER); - PPPOE_PARAM_LOCK(sc); + PPPOE_LOCK(sc, RW_WRITER); callout_halt(>sc_timeout, NULL); LIST_REMOVE(sc, sc_list); @@ -369,7 +360,6 @@ pppoe_clone_destroy(struct ifnet *ifp) } rw_exit(_softc_list_lock); - PPPOE_SESSION_LOCK(sc, RW_WRITER); bpf_detach(ifp); sppp_detach(>sc_sppp.pp_if); @@ -384,11 +374,8 @@ pppoe_clone_destroy(struct ifnet *ifp) free(sc->sc_relay_sid,
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Wed Oct 25 07:14:10 UTC 2017 Modified Files: src/sys/net [netbsd-8]: bpf.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #329): sys/net/bpf.c: revision 1.217 Turn on D_MPSAFE flag of bpf_cdevsw that is already MP-safe Pointed out by k-goda@IIJ To generate a diff of this commit: cvs rdiff -u -r1.216 -r1.216.6.1 src/sys/net/bpf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.216 src/sys/net/bpf.c:1.216.6.1 --- src/sys/net/bpf.c:1.216 Mon Feb 20 03:08:38 2017 +++ src/sys/net/bpf.c Wed Oct 25 07:14:09 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.216 2017/02/20 03:08:38 ozaki-r Exp $ */ +/* $NetBSD: bpf.c,v 1.216.6.1 2017/10/25 07:14:09 snj Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216 2017/02/20 03:08:38 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.1 2017/10/25 07:14:09 snj Exp $"); #if defined(_KERNEL_OPT) #include "opt_bpf.h" @@ -296,7 +296,7 @@ const struct cdevsw bpf_cdevsw = { .d_mmap = nommap, .d_kqfilter = nokqfilter, .d_discard = nodiscard, - .d_flag = D_OTHER + .d_flag = D_OTHER | D_MPSAFE }; bpfjit_func_t
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Wed Oct 25 07:12:33 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #328): sys/net/if_vlan.c: revision 1.103 Set IFEF_START_MPSAFE by default Because vlan_start is already MP-safe, there is no reason to not do so. Acked by s-yamaguchi@IIJ To generate a diff of this commit: cvs rdiff -u -r1.97.2.3 -r1.97.2.4 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.3 src/sys/net/if_vlan.c:1.97.2.4 --- src/sys/net/if_vlan.c:1.97.2.3 Tue Oct 24 08:38:59 2017 +++ src/sys/net/if_vlan.c Wed Oct 25 07:12:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.3 2017/10/24 08:38:59 snj Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.4 2017/10/25 07:12:33 snj Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,11 +78,10 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.3 2017/10/24 08:38:59 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.4 2017/10/25 07:12:33 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" -#include "opt_net_mpsafe.h" #endif #include @@ -123,10 +122,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v #include "ioconf.h" -#ifdef NET_MPSAFE -#define VLAN_MPSAFE 1 -#endif - struct vlan_mc_entry { LIST_ENTRY(vlan_mc_entry) mc_entries; /* @@ -342,9 +337,7 @@ vlan_clone_create(struct if_clone *ifc, if_initname(ifp, ifc->ifc_name, unit); ifp->if_softc = ifv; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; -#ifdef VLAN_MPSAFE ifp->if_extflags = IFEF_START_MPSAFE; -#endif ifp->if_start = vlan_start; ifp->if_transmit = vlan_transmit; ifp->if_ioctl = vlan_ioctl; @@ -1183,10 +1176,6 @@ vlan_start(struct ifnet *ifp) struct psref psref; int error; -#ifndef NET_MPSAFE - KASSERT(KERNEL_LOCKED_P()); -#endif - mib = vlan_getref_linkmib(ifv, ); if (mib == NULL) return;
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Tue Oct 24 08:50:44 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_loop.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #304): sys/net/if_loop.c: revision 1.95 loop_clone_create() must be called after ncpu is counted up for all CPUs. loop_clone_create() uses ncpu in the following call-path. - loop_clone_create() - if_attach() - if_percpuq_create() - softint_establish() // use ncpu - percpu_foreach() // use ncpu However, loopinit() of built-in module is called from module_init_class(MODULE_CLASS_DRIVER) which is called before ncpu is counted up in some architectures. So, It is too fast. On the other hand, it is too late for rump netinet component to call loop_clone_create() in config_finalize(). As the result, loop_clone_create() shuld be called in loopattach() for built-in module, and in loopinit() for dynamic module. To generate a diff of this commit: cvs rdiff -u -r1.94 -r1.94.6.1 src/sys/net/if_loop.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_loop.c diff -u src/sys/net/if_loop.c:1.94 src/sys/net/if_loop.c:1.94.6.1 --- src/sys/net/if_loop.c:1.94 Tue Mar 28 08:47:19 2017 +++ src/sys/net/if_loop.c Tue Oct 24 08:50:44 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_loop.c,v 1.94 2017/03/28 08:47:19 ozaki-r Exp $ */ +/* $NetBSD: if_loop.c,v 1.94.6.1 2017/10/24 08:50:44 snj Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94 2017/03/28 08:47:19 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94.6.1 2017/10/24 08:50:44 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -146,10 +146,9 @@ void loopattach(int n) { - /* - * Nothing to do here, initialization is handled by the - * module initialization code in loopnit() below). - */ +#ifndef _MODULE + loop_clone_create(_cloner, 0); /* lo0 always exists */ +#endif } void @@ -159,7 +158,9 @@ loopinit(void) if (lo0ifp != NULL) /* can happen in rump kernel */ return; - (void)loop_clone_create(_cloner, 0); /* lo0 always exists */ +#ifdef _MODULE + loop_clone_create(_cloner, 0); /* lo0 always exists */ +#endif if_clone_attach(_cloner); }
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Mon Oct 2 13:33:41 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_bridge.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #297): sys/net/if_bridge.c: revision 1.135 Add curlwp_bind to bridge_input for psref It can be called in a thread context via tap (tap_dev_write). Fix PR kern/52587 To generate a diff of this commit: cvs rdiff -u -r1.134 -r1.134.6.1 src/sys/net/if_bridge.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_bridge.c diff -u src/sys/net/if_bridge.c:1.134 src/sys/net/if_bridge.c:1.134.6.1 --- src/sys/net/if_bridge.c:1.134 Tue Mar 7 01:53:53 2017 +++ src/sys/net/if_bridge.c Mon Oct 2 13:33:41 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_bridge.c,v 1.134 2017/03/07 01:53:53 ozaki-r Exp $ */ +/* $NetBSD: if_bridge.c,v 1.134.6.1 2017/10/02 13:33:41 martin Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -80,7 +80,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134 2017/03/07 01:53:53 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.1 2017/10/02 13:33:41 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_bridge_ipf.h" @@ -1792,6 +1792,7 @@ bridge_input(struct ifnet *ifp, struct m struct bridge_iflist *bif; struct ether_header *eh; struct psref psref; + int bound; DECLARE_LOCK_VARIABLE; KASSERT(!cpu_intr_p()); @@ -1804,8 +1805,10 @@ bridge_input(struct ifnet *ifp, struct m return; } + bound = curlwp_bind(); bif = bridge_lookup_member_if(sc, ifp, ); if (bif == NULL) { + curlwp_bindx(bound); ACQUIRE_GLOBAL_LOCKS(); ether_input(ifp, m); RELEASE_GLOBAL_LOCKS(); @@ -1857,6 +1860,7 @@ out: if (_bif != NULL) { bridge_release_member(sc, bif, ); + curlwp_bindx(bound); if (_ifp != NULL) { m->m_flags &= ~M_PROMISC; ACQUIRE_GLOBAL_LOCKS(); @@ -1873,6 +1877,7 @@ out: memcmp(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN) == 0) { bstp_input(sc, bif, m); bridge_release_member(sc, bif, ); + curlwp_bindx(bound); return; } @@ -1882,6 +1887,7 @@ out: */ if (bstp_state_before_learning(bif)) { bridge_release_member(sc, bif, ); + curlwp_bindx(bound); ACQUIRE_GLOBAL_LOCKS(); ether_input(ifp, m); RELEASE_GLOBAL_LOCKS(); @@ -1891,6 +1897,8 @@ out: bridge_release_member(sc, bif, ); bridge_forward(sc, m); + + curlwp_bindx(bound); } /*
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Mon Aug 14 23:39:24 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_vlan.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #205): sys/net/if_vlan.c: revision 1.99 Fix vlan(4) obytes counter. Implemented by s-yamaguchi@IIJ, thanks. To generate a diff of this commit: cvs rdiff -u -r1.97.2.1 -r1.97.2.2 src/sys/net/if_vlan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97.2.1 src/sys/net/if_vlan.c:1.97.2.2 --- src/sys/net/if_vlan.c:1.97.2.1 Wed Jun 21 17:39:24 2017 +++ src/sys/net/if_vlan.c Mon Aug 14 23:39:24 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97.2.1 2017/06/21 17:39:24 snj Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.2 2017/08/14 23:39:24 snj Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.1 2017/06/21 17:39:24 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.2 2017/08/14 23:39:24 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1342,6 +1342,8 @@ vlan_transmit(struct ifnet *ifp, struct struct ifvlan_linkmib *mib; struct psref psref; int error; + size_t pktlen = m->m_pkthdr.len; + bool mcast = (m->m_flags & M_MCAST) != 0; mib = vlan_getref_linkmib(ifv, ); if (mib == NULL) { @@ -1451,10 +1453,11 @@ vlan_transmit(struct ifnet *ifp, struct /* mbuf is already freed */ ifp->if_oerrors++; } else { + ifp->if_opackets++; - /* - * obytes is incremented at ether_output() or bridge_enqueue(). - */ + ifp->if_obytes += pktlen; + if (mcast) + ifp->if_omcasts++; } out:
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Wed Aug 9 05:51:50 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_gif.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #201): sys/net/if_gif.c: revision 1.128 fix leak when encap_attach() fails twice. To generate a diff of this commit: cvs rdiff -u -r1.126.2.1 -r1.126.2.2 src/sys/net/if_gif.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_gif.c diff -u src/sys/net/if_gif.c:1.126.2.1 src/sys/net/if_gif.c:1.126.2.2 --- src/sys/net/if_gif.c:1.126.2.1 Fri Jun 30 06:17:51 2017 +++ src/sys/net/if_gif.c Wed Aug 9 05:51:50 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_gif.c,v 1.126.2.1 2017/06/30 06:17:51 snj Exp $ */ +/* $NetBSD: if_gif.c,v 1.126.2.2 2017/08/09 05:51:50 snj Exp $ */ /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.1 2017/06/30 06:17:51 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.2 2017/08/09 05:51:50 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -997,31 +997,34 @@ gif_set_tunnel(struct ifnet *ifp, struct /* * Secondly, try to set new configurations. - * If the setup failed, rollback to old configurations. */ - do { - osrc = sc->gif_psrc; - odst = sc->gif_pdst; - sc->gif_psrc = nsrc; - sc->gif_pdst = ndst; - + osrc = sc->gif_psrc; + odst = sc->gif_pdst; + sc->gif_psrc = nsrc; + sc->gif_pdst = ndst; + error = gif_encap_attach(sc); + if (error && osrc != NULL && odst != NULL) { + /* + * Thirdly, when error occured, rollback to old configurations, + * if last setting is valid. + */ + sc->gif_psrc = osrc; + sc->gif_pdst = odst; + osrc = nsrc; /* to free */ + odst = ndst; /* to free */ error = gif_encap_attach(sc); - if (error) { - /* rollback to the last configuration. */ - nsrc = osrc; - ndst = odst; - osrc = sc->gif_psrc; - odst = sc->gif_pdst; - - continue; - } - } while (error != 0 && (nsrc != NULL && ndst != NULL)); - /* Thirdly, even rollback failed, clear configurations. */ + } if (error) { - osrc = sc->gif_psrc; - odst = sc->gif_pdst; + /* + * Fourthly, even rollback failed or last setting is not valid, + * clear configurations. + */ + osrc = sc->gif_psrc; /* to free */ + odst = sc->gif_pdst; /* to free */ sc->gif_psrc = NULL; sc->gif_pdst = NULL; + sockaddr_free(nsrc); + sockaddr_free(ndst); } if (osrc)
CVS commit: [netbsd-8] src/sys/net/npf
Module Name:src Committed By: snj Date: Tue Jul 25 02:17:16 UTC 2017 Modified Files: src/sys/net/npf [netbsd-8]: npf_os.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #155): sys/net/npf/npf_os.c: revision 1.7 The npf module depends on some stuff from the bpf module, so set the required modules list accordingly. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.6.8.1 src/sys/net/npf/npf_os.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/npf/npf_os.c diff -u src/sys/net/npf/npf_os.c:1.6 src/sys/net/npf/npf_os.c:1.6.8.1 --- src/sys/net/npf/npf_os.c:1.6 Fri Jan 27 17:25:34 2017 +++ src/sys/net/npf/npf_os.c Tue Jul 25 02:17:16 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_os.c,v 1.6 2017/01/27 17:25:34 ryo Exp $ */ +/* $NetBSD: npf_os.c,v 1.6.8.1 2017/07/25 02:17:16 snj Exp $ */ /*- * Copyright (c) 2009-2016 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.6 2017/01/27 17:25:34 ryo Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.6.8.1 2017/07/25 02:17:16 snj Exp $"); #ifdef _KERNEL_OPT #include "pf.h" @@ -79,10 +79,10 @@ __KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1 * So we make this misc; a better way would be to have early boot and late * boot drivers. */ -MODULE(MODULE_CLASS_MISC, npf, NULL); +MODULE(MODULE_CLASS_MISC, npf, "bpf"); #else /* This module autoloads via /dev/npf so it needs to be a driver */ -MODULE(MODULE_CLASS_DRIVER, npf, NULL); +MODULE(MODULE_CLASS_DRIVER, npf, "bpf"); #endif static int npf_dev_open(dev_t, int, int, lwp_t *);
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Tue Jul 25 02:07:12 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_pppoe.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #149): sys/net/if_pppoe.c: revision 1.126 fix panic when PPPOE_DEBUG enabled. implemented by s-yamaguchi@IIJ, thanks. To generate a diff of this commit: cvs rdiff -u -r1.125 -r1.125.6.1 src/sys/net/if_pppoe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.125 src/sys/net/if_pppoe.c:1.125.6.1 --- src/sys/net/if_pppoe.c:1.125 Tue Feb 7 02:33:54 2017 +++ src/sys/net/if_pppoe.c Tue Jul 25 02:07:11 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.125 2017/02/07 02:33:54 ozaki-r Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.125.6.1 2017/07/25 02:07:11 snj Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125 2017/02/07 02:33:54 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.1 2017/07/25 02:07:11 snj Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -1366,7 +1366,6 @@ pppoe_send_padi(struct pppoe_softc *sc) } #ifdef PPPOE_DEBUG - p += sizeof sc; if (p - mtod(m0, uint8_t *) != len + PPPOE_HEADERLEN) panic("pppoe_send_padi: garbled output len, should be %ld, is %ld", (long)(len + PPPOE_HEADERLEN), (long)(p - mtod(m0, uint8_t *))); @@ -1666,7 +1665,6 @@ pppoe_send_padr(struct pppoe_softc *sc) } #ifdef PPPOE_DEBUG - p += sizeof sc; if (p - mtod(m0, uint8_t *) != len + PPPOE_HEADERLEN) panic("pppoe_send_padr: garbled output len, should be %ld, is %ld", (long)(len + PPPOE_HEADERLEN), (long)(p - mtod(m0, uint8_t *)));
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: martin Date: Tue Jul 4 16:13:58 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_media.h Log Message: Pull up following revision(s) (requested by msaitoh in ticket #82): sys/net/if_media.h: revision 1.58 sys/net/if_media.h: revision 1.59 No functional change: - Relocate definitions in the following order to be easy to understand. 0) IFM_*MASK 1) macros to extract various bits of information from the media word. 2) Media type. 3) Shared media sub-type. 4) Status bits. 5) Shared (global) options 6) Media dependent definitions. 7) kernel function declarations. 7) userland function declarations. - Add comments. This change makes me realize that: 0) RFU bit have never used. 1) bit 1..0 are shared between Shared media sub-type and Status bits. It's little dangerous. 2) No. 5 of Media type is not used (hole). 3) Only IEEE80211 uses IFM_MMASK(IFM_MODE()) bits. 4) IFM_TOKEN's OMASK bits doesn't start from 0x0100 but starts from 0x0200. Is this for BSD/OS compatibility? - Add some missing baudrate entries - Add 1000BASE-KX and 2500BASE-KX To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.57.8.1 src/sys/net/if_media.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_media.h diff -u src/sys/net/if_media.h:1.57 src/sys/net/if_media.h:1.57.8.1 --- src/sys/net/if_media.h:1.57 Wed Sep 14 11:43:08 2016 +++ src/sys/net/if_media.h Tue Jul 4 16:13:58 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_media.h,v 1.57 2016/09/14 11:43:08 roy Exp $ */ +/* $NetBSD: if_media.h,v 1.57.8.1 2017/07/04 16:13:58 martin Exp $ */ /*- * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc. @@ -80,91 +80,124 @@ */ #ifdef _KERNEL - #include +#endif /*_KERNEL */ /* - * Driver callbacks for media status and change requests. + * if_media Options word: + * Bits Use + * --- + * 0-4 Media subtype MAX SUBTYPE == 31! + * 5-7 Media type + * 8-15 Type specific options + * 16-18 Mode (for multi-mode devices) + * 19 RFU (not used) + * 20-27 Shared (global) options + * 28-31 Instance + * + * 3 2 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +---+---+-+-+---+-+-+ + * | | |R| | | | |STA| + * | IMASK | GMASK |F|MMASK| OMASK |NMASK| +---| + * | | |U| | | | TMASK | + * +---+---+-+-+---+-+-+ + * <-> <---> <---> + * IFM_INST() IFM_MODE()IFM_TYPE() + * + * <-> <-> <---> + *IFM_OPTIONS() IFM_SUBTYPE() */ -typedef int (*ifm_change_cb_t)(struct ifnet *); -typedef void (*ifm_stat_cb_t)(struct ifnet *, struct ifmediareq *); /* - * In-kernel representation of a single supported media type. + * Masks */ -struct ifmedia_entry { - TAILQ_ENTRY(ifmedia_entry) ifm_list; - u_int ifm_media; /* description of this media attachment */ - u_int ifm_data; /* for driver-specific use */ - void *ifm_aux; /* for driver-specific use */ -}; +#define IFM_NMASK 0x00e0 /* Network type */ +#define IFM_TMASK 0x001f /* Media sub-type */ +#define IFM_IMASK 0xf000 /* Instance */ +#define IFM_ISHIFT 28 /* Instance shift */ +#define IFM_OMASK 0xff00 /* Type specific options */ +#define IFM_MMASK 0x0007 /* Mode */ +#define IFM_MSHIFT 16 /* Mode shift */ +#define IFM_GMASK 0x0ff0 /* Global options */ /* - * One of these goes into a network interface's softc structure. - * It is used to keep general media state. + * Macros to extract various bits of information from the media word. */ -struct ifmedia { - u_int ifm_mask; /* mask of changes we don't care about */ - u_int ifm_media; /* current user-set media word */ - struct ifmedia_entry *ifm_cur; /* currently selected media */ - TAILQ_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */ - ifm_change_cb_t ifm_change; /* media change driver callback */ - ifm_stat_cb_t ifm_status; /* media status driver callback */ -}; - -/* Initialize an interface's struct if_media field. */ -void ifmedia_init(struct ifmedia *, int, ifm_change_cb_t, ifm_stat_cb_t); - -int ifmedia_change(struct ifmedia *, struct ifnet *); +#define IFM_TYPE(x) ((x) & IFM_NMASK) +#define IFM_SUBTYPE(x) ((x) & IFM_TMASK) +#define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT) +#define IFM_OPTIONS(x) ((x) & (IFM_OMASK | IFM_GMASK)) +#define IFM_MODE(x) ((x) & IFM_MMASK) -/* Add one supported medium to a struct ifmedia. */ -void ifmedia_add(struct ifmedia *, int, int, void *); +#define IFM_TYPE_MATCH(dt, t) \ + (IFM_TYPE((dt)) == 0 || IFM_TYPE((dt)) == IFM_TYPE((t))) -/*
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Fri Jun 30 06:17:51 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_gif.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #58): sys/net/if_gif.c: revision 1.127 I have forgotten to commit this gif(4) MP-ify patch for a long time, sorry. To generate a diff of this commit: cvs rdiff -u -r1.126 -r1.126.2.1 src/sys/net/if_gif.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_gif.c diff -u src/sys/net/if_gif.c:1.126 src/sys/net/if_gif.c:1.126.2.1 --- src/sys/net/if_gif.c:1.126 Thu Jun 1 02:45:14 2017 +++ src/sys/net/if_gif.c Fri Jun 30 06:17:51 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_gif.c,v 1.126 2017/06/01 02:45:14 chs Exp $ */ +/* $NetBSD: if_gif.c,v 1.126.2.1 2017/06/30 06:17:51 snj Exp $ */ /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126 2017/06/01 02:45:14 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.1 2017/06/30 06:17:51 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -608,7 +608,12 @@ gif_input(struct mbuf *m, int af, struct return; } - if (__predict_true(pktq_enqueue(pktq, m, 0))) { +#ifdef GIF_MPSAFE + const u_int h = curcpu()->ci_index; +#else + const uint32_t h = pktq_rps_hash(m); +#endif + if (__predict_true(pktq_enqueue(pktq, m, h))) { ifp->if_ibytes += pktlen; ifp->if_ipackets++; } else {
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Sun Jun 25 06:31:58 UTC 2017 Modified Files: src/sys/net [netbsd-8]: route.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #57): sys/net/route.c: revision 1.195 Fix locking in rtalloc1 (affected only if NET_MPSAFE) To generate a diff of this commit: cvs rdiff -u -r1.194 -r1.194.6.1 src/sys/net/route.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/route.c diff -u src/sys/net/route.c:1.194 src/sys/net/route.c:1.194.6.1 --- src/sys/net/route.c:1.194 Fri Mar 24 03:45:02 2017 +++ src/sys/net/route.c Sun Jun 25 06:31:58 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.194 2017/03/24 03:45:02 ozaki-r Exp $ */ +/* $NetBSD: route.c,v 1.194.6.1 2017/06/25 06:31:58 snj Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194 2017/03/24 03:45:02 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.1 2017/06/25 06:31:58 snj Exp $"); #include #ifdef RTFLUSH_DEBUG @@ -280,7 +280,7 @@ static void rtcache_invalidate(struct do static void rt_ref(struct rtentry *); static struct rtentry * -rtalloc1_locked(const struct sockaddr *, int, bool); +rtalloc1_locked(const struct sockaddr *, int, bool, bool); static struct rtentry * rtcache_validate_locked(struct route *); static void rtcache_free_locked(struct route *); @@ -557,7 +557,8 @@ dump_rt(const struct rtentry *rt) * will be incremented. The caller has to rtfree it by itself. */ struct rtentry * -rtalloc1_locked(const struct sockaddr *dst, int report, bool wait_ok) +rtalloc1_locked(const struct sockaddr *dst, int report, bool wait_ok, +bool wlock) { rtbl_t *rtbl; struct rtentry *rt; @@ -599,6 +600,10 @@ retry: if (need_lock) RTCACHE_WLOCK(); + if (wlock) + RT_WLOCK(); + else + RT_RLOCK(); goto retry; } #endif /* NET_MPSAFE */ @@ -627,7 +632,7 @@ rtalloc1(const struct sockaddr *dst, int struct rtentry *rt; RT_RLOCK(); - rt = rtalloc1_locked(dst, report, true); + rt = rtalloc1_locked(dst, report, true, false); RT_UNLOCK(); return rt; @@ -1026,7 +1031,7 @@ ifa_ifwithroute_psref(int flags, const s /* XXX we cannot call rtalloc1 if holding the rt lock */ if (RT_LOCKED()) - rt = rtalloc1_locked(gateway, 0, true); + rt = rtalloc1_locked(gateway, 0, true, true); else rt = rtalloc1(gateway, 0); if (rt == NULL) @@ -1387,7 +1392,7 @@ rt_setgate(struct rtentry *rt, const str /* XXX we cannot call rtalloc1 if holding the rt lock */ if (RT_LOCKED()) - gwrt = rtalloc1_locked(gate, 1, false); + gwrt = rtalloc1_locked(gate, 1, false, true); else gwrt = rtalloc1(gate, 1); /*
CVS commit: [netbsd-8] src/sys/net
Module Name:src Committed By: snj Date: Wed Jun 21 17:39:24 UTC 2017 Modified Files: src/sys/net [netbsd-8]: if_vlan.c if_vlanvar.h Log Message: Pull up following revision(s) (requested by knakahara in ticket #41): sys/net/if_vlan.c: revision 1.98 sys/net/if_vlanvar.h: revision 1.10 vlan(4) MP-ify. contributed by s-yamaguchi@IIJ, thanks. To generate a diff of this commit: cvs rdiff -u -r1.97 -r1.97.2.1 src/sys/net/if_vlan.c cvs rdiff -u -r1.9 -r1.9.80.1 src/sys/net/if_vlanvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.97 src/sys/net/if_vlan.c:1.97.2.1 --- src/sys/net/if_vlan.c:1.97 Mon May 29 02:55:49 2017 +++ src/sys/net/if_vlan.c Wed Jun 21 17:39:24 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.97 2017/05/29 02:55:49 ozaki-r Exp $ */ +/* $NetBSD: if_vlan.c,v 1.97.2.1 2017/06/21 17:39:24 snj Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97 2017/05/29 02:55:49 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.1 2017/06/21 17:39:24 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -86,6 +86,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v #endif #include +#include #include #include #include @@ -95,6 +96,12 @@ __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v #include #include #include +#include +#include +#include +#include +#include +#include #include #include @@ -116,6 +123,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v #include "ioconf.h" +#ifdef NET_MPSAFE +#define VLAN_MPSAFE 1 +#endif + struct vlan_mc_entry { LIST_ENTRY(vlan_mc_entry) mc_entries; /* @@ -131,21 +142,33 @@ struct vlan_mc_entry { #define mc_enm mc_u.mcu_enm + +struct ifvlan_linkmib { + struct ifvlan *ifvm_ifvlan; + const struct vlan_multisw *ifvm_msw; + int ifvm_encaplen; /* encapsulation length */ + int ifvm_mtufudge; /* MTU fudged by this much */ + int ifvm_mintu; /* min transmission unit */ + uint16_t ifvm_proto; /* encapsulation ethertype */ + uint16_t ifvm_tag; /* tag to apply on packets */ + struct ifnet *ifvm_p; /* parent interface of this vlan */ + + struct psref_target ifvm_psref; +}; + struct ifvlan { union { struct ethercom ifvu_ec; } ifv_u; - struct ifnet *ifv_p; /* parent interface of this vlan */ - struct ifv_linkmib { - const struct vlan_multisw *ifvm_msw; - int ifvm_encaplen; /* encapsulation length */ - int ifvm_mtufudge; /* MTU fudged by this much */ - int ifvm_mintu; /* min transmission unit */ - uint16_t ifvm_proto; /* encapsulation ethertype */ - uint16_t ifvm_tag; /* tag to apply on packets */ - } ifv_mib; + struct ifvlan_linkmib *ifv_mib; /* + * reader must use vlan_getref_linkmib() + * instead of direct dereference + */ + kmutex_t ifv_lock; /* writer lock for ifv_mib */ + LIST_HEAD(__vlan_mchead, vlan_mc_entry) ifv_mc_listhead; LIST_ENTRY(ifvlan) ifv_list; + struct pslist_entry ifv_hash; int ifv_flags; }; @@ -179,15 +202,47 @@ const struct vlan_multisw vlan_ether_mul static int vlan_clone_create(struct if_clone *, int); static int vlan_clone_destroy(struct ifnet *); -static int vlan_config(struct ifvlan *, struct ifnet *); +static int vlan_config(struct ifvlan *, struct ifnet *, +uint16_t); static int vlan_ioctl(struct ifnet *, u_long, void *); static void vlan_start(struct ifnet *); +static int vlan_transmit(struct ifnet *, struct mbuf *); static void vlan_unconfig(struct ifnet *); +static int vlan_unconfig_locked(struct ifvlan *, +struct ifvlan_linkmib *); +static void vlan_hash_init(void); +static int vlan_hash_fini(void); +static struct ifvlan_linkmib* vlan_getref_linkmib(struct ifvlan *, +struct psref *); +static void vlan_putref_linkmib(struct ifvlan_linkmib *, +struct psref *); +static void vlan_linkmib_update(struct ifvlan *, +struct ifvlan_linkmib *); +static struct ifvlan_linkmib* vlan_lookup_tag_psref(struct ifnet *, +uint16_t, struct psref *); +static int tag_hash_func(uint16_t, u_long); + +LIST_HEAD(vlan_ifvlist, ifvlan); +static struct { + kmutex_t lock; + struct vlan_ifvlist list; +} ifv_list __cacheline_aligned; -/* XXX This should be a hash table with the tag as the basis of the key. */ -static LIST_HEAD(, ifvlan) ifv_list; -static kmutex_t ifv_mtx __cacheline_aligned; +#if !defined(VLAN_TAG_HASH_SIZE) +#define VLAN_TAG_HASH_SIZE 32 +#endif +static struct { + kmutex_t lock; + struct pslist_head *lists; + u_long mask; +} ifv_hash __cacheline_aligned = { + .lists = NULL, + .mask = 0, +}; + +pserialize_t vlan_psz __read_mostly; +static struct psref_class *ifvm_psref_class __read_mostly; struct if_clone vlan_cloner = IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy); @@ -208,10 +263,15 @@ vlanattach(int n) static void vlaninit(void) { +