summaryrefslogtreecommitdiff
path: root/sys/net/if_mpe.c
diff options
context:
space:
mode:
authorMichele Marchetto <michele@cvs.openbsd.org>2008-11-01 16:37:56 +0000
committerMichele Marchetto <michele@cvs.openbsd.org>2008-11-01 16:37:56 +0000
commitf723c9f48787cea7734d262afdc442af3bb26d38 (patch)
tree1fa67bae3f7963de2b83ce699ba4e25c66163a53 /sys/net/if_mpe.c
parent80e890cd112608c6aca701f2a0ecf679ae37e447 (diff)
Introduced Uniform Model for TTL handling.
MPLS TTL is mapped into network layer one as the packet exits the LSP. Just IPv4 support for now. Added the relevant sysctls to enable this behaviour. Input and OK claudio@
Diffstat (limited to 'sys/net/if_mpe.c')
-rw-r--r--sys/net/if_mpe.c45
1 files changed, 38 insertions, 7 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);