i want this so it makes mpls_input have the same function signature
as all the other protocol input functions we care about.

it also helps mpls_input because it looks up the interface the mpls
packet was received on, but it's always called by the interface
that the packet was receieved on.

on a related note, does anyone have an opinion on what a representative
mpls test setup looks like?

anyway, ok?

Index: net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.534
diff -u -p -r1.534 if.c
--- net/if.c    4 Jan 2018 10:48:02 -0000       1.534
+++ net/if.c    8 Jan 2018 01:43:50 -0000
@@ -756,7 +756,7 @@ if_input_local(struct ifnet *ifp, struct
 #endif /* INET6 */
 #ifdef MPLS
        case AF_MPLS:
-               mpls_input(m);
+               mpls_input(ifp, m);
                break;
 #endif /* MPLS */
        default:
Index: net/if_ethersubr.c
===================================================================
RCS file: /cvs/src/sys/net/if_ethersubr.c,v
retrieving revision 1.248
diff -u -p -r1.248 if_ethersubr.c
--- net/if_ethersubr.c  4 Jan 2018 00:33:54 -0000       1.248
+++ net/if_ethersubr.c  8 Jan 2018 01:43:50 -0000
@@ -434,7 +434,7 @@ ether_input(struct ifnet *ifp, struct mb
 #ifdef MPLS
        case ETHERTYPE_MPLS:
        case ETHERTYPE_MPLS_MCAST:
-               mpls_input(m);
+               mpls_input(ifp, m);
                return (1);
 #endif
        default:
Index: netinet/ip_ether.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_ether.c,v
retrieving revision 1.97
diff -u -p -r1.97 ip_ether.c
--- netinet/ip_ether.c  20 Nov 2017 10:35:24 -0000      1.97
+++ netinet/ip_ether.c  8 Jan 2018 01:43:50 -0000
@@ -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 *
Index: netinet/ip_gre.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_gre.c,v
retrieving revision 1.68
diff -u -p -r1.68 ip_gre.c
--- netinet/ip_gre.c    20 Nov 2017 10:35:24 -0000      1.68
+++ netinet/ip_gre.c    8 Jan 2018 01:43:50 -0000
@@ -175,7 +175,7 @@ gre_input2(struct mbuf *m, int hlen, int
 #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 */
Index: netmpls/mpls.h
===================================================================
RCS file: /cvs/src/sys/netmpls/mpls.h,v
retrieving revision 1.37
diff -u -p -r1.37 mpls.h
--- netmpls/mpls.h      28 Feb 2017 07:07:07 -0000      1.37
+++ netmpls/mpls.h      8 Jan 2018 01:43:50 -0000
@@ -185,6 +185,6 @@ struct mbuf *mpls_shim_push(struct mbuf 
 
 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 */
Index: netmpls/mpls_input.c
===================================================================
RCS file: /cvs/src/sys/netmpls/mpls_input.c,v
retrieving revision 1.65
diff -u -p -r1.65 mpls_input.c
--- netmpls/mpls_input.c        8 Dec 2017 22:10:34 -0000       1.65
+++ netmpls/mpls_input.c        8 Jan 2018 01:43:50 -0000
@@ -53,36 +53,32 @@ struct mbuf *mpls_ip6_adjttl(struct mbuf
 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;
        int hasbos;
 
-       if ((ifp = if_get(m->m_pkthdr.ph_ifidx)) == NULL ||
-           !ISSET(ifp->if_xflags, IFXF_MPLS)) {
+       if (!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 *);
 
@@ -98,10 +94,9 @@ mpls_input(struct mbuf *m)
        if (ttl-- <= 1) {
                /* 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);
        }
@@ -116,10 +111,8 @@ mpls_input(struct mbuf *m)
 
        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 +128,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 +153,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);

Reply via email to