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