1 /* $OpenBSD: mpls_raw.c,v 1.4 2008/11/01 16:37:55 michele Exp $ */ 2 3 /* 4 * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #include <sys/param.h> 34 #include <sys/malloc.h> 35 #include <sys/mbuf.h> 36 #include <sys/errno.h> 37 #include <sys/protosw.h> 38 #include <sys/sockio.h> 39 #include <sys/socket.h> 40 #include <sys/socketvar.h> 41 #include <sys/systm.h> 42 #include <sys/sysctl.h> 43 44 #include <net/if.h> 45 #include <net/if_types.h> 46 #include <net/route.h> 47 48 #include <netmpls/mpls.h> 49 50 #define MPLS_RAW_SNDQ 8192 51 #define MPLS_RAW_RCVQ 8192 52 53 u_long mpls_raw_sendspace = MPLS_RAW_SNDQ; 54 u_long mpls_raw_recvspace = MPLS_RAW_RCVQ; 55 56 int mpls_enable = 0; 57 int mpls_defttl = 255; 58 int mpls_inkloop = 16; 59 int mpls_push_expnull_ip = 0; 60 int mpls_push_expnull_ip6 = 0; 61 int mpls_mapttl_ip = 1; 62 int mpls_mapttl_ip6 = 0; 63 64 int *mplsctl_vars[MPLSCTL_MAXID] = MPLSCTL_VARS; 65 66 int mpls_control(struct socket *, u_long, caddr_t, struct ifnet *); 67 68 /* 69 * Generic MPLS control operations (ioctl's). 70 * Ifp is 0 if not an interface-specific ioctl. 71 */ 72 /* ARGSUSED */ 73 int 74 mpls_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) 75 { 76 return (EOPNOTSUPP); 77 } 78 79 int 80 mpls_raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, 81 struct mbuf *control, struct proc *p) 82 { 83 int error = 0; 84 85 #ifdef MPLS_DEBUG 86 printf("mpls_raw_usrreq: called! (reqid=%d).\n", req); 87 #endif /* MPLS_DEBUG */ 88 89 if (req == PRU_CONTROL) 90 return (mpls_control(so, (u_long)m, (caddr_t)nam, 91 (struct ifnet *)control)); 92 93 switch (req) { 94 case PRU_ATTACH: 95 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { 96 error = soreserve(so, mpls_raw_sendspace, 97 mpls_raw_recvspace); 98 if (error) 99 break; 100 } 101 break; 102 103 case PRU_DETACH: 104 case PRU_BIND: 105 case PRU_LISTEN: 106 case PRU_CONNECT: 107 case PRU_CONNECT2: 108 case PRU_DISCONNECT: 109 case PRU_SHUTDOWN: 110 case PRU_RCVD: 111 case PRU_SEND: 112 case PRU_SENSE: 113 case PRU_RCVOOB: 114 case PRU_SENDOOB: 115 case PRU_SOCKADDR: 116 case PRU_PEERADDR: 117 error = EOPNOTSUPP; 118 break; 119 120 default: 121 panic("rip_usrreq"); 122 } 123 124 return (error); 125 } 126 127 int 128 mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, 129 size_t newlen) 130 { 131 if (name[0] >= MPLSCTL_MAXID) 132 return (EOPNOTSUPP); 133 134 /* Almost all sysctl names at this level are terminal. */ 135 if (namelen != 1 && name[0] != MPLSCTL_IFQUEUE) 136 return (ENOTDIR); 137 138 switch (name[0]) { 139 case MPLSCTL_IFQUEUE: 140 return (sysctl_ifq(name + 1, namelen - 1, 141 oldp, oldlenp, newp, newlen, &mplsintrq)); 142 default: 143 return sysctl_int_arr(mplsctl_vars, name, namelen, 144 oldp, oldlenp, newp, newlen); 145 } 146 } 147