diff options
author | 2008-04-23 11:22:23 +0000 | |
---|---|---|
committer | 2008-04-23 11:22:23 +0000 | |
commit | 5e171871a36abd36b391cf9ac0f3fef368d04d31 (patch) | |
tree | f8f6e22a92096daf01fd7829347c1dcdce6bc68a | |
parent | learn about the fans (diff) | |
download | wireguard-openbsd-5e171871a36abd36b391cf9ac0f3fef368d04d31.tar.xz wireguard-openbsd-5e171871a36abd36b391cf9ac0f3fef368d04d31.zip |
I hate working outside the tree.
Fix my faulty import....
-rw-r--r-- | sys/netmpls/mpls.h | 161 | ||||
-rw-r--r-- | sys/netmpls/mpls_input.c | 163 | ||||
-rw-r--r-- | sys/netmpls/mpls_proto.c | 81 | ||||
-rw-r--r-- | sys/netmpls/mpls_raw.c | 157 | ||||
-rw-r--r-- | sys/netmpls/mpls_shim.c | 148 |
5 files changed, 5 insertions, 705 deletions
diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h index 969795208f2..703d85d9ebf 100644 --- a/sys/netmpls/mpls.h +++ b/sys/netmpls/mpls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls.h,v 1.1 2008/04/23 11:00:35 norby Exp $ */ +/* $OpenBSD: mpls.h,v 1.2 2008/04/23 11:22:23 norby Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -135,162 +135,3 @@ struct sockaddr_mpls { } #endif -/* - * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * - * $Id: mpls.h,v 1.1 2008/04/23 11:00:35 norby Exp $ - */ - -#ifndef _NETMPLS_MPLS_H_ -#define _NETMPLS_MPLS_H_ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/proc.h> -#include <sys/queue.h> - -#include <net/if.h> -#include <net/if_dl.h> - -/* - * Structure of a SHIM header. - */ -struct shim_hdr { - u_int32_t shim_label; /* 20bit label, 4bit exp & BOS, 8bit ttl */ -}; - -/* - * By byte-swapping the constants, we avoid ever having to byte-swap IP - * addresses inside the kernel. Unfortunately, user-level programs rely - * on these macros not doing byte-swapping. - */ -#define SHIM_LABEL_MASK 0xfffff000U -#define SHIM_LABEL_OFFSET 12 -#define SHIM_EXP_MASK 0x00000e00U -#define SHIM_EXP_OFFSET 9 -#define SHIM_BOS_MASK 0x00000100U -#define SHIM_BOS_OFFSET 8 -#define SHIM_TTL_MASK 0x000000ffU - -#define MPLS_SHIM_LABEL_GET(l) (((l) & SHIM_LABEL_MASK) >> SHIM_LABEL_OFFSET) -#define MPLS_SHIM_EXP_GET(l) (((l) & SHIM_EXP_MASK) >> SHIM_EXP_OFFSET) -#define MPLS_SHIM_BOS_ISSET(l) (((l) & SHIM_BOS_MASK) == SHIM_BOS_MASK) -#define MPLS_SHIM_TTL_GET(l) ((l) & SHIM_TTL_MASK) -#define MPLS_SHIM_TTL_SET(l, t) (((l) & ~SHIM_TTL_MASK) | ((t) & SHIM_TTL_MASK)) - -/* Reserved lavel values (rfc3032) */ -#define MPLS_LABEL_IPV4NULL 0 /* IPv4 Explicit NULL Label */ -#define MPLS_LABEL_RTALERT 1 /* Router Alert Label */ -#define MPLS_LABEL_IPV6NULL 2 /* IPv6 Explicit NULL Label */ -#define MPLS_LABEL_IMPLNULL 3 /* Implicit NULL Label */ -/* MPLS_LABEL_RESERVED 4-15 */ /* Values 4-15 are reserved */ -#define MPLS_LABEL_RESERVED_MAX 15 - -/* - * Socket address - */ - -struct sockaddr_mpls { - u_int8_t smpls_len; /* length */ - u_int8_t smpls_family; /* AF_MPLS */ - u_int8_t smpls_operation; - u_int8_t smpls_out_exp; /* outgoing exp value */ - u_int32_t smpls_out_label; /* outgoing MPLS label */ - u_int16_t smpls_out_ifindex; - u_int16_t smpls_in_ifindex; - u_int32_t smpls_in_label; /* MPLS label 20 bits*/ -#if MPLS_MCAST - u_int8_t smpls_mcexp; - u_int8_t smpls_pad2[2]; - u_int32_t smpls_mclabel; -#endif -}; - -#define MPLS_EXP_MASK 0x07 /* mpls exp value ( 3bits) */ - -#define MPLS_OP_POP 1 -#define MPLS_OP_PUSH 2 -#define MPLS_OP_SWAP 3 - -#define MPLS_INKERNEL_LOOP_MAX 16 - -#define satosmpls(sa) ((struct sockaddr_mpls *)(sa)) -#define smplstosa(smpls) ((struct sockaddr *)(smpls)) -#define satosdl(sa) ((struct sockaddr_dl *)(sa)) -#define sdltosa(sdl) ((struct sockaddr *)(sdl)) - -struct mpls_ifaddr { - struct ifaddr ia_ifa; /* protocol-independent info */ -#define ia_ifp ia_ifa.ifa_ifp -#define ia_flags ia_ifa.ifa_flags - TAILQ_ENTRY(mpls_ifaddr) ia_list; /* list of MPLS addresses */ - struct sockaddr_mpls ia_addr; /* interface address */ - struct sockaddr ia_dstaddr; /* peer dst address */ -}; - -struct mpls_aliasreq { - char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ - struct sockaddr_mpls ifra_addr; - struct sockaddr ifra_dstaddr; - struct sockaddr_mpls ifra_mask; /* not used */ -}; - - -/* - * Names for IP sysctl objects - */ -#define MPLSCTL_DEFTTL 1 -#define MPLSCTL_MAXINKLOOP 2 -#define MPLSCTL_PUSHEXPNULL_IP 3 -#define MPLSCTL_PUSHEXPNULL_IP6 4 -#define MPLSCTL_MAPTTL_IP 5 -#define MPLSCTL_MAPTTL_IP6 6 -#define MPLSCTL_MAXID 7 - -#define MPLSCTL_NAMES { \ - { 0, 0 }, \ - { "ttl", CTLTYPE_INT }, \ - { "maxloop_inkernel", CTLTYPE_INT }, \ - { "pushexpnull_ip", CTLTYPE_INT }, \ - { "pushexpnull_ip6", CTLTYPE_INT }, \ - { "mapttl_ip", CTLTYPE_INT }, \ - { "mapttl_ip6", CTLTYPE_INT }, \ -} - -#ifdef _KERNEL -TAILQ_HEAD(mpls_ifaddrhead, mpls_ifaddr); /* the actual queue head */ -extern struct mpls_ifaddrhead mpls_ifaddr; - -extern void mpls_init(void); -extern int mpls_control(struct socket *, u_long, caddr_t, struct ifnet *); -extern void mpls_purgeif(struct ifnet *); -#endif /* _KERNEL */ -#endif /* _NETMPLS_MPLS_H_ */ diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index 2e5681b3848..ec75abef34e 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_input.c,v 1.1 2008/04/23 11:00:35 norby Exp $ */ +/* $OpenBSD: mpls_input.c,v 1.2 2008/04/23 11:22:23 norby Exp $ */ /* * Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org> @@ -174,164 +174,3 @@ done: if (rt) RTFREE(rt); } -/* $OpenBSD: mpls_input.c,v 1.1 2008/04/23 11:00:35 norby Exp $ */ -/* - * Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/param.h> -#include <sys/mbuf.h> -#include <sys/systm.h> -#include <sys/socket.h> - -#include <net/if.h> -#include <net/route.h> - -#include <netmpls/mpls.h> -#include <netmpls/mpls_var.h> - -struct ifqueue mplsintrq; - -void mpls_input(struct mbuf *); - -void -mplsintr(void) -{ - struct mbuf *m; - int s; - - while (mplsintrq.ifq_head) { - /* Get next datagram of input queue */ - s = splnet(); - IF_DEQUEUE(&mplsintrq, m); - splx(s); - if (m == NULL) - return; -#ifdef DIAGNOSTIC - if ((m->m_flags & M_PKTHDR) == 0) - panic("ipintr no HDR"); -#endif - mpls_input(m); - } -} - -void -mpls_input(struct mbuf *m) -{ - struct route ro; - struct ifnet *ifp = m->m_pkthdr.rcvif; - struct sockaddr_mpls *smpls; - struct shim_hdr *shim; - struct rtentry *rt = NULL; - u_int32_t label, ttl; - int i, error; - - printf("mpls_input: !! \n"); - - if (m->m_len < sizeof(label)) - if ((m = m_pullup(m, sizeof(label))) == NULL) - return; - - shim = mtod(m, struct shim_hdr *); - /* swap label to host byte order. */ - label = ntohl(shim->shim_label); - -#ifdef MPLS_DEBUG - printf("mpls_input: iface %s label=%d, ttl=%d BoS %d\n", - ifp->if_xname, MPLS_SHIM_LABEL_GET(label), - MPLS_SHIM_TTL_GET(label), MPLS_SHIM_BOS_ISSET(label)); -#endif /* MPLS_DEBUG */ - - /* check and decrement TTL */ - ttl = MPLS_SHIM_TTL_GET(label); - if (ttl <= 1) { - /* ttl exceeded */ - /* - * XXX if possible hand packet up to network layer so that an - * ICMP TTL exceeded can be sent back. - */ - m_freem(m); - return; - } - ttl--; - - for (i = 0; i < MPLS_INKERNEL_LOOP_MAX; i++) { - /* XXX maybe this should be done later */ - if (MPLS_SHIM_BOS_ISSET(label)) { - /* no LER until now */ - error = EHOSTUNREACH; - goto done; - } - - bzero(&ro, sizeof(ro)); - smpls = satosmpls(&ro.ro_dst); - smpls->smpls_family = AF_MPLS; - smpls->smpls_len = sizeof(*smpls); - smpls->smpls_in_ifindex = ifp->if_index; - smpls->smpls_in_label = MPLS_SHIM_LABEL_GET(label); - - rtalloc(&ro); /* XXX switch to rtalloc1() */ - rt = ro.ro_rt; - - if (rt == NULL) { - /* no entry for this label */ - error = EHOSTUNREACH; -#ifdef MPLS_DEBUG - printf("MPLS_DEBUG: label not found\n"); -#endif - goto done; - } - - rt->rt_use++; - smpls = satosmpls(rt_key(rt)); - - switch (smpls->smpls_operation) { - case MPLS_OP_POP: - printf("mpls_input: POP\n"); - /* mpls_shim_pop() */ - break; - case MPLS_OP_PUSH: - printf("mpls_input: PUSH\n"); - /* mpls_shim_push() */ - break; - case MPLS_OP_SWAP: - printf("mpls_input: SWAP\n"); - /* mpls_shim_swap() */ - break; - default: - break; - } - - /* not yet done with packet */ - /* reget current label */ - shim = mtod(m, struct shim_hdr *); - label = ntohl(shim->shim_label); - - if (rt) { - RTFREE(rt); - rt = NULL; - } - } - - /* write back modified label */ - shim->shim_label = htonl(MPLS_SHIM_TTL_SET(label, ttl)); - - error = (*ifp->if_output)(ifp, m, smplstosa(&smpls), rt); -done: - if (error) - m_freem(m); - if (rt) - RTFREE(rt); -} diff --git a/sys/netmpls/mpls_proto.c b/sys/netmpls/mpls_proto.c index 3984208fdd3..f3e4f510f3c 100644 --- a/sys/netmpls/mpls_proto.c +++ b/sys/netmpls/mpls_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_proto.c,v 1.1 2008/04/23 11:00:35 norby Exp $ */ +/* $OpenBSD: mpls_proto.c,v 1.2 2008/04/23 11:22:23 norby Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -74,82 +74,3 @@ struct domain mplsdomain = { offsetof(struct sockaddr_mpls, smpls_in_ifindex) << 3, sizeof(struct sockaddr_mpls) }; -/* - * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * - * $Id: mpls_proto.c,v 1.1 2008/04/23 11:00:35 norby Exp $ - */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/protosw.h> -#include <sys/domain.h> -#include <sys/mbuf.h> - -#include <net/if.h> -#include <net/route.h> - -#include <netmpls/mpls.h> -#include <netmpls/mpls_var.h> - -/* - * MPLS protocol family: - */ - -extern struct domain mplsdomain; - -struct protosw mplssw[] = { -{ 0, &mplsdomain, 0, 0, - 0, 0, 0, 0, - 0, - mpls_init, 0, 0, 0, mpls_sysctl -}, -{ SOCK_DGRAM, &mplsdomain, 0, PR_ATOMIC|PR_ADDR, - 0, 0, 0, 0, - mpls_raw_usrreq, - 0, 0, 0, 0, mpls_sysctl, -}, -/* raw wildcard */ -{ SOCK_RAW, &mplsdomain, 0, PR_ATOMIC|PR_ADDR, - 0, 0, 0, 0, - mpls_raw_usrreq, - 0, 0, 0, 0, mpls_sysctl, -}, -}; - -struct domain mplsdomain = { - AF_MPLS, "mpls", /*mpls_init */ 0 , 0, 0, - mplssw, - &mplssw[sizeof(mplssw)/sizeof(mplssw[0])], 0, - rn_inithead, - offsetof(struct sockaddr_mpls, smpls_in_ifindex) << 3, - sizeof(struct sockaddr_mpls) -}; diff --git a/sys/netmpls/mpls_raw.c b/sys/netmpls/mpls_raw.c index b084f879dcc..75d41a8057c 100644 --- a/sys/netmpls/mpls_raw.c +++ b/sys/netmpls/mpls_raw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_raw.c,v 1.1 2008/04/23 11:00:35 norby Exp $ */ +/* $OpenBSD: mpls_raw.c,v 1.2 2008/04/23 11:22:23 norby Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -144,158 +144,3 @@ mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, oldp, oldlenp, newp, newlen); } } -/* - * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * - * $Id: mpls_raw.c,v 1.1 2008/04/23 11:00:35 norby Exp $ - */ - -#include <sys/param.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/errno.h> -#include <sys/protosw.h> -#include <sys/sockio.h> -#include <sys/socket.h> -#include <sys/socketvar.h> -#include <sys/systm.h> -#include <sys/sysctl.h> - -#include <net/if.h> -#include <net/if_types.h> -#include <net/route.h> - -#include <netmpls/mpls.h> -#include <netmpls/mpls_var.h> - -#define MPLS_RAW_SNDQ 8192 -#define MPLS_RAW_RCVQ 8192 - -u_long mpls_raw_sendspace = MPLS_RAW_SNDQ; -u_long mpls_raw_recvspace = MPLS_RAW_RCVQ; - -int mpls_defttl = 255; -int mpls_inkloop = 16; -int mpls_push_expnull_ip = 0; -int mpls_push_expnull_ip6 = 0; -int mpls_mapttl_ip = 1; -int mpls_mapttl_ip6 = 0; - -#define MPLSCTL_VARS { \ - 0, \ - &mpls_defttl, \ - &mpls_inkloop, \ - &mpls_push_expnull_ip, \ - &mpls_push_expnull_ip6, \ - &mpls_mapttl_ip, \ - &mpls_mapttl_ip6, \ -} - -int -mpls_raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, - struct mbuf *control) -{ - int s; - int error = 0; - -#ifdef MPLS_DEBUG - printf("mpls_raw_usrreq: called! (reqid=%d).\n", req); -#endif /* MPLS_DEBUG */ - - if (req == PRU_CONTROL) - return (mpls_control(so, (long)m, (caddr_t)nam, - (struct ifnet *)control)); -/* XXX norby - if (req == PRU_PURGEIF) { - mpls_purgeif((struct ifnet *)control); - return (0); - } -*/ - s = splsoftnet(); - - switch (req) { - - case PRU_ATTACH: - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { - error = soreserve(so, mpls_raw_sendspace, mpls_raw_recvspace); - if (error) - break; - } - break; - - case PRU_DETACH: - case PRU_BIND: - case PRU_LISTEN: - case PRU_CONNECT: - case PRU_CONNECT2: - case PRU_DISCONNECT: - case PRU_SHUTDOWN: - case PRU_RCVD: - case PRU_SEND: - case PRU_SENSE: - case PRU_RCVOOB: - case PRU_SENDOOB: - case PRU_SOCKADDR: - case PRU_PEERADDR: - error = EOPNOTSUPP; - break; - - default: - panic("rip_usrreq"); - } - -/* release: */ - splx(s); - return (error); -} - -static int *mpls_sysvars[] = MPLSCTL_VARS; - -int -mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, - size_t newlen) -{ - if (name[0] >= MPLSCTL_MAXID) - return EOPNOTSUPP; - if (!mpls_sysvars[name[0]]) - return EOPNOTSUPP; - -#ifdef MPLS_DEBUG - printf("mpls_sysctl\n"); -#endif /* MPLS_DEBUG */ - - switch (name[0]) { - default: - return sysctl_int(oldp, oldlenp, newp, newlen, - mpls_sysvars[name[0]]); - } -} - diff --git a/sys/netmpls/mpls_shim.c b/sys/netmpls/mpls_shim.c index 57df3b4f1ce..9d4cc6f2b86 100644 --- a/sys/netmpls/mpls_shim.c +++ b/sys/netmpls/mpls_shim.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_shim.c,v 1.1 2008/04/23 11:00:35 norby Exp $ */ +/* $OpenBSD: mpls_shim.c,v 1.2 2008/04/23 11:22:23 norby Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -99,149 +99,3 @@ mpls_shim_push(struct mbuf *m, struct sockaddr_mpls *smplsp) return (mpls_shim_swap(m, smplsp)); } -/* - * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * - * $Id: mpls_shim.c,v 1.1 2008/04/23 11:00:35 norby Exp $ - */ - -#include <sys/param.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/errno.h> -#include <sys/socket.h> -#include <sys/systm.h> - -#include <net/if.h> -#include <net/route.h> - -#include <netmpls/mpls.h> -#include <netmpls/mpls_var.h> - -struct mbuf * -mpls_shim_pop(struct mbuf *m, struct sockaddr_mpls *smplsp, u_int32_t *labelp, - u_int8_t *bosp, u_int8_t *ttlp) -{ - u_int32_t label; - - /* shaves off top shim header from mbuf */ - m_adj(m, sizeof(struct shim_hdr)); - - /* catch-up next shim_hdr */ - if (m->m_len < sizeof(struct shim_hdr)) - if ((m = m_pullup(m, sizeof(struct shim_hdr))) == 0) - return(0); - - label = ntohl(*mtod(m, u_int32_t *)); - - /* set each values, if need */ - if (bosp) - *bosp = MPLS_SHIM_BOS_ISSET(label); - if (ttlp) - *ttlp = MPLS_SHIM_TTL_GET(label); - if (labelp) - *labelp = MPLS_SHIM_LABEL_GET(label); - if (smplsp) { - bzero(smplsp, sizeof(*smplsp)); - smplsp->smpls_family = AF_MPLS; - smplsp->smpls_len = sizeof(*smplsp); - smplsp->smpls_in_label = MPLS_SHIM_LABEL_GET(label); - } - - /* return mbuf */ - return(m); -} - -struct mbuf * -mpls_shim_swap(struct mbuf *m, struct sockaddr_mpls *smplsp, u_int32_t *labelp) -{ - struct shim_hdr *shim; - u_int32_t label; - - /* pullup shim_hdr */ - if (m->m_len < sizeof(struct shim_hdr)) /* XXX isn't this - already checked by mpls_shim_peep ? */ - if ((m = m_pullup(m, sizeof(struct shim_hdr))) == 0) - return(0); - shim = mtod(m, struct shim_hdr *); - shim->shim_label = ntohl(shim->shim_label); - - if (smplsp == NULL && labelp == NULL) - /* can't swap, because no dst label */ - return(m); /* XXX discard? XXX */ - - if (labelp) { - label = *labelp; - /* - if (smplsp) - smplsp->smpls_in_label = htonl(*labelp); - */ - } else - label = ntohl(smplsp->smpls_in_label); - - /* shim swap label */ - shim->shim_label &= ~SHIM_LABEL_MASK; - shim->shim_label |= MPLS_SHIM_LABEL_GET(label) << SHIM_LABEL_OFFSET; - - /* shim swap exp : XXX exp override */ - if (smplsp) { - shim->shim_label &= ~SHIM_EXP_MASK; - shim->shim_label |= - smplsp->smpls_out_exp << SHIM_EXP_OFFSET & SHIM_EXP_MASK; - } - shim->shim_label = htonl(shim->shim_label); - - return(m); -} - -struct mbuf * -mpls_shim_push(struct mbuf *m, struct sockaddr_mpls *smplsp, u_int32_t *labelp, - u_int8_t *bosp, u_int8_t *ttlp) -{ - struct shim_hdr *shim; - - M_PREPEND(m, sizeof(struct shim_hdr), M_DONTWAIT); - if (m == 0) - return(0); - - shim = mtod(m, struct shim_hdr *); - bzero((caddr_t)shim, sizeof(*shim)); - - if (bosp && *bosp) - shim->shim_label |= SHIM_BOS_MASK; - if (ttlp) - shim->shim_label |= *ttlp & SHIM_TTL_MASK; - else - shim->shim_label |= 255; /* XXX */ - m = mpls_shim_swap(m, smplsp, labelp); - - return m; -} |