xref: /f-stack/tools/compat/include/netinet/udp_var.h (revision 1eaf0ac3)
1*1eaf0ac3Slogwang /*-
2*1eaf0ac3Slogwang  * Copyright (c) 1982, 1986, 1989, 1993
3*1eaf0ac3Slogwang  *	The Regents of the University of California.
4*1eaf0ac3Slogwang  * All rights reserved.
5*1eaf0ac3Slogwang  *
6*1eaf0ac3Slogwang  * Redistribution and use in source and binary forms, with or without
7*1eaf0ac3Slogwang  * modification, are permitted provided that the following conditions
8*1eaf0ac3Slogwang  * are met:
9*1eaf0ac3Slogwang  * 1. Redistributions of source code must retain the above copyright
10*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer.
11*1eaf0ac3Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
12*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer in the
13*1eaf0ac3Slogwang  *    documentation and/or other materials provided with the distribution.
14*1eaf0ac3Slogwang  * 4. Neither the name of the University nor the names of its contributors
15*1eaf0ac3Slogwang  *    may be used to endorse or promote products derived from this software
16*1eaf0ac3Slogwang  *    without specific prior written permission.
17*1eaf0ac3Slogwang  *
18*1eaf0ac3Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19*1eaf0ac3Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*1eaf0ac3Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*1eaf0ac3Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22*1eaf0ac3Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*1eaf0ac3Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*1eaf0ac3Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*1eaf0ac3Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*1eaf0ac3Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*1eaf0ac3Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*1eaf0ac3Slogwang  * SUCH DAMAGE.
29*1eaf0ac3Slogwang  *
30*1eaf0ac3Slogwang  *	@(#)udp_var.h	8.1 (Berkeley) 6/10/93
31*1eaf0ac3Slogwang  * $FreeBSD$
32*1eaf0ac3Slogwang  */
33*1eaf0ac3Slogwang 
34*1eaf0ac3Slogwang #ifndef _NETINET_UDP_VAR_H_
35*1eaf0ac3Slogwang #define	_NETINET_UDP_VAR_H_
36*1eaf0ac3Slogwang 
37*1eaf0ac3Slogwang /*
38*1eaf0ac3Slogwang  * UDP kernel structures and variables.
39*1eaf0ac3Slogwang  */
40*1eaf0ac3Slogwang struct udpiphdr {
41*1eaf0ac3Slogwang 	struct ipovly	ui_i;		/* overlaid ip structure */
42*1eaf0ac3Slogwang 	struct udphdr	ui_u;		/* udp header */
43*1eaf0ac3Slogwang };
44*1eaf0ac3Slogwang #define	ui_x1		ui_i.ih_x1
45*1eaf0ac3Slogwang #define	ui_v		ui_i.ih_x1[0]
46*1eaf0ac3Slogwang #define	ui_pr		ui_i.ih_pr
47*1eaf0ac3Slogwang #define	ui_len		ui_i.ih_len
48*1eaf0ac3Slogwang #define	ui_src		ui_i.ih_src
49*1eaf0ac3Slogwang #define	ui_dst		ui_i.ih_dst
50*1eaf0ac3Slogwang #define	ui_sport	ui_u.uh_sport
51*1eaf0ac3Slogwang #define	ui_dport	ui_u.uh_dport
52*1eaf0ac3Slogwang #define	ui_ulen		ui_u.uh_ulen
53*1eaf0ac3Slogwang #define	ui_sum		ui_u.uh_sum
54*1eaf0ac3Slogwang 
55*1eaf0ac3Slogwang struct inpcb;
56*1eaf0ac3Slogwang struct mbuf;
57*1eaf0ac3Slogwang 
58*1eaf0ac3Slogwang typedef void(*udp_tun_func_t)(struct mbuf *, int, struct inpcb *,
59*1eaf0ac3Slogwang 			      const struct sockaddr *, void *);
60*1eaf0ac3Slogwang typedef void(*udp_tun_icmp_t)(int, struct sockaddr *, void *, void *);
61*1eaf0ac3Slogwang 
62*1eaf0ac3Slogwang /*
63*1eaf0ac3Slogwang  * UDP control block; one per udp.
64*1eaf0ac3Slogwang  */
65*1eaf0ac3Slogwang struct udpcb {
66*1eaf0ac3Slogwang 	udp_tun_func_t	u_tun_func;	/* UDP kernel tunneling callback. */
67*1eaf0ac3Slogwang 	udp_tun_icmp_t  u_icmp_func;	/* UDP kernel tunneling icmp callback */
68*1eaf0ac3Slogwang 	u_int		u_flags;	/* Generic UDP flags. */
69*1eaf0ac3Slogwang 	uint16_t	u_rxcslen;	/* Coverage for incoming datagrams. */
70*1eaf0ac3Slogwang 	uint16_t	u_txcslen;	/* Coverage for outgoing datagrams. */
71*1eaf0ac3Slogwang 	void 		*u_tun_ctx;	/* Tunneling callback context. */
72*1eaf0ac3Slogwang };
73*1eaf0ac3Slogwang 
74*1eaf0ac3Slogwang #define	intoudpcb(ip)	((struct udpcb *)(ip)->inp_ppcb)
75*1eaf0ac3Slogwang #define	sotoudpcb(so)	(intoudpcb(sotoinpcb(so)))
76*1eaf0ac3Slogwang 
77*1eaf0ac3Slogwang 				/* IPsec: ESP in UDP tunneling: */
78*1eaf0ac3Slogwang #define	UF_ESPINUDP_NON_IKE	0x00000001	/* w/ non-IKE marker .. */
79*1eaf0ac3Slogwang 	/* .. per draft-ietf-ipsec-nat-t-ike-0[01],
80*1eaf0ac3Slogwang 	 * and draft-ietf-ipsec-udp-encaps-(00/)01.txt */
81*1eaf0ac3Slogwang #define	UF_ESPINUDP		0x00000002	/* w/ non-ESP marker. */
82*1eaf0ac3Slogwang 
83*1eaf0ac3Slogwang struct udpstat {
84*1eaf0ac3Slogwang 				/* input statistics: */
85*1eaf0ac3Slogwang 	uint64_t udps_ipackets;		/* total input packets */
86*1eaf0ac3Slogwang 	uint64_t udps_hdrops;		/* packet shorter than header */
87*1eaf0ac3Slogwang 	uint64_t udps_badsum;		/* checksum error */
88*1eaf0ac3Slogwang 	uint64_t udps_nosum;		/* no checksum */
89*1eaf0ac3Slogwang 	uint64_t udps_badlen;		/* data length larger than packet */
90*1eaf0ac3Slogwang 	uint64_t udps_noport;		/* no socket on port */
91*1eaf0ac3Slogwang 	uint64_t udps_noportbcast;	/* of above, arrived as broadcast */
92*1eaf0ac3Slogwang 	uint64_t udps_fullsock;		/* not delivered, input socket full */
93*1eaf0ac3Slogwang 	uint64_t udpps_pcbcachemiss;	/* input packets missing pcb cache */
94*1eaf0ac3Slogwang 	uint64_t udpps_pcbhashmiss;	/* input packets not for hashed pcb */
95*1eaf0ac3Slogwang 				/* output statistics: */
96*1eaf0ac3Slogwang 	uint64_t udps_opackets;		/* total output packets */
97*1eaf0ac3Slogwang 	uint64_t udps_fastout;		/* output packets on fast path */
98*1eaf0ac3Slogwang 	/* of no socket on port, arrived as multicast */
99*1eaf0ac3Slogwang 	uint64_t udps_noportmcast;
100*1eaf0ac3Slogwang 	uint64_t udps_filtermcast;	/* blocked by multicast filter */
101*1eaf0ac3Slogwang };
102*1eaf0ac3Slogwang 
103*1eaf0ac3Slogwang #ifdef _KERNEL
104*1eaf0ac3Slogwang #include <sys/counter.h>
105*1eaf0ac3Slogwang 
106*1eaf0ac3Slogwang VNET_PCPUSTAT_DECLARE(struct udpstat, udpstat);
107*1eaf0ac3Slogwang /*
108*1eaf0ac3Slogwang  * In-kernel consumers can use these accessor macros directly to update
109*1eaf0ac3Slogwang  * stats.
110*1eaf0ac3Slogwang  */
111*1eaf0ac3Slogwang #define	UDPSTAT_ADD(name, val)  \
112*1eaf0ac3Slogwang     VNET_PCPUSTAT_ADD(struct udpstat, udpstat, name, (val))
113*1eaf0ac3Slogwang #define	UDPSTAT_INC(name)	UDPSTAT_ADD(name, 1)
114*1eaf0ac3Slogwang 
115*1eaf0ac3Slogwang /*
116*1eaf0ac3Slogwang  * Kernel module consumers must use this accessor macro.
117*1eaf0ac3Slogwang  */
118*1eaf0ac3Slogwang void	kmod_udpstat_inc(int statnum);
119*1eaf0ac3Slogwang #define	KMOD_UDPSTAT_INC(name)	\
120*1eaf0ac3Slogwang     kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(uint64_t))
121*1eaf0ac3Slogwang #endif
122*1eaf0ac3Slogwang 
123*1eaf0ac3Slogwang /*
124*1eaf0ac3Slogwang  * Identifiers for UDP sysctl nodes.
125*1eaf0ac3Slogwang  */
126*1eaf0ac3Slogwang #define	UDPCTL_CHECKSUM		1	/* checksum UDP packets */
127*1eaf0ac3Slogwang #define	UDPCTL_STATS		2	/* statistics (read-only) */
128*1eaf0ac3Slogwang #define	UDPCTL_MAXDGRAM		3	/* max datagram size */
129*1eaf0ac3Slogwang #define	UDPCTL_RECVSPACE	4	/* default receive buffer space */
130*1eaf0ac3Slogwang #define	UDPCTL_PCBLIST		5	/* list of PCBs for UDP sockets */
131*1eaf0ac3Slogwang 
132*1eaf0ac3Slogwang #ifdef _KERNEL
133*1eaf0ac3Slogwang #include <netinet/in_pcb.h>
134*1eaf0ac3Slogwang SYSCTL_DECL(_net_inet_udp);
135*1eaf0ac3Slogwang 
136*1eaf0ac3Slogwang extern struct pr_usrreqs	udp_usrreqs;
137*1eaf0ac3Slogwang VNET_DECLARE(struct inpcbhead, udb);
138*1eaf0ac3Slogwang VNET_DECLARE(struct inpcbinfo, udbinfo);
139*1eaf0ac3Slogwang VNET_DECLARE(struct inpcbhead, ulitecb);
140*1eaf0ac3Slogwang VNET_DECLARE(struct inpcbinfo, ulitecbinfo);
141*1eaf0ac3Slogwang #define	V_udb			VNET(udb)
142*1eaf0ac3Slogwang #define	V_udbinfo		VNET(udbinfo)
143*1eaf0ac3Slogwang #define	V_ulitecb		VNET(ulitecb)
144*1eaf0ac3Slogwang #define	V_ulitecbinfo		VNET(ulitecbinfo)
145*1eaf0ac3Slogwang 
146*1eaf0ac3Slogwang extern u_long			udp_sendspace;
147*1eaf0ac3Slogwang extern u_long			udp_recvspace;
148*1eaf0ac3Slogwang VNET_DECLARE(int, udp_cksum);
149*1eaf0ac3Slogwang VNET_DECLARE(int, udp_blackhole);
150*1eaf0ac3Slogwang #define	V_udp_cksum		VNET(udp_cksum)
151*1eaf0ac3Slogwang #define	V_udp_blackhole		VNET(udp_blackhole)
152*1eaf0ac3Slogwang extern int			udp_log_in_vain;
153*1eaf0ac3Slogwang 
154*1eaf0ac3Slogwang static __inline struct inpcbinfo *
155*1eaf0ac3Slogwang udp_get_inpcbinfo(int protocol)
156*1eaf0ac3Slogwang {
157*1eaf0ac3Slogwang 	return (protocol == IPPROTO_UDP) ? &V_udbinfo : &V_ulitecbinfo;
158*1eaf0ac3Slogwang }
159*1eaf0ac3Slogwang 
160*1eaf0ac3Slogwang static __inline struct inpcbhead *
161*1eaf0ac3Slogwang udp_get_pcblist(int protocol)
162*1eaf0ac3Slogwang {
163*1eaf0ac3Slogwang 	return (protocol == IPPROTO_UDP) ? &V_udb : &V_ulitecb;
164*1eaf0ac3Slogwang }
165*1eaf0ac3Slogwang 
166*1eaf0ac3Slogwang int		udp_newudpcb(struct inpcb *);
167*1eaf0ac3Slogwang void		udp_discardcb(struct udpcb *);
168*1eaf0ac3Slogwang 
169*1eaf0ac3Slogwang void		udp_ctlinput(int, struct sockaddr *, void *);
170*1eaf0ac3Slogwang void		udplite_ctlinput(int, struct sockaddr *, void *);
171*1eaf0ac3Slogwang int		udp_ctloutput(struct socket *, struct sockopt *);
172*1eaf0ac3Slogwang void		udp_init(void);
173*1eaf0ac3Slogwang void		udplite_init(void);
174*1eaf0ac3Slogwang int		udp_input(struct mbuf **, int *, int);
175*1eaf0ac3Slogwang void		udplite_input(struct mbuf *, int);
176*1eaf0ac3Slogwang struct inpcb	*udp_notify(struct inpcb *inp, int errno);
177*1eaf0ac3Slogwang int		udp_shutdown(struct socket *so);
178*1eaf0ac3Slogwang 
179*1eaf0ac3Slogwang int		udp_set_kernel_tunneling(struct socket *so, udp_tun_func_t f,
180*1eaf0ac3Slogwang 		    udp_tun_icmp_t i, void *ctx);
181*1eaf0ac3Slogwang 
182*1eaf0ac3Slogwang #endif /* _KERNEL */
183*1eaf0ac3Slogwang 
184*1eaf0ac3Slogwang #endif /* _NETINET_UDP_VAR_H_ */
185