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