Module Name: src Committed By: kefren Date: Wed Aug 7 06:55:00 UTC 2013
Modified Files: src/sys/netmpls: mpls_ttl.c Log Message: reserve space for ICMP header accordingly to RFC4884 To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/netmpls/mpls_ttl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netmpls/mpls_ttl.c diff -u src/sys/netmpls/mpls_ttl.c:1.3 src/sys/netmpls/mpls_ttl.c:1.4 --- src/sys/netmpls/mpls_ttl.c:1.3 Mon Jul 5 09:54:26 2010 +++ src/sys/netmpls/mpls_ttl.c Wed Aug 7 06:55:00 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_ttl.c,v 1.3 2010/07/05 09:54:26 kefren Exp $ */ +/* $NetBSD: mpls_ttl.c,v 1.4 2013/08/07 06:55:00 kefren Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -97,7 +97,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.3 2010/07/05 09:54:26 kefren Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.4 2013/08/07 06:55:00 kefren Exp $"); #include "opt_inet.h" #include "opt_mpls.h" @@ -165,8 +165,9 @@ static void mpls_icmp_error(struct mbuf static bool ip4_check(struct mbuf *); /* - * Reference: http://tools.ietf.org/html/rfc4950 + * References: RFC 4884 and RFC 4950 * This should be in sync with icmp_error() in sys/netinet/ip_icmp.c + * XXX: is called only for ICMP_TIMXCEED_INTRANS but code is too general */ static void @@ -238,7 +239,8 @@ mpls_icmp_error(struct mbuf *n, int type mblen += m->m_len; icmplen = min(mblen, icmplen); - packetlen = sizeof(struct ip) + ICMP_EXT_OFFSET + sizeof(mpls_icmp_ext); + packetlen = sizeof(struct ip) + offsetof(struct icmp, icmp_ip) + + ICMP_EXT_OFFSET + sizeof(mpls_icmp_ext); /* * As we are not required to return everything we have, @@ -265,13 +267,12 @@ mpls_icmp_error(struct mbuf *n, int type m->m_len = packetlen; if ((m->m_flags & M_EXT) == 0) MH_ALIGN(m, m->m_len); - else { - m->m_data += sizeof(struct ip); - m->m_len -= sizeof(struct ip); - } + m->m_data += sizeof(struct ip); + m->m_len -= sizeof(struct ip); + icp = mtod(m, struct icmp *); if ((u_int)type > ICMP_MAXTYPE) - panic("icmp error"); + panic("icmp error (mpls_ttl)"); ICMP_STATINC(ICMP_STAT_OUTHIST + type); icp->icmp_type = type; if (type == ICMP_REDIRECT) @@ -377,8 +378,8 @@ mpls_ttl_dec(struct mbuf *m) union mpls_shim top_shim, bossh; #endif - if (m->m_len < sizeof(union mpls_shim) && - (m = m_pullup(m, sizeof(union mpls_shim))) == NULL) + if (__predict_false(m->m_len < sizeof(union mpls_shim) && + (m = m_pullup(m, sizeof(union mpls_shim))) == NULL)) return NULL; mshim = mtod(m, union mpls_shim *); mshim->s_addr = ntohl(mshim->s_addr);