From f723c9f48787cea7734d262afdc442af3bb26d38 Mon Sep 17 00:00:00 2001 From: Michele Marchetto Date: Sat, 1 Nov 2008 16:37:56 +0000 Subject: 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@ --- sys/net/if_mpe.c | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'sys/net/if_mpe.c') 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 @@ -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); -- cgit v1.2.3