From: dlg Date: Tue, 9 Jan 2018 06:24:14 +0000 (+0000) Subject: make mpls_input take a struct ifnet *ifp argument. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5c53b9324545b7febab2dcf52402199d72b231d3;p=openbsd make mpls_input take a struct ifnet *ifp argument. this makes it like all our other protocol family input functions. mpls_input always looks up the interface the mbuf was received on, but it's always called by code that already has a reference to that interface anyway. the result of this is a few less if_get/if_put calls. ok mpi@ bluhm@ visa@ claudio@ --- diff --git a/sys/net/if.c b/sys/net/if.c index 683a78f2414..5dc00bd0340 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.534 2018/01/04 10:48:02 mpi Exp $ */ +/* $OpenBSD: if.c,v 1.535 2018/01/09 06:24:14 dlg Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -756,7 +756,7 @@ if_input_local(struct ifnet *ifp, struct mbuf *m, sa_family_t af) #endif /* INET6 */ #ifdef MPLS case AF_MPLS: - mpls_input(m); + mpls_input(ifp, m); break; #endif /* MPLS */ default: diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index f6376883b54..d562dad36d9 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ethersubr.c,v 1.248 2018/01/04 00:33:54 dlg Exp $ */ +/* $OpenBSD: if_ethersubr.c,v 1.249 2018/01/09 06:24:15 dlg Exp $ */ /* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */ /* @@ -434,7 +434,7 @@ ether_input(struct ifnet *ifp, struct mbuf *m, void *cookie) #ifdef MPLS case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: - mpls_input(m); + mpls_input(ifp, m); return (1); #endif default: diff --git a/sys/netinet/ip_ether.c b/sys/netinet/ip_ether.c index 840f53cec2a..f84a065984f 100644 --- a/sys/netinet/ip_ether.c +++ b/sys/netinet/ip_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ether.c,v 1.97 2017/11/20 10:35:24 mpi Exp $ */ +/* $OpenBSD: ip_ether.c,v 1.98 2018/01/09 06:24:15 dlg Exp $ */ /* * The author of this code is Angelos D. Keromytis (kermit@adk.gr) * @@ -130,7 +130,7 @@ mplsip_decap(struct mbuf *m, int iphlen) pf_pkt_addr_changed(m); #endif - mpls_input(m); + mpls_input(&sc->gif_if, m); } struct gif_softc * diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 1f56bd09119..0dba2339b21 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.68 2017/11/20 10:35:24 mpi Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.69 2018/01/09 06:24:15 dlg Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -175,7 +175,7 @@ gre_input2(struct mbuf *m, int hlen, int proto) #ifdef MPLS case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: - mpls_input(m); + mpls_input(&sc->sc_if, m); return (1); #endif default: /* others not yet supported */ diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h index b5971dd71fc..a0962dd98ad 100644 --- a/sys/netmpls/mpls.h +++ b/sys/netmpls/mpls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls.h,v 1.37 2017/02/28 07:07:07 claudio Exp $ */ +/* $OpenBSD: mpls.h,v 1.38 2018/01/09 06:24:15 dlg Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -185,6 +185,6 @@ struct mbuf *mpls_shim_push(struct mbuf *, struct rt_mpls *); int mpls_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); -void mpls_input(struct mbuf *); +void mpls_input(struct ifnet *, struct mbuf *); #endif /* _KERNEL */ diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index 1a470a61f7b..34fe7314d83 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_input.c,v 1.65 2017/12/08 22:10:34 bluhm Exp $ */ +/* $OpenBSD: mpls_input.c,v 1.66 2018/01/09 06:24:15 dlg Exp $ */ /* * Copyright (c) 2008 Claudio Jeker @@ -53,58 +53,46 @@ struct mbuf *mpls_ip6_adjttl(struct mbuf *, u_int8_t); struct mbuf *mpls_do_error(struct mbuf *, int, int, int); void -mpls_input(struct mbuf *m) +mpls_input(struct ifnet *ifp, struct mbuf *m) { struct sockaddr_mpls *smpls; struct sockaddr_mpls sa_mpls; struct shim_hdr *shim; struct rtentry *rt; struct rt_mpls *rt_mpls; - struct ifnet *ifp; - u_int8_t ttl; + uint8_t ttl; int hasbos; - if ((ifp = if_get(m->m_pkthdr.ph_ifidx)) == NULL || - !ISSET(ifp->if_xflags, IFXF_MPLS)) { - m_freem(m); - if_put(ifp); - return; - } - /* drop all broadcast and multicast packets */ if (m->m_flags & (M_BCAST | M_MCAST)) { m_freem(m); - if_put(ifp); return; } - if (m->m_len < sizeof(*shim)) - if ((m = m_pullup(m, sizeof(*shim))) == NULL) { - if_put(ifp); + if (m->m_len < sizeof(*shim)) { + m = m_pullup(m, sizeof(*shim)); + if (m == NULL) return; - } + } shim = mtod(m, struct shim_hdr *); #ifdef MPLS_DEBUG - printf("mpls_input: iface %d label=%d, ttl=%d BoS %d\n", - m->m_pkthdr.ph_ifidx, MPLS_LABEL_GET(shim->shim_label), - MPLS_TTL_GET(shim->shim_label), - MPLS_BOS_ISSET(shim->shim_label)); + printf("mpls_input: iface %s label=%d, ttl=%d BoS %d\n", + ifp->if_xname, MPLS_LABEL_GET(shim->shim_label), ttls, hasbos); #endif /* check and decrement TTL */ - ttl = ntohl(shim->shim_label & MPLS_TTL_MASK); - if (ttl-- <= 1) { + if (--ttl == 0) { /* TTL exceeded */ m = mpls_do_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0); - if (m == NULL) { - if_put(ifp); + if (m == NULL) return; - } + shim = mtod(m, struct shim_hdr *); ttl = ntohl(shim->shim_label & MPLS_TTL_MASK); } + hasbos = MPLS_BOS_ISSET(shim->shim_label); bzero(&sa_mpls, sizeof(sa_mpls)); smpls = &sa_mpls; @@ -112,14 +100,10 @@ mpls_input(struct mbuf *m) smpls->smpls_len = sizeof(*smpls); smpls->smpls_label = shim->shim_label & MPLS_LABEL_MASK; - hasbos = MPLS_BOS_ISSET(shim->shim_label); - if (ntohl(smpls->smpls_label) < MPLS_LABEL_RESERVED_MAX) { m = mpls_shim_pop(m); - if (m == NULL) { - if_put(ifp); + if (m == NULL) return; - } if (!hasbos) { /* * RFC 4182 relaxes the position of the @@ -135,30 +119,22 @@ mpls_input(struct mbuf *m) switch (ntohl(smpls->smpls_label)) { case MPLS_LABEL_IPV4NULL: do_v4: - if ((m = mpls_ip_adjttl(m, ttl)) == NULL) { - if_put(ifp); + if ((m = mpls_ip_adjttl(m, ttl)) == NULL) return; - } ipv4_input(ifp, m); - if_put(ifp); return; #ifdef INET6 case MPLS_LABEL_IPV6NULL: do_v6: - if ((m = mpls_ip6_adjttl(m, ttl)) == NULL) { - if_put(ifp); + if ((m = mpls_ip6_adjttl(m, ttl)) == NULL) return; - } ipv6_input(ifp, m); - if_put(ifp); return; #endif /* INET6 */ case MPLS_LABEL_IMPLNULL: if (m->m_len < sizeof(u_char) && - (m = m_pullup(m, sizeof(u_char))) == NULL) { - if_put(ifp); + (m = m_pullup(m, sizeof(u_char))) == NULL) return; - } switch (*mtod(m, u_char *) >> 4) { case IPVERSION: goto do_v4; @@ -168,18 +144,16 @@ do_v6: #endif default: m_freem(m); - if_put(ifp); return; } default: /* Other cases are not handled for now */ m_freem(m); - if_put(ifp); return; } } } - if_put(ifp); + ifp = NULL; rt = rtalloc(smplstosa(smpls), RT_RESOLVE, m->m_pkthdr.ph_rtableid);