xref: /dragonfly/sys/netinet/udp_var.h (revision c55be4c1b3406d689d541bcd4a9790c9069c5735)
1 /*
2  * Copyright (c) 2003, 2004 Jeffrey M. Hsu.  All rights reserved.
3  * Copyright (c) 2003, 2004 The DragonFly Project.  All rights reserved.
4  *
5  * This code is derived from software contributed to The DragonFly Project
6  * by Jeffrey M. Hsu.
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 DragonFly Project nor the names of its
17  *    contributors may be used to endorse or promote products derived
18  *    from this software without specific, prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1982, 1986, 1989, 1993
36  *        The Regents of the University of California.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  *
62  *        @(#)udp_var.h       8.1 (Berkeley) 6/10/93
63  * $FreeBSD: src/sys/netinet/udp_var.h,v 1.22.2.1 2001/02/18 07:12:25 luigi Exp $
64  * $DragonFly: src/sys/netinet/udp_var.h,v 1.19 2008/11/11 10:46:58 sephe Exp $
65  */
66 
67 #ifndef _NETINET_UDP_VAR_H_
68 #define _NETINET_UDP_VAR_H_
69 
70 #ifndef _NETINET_IP_VAR_H_
71 #include <netinet/ip_var.h>
72 #endif
73 #ifndef _NETINET_UDP_H_
74 #include <netinet/udp.h>
75 #endif
76 
77 /*
78  * UDP kernel structures and variables.
79  */
80 struct    udpiphdr {
81           struct    ipovly ui_i;                  /* overlaid ip structure */
82           struct    udphdr ui_u;                  /* udp header */
83 };
84 #define   ui_x1               ui_i.ih_x1
85 #define   ui_pr               ui_i.ih_pr
86 #define   ui_len              ui_i.ih_len
87 #define   ui_src              ui_i.ih_src
88 #define   ui_dst              ui_i.ih_dst
89 #define   ui_sport  ui_u.uh_sport
90 #define   ui_dport  ui_u.uh_dport
91 #define   ui_ulen             ui_u.uh_ulen
92 #define   ui_sum              ui_u.uh_sum
93 
94 /*
95  * UDP Statistics.
96  *
97  * NOTE: Make sure this struct's size is multiple cache line size.
98  */
99 struct    udpstat {
100                                         /* input statistics: */
101           u_long    udps_ipackets;                /* total input packets */
102           u_long    udps_hdrops;                  /* packet shorter than header */
103           u_long    udps_badsum;                  /* checksum error */
104           u_long    udps_nosum;                   /* no checksum */
105           u_long    udps_badlen;                  /* data length larger than packet */
106           u_long    udps_noport;                  /* no socket on port */
107           u_long    udps_noportbcast;   /* of above, arrived as broadcast */
108           u_long    udps_fullsock;                /* not delivered, input socket full */
109           u_long    udpps_pcbcachemiss; /* input packets missing pcb cache */
110           u_long    udpps_pcbhashmiss;  /* input packets not for hashed pcb */
111                                         /* output statistics: */
112           u_long    udps_opackets;                /* total output packets */
113           u_long    udps_fastout;                 /* output packets on fast path */
114           /* of no socket on port, arrived as multicast */
115           u_long    udps_noportmcast;
116           u_long    udps_pad[3];                  /* pad to cache line size (64B) */
117 };
118 #ifdef _KERNEL
119 CTASSERT((sizeof(struct udpstat) & __VM_CACHELINE_MASK) == 0);
120 #endif
121 
122 /*
123  * Names for UDP sysctl objects
124  */
125 #define   UDPCTL_CHECKSUM               1         /* checksum UDP packets */
126 #define UDPCTL_STATS                    2         /* statistics (read-only) */
127 #define   UDPCTL_MAXDGRAM               3         /* max datagram size */
128 #define   UDPCTL_RECVSPACE    4         /* default receive buffer space */
129 #define   UDPCTL_PCBLIST                5         /* list of PCBs for UDP sockets */
130 #define UDPCTL_MAXID                    6
131 
132 #define UDPCTL_NAMES { \
133           { 0, 0 }, \
134           { "checksum", CTLTYPE_INT }, \
135           { "stats", CTLTYPE_STRUCT }, \
136           { "maxdgram", CTLTYPE_INT }, \
137           { "recvspace", CTLTYPE_INT }, \
138           { "pcblist", CTLTYPE_STRUCT }, \
139 }
140 
141 #ifdef _KERNEL
142 
143 #define INP_WASBOUND_NOTANY   INP_FLAG_PROTO1     /* bound to non-null laddr */
144 
145 #ifdef SYSCTL_DECL
146 SYSCTL_DECL(_net_inet_udp);
147 #endif
148 
149 #define udp_stat    udpstat_percpu[mycpuid]
150 
151 extern struct       pr_usrreqs udp_usrreqs;
152 extern struct       inpcbinfo udbinfo[MAXCPU];
153 extern u_long       udp_sendspace;
154 extern u_long       udp_recvspace;
155 extern struct       udpstat udpstat_percpu[MAXCPU];
156 extern int          log_in_vain;
157 
158 int                           udp_addrcpu (in_addr_t faddr, in_port_t fport,
159                                              in_addr_t laddr, in_port_t lport);
160 int                           udp_addrhash (in_addr_t faddr, in_port_t fport,
161                                               in_addr_t laddr, in_port_t lport);
162 struct lwkt_port    *udp_addrport (in_addr_t faddr, in_port_t fport,
163                                              in_addr_t laddr, in_port_t lport);
164 void                          udp_ctlinput(netmsg_t msg);
165 void                          udp_ctloutput(netmsg_t msg);
166 void                          udp_init (void);
167 void                          udp_thread_init (void);
168 int                           udp_input (struct mbuf **, int *, int);
169 void                          udp_notify (struct inpcb *inp, int error);
170 void                          udp_shutdown (union netmsg *);
171 struct lwkt_port    *udp_ctlport (int, struct sockaddr *, void *, int *);
172 struct lwkt_port    *udp_initport(void);
173 inp_notify_t                  udp_get_inpnotify(int, const struct sockaddr *,
174                                   struct ip **, int *);
175 
176 #endif    /* _KERNEL */
177 
178 #endif
179