CVS commit: src/sys/netmpls
Module Name:src Committed By: maxv Date: Wed Apr 11 06:37:32 UTC 2018 Modified Files: src/sys/netmpls: mpls_ttl.c Log Message: Add one more XXX in the list. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 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.11 src/sys/netmpls/mpls_ttl.c:1.12 --- src/sys/netmpls/mpls_ttl.c:1.11 Fri Jan 19 14:15:35 2018 +++ src/sys/netmpls/mpls_ttl.c Wed Apr 11 06:37:32 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_ttl.c,v 1.11 2018/01/19 14:15:35 maxv Exp $ */ +/* $NetBSD: mpls_ttl.c,v 1.12 2018/04/11 06:37:32 maxv Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.11 2018/01/19 14:15:35 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.12 2018/04/11 06:37:32 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -146,10 +146,12 @@ static struct mbuf *ip4_check(struct mbu /* * Send an ICMP Extended error message. References: RFC4884 and RFC4950. * - * 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. + * XXX: This code is inspired from icmp_error(), and should really be merged + * into it. icmp_error() should handle ICMP Extended error messages. * - * XXX We're not setting the 'length' field of the Extended ICMP header. + * XXX: It is called only for ICMP_TIMXCEED_INTRANS but code is too general. + * + * XXX: We're not setting the 'length' field of the Extended ICMP header. * According to RFC4884, we are in 'non-compliant' mode. Moreover, we're * not computing the checksum of the Extended ICMP header. */
CVS commit: src/sys/netmpls
Module Name:src Committed By: maxv Date: Fri Jan 19 14:15:35 UTC 2018 Modified Files: src/sys/netmpls: mpls_ttl.c Log Message: Add XXX. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 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.10 src/sys/netmpls/mpls_ttl.c:1.11 --- src/sys/netmpls/mpls_ttl.c:1.10 Fri Jan 19 10:54:31 2018 +++ src/sys/netmpls/mpls_ttl.c Fri Jan 19 14:15:35 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_ttl.c,v 1.10 2018/01/19 10:54:31 maxv Exp $ */ +/* $NetBSD: mpls_ttl.c,v 1.11 2018/01/19 14:15:35 maxv Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.10 2018/01/19 10:54:31 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.11 2018/01/19 14:15:35 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -147,7 +147,11 @@ static struct mbuf *ip4_check(struct mbu * Send an ICMP Extended error message. References: RFC4884 and RFC4950. * * 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 + * XXX: is called only for ICMP_TIMXCEED_INTRANS but code is too general. + * + * XXX We're not setting the 'length' field of the Extended ICMP header. + * According to RFC4884, we are in 'non-compliant' mode. Moreover, we're + * not computing the checksum of the Extended ICMP header. */ static void mpls_icmp_error(struct mbuf *n, int type, int code, n_long dest, @@ -162,7 +166,7 @@ mpls_icmp_error(struct mbuf *n, int type memset(_icmp_ext, 0, sizeof(mpls_icmp_ext)); mpls_icmp_ext.cmn_hdr.version = ICMP_EXT_VERSION; - mpls_icmp_ext.cmn_hdr.checksum = 0; + mpls_icmp_ext.cmn_hdr.checksum = 0; /* XXX */ mpls_icmp_ext.obj_hdr.length = htons(sizeof(union mpls_shim) + sizeof(struct icmp_ext_obj_hdr));
CVS commit: src/sys/netmpls
Module Name:src Committed By: joerg Date: Sat Oct 8 20:19:37 UTC 2016 Modified Files: src/sys/netmpls: mpls.h Log Message: Assert size for sockaddr_mpls, but don't require it to be packed. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/netmpls/mpls.h 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.h diff -u src/sys/netmpls/mpls.h:1.1 src/sys/netmpls/mpls.h:1.2 --- src/sys/netmpls/mpls.h:1.1 Sat Jun 26 14:24:28 2010 +++ src/sys/netmpls/mpls.h Sat Oct 8 20:19:37 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls.h,v 1.1 2010/06/26 14:24:28 kefren Exp $ */ +/* $NetBSD: mpls.h,v 1.2 2016/10/08 20:19:37 joerg Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ struct sockaddr_mpls { uint8_t smpls_family; uint8_t smpls_pad[2]; union mpls_shim smpls_addr; -} __packed; - +}; +__CTASSERT(sizeof(struct sockaddr_mpls) == 8); #endif /* !_NETMPLS_MPLS_H_ */
CVS commit: src/sys/netmpls
Module Name:src Committed By: rtr Date: Thu Jul 31 05:37:00 UTC 2014 Modified Files: src/sys/netmpls: mpls_proto.c Log Message: add missing KASSERT(req != PRU_XXX) to mpls_usrreq() for PRUs that have already been split. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/netmpls/mpls_proto.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_proto.c diff -u src/sys/netmpls/mpls_proto.c:1.19 src/sys/netmpls/mpls_proto.c:1.20 --- src/sys/netmpls/mpls_proto.c:1.19 Thu Jul 31 03:39:35 2014 +++ src/sys/netmpls/mpls_proto.c Thu Jul 31 05:37:00 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_proto.c,v 1.19 2014/07/31 03:39:35 rtr Exp $ */ +/* $NetBSD: mpls_proto.c,v 1.20 2014/07/31 05:37:00 rtr Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.19 2014/07/31 03:39:35 rtr Exp $); +__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.20 2014/07/31 05:37:00 rtr Exp $); #include opt_inet.h #include opt_mbuftrace.h @@ -200,6 +200,23 @@ static int mpls_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l) { + + KASSERT(req != PRU_ATTACH); + KASSERT(req != PRU_DETACH); + KASSERT(req != PRU_ACCEPT); + KASSERT(req != PRU_BIND); + KASSERT(req != PRU_LISTEN); + KASSERT(req != PRU_CONNECT); + KASSERT(req != PRU_DISCONNECT); + KASSERT(req != PRU_SHUTDOWN); + KASSERT(req != PRU_ABORT); + KASSERT(req != PRU_CONTROL); + KASSERT(req != PRU_SENSE); + KASSERT(req != PRU_PEERADDR); + KASSERT(req != PRU_SOCKADDR); + KASSERT(req != PRU_RCVOOB); + KASSERT(req != PRU_SENDOOB); + return EOPNOTSUPP; }
CVS commit: src/sys/netmpls
Module Name:src Committed By: rtr Date: Sun Jul 6 04:47:26 UTC 2014 Modified Files: src/sys/netmpls: mpls_proto.c Log Message: * split PRU_SENSE functionality out of mpls_usrreq() and place into separate mpls_stat(struct socket *, struct stat *) function missed this in previous commit, fixes build of ALL kernel. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/netmpls/mpls_proto.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_proto.c diff -u src/sys/netmpls/mpls_proto.c:1.11 src/sys/netmpls/mpls_proto.c:1.12 --- src/sys/netmpls/mpls_proto.c:1.11 Tue Jul 1 05:49:19 2014 +++ src/sys/netmpls/mpls_proto.c Sun Jul 6 04:47:26 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_proto.c,v 1.11 2014/07/01 05:49:19 rtr Exp $ */ +/* $NetBSD: mpls_proto.c,v 1.12 2014/07/06 04:47:26 rtr Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.11 2014/07/01 05:49:19 rtr Exp $); +__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.12 2014/07/06 04:47:26 rtr Exp $); #include opt_inet.h #include opt_mbuftrace.h @@ -101,6 +101,12 @@ mpls_ioctl(struct socket *so, u_long cmd } static int +mpls_stat(struct socket *so, struct stat *ub) +{ + return EOPNOTSUPP; +} + +static int mpls_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l) { @@ -192,12 +198,14 @@ PR_WRAP_USRREQS(mpls) #define mpls_attach mpls_attach_wrapper #define mpls_detach mpls_detach_wrapper #define mpls_ioctl mpls_ioctl_wrapper +#define mpls_stat mpls_stat_wrapper #define mpls_usrreq mpls_usrreq_wrapper static const struct pr_usrreqs mpls_usrreqs = { .pr_attach = mpls_attach, .pr_detach = mpls_detach, .pr_ioctl = mpls_ioctl, + .pr_stat = mpls_stat, .pr_generic = mpls_usrreq, };
CVS commit: src/sys/netmpls
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);
CVS commit: src/sys/netmpls
Module Name:src Committed By: kefren Date: Thu Jul 18 06:23:07 UTC 2013 Modified Files: src/sys/netmpls: mpls_proto.c Log Message: explicitly call sysctl setup in init. Needed for future dynamic loading To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/netmpls/mpls_proto.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_proto.c diff -u src/sys/netmpls/mpls_proto.c:1.3 src/sys/netmpls/mpls_proto.c:1.4 --- src/sys/netmpls/mpls_proto.c:1.3 Wed Feb 1 16:49:36 2012 +++ src/sys/netmpls/mpls_proto.c Thu Jul 18 06:23:07 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_proto.c,v 1.3 2012/02/01 16:49:36 christos Exp $ */ +/* $NetBSD: mpls_proto.c,v 1.4 2013/07/18 06:23:07 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.3 2012/02/01 16:49:36 christos Exp $); +__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.4 2013/07/18 06:23:07 kefren Exp $); #include opt_inet.h #include opt_mbuftrace.h @@ -51,6 +51,7 @@ struct ifqueue mplsintrq; static int mpls_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *); +static void sysctl_net_mpls_setup(struct sysctllog **); #ifdef MBUFTRACE struct mowner mpls_owner = MOWNER_INIT(MPLS, ); @@ -72,6 +73,8 @@ void mpls_init(void) #endif memset(mplsintrq, 0, sizeof(mplsintrq)); mplsintrq.ifq_maxlen = 256; + + sysctl_net_mpls_setup(NULL); } DOMAIN_DEFINE(mplsdomain); @@ -134,7 +137,8 @@ mpls_usrreq(struct socket *so, int req, /* * Sysctl for MPLS variables. */ -SYSCTL_SETUP(sysctl_net_mpls_setup, sysctl net.mpls subtree setup) +static void +sysctl_net_mpls_setup(struct sysctllog **clog) { sysctl_createv(clog, 0, NULL, NULL,
CVS commit: src/sys/netmpls
Module Name:src Committed By: christos Date: Wed Feb 1 16:49:37 UTC 2012 Modified Files: src/sys/netmpls: mpls_proto.c Log Message: old style def To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/netmpls/mpls_proto.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_proto.c diff -u src/sys/netmpls/mpls_proto.c:1.2 src/sys/netmpls/mpls_proto.c:1.3 --- src/sys/netmpls/mpls_proto.c:1.2 Thu Mar 31 15:40:53 2011 +++ src/sys/netmpls/mpls_proto.c Wed Feb 1 11:49:36 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_proto.c,v 1.2 2011/03/31 19:40:53 dyoung Exp $ */ +/* $NetBSD: mpls_proto.c,v 1.3 2012/02/01 16:49:36 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.2 2011/03/31 19:40:53 dyoung Exp $); +__KERNEL_RCSID(0, $NetBSD: mpls_proto.c,v 1.3 2012/02/01 16:49:36 christos Exp $); #include opt_inet.h #include opt_mbuftrace.h @@ -65,7 +65,7 @@ int mpls_accept = 0; int mpls_mapprec_inet = 1; int mpls_mapclass_inet6 = 1; -void mpls_init() +void mpls_init(void) { #ifdef MBUFTRACE MOWNER_ATTACH(mpls_owner);
CVS commit: src/sys/netmpls
Module Name:src Committed By: kefren Date: Mon Jul 5 09:54:26 UTC 2010 Modified Files: src/sys/netmpls: mpls_ttl.c Log Message: do some rudimentary checks on ip4 header before passing packet to mpls_icmp_error To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 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.2 src/sys/netmpls/mpls_ttl.c:1.3 --- src/sys/netmpls/mpls_ttl.c:1.2 Fri Jul 2 12:25:54 2010 +++ src/sys/netmpls/mpls_ttl.c Mon Jul 5 09:54:26 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_ttl.c,v 1.2 2010/07/02 12:25:54 kefren Exp $ */ +/* $NetBSD: mpls_ttl.c,v 1.3 2010/07/05 09:54:26 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.2 2010/07/02 12:25:54 kefren Exp $); +__KERNEL_RCSID(0, $NetBSD: mpls_ttl.c,v 1.3 2010/07/05 09:54:26 kefren Exp $); #include opt_inet.h #include opt_mpls.h @@ -160,10 +160,12 @@ union mpls_shim ms; } __packed; -static void mpls_icmp_error(struct mbuf*, int, int, n_long, int, union mpls_shim *); +static void mpls_icmp_error(struct mbuf *, int, int, n_long, int, + union mpls_shim *); +static bool ip4_check(struct mbuf *); /* - * http://www.ietf.org/proceedings/01aug/I-D/draft-ietf-mpls-icmp-02.txt + * Reference: http://tools.ietf.org/html/rfc4950 * This should be in sync with icmp_error() in sys/netinet/ip_icmp.c */ @@ -326,6 +328,45 @@ } +static bool +ip4_check(struct mbuf *m) +{ + struct ip *iph; + int hlen, len; + + if (m-m_len sizeof(struct ip) + (m = m_pullup(m, sizeof(struct ip))) == NULL) + return false; + + iph = mtod(m, struct ip *); + + if (iph-ip_v != IPVERSION) + goto freeit; + hlen = iph-ip_hl 2; + if (hlen sizeof(struct ip)) + goto freeit; + if (hlen m-m_len) { + if ((m = m_pullup(m, hlen)) == NULL) + return false; + iph = mtod(m, struct ip *); + } + if (IN_MULTICAST(iph-ip_src.s_addr) || + (ntohl(iph-ip_dst.s_addr) IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || + (ntohl(iph-ip_src.s_addr) IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || + in_cksum(m, hlen) != 0) + goto freeit; + + len = ntohs(iph-ip_len); + if (len hlen || m-m_pkthdr.len len) + goto freeit; + + return true; +freeit: + m_freem(m); + return false; + +} + #endif /* INET */ struct mbuf * @@ -368,9 +409,10 @@ bossh.s_addr = ntohl(mtod(m, union mpls_shim *)-s_addr); m_adj(m, sizeof(union mpls_shim)); } - - mpls_icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, - 0, 0, top_shim); + + if (ip4_check(m) == true) + mpls_icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, + 0, 0, top_shim); #else m_freem(m); #endif
CVS commit: src/sys/netmpls
Module Name:src Committed By: kefren Date: Fri Jul 2 12:25:54 UTC 2010 Modified Files: src/sys/netmpls: mpls_ttl.c Log Message: * correct packet size * fix crash when cluster was involved * extension offset is constant * fix endianess issues in BoS loop * free cluster if INET not defined but icmp_respond sysctl != 1 To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 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.1 src/sys/netmpls/mpls_ttl.c:1.2 --- src/sys/netmpls/mpls_ttl.c:1.1 Sat Jun 26 14:24:29 2010 +++ src/sys/netmpls/mpls_ttl.c Fri Jul 2 12:25:54 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_ttl.c,v 1.1 2010/06/26 14:24:29 kefren Exp $ */ +/* $NetBSD: mpls_ttl.c,v 1.2 2010/07/02 12:25:54 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.1 2010/06/26 14:24:29 kefren Exp $); +__KERNEL_RCSID(0, $NetBSD: mpls_ttl.c,v 1.2 2010/07/02 12:25:54 kefren Exp $); #include opt_inet.h #include opt_mpls.h @@ -131,9 +131,8 @@ /* ICMP Extensions */ #define ICMP_EXT_VERSION 2 -#define ICMP_EXT_OFFSET (ICMP_MINLEN + 128) /* 128 bytes from original - * datagram required */ -#define MPLS_ICMP_LEN (ICMP_EXT_OFFSET + sizeof(struct mpls_extension)) +#define MPLS_RETURN_DATA 128 +#define ICMP_EXT_OFFSET 128 struct icmp_ext_cmn_hdr { #if BYTE_ORDER == BIG_ENDIAN @@ -172,12 +171,11 @@ mpls_icmp_error(struct mbuf *n, int type, int code, n_long dest, int destmtu, union mpls_shim *shim) { -struct ip *oip = mtod(n, struct ip *), *nip; -unsigned oiplen = oip-ip_hl 2; -struct icmp *icp; -struct mbuf *m; -unsigned icmplen, mblen; - + struct ip *oip = mtod(n, struct ip *), *nip; + unsigned oiplen = oip-ip_hl 2; + struct icmp *icp; + struct mbuf *m; + unsigned icmplen, mblen, packetlen; struct mpls_extension mpls_icmp_ext; memset(mpls_icmp_ext, 0, sizeof(mpls_icmp_ext)); @@ -238,6 +236,8 @@ mblen += m-m_len; icmplen = min(mblen, icmplen); + packetlen = sizeof(struct ip) + ICMP_EXT_OFFSET + sizeof(mpls_icmp_ext); + /* * As we are not required to return everything we have, * we return whatever we can return at ease. @@ -247,15 +247,10 @@ * icmp_sysctl will keep things below that limit. */ - /* XXX: should we leave this here ? MCLBYTES should be 200 anyway - * XXX: but it's arch dependant after all and let's keep - * XXX: surprises out - */ - KASSERT (MPLS_ICMP_LEN + ICMP_MINLEN = MCLBYTES); + KASSERT (packetlen = MCLBYTES); m = m_gethdr(M_DONTWAIT, MT_HEADER); - /* XXX: MPLS_ICMP_LEN + ICMP_MINLEN should be always MHLEN but ... */ - if (m (MPLS_ICMP_LEN + ICMP_MINLEN MHLEN)) { + if (m (packetlen MHLEN)) { MCLGET(m, M_DONTWAIT); if ((m-m_flags M_EXT) == 0) { m_freem(m); @@ -265,9 +260,13 @@ if (m == NULL) goto freeit; MCLAIM(m, n-m_owner); - m-m_len = MPLS_ICMP_LEN; + 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); + } icp = mtod(m, struct icmp *); if ((u_int)type ICMP_MAXTYPE) panic(icmp error); @@ -290,20 +289,21 @@ } icp-icmp_code = code; - - /* Zero padding in case icmplen ICMP_EXT_OFFSET */ - memset(icp-icmp_ip, 0, MPLS_ICMP_LEN); + + memset(icp-icmp_ip, 0, ICMP_EXT_OFFSET); m_copydata(n, 0, icmplen, (char *)icp-icmp_ip); - /* Copy the extension structures */ - memcpy(((char*)icp-icmp_ip) + ICMP_EXT_OFFSET - ICMP_MINLEN, + /* Append the extension structure */ + memcpy(((char*)icp-icmp_ip) + ICMP_EXT_OFFSET, mpls_icmp_ext, sizeof(mpls_icmp_ext)); /* * Now, copy old ip header (without options) * in front of icmp message. */ - KASSERT(m-m_data - sizeof(struct ip) = m-m_pktdat); + if ((m-m_flags M_EXT) == 0 + m-m_data - sizeof(struct ip) m-m_pktdat) + panic(icmp len); m-m_data -= sizeof(struct ip); m-m_len += sizeof(struct ip); m-m_pkthdr.len = m-m_len; @@ -351,11 +351,11 @@ #ifdef INET /* - * shim ttl exceed + * shim ttl exceeded * send back ICMP type 11 code 0 */ - bossh.s_addr = top_shim.s_addr = - ntohl(mtod(m, union mpls_shim *)-s_addr); + bossh.s_addr = mshim-s_addr; + top_shim.s_addr = htonl(mshim-s_addr); m_adj(m, sizeof(union mpls_shim)); /* Goto BOS */ @@ -371,6 +371,8 @@ mpls_icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, 0, top_shim); +#else + m_freem(m); #endif return NULL; }