xref: /netbsd-src/sys/net/if_mpls.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: if_mpls.c,v 1.14 2014/06/06 01:02:47 rmind Exp $ */
2 
3 /*
4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Mihai Chelaru <kefren@NetBSD.org>
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.14 2014/06/06 01:02:47 rmind Exp $");
34 
35 #include "opt_inet.h"
36 #include "opt_mpls.h"
37 
38 #include <sys/param.h>
39 
40 #include <sys/errno.h>
41 #include <sys/malloc.h>
42 #include <sys/mbuf.h>
43 #include <sys/sysctl.h>
44 
45 #include <net/bpf.h>
46 #include <net/if.h>
47 #include <net/if_types.h>
48 #include <net/netisr.h>
49 #include <net/route.h>
50 
51 #ifdef INET
52 #include <netinet/in.h>
53 #include <netinet/in_systm.h>
54 #include <netinet/in_var.h>
55 #include <netinet/ip.h>
56 #endif
57 
58 #ifdef INET6
59 #include <netinet/ip6.h>
60 #include <netinet6/in6_var.h>
61 #include <netinet6/ip6_var.h>
62 #endif
63 
64 #include <netmpls/mpls.h>
65 #include <netmpls/mpls_var.h>
66 
67 #include "if_mpls.h"
68 
69 #define TRIM_LABEL do { \
70 	m_adj(m, sizeof(union mpls_shim)); \
71 	if (m->m_len < sizeof(union mpls_shim) && \
72 	    (m = m_pullup(m, sizeof(union mpls_shim))) == NULL) \
73 		goto done; \
74 	dst.smpls_addr.s_addr = ntohl(mtod(m, union mpls_shim *)->s_addr); \
75 	} while (/* CONSTCOND */ 0)
76 
77 
78 void ifmplsattach(int);
79 
80 static int mpls_clone_create(struct if_clone *, int);
81 static int mpls_clone_destroy(struct ifnet *);
82 
83 static struct if_clone mpls_if_cloner =
84 	IF_CLONE_INITIALIZER("mpls", mpls_clone_create, mpls_clone_destroy);
85 
86 
87 static void mpls_input(struct ifnet *, struct mbuf *);
88 static int mpls_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
89 	struct rtentry *);
90 static int mpls_ioctl(struct ifnet *, u_long, void *);
91 static int mpls_send_frame(struct mbuf *, struct ifnet *, struct rtentry *);
92 static int mpls_lse(struct mbuf *);
93 
94 #ifdef INET
95 static int mpls_unlabel_inet(struct mbuf *);
96 static struct mbuf *mpls_label_inet(struct mbuf *, union mpls_shim *, uint);
97 #endif
98 
99 #ifdef INET6
100 static int mpls_unlabel_inet6(struct mbuf *);
101 static struct mbuf *mpls_label_inet6(struct mbuf *, union mpls_shim *, uint);
102 #endif
103 
104 static struct mbuf *mpls_prepend_shim(struct mbuf *, union mpls_shim *);
105 
106 extern int mpls_defttl, mpls_mapttl_inet, mpls_mapttl_inet6, mpls_icmp_respond,
107 	mpls_forwarding, mpls_accept, mpls_mapprec_inet, mpls_mapclass_inet6,
108 	mpls_rfc4182;
109 
110 /* ARGSUSED */
111 void
112 ifmplsattach(int count)
113 {
114 	if_clone_attach(&mpls_if_cloner);
115 }
116 
117 static int
118 mpls_clone_create(struct if_clone *ifc, int unit)
119 {
120 	struct mpls_softc *sc;
121 
122 	sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
123 
124 	if_initname(&sc->sc_if, ifc->ifc_name, unit);
125 	sc->sc_if.if_softc = sc;
126 	sc->sc_if.if_type = IFT_MPLS;
127 	sc->sc_if.if_addrlen = 0;
128 	sc->sc_if.if_hdrlen = sizeof(union mpls_shim);
129 	sc->sc_if.if_dlt = DLT_NULL;
130 	sc->sc_if.if_mtu = 1500;
131 	sc->sc_if.if_flags = 0;
132 	sc->sc_if.if_input = mpls_input;
133 	sc->sc_if.if_output = mpls_output;
134 	sc->sc_if.if_ioctl = mpls_ioctl;
135 
136 	if_attach(&sc->sc_if);
137 	if_alloc_sadl(&sc->sc_if);
138 	bpf_attach(&sc->sc_if, DLT_NULL, sizeof(uint32_t));
139 	return 0;
140 }
141 
142 static int
143 mpls_clone_destroy(struct ifnet *ifp)
144 {
145 	int s;
146 
147 	bpf_detach(ifp);
148 
149 	s = splnet();
150 	if_detach(ifp);
151 	splx(s);
152 
153 	free(ifp->if_softc, M_DEVBUF);
154 	return 0;
155 }
156 
157 static void
158 mpls_input(struct ifnet *ifp, struct mbuf *m)
159 {
160 #if 0
161 	/*
162 	 * TODO - kefren
163 	 * I'd love to unshim the packet, guess family
164 	 * and pass it to bpf
165 	 */
166 	bpf_mtap_af(ifp, AF_MPLS, m);
167 #endif
168 
169 	mpls_lse(m);
170 }
171 
172 void
173 mplsintr(void)
174 {
175 	struct mbuf *m;
176 	int s;
177 
178 	while (!IF_IS_EMPTY(&mplsintrq)) {
179 		s = splnet();
180 		IF_DEQUEUE(&mplsintrq, m);
181 		splx(s);
182 
183 		if (!m)
184 			return;
185 
186 		if (((m->m_flags & M_PKTHDR) == 0) ||
187 		    (m->m_pkthdr.rcvif == 0))
188 			panic("mplsintr(): no pkthdr or rcvif");
189 
190 #ifdef MBUFTRACE
191 		m_claimm(m, &mpls_owner);
192 #endif
193 		mpls_input(m->m_pkthdr.rcvif, m);
194 	}
195 }
196 
197 /*
198  * prepend shim and deliver
199  */
200 static int
201 mpls_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, struct rtentry *rt)
202 {
203 	union mpls_shim mh, *pms;
204 	struct rtentry *rt1;
205 	int err;
206 	uint psize = sizeof(struct sockaddr_mpls);
207 
208 	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
209 		m_freem(m);
210 		return ENETDOWN;
211 	}
212 
213 	if (rt_gettag(rt) == NULL || rt_gettag(rt)->sa_family != AF_MPLS) {
214 		m_freem(m);
215 		return EINVAL;
216 	}
217 
218 	bpf_mtap_af(ifp, dst->sa_family, m);
219 
220 	memset(&mh, 0, sizeof(mh));
221 	mh.s_addr = MPLS_GETSADDR(rt);
222 	mh.shim.bos = 1;
223 	mh.shim.exp = 0;
224 	mh.shim.ttl = mpls_defttl;
225 
226 	pms = &((struct sockaddr_mpls*)rt_gettag(rt))->smpls_addr;
227 
228 	while (psize <= rt_gettag(rt)->sa_len - sizeof(mh)) {
229 		pms++;
230 		if (mh.shim.label != MPLS_LABEL_IMPLNULL &&
231 		    ((m = mpls_prepend_shim(m, &mh)) == NULL))
232 			return ENOBUFS;
233 		memset(&mh, 0, sizeof(mh));
234 		mh.s_addr = ntohl(pms->s_addr);
235 		mh.shim.bos = mh.shim.exp = 0;
236 		mh.shim.ttl = mpls_defttl;
237 		psize += sizeof(mh);
238 	}
239 
240 	switch(dst->sa_family) {
241 #ifdef INET
242 	case AF_INET:
243 		m = mpls_label_inet(m, &mh, psize - sizeof(struct sockaddr_mpls));
244 		break;
245 #endif
246 #ifdef INET6
247 	case AF_INET6:
248 		m = mpls_label_inet6(m, &mh, psize - sizeof(struct sockaddr_mpls));
249 		break;
250 #endif
251 	default:
252 		m = mpls_prepend_shim(m, &mh);
253 		break;
254 	}
255 
256 	if (m == NULL) {
257 		IF_DROP(&ifp->if_snd);
258 		ifp->if_oerrors++;
259 		return ENOBUFS;
260 	}
261 
262 	ifp->if_opackets++;
263 	ifp->if_obytes += m->m_pkthdr.len;
264 
265 	if ((rt1=rtalloc1(rt->rt_gateway, 1)) == NULL) {
266 		m_freem(m);
267 		return EHOSTUNREACH;
268 	}
269 
270 	err = mpls_send_frame(m, rt1->rt_ifp, rt);
271 	rtfree(rt1);
272 	return err;
273 }
274 
275 static int
276 mpls_ioctl(struct ifnet *ifp, u_long cmd, void *data)
277 {
278 	int error = 0, s = splnet();
279 	struct ifreq *ifr = data;
280 
281 	switch(cmd) {
282 	case SIOCINITIFADDR:
283 		ifp->if_flags |= IFF_UP | IFF_RUNNING;
284 		break;
285 	case SIOCSIFMTU:
286 		if (ifr != NULL && ifr->ifr_mtu < 576) {
287 			error = EINVAL;
288 			break;
289 		}
290 		/* FALLTHROUGH */
291 	case SIOCGIFMTU:
292 		if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET)
293 			error = 0;
294 		break;
295 	case SIOCSIFFLAGS:
296 		if ((error = ifioctl_common(ifp, cmd, data)) != 0)
297 			break;
298 		if (ifp->if_flags & IFF_UP)
299 			ifp->if_flags |= IFF_RUNNING;
300 		break;
301 	default:
302 		error = ifioctl_common(ifp, cmd, data);
303 		break;
304 	}
305 	splx(s);
306 	return error;
307 }
308 
309 /*
310  * MPLS Label Switch Engine
311  */
312 static int
313 mpls_lse(struct mbuf *m)
314 {
315 	struct sockaddr_mpls dst;
316 	union mpls_shim tshim, *htag;
317 	struct rtentry *rt = NULL;
318 	int error = ENOBUFS;
319 	uint psize = sizeof(struct sockaddr_mpls);
320 	bool push_back_alert = false;
321 
322 	if (m->m_len < sizeof(union mpls_shim) &&
323 	    (m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
324 		goto done;
325 
326 	dst.smpls_len = sizeof(struct sockaddr_mpls);
327 	dst.smpls_family = AF_MPLS;
328 	dst.smpls_addr.s_addr = ntohl(mtod(m, union mpls_shim *)->s_addr);
329 
330 	/* Check if we're accepting MPLS Frames */
331 	error = EINVAL;
332 	if (!mpls_accept)
333 		goto done;
334 
335 	/* TTL decrement */
336 	if ((m = mpls_ttl_dec(m)) == NULL)
337 		goto done;
338 
339 	/* RFC 4182 */
340 	if (mpls_rfc4182 != 0)
341 		while((dst.smpls_addr.shim.label == MPLS_LABEL_IPV4NULL ||
342 		    dst.smpls_addr.shim.label == MPLS_LABEL_IPV6NULL) &&
343 		    __predict_false(dst.smpls_addr.shim.bos == 0))
344 			TRIM_LABEL;
345 
346 	/* RFC 3032 Section 2.1 Page 4 */
347 	if (__predict_false(dst.smpls_addr.shim.label == MPLS_LABEL_RTALERT) &&
348 	    dst.smpls_addr.shim.bos == 0) {
349 		TRIM_LABEL;
350 		push_back_alert = true;
351 	}
352 
353 	if (dst.smpls_addr.shim.label <= MPLS_LABEL_RESMAX) {
354 		/* Don't swap reserved labels */
355 		switch (dst.smpls_addr.shim.label) {
356 #ifdef INET
357 		case MPLS_LABEL_IPV4NULL:
358 			/* Pop shim and push mbuf to IP stack */
359 			if (dst.smpls_addr.shim.bos)
360 				error = mpls_unlabel_inet(m);
361 			break;
362 #endif
363 #ifdef INET6
364 		case MPLS_LABEL_IPV6NULL:
365 			/* Pop shim and push mbuf to IPv6 stack */
366 			if (dst.smpls_addr.shim.bos)
367 				error = mpls_unlabel_inet6(m);
368 			break;
369 #endif
370 		case MPLS_LABEL_RTALERT:	/* Yeah, I'm all alerted */
371 		case MPLS_LABEL_IMPLNULL:	/* This is logical only */
372 		default:			/* Rest are not allowed */
373 			break;
374 		}
375 		goto done;
376 	}
377 
378 	/* Check if we should do MPLS forwarding */
379 	error = EHOSTUNREACH;
380 	if (!mpls_forwarding)
381 		goto done;
382 
383 	/* Get a route to dst */
384 	dst.smpls_addr.shim.ttl =
385 	    dst.smpls_addr.shim.bos =
386 	    dst.smpls_addr.shim.exp = 0;
387 	dst.smpls_addr.s_addr = htonl(dst.smpls_addr.s_addr);
388 	if ((rt = rtalloc1((const struct sockaddr*)&dst, 1)) == NULL)
389 		goto done;
390 
391 	/* MPLS packet with no MPLS tagged route ? */
392 	if ((rt->rt_flags & RTF_GATEWAY) == 0 ||
393 	     rt_gettag(rt) == NULL ||
394 	     rt_gettag(rt)->sa_family != AF_MPLS)
395 		goto done;
396 
397 	tshim.s_addr = MPLS_GETSADDR(rt);
398 
399 	/* Swap labels */
400 	if ((m->m_len < sizeof(union mpls_shim)) &&
401 	    (m = m_pullup(m, sizeof(union mpls_shim))) == 0) {
402 		error = ENOBUFS;
403 		goto done;
404 	}
405 
406 	/* Replace only the label */
407 	htag = mtod(m, union mpls_shim *);
408 	htag->s_addr = ntohl(htag->s_addr);
409 	htag->shim.label = tshim.shim.label;
410 	htag->s_addr = htonl(htag->s_addr);
411 
412 	/* check if there is anything more to prepend */
413 	htag = &((struct sockaddr_mpls*)rt_gettag(rt))->smpls_addr;
414 	while (psize <= rt_gettag(rt)->sa_len - sizeof(tshim)) {
415 		htag++;
416 		memset(&tshim, 0, sizeof(tshim));
417 		tshim.s_addr = ntohl(htag->s_addr);
418 		tshim.shim.bos = tshim.shim.exp = 0;
419 		tshim.shim.ttl = mpls_defttl;
420 		if (tshim.shim.label != MPLS_LABEL_IMPLNULL &&
421 		    ((m = mpls_prepend_shim(m, &tshim)) == NULL))
422 			return ENOBUFS;
423 		psize += sizeof(tshim);
424 	}
425 
426 	if (__predict_false(push_back_alert == true)) {
427 		/* re-add the router alert label */
428 		memset(&tshim, 0, sizeof(tshim));
429 		tshim.s_addr = MPLS_LABEL_RTALERT;
430 		tshim.shim.bos = tshim.shim.exp = 0;
431 		tshim.shim.ttl = mpls_defttl;
432 		if ((m = mpls_prepend_shim(m, &tshim)) == NULL)
433 			return ENOBUFS;
434 	}
435 
436 	error = mpls_send_frame(m, rt->rt_ifp, rt);
437 
438 done:
439 	if (error != 0 && m != NULL)
440 		m_freem(m);
441 	if (rt != NULL)
442 		rtfree(rt);
443 
444 	return error;
445 }
446 
447 static int
448 mpls_send_frame(struct mbuf *m, struct ifnet *ifp, struct rtentry *rt)
449 {
450 	union mpls_shim msh;
451 
452 	if ((rt->rt_flags & RTF_GATEWAY) == 0)
453 		return EHOSTUNREACH;
454 
455 	rt->rt_use++;
456 
457 	msh.s_addr = MPLS_GETSADDR(rt);
458 	if (msh.shim.label == MPLS_LABEL_IMPLNULL ||
459 	    (m->m_flags & (M_MCAST | M_BCAST))) {
460 		m_adj(m, sizeof(union mpls_shim));
461 		m->m_pkthdr.csum_flags = 0;
462 	}
463 
464 	switch(ifp->if_type) {
465 	/* only these are supported for now */
466 	case IFT_ETHER:
467 	case IFT_TUNNEL:
468 	case IFT_LOOP:
469 		return (*ifp->if_output)(ifp, m, rt->rt_gateway, rt);
470 		break;
471 	default:
472 		return ENETUNREACH;
473 	}
474 	return 0;
475 }
476 
477 
478 
479 #ifdef INET
480 static int
481 mpls_unlabel_inet(struct mbuf *m)
482 {
483 	struct ip *iph;
484 	union mpls_shim *ms;
485 	int iphlen;
486 
487 	if (mpls_mapttl_inet || mpls_mapprec_inet) {
488 
489 		/* get shim info */
490 		ms = mtod(m, union mpls_shim *);
491 		ms->s_addr = ntohl(ms->s_addr);
492 
493 		/* and get rid of it */
494 		m_adj(m, sizeof(union mpls_shim));
495 
496 		/* get ip header */
497 		if (m->m_len < sizeof (struct ip) &&
498 		    (m = m_pullup(m, sizeof(struct ip))) == NULL)
499 			return ENOBUFS;
500 		iph = mtod(m, struct ip *);
501 		iphlen = iph->ip_hl << 2;
502 
503 		/* get it all */
504 		if (m->m_len < iphlen) {
505 			if ((m = m_pullup(m, iphlen)) == NULL)
506 				return ENOBUFS;
507 			iph = mtod(m, struct ip *);
508 		}
509 
510 		/* check ipsum */
511 		if (in_cksum(m, iphlen) != 0) {
512 			m_freem(m);
513 			return EINVAL;
514 		}
515 
516 		/* set IP ttl from MPLS ttl */
517 		if (mpls_mapttl_inet)
518 			iph->ip_ttl = ms->shim.ttl;
519 
520 		/* set IP Precedence from MPLS Exp */
521 		if (mpls_mapprec_inet) {
522 			iph->ip_tos = (iph->ip_tos << 3) >> 3;
523 			iph->ip_tos |= ms->shim.exp << 5;
524 		}
525 
526 		/* reset ipsum because we modified TTL and TOS */
527 		iph->ip_sum = 0;
528 		iph->ip_sum = in_cksum(m, iphlen);
529 	} else
530 		m_adj(m, sizeof(union mpls_shim));
531 
532 	/* Put it on IP queue */
533 	if (__predict_false(!pktq_enqueue(ip_pktq, m, 0))) {
534 		m_freem(m);
535 		return ENOBUFS;
536 	}
537 	return 0;
538 }
539 
540 /*
541  * Prepend MPLS label
542  */
543 static struct mbuf *
544 mpls_label_inet(struct mbuf *m, union mpls_shim *ms, uint offset)
545 {
546 	struct ip iphdr;
547 
548 	if (mpls_mapttl_inet || mpls_mapprec_inet) {
549 		if ((m->m_len < sizeof(struct ip)) &&
550 		    (m = m_pullup(m, offset + sizeof(struct ip))) == 0)
551 			return NULL; /* XXX */
552 		m_copydata(m, offset, sizeof(struct ip), &iphdr);
553 
554 		/* Map TTL */
555 		if (mpls_mapttl_inet)
556 			ms->shim.ttl = iphdr.ip_ttl;
557 
558 		/* Copy IP precedence to EXP */
559 		if (mpls_mapprec_inet)
560 			ms->shim.exp = ((u_int8_t)iphdr.ip_tos) >> 5;
561 	}
562 
563 	if ((m = mpls_prepend_shim(m, ms)) == NULL)
564 		return NULL;
565 
566 	return m;
567 }
568 
569 #endif	/* INET */
570 
571 #ifdef INET6
572 
573 static int
574 mpls_unlabel_inet6(struct mbuf *m)
575 {
576 	struct ip6_hdr *ip6hdr;
577 	union mpls_shim ms;
578 
579 	/* TODO: mapclass */
580 	if (mpls_mapttl_inet6) {
581 		ms.s_addr = ntohl(mtod(m, union mpls_shim *)->s_addr);
582 		m_adj(m, sizeof(union mpls_shim));
583 
584 		if (m->m_len < sizeof (struct ip6_hdr) &&
585 		    (m = m_pullup(m, sizeof(struct ip6_hdr))) == 0)
586 			return ENOBUFS;
587 		ip6hdr = mtod(m, struct ip6_hdr *);
588 
589 		/* Because we just decremented this in mpls_lse */
590 		ip6hdr->ip6_hlim = ms.shim.ttl + 1;
591 	} else
592 		m_adj(m, sizeof(union mpls_shim));
593 
594 	/* Put it back on IPv6 queue. */
595 	if (__predict_false(!pktq_enqueue(ip6_pktq, m, 0))) {
596 		m_freem(m);
597 		return ENOBUFS;
598 	}
599 	return 0;
600 }
601 
602 static struct mbuf *
603 mpls_label_inet6(struct mbuf *m, union mpls_shim *ms, uint offset)
604 {
605 	struct ip6_hdr ip6h;
606 
607 	if (mpls_mapttl_inet6 || mpls_mapclass_inet6) {
608 		if (m->m_len < sizeof(struct ip6_hdr) &&
609 		    (m = m_pullup(m, offset + sizeof(struct ip6_hdr))) == 0)
610 			return NULL;
611 		m_copydata(m, offset, sizeof(struct ip6_hdr), &ip6h);
612 
613 		if (mpls_mapttl_inet6)
614 			ms->shim.ttl = ip6h.ip6_hlim;
615 
616 		if (mpls_mapclass_inet6)
617 			ms->shim.exp = ip6h.ip6_vfc << 1 >> 5;
618 	}
619 
620 	if ((m = mpls_prepend_shim(m, ms)) == NULL)
621 		return NULL;
622 
623 	return m;
624 }
625 
626 #endif	/* INET6 */
627 
628 static struct mbuf *
629 mpls_prepend_shim(struct mbuf *m, union mpls_shim *ms)
630 {
631 	union mpls_shim *shim;
632 
633 	M_PREPEND(m, sizeof(*ms), M_DONTWAIT);
634 	if (m == NULL)
635 		return NULL;
636 
637 	if (m->m_len < sizeof(union mpls_shim) &&
638 	    (m = m_pullup(m, sizeof(union mpls_shim))) == 0)
639 		return NULL;
640 
641 	shim = mtod(m, union mpls_shim *);
642 
643 	memcpy(shim, ms, sizeof(*shim));
644 	shim->s_addr = htonl(shim->s_addr);
645 
646 	return m;
647 }
648