diff options
author | 2008-05-08 03:18:39 +0000 | |
---|---|---|
committer | 2008-05-08 03:18:39 +0000 | |
commit | 3b0a60838d710043f0125f33dac960bd68df6fab (patch) | |
tree | 0054bb5b8d5a39d86866846c7b8aab575caa65b7 | |
parent | Receiving carp packets for unknown vhid's is not really an error. (diff) | |
download | wireguard-openbsd-3b0a60838d710043f0125f33dac960bd68df6fab.tar.xz wireguard-openbsd-3b0a60838d710043f0125f33dac960bd68df6fab.zip |
Hook mpe(4) correctly into mpls so that it is possible to tunnel packets over
MPLS. Still a bit hackish but getting closer. hai norby@
-rw-r--r-- | sys/net/if_mpe.c | 30 | ||||
-rw-r--r-- | sys/netmpls/mpls.h | 5 | ||||
-rw-r--r-- | sys/netmpls/mpls_input.c | 22 |
3 files changed, 29 insertions, 28 deletions
diff --git a/sys/net/if_mpe.c b/sys/net/if_mpe.c index 348e9ed0d99..29c0370cefe 100644 --- a/sys/net/if_mpe.c +++ b/sys/net/if_mpe.c @@ -152,6 +152,15 @@ mpeoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, int error; error = 0; + /* + * drop MPLS packets entering here. This is a hack to prevent + * loops because of misconfiguration. + */ + if (dst->sa_family == AF_MPLS) { + m_freem(m); + error = ENETUNREACH; + return (error); + } s = splnet(); IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error); if (error) { @@ -232,26 +241,13 @@ mpeioctl(struct ifnet *ifp, u_long cmd, caddr_t data) } void -mpe_input(struct mbuf *m) +mpe_input(struct mbuf *m, struct ifnet *ifp, struct sockaddr_mpls *smpls, + u_int32_t ttl) { int s; - struct shim_hdr *shim; - shim = mtod(m, struct shim_hdr *); - if (!(MPLS_BOS_ISSET(shim->shim_label))) { -#ifdef MPLS_DEBUG - printf("mpe_input: invalid packet with non BoS label\n"); -#endif - m_free(m); - return; - } - - -#ifdef MPLS_DEBUG - printf("mpe_input: got packet with label: %d\n", - ((ntohl(shim->shim_label & MPLS_LABEL_MASK)) >> MPLS_LABEL_OFFSET)); -#endif - m_adj(m, sizeof(shim)); + /* fixup ttl */ + /* label -> AF lookup */ s = splnet(); /* diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h index 45185c8bc46..fed04276ba1 100644 --- a/sys/netmpls/mpls.h +++ b/sys/netmpls/mpls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls.h,v 1.8 2008/05/07 08:00:50 pyr Exp $ */ +/* $OpenBSD: mpls.h,v 1.9 2008/05/08 03:18:39 claudio Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -152,7 +152,8 @@ struct mpe_softc { #define MPE_MTU_MIN 256 #define MPE_MTU_MAX 8192 -void mpe_input(struct mbuf *); +void mpe_input(struct mbuf *, struct ifnet *, struct sockaddr_mpls *, + u_int32_t); extern int mpls_raw_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *); diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index 9081b2f6339..7bf6519e669 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_input.c,v 1.10 2008/05/06 13:33:50 pyr Exp $ */ +/* $OpenBSD: mpls_input.c,v 1.11 2008/05/08 03:18:39 claudio Exp $ */ /* * Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org> @@ -22,6 +22,7 @@ #include <sys/socket.h> #include <net/if.h> +#include <net/if_types.h> #include <net/route.h> #include <netmpls/mpls.h> @@ -71,7 +72,7 @@ mpls_input(struct mbuf *m) struct shim_hdr *shim; struct rtentry *rt = NULL; u_int32_t ttl; - int i; + int i, hasbos; if (!mpls_enable) { m_freem(m); @@ -111,13 +112,6 @@ mpls_input(struct mbuf *m) ttl = htonl(ttl - 1); for (i = 0; i < mpls_inkloop; i++) { - /* XXX maybe this should be done later */ - if (MPLS_BOS_ISSET(shim->shim_label)) { - /* no LER until now */ - m_freem(m); - goto done; - } - bzero(&sa_mpls, sizeof(sa_mpls)); smpls = &sa_mpls; smpls->smpls_family = AF_MPLS; @@ -156,7 +150,17 @@ mpls_input(struct mbuf *m) switch (smpls->smpls_operation) { case MPLS_OP_POP: + hasbos = MPLS_BOS_ISSET(shim->shim_label); m = mpls_shim_pop(m); + if (hasbos) { + if (rt->rt_ifp->if_type == IFT_MPLS) { + mpe_input(m, rt->rt_ifp, smpls, ttl); + goto done; + } + /* last label but we have no clue so drop */ + m_freem(m); + goto done; + } break; case MPLS_OP_PUSH: m = mpls_shim_push(m, smpls); |