home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / sys / protosw.h < prev    next >
C/C++ Source or Header  |  1993-10-19  |  8KB  |  222 lines

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