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