1 /*- 2 * Copyright (c) 1982, 1986 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)protosw.h 7.8 (Berkeley) 04/28/91 8 */ 9 10 /* 11 * Protocol switch table. 12 * 13 * Each protocol has a handle initializing one of these structures, 14 * which is used for protocol-protocol and system-protocol communication. 15 * 16 * A protocol is called through the pr_init entry before any other. 17 * Thereafter it is called every 200ms through the pr_fasttimo entry and 18 * every 500ms through the pr_slowtimo for timer based actions. 19 * The system will call the pr_drain entry if it is low on space and 20 * this should throw away any non-critical data. 21 * 22 * Protocols pass data between themselves as chains of mbufs using 23 * the pr_input and pr_output hooks. Pr_input passes data up (towards 24 * UNIX) and pr_output passes it down (towards the imps); control 25 * information passes up and down on pr_ctlinput and pr_ctloutput. 26 * The protocol is responsible for the space occupied by any the 27 * arguments to these entries and must dispose it. 28 * 29 * The userreq routine interfaces protocols to the system and is 30 * described below. 31 */ 32 struct protosw { 33 short pr_type; /* socket type used for */ 34 struct domain *pr_domain; /* domain protocol a member of */ 35 short pr_protocol; /* protocol number */ 36 short pr_flags; /* see below */ 37 /* protocol-protocol hooks */ 38 int (*pr_input)(); /* input to protocol (from below) */ 39 int (*pr_output)(); /* output to protocol (from above) */ 40 int (*pr_ctlinput)(); /* control input (from below) */ 41 int (*pr_ctloutput)(); /* control output (from above) */ 42 /* user-protocol hook */ 43 int (*pr_usrreq)(); /* user request: see list below */ 44 /* utility hooks */ 45 int (*pr_init)(); /* initialization hook */ 46 int (*pr_fasttimo)(); /* fast timeout (200ms) */ 47 int (*pr_slowtimo)(); /* slow timeout (500ms) */ 48 int (*pr_drain)(); /* flush any excess space possible */ 49 }; 50 51 #define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 52 #define PR_FASTHZ 5 /* 5 fast timeouts per second */ 53 54 /* 55 * Values for pr_flags. 56 * PR_ADDR requires PR_ATOMIC; 57 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. 58 */ 59 #define PR_ATOMIC 0x01 /* exchange atomic messages only */ 60 #define PR_ADDR 0x02 /* addresses given with messages */ 61 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 62 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 63 #define PR_RIGHTS 0x10 /* passes capabilities */ 64 65 /* 66 * The arguments to usrreq are: 67 * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 68 * where up is a (struct socket *), req is one of these requests, 69 * m is a optional mbuf chain containing a message, 70 * nam is an optional mbuf chain containing an address, 71 * and opt is a pointer to a socketopt structure or nil. 72 * The protocol is responsible for disposal of the mbuf chain m, 73 * the caller is responsible for any space held by nam and opt. 74 * A non-zero return from usrreq gives an 75 * UNIX error number which should be passed to higher level software. 76 */ 77 #define PRU_ATTACH 0 /* attach protocol to up */ 78 #define PRU_DETACH 1 /* detach protocol from up */ 79 #define PRU_BIND 2 /* bind socket to address */ 80 #define PRU_LISTEN 3 /* listen for connection */ 81 #define PRU_CONNECT 4 /* establish connection to peer */ 82 #define PRU_ACCEPT 5 /* accept connection from peer */ 83 #define PRU_DISCONNECT 6 /* disconnect from peer */ 84 #define PRU_SHUTDOWN 7 /* won't send any more data */ 85 #define PRU_RCVD 8 /* have taken data; more room now */ 86 #define PRU_SEND 9 /* send this data */ 87 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 88 #define PRU_CONTROL 11 /* control operations on protocol */ 89 #define PRU_SENSE 12 /* return status into m */ 90 #define PRU_RCVOOB 13 /* retrieve out of band data */ 91 #define PRU_SENDOOB 14 /* send out of band data */ 92 #define PRU_SOCKADDR 15 /* fetch socket's address */ 93 #define PRU_PEERADDR 16 /* fetch peer's address */ 94 #define PRU_CONNECT2 17 /* connect two sockets */ 95 /* begin for protocols internal use */ 96 #define PRU_FASTTIMO 18 /* 200ms timeout */ 97 #define PRU_SLOWTIMO 19 /* 500ms timeout */ 98 #define PRU_PROTORCV 20 /* receive from below */ 99 #define PRU_PROTOSEND 21 /* send to below */ 100 101 #define PRU_NREQ 21 102 103 #ifdef PRUREQUESTS 104 char *prurequests[] = { 105 "ATTACH", "DETACH", "BIND", "LISTEN", 106 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 107 "RCVD", "SEND", "ABORT", "CONTROL", 108 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 109 "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", 110 "PROTORCV", "PROTOSEND", 111 }; 112 #endif 113 114 /* 115 * The arguments to the ctlinput routine are 116 * (*protosw[].pr_ctlinput)(cmd, sa, arg); 117 * where cmd is one of the commands below, sa is a pointer to a sockaddr, 118 * and arg is an optional caddr_t argument used within a protocol family. 119 */ 120 #define PRC_IFDOWN 0 /* interface transition */ 121 #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ 122 #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ 123 #define PRC_QUENCH 4 /* some one said to slow down */ 124 #define PRC_MSGSIZE 5 /* message size forced drop */ 125 #define PRC_HOSTDEAD 6 /* host appears to be down */ 126 #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ 127 #define PRC_UNREACH_NET 8 /* no route to network */ 128 #define PRC_UNREACH_HOST 9 /* no route to host */ 129 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 130 #define PRC_UNREACH_PORT 11 /* bad port # */ 131 /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ 132 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */ 133 #define PRC_REDIRECT_NET 14 /* net routing redirect */ 134 #define PRC_REDIRECT_HOST 15 /* host routing redirect */ 135 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ 136 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ 137 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ 138 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ 139 #define PRC_PARAMPROB 20 /* header incorrect */ 140 141 #define PRC_NCMDS 21 142 143 #define PRC_IS_REDIRECT(cmd) \ 144 ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) 145 146 #ifdef PRCREQUESTS 147 char *prcrequests[] = { 148 "IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2", 149 "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", 150 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 151 "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", 152 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", 153 "PARAMPROB" 154 }; 155 #endif 156 157 /* 158 * The arguments to ctloutput are: 159 * (*protosw[].pr_ctloutput)(req, so, level, optname, optval); 160 * req is one of the actions listed below, so is a (struct socket *), 161 * level is an indication of which protocol layer the option is intended. 162 * optname is a protocol dependent socket option request, 163 * optval is a pointer to a mbuf-chain pointer, for value-return results. 164 * The protocol is responsible for disposal of the mbuf chain *optval 165 * if supplied, 166 * the caller is responsible for any space held by *optval, when returned. 167 * A non-zero return from usrreq gives an 168 * UNIX error number which should be passed to higher level software. 169 */ 170 #define PRCO_GETOPT 0 171 #define PRCO_SETOPT 1 172 173 #define PRCO_NCMDS 2 174 175 #ifdef PRCOREQUESTS 176 char *prcorequests[] = { 177 "GETOPT", "SETOPT", 178 }; 179 #endif 180 181 #ifdef KERNEL 182 extern struct protosw *pffindproto(), *pffindtype(); 183 #endif 184