Re: make mpls_input take struct ifnet *ifp as an argument

2018-01-09 Thread bijan
(forwarded from misc@) Hi, while reading the changes in OpenBSD source 
code (hopefully to learn more), I've notice the usage of Uninitialized 
variable. Looks like the latest commit unintentionally removed the 
assignment line (sorry for the github link):


https://github.com/openbsd/src/commit/5c53b9324545b7febab2dcf52402199d72b231d3?diff=split#diff-3efc580dfa272b2173162f5950c92484R86 



The following should bring back (the possibly) unwanted change.s Hope it 
helps unless I missed something



diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c
index 34fe7314d..fff3564c8 100644
--- a/sys/netmpls/mpls_input.c
+++ b/sys/netmpls/mpls_input.c
@@ -76,13 +76,15 @@ mpls_input(struct ifnet *ifp, struct mbuf *m)
}

shim = mtod(m, struct shim_hdr *);
-
 #ifdef MPLS_DEBUG
printf("mpls_input: iface %s label=%d, ttl=%d BoS %d\n",
-   ifp->if_xname, MPLS_LABEL_GET(shim->shim_label), ttls, hasbos);
+   ifp->if_xname, MPLS_LABEL_GET(shim->shim_label),
+   MPLS_LABEL_GET(shim->shim_label),
+   MPLS_BOS_ISSET(shim->shim_label));
 #endif

/* check and decrement TTL */
+   ttl = MPLS_LABEL_GET(shim->shim_label);
if (--ttl == 0) {
/* TTL exceeded */
m = mpls_do_error(m, ICMP_TIMXCEED, 
ICMP_TIMXCEED_INTRANS, 0);




Re: make mpls_input take struct ifnet *ifp as an argument

2018-01-08 Thread Claudio Jeker
On Mon, Jan 08, 2018 at 11:50:54AM +0100, Alexander Bluhm wrote:
> On Mon, Jan 08, 2018 at 11:49:05AM +1000, David Gwynne wrote:
> > 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?
> 
> OK bluhm@

This is also fine by me.

As a simple test setup I would use static mpls routes. Need to dig out the
commands to do that easily.
 
> > 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.c4 Jan 2018 10:48:02 -   1.534
> > +++ net/if.c8 Jan 2018 01:43:50 -
> > @@ -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 -   1.248
> > +++ net/if_ethersubr.c  8 Jan 2018 01:43:50 -
> > @@ -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 -  1.97
> > +++ netinet/ip_ether.c  8 Jan 2018 01:43:50 -
> > @@ -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.c20 Nov 2017 10:35:24 -  1.68
> > +++ netinet/ip_gre.c8 Jan 2018 01:43:50 -
> > @@ -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 -  1.37
> > +++ netmpls/mpls.h  8 Jan 2018 01:43:50 -
> > @@ -185,6 +185,6 @@ struct mbuf *mpls_shim_push(struct mbuf 
> >  
> >  int mpls_output(struct ifnet *, struct mbuf *, struct 
> > sockaddr *,
> > struct rtentry *);
> > -voidmpls_input(struct mbuf *);
> > +voidmpls_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.c8 Dec 2017 22:10:34 -   1.65
> > +++ netmpls/mpls_input.c8 Jan 2018 01:43:50 -
> > @@ -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

Re: make mpls_input take struct ifnet *ifp as an argument

2018-01-08 Thread Alexander Bluhm
On Mon, Jan 08, 2018 at 11:49:05AM +1000, David Gwynne wrote:
> 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?

OK bluhm@

> 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 -   1.534
> +++ net/if.c  8 Jan 2018 01:43:50 -
> @@ -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.c4 Jan 2018 00:33:54 -   1.248
> +++ net/if_ethersubr.c8 Jan 2018 01:43:50 -
> @@ -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.c20 Nov 2017 10:35:24 -  1.97
> +++ netinet/ip_ether.c8 Jan 2018 01:43:50 -
> @@ -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 -  1.68
> +++ netinet/ip_gre.c  8 Jan 2018 01:43:50 -
> @@ -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.h28 Feb 2017 07:07:07 -  1.37
> +++ netmpls/mpls.h8 Jan 2018 01:43:50 -
> @@ -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 -   1.65
> +++ netmpls/mpls_input.c  8 Jan 2018 01:43:50 -
> @@ -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;
> -  

make mpls_input take struct ifnet *ifp as an argument

2018-01-07 Thread David Gwynne
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.c4 Jan 2018 10:48:02 -   1.534
+++ net/if.c8 Jan 2018 01:43:50 -
@@ -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 -   1.248
+++ net/if_ethersubr.c  8 Jan 2018 01:43:50 -
@@ -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 -  1.97
+++ netinet/ip_ether.c  8 Jan 2018 01:43:50 -
@@ -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.c20 Nov 2017 10:35:24 -  1.68
+++ netinet/ip_gre.c8 Jan 2018 01:43:50 -
@@ -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 -  1.37
+++ netmpls/mpls.h  8 Jan 2018 01:43:50 -
@@ -185,6 +185,6 @@ struct mbuf *mpls_shim_push(struct mbuf 
 
 int mpls_output(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
-voidmpls_input(struct mbuf *);
+voidmpls_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.c8 Dec 2017 22:10:34 -   1.65
+++ netmpls/mpls_input.c8 Jan 2018 01:43:50 -
@@ -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);
-