protosw.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* $OpenBSD: protosw.h,v 1.18 2013/04/24 10:17:08 mpi Exp $ */
  2. /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */
  3. /*-
  4. * Copyright (c) 1982, 1986, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)protosw.h 8.1 (Berkeley) 6/2/93
  32. */
  33. /*
  34. * Protocol switch table.
  35. *
  36. * Each protocol has a handle initializing one of these structures,
  37. * which is used for protocol-protocol and system-protocol communication.
  38. *
  39. * A protocol is called through the pr_init entry before any other.
  40. * Thereafter it is called every 200ms through the pr_fasttimo entry and
  41. * every 500ms through the pr_slowtimo for timer based actions.
  42. * The system will call the pr_drain entry if it is low on space and
  43. * this should throw away any non-critical data.
  44. *
  45. * Protocols pass data between themselves as chains of mbufs using
  46. * the pr_input and pr_output hooks. Pr_input passes data up (towards
  47. * UNIX) and pr_output passes it down (towards the imps); control
  48. * information passes up and down on pr_ctlinput and pr_ctloutput.
  49. * The protocol is responsible for the space occupied by any the
  50. * arguments to these entries and must dispose it.
  51. *
  52. * The userreq routine interfaces protocols to the system and is
  53. * described below.
  54. */
  55. struct mbuf;
  56. struct sockaddr;
  57. struct socket;
  58. struct domain;
  59. struct proc;
  60. struct protosw {
  61. short pr_type; /* socket type used for */
  62. struct domain *pr_domain; /* domain protocol a member of */
  63. short pr_protocol; /* protocol number */
  64. short pr_flags; /* see below */
  65. /* protocol-protocol hooks */
  66. /* input to protocol (from below) */
  67. void (*pr_input)(struct mbuf *, ...);
  68. /* output to protocol (from above) */
  69. int (*pr_output)(struct mbuf *, ...);
  70. /* control input (from below) */
  71. void *(*pr_ctlinput)(int, struct sockaddr *, u_int, void *);
  72. /* control output (from above) */
  73. int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf **);
  74. /* user-protocol hook */
  75. /* user request: see list below */
  76. int (*pr_usrreq)(struct socket *, int, struct mbuf *,
  77. struct mbuf *, struct mbuf *, struct proc *);
  78. /* utility hooks */
  79. void (*pr_init)(void); /* initialization hook */
  80. void (*pr_fasttimo)(void); /* fast timeout (200ms) */
  81. void (*pr_slowtimo)(void); /* slow timeout (500ms) */
  82. void (*pr_drain)(void); /* flush any excess space possible */
  83. /* sysctl for protocol */
  84. int (*pr_sysctl)(int *, u_int, void *, size_t *, void *, size_t);
  85. };
  86. #define PR_SLOWHZ 2 /* 2 slow timeouts per second */
  87. #define PR_FASTHZ 5 /* 5 fast timeouts per second */
  88. /*
  89. * Values for pr_flags.
  90. * PR_ADDR requires PR_ATOMIC;
  91. * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
  92. */
  93. #define PR_ATOMIC 0x01 /* exchange atomic messages only */
  94. #define PR_ADDR 0x02 /* addresses given with messages */
  95. #define PR_CONNREQUIRED 0x04 /* connection required by protocol */
  96. #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
  97. #define PR_RIGHTS 0x10 /* passes capabilities */
  98. #define PR_ABRTACPTDIS 0x20 /* abort on accept(2) to disconnected
  99. socket */
  100. #define PR_SPLICE 0x40 /* socket splicing is possible */
  101. /*
  102. * The arguments to usrreq are:
  103. * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
  104. * where up is a (struct socket *), req is one of these requests,
  105. * m is a optional mbuf chain containing a message,
  106. * nam is an optional mbuf chain containing an address,
  107. * and opt is a pointer to a socketopt structure or nil.
  108. * The protocol is responsible for disposal of the mbuf chain m,
  109. * the caller is responsible for any space held by nam and opt.
  110. * A non-zero return from usrreq gives an
  111. * UNIX error number which should be passed to higher level software.
  112. */
  113. #define PRU_ATTACH 0 /* attach protocol to up */
  114. #define PRU_DETACH 1 /* detach protocol from up */
  115. #define PRU_BIND 2 /* bind socket to address */
  116. #define PRU_LISTEN 3 /* listen for connection */
  117. #define PRU_CONNECT 4 /* establish connection to peer */
  118. #define PRU_ACCEPT 5 /* accept connection from peer */
  119. #define PRU_DISCONNECT 6 /* disconnect from peer */
  120. #define PRU_SHUTDOWN 7 /* won't send any more data */
  121. #define PRU_RCVD 8 /* have taken data; more room now */
  122. #define PRU_SEND 9 /* send this data */
  123. #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETACH) */
  124. #define PRU_CONTROL 11 /* control operations on protocol */
  125. #define PRU_SENSE 12 /* return status into m */
  126. #define PRU_RCVOOB 13 /* retrieve out of band data */
  127. #define PRU_SENDOOB 14 /* send out of band data */
  128. #define PRU_SOCKADDR 15 /* fetch socket's address */
  129. #define PRU_PEERADDR 16 /* fetch peer's address */
  130. #define PRU_CONNECT2 17 /* connect two sockets */
  131. /* begin for protocols internal use */
  132. #define PRU_FASTTIMO 18 /* 200ms timeout */
  133. #define PRU_SLOWTIMO 19 /* 500ms timeout */
  134. #define PRU_PROTORCV 20 /* receive from below */
  135. #define PRU_PROTOSEND 21 /* send to below */
  136. #define PRU_NREQ 22
  137. #ifdef PRUREQUESTS
  138. char *prurequests[] = {
  139. "ATTACH", "DETACH", "BIND", "LISTEN",
  140. "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
  141. "RCVD", "SEND", "ABORT", "CONTROL",
  142. "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
  143. "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
  144. "PROTORCV", "PROTOSEND",
  145. };
  146. #endif
  147. /*
  148. * The arguments to the ctlinput routine are
  149. * (*protosw[].pr_ctlinput)(cmd, sa, arg);
  150. * where cmd is one of the commands below, sa is a pointer to a sockaddr,
  151. * and arg is an optional caddr_t argument used within a protocol family.
  152. */
  153. #define PRC_IFDOWN 0 /* interface transition */
  154. #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
  155. #define PRC_MTUINC 2 /* increase in mtu to host */
  156. #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
  157. #define PRC_QUENCH 4 /* some one said to slow down */
  158. #define PRC_MSGSIZE 5 /* message size forced drop */
  159. #define PRC_HOSTDEAD 6 /* host appears to be down */
  160. #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
  161. #define PRC_UNREACH_NET 8 /* no route to network */
  162. #define PRC_UNREACH_HOST 9 /* no route to host */
  163. #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
  164. #define PRC_UNREACH_PORT 11 /* bad port # */
  165. /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
  166. #define PRC_UNREACH_SRCFAIL 13 /* source route failed */
  167. #define PRC_REDIRECT_NET 14 /* net routing redirect */
  168. #define PRC_REDIRECT_HOST 15 /* host routing redirect */
  169. #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
  170. #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
  171. #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
  172. #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
  173. #define PRC_PARAMPROB 20 /* header incorrect */
  174. #define PRC_NCMDS 21
  175. #define PRC_IS_REDIRECT(cmd) \
  176. ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
  177. #ifdef PRCREQUESTS
  178. char *prcrequests[] = {
  179. "IFDOWN", "ROUTEDEAD", "MTUINC", "DEC-BIT-QUENCH2",
  180. "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
  181. "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
  182. "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
  183. "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
  184. "PARAMPROB"
  185. };
  186. #endif
  187. /*
  188. * The arguments to ctloutput are:
  189. * (*protosw[].pr_ctloutput)(req, so, level, optname, optval);
  190. * req is one of the actions listed below, so is a (struct socket *),
  191. * level is an indication of which protocol layer the option is intended.
  192. * optname is a protocol dependent socket option request,
  193. * optval is a pointer to a mbuf-chain pointer, for value-return results.
  194. * The protocol is responsible for disposal of the mbuf chain *optval
  195. * if supplied,
  196. * the caller is responsible for any space held by *optval, when returned.
  197. * A non-zero return from usrreq gives an
  198. * UNIX error number which should be passed to higher level software.
  199. */
  200. #define PRCO_GETOPT 0
  201. #define PRCO_SETOPT 1
  202. #define PRCO_NCMDS 2
  203. #ifdef PRCOREQUESTS
  204. char *prcorequests[] = {
  205. "GETOPT", "SETOPT",
  206. };
  207. #endif
  208. #ifdef _KERNEL
  209. struct sockaddr;
  210. struct protosw *pffindproto(int, int, int);
  211. struct protosw *pffindtype(int, int);
  212. void pfctlinput(int, struct sockaddr *);
  213. extern u_char ip_protox[];
  214. extern struct protosw inetsw[];
  215. #endif