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