protosw.h revision 1541
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 341541Srgrimes */ 351541Srgrimes 361541Srgrimes/* 371541Srgrimes * Protocol switch table. 381541Srgrimes * 391541Srgrimes * Each protocol has a handle initializing one of these structures, 401541Srgrimes * which is used for protocol-protocol and system-protocol communication. 411541Srgrimes * 421541Srgrimes * A protocol is called through the pr_init entry before any other. 431541Srgrimes * Thereafter it is called every 200ms through the pr_fasttimo entry and 441541Srgrimes * every 500ms through the pr_slowtimo for timer based actions. 451541Srgrimes * The system will call the pr_drain entry if it is low on space and 461541Srgrimes * this should throw away any non-critical data. 471541Srgrimes * 481541Srgrimes * Protocols pass data between themselves as chains of mbufs using 491541Srgrimes * the pr_input and pr_output hooks. Pr_input passes data up (towards 501541Srgrimes * UNIX) and pr_output passes it down (towards the imps); control 511541Srgrimes * information passes up and down on pr_ctlinput and pr_ctloutput. 521541Srgrimes * The protocol is responsible for the space occupied by any the 531541Srgrimes * arguments to these entries and must dispose it. 541541Srgrimes * 551541Srgrimes * The userreq routine interfaces protocols to the system and is 561541Srgrimes * described below. 571541Srgrimes */ 581541Srgrimesstruct protosw { 591541Srgrimes short pr_type; /* socket type used for */ 601541Srgrimes struct domain *pr_domain; /* domain protocol a member of */ 611541Srgrimes short pr_protocol; /* protocol number */ 621541Srgrimes short pr_flags; /* see below */ 631541Srgrimes/* protocol-protocol hooks */ 641541Srgrimes void (*pr_input)(); /* input to protocol (from below) */ 651541Srgrimes int (*pr_output)(); /* output to protocol (from above) */ 661541Srgrimes void (*pr_ctlinput)(); /* control input (from below) */ 671541Srgrimes int (*pr_ctloutput)(); /* control output (from above) */ 681541Srgrimes/* user-protocol hook */ 691541Srgrimes int (*pr_usrreq)(); /* user request: see list below */ 701541Srgrimes/* utility hooks */ 711541Srgrimes void (*pr_init)(); /* initialization hook */ 721541Srgrimes void (*pr_fasttimo)(); /* fast timeout (200ms) */ 731541Srgrimes void (*pr_slowtimo)(); /* slow timeout (500ms) */ 741541Srgrimes void (*pr_drain)(); /* flush any excess space possible */ 751541Srgrimes int (*pr_sysctl)(); /* sysctl for protocol */ 761541Srgrimes}; 771541Srgrimes 781541Srgrimes#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 791541Srgrimes#define PR_FASTHZ 5 /* 5 fast timeouts per second */ 801541Srgrimes 811541Srgrimes/* 821541Srgrimes * Values for pr_flags. 831541Srgrimes * PR_ADDR requires PR_ATOMIC; 841541Srgrimes * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. 851541Srgrimes */ 861541Srgrimes#define PR_ATOMIC 0x01 /* exchange atomic messages only */ 871541Srgrimes#define PR_ADDR 0x02 /* addresses given with messages */ 881541Srgrimes#define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 891541Srgrimes#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 901541Srgrimes#define PR_RIGHTS 0x10 /* passes capabilities */ 911541Srgrimes 921541Srgrimes/* 931541Srgrimes * The arguments to usrreq are: 941541Srgrimes * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 951541Srgrimes * where up is a (struct socket *), req is one of these requests, 961541Srgrimes * m is a optional mbuf chain containing a message, 971541Srgrimes * nam is an optional mbuf chain containing an address, 981541Srgrimes * and opt is a pointer to a socketopt structure or nil. 991541Srgrimes * The protocol is responsible for disposal of the mbuf chain m, 1001541Srgrimes * the caller is responsible for any space held by nam and opt. 1011541Srgrimes * A non-zero return from usrreq gives an 1021541Srgrimes * UNIX error number which should be passed to higher level software. 1031541Srgrimes */ 1041541Srgrimes#define PRU_ATTACH 0 /* attach protocol to up */ 1051541Srgrimes#define PRU_DETACH 1 /* detach protocol from up */ 1061541Srgrimes#define PRU_BIND 2 /* bind socket to address */ 1071541Srgrimes#define PRU_LISTEN 3 /* listen for connection */ 1081541Srgrimes#define PRU_CONNECT 4 /* establish connection to peer */ 1091541Srgrimes#define PRU_ACCEPT 5 /* accept connection from peer */ 1101541Srgrimes#define PRU_DISCONNECT 6 /* disconnect from peer */ 1111541Srgrimes#define PRU_SHUTDOWN 7 /* won't send any more data */ 1121541Srgrimes#define PRU_RCVD 8 /* have taken data; more room now */ 1131541Srgrimes#define PRU_SEND 9 /* send this data */ 1141541Srgrimes#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 1151541Srgrimes#define PRU_CONTROL 11 /* control operations on protocol */ 1161541Srgrimes#define PRU_SENSE 12 /* return status into m */ 1171541Srgrimes#define PRU_RCVOOB 13 /* retrieve out of band data */ 1181541Srgrimes#define PRU_SENDOOB 14 /* send out of band data */ 1191541Srgrimes#define PRU_SOCKADDR 15 /* fetch socket's address */ 1201541Srgrimes#define PRU_PEERADDR 16 /* fetch peer's address */ 1211541Srgrimes#define PRU_CONNECT2 17 /* connect two sockets */ 1221541Srgrimes/* begin for protocols internal use */ 1231541Srgrimes#define PRU_FASTTIMO 18 /* 200ms timeout */ 1241541Srgrimes#define PRU_SLOWTIMO 19 /* 500ms timeout */ 1251541Srgrimes#define PRU_PROTORCV 20 /* receive from below */ 1261541Srgrimes#define PRU_PROTOSEND 21 /* send to below */ 1271541Srgrimes 1281541Srgrimes#define PRU_NREQ 21 1291541Srgrimes 1301541Srgrimes#ifdef PRUREQUESTS 1311541Srgrimeschar *prurequests[] = { 1321541Srgrimes "ATTACH", "DETACH", "BIND", "LISTEN", 1331541Srgrimes "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 1341541Srgrimes "RCVD", "SEND", "ABORT", "CONTROL", 1351541Srgrimes "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 1361541Srgrimes "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", 1371541Srgrimes "PROTORCV", "PROTOSEND", 1381541Srgrimes}; 1391541Srgrimes#endif 1401541Srgrimes 1411541Srgrimes/* 1421541Srgrimes * The arguments to the ctlinput routine are 1431541Srgrimes * (*protosw[].pr_ctlinput)(cmd, sa, arg); 1441541Srgrimes * where cmd is one of the commands below, sa is a pointer to a sockaddr, 1451541Srgrimes * and arg is an optional caddr_t argument used within a protocol family. 1461541Srgrimes */ 1471541Srgrimes#define PRC_IFDOWN 0 /* interface transition */ 1481541Srgrimes#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ 1491541Srgrimes#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ 1501541Srgrimes#define PRC_QUENCH 4 /* some one said to slow down */ 1511541Srgrimes#define PRC_MSGSIZE 5 /* message size forced drop */ 1521541Srgrimes#define PRC_HOSTDEAD 6 /* host appears to be down */ 1531541Srgrimes#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ 1541541Srgrimes#define PRC_UNREACH_NET 8 /* no route to network */ 1551541Srgrimes#define PRC_UNREACH_HOST 9 /* no route to host */ 1561541Srgrimes#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 1571541Srgrimes#define PRC_UNREACH_PORT 11 /* bad port # */ 1581541Srgrimes/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ 1591541Srgrimes#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ 1601541Srgrimes#define PRC_REDIRECT_NET 14 /* net routing redirect */ 1611541Srgrimes#define PRC_REDIRECT_HOST 15 /* host routing redirect */ 1621541Srgrimes#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ 1631541Srgrimes#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ 1641541Srgrimes#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ 1651541Srgrimes#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ 1661541Srgrimes#define PRC_PARAMPROB 20 /* header incorrect */ 1671541Srgrimes 1681541Srgrimes#define PRC_NCMDS 21 1691541Srgrimes 1701541Srgrimes#define PRC_IS_REDIRECT(cmd) \ 1711541Srgrimes ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) 1721541Srgrimes 1731541Srgrimes#ifdef PRCREQUESTS 1741541Srgrimeschar *prcrequests[] = { 1751541Srgrimes "IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2", 1761541Srgrimes "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", 1771541Srgrimes "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 1781541Srgrimes "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", 1791541Srgrimes "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", 1801541Srgrimes "PARAMPROB" 1811541Srgrimes}; 1821541Srgrimes#endif 1831541Srgrimes 1841541Srgrimes/* 1851541Srgrimes * The arguments to ctloutput are: 1861541Srgrimes * (*protosw[].pr_ctloutput)(req, so, level, optname, optval); 1871541Srgrimes * req is one of the actions listed below, so is a (struct socket *), 1881541Srgrimes * level is an indication of which protocol layer the option is intended. 1891541Srgrimes * optname is a protocol dependent socket option request, 1901541Srgrimes * optval is a pointer to a mbuf-chain pointer, for value-return results. 1911541Srgrimes * The protocol is responsible for disposal of the mbuf chain *optval 1921541Srgrimes * if supplied, 1931541Srgrimes * the caller is responsible for any space held by *optval, when returned. 1941541Srgrimes * A non-zero return from usrreq gives an 1951541Srgrimes * UNIX error number which should be passed to higher level software. 1961541Srgrimes */ 1971541Srgrimes#define PRCO_GETOPT 0 1981541Srgrimes#define PRCO_SETOPT 1 1991541Srgrimes 2001541Srgrimes#define PRCO_NCMDS 2 2011541Srgrimes 2021541Srgrimes#ifdef PRCOREQUESTS 2031541Srgrimeschar *prcorequests[] = { 2041541Srgrimes "GETOPT", "SETOPT", 2051541Srgrimes}; 2061541Srgrimes#endif 2071541Srgrimes 2081541Srgrimes#ifdef KERNEL 2091541Srgrimesextern struct protosw *pffindproto(), *pffindtype(); 2101541Srgrimes#endif 211