netwerk/sctp/src/user_inpcb.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/sctp/src/user_inpcb.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,378 @@
     1.4 +/*-
     1.5 + * Copyright (c) 1982, 1986, 1990, 1993
     1.6 + *	The Regents of the University of California.  All rights reserved.
     1.7 + *
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + * 1. Redistributions of source code must retain the above copyright
    1.12 + *    notice, this list of conditions and the following disclaimer.
    1.13 + * 2. Redistributions in binary form must reproduce the above copyright
    1.14 + *    notice, this list of conditions and the following disclaimer in the
    1.15 + *    documentation and/or other materials provided with the distribution.
    1.16 + * 4. Neither the name of the University nor the names of its contributors
    1.17 + *    may be used to endorse or promote products derived from this software
    1.18 + *    without specific prior written permission.
    1.19 + *
    1.20 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    1.21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.23 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    1.24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.30 + * SUCH DAMAGE.
    1.31 + *
    1.32 + *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
    1.33 + * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.100.2.1 2007/12/07 05:46:08 kmacy Exp $
    1.34 + */
    1.35 +
    1.36 +#ifndef _USER_INPCB_H_
    1.37 +#define _USER_INPCB_H_
    1.38 +
    1.39 +#include <user_route.h> /* was <net/route.h> */
    1.40 +
    1.41 +#define	in6pcb		inpcb	/* for KAME src sync over BSD*'s */
    1.42 +#define	in6p_sp		inp_sp	/* for KAME src sync over BSD*'s */
    1.43 +struct inpcbpolicy;
    1.44 +
    1.45 +/*
    1.46 + * Struct inpcb is the ommon structure pcb for the Internet Protocol
    1.47 + * implementation.
    1.48 + *
    1.49 + * Pointers to local and foreign host table entries, local and foreign socket
    1.50 + * numbers, and pointers up (to a socket structure) and down (to a
    1.51 + * protocol-specific control block) are stored here.
    1.52 + */
    1.53 +LIST_HEAD(inpcbhead, inpcb);
    1.54 +LIST_HEAD(inpcbporthead, inpcbport);
    1.55 +
    1.56 +/*
    1.57 + * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
    1.58 + * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
    1.59 + * the following structure.
    1.60 + */
    1.61 +struct in_addr_4in6 {
    1.62 +	u_int32_t	ia46_pad32[3];
    1.63 +	struct	in_addr	ia46_addr4;
    1.64 +};
    1.65 +
    1.66 +/*
    1.67 + * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553.  in_conninfo has
    1.68 + * some extra padding to accomplish this.
    1.69 + */
    1.70 +struct in_endpoints {
    1.71 +	u_int16_t	ie_fport;		/* foreign port */
    1.72 +	u_int16_t	ie_lport;		/* local port */
    1.73 +	/* protocol dependent part, local and foreign addr */
    1.74 +	union {
    1.75 +		/* foreign host table entry */
    1.76 +		struct	in_addr_4in6 ie46_foreign;
    1.77 +		struct	in6_addr ie6_foreign;
    1.78 +	} ie_dependfaddr;
    1.79 +	union {
    1.80 +		/* local host table entry */
    1.81 +		struct	in_addr_4in6 ie46_local;
    1.82 +		struct	in6_addr ie6_local;
    1.83 +	} ie_dependladdr;
    1.84 +#define	ie_faddr	ie_dependfaddr.ie46_foreign.ia46_addr4
    1.85 +#define	ie_laddr	ie_dependladdr.ie46_local.ia46_addr4
    1.86 +#define	ie6_faddr	ie_dependfaddr.ie6_foreign
    1.87 +#define	ie6_laddr	ie_dependladdr.ie6_local
    1.88 +};
    1.89 +
    1.90 +/*
    1.91 + * XXX The defines for inc_* are hacks and should be changed to direct
    1.92 + * references.
    1.93 + */
    1.94 +struct in_conninfo {
    1.95 +	u_int8_t	inc_flags;
    1.96 +	u_int8_t	inc_len;
    1.97 +	u_int16_t	inc_pad;	/* XXX alignment for in_endpoints */
    1.98 +	/* protocol dependent part */
    1.99 +	struct	in_endpoints inc_ie;
   1.100 +};
   1.101 +#define inc_isipv6	inc_flags	/* temp compatability */
   1.102 +#define	inc_fport	inc_ie.ie_fport
   1.103 +#define	inc_lport	inc_ie.ie_lport
   1.104 +#define	inc_faddr	inc_ie.ie_faddr
   1.105 +#define	inc_laddr	inc_ie.ie_laddr
   1.106 +#define	inc6_faddr	inc_ie.ie6_faddr
   1.107 +#define	inc6_laddr	inc_ie.ie6_laddr
   1.108 +
   1.109 +struct	icmp6_filter;
   1.110 +
   1.111 +struct inpcb {
   1.112 +	LIST_ENTRY(inpcb) inp_hash;	/* hash list */
   1.113 +	LIST_ENTRY(inpcb) inp_list;	/* list for all PCBs of this proto */
   1.114 +	void	*inp_ppcb;		/* pointer to per-protocol pcb */
   1.115 +	struct	inpcbinfo *inp_pcbinfo;	/* PCB list info */
   1.116 +	struct	socket *inp_socket;	/* back pointer to socket */
   1.117 +
   1.118 +	u_int32_t	inp_flow;
   1.119 +	int	inp_flags;		/* generic IP/datagram flags */
   1.120 +
   1.121 +	u_char	inp_vflag;		/* IP version flag (v4/v6) */
   1.122 +#define	INP_IPV4	0x1
   1.123 +#define	INP_IPV6	0x2
   1.124 +#define	INP_IPV6PROTO	0x4		/* opened under IPv6 protocol */
   1.125 +#define	INP_TIMEWAIT	0x8		/* .. probably doesn't go here */
   1.126 +#define	INP_ONESBCAST	0x10		/* send all-ones broadcast */
   1.127 +#define	INP_DROPPED	0x20		/* protocol drop flag */
   1.128 +#define	INP_SOCKREF	0x40		/* strong socket reference */
   1.129 +#define INP_CONN        0x80
   1.130 +	u_char	inp_ip_ttl;		/* time to live proto */
   1.131 +	u_char	inp_ip_p;		/* protocol proto */
   1.132 +	u_char	inp_ip_minttl;		/* minimum TTL or drop */
   1.133 +	uint32_t inp_ispare1;		/* connection id / queue id */
   1.134 +	void	*inp_pspare[2];		/* rtentry / general use */
   1.135 +
   1.136 +	/* Local and foreign ports, local and foreign addr. */
   1.137 +	struct	in_conninfo inp_inc;
   1.138 +
   1.139 +					/* list for this PCB's local port */
   1.140 +	struct	label *inp_label;	/* MAC label */
   1.141 +	struct	inpcbpolicy *inp_sp;    /* for IPSEC */
   1.142 +
   1.143 +	/* Protocol-dependent part; options. */
   1.144 +	struct {
   1.145 +		u_char	inp4_ip_tos;		/* type of service proto */
   1.146 +		struct	mbuf *inp4_options;	/* IP options */
   1.147 +		struct	ip_moptions *inp4_moptions; /* IP multicast options */
   1.148 +	} inp_depend4;
   1.149 +#define	inp_fport	inp_inc.inc_fport
   1.150 +#define	inp_lport	inp_inc.inc_lport
   1.151 +#define	inp_faddr	inp_inc.inc_faddr
   1.152 +#define	inp_laddr	inp_inc.inc_laddr
   1.153 +#define	inp_ip_tos	inp_depend4.inp4_ip_tos
   1.154 +#define	inp_options	inp_depend4.inp4_options
   1.155 +#define	inp_moptions	inp_depend4.inp4_moptions
   1.156 +	struct {
   1.157 +		/* IP options */
   1.158 +		struct	mbuf *inp6_options;
   1.159 +		/* IP6 options for outgoing packets */
   1.160 +		struct	ip6_pktopts *inp6_outputopts;
   1.161 +		/* IP multicast options */
   1.162 +#if 0
   1.163 +		struct	ip6_moptions *inp6_moptions;
   1.164 +#endif
   1.165 +		/* ICMPv6 code type filter */
   1.166 +		struct	icmp6_filter *inp6_icmp6filt;
   1.167 +		/* IPV6_CHECKSUM setsockopt */
   1.168 +		int	inp6_cksum;
   1.169 +		short	inp6_hops;
   1.170 +	} inp_depend6;
   1.171 +	LIST_ENTRY(inpcb) inp_portlist;
   1.172 +	struct	inpcbport *inp_phd;	/* head of this list */
   1.173 +#define inp_zero_size offsetof(struct inpcb, inp_gencnt)
   1.174 +	struct mtx	inp_mtx;
   1.175 +
   1.176 +#define	in6p_faddr	inp_inc.inc6_faddr
   1.177 +#define	in6p_laddr	inp_inc.inc6_laddr
   1.178 +#define	in6p_hops	inp_depend6.inp6_hops	/* default hop limit */
   1.179 +#define	in6p_ip6_nxt	inp_ip_p
   1.180 +#define	in6p_flowinfo	inp_flow
   1.181 +#define	in6p_vflag	inp_vflag
   1.182 +#define	in6p_options	inp_depend6.inp6_options
   1.183 +#define	in6p_outputopts	inp_depend6.inp6_outputopts
   1.184 +#if 0
   1.185 +#define	in6p_moptions	inp_depend6.inp6_moptions
   1.186 +#endif
   1.187 +#define	in6p_icmp6filt	inp_depend6.inp6_icmp6filt
   1.188 +#define	in6p_cksum	inp_depend6.inp6_cksum
   1.189 +#define	in6p_flags	inp_flags  /* for KAME src sync over BSD*'s */
   1.190 +#define	in6p_socket	inp_socket  /* for KAME src sync over BSD*'s */
   1.191 +#define	in6p_lport	inp_lport  /* for KAME src sync over BSD*'s */
   1.192 +#define	in6p_fport	inp_fport  /* for KAME src sync over BSD*'s */
   1.193 +#define	in6p_ppcb	inp_ppcb  /* for KAME src sync over BSD*'s */
   1.194 +};
   1.195 +/*
   1.196 + * The range of the generation count, as used in this implementation, is 9e19.
   1.197 + * We would have to create 300 billion connections per second for this number
   1.198 + * to roll over in a year.  This seems sufficiently unlikely that we simply
   1.199 + * don't concern ourselves with that possibility.
   1.200 + */
   1.201 +
   1.202 +struct inpcbport {
   1.203 +	LIST_ENTRY(inpcbport) phd_hash;
   1.204 +	struct inpcbhead phd_pcblist;
   1.205 +	u_short phd_port;
   1.206 +};
   1.207 +
   1.208 +/*
   1.209 + * Global data structure for each high-level protocol (UDP, TCP, ...) in both
   1.210 + * IPv4 and IPv6.  Holds inpcb lists and information for managing them.
   1.211 + */
   1.212 +struct inpcbinfo {
   1.213 +	/*
   1.214 +	 * Global list of inpcbs on the protocol.
   1.215 +	 */
   1.216 +	struct inpcbhead	*ipi_listhead;
   1.217 +	u_int			 ipi_count;
   1.218 +
   1.219 +	/*
   1.220 +	 * Global hash of inpcbs, hashed by local and foreign addresses and
   1.221 +	 * port numbers.
   1.222 +	 */
   1.223 +	struct inpcbhead	*ipi_hashbase;
   1.224 +	u_long			 ipi_hashmask;
   1.225 +
   1.226 +	/*
   1.227 +	 * Global hash of inpcbs, hashed by only local port number.
   1.228 +	 */
   1.229 +	struct inpcbporthead	*ipi_porthashbase;
   1.230 +	u_long			 ipi_porthashmask;
   1.231 +
   1.232 +	/*
   1.233 +	 * Fields associated with port lookup and allocation.
   1.234 +	 */
   1.235 +	u_short			 ipi_lastport;
   1.236 +	u_short			 ipi_lastlow;
   1.237 +	u_short			 ipi_lasthi;
   1.238 +
   1.239 +	/*
   1.240 +	 * UMA zone from which inpcbs are allocated for this protocol.
   1.241 +	 */
   1.242 +	struct	uma_zone	*ipi_zone;
   1.243 +
   1.244 +	/*
   1.245 +	 * Generation count--incremented each time a connection is allocated
   1.246 +	 * or freed.
   1.247 +	 */
   1.248 +	struct mtx		 ipi_mtx;
   1.249 +
   1.250 +	/*
   1.251 +	 * vimage 1
   1.252 +	 * general use 1
   1.253 +	 */
   1.254 +	void 			*ipi_pspare[2];
   1.255 +};
   1.256 +
   1.257 +#define INP_LOCK_INIT(inp, d, t) \
   1.258 +	mtx_init(&(inp)->inp_mtx, (d), (t), MTX_DEF | MTX_RECURSE | MTX_DUPOK)
   1.259 +#define INP_LOCK_DESTROY(inp)	mtx_destroy(&(inp)->inp_mtx)
   1.260 +#define INP_LOCK(inp)		mtx_lock(&(inp)->inp_mtx)
   1.261 +#define INP_UNLOCK(inp)		mtx_unlock(&(inp)->inp_mtx)
   1.262 +#define INP_LOCK_ASSERT(inp)	mtx_assert(&(inp)->inp_mtx, MA_OWNED)
   1.263 +#define	INP_UNLOCK_ASSERT(inp)	mtx_assert(&(inp)->inp_mtx, MA_NOTOWNED)
   1.264 +
   1.265 +#define INP_INFO_LOCK_INIT(ipi, d) \
   1.266 +	mtx_init(&(ipi)->ipi_mtx, (d), NULL, MTX_DEF | MTX_RECURSE)
   1.267 +#define INP_INFO_LOCK_DESTROY(ipi)  mtx_destroy(&(ipi)->ipi_mtx)
   1.268 +#define INP_INFO_RLOCK(ipi)	mtx_lock(&(ipi)->ipi_mtx)
   1.269 +#define INP_INFO_WLOCK(ipi)	mtx_lock(&(ipi)->ipi_mtx)
   1.270 +#define INP_INFO_RUNLOCK(ipi)	mtx_unlock(&(ipi)->ipi_mtx)
   1.271 +#define INP_INFO_WUNLOCK(ipi)	mtx_unlock(&(ipi)->ipi_mtx)
   1.272 +#define INP_INFO_RLOCK_ASSERT(ipi)	mtx_assert(&(ipi)->ipi_mtx, MA_OWNED)
   1.273 +#define INP_INFO_WLOCK_ASSERT(ipi)	mtx_assert(&(ipi)->ipi_mtx, MA_OWNED)
   1.274 +#define INP_INFO_UNLOCK_ASSERT(ipi)	mtx_assert(&(ipi)->ipi_mtx, MA_NOTOWNED)
   1.275 +
   1.276 +#define INP_PCBHASH(faddr, lport, fport, mask) \
   1.277 +	(((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
   1.278 +#define INP_PCBPORTHASH(lport, mask) \
   1.279 +	(ntohs((lport)) & (mask))
   1.280 +
   1.281 +/* flags in inp_flags: */
   1.282 +#define	INP_RECVOPTS		0x01	/* receive incoming IP options */
   1.283 +#define	INP_RECVRETOPTS		0x02	/* receive IP options for reply */
   1.284 +#define	INP_RECVDSTADDR		0x04	/* receive IP dst address */
   1.285 +#define	INP_HDRINCL		0x08	/* user supplies entire IP header */
   1.286 +#define	INP_HIGHPORT		0x10	/* user wants "high" port binding */
   1.287 +#define	INP_LOWPORT		0x20	/* user wants "low" port binding */
   1.288 +#define	INP_ANONPORT		0x40	/* port chosen for user */
   1.289 +#define	INP_RECVIF		0x80	/* receive incoming interface */
   1.290 +#define	INP_MTUDISC		0x100	/* user can do MTU discovery */
   1.291 +#define	INP_FAITH		0x200	/* accept FAITH'ed connections */
   1.292 +#define	INP_RECVTTL		0x400	/* receive incoming IP TTL */
   1.293 +#define	INP_DONTFRAG		0x800	/* don't fragment packet */
   1.294 +
   1.295 +#define IN6P_IPV6_V6ONLY	0x008000 /* restrict AF_INET6 socket for v6 */
   1.296 +
   1.297 +#define	IN6P_PKTINFO		0x010000 /* receive IP6 dst and I/F */
   1.298 +#define	IN6P_HOPLIMIT		0x020000 /* receive hoplimit */
   1.299 +#define	IN6P_HOPOPTS		0x040000 /* receive hop-by-hop options */
   1.300 +#define	IN6P_DSTOPTS		0x080000 /* receive dst options after rthdr */
   1.301 +#define	IN6P_RTHDR		0x100000 /* receive routing header */
   1.302 +#define	IN6P_RTHDRDSTOPTS	0x200000 /* receive dstoptions before rthdr */
   1.303 +#define	IN6P_TCLASS		0x400000 /* receive traffic class value */
   1.304 +#define	IN6P_AUTOFLOWLABEL	0x800000 /* attach flowlabel automatically */
   1.305 +#define	IN6P_RFC2292		0x40000000 /* used RFC2292 API on the socket */
   1.306 +#define	IN6P_MTU		0x80000000 /* receive path MTU */
   1.307 +
   1.308 +#define	INP_CONTROLOPTS		(INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
   1.309 +				 INP_RECVIF|INP_RECVTTL|\
   1.310 +				 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
   1.311 +				 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
   1.312 +				 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
   1.313 +				 IN6P_MTU)
   1.314 +#define	INP_UNMAPPABLEOPTS	(IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
   1.315 +				 IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
   1.316 +
   1.317 + /* for KAME src sync over BSD*'s */
   1.318 +#define	IN6P_HIGHPORT		INP_HIGHPORT
   1.319 +#define	IN6P_LOWPORT		INP_LOWPORT
   1.320 +#define	IN6P_ANONPORT		INP_ANONPORT
   1.321 +#define	IN6P_RECVIF		INP_RECVIF
   1.322 +#define	IN6P_MTUDISC		INP_MTUDISC
   1.323 +#define	IN6P_FAITH		INP_FAITH
   1.324 +#define	IN6P_CONTROLOPTS INP_CONTROLOPTS
   1.325 +	/*
   1.326 +	 * socket AF version is {newer than,or include}
   1.327 +	 * actual datagram AF version
   1.328 +	 */
   1.329 +
   1.330 +#define	INPLOOKUP_WILDCARD	1
   1.331 +#define	sotoinpcb(so)	((struct inpcb *)(so)->so_pcb)
   1.332 +#define	sotoin6pcb(so)	sotoinpcb(so) /* for KAME src sync over BSD*'s */
   1.333 +
   1.334 +#define	INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
   1.335 +
   1.336 +#define	INP_CHECK_SOCKAF(so, af)	(INP_SOCKAF(so) == af)
   1.337 +
   1.338 +/* #ifdef _KERNEL */
   1.339 +extern int	ipport_reservedhigh;
   1.340 +extern int	ipport_reservedlow;
   1.341 +extern int	ipport_lowfirstauto;
   1.342 +extern int	ipport_lowlastauto;
   1.343 +extern int	ipport_firstauto;
   1.344 +extern int	ipport_lastauto;
   1.345 +extern int	ipport_hifirstauto;
   1.346 +extern int	ipport_hilastauto;
   1.347 +extern struct callout ipport_tick_callout;
   1.348 +
   1.349 +void	in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
   1.350 +int	in_pcballoc(struct socket *, struct inpcbinfo *);
   1.351 +int	in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
   1.352 +int	in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
   1.353 +void	in_pcbdetach(struct inpcb *);
   1.354 +void	in_pcbdisconnect(struct inpcb *);
   1.355 +void	in_pcbdrop(struct inpcb *);
   1.356 +void	in_pcbfree(struct inpcb *);
   1.357 +int	in_pcbinshash(struct inpcb *);
   1.358 +struct inpcb *
   1.359 +	in_pcblookup_local(struct inpcbinfo *,
   1.360 +	    struct in_addr, u_int, int);
   1.361 +struct inpcb *
   1.362 +	in_pcblookup_hash(struct inpcbinfo *, struct in_addr, u_int,
   1.363 +	    struct in_addr, u_int, int, struct ifnet *);
   1.364 +void	in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
   1.365 +	    int, struct inpcb *(*)(struct inpcb *, int));
   1.366 +void	in_pcbrehash(struct inpcb *);
   1.367 +void	in_pcbsetsolabel(struct socket *so);
   1.368 +int	in_getpeeraddr(struct socket *so, struct sockaddr **nam);
   1.369 +int	in_getsockaddr(struct socket *so, struct sockaddr **nam);
   1.370 +void	in_pcbsosetlabel(struct socket *so);
   1.371 +void	in_pcbremlists(struct inpcb *inp);
   1.372 +void	ipport_tick(void *xtp);
   1.373 +
   1.374 +/*
   1.375 + * Debugging routines compiled in when DDB is present.
   1.376 + */
   1.377 +void	db_print_inpcb(struct inpcb *inp, const char *name, int indent);
   1.378 +
   1.379 +/* #endif  _KERNEL */
   1.380 +
   1.381 +#endif /* !_NETINET_IN_PCB_H_ */

mercurial