summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/net/if_mpe.c45
-rw-r--r--sys/netmpls/mpls.h14
-rw-r--r--sys/netmpls/mpls_input.c10
-rw-r--r--sys/netmpls/mpls_raw.c4
4 files changed, 55 insertions, 18 deletions
diff --git a/sys/net/if_mpe.c b/sys/net/if_mpe.c
index 20f21292570..7915f861813 100644
--- a/sys/net/if_mpe.c
+++ b/sys/net/if_mpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_mpe.c,v 1.12 2008/10/28 01:16:14 michele Exp $ */
+/* $OpenBSD: if_mpe.c,v 1.13 2008/11/01 16:37:55 michele Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -69,6 +69,9 @@ LIST_HEAD(, mpe_softc) mpeif_list;
struct if_clone mpe_cloner =
IF_CLONE_INITIALIZER("mpe", mpe_clone_create, mpe_clone_destroy);
+extern int mpls_mapttl_ip;
+extern int mpls_mapttl_ip6;
+
void
mpeattach(int nmpe)
{
@@ -277,12 +280,37 @@ mpeioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
void
mpe_input(struct mbuf *m, struct ifnet *ifp, struct sockaddr_mpls *smpls,
- u_int32_t ttl)
+ u_int8_t ttl)
{
- int s;
+ struct ip *ip;
+ int s, hlen;
- /* fixup ttl */
/* label -> AF lookup */
+
+ if (mpls_mapttl_ip) {
+ if (m->m_len < sizeof (struct ip) &&
+ (m = m_pullup(m, sizeof(struct ip))) == NULL)
+ return;
+ ip = mtod(m, struct ip *);
+ hlen = ip->ip_hl << 2;
+ if (m->m_len < hlen) {
+ if ((m = m_pullup(m, hlen)) == NULL)
+ return;
+ ip = mtod(m, struct ip *);
+ }
+
+ if (in_cksum(m, hlen) != 0) {
+ m_free(m);
+ return;
+ }
+
+ /* set IP ttl from MPLS ttl */
+ ip->ip_ttl = ttl;
+
+ /* recalculate checksum */
+ ip->ip_sum = 0;
+ ip->ip_sum = in_cksum(m, hlen);
+ }
#if NBPFILTER > 0
if (ifp && ifp->if_bpf)
@@ -296,13 +324,16 @@ mpe_input(struct mbuf *m, struct ifnet *ifp, struct sockaddr_mpls *smpls,
void
mpe_input6(struct mbuf *m, struct ifnet *ifp, struct sockaddr_mpls *smpls,
- u_int32_t ttl)
+ u_int8_t ttl)
{
int s;
- /* fixup ttl */
/* label -> AF lookup */
-
+
+ if (mpls_mapttl_ip6) {
+ /* XXX: fixup IPv6 ttl */
+ }
+
#if NBPFILTER > 0
if (ifp && ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT);
diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h
index 7b4b464d642..03017c9b63c 100644
--- a/sys/netmpls/mpls.h
+++ b/sys/netmpls/mpls.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls.h,v 1.13 2008/10/28 01:16:14 michele Exp $ */
+/* $OpenBSD: mpls.h,v 1.14 2008/11/01 16:37:55 michele Exp $ */
/*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@@ -116,7 +116,9 @@ struct sockaddr_mpls {
#define MPLSCTL_DEFTTL 2
#define MPLSCTL_IFQUEUE 3
#define MPLSCTL_MAXINKLOOP 4
-#define MPLSCTL_MAXID 5
+#define MPLSCTL_MAPTTL_IP 5
+#define MPLSCTL_MAPTTL_IP6 6
+#define MPLSCTL_MAXID 7
#define MPLSCTL_NAMES { \
{ 0, 0 }, \
@@ -124,6 +126,8 @@ struct sockaddr_mpls {
{ "ttl", CTLTYPE_INT }, \
{ "ifq", CTLTYPE_NODE },\
{ "maxloop_inkernel", CTLTYPE_INT }, \
+ { "mapttl_ip", CTLTYPE_INT }, \
+ { "mapttl_ip6", CTLTYPE_INT }, \
}
#define MPLSCTL_VARS { \
@@ -132,6 +136,8 @@ struct sockaddr_mpls {
&mpls_defttl, \
0, \
&mpls_inkloop, \
+ &mpls_mapttl_ip, \
+ &mpls_mapttl_ip6, \
}
#endif
@@ -151,9 +157,9 @@ struct mpe_softc {
#define MPE_MTU_MAX 8192
void mpe_input(struct mbuf *, struct ifnet *, struct sockaddr_mpls *,
- u_int32_t);
+ u_int8_t);
void mpe_input6(struct mbuf *, struct ifnet *, struct sockaddr_mpls *,
- u_int32_t);
+ u_int8_t);
extern int mpls_raw_usrreq(struct socket *, int, struct mbuf *,
struct mbuf *, struct mbuf *, struct proc *);
diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c
index 39ff4c621b6..e267fd9ea1b 100644
--- a/sys/netmpls/mpls_input.c
+++ b/sys/netmpls/mpls_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_input.c,v 1.14 2008/10/14 20:43:33 michele Exp $ */
+/* $OpenBSD: mpls_input.c,v 1.15 2008/11/01 16:37:55 michele Exp $ */
/*
* Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org>
@@ -71,9 +71,9 @@ mpls_input(struct mbuf *m)
struct ifnet *ifp = m->m_pkthdr.rcvif;
struct sockaddr_mpls *smpls;
struct sockaddr_mpls sa_mpls;
- struct shim_hdr *shim;
+ struct shim_hdr *shim;
struct rtentry *rt = NULL;
- u_int32_t ttl;
+ u_int8_t ttl;
int i, hasbos;
if (!mpls_enable) {
@@ -111,7 +111,7 @@ mpls_input(struct mbuf *m)
m_freem(m);
return;
}
- ttl = htonl(ttl - 1);
+ ttl--;
for (i = 0; i < mpls_inkloop; i++) {
bzero(&sa_mpls, sizeof(sa_mpls));
@@ -219,7 +219,7 @@ mpls_input(struct mbuf *m)
}
/* write back TTL */
- shim->shim_label = (shim->shim_label & ~MPLS_TTL_MASK) | ttl;
+ shim->shim_label = (shim->shim_label & ~MPLS_TTL_MASK) | htonl(ttl);
#ifdef MPLS_DEBUG
printf("MPLS: sending on %s outlabel %x dst af %d in %d out %d\n",
diff --git a/sys/netmpls/mpls_raw.c b/sys/netmpls/mpls_raw.c
index 1f3257cb7ab..2350afe652d 100644
--- a/sys/netmpls/mpls_raw.c
+++ b/sys/netmpls/mpls_raw.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_raw.c,v 1.3 2008/05/23 16:03:03 thib Exp $ */
+/* $OpenBSD: mpls_raw.c,v 1.4 2008/11/01 16:37:55 michele Exp $ */
/*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@@ -129,7 +129,7 @@ mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
size_t newlen)
{
if (name[0] >= MPLSCTL_MAXID)
- return EOPNOTSUPP;
+ return (EOPNOTSUPP);
/* Almost all sysctl names at this level are terminal. */
if (namelen != 1 && name[0] != MPLSCTL_IFQUEUE)