diff options
author | Rafael Zalamena <rzalamena@cvs.openbsd.org> | 2015-07-20 21:16:40 +0000 |
---|---|---|
committer | Rafael Zalamena <rzalamena@cvs.openbsd.org> | 2015-07-20 21:16:40 +0000 |
commit | 503147628815fcec50bad05550b4c514ac7913ef (patch) | |
tree | 12dc83617bbe043e03891a99fb8a66c23863a917 /sys | |
parent | a8178caf97ea6e5635f5b12dac868a8a543917c6 (diff) |
Kill NETISR_MPLS, from now on we will use interface input handlers to deal
with MPLS packets.
ok mpi@, claudio@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if.c | 12 | ||||
-rw-r--r-- | sys/net/if_ethersubr.c | 10 | ||||
-rw-r--r-- | sys/net/if_loop.c | 17 | ||||
-rw-r--r-- | sys/net/netisr.c | 4 | ||||
-rw-r--r-- | sys/net/netisr.h | 4 | ||||
-rw-r--r-- | sys/netinet/ip_ether.c | 18 | ||||
-rw-r--r-- | sys/netinet/ip_gre.c | 18 | ||||
-rw-r--r-- | sys/netmpls/mpls.h | 8 | ||||
-rw-r--r-- | sys/netmpls/mpls_input.c | 66 | ||||
-rw-r--r-- | sys/netmpls/mpls_raw.c | 7 |
10 files changed, 108 insertions, 56 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index 76ff37080cc..03f1a5ee259 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.352 2015/07/18 16:10:03 mpi Exp $ */ +/* $OpenBSD: if.c,v 1.353 2015/07/20 21:16:39 rzalamena Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -632,7 +632,9 @@ 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,6 +1402,11 @@ 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; @@ -1411,6 +1418,7 @@ 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 c86a6314c79..6cbbce3b309 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ethersubr.c,v 1.219 2015/07/18 00:25:06 claudio Exp $ */ +/* $OpenBSD: if_ethersubr.c,v 1.220 2015/07/20 21:16:39 rzalamena Exp $ */ /* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */ /* @@ -412,8 +412,12 @@ decapsulate: #ifdef MPLS case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: - inq = &mplsintrq; - break; + /* Let's call mpls_input() handler. */ + if (ifp->if_xflags & IFXF_MPLS) + return (0); + + /* Otherwise this packet has nowhere to go. */ + goto dropanyway; #endif default: if (llcfound || etype > ETHERMTU) diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index d7cd01898f8..cda152065ad 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_loop.c,v 1.66 2015/06/16 11:09:39 mpi Exp $ */ +/* $OpenBSD: if_loop.c,v 1.67 2015/07/20 21:16:39 rzalamena Exp $ */ /* $NetBSD: if_loop.c,v 1.15 1996/05/07 02:40:33 thorpej Exp $ */ /* @@ -204,6 +204,8 @@ looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) { struct niqueue *ifq = NULL; + struct mbuf_list ml = MBUF_LIST_INITIALIZER(); + int s; if ((m->m_flags & M_PKTHDR) == 0) panic("looutput: no header mbuf"); @@ -238,8 +240,17 @@ looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, #endif /* INET6 */ #ifdef MPLS case AF_MPLS: - ifq = &mplsintrq; - break; + if ((ifp->if_xflags & IFXF_MPLS) == 0) { + m_freem(m); + return (EINVAL); + } + + ml_enqueue(&ml, m); + + s = splnet(); + if_input(ifp, &ml); + splx(s); + return (0); #endif /* MPLS */ default: printf("%s: can't handle af%d\n", ifp->if_xname, diff --git a/sys/net/netisr.c b/sys/net/netisr.c index 27c88a83d90..7ec073f76e1 100644 --- a/sys/net/netisr.c +++ b/sys/net/netisr.c @@ -49,10 +49,6 @@ netintr(void *unused) /* ARGSUSED */ if (n & (1 << NETISR_IPV6)) ip6intr(); #endif -#ifdef MPLS - if (n & (1 << NETISR_MPLS)) - mplsintr(); -#endif #if NPPP > 0 if (n & (1 << NETISR_PPP)) pppintr(); diff --git a/sys/net/netisr.h b/sys/net/netisr.h index 5aba72daa11..23373f03ac0 100644 --- a/sys/net/netisr.h +++ b/sys/net/netisr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netisr.h,v 1.41 2015/05/26 11:36:26 dlg Exp $ */ +/* $OpenBSD: netisr.h,v 1.42 2015/07/20 21:16:39 rzalamena Exp $ */ /* $NetBSD: netisr.h,v 1.12 1995/08/12 23:59:24 mycroft Exp $ */ /* @@ -52,7 +52,6 @@ */ #define NETISR_IP 2 /* same as AF_INET */ #define NETISR_TX 3 /* for if_snd processing */ -#define NETISR_MPLS 4 /* AF_MPLS would overflow */ #define NETISR_PFSYNC 5 /* for pfsync "immediate" tx */ #define NETISR_ARP 18 /* same as AF_LINK */ #define NETISR_IPV6 24 /* same as AF_INET6 */ @@ -72,7 +71,6 @@ void ip6intr(void); void pppintr(void); void bridgeintr(void); void pppoeintr(void); -void mplsintr(void); void pfsyncintr(void); #include <machine/atomic.h> diff --git a/sys/netinet/ip_ether.c b/sys/netinet/ip_ether.c index 9ddc3c81387..f006628fc89 100644 --- a/sys/netinet/ip_ether.c +++ b/sys/netinet/ip_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ether.c,v 1.75 2015/07/15 17:33:48 deraadt Exp $ */ +/* $OpenBSD: ip_ether.c,v 1.76 2015/07/20 21:16:39 rzalamena Exp $ */ /* * The author of this code is Angelos D. Keromytis (kermit@adk.gr) * @@ -266,6 +266,13 @@ void mplsip_decap(struct mbuf *m, int iphlen) { struct gif_softc *sc; + int s; + struct mbuf_list ml = MBUF_LIST_INITIALIZER(); + + if ((sc->gif_if.if_xflags & IFXF_MPLS) == 0) { + m_freem(m); + return; + } etheripstat.etherip_ipackets++; @@ -314,12 +321,11 @@ mplsip_decap(struct mbuf *m, int iphlen) pf_pkt_addr_changed(m); #endif - if (niq_enqueue(&mplsintrq, m) != 0) { - etheripstat.etherip_qfull++; + ml_enqueue(&ml, m); - DPRINTF(("mplsip_input(): packet dropped because of full " - "queue\n")); - } + s = splnet(); + if_input(&sc->gif_if, &ml); + splx(s); } #endif diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index e8ead454a10..7d348a66c17 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.55 2015/06/16 11:09:40 mpi Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.56 2015/07/20 21:16:39 rzalamena Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -97,6 +97,8 @@ 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. */ @@ -178,9 +180,17 @@ gre_input2(struct mbuf *m, int hlen, u_char proto) #ifdef MPLS case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: - ifq = &mplsintrq; - af = AF_MPLS; - break; + 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); #endif default: /* others not yet supported */ return (0); diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h index fa06237bd7b..a49e3ada76e 100644 --- a/sys/netmpls/mpls.h +++ b/sys/netmpls/mpls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls.h,v 1.31 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: mpls.h,v 1.32 2015/07/20 21:16:39 rzalamena Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -107,7 +107,6 @@ struct rt_mpls { */ #define MPLSCTL_ENABLE 1 #define MPLSCTL_DEFTTL 2 -#define MPLSCTL_IFQUEUE 3 #define MPLSCTL_MAXINKLOOP 4 #define MPLSCTL_MAPTTL_IP 5 #define MPLSCTL_MAPTTL_IP6 6 @@ -160,7 +159,6 @@ void mpe_input6(struct mbuf *, struct ifnet *, struct sockaddr_mpls *, extern int mpls_raw_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); -extern struct niqueue mplsintrq; /* MPLS input queue */ extern int mpls_defttl; extern int mpls_mapttl_ip; extern int mpls_mapttl_ip6; @@ -168,15 +166,15 @@ extern int mpls_inkloop; void mpls_init(void); -void mplsintr(void); struct mbuf *mpls_shim_pop(struct mbuf *); struct mbuf *mpls_shim_swap(struct mbuf *, struct rt_mpls *); struct mbuf *mpls_shim_push(struct mbuf *, struct rt_mpls *); int mpls_sysctl(int *, u_int, void *, size_t *, void *, size_t); -void mpls_input(struct mbuf *); int mpls_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); +int mpls_install_handler(struct ifnet *); +void mpls_uninstall_handler(struct ifnet *); #endif /* _KERNEL */ diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index 622442a79b4..ff87587f8e6 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_input.c,v 1.44 2015/06/16 11:09:40 mpi Exp $ */ +/* $OpenBSD: mpls_input.c,v 1.45 2015/07/20 21:16:39 rzalamena Exp $ */ /* * Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org> @@ -40,8 +40,6 @@ #include <netmpls/mpls.h> -struct niqueue mplsintrq = NIQUEUE_INITIALIZER(IFQ_MAXLEN, NETISR_MPLS); - #ifdef MPLS_DEBUG #define MPLS_LABEL_GET(l) ((ntohl((l) & MPLS_LABEL_MASK)) >> MPLS_LABEL_OFFSET) #define MPLS_TTL_GET(l) (ntohl((l) & MPLS_TTL_MASK)) @@ -53,31 +51,56 @@ 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 -mplsintr(void) +mpls_uninstall_handler(struct ifnet *ifp) { - struct mbuf *m; + struct ifih *ifih; - /* Get next datagram of input queue */ - while ((m = niq_dequeue(&mplsintrq)) != NULL) { -#ifdef DIAGNOSTIC - if ((m->m_flags & M_PKTHDR) == 0) - panic("mplsintr no HDR"); -#endif - mpls_input(m); + 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)); } -void -mpls_input(struct mbuf *m) +int +mpls_input(struct ifnet *ifp, struct mbuf *m) { - struct ifnet *ifp; struct sockaddr_mpls *smpls; struct sockaddr_mpls sa_mpls; struct shim_hdr *shim; @@ -86,21 +109,20 @@ mpls_input(struct mbuf *m) u_int8_t ttl; int i, hasbos; - ifp = if_get(m->m_pkthdr.ph_ifidx); - if (ifp == NULL || !ISSET(ifp->if_xflags, IFXF_MPLS)) { + if (!ISSET(ifp->if_xflags, IFXF_MPLS)) { m_freem(m); - return; + return (1); } /* drop all broadcast and multicast packets */ if (m->m_flags & (M_BCAST | M_MCAST)) { m_freem(m); - return; + return (1); } if (m->m_len < sizeof(*shim)) if ((m = m_pullup(m, sizeof(*shim))) == NULL) - return; + return (1); shim = mtod(m, struct shim_hdr *); @@ -117,7 +139,7 @@ mpls_input(struct mbuf *m) /* TTL exceeded */ m = mpls_do_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0); if (m == NULL) - return; + return (1); shim = mtod(m, struct shim_hdr *); ttl = ntohl(shim->shim_label & MPLS_TTL_MASK); } @@ -334,6 +356,8 @@ do_v6: done: if (rt) rtfree(rt); + + return (1); } int diff --git a/sys/netmpls/mpls_raw.c b/sys/netmpls/mpls_raw.c index a3165155f4c..e980902ec6a 100644 --- a/sys/netmpls/mpls_raw.c +++ b/sys/netmpls/mpls_raw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_raw.c,v 1.11 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: mpls_raw.c,v 1.12 2015/07/20 21:16:39 rzalamena Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -130,13 +130,10 @@ mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, return (EOPNOTSUPP); /* Almost all sysctl names at this level are terminal. */ - if (namelen != 1 && name[0] != MPLSCTL_IFQUEUE) + if (namelen != 1) return (ENOTDIR); switch (name[0]) { - case MPLSCTL_IFQUEUE: - return (sysctl_niq(name + 1, namelen - 1, - oldp, oldlenp, newp, newlen, &mplsintrq)); default: return sysctl_int_arr(mplsctl_vars, name, namelen, oldp, oldlenp, newp, newlen); |