protosw.h revision 6223
11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 331541Srgrimes * @(#)protosw.h 8.1 (Berkeley) 6/2/93 346223Swollman * $Id: protosw.h,v 1.5 1994/10/08 22:22:57 phk Exp $ 351541Srgrimes */ 361541Srgrimes 372165Spaul#ifndef _SYS_PROTOSW_H_ 382165Spaul#define _SYS_PROTOSW_H_ 392165Spaul 401541Srgrimes/* 411541Srgrimes * Protocol switch table. 421541Srgrimes * 431541Srgrimes * Each protocol has a handle initializing one of these structures, 441541Srgrimes * which is used for protocol-protocol and system-protocol communication. 451541Srgrimes * 461541Srgrimes * A protocol is called through the pr_init entry before any other. 471541Srgrimes * Thereafter it is called every 200ms through the pr_fasttimo entry and 481541Srgrimes * every 500ms through the pr_slowtimo for timer based actions. 491541Srgrimes * The system will call the pr_drain entry if it is low on space and 501541Srgrimes * this should throw away any non-critical data. 511541Srgrimes * 521541Srgrimes * Protocols pass data between themselves as chains of mbufs using 531541Srgrimes * the pr_input and pr_output hooks. Pr_input passes data up (towards 541541Srgrimes * UNIX) and pr_output passes it down (towards the imps); control 551541Srgrimes * information passes up and down on pr_ctlinput and pr_ctloutput. 561541Srgrimes * The protocol is responsible for the space occupied by any the 571541Srgrimes * arguments to these entries and must dispose it. 581541Srgrimes * 591541Srgrimes * The userreq routine interfaces protocols to the system and is 601541Srgrimes * described below. 611541Srgrimes */ 621541Srgrimesstruct protosw { 631541Srgrimes short pr_type; /* socket type used for */ 641541Srgrimes struct domain *pr_domain; /* domain protocol a member of */ 651541Srgrimes short pr_protocol; /* protocol number */ 661541Srgrimes short pr_flags; /* see below */ 671541Srgrimes/* protocol-protocol hooks */ 681541Srgrimes void (*pr_input)(); /* input to protocol (from below) */ 691541Srgrimes int (*pr_output)(); /* output to protocol (from above) */ 701541Srgrimes void (*pr_ctlinput)(); /* control input (from below) */ 711541Srgrimes int (*pr_ctloutput)(); /* control output (from above) */ 721541Srgrimes/* user-protocol hook */ 731541Srgrimes int (*pr_usrreq)(); /* user request: see list below */ 741541Srgrimes/* utility hooks */ 751541Srgrimes void (*pr_init)(); /* initialization hook */ 761541Srgrimes void (*pr_fasttimo)(); /* fast timeout (200ms) */ 771541Srgrimes void (*pr_slowtimo)(); /* slow timeout (500ms) */ 781541Srgrimes void (*pr_drain)(); /* flush any excess space possible */ 791541Srgrimes int (*pr_sysctl)(); /* sysctl for protocol */ 801541Srgrimes}; 811541Srgrimes 821541Srgrimes#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 831541Srgrimes#define PR_FASTHZ 5 /* 5 fast timeouts per second */ 841541Srgrimes 851541Srgrimes/* 861541Srgrimes * Values for pr_flags. 871541Srgrimes * PR_ADDR requires PR_ATOMIC; 881541Srgrimes * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. 896223Swollman * PR_IMPLOPCL means that the protocol allows sendto without prior connect, 906223Swollman * and the protocol understands the MSG_EOF flag. The first property is 916223Swollman * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed 926223Swollman * anyhow). 931541Srgrimes */ 941541Srgrimes#define PR_ATOMIC 0x01 /* exchange atomic messages only */ 951541Srgrimes#define PR_ADDR 0x02 /* addresses given with messages */ 961541Srgrimes#define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 971541Srgrimes#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 981541Srgrimes#define PR_RIGHTS 0x10 /* passes capabilities */ 996223Swollman#define PR_IMPLOPCL 0x20 /* implied open/close */ 1001541Srgrimes 1011541Srgrimes/* 1021541Srgrimes * The arguments to usrreq are: 1031541Srgrimes * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 1041541Srgrimes * where up is a (struct socket *), req is one of these requests, 1051541Srgrimes * m is a optional mbuf chain containing a message, 1061541Srgrimes * nam is an optional mbuf chain containing an address, 1071541Srgrimes * and opt is a pointer to a socketopt structure or nil. 1081541Srgrimes * The protocol is responsible for disposal of the mbuf chain m, 1091541Srgrimes * the caller is responsible for any space held by nam and opt. 1101541Srgrimes * A non-zero return from usrreq gives an 1111541Srgrimes * UNIX error number which should be passed to higher level software. 1121541Srgrimes */ 1131541Srgrimes#define PRU_ATTACH 0 /* attach protocol to up */ 1141541Srgrimes#define PRU_DETACH 1 /* detach protocol from up */ 1151541Srgrimes#define PRU_BIND 2 /* bind socket to address */ 1161541Srgrimes#define PRU_LISTEN 3 /* listen for connection */ 1171541Srgrimes#define PRU_CONNECT 4 /* establish connection to peer */ 1181541Srgrimes#define PRU_ACCEPT 5 /* accept connection from peer */ 1191541Srgrimes#define PRU_DISCONNECT 6 /* disconnect from peer */ 1201541Srgrimes#define PRU_SHUTDOWN 7 /* won't send any more data */ 1211541Srgrimes#define PRU_RCVD 8 /* have taken data; more room now */ 1221541Srgrimes#define PRU_SEND 9 /* send this data */ 1231541Srgrimes#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 1241541Srgrimes#define PRU_CONTROL 11 /* control operations on protocol */ 1251541Srgrimes#define PRU_SENSE 12 /* return status into m */ 1261541Srgrimes#define PRU_RCVOOB 13 /* retrieve out of band data */ 1271541Srgrimes#define PRU_SENDOOB 14 /* send out of band data */ 1281541Srgrimes#define PRU_SOCKADDR 15 /* fetch socket's address */ 1291541Srgrimes#define PRU_PEERADDR 16 /* fetch peer's address */ 1301541Srgrimes#define PRU_CONNECT2 17 /* connect two sockets */ 1311541Srgrimes/* begin for protocols internal use */ 1321541Srgrimes#define PRU_FASTTIMO 18 /* 200ms timeout */ 1331541Srgrimes#define PRU_SLOWTIMO 19 /* 500ms timeout */ 1341541Srgrimes#define PRU_PROTORCV 20 /* receive from below */ 1351541Srgrimes#define PRU_PROTOSEND 21 /* send to below */ 1366223Swollman#define PRU_SEND_EOF 22 /* send and close */ 1376223Swollman#define PRU_NREQ 22 1381541Srgrimes 1391541Srgrimes#ifdef PRUREQUESTS 1401541Srgrimeschar *prurequests[] = { 1411541Srgrimes "ATTACH", "DETACH", "BIND", "LISTEN", 1421541Srgrimes "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 1431541Srgrimes "RCVD", "SEND", "ABORT", "CONTROL", 1441541Srgrimes "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 1451541Srgrimes "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", 1461541Srgrimes "PROTORCV", "PROTOSEND", 1476223Swollman "SEND_EOF", 1481541Srgrimes}; 1491541Srgrimes#endif 1501541Srgrimes 1511541Srgrimes/* 1521541Srgrimes * The arguments to the ctlinput routine are 1531541Srgrimes * (*protosw[].pr_ctlinput)(cmd, sa, arg); 1541541Srgrimes * where cmd is one of the commands below, sa is a pointer to a sockaddr, 1551541Srgrimes * and arg is an optional caddr_t argument used within a protocol family. 1561541Srgrimes */ 1571541Srgrimes#define PRC_IFDOWN 0 /* interface transition */ 1581541Srgrimes#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ 1591541Srgrimes#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ 1601541Srgrimes#define PRC_QUENCH 4 /* some one said to slow down */ 1611541Srgrimes#define PRC_MSGSIZE 5 /* message size forced drop */ 1621541Srgrimes#define PRC_HOSTDEAD 6 /* host appears to be down */ 1631541Srgrimes#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ 1641541Srgrimes#define PRC_UNREACH_NET 8 /* no route to network */ 1651541Srgrimes#define PRC_UNREACH_HOST 9 /* no route to host */ 1661541Srgrimes#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 1671541Srgrimes#define PRC_UNREACH_PORT 11 /* bad port # */ 1681541Srgrimes/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ 1691541Srgrimes#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ 1701541Srgrimes#define PRC_REDIRECT_NET 14 /* net routing redirect */ 1711541Srgrimes#define PRC_REDIRECT_HOST 15 /* host routing redirect */ 1721541Srgrimes#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ 1731541Srgrimes#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ 1741541Srgrimes#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ 1751541Srgrimes#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ 1761541Srgrimes#define PRC_PARAMPROB 20 /* header incorrect */ 1771541Srgrimes 1781541Srgrimes#define PRC_NCMDS 21 1791541Srgrimes 1801541Srgrimes#define PRC_IS_REDIRECT(cmd) \ 1811541Srgrimes ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) 1821541Srgrimes 1831541Srgrimes#ifdef PRCREQUESTS 1841541Srgrimeschar *prcrequests[] = { 1851541Srgrimes "IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2", 1861541Srgrimes "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", 1871541Srgrimes "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 1881541Srgrimes "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", 1891541Srgrimes "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", 1901541Srgrimes "PARAMPROB" 1911541Srgrimes}; 1921541Srgrimes#endif 1931541Srgrimes 1941541Srgrimes/* 1951541Srgrimes * The arguments to ctloutput are: 1961541Srgrimes * (*protosw[].pr_ctloutput)(req, so, level, optname, optval); 1971541Srgrimes * req is one of the actions listed below, so is a (struct socket *), 1981541Srgrimes * level is an indication of which protocol layer the option is intended. 1991541Srgrimes * optname is a protocol dependent socket option request, 2001541Srgrimes * optval is a pointer to a mbuf-chain pointer, for value-return results. 2011541Srgrimes * The protocol is responsible for disposal of the mbuf chain *optval 2021541Srgrimes * if supplied, 2031541Srgrimes * the caller is responsible for any space held by *optval, when returned. 2041541Srgrimes * A non-zero return from usrreq gives an 2051541Srgrimes * UNIX error number which should be passed to higher level software. 2061541Srgrimes */ 2071541Srgrimes#define PRCO_GETOPT 0 2081541Srgrimes#define PRCO_SETOPT 1 2091541Srgrimes 2101541Srgrimes#define PRCO_NCMDS 2 2111541Srgrimes 2121541Srgrimes#ifdef PRCOREQUESTS 2131541Srgrimeschar *prcorequests[] = { 2141541Srgrimes "GETOPT", "SETOPT", 2151541Srgrimes}; 2161541Srgrimes#endif 2171541Srgrimes 2181541Srgrimes#ifdef KERNEL 2191541Srgrimesextern struct protosw *pffindproto(), *pffindtype(); 2201541Srgrimes#endif 2212165Spaul 2222165Spaul#endif 223