Home | History | Annotate | Line # | Download | only in netinet
in_pcb.h revision 1.68
      1  1.68  riastrad /*	$NetBSD: in_pcb.h,v 1.68 2020/08/28 07:01:57 riastradh Exp $	*/
      2  1.27    itojun 
      3  1.27    itojun /*
      4  1.27    itojun  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5  1.27    itojun  * All rights reserved.
      6  1.31    itojun  *
      7  1.27    itojun  * Redistribution and use in source and binary forms, with or without
      8  1.27    itojun  * modification, are permitted provided that the following conditions
      9  1.27    itojun  * are met:
     10  1.27    itojun  * 1. Redistributions of source code must retain the above copyright
     11  1.27    itojun  *    notice, this list of conditions and the following disclaimer.
     12  1.27    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.27    itojun  *    notice, this list of conditions and the following disclaimer in the
     14  1.27    itojun  *    documentation and/or other materials provided with the distribution.
     15  1.27    itojun  * 3. Neither the name of the project nor the names of its contributors
     16  1.27    itojun  *    may be used to endorse or promote products derived from this software
     17  1.27    itojun  *    without specific prior written permission.
     18  1.31    itojun  *
     19  1.27    itojun  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20  1.27    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.27    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.27    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23  1.27    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.27    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.27    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.27    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.27    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.27    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.27    itojun  * SUCH DAMAGE.
     30  1.27    itojun  */
     31   1.7       cgd 
     32   1.1       cgd /*
     33   1.6   mycroft  * Copyright (c) 1982, 1986, 1990, 1993
     34   1.6   mycroft  *	The Regents of the University of California.  All rights reserved.
     35   1.1       cgd  *
     36   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     37   1.1       cgd  * modification, are permitted provided that the following conditions
     38   1.1       cgd  * are met:
     39   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     40   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     41   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     42   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     43   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     44  1.34       agc  * 3. Neither the name of the University nor the names of its contributors
     45   1.1       cgd  *    may be used to endorse or promote products derived from this software
     46   1.1       cgd  *    without specific prior written permission.
     47   1.1       cgd  *
     48   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58   1.1       cgd  * SUCH DAMAGE.
     59   1.1       cgd  *
     60   1.7       cgd  *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
     61   1.1       cgd  */
     62   1.1       cgd 
     63  1.24     perry #ifndef _NETINET_IN_PCB_H_
     64  1.24     perry #define _NETINET_IN_PCB_H_
     65  1.24     perry 
     66  1.68  riastrad #include <sys/types.h>
     67  1.68  riastrad 
     68  1.60     ozaki #include <net/route.h>
     69  1.68  riastrad 
     70  1.68  riastrad #include <netinet/in.h>
     71  1.35    itojun #include <netinet/in_pcb_hdr.h>
     72  1.68  riastrad #include <netinet/ip.h>
     73  1.68  riastrad 
     74  1.68  riastrad struct ip_moptions;
     75  1.68  riastrad struct mbuf;
     76  1.10   mycroft 
     77   1.1       cgd /*
     78   1.1       cgd  * Common structure pcb for internet protocol implementation.
     79   1.1       cgd  * Here are stored pointers to local and foreign host table
     80   1.1       cgd  * entries, local and foreign socket numbers, and pointers
     81   1.1       cgd  * up (to a socket structure) and down (to a protocol-specific)
     82   1.1       cgd  * control block.
     83   1.1       cgd  */
     84   1.1       cgd struct inpcb {
     85  1.35    itojun 	struct inpcb_hdr inp_head;
     86  1.35    itojun #define inp_hash	inp_head.inph_hash
     87  1.35    itojun #define inp_queue	inp_head.inph_queue
     88  1.35    itojun #define inp_af		inp_head.inph_af
     89  1.35    itojun #define inp_ppcb	inp_head.inph_ppcb
     90  1.35    itojun #define inp_state	inp_head.inph_state
     91  1.50  christos #define inp_portalgo	inp_head.inph_portalgo
     92  1.35    itojun #define inp_socket	inp_head.inph_socket
     93  1.35    itojun #define inp_table	inp_head.inph_table
     94  1.35    itojun #define inp_sp		inp_head.inph_sp
     95  1.35    itojun 	struct	  route inp_route;	/* placeholder for routing entry */
     96   1.9       cgd 	u_int16_t inp_fport;		/* foreign port */
     97   1.9       cgd 	u_int16_t inp_lport;		/* local port */
     98   1.9       cgd 	int	  inp_flags;		/* generic IP/datagram flags */
     99   1.9       cgd 	struct	  ip inp_ip;		/* header prototype; should have more */
    100   1.9       cgd 	struct	  mbuf *inp_options;	/* IP options */
    101   1.9       cgd 	struct	  ip_moptions *inp_moptions; /* IP multicast options */
    102  1.22      matt 	int	  inp_errormtu;		/* MTU of last xmit status = EMSGSIZE */
    103  1.47   minskim 	uint8_t	  inp_ip_minttl;
    104  1.49  christos 	bool      inp_bindportonsend;
    105  1.65  christos 	struct    in_addr inp_prefsrcip; /* preferred src IP when wild  */
    106  1.67  riastrad 	pcb_overudp_cb_t inp_overudp_cb;
    107  1.67  riastrad 	void      *inp_overudp_arg;
    108   1.1       cgd };
    109  1.35    itojun 
    110  1.18   mycroft #define	inp_faddr	inp_ip.ip_dst
    111  1.18   mycroft #define	inp_laddr	inp_ip.ip_src
    112   1.1       cgd 
    113   1.1       cgd /* flags in inp_flags: */
    114  1.51  christos #define	INP_RECVOPTS		0x0001	/* receive incoming IP options */
    115  1.51  christos #define	INP_RECVRETOPTS		0x0002	/* receive IP options for reply */
    116  1.51  christos #define	INP_RECVDSTADDR		0x0004	/* receive IP dst address */
    117  1.51  christos #define	INP_HDRINCL		0x0008	/* user supplies entire IP header */
    118  1.51  christos #define	INP_HIGHPORT		0x0010	/* (unused; FreeBSD compat) */
    119  1.51  christos #define	INP_LOWPORT		0x0020	/* user wants "low" port binding */
    120  1.51  christos #define	INP_ANONPORT		0x0040	/* port chosen for user */
    121  1.51  christos #define	INP_RECVIF		0x0080	/* receive incoming interface */
    122  1.39      manu /* XXX should move to an UDP control block */
    123  1.51  christos #define INP_ESPINUDP		0x0100	/* ESP over UDP for NAT-T */
    124  1.51  christos #define INP_ESPINUDP_NON_IKE	0x0200	/* ESP over UDP for NAT-T */
    125  1.51  christos #define INP_NOHEADER		0x0400	/* Kernel removes IP header
    126  1.43    dyoung 					 * before feeding a packet
    127  1.43    dyoung 					 * to the raw socket user.
    128  1.43    dyoung 					 * The socket user will
    129  1.43    dyoung 					 * not supply an IP header.
    130  1.43    dyoung 					 * Cancels INP_HDRINCL.
    131  1.43    dyoung 					 */
    132  1.51  christos #define	INP_RECVTTL		0x0800	/* receive incoming IP TTL */
    133  1.65  christos #define	INP_RECVPKTINFO		0x1000	/* receive IP dst if/addr */
    134  1.46   minskim #define	INP_CONTROLOPTS		(INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
    135  1.65  christos 				INP_RECVIF|INP_RECVTTL|INP_RECVPKTINFO)
    136   1.1       cgd 
    137  1.16   mycroft #define	sotoinpcb(so)		((struct inpcb *)(so)->so_pcb)
    138  1.63     ozaki #define	inp_lock(inp)		solock((inp)->inp_socket)
    139  1.63     ozaki #define	inp_unlock(inp)		sounlock((inp)->inp_socket)
    140  1.63     ozaki #define	inp_locked(inp)		solocked((inp)->inp_socket)
    141   1.1       cgd 
    142   1.8       jtc #ifdef _KERNEL
    143  1.68  riastrad 
    144  1.68  riastrad #include <sys/kauth.h>
    145  1.68  riastrad #include <sys/queue.h>
    146  1.68  riastrad 
    147  1.68  riastrad struct inpcbtable;
    148  1.68  riastrad struct lwp;
    149  1.68  riastrad struct rtentry;
    150  1.68  riastrad struct sockaddr_in;
    151  1.68  riastrad struct socket;
    152  1.68  riastrad struct vestigial_inpcb;
    153  1.68  riastrad 
    154  1.38    itojun void	in_losing(struct inpcb *);
    155  1.38    itojun int	in_pcballoc(struct socket *, void *);
    156  1.64       ryo int	in_pcbbindableaddr(struct sockaddr_in *, kauth_cred_t);
    157  1.56       rtr int	in_pcbbind(void *, struct sockaddr_in *, struct lwp *);
    158  1.58       rtr int	in_pcbconnect(void *, struct sockaddr_in *, struct lwp *);
    159  1.38    itojun void	in_pcbdetach(void *);
    160  1.38    itojun void	in_pcbdisconnect(void *);
    161  1.38    itojun void	in_pcbinit(struct inpcbtable *, int, int);
    162  1.35    itojun struct inpcb *
    163  1.38    itojun 	in_pcblookup_port(struct inpcbtable *,
    164  1.48    dyoung 			  struct in_addr, u_int, int, struct vestigial_inpcb *);
    165  1.13   mycroft struct inpcb *
    166  1.38    itojun 	in_pcblookup_bind(struct inpcbtable *,
    167  1.37      matt 	    struct in_addr, u_int);
    168  1.17   mycroft struct inpcb *
    169  1.38    itojun 	in_pcblookup_connect(struct inpcbtable *,
    170  1.48    dyoung 			     struct in_addr, u_int, struct in_addr, u_int,
    171  1.48    dyoung 			     struct vestigial_inpcb *);
    172  1.38    itojun int	in_pcbnotify(struct inpcbtable *, struct in_addr, u_int,
    173  1.37      matt 	    struct in_addr, u_int, int, void (*)(struct inpcb *, int));
    174  1.38    itojun void	in_pcbnotifyall(struct inpcbtable *, struct in_addr, int,
    175  1.37      matt 	    void (*)(struct inpcb *, int));
    176  1.38    itojun void	in_pcbpurgeif0(struct inpcbtable *, struct ifnet *);
    177  1.38    itojun void	in_pcbpurgeif(struct inpcbtable *, struct ifnet *);
    178  1.55     seanb void	in_purgeifmcast(struct ip_moptions *, struct ifnet *);
    179  1.38    itojun void	in_pcbstate(struct inpcb *, int);
    180  1.38    itojun void	in_rtchange(struct inpcb *, int);
    181  1.57       rtr void	in_setpeeraddr(struct inpcb *, struct sockaddr_in *);
    182  1.57       rtr void	in_setsockaddr(struct inpcb *, struct sockaddr_in *);
    183  1.21   thorpej struct rtentry *
    184  1.38    itojun 	in_pcbrtentry(struct inpcb *);
    185  1.61     ozaki void	in_pcbrtentry_unref(struct rtentry *, struct inpcb *);
    186  1.67  riastrad 
    187  1.67  riastrad static inline void
    188  1.67  riastrad in_pcb_register_overudp_cb(struct inpcb *inp, pcb_overudp_cb_t cb, void *arg)
    189  1.67  riastrad {
    190  1.67  riastrad 
    191  1.67  riastrad 	inp->inp_overudp_cb = cb;
    192  1.67  riastrad 	inp->inp_overudp_arg = arg;
    193  1.67  riastrad }
    194  1.24     perry 
    195  1.68  riastrad #endif	/* _KERNEL */
    196  1.68  riastrad 
    197  1.68  riastrad #endif	/* !_NETINET_IN_PCB_H_ */
    198