mpls_ttl.c revision 1.2.2.2 1 1.2.2.2 rmind /* $NetBSD: mpls_ttl.c,v 1.2.2.2 2010/07/03 01:20:00 rmind Exp $ */
2 1.2.2.2 rmind
3 1.2.2.2 rmind /*
4 1.2.2.2 rmind * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 1.2.2.2 rmind * All rights reserved.
6 1.2.2.2 rmind *
7 1.2.2.2 rmind * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 rmind * modification, are permitted provided that the following conditions
9 1.2.2.2 rmind * are met:
10 1.2.2.2 rmind * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 rmind * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 rmind * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 rmind * documentation and/or other materials provided with the distribution.
15 1.2.2.2 rmind * 3. Neither the name of the project nor the names of its contributors
16 1.2.2.2 rmind * may be used to endorse or promote products derived from this software
17 1.2.2.2 rmind * without specific prior written permission.
18 1.2.2.2 rmind *
19 1.2.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 1.2.2.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.2.2.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.2.2.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 1.2.2.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.2.2.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.2.2.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2.2.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2.2.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2.2.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2.2.2 rmind * SUCH DAMAGE.
30 1.2.2.2 rmind */
31 1.2.2.2 rmind
32 1.2.2.2 rmind /*-
33 1.2.2.2 rmind * Copyright (c) 2010 The NetBSD Foundation, Inc.
34 1.2.2.2 rmind * All rights reserved.
35 1.2.2.2 rmind *
36 1.2.2.2 rmind * This code is derived from software contributed to The NetBSD Foundation
37 1.2.2.2 rmind * by Public Access Networks Corporation ("Panix"). It was developed under
38 1.2.2.2 rmind * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon.
39 1.2.2.2 rmind *
40 1.2.2.2 rmind * This code is derived from software contributed to The NetBSD Foundation
41 1.2.2.2 rmind * by Jason R. Thorpe of Zembu Labs, Inc.
42 1.2.2.2 rmind *
43 1.2.2.2 rmind * This code is derived from software contributed to The NetBSD Foundation
44 1.2.2.2 rmind * by Mihai Chelaru <kefren (at) NetBSD.org>
45 1.2.2.2 rmind *
46 1.2.2.2 rmind * Redistribution and use in source and binary forms, with or without
47 1.2.2.2 rmind * modification, are permitted provided that the following conditions
48 1.2.2.2 rmind * are met:
49 1.2.2.2 rmind * 1. Redistributions of source code must retain the above copyright
50 1.2.2.2 rmind * notice, this list of conditions and the following disclaimer.
51 1.2.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
52 1.2.2.2 rmind * notice, this list of conditions and the following disclaimer in the
53 1.2.2.2 rmind * documentation and/or other materials provided with the distribution.
54 1.2.2.2 rmind *
55 1.2.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
56 1.2.2.2 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 1.2.2.2 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 1.2.2.2 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
59 1.2.2.2 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 1.2.2.2 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 1.2.2.2 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 1.2.2.2 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 1.2.2.2 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 1.2.2.2 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 1.2.2.2 rmind * POSSIBILITY OF SUCH DAMAGE.
66 1.2.2.2 rmind */
67 1.2.2.2 rmind
68 1.2.2.2 rmind /*
69 1.2.2.2 rmind * Copyright (c) 1982, 1986, 1988, 1993
70 1.2.2.2 rmind * The Regents of the University of California. All rights reserved.
71 1.2.2.2 rmind *
72 1.2.2.2 rmind * Redistribution and use in source and binary forms, with or without
73 1.2.2.2 rmind * modification, are permitted provided that the following conditions
74 1.2.2.2 rmind * are met:
75 1.2.2.2 rmind * 1. Redistributions of source code must retain the above copyright
76 1.2.2.2 rmind * notice, this list of conditions and the following disclaimer.
77 1.2.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
78 1.2.2.2 rmind * notice, this list of conditions and the following disclaimer in the
79 1.2.2.2 rmind * documentation and/or other materials provided with the distribution.
80 1.2.2.2 rmind * 3. Neither the name of the University nor the names of its contributors
81 1.2.2.2 rmind * may be used to endorse or promote products derived from this software
82 1.2.2.2 rmind * without specific prior written permission.
83 1.2.2.2 rmind *
84 1.2.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
85 1.2.2.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86 1.2.2.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87 1.2.2.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
88 1.2.2.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89 1.2.2.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
90 1.2.2.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91 1.2.2.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
92 1.2.2.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93 1.2.2.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 1.2.2.2 rmind * SUCH DAMAGE.
95 1.2.2.2 rmind *
96 1.2.2.2 rmind * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94
97 1.2.2.2 rmind */
98 1.2.2.2 rmind
99 1.2.2.2 rmind #include <sys/cdefs.h>
100 1.2.2.2 rmind __KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.2.2.2 2010/07/03 01:20:00 rmind Exp $");
101 1.2.2.2 rmind
102 1.2.2.2 rmind #include "opt_inet.h"
103 1.2.2.2 rmind #include "opt_mpls.h"
104 1.2.2.2 rmind
105 1.2.2.2 rmind #include <sys/param.h>
106 1.2.2.2 rmind #include <sys/malloc.h>
107 1.2.2.2 rmind #include <sys/mbuf.h>
108 1.2.2.2 rmind #include <sys/errno.h>
109 1.2.2.2 rmind #include <sys/socket.h>
110 1.2.2.2 rmind #include <sys/systm.h>
111 1.2.2.2 rmind
112 1.2.2.2 rmind #include <net/if.h>
113 1.2.2.2 rmind #include <net/if_dl.h>
114 1.2.2.2 rmind #include <net/route.h>
115 1.2.2.2 rmind
116 1.2.2.2 rmind #include <netinet/in.h>
117 1.2.2.2 rmind #include <netinet/in_systm.h>
118 1.2.2.2 rmind #include <netinet/ip.h>
119 1.2.2.2 rmind #include <netinet/ip_icmp.h>
120 1.2.2.2 rmind #include <netinet/icmp_private.h>
121 1.2.2.2 rmind #include <netinet/icmp_var.h>
122 1.2.2.2 rmind
123 1.2.2.2 rmind #include <netmpls/mpls.h>
124 1.2.2.2 rmind #include <netmpls/mpls_var.h>
125 1.2.2.2 rmind
126 1.2.2.2 rmind #ifdef INET
127 1.2.2.2 rmind
128 1.2.2.2 rmind /* in netinet/ip_icmp.c */
129 1.2.2.2 rmind extern int icmpreturndatabytes;
130 1.2.2.2 rmind
131 1.2.2.2 rmind /* ICMP Extensions */
132 1.2.2.2 rmind
133 1.2.2.2 rmind #define ICMP_EXT_VERSION 2
134 1.2.2.2 rmind #define MPLS_RETURN_DATA 128
135 1.2.2.2 rmind #define ICMP_EXT_OFFSET 128
136 1.2.2.2 rmind
137 1.2.2.2 rmind struct icmp_ext_cmn_hdr {
138 1.2.2.2 rmind #if BYTE_ORDER == BIG_ENDIAN
139 1.2.2.2 rmind unsigned char version:4;
140 1.2.2.2 rmind unsigned char reserved1:4;
141 1.2.2.2 rmind #else
142 1.2.2.2 rmind unsigned char reserved1:4;
143 1.2.2.2 rmind unsigned char version:4;
144 1.2.2.2 rmind #endif
145 1.2.2.2 rmind unsigned char reserved2;
146 1.2.2.2 rmind unsigned short checksum;
147 1.2.2.2 rmind };
148 1.2.2.2 rmind
149 1.2.2.2 rmind struct icmp_ext_obj_hdr {
150 1.2.2.2 rmind u_short length;
151 1.2.2.2 rmind u_char class_num;
152 1.2.2.2 rmind #define MPLS_STACK_ENTRY_CLASS 1
153 1.2.2.2 rmind u_char c_type;
154 1.2.2.2 rmind #define MPLS_STACK_ENTRY_C_TYPE 1
155 1.2.2.2 rmind };
156 1.2.2.2 rmind
157 1.2.2.2 rmind struct mpls_extension {
158 1.2.2.2 rmind struct icmp_ext_cmn_hdr cmn_hdr;
159 1.2.2.2 rmind struct icmp_ext_obj_hdr obj_hdr;
160 1.2.2.2 rmind union mpls_shim ms;
161 1.2.2.2 rmind } __packed;
162 1.2.2.2 rmind
163 1.2.2.2 rmind static void mpls_icmp_error(struct mbuf*, int, int, n_long, int, union mpls_shim *);
164 1.2.2.2 rmind
165 1.2.2.2 rmind /*
166 1.2.2.2 rmind * http://www.ietf.org/proceedings/01aug/I-D/draft-ietf-mpls-icmp-02.txt
167 1.2.2.2 rmind * This should be in sync with icmp_error() in sys/netinet/ip_icmp.c
168 1.2.2.2 rmind */
169 1.2.2.2 rmind
170 1.2.2.2 rmind static void
171 1.2.2.2 rmind mpls_icmp_error(struct mbuf *n, int type, int code, n_long dest,
172 1.2.2.2 rmind int destmtu, union mpls_shim *shim)
173 1.2.2.2 rmind {
174 1.2.2.2 rmind struct ip *oip = mtod(n, struct ip *), *nip;
175 1.2.2.2 rmind unsigned oiplen = oip->ip_hl << 2;
176 1.2.2.2 rmind struct icmp *icp;
177 1.2.2.2 rmind struct mbuf *m;
178 1.2.2.2 rmind unsigned icmplen, mblen, packetlen;
179 1.2.2.2 rmind struct mpls_extension mpls_icmp_ext;
180 1.2.2.2 rmind
181 1.2.2.2 rmind memset(&mpls_icmp_ext, 0, sizeof(mpls_icmp_ext));
182 1.2.2.2 rmind mpls_icmp_ext.cmn_hdr.version = ICMP_EXT_VERSION;
183 1.2.2.2 rmind mpls_icmp_ext.cmn_hdr.checksum = 0;
184 1.2.2.2 rmind
185 1.2.2.2 rmind mpls_icmp_ext.obj_hdr.length = htons(sizeof(union mpls_shim) +
186 1.2.2.2 rmind sizeof(struct icmp_ext_obj_hdr));
187 1.2.2.2 rmind mpls_icmp_ext.obj_hdr.class_num = MPLS_STACK_ENTRY_CLASS;
188 1.2.2.2 rmind mpls_icmp_ext.obj_hdr.c_type = MPLS_STACK_ENTRY_C_TYPE;
189 1.2.2.2 rmind
190 1.2.2.2 rmind mpls_icmp_ext.ms.s_addr = shim->s_addr;
191 1.2.2.2 rmind
192 1.2.2.2 rmind #ifdef ICMPPRINTFS
193 1.2.2.2 rmind if (icmpprintfs)
194 1.2.2.2 rmind printf("mpls_icmp_error(%p, type:%d, code:%d)\n", oip, type,
195 1.2.2.2 rmind code);
196 1.2.2.2 rmind #endif
197 1.2.2.2 rmind if (type != ICMP_REDIRECT)
198 1.2.2.2 rmind ICMP_STATINC(ICMP_STAT_ERROR);
199 1.2.2.2 rmind /*
200 1.2.2.2 rmind * Don't send error if the original packet was encrypted.
201 1.2.2.2 rmind * Don't send error if not the first fragment of message.
202 1.2.2.2 rmind * Don't error if the old packet protocol was ICMP
203 1.2.2.2 rmind * error message, only known informational types.
204 1.2.2.2 rmind */
205 1.2.2.2 rmind if (n->m_flags & M_DECRYPTED)
206 1.2.2.2 rmind goto freeit;
207 1.2.2.2 rmind if (oip->ip_off &~ htons(IP_MF|IP_DF))
208 1.2.2.2 rmind goto freeit;
209 1.2.2.2 rmind if (oip->ip_p == IPPROTO_ICMP && type != ICMP_REDIRECT &&
210 1.2.2.2 rmind n->m_len >= oiplen + ICMP_MINLEN &&
211 1.2.2.2 rmind !ICMP_INFOTYPE(((struct icmp *)((char *)oip + oiplen))->icmp_type))
212 1.2.2.2 rmind {
213 1.2.2.2 rmind ICMP_STATINC(ICMP_STAT_OLDICMP);
214 1.2.2.2 rmind goto freeit;
215 1.2.2.2 rmind }
216 1.2.2.2 rmind /* Don't send error in response to a multicast or broadcast packet */
217 1.2.2.2 rmind if (n->m_flags & (M_BCAST|M_MCAST))
218 1.2.2.2 rmind goto freeit;
219 1.2.2.2 rmind
220 1.2.2.2 rmind /*
221 1.2.2.2 rmind * First, do a rate limitation check.
222 1.2.2.2 rmind */
223 1.2.2.2 rmind if (icmp_ratelimit(&oip->ip_src, type, code))
224 1.2.2.2 rmind /* XXX stats */
225 1.2.2.2 rmind goto freeit;
226 1.2.2.2 rmind
227 1.2.2.2 rmind /*
228 1.2.2.2 rmind * Now, formulate icmp message
229 1.2.2.2 rmind */
230 1.2.2.2 rmind icmplen = min(ICMP_EXT_OFFSET, ntohs(oip->ip_len));
231 1.2.2.2 rmind /*
232 1.2.2.2 rmind * Defend against mbuf chains shorter than oip->ip_len - oiplen:
233 1.2.2.2 rmind */
234 1.2.2.2 rmind mblen = 0;
235 1.2.2.2 rmind for (m = n; m && (mblen < icmplen); m = m->m_next)
236 1.2.2.2 rmind mblen += m->m_len;
237 1.2.2.2 rmind icmplen = min(mblen, icmplen);
238 1.2.2.2 rmind
239 1.2.2.2 rmind packetlen = sizeof(struct ip) + ICMP_EXT_OFFSET + sizeof(mpls_icmp_ext);
240 1.2.2.2 rmind
241 1.2.2.2 rmind /*
242 1.2.2.2 rmind * As we are not required to return everything we have,
243 1.2.2.2 rmind * we return whatever we can return at ease.
244 1.2.2.2 rmind *
245 1.2.2.2 rmind * Note that ICMP datagrams longer than 576 octets are out of spec
246 1.2.2.2 rmind * according to RFC1812; the limit on icmpreturndatabytes below in
247 1.2.2.2 rmind * icmp_sysctl will keep things below that limit.
248 1.2.2.2 rmind */
249 1.2.2.2 rmind
250 1.2.2.2 rmind KASSERT (packetlen <= MCLBYTES);
251 1.2.2.2 rmind
252 1.2.2.2 rmind m = m_gethdr(M_DONTWAIT, MT_HEADER);
253 1.2.2.2 rmind if (m && (packetlen > MHLEN)) {
254 1.2.2.2 rmind MCLGET(m, M_DONTWAIT);
255 1.2.2.2 rmind if ((m->m_flags & M_EXT) == 0) {
256 1.2.2.2 rmind m_freem(m);
257 1.2.2.2 rmind m = NULL;
258 1.2.2.2 rmind }
259 1.2.2.2 rmind }
260 1.2.2.2 rmind if (m == NULL)
261 1.2.2.2 rmind goto freeit;
262 1.2.2.2 rmind MCLAIM(m, n->m_owner);
263 1.2.2.2 rmind m->m_len = packetlen;
264 1.2.2.2 rmind if ((m->m_flags & M_EXT) == 0)
265 1.2.2.2 rmind MH_ALIGN(m, m->m_len);
266 1.2.2.2 rmind else {
267 1.2.2.2 rmind m->m_data += sizeof(struct ip);
268 1.2.2.2 rmind m->m_len -= sizeof(struct ip);
269 1.2.2.2 rmind }
270 1.2.2.2 rmind icp = mtod(m, struct icmp *);
271 1.2.2.2 rmind if ((u_int)type > ICMP_MAXTYPE)
272 1.2.2.2 rmind panic("icmp error");
273 1.2.2.2 rmind ICMP_STATINC(ICMP_STAT_OUTHIST + type);
274 1.2.2.2 rmind icp->icmp_type = type;
275 1.2.2.2 rmind if (type == ICMP_REDIRECT)
276 1.2.2.2 rmind icp->icmp_gwaddr.s_addr = dest;
277 1.2.2.2 rmind else {
278 1.2.2.2 rmind icp->icmp_void = 0;
279 1.2.2.2 rmind /*
280 1.2.2.2 rmind * The following assignments assume an overlay with the
281 1.2.2.2 rmind * zeroed icmp_void field.
282 1.2.2.2 rmind */
283 1.2.2.2 rmind if (type == ICMP_PARAMPROB) {
284 1.2.2.2 rmind icp->icmp_pptr = code;
285 1.2.2.2 rmind code = 0;
286 1.2.2.2 rmind } else if (type == ICMP_UNREACH &&
287 1.2.2.2 rmind code == ICMP_UNREACH_NEEDFRAG && destmtu)
288 1.2.2.2 rmind icp->icmp_nextmtu = htons(destmtu);
289 1.2.2.2 rmind }
290 1.2.2.2 rmind
291 1.2.2.2 rmind icp->icmp_code = code;
292 1.2.2.2 rmind
293 1.2.2.2 rmind memset(&icp->icmp_ip, 0, ICMP_EXT_OFFSET);
294 1.2.2.2 rmind m_copydata(n, 0, icmplen, (char *)&icp->icmp_ip);
295 1.2.2.2 rmind
296 1.2.2.2 rmind /* Append the extension structure */
297 1.2.2.2 rmind memcpy(((char*)&icp->icmp_ip) + ICMP_EXT_OFFSET,
298 1.2.2.2 rmind &mpls_icmp_ext, sizeof(mpls_icmp_ext));
299 1.2.2.2 rmind
300 1.2.2.2 rmind /*
301 1.2.2.2 rmind * Now, copy old ip header (without options)
302 1.2.2.2 rmind * in front of icmp message.
303 1.2.2.2 rmind */
304 1.2.2.2 rmind if ((m->m_flags & M_EXT) == 0 &&
305 1.2.2.2 rmind m->m_data - sizeof(struct ip) < m->m_pktdat)
306 1.2.2.2 rmind panic("icmp len");
307 1.2.2.2 rmind m->m_data -= sizeof(struct ip);
308 1.2.2.2 rmind m->m_len += sizeof(struct ip);
309 1.2.2.2 rmind m->m_pkthdr.len = m->m_len;
310 1.2.2.2 rmind m->m_pkthdr.rcvif = n->m_pkthdr.rcvif;
311 1.2.2.2 rmind nip = mtod(m, struct ip *);
312 1.2.2.2 rmind /* ip_v set in ip_output */
313 1.2.2.2 rmind nip->ip_hl = sizeof(struct ip) >> 2;
314 1.2.2.2 rmind nip->ip_tos = 0;
315 1.2.2.2 rmind nip->ip_len = htons(m->m_len);
316 1.2.2.2 rmind /* ip_id set in ip_output */
317 1.2.2.2 rmind nip->ip_off = htons(0);
318 1.2.2.2 rmind /* ip_ttl set in icmp_reflect */
319 1.2.2.2 rmind nip->ip_p = IPPROTO_ICMP;
320 1.2.2.2 rmind nip->ip_src = oip->ip_src;
321 1.2.2.2 rmind nip->ip_dst = oip->ip_dst;
322 1.2.2.2 rmind icmp_reflect(m);
323 1.2.2.2 rmind
324 1.2.2.2 rmind freeit:
325 1.2.2.2 rmind m_freem(n);
326 1.2.2.2 rmind
327 1.2.2.2 rmind }
328 1.2.2.2 rmind
329 1.2.2.2 rmind #endif /* INET */
330 1.2.2.2 rmind
331 1.2.2.2 rmind struct mbuf *
332 1.2.2.2 rmind mpls_ttl_dec(struct mbuf *m)
333 1.2.2.2 rmind {
334 1.2.2.2 rmind union mpls_shim *mshim;
335 1.2.2.2 rmind #ifdef INET
336 1.2.2.2 rmind union mpls_shim top_shim, bossh;
337 1.2.2.2 rmind #endif
338 1.2.2.2 rmind
339 1.2.2.2 rmind if (m->m_len < sizeof(union mpls_shim) &&
340 1.2.2.2 rmind (m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
341 1.2.2.2 rmind return NULL;
342 1.2.2.2 rmind mshim = mtod(m, union mpls_shim *);
343 1.2.2.2 rmind mshim->s_addr = ntohl(mshim->s_addr);
344 1.2.2.2 rmind mshim->shim.ttl--;
345 1.2.2.2 rmind
346 1.2.2.2 rmind if (mshim->shim.ttl == 0) {
347 1.2.2.2 rmind if (!mpls_icmp_respond) {
348 1.2.2.2 rmind m_freem(m);
349 1.2.2.2 rmind return NULL;
350 1.2.2.2 rmind }
351 1.2.2.2 rmind
352 1.2.2.2 rmind #ifdef INET
353 1.2.2.2 rmind /*
354 1.2.2.2 rmind * shim ttl exceeded
355 1.2.2.2 rmind * send back ICMP type 11 code 0
356 1.2.2.2 rmind */
357 1.2.2.2 rmind bossh.s_addr = mshim->s_addr;
358 1.2.2.2 rmind top_shim.s_addr = htonl(mshim->s_addr);
359 1.2.2.2 rmind m_adj(m, sizeof(union mpls_shim));
360 1.2.2.2 rmind
361 1.2.2.2 rmind /* Goto BOS */
362 1.2.2.2 rmind while(bossh.shim.bos == 0) {
363 1.2.2.2 rmind if (m->m_len < sizeof(union mpls_shim) &&
364 1.2.2.2 rmind (m = m_pullup(m, sizeof(union mpls_shim))) == NULL) {
365 1.2.2.2 rmind m_freem(m);
366 1.2.2.2 rmind return NULL;
367 1.2.2.2 rmind }
368 1.2.2.2 rmind bossh.s_addr = ntohl(mtod(m, union mpls_shim *)->s_addr);
369 1.2.2.2 rmind m_adj(m, sizeof(union mpls_shim));
370 1.2.2.2 rmind }
371 1.2.2.2 rmind
372 1.2.2.2 rmind mpls_icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS,
373 1.2.2.2 rmind 0, 0, &top_shim);
374 1.2.2.2 rmind #else
375 1.2.2.2 rmind m_freem(m);
376 1.2.2.2 rmind #endif
377 1.2.2.2 rmind return NULL;
378 1.2.2.2 rmind }
379 1.2.2.2 rmind
380 1.2.2.2 rmind mshim->s_addr = htonl(mshim->s_addr);
381 1.2.2.2 rmind
382 1.2.2.2 rmind return m;
383 1.2.2.2 rmind }
384