1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1991 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #ifndef _SYS_PROTOSW_H 41 #define _SYS_PROTOSW_H 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /* 48 * Protocol switch table. 49 * 50 * Each protocol has a handle initializing one of these structures, 51 * which is used for protocol-protocol and system-protocol communication. 52 * 53 * A protocol is called through the pr_init entry before any other. 54 * Thereafter it is called every 200ms through the pr_fasttimo entry and 55 * every 500ms through the pr_slowtimo for timer based actions. 56 * The system will call the pr_drain entry if it is low on space and 57 * this should throw away any non-critical data. 58 * 59 * Protocols pass data between themselves as chains of mbufs using 60 * the pr_input and pr_output hooks. Pr_input passes data up (towards 61 * UNIX) and pr_output passes it down (towards the imps); control 62 * information passes up and down on pr_ctlinput and pr_ctloutput. 63 * The protocol is responsible for the space occupied by any the 64 * arguments to these entries and must dispose it. 65 * 66 * The userreq routine interfaces protocols to the system and is 67 * described below. 68 */ 69 struct protosw { 70 short pr_type; /* socket type used for */ 71 struct domain *pr_domain; /* domain protocol a member of */ 72 short pr_protocol; /* protocol number */ 73 short pr_flags; /* see below */ 74 /* protocol-protocol hooks */ 75 int (*pr_input)(); /* input to protocol (from below) */ 76 int (*pr_output)(); /* output to protocol (from above) */ 77 int (*pr_ctlinput)(); /* control input (from below) */ 78 int (*pr_ctloutput)(); /* control output (from above) */ 79 /* user-protocol hook */ 80 int (*pr_usrreq)(); /* user request: see list below */ 81 /* utility hooks */ 82 int (*pr_init)(); /* initialization hook */ 83 int (*pr_fasttimo)(); /* fast timeout (200ms) */ 84 int (*pr_slowtimo)(); /* slow timeout (500ms) */ 85 int (*pr_drain)(); /* flush any excess space possible */ 86 }; 87 88 #define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 89 #define PR_FASTHZ 5 /* 5 fast timeouts per second */ 90 91 /* 92 * Values for pr_flags 93 */ 94 #define PR_ATOMIC 0x01 /* exchange atomic messages only */ 95 #define PR_ADDR 0x02 /* addresses given with messages */ 96 /* in the current implementation, PR_ADDR needs PR_ATOMIC to work */ 97 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 98 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 99 #define PR_RIGHTS 0x10 /* passes capabilities */ 100 #define PR_OOB_ADDR 0x20 /* addresses given with OOB data */ 101 102 /* 103 * The arguments to usrreq are: 104 * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 105 * where up is a (struct socket *), req is one of these requests, 106 * m is a optional mbuf chain containing a message, 107 * nam is an optional mbuf chain containing an address, 108 * and opt is a pointer to a socketopt structure or nil. 109 * The protocol is responsible for disposal of the mbuf chain m, 110 * the caller is responsible for any space held by nam and opt. 111 * A non-zero return from usrreq gives an 112 * UNIX error number which should be passed to higher level software. 113 */ 114 #define PRU_ATTACH 0 /* attach protocol to up */ 115 #define PRU_DETACH 1 /* detach protocol from up */ 116 #define PRU_BIND 2 /* bind socket to address */ 117 #define PRU_LISTEN 3 /* listen for connection */ 118 #define PRU_CONNECT 4 /* establish connection to peer */ 119 #define PRU_ACCEPT 5 /* accept connection from peer */ 120 #define PRU_DISCONNECT 6 /* disconnect from peer */ 121 #define PRU_SHUTDOWN 7 /* won't send any more data */ 122 #define PRU_RCVD 8 /* have taken data; more room now */ 123 #define PRU_SEND 9 /* send this data */ 124 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 125 #define PRU_CONTROL 11 /* control operations on protocol */ 126 #define PRU_SENSE 12 /* return status into m */ 127 #define PRU_RCVOOB 13 /* retrieve out of band data */ 128 #define PRU_SENDOOB 14 /* send out of band data */ 129 #define PRU_SOCKADDR 15 /* fetch socket's address */ 130 #define PRU_PEERADDR 16 /* fetch peer's address */ 131 #define PRU_CONNECT2 17 /* connect two sockets */ 132 /* begin for protocols internal use */ 133 #define PRU_FASTTIMO 18 /* 200ms timeout */ 134 #define PRU_SLOWTIMO 19 /* 500ms timeout */ 135 #define PRU_PROTORCV 20 /* receive from below */ 136 #define PRU_PROTOSEND 21 /* send to below */ 137 138 #define PRU_NREQ 21 139 140 #ifdef PRUREQUESTS 141 char *prurequests[] = { 142 "ATTACH", "DETACH", "BIND", "LISTEN", 143 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 144 "RCVD", "SEND", "ABORT", "CONTROL", 145 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 146 "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", 147 "PROTORCV", "PROTOSEND", 148 }; 149 #endif 150 151 /* 152 * The arguments to the ctlinput routine are 153 * (*protosw[].pr_ctlinput)(cmd, arg); 154 * where cmd is one of the commands below, and arg is 155 * an optional argument (caddr_t). 156 * 157 * N.B. The IMP code, in particular, pressumes the values 158 * of some of the commands; change with extreme care. 159 * TODO: 160 * spread out codes so new ICMP codes can be 161 * accomodated more easily 162 */ 163 #define PRC_IFDOWN 0 /* interface transition */ 164 #define PRC_ROUTEDEAD 1 /* select new route if possible */ 165 #define PRC_QUENCH 4 /* some said to slow down */ 166 #define PRC_MSGSIZE 5 /* message size forced drop */ 167 #define PRC_HOSTDEAD 6 /* normally from IMP */ 168 #define PRC_HOSTUNREACH 7 /* ditto */ 169 #define PRC_UNREACH_NET 8 /* no route to network */ 170 #define PRC_UNREACH_HOST 9 /* no route to host */ 171 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 172 #define PRC_UNREACH_PORT 11 /* bad port # */ 173 #define PRC_UNREACH_NEEDFRAG 12 /* IP_DF caused drop */ 174 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */ 175 #define PRC_REDIRECT_NET 14 /* net routing redirect */ 176 #define PRC_REDIRECT_HOST 15 /* host routing redirect */ 177 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ 178 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ 179 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ 180 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ 181 #define PRC_PARAMPROB 20 /* header incorrect */ 182 #define PRC_GWDOWN 21 /* gateway down */ 183 184 #define PRC_NCMDS 22 185 186 #ifdef PRCREQUESTS 187 char *prcrequests[] = { 188 "IFDOWN", "ROUTEDEAD", "#2", "#3", 189 "QUENCH", "MSGSIZE", "HOSTDEAD", "HOSTUNREACH", 190 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 191 "FRAG-UNREACH", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", 192 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", 193 "PARAMPROB" 194 }; 195 #endif 196 197 /* 198 * The arguments to ctloutput are: 199 * (*protosw[].pr_ctloutput)(req, so, level, optname, optval); 200 * req is one of the actions listed below, so is a (struct socket *), 201 * level is an indication of which protocol layer the option is intended. 202 * optname is a protocol dependent socket option request, 203 * optval is a pointer to a mbuf-chain pointer, for value-return results. 204 * The protocol is responsible for disposal of the mbuf chain *optval 205 * if supplied, 206 * the caller is responsible for any space held by *optval, when returned. 207 * A non-zero return from usrreq gives an 208 * UNIX error number which should be passed to higher level software. 209 */ 210 #define PRCO_GETOPT 0 211 #define PRCO_SETOPT 1 212 213 #define PRCO_NCMDS 2 214 215 #ifdef PRCOREQUESTS 216 char *prcorequests[] = { 217 "GETOPT", "SETOPT", 218 }; 219 #endif 220 221 #ifdef _KERNEL 222 extern struct protosw *pffindproto(), *pffindtype(); 223 #endif 224 225 #ifdef __cplusplus 226 } 227 #endif 228 229 #endif /* _SYS_PROTOSW_H */ 230