1 /* protosw.h 4.14 82/11/13 */ 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 56 /* 57 * The arguments to usrreq are: 58 * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 59 * where up is a (struct socket *), req is one of these requests, 60 * m is a optional mbuf chain containing a message, 61 * nam is an optional mbuf chain containing an address, 62 * and opt is a pointer to a socketopt structure or nil. 63 * The protocol is responsible for disposal of the mbuf chain m, 64 * the caller is responsible for any space held by nam and opt. 65 * A non-zero return from usrreq gives an 66 * UNIX error number which should be passed to higher level software. 67 */ 68 #define PRU_ATTACH 0 /* attach protocol to up */ 69 #define PRU_DETACH 1 /* detach protocol from up */ 70 #define PRU_BIND 2 /* bind socket to address */ 71 #define PRU_LISTEN 3 /* listen for connection */ 72 #define PRU_CONNECT 4 /* establish connection to peer */ 73 #define PRU_ACCEPT 5 /* accept connection from peer */ 74 #define PRU_DISCONNECT 6 /* disconnect from peer */ 75 #define PRU_SHUTDOWN 7 /* won't send any more data */ 76 #define PRU_RCVD 8 /* have taken data; more room now */ 77 #define PRU_SEND 9 /* send this data */ 78 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 79 #define PRU_CONTROL 11 /* control operations on protocol */ 80 #define PRU_SENSE 12 /* return status into m */ 81 #define PRU_RCVOOB 13 /* retrieve out of band data */ 82 #define PRU_SENDOOB 14 /* send out of band data */ 83 #define PRU_SOCKADDR 15 /* fetch socket's address */ 84 /* begin for protocols internal use */ 85 #define PRU_FASTTIMO 16 /* 200ms timeout */ 86 #define PRU_SLOWTIMO 17 /* 500ms timeout */ 87 #define PRU_PROTORCV 18 /* receive from below */ 88 #define PRU_PROTOSEND 19 /* send to below */ 89 90 #define PRU_NREQ 20 91 92 #ifdef PRUREQUESTS 93 char *prurequests[] = { 94 "ATTACH", "DETACH", "BIND", "LISTEN", 95 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 96 "RCVD", "SEND", "ABORT", "CONTROL", 97 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 98 "FASTTIMO", "SLOWTIMO", "PROTORCV", "PROTOSEND", 99 }; 100 #endif 101 102 /* 103 * The arguments to the ctlinput routine are 104 * (*protosw[].pr_ctlinput)(cmd, arg); 105 * where cmd is one of the commands below, and arg is 106 * an optional argument (caddr_t). 107 * 108 * N.B. The IMP code, in particular, pressumes the values 109 * of some of the commands; change with extreme care. 110 * TODO: 111 * spread out codes so new ICMP codes can be 112 * accomodated more easily 113 */ 114 #define PRC_IFDOWN 0 /* interface transition */ 115 #define PRC_ROUTEDEAD 1 /* select new route if possible */ 116 #define PRC_QUENCH 4 /* some said to slow down */ 117 #define PRC_MSGSIZE 5 /* message size forced drop */ 118 #define PRC_HOSTDEAD 6 /* normally from IMP */ 119 #define PRC_HOSTUNREACH 7 /* ditto */ 120 #define PRC_UNREACH_NET 8 /* no route to network */ 121 #define PRC_UNREACH_HOST 9 /* no route to host */ 122 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 123 #define PRC_UNREACH_PORT 11 /* bad port # */ 124 #define PRC_UNREACH_SRCFAIL 12 /* source route failed */ 125 #define PRC_REDIRECT_NET 13 /* net routing redirect */ 126 #define PRC_REDIRECT_HOST 14 /* host routing redirect */ 127 #define PRC_REDIRECT_TOSNET 15 /* redirect for type of service & net */ 128 #define PRC_REDIRECT_TOSHOST 16 /* redirect for tos & host */ 129 #define PRC_TIMXCEED_INTRANS 17 /* packet lifetime expired in transit */ 130 #define PRC_TIMXCEED_REASS 18 /* lifetime expired on reass q */ 131 #define PRC_PARAMPROB 19 /* header incorrect */ 132 133 #define PRC_NCMDS 20 134 135 #ifdef PRCREQUESTS 136 char *prcrequests[] = { 137 "IFDOWN", "ROUTEDEAD", "#2", "#3", 138 "QUENCH", "MSGSIZE", "HOSTDEAD", "HOSTUNREACH", 139 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 140 "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", "TOSNET-REDIRECT", 141 "TOSHOST-REDIRECT","TX-INTRANS", "TX-REASS", "PARAMPROB" 142 }; 143 #endif 144 145 #ifdef KERNEL 146 extern struct protosw *pffindproto(), *pffindtype(); 147 #endif 148