diff options
author | 2015-07-29 00:04:03 +0000 | |
---|---|---|
committer | 2015-07-29 00:04:03 +0000 | |
commit | da955d8e79dbdc19f4b008e28eb56dcbe9198b22 (patch) | |
tree | 157f907d339e9abecd7b795d47017f507dd77d63 /sys | |
parent | refine a comment (diff) | |
download | wireguard-openbsd-da955d8e79dbdc19f4b008e28eb56dcbe9198b22.tar.xz wireguard-openbsd-da955d8e79dbdc19f4b008e28eb56dcbe9198b22.zip |
Don't use mpls_input() as input handler anymore and instead call it
directly. Also protect non mp-safe functions while at it.
ok mpi@.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if.c | 11 | ||||
-rw-r--r-- | sys/net/if_ethersubr.c | 10 | ||||
-rw-r--r-- | sys/net/if_loop.c | 15 | ||||
-rw-r--r-- | sys/netinet/ip_ether.c | 14 | ||||
-rw-r--r-- | sys/netinet/ip_gre.c | 17 | ||||
-rw-r--r-- | sys/netmpls/mpls.h | 5 | ||||
-rw-r--r-- | sys/netmpls/mpls_input.c | 74 |
7 files changed, 43 insertions, 103 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index fe97a1f3937..a0e23d64d45 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.355 2015/07/21 04:21:50 jca Exp $ */ +/* $OpenBSD: if.c,v 1.356 2015/07/29 00:04:03 rzalamena Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -630,9 +630,6 @@ if_detach(struct ifnet *ifp) #ifdef INET6 in6_ifdetach(ifp); #endif -#ifdef MPLS - mpls_uninstall_handler(ifp); -#endif /* MPLS */ #if NPF > 0 pfi_detach_ifnet(ifp); #endif @@ -1400,11 +1397,6 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) if (ISSET(ifr->ifr_flags, IFXF_MPLS) && !ISSET(ifp->if_xflags, IFXF_MPLS)) { s = splnet(); - if (mpls_install_handler(ifp) != 0) { - splx(s); - return (ENOMEM); - } - ifp->if_xflags |= IFXF_MPLS; ifp->if_ll_output = ifp->if_output; ifp->if_output = mpls_output; @@ -1416,7 +1408,6 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) ifp->if_xflags &= ~IFXF_MPLS; ifp->if_output = ifp->if_ll_output; ifp->if_ll_output = NULL; - mpls_uninstall_handler(ifp); splx(s); } #endif /* MPLS */ diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 6cbbce3b309..f7845beeb80 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ethersubr.c,v 1.220 2015/07/20 21:16:39 rzalamena Exp $ */ +/* $OpenBSD: if_ethersubr.c,v 1.221 2015/07/29 00:04:03 rzalamena Exp $ */ /* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */ /* @@ -412,12 +412,8 @@ decapsulate: #ifdef MPLS case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: - /* Let's call mpls_input() handler. */ - if (ifp->if_xflags & IFXF_MPLS) - return (0); - - /* Otherwise this packet has nowhere to go. */ - goto dropanyway; + mpls_input(ifp, m); + return (1); #endif default: if (llcfound || etype > ETHERMTU) diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index af6dab6d508..7b2bae1005f 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_loop.c,v 1.69 2015/07/21 02:46:54 mpi Exp $ */ +/* $OpenBSD: if_loop.c,v 1.70 2015/07/29 00:04:03 rzalamena Exp $ */ /* $NetBSD: if_loop.c,v 1.15 1996/05/07 02:40:33 thorpej Exp $ */ /* @@ -204,9 +204,6 @@ looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) { struct niqueue *ifq = NULL; -#ifdef MPLS - struct mbuf_list ml = MBUF_LIST_INITIALIZER(); -#endif /* MPLS */ if ((m->m_flags & M_PKTHDR) == 0) panic("looutput: no header mbuf"); @@ -241,13 +238,9 @@ looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, #endif /* INET6 */ #ifdef MPLS case AF_MPLS: - if ((ifp->if_xflags & IFXF_MPLS) == 0) { - m_freem(m); - return (EINVAL); - } - - ml_enqueue(&ml, m); - if_input(ifp, &ml); + ifp->if_ipackets++; + ifp->if_ibytes += m->m_pkthdr.len; + mpls_input(ifp, m); return (0); #endif /* MPLS */ default: diff --git a/sys/netinet/ip_ether.c b/sys/netinet/ip_ether.c index f006628fc89..5f4cb7f2562 100644 --- a/sys/netinet/ip_ether.c +++ b/sys/netinet/ip_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ether.c,v 1.76 2015/07/20 21:16:39 rzalamena Exp $ */ +/* $OpenBSD: ip_ether.c,v 1.77 2015/07/29 00:04:03 rzalamena Exp $ */ /* * The author of this code is Angelos D. Keromytis (kermit@adk.gr) * @@ -266,9 +266,11 @@ void mplsip_decap(struct mbuf *m, int iphlen) { struct gif_softc *sc; - int s; - struct mbuf_list ml = MBUF_LIST_INITIALIZER(); + /* + * Avoid going through all the code if the interface doesn't have + * the appropriate flag. + */ if ((sc->gif_if.if_xflags & IFXF_MPLS) == 0) { m_freem(m); return; @@ -321,11 +323,7 @@ mplsip_decap(struct mbuf *m, int iphlen) pf_pkt_addr_changed(m); #endif - ml_enqueue(&ml, m); - - s = splnet(); - if_input(&sc->gif_if, &ml); - splx(s); + mpls_input(&sc->gif_if, m); } #endif diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 7d348a66c17..65055d2cce6 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.56 2015/07/20 21:16:39 rzalamena Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.57 2015/07/29 00:04:03 rzalamena Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -97,8 +97,6 @@ gre_input2(struct mbuf *m, int hlen, u_char proto) struct gre_softc *sc; u_short flags; u_int af; - int s; - struct mbuf_list ml = MBUF_LIST_INITIALIZER(); if ((sc = gre_lookup(m, proto)) == NULL) { /* No matching tunnel or tunnel is down. */ @@ -180,17 +178,8 @@ gre_input2(struct mbuf *m, int hlen, u_char proto) #ifdef MPLS case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: - if ((sc->sc_if.if_xflags & IFXF_MPLS) == 0) { - m_freem(m); - return (0); - } - - ml_enqueue(&ml, m); - - s = splnet(); - if_input(&sc->sc_if, &ml); - splx(s); - return (0); + mpls_input(&sc->sc_if, m); + return (1); #endif default: /* others not yet supported */ return (0); diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h index 07231e0df47..ed71f6cbd18 100644 --- a/sys/netmpls/mpls.h +++ b/sys/netmpls/mpls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls.h,v 1.33 2015/07/20 22:16:41 rzalamena Exp $ */ +/* $OpenBSD: mpls.h,v 1.34 2015/07/29 00:04:03 rzalamena Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -191,7 +191,6 @@ struct mbuf *mpls_shim_push(struct mbuf *, struct rt_mpls *); int mpls_sysctl(int *, u_int, void *, size_t *, void *, size_t); int mpls_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); -int mpls_install_handler(struct ifnet *); -void mpls_uninstall_handler(struct ifnet *); +void mpls_input(struct ifnet *, struct mbuf *); #endif /* _KERNEL */ diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index d1aa4ca2922..2ae6cb7b9fc 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_input.c,v 1.46 2015/07/20 22:16:41 rzalamena Exp $ */ +/* $OpenBSD: mpls_input.c,v 1.47 2015/07/29 00:04:03 rzalamena Exp $ */ /* * Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org> @@ -51,54 +51,13 @@ int mpls_ip6_adjttl(struct mbuf *, u_int8_t); #endif struct mbuf *mpls_do_error(struct mbuf *, int, int, int); -int mpls_input(struct ifnet *, struct mbuf *); void mpls_init(void) { } -int -mpls_install_handler(struct ifnet *ifp) -{ - struct ifih *ifih, *ifihn; - - ifih = malloc(sizeof(*ifih), M_DEVBUF, M_ZERO | M_NOWAIT); - if (ifih == NULL) - return (-1); - - ifih->ifih_input = mpls_input; - - /* We must install mpls_input() after ether_input(). */ - SLIST_FOREACH(ifihn, &ifp->if_inputs, ifih_next) - if (SLIST_NEXT(ifihn, ifih_next) == NULL) - break; - - if (ifihn == NULL) - SLIST_INSERT_HEAD(&ifp->if_inputs, ifih, ifih_next); - else - SLIST_INSERT_AFTER(ifihn, ifih, ifih_next); - - return (0); -} - void -mpls_uninstall_handler(struct ifnet *ifp) -{ - struct ifih *ifih; - - SLIST_FOREACH(ifih, &ifp->if_inputs, ifih_next) { - if (ifih->ifih_input != mpls_input) - continue; - - SLIST_REMOVE(&ifp->if_inputs, ifih, ifih, ifih_next); - break; - } - - free(ifih, M_DEVBUF, sizeof(*ifih)); -} - -int mpls_input(struct ifnet *ifp, struct mbuf *m) { struct sockaddr_mpls *smpls; @@ -111,18 +70,18 @@ mpls_input(struct ifnet *ifp, struct mbuf *m) if (!ISSET(ifp->if_xflags, IFXF_MPLS)) { m_freem(m); - return (1); + return; } /* drop all broadcast and multicast packets */ if (m->m_flags & (M_BCAST | M_MCAST)) { m_freem(m); - return (1); + return; } if (m->m_len < sizeof(*shim)) if ((m = m_pullup(m, sizeof(*shim))) == NULL) - return (1); + return; shim = mtod(m, struct shim_hdr *); @@ -139,7 +98,7 @@ mpls_input(struct ifnet *ifp, struct mbuf *m) /* TTL exceeded */ m = mpls_do_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0); if (m == NULL) - return (1); + return; shim = mtod(m, struct shim_hdr *); ttl = ntohl(shim->shim_label & MPLS_TTL_MASK); } @@ -211,7 +170,9 @@ do_v6: } } + KERNEL_LOCK(); rt = rtalloc(smplstosa(smpls), RT_REPORT|RT_RESOLVE, 0); + KERNEL_UNLOCK(); if (rt == NULL) { /* no entry for this label */ #ifdef MPLS_DEBUG @@ -330,7 +291,9 @@ do_v6: if (ifp != NULL && rt_mpls->mpls_operation != MPLS_OP_LOCAL) break; + KERNEL_LOCK(); rtfree(rt); + KERNEL_UNLOCK(); rt = NULL; } @@ -357,12 +320,15 @@ do_v6: goto done; } + KERNEL_LOCK(); (*ifp->if_ll_output)(ifp, m, smplstosa(smpls), rt); + KERNEL_UNLOCK(); done: - if (rt) + if (rt) { + KERNEL_LOCK(); rtfree(rt); - - return (1); + KERNEL_UNLOCK(); + } } int @@ -462,7 +428,9 @@ mpls_do_error(struct mbuf *m, int type, int code, int destmtu) smpls->smpls_len = sizeof(*smpls); smpls->smpls_label = shim->shim_label & MPLS_LABEL_MASK; + KERNEL_LOCK(); rt = rtalloc(smplstosa(smpls), RT_REPORT|RT_RESOLVE, 0); + KERNEL_UNLOCK(); if (rt == NULL) { /* no entry for this label */ m_freem(m); @@ -475,14 +443,20 @@ mpls_do_error(struct mbuf *m, int type, int code, int destmtu) * less interface we need to find some other IP to * use as source. */ + KERNEL_LOCK(); rtfree(rt); + KERNEL_UNLOCK(); m_freem(m); return (NULL); } rt->rt_use++; + KERNEL_LOCK(); rtfree(rt); - if (icmp_reflect(m, NULL, ia)) + if (icmp_reflect(m, NULL, ia)) { + KERNEL_UNLOCK(); return (NULL); + } + KERNEL_UNLOCK(); ip = mtod(m, struct ip *); /* stuff to fix up which is normaly done in ip_output */ |