1 /* protosw.h 4.15 83/05/27 */ 2 3 /* 4 * Protocol switch table. 5 * 6 * Each protocol has a handle initializing one of these structures, 7 * which is used for protocol-protocol and system-protocol communication. 8 * 9 * A protocol is called through the pr_init entry before any other. 10 * Thereafter it is called every 200ms through the pr_fasttimo entry and 11 * every 500ms through the pr_slowtimo for timer based actions. 12 * The system will call the pr_drain entry if it is low on space and 13 * this should throw away any non-critical data. 14 * 15 * Protocols pass data between themselves as chains of mbufs using 16 * the pr_input and pr_output hooks. Pr_input passes data up (towards 17 * UNIX) and pr_output passes it down (towards the imps); control 18 * information passes up and down on pr_ctlinput and pr_ctloutput. 19 * The protocol is responsible for the space occupied by any the 20 * arguments to these entries and must dispose it. 21 * 22 * The userreq routine interfaces protocols to the system and is 23 * described below. 24 */ 25 struct protosw { 26 short pr_type; /* socket type used for */ 27 short pr_family; /* protocol family */ 28 short pr_protocol; /* protocol number */ 29 short pr_flags; /* see below */ 30 /* protocol-protocol hooks */ 31 int (*pr_input)(); /* input to protocol (from below) */ 32 int (*pr_output)(); /* output to protocol (from above) */ 33 int (*pr_ctlinput)(); /* control input (from below) */ 34 int (*pr_ctloutput)(); /* control output (from above) */ 35 /* user-protocol hook */ 36 int (*pr_usrreq)(); /* user request: see list below */ 37 /* utility hooks */ 38 int (*pr_init)(); /* initialization hook */ 39 int (*pr_fasttimo)(); /* fast timeout (200ms) */ 40 int (*pr_slowtimo)(); /* slow timeout (500ms) */ 41 int (*pr_drain)(); /* flush any excess space possible */ 42 }; 43 44 #define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 45 #define PR_FASTHZ 5 /* 5 fast timeouts per second */ 46 47 /* 48 * Values for pr_flags 49 */ 50 #define PR_ATOMIC 0x01 /* exchange atomic messages only */ 51 #define PR_ADDR 0x02 /* addresses given with messages */ 52 /* in the current implementation, PR_ADDR needs PR_ATOMIC to work */ 53 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 54 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 55 #define PR_RIGHTS 0x10 /* passes capabilities */ 56 57 /* 58 * The arguments to usrreq are: 59 * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 60 * where up is a (struct socket *), req is one of these requests, 61 * m is a optional mbuf chain containing a message, 62 * nam is an optional mbuf chain containing an address, 63 * and opt is a pointer to a socketopt structure or nil. 64 * The protocol is responsible for disposal of the mbuf chain m, 65 * the caller is responsible for any space held by nam and opt. 66 * A non-zero return from usrreq gives an 67 * UNIX error number which should be passed to higher level software. 68 */ 69 #define PRU_ATTACH 0 /* attach protocol to up */ 70 #define PRU_DETACH 1 /* detach protocol from up */ 71 #define PRU_BIND 2 /* bind socket to address */ 72 #define PRU_LISTEN 3 /* listen for connection */ 73 #define PRU_CONNECT 4 /* establish connection to peer */ 74 #define PRU_ACCEPT 5 /* accept connection from peer */ 75 #define PRU_DISCONNECT 6 /* disconnect from peer */ 76 #define PRU_SHUTDOWN 7 /* won't send any more data */ 77 #define PRU_RCVD 8 /* have taken data; more room now */ 78 #define PRU_SEND 9 /* send this data */ 79 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 80 #define PRU_CONTROL 11 /* control operations on protocol */ 81 #define PRU_SENSE 12 /* return status into m */ 82 #define PRU_RCVOOB 13 /* retrieve out of band data */ 83 #define PRU_SENDOOB 14 /* send out of band data */ 84 #define PRU_SOCKADDR 15 /* fetch socket's address */ 85 /* begin for protocols internal use */ 86 #define PRU_FASTTIMO 16 /* 200ms timeout */ 87 #define PRU_SLOWTIMO 17 /* 500ms timeout */ 88 #define PRU_PROTORCV 18 /* receive from below */ 89 #define PRU_PROTOSEND 19 /* send to below */ 90 91 #define PRU_NREQ 20 92 93 #ifdef PRUREQUESTS 94 char *prurequests[] = { 95 "ATTACH", "DETACH", "BIND", "LISTEN", 96 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 97 "RCVD", "SEND", "ABORT", "CONTROL", 98 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 99 "FASTTIMO", "SLOWTIMO", "PROTORCV", "PROTOSEND", 100 }; 101 #endif 102 103 /* 104 * The arguments to the ctlinput routine are 105 * (*protosw[].pr_ctlinput)(cmd, arg); 106 * where cmd is one of the commands below, and arg is 107 * an optional argument (caddr_t). 108 * 109 * N.B. The IMP code, in particular, pressumes the values 110 * of some of the commands; change with extreme care. 111 * TODO: 112 * spread out codes so new ICMP codes can be 113 * accomodated more easily 114 */ 115 #define PRC_IFDOWN 0 /* interface transition */ 116 #define PRC_ROUTEDEAD 1 /* select new route if possible */ 117 #define PRC_QUENCH 4 /* some said to slow down */ 118 #define PRC_MSGSIZE 5 /* message size forced drop */ 119 #define PRC_HOSTDEAD 6 /* normally from IMP */ 120 #define PRC_HOSTUNREACH 7 /* ditto */ 121 #define PRC_UNREACH_NET 8 /* no route to network */ 122 #define PRC_UNREACH_HOST 9 /* no route to host */ 123 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 124 #define PRC_UNREACH_PORT 11 /* bad port # */ 125 #define PRC_UNREACH_SRCFAIL 12 /* source route failed */ 126 #define PRC_REDIRECT_NET 13 /* net routing redirect */ 127 #define PRC_REDIRECT_HOST 14 /* host routing redirect */ 128 #define PRC_REDIRECT_TOSNET 15 /* redirect for type of service & net */ 129 #define PRC_REDIRECT_TOSHOST 16 /* redirect for tos & host */ 130 #define PRC_TIMXCEED_INTRANS 17 /* packet lifetime expired in transit */ 131 #define PRC_TIMXCEED_REASS 18 /* lifetime expired on reass q */ 132 #define PRC_PARAMPROB 19 /* header incorrect */ 133 134 #define PRC_NCMDS 20 135 136 #ifdef PRCREQUESTS 137 char *prcrequests[] = { 138 "IFDOWN", "ROUTEDEAD", "#2", "#3", 139 "QUENCH", "MSGSIZE", "HOSTDEAD", "HOSTUNREACH", 140 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 141 "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", "TOSNET-REDIRECT", 142 "TOSHOST-REDIRECT","TX-INTRANS", "TX-REASS", "PARAMPROB" 143 }; 144 #endif 145 146 #ifdef KERNEL 147 extern struct protosw *pffindproto(), *pffindtype(); 148 #endif 149