root/sys/protosw.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */