The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/protosw.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: protosw.h,v 1.39 2006/08/27 23:55:16 christos Exp $    */
    2 
    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 #ifndef _SYS_PROTOSW_H_
   35 #define _SYS_PROTOSW_H_
   36 
   37 /*
   38  * Protocol switch table.
   39  *
   40  * Each protocol has a handle initializing one of these structures,
   41  * which is used for protocol-protocol and system-protocol communication.
   42  *
   43  * A protocol is called through the pr_init entry before any other.
   44  * Thereafter it is called every 200ms through the pr_fasttimo entry and
   45  * every 500ms through the pr_slowtimo for timer based actions.
   46  * The system will call the pr_drain entry if it is low on space and
   47  * this should throw away any non-critical data.
   48  *
   49  * Protocols pass data between themselves as chains of mbufs using
   50  * the pr_input and pr_output hooks.  Pr_input passes data up (towards
   51  * UNIX) and pr_output passes it down (towards the imps); control
   52  * information passes up and down on pr_ctlinput and pr_ctloutput.
   53  * The protocol is responsible for the space occupied by any the
   54  * arguments to these entries and must dispose it.
   55  *
   56  * The userreq routine interfaces protocols to the system and is
   57  * described below.
   58  */
   59 
   60 struct mbuf;
   61 struct sockaddr;
   62 struct socket;
   63 struct domain;
   64 struct proc;
   65 struct lwp;
   66 
   67 struct protosw {
   68         int     pr_type;                /* socket type used for */
   69         struct  domain *pr_domain;      /* domain protocol a member of */
   70         short   pr_protocol;            /* protocol number */
   71         short   pr_flags;               /* see below */
   72 
   73 /* protocol-protocol hooks */
   74         void    (*pr_input)             /* input to protocol (from below) */
   75                         (struct mbuf *, ...);
   76         int     (*pr_output)            /* output to protocol (from above) */
   77                         (struct mbuf *, ...);
   78         void    *(*pr_ctlinput)         /* control input (from below) */
   79                         (int, struct sockaddr *, void *);
   80         int     (*pr_ctloutput)         /* control output (from above) */
   81                         (int, struct socket *, int, int, struct mbuf **);
   82 
   83 /* user-protocol hook */
   84         int     (*pr_usrreq)            /* user request: see list below */
   85                         (struct socket *, int, struct mbuf *,
   86                              struct mbuf *, struct mbuf *, struct lwp *);
   87 
   88 /* utility hooks */
   89         void    (*pr_init)              /* initialization hook */
   90                         (void);
   91 
   92         void    (*pr_fasttimo)          /* fast timeout (200ms) */
   93                         (void);
   94         void    (*pr_slowtimo)          /* slow timeout (500ms) */
   95                         (void);
   96         void    (*pr_drain)             /* flush any excess space possible */
   97                         (void);
   98 };
   99 
  100 #define PR_SLOWHZ       2               /* 2 slow timeouts per second */
  101 #define PR_FASTHZ       5               /* 5 fast timeouts per second */
  102 
  103 /*
  104  * Values for pr_flags.
  105  * PR_ADDR requires PR_ATOMIC;
  106  * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
  107  */
  108 #define PR_ATOMIC       0x01            /* exchange atomic messages only */
  109 #define PR_ADDR         0x02            /* addresses given with messages */
  110 #define PR_CONNREQUIRED 0x04            /* connection required by protocol */
  111 #define PR_WANTRCVD     0x08            /* want PRU_RCVD calls */
  112 #define PR_RIGHTS       0x10            /* passes capabilities */
  113 #define PR_LISTEN       0x20            /* supports listen(2) and accept(2) */
  114 #define PR_LASTHDR      0x40            /* enforce ipsec policy; last header */
  115 #define PR_ABRTACPTDIS  0x80            /* abort on accept(2) to disconnected
  116                                            socket */
  117 #define PR_PURGEIF      0x100           /* might store struct ifnet pointer;
  118                                            PRU_PURGEIF must be called on ifnet
  119                                            deletion */
  120 
  121 /*
  122  * The arguments to usrreq are:
  123  *      (*protosw[].pr_usrreq)(up, req, m, nam, opt, p);
  124  * where up is a (struct socket *), req is one of these requests,
  125  * m is a optional mbuf chain containing a message,
  126  * nam is an optional mbuf chain containing an address,
  127  * opt is an optional mbuf containing socket options,
  128  * and p is a pointer to the process requesting the action (if any).
  129  * The protocol is responsible for disposal of the mbuf chains m and opt,
  130  * the caller is responsible for any space held by nam.
  131  * A non-zero return from usrreq gives an
  132  * UNIX error number which should be passed to higher level software.
  133  */
  134 #define PRU_ATTACH              0       /* attach protocol to up */
  135 #define PRU_DETACH              1       /* detach protocol from up */
  136 #define PRU_BIND                2       /* bind socket to address */
  137 #define PRU_LISTEN              3       /* listen for connection */
  138 #define PRU_CONNECT             4       /* establish connection to peer */
  139 #define PRU_ACCEPT              5       /* accept connection from peer */
  140 #define PRU_DISCONNECT          6       /* disconnect from peer */
  141 #define PRU_SHUTDOWN            7       /* won't send any more data */
  142 #define PRU_RCVD                8       /* have taken data; more room now */
  143 #define PRU_SEND                9       /* send this data */
  144 #define PRU_ABORT               10      /* abort (fast DISCONNECT, DETACH) */
  145 #define PRU_CONTROL             11      /* control operations on protocol */
  146 #define PRU_SENSE               12      /* return status into m */
  147 #define PRU_RCVOOB              13      /* retrieve out of band data */
  148 #define PRU_SENDOOB             14      /* send out of band data */
  149 #define PRU_SOCKADDR            15      /* fetch socket's address */
  150 #define PRU_PEERADDR            16      /* fetch peer's address */
  151 #define PRU_CONNECT2            17      /* connect two sockets */
  152 /* begin for protocols internal use */
  153 #define PRU_FASTTIMO            18      /* 200ms timeout */
  154 #define PRU_SLOWTIMO            19      /* 500ms timeout */
  155 #define PRU_PROTORCV            20      /* receive from below */
  156 #define PRU_PROTOSEND           21      /* send to below */
  157 #define PRU_PURGEIF             22      /* purge specified if */
  158 
  159 #define PRU_NREQ                23
  160 
  161 #ifdef PRUREQUESTS
  162 const char * const prurequests[] = {
  163         "ATTACH",       "DETACH",       "BIND",         "LISTEN",
  164         "CONNECT",      "ACCEPT",       "DISCONNECT",   "SHUTDOWN",
  165         "RCVD",         "SEND",         "ABORT",        "CONTROL",
  166         "SENSE",        "RCVOOB",       "SENDOOB",      "SOCKADDR",
  167         "PEERADDR",     "CONNECT2",     "FASTTIMO",     "SLOWTIMO",
  168         "PROTORCV",     "PROTOSEND",    "PURGEIF",
  169 };
  170 #endif
  171 
  172 /*
  173  * The arguments to the ctlinput routine are
  174  *      (*protosw[].pr_ctlinput)(cmd, sa, arg);
  175  * where cmd is one of the commands below, sa is a pointer to a sockaddr,
  176  * and arg is an optional caddr_t argument used within a protocol family.
  177  */
  178 #define PRC_IFDOWN              0       /* interface transition */
  179 #define PRC_ROUTEDEAD           1       /* select new route if possible ??? */
  180 #define PRC_QUENCH2             3       /* DEC congestion bit says slow down */
  181 #define PRC_QUENCH              4       /* some one said to slow down */
  182 #define PRC_MSGSIZE             5       /* message size forced drop */
  183 #define PRC_HOSTDEAD            6       /* host appears to be down */
  184 #define PRC_HOSTUNREACH         7       /* deprecated (use PRC_UNREACH_HOST) */
  185 #define PRC_UNREACH_NET         8       /* no route to network */
  186 #define PRC_UNREACH_HOST        9       /* no route to host */
  187 #define PRC_UNREACH_PROTOCOL    10      /* dst says bad protocol */
  188 #define PRC_UNREACH_PORT        11      /* bad port # */
  189 /* was  PRC_UNREACH_NEEDFRAG    12         (use PRC_MSGSIZE) */
  190 #define PRC_UNREACH_SRCFAIL     13      /* source route failed */
  191 #define PRC_REDIRECT_NET        14      /* net routing redirect */
  192 #define PRC_REDIRECT_HOST       15      /* host routing redirect */
  193 #define PRC_REDIRECT_TOSNET     16      /* redirect for type of service & net */
  194 #define PRC_REDIRECT_TOSHOST    17      /* redirect for tos & host */
  195 #define PRC_TIMXCEED_INTRANS    18      /* packet lifetime expired in transit */
  196 #define PRC_TIMXCEED_REASS      19      /* lifetime expired on reass q */
  197 #define PRC_PARAMPROB           20      /* header incorrect */
  198 
  199 #define PRC_NCMDS               21
  200 
  201 #define PRC_IS_REDIRECT(cmd)    \
  202         ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
  203 
  204 #ifdef PRCREQUESTS
  205 const char * const prcrequests[] = {
  206         "IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2",
  207         "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
  208         "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
  209         "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
  210         "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
  211         "PARAMPROB"
  212 };
  213 #endif
  214 
  215 /*
  216  * The arguments to ctloutput are:
  217  *      (*protosw[].pr_ctloutput)(req, so, level, optname, optval);
  218  * req is one of the actions listed below, so is a (struct socket *),
  219  * level is an indication of which protocol layer the option is intended.
  220  * optname is a protocol dependent socket option request,
  221  * optval is a pointer to a mbuf-chain pointer, for value-return results.
  222  * The protocol is responsible for disposal of the mbuf chain *optval
  223  * if supplied,
  224  * the caller is responsible for any space held by *optval, when returned.
  225  * A non-zero return from usrreq gives an
  226  * UNIX error number which should be passed to higher level software.
  227  */
  228 #define PRCO_GETOPT     0
  229 #define PRCO_SETOPT     1
  230 
  231 #define PRCO_NCMDS      2
  232 
  233 #ifdef PRCOREQUESTS
  234 const char * const prcorequests[] = {
  235         "GETOPT", "SETOPT",
  236 };
  237 #endif
  238 
  239 #ifdef _KERNEL
  240 extern const char * const prurequests[];
  241 extern const char * const prcrequests[];
  242 extern const char * const prcorequests[];
  243 /*
  244  * Monotonically increasing time values for slow and fast timers.
  245  */
  246 extern  u_int pfslowtimo_now;
  247 extern  u_int pffasttimo_now;
  248 
  249 #define PRT_SLOW_ARM(t, nticks) (t) = (pfslowtimo_now + (nticks))
  250 #define PRT_FAST_ARM(t, nticks) (t) = (pffasttimo_now + (nticks))
  251 
  252 #define PRT_SLOW_DISARM(t)      (t) = 0
  253 #define PRT_FAST_DISARM(t)      (t) = 0
  254 
  255 #define PRT_SLOW_ISARMED(t)     ((t) != 0)
  256 #define PRT_FAST_ISARMED(t)     ((t) != 0)
  257 
  258 #define PRT_SLOW_ISEXPIRED(t)   (PRT_SLOW_ISARMED((t)) && (t) <= pfslowtimo_now)
  259 #define PRT_FAST_ISEXPIRED(t)   (PRT_FAST_ISARMED((t)) && (t) <= pffasttimo_now)
  260 
  261 struct sockaddr;
  262 const struct protosw *pffindproto(int, int, int);
  263 const struct protosw *pffindtype(int, int);
  264 struct domain *pffinddomain(int);
  265 void pfctlinput(int, struct sockaddr *);
  266 void pfctlinput2(int, struct sockaddr *, void *);
  267 #endif /* _KERNEL */
  268 
  269 #endif /* !_SYS_PROTOSW_H_ */

Cache object: 0e53eeb7bad08e88f95b45b1404165e5


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.