xref: /openbsd/sys/netinet/udp_var.h (revision 09467b48)
1 /*	$OpenBSD: udp_var.h,v 1.34 2017/11/02 14:01:18 florian Exp $	*/
2 /*	$NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1982, 1986, 1989, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)udp_var.h	8.1 (Berkeley) 6/10/93
33  */
34 
35 #ifndef _NETINET_UDP_VAR_H_
36 #define _NETINET_UDP_VAR_H_
37 
38 /*
39  * UDP kernel structures and variables.
40  */
41 struct	udpiphdr {
42 	struct	ipovly ui_i;		/* overlaid ip structure */
43 	struct	udphdr ui_u;		/* udp header */
44 };
45 #define	ui_x1		ui_i.ih_x1
46 #define	ui_pr		ui_i.ih_pr
47 #define	ui_len		ui_i.ih_len
48 #define	ui_src		ui_i.ih_src
49 #define	ui_dst		ui_i.ih_dst
50 #define	ui_sport	ui_u.uh_sport
51 #define	ui_dport	ui_u.uh_dport
52 #define	ui_ulen		ui_u.uh_ulen
53 #define	ui_sum		ui_u.uh_sum
54 
55 struct	udpstat {
56 				/* input statistics: */
57 	u_long	udps_ipackets;		/* total input packets */
58 	u_long	udps_hdrops;		/* packet shorter than header */
59 	u_long	udps_badsum;		/* checksum error */
60 	u_long	udps_nosum;		/* no checksum */
61 	u_long	udps_badlen;		/* data length larger than packet */
62 	u_long	udps_noport;		/* no socket on port */
63 	u_long	udps_noportbcast;	/* of above, arrived as broadcast */
64 	u_long	udps_nosec;		/* dropped for lack of ipsec */
65 	u_long	udps_fullsock;		/* not delivered, input socket full */
66 	u_long	udps_pcbhashmiss;	/* input packets missing pcb hash */
67 	u_long	udps_inswcsum;		/* input software-csummed packets */
68 				/* output statistics: */
69 	u_long	udps_opackets;		/* total output packets */
70 	u_long	udps_outswcsum;		/* output software-csummed packets */
71 };
72 
73 /*
74  * Names for UDP sysctl objects
75  */
76 #define	UDPCTL_CHECKSUM		1 /* checksum UDP packets */
77 #define	UDPCTL_BADDYNAMIC	2 /* return bad dynamic port bitmap */
78 #define UDPCTL_RECVSPACE	3 /* receive buffer space */
79 #define UDPCTL_SENDSPACE	4 /* send buffer space */
80 #define UDPCTL_STATS		5 /* UDP statistics */
81 #define UDPCTL_ROOTONLY		6 /* root only port bitmap */
82 #define UDPCTL_MAXID		7
83 
84 #define UDPCTL_NAMES { \
85 	{ 0, 0 }, \
86 	{ "checksum", CTLTYPE_INT }, \
87 	{ "baddynamic", CTLTYPE_STRUCT }, \
88 	{ "recvspace",  CTLTYPE_INT }, \
89 	{ "sendspace",  CTLTYPE_INT }, \
90 	{ "stats",	CTLTYPE_STRUCT }, \
91 	{ "rootonly", CTLTYPE_STRUCT }, \
92 }
93 
94 #define UDPCTL_VARS { \
95 	NULL, \
96 	&udpcksum, \
97 	NULL, \
98 	&udp_recvspace, \
99 	&udp_sendspace, \
100 	NULL, \
101 	NULL \
102 }
103 
104 #ifdef _KERNEL
105 
106 #include <sys/percpu.h>
107 
108 enum udpstat_counters {
109 			/* input statistics: */
110 	udps_ipackets,		/* total input packets */
111 	udps_hdrops,		/* packet shorter than header */
112 	udps_badsum,		/* checksum error */
113 	udps_nosum,		/* no checksum */
114 	udps_badlen,		/* data length larger than packet */
115 	udps_noport,		/* no socket on port */
116 	udps_noportbcast,	/* of above, arrived as broadcast */
117 	udps_nosec,		/* dropped for lack of ipsec */
118 	udps_fullsock,		/* not delivered, input socket full */
119 	udps_pcbhashmiss,	/* input packets missing pcb hash */
120 	udps_inswcsum,		/* input software-csummed packets */
121 			/* output statistics: */
122 	udps_opackets,		/* total output packets */
123 	udps_outswcsum,		/* output software-csummed packets */
124 
125 	udps_ncounters
126 };
127 
128 extern struct cpumem *udpcounters;
129 
130 static inline void
131 udpstat_inc(enum udpstat_counters c)
132 {
133 	counters_inc(udpcounters, c);
134 }
135 
136 extern struct	inpcbtable udbtable;
137 extern struct	udpstat udpstat;
138 
139 #ifdef INET6
140 void	udp6_ctlinput(int, struct sockaddr *, u_int, void *);
141 #endif /* INET6 */
142 void	 udp_ctlinput(int, struct sockaddr *, u_int, void *);
143 void	 udp_init(void);
144 int	 udp_input(struct mbuf **, int *, int, int);
145 #ifdef INET6
146 int	 udp6_output(struct inpcb *, struct mbuf *, struct mbuf *,
147 	struct mbuf *);
148 #endif /* INET6 */
149 int	 udp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
150 int	 udp_usrreq(struct socket *,
151 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
152 int	 udp_attach(struct socket *, int);
153 int	 udp_detach(struct socket *);
154 #endif /* _KERNEL */
155 #endif /* _NETINET_UDP_VAR_H_ */
156