/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos720 src/bos/kernel/sys/protosw.h 1.15.6.1                           */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1988,1993              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)97	1.15.6.1  src/bos/kernel/sys/protosw.h, sockinc, bos720, 1508A_720 1/27/15 13:46:18 */
/*
 *   COMPONENT_NAME: SOCKINC
 *
 *   FUNCTIONS: PRC_IS_REDIRECT
 *
 *
 *   ORIGINS: 26,27,85
 *
 *
 *   (C) COPYRIGHT International Business Machines Corp. 1988,1993
 *   All Rights Reserved
 *   Licensed Materials - Property of IBM
 *   US Government Users Restricted Rights - Use, duplication or
 *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */
/*
 * (c) Copyright 1990, 1991, 1992, 1993 OPEN SOFTWARE FOUNDATION, INC.
 * ALL RIGHTS RESERVED
 */
/*
 * OSF/1 1.2
 */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted provided
 * that: (1) source distributions retain this entire copyright notice and
 * comment, and (2) distributions including binaries display the following
 * acknowledgement:  ``This product includes software developed by the
 * University of California, Berkeley and its contributors'' in the
 * documentation or other materials provided with the distribution and in
 * all advertising materials mentioning features or use of this software.
 * Neither the name of the University nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *      Base:   protosw.h       7.4 (Berkeley) 9/4/89
 *      Merged: protosw.h       7.6 (Berkeley) 6/28/90
 */

#ifndef _SYS_PROTOSW_H_
#define _SYS_PROTOSW_H_

#ifdef __cplusplus
struct domain;

#ifndef CONST
#define CONST const
#endif
#endif

/*
 * Protocol switch table.
 *
 * Each protocol has a handle initializing one of these structures,
 * which is used for protocol-protocol and system-protocol communication.
 *
 * A protocol is called through the pr_init entry before any other.
 * Thereafter it is called every 200ms through the pr_fasttimo entry and
 * every 500ms through the pr_slowtimo for timer based actions.
 * The system will call the pr_drain entry if it is low on space and
 * this should throw away any non-critical data.
 *
 * Protocols pass data between themselves as chains of mbufs using
 * the pr_input and pr_output hooks.  Pr_input passes data up (towards
 * UNIX) and pr_output passes it down (towards the imps); control
 * information passes up and down on pr_ctlinput and pr_ctloutput.
 * The protocol is responsible for the space occupied by any the
 * arguments to these entries and must dispose it.
 *
 * The userreq routine interfaces protocols to the system and is
 * described below.
 */
struct protosw {
        short   pr_type;                /* socket type used for */
        struct  domain *pr_domain;      /* domain protocol a member of */
        short   pr_protocol;            /* protocol number */
        short   pr_flags;               /* see below */
#ifdef  _KERNEL
        int     (*pr_input)();          /* prototypes per-domain */
        int     (*pr_output)();         /* prototypes per-domain */
        void    (*pr_ctlinput)(int, struct sockaddr *, caddr_t);
        int     (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf **);
        int     (*pr_usrreq)(struct socket *, int,
                                struct mbuf *, struct mbuf *, struct mbuf *);
        int     (*pr_send)(struct socket *, struct mbuf *, struct uio *,
                                struct mbuf *, struct mbuf *, int);
        int     (*pr_receive)(struct socket *, struct mbuf **, struct uio *,
                                struct mbuf **, struct mbuf **, int *);
        void    (*pr_init)(void);
        void    (*pr_fasttimo)(void);
        void    (*pr_slowtimo)(void);
        void    (*pr_drain)(void);
#else
/* protocol-protocol hooks */
        int     (*pr_input)();          /* input to protocol (from below) */
        int     (*pr_output)();         /* output to protocol (from above) */
        void    (*pr_ctlinput)();       /* control input (from below) */
        int     (*pr_ctloutput)();      /* control output (from above) */
/* user-protocol hook */
        int     (*pr_usrreq)();         /* user request: see list below */
        int     (*pr_send)();           /* protocol-specific sosend */
        int     (*pr_receive)();        /* protocol-specific soreceive */
/* utility hooks */
        void    (*pr_init)();           /* initialization hook */
        void    (*pr_fasttimo)();       /* fast timeout (200ms) */
        void    (*pr_slowtimo)();       /* slow timeout (500ms) */
        void    (*pr_drain)();          /* flush any excess space possible */
#endif
};

#define PR_SLOWHZ       2               /* 2 slow timeouts per second */
#define PR_FASTHZ       5               /* 5 fast timeouts per second */

/*
 * Values for pr_flags.
 * PR_ADDR requires PR_ATOMIC;
 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
 */
#define PR_ATOMIC       0x01            /* exchange atomic messages only */
#define PR_ADDR         0x02            /* addresses given with messages */
#define PR_CONNREQUIRED 0x04            /* connection required by protocol */
#define PR_WANTRCVD     0x08            /* want PRU_RCVD calls */
#define PR_RIGHTS       0x10            /* passes capabilities */
#define PR_64BIT        0x20            /* 64 bit supported */
#define	PR_INP		0x40		/* The socket's so_pcb field points to*/
					/* 	a inpcb */
#define PR_MLS		0x100		/* protocol supports MLS labeling */
#define	PR_MLS_1_LABEL	0x200		/* protocol supports sending single MLS label per data stream */
#define PR_ARGEXT	0x400		/* protocol supports argextension for pr_receive vector */
#define PR_NOEOR        0x4000          /* Records not supported */
#define PR_INTRLEVEL    0x8000          /* Protocol runs on interrupt level */

/*
 * The arguments to usrreq are:
 *      (*protosw[].pr_usrreq)(up, req, m, nam, control);
 * where up is a (struct socket *), req is one of these requests,
 * m is a optional mbuf chain containing a message,
 * nam is an optional mbuf chain containing an address,
 * and control is a pointer to a control chain or nil.
 * The protocol is responsible for disposal of the mbuf chain m,
 * the caller is responsible for any space held by nam and control.
 * A non-zero return from usrreq gives an
 * UNIX error number which should be passed to higher level software.
 */
#define PRU_ATTACH              0       /* attach protocol to up */
#define PRU_DETACH              1       /* detach protocol from up */
#define PRU_BIND                2       /* bind socket to address */
#define PRU_LISTEN              3       /* listen for connection */
#define PRU_CONNECT             4       /* establish connection to peer */
#define PRU_ACCEPT              5       /* accept connection from peer */
#define PRU_DISCONNECT          6       /* disconnect from peer */
#define PRU_SHUTDOWN            7       /* won't send any more data */
#define PRU_RCVD                8       /* have taken data; more room now */
#define PRU_SEND                9       /* send this data */
#define PRU_ABORT               10      /* abort (fast DISCONNECT, DETACH) */
#define PRU_CONTROL             11      /* control operations on protocol */
#define PRU_SENSE               12      /* return status into m */
#define PRU_RCVOOB              13      /* retrieve out of band data */
#define PRU_SENDOOB             14      /* send out of band data */
#define PRU_SOCKADDR            15      /* fetch socket's address */
#define PRU_PEERADDR            16      /* fetch peer's address */
#define PRU_CONNECT2            17      /* connect two sockets */
/* begin for protocols internal use */
#define PRU_FASTTIMO            18      /* 200ms timeout */
#define PRU_SLOWTIMO            19      /* 500ms timeout */
#define PRU_PROTORCV            20      /* receive from below */
#define PRU_PROTOSEND           21      /* send to below */
#define PRU_SEND_AND_DISCONNECT 22      /* disconnect after send */
#define PRU_DYNBIND             23      /* dynamically bind an address */
#define PRU_SPLICE              24      /* used by splice() for tcp splicing */
#define PRU_DISCONNECTREUSE	25      /* disconnect from peer but allow reuse of socket */

#define PRU_PEEREID             26      /* fetch peer's eid */
#define PRU_PEERID		27	/* fetch peer's pid, tid, euid and egid */
#define PRU_NODELAY             28	/* nagle override */
#define PRU_NREQ                29	/* should be the max # of requests */
#define PRU_DETACH_SCTP_NOLOCK	30	/* call sctp_close without INPCB lock held */

#ifndef CONST
#define CONST
#endif

#ifdef PRUREQUESTS
CONST char      *prurequests[] = {
        "ATTACH",       "DETACH",       "BIND",         "LISTEN",
        "CONNECT",      "ACCEPT",       "DISCONNECT",   "SHUTDOWN",
        "RCVD",         "SEND",         "ABORT",        "CONTROL",
        "SENSE",        "RCVOOB",       "SENDOOB",      "SOCKADDR",
        "PEERADDR",     "CONNECT2",     "FASTTIMO",     "SLOWTIMO",
        "PROTORCV",     "PROTOSEND",    "SEND_AND_DISCONNECT", "DYNBIND",
	"SPLICE",	"DISCONNECTREUSE",	"PEEREID", "PEERID",
	"NODELAY", "NREQ", "DETACH_SCTP_NOLOCK"
};
#endif

/*
 * The arguments to the ctlinput routine are
 *      (*protosw[].pr_ctlinput)(cmd, sa, arg);
 * where cmd is one of the commands below, sa is a pointer to a sockaddr,
 * and arg is an optional caddr_t argument used within a protocol family.
 */
#define PRC_IFDOWN              0       /* interface transition */
#define PRC_ROUTEDEAD           1       /* select new route if possible ??? */
#define PRC_QUENCH2             3       /* DEC congestion bit says slow down */
#define PRC_QUENCH              4       /* some one said to slow down */
#define PRC_MSGSIZE             5       /* message size forced drop */
#define PRC_HOSTDEAD            6       /* host appears to be down */
#define PRC_HOSTUNREACH         7       /* deprecated (use PRC_UNREACH_HOST) */
#define PRC_UNREACH_NET         8       /* no route to network */
#define PRC_UNREACH_HOST        9       /* no route to host */
#define PRC_UNREACH_PROTOCOL    10      /* dst says bad protocol */
#define PRC_UNREACH_PORT        11      /* bad port # */
/* was  PRC_UNREACH_NEEDFRAG    12         (use PRC_MSGSIZE) */
#define PRC_UNREACH_SRCFAIL     13      /* source route failed */
#define PRC_REDIRECT_NET        14      /* net routing redirect */
#define PRC_REDIRECT_HOST       15      /* host routing redirect */
#define PRC_REDIRECT_TOSNET     16      /* redirect for type of service & net */
#define PRC_REDIRECT_TOSHOST    17      /* redirect for tos & host */
#define PRC_TIMXCEED_INTRANS    18      /* packet lifetime expired in transit */
#define PRC_TIMXCEED_REASS      19      /* lifetime expired on reass q */
#define PRC_PARAMPROB           20      /* header incorrect */
#define PRC_IFATTACH            21      /* if attach notification */
#define PRC_IFDETACH            22      /* if detach notification */
#define PRC_QOS                 23      /* Quality Of Service request */

#define PRC_NCMDS               24

#define PRC_IS_REDIRECT(cmd)    \
        ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)

#ifdef PRCREQUESTS
CONST char      *prcrequests[] = {
        "IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2",
        "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
        "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
        "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
        "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
        "PARAMPROB", "IFATTACH", "IFDETACH"
};
#endif

/*
 * The arguments to ctloutput are:
 *      (*protosw[].pr_ctloutput)(req, so, level, optname, optval);
 * req is one of the actions listed below, so is a (struct socket *),
 * level is an indication of which protocol layer the option is intended.
 * optname is a protocol dependent socket option request,
 * optval is a pointer to a mbuf-chain pointer, for value-return results.
 * The protocol is responsible for disposal of the mbuf chain *optval
 * if supplied,
 * the caller is responsible for any space held by *optval, when returned.
 * A non-zero return from usrreq gives an
 * UNIX error number which should be passed to higher level software.
 */
#define PRCO_GETOPT     0
#define PRCO_SETOPT     1

#define PRCO_NCMDS      2

#ifdef PRCOREQUESTS
CONST char      *prcorequests[] = {
        "GETOPT", "SETOPT"
};
#endif

#endif
