udp_var.h revision 226431
1139823Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1993 3166841Srwatson * The Regents of the University of California. 4166841Srwatson * All rights reserved. 51541Srgrimes * 61541Srgrimes * Redistribution and use in source and binary forms, with or without 71541Srgrimes * modification, are permitted provided that the following conditions 81541Srgrimes * are met: 91541Srgrimes * 1. Redistributions of source code must retain the above copyright 101541Srgrimes * notice, this list of conditions and the following disclaimer. 111541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 121541Srgrimes * notice, this list of conditions and the following disclaimer in the 131541Srgrimes * documentation and/or other materials provided with the distribution. 141541Srgrimes * 4. Neither the name of the University nor the names of its contributors 151541Srgrimes * may be used to endorse or promote products derived from this software 161541Srgrimes * without specific prior written permission. 171541Srgrimes * 181541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 191541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 201541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 211541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 221541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 231541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 241541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 251541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 261541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281541Srgrimes * SUCH DAMAGE. 291541Srgrimes * 301541Srgrimes * @(#)udp_var.h 8.1 (Berkeley) 6/10/93 3150477Speter * $FreeBSD: head/sys/netinet/udp_var.h 226431 2011-10-16 10:58:00Z ed $ 321541Srgrimes */ 331541Srgrimes 342169Spaul#ifndef _NETINET_UDP_VAR_H_ 35166841Srwatson#define _NETINET_UDP_VAR_H_ 362169Spaul 371541Srgrimes/* 381541Srgrimes * UDP kernel structures and variables. 391541Srgrimes */ 40166841Srwatsonstruct udpiphdr { 41166841Srwatson struct ipovly ui_i; /* overlaid ip structure */ 42166841Srwatson struct udphdr ui_u; /* udp header */ 431541Srgrimes}; 441541Srgrimes#define ui_x1 ui_i.ih_x1 451541Srgrimes#define ui_pr ui_i.ih_pr 461541Srgrimes#define ui_len ui_i.ih_len 471541Srgrimes#define ui_src ui_i.ih_src 481541Srgrimes#define ui_dst ui_i.ih_dst 491541Srgrimes#define ui_sport ui_u.uh_sport 501541Srgrimes#define ui_dport ui_u.uh_dport 511541Srgrimes#define ui_ulen ui_u.uh_ulen 521541Srgrimes#define ui_sum ui_u.uh_sum 531541Srgrimes 54226431Sedstruct inpcb; 55226431Sedstruct mbuf; 56226431Sed 57192649Sbztypedef void(*udp_tun_func_t)(struct mbuf *, int off, struct inpcb *); 58192649Sbz 59192649Sbz/* 60192649Sbz * UDP control block; one per udp. 61192649Sbz */ 62192649Sbzstruct udpcb { 63192649Sbz udp_tun_func_t u_tun_func; /* UDP kernel tunneling callback. */ 64192649Sbz u_int u_flags; /* Generic UDP flags. */ 65192649Sbz}; 66192649Sbz 67192649Sbz#define intoudpcb(ip) ((struct udpcb *)(ip)->inp_ppcb) 68192649Sbz#define sotoudpcb(so) (intoudpcb(sotoinpcb(so))) 69192649Sbz 70194062Svanhu /* IPsec: ESP in UDP tunneling: */ 71194062Svanhu#define UF_ESPINUDP_NON_IKE 0x00000001 /* w/ non-IKE marker .. */ 72194062Svanhu /* .. per draft-ietf-ipsec-nat-t-ike-0[01], 73194062Svanhu * and draft-ietf-ipsec-udp-encaps-(00/)01.txt */ 74194062Svanhu#define UF_ESPINUDP 0x00000002 /* w/ non-ESP marker. */ 75194062Svanhu 76166841Srwatsonstruct udpstat { 771541Srgrimes /* input statistics: */ 781541Srgrimes u_long udps_ipackets; /* total input packets */ 791541Srgrimes u_long udps_hdrops; /* packet shorter than header */ 801541Srgrimes u_long udps_badsum; /* checksum error */ 8152904Sshin u_long udps_nosum; /* no checksum */ 821541Srgrimes u_long udps_badlen; /* data length larger than packet */ 831541Srgrimes u_long udps_noport; /* no socket on port */ 841541Srgrimes u_long udps_noportbcast; /* of above, arrived as broadcast */ 851541Srgrimes u_long udps_fullsock; /* not delivered, input socket full */ 861541Srgrimes u_long udpps_pcbcachemiss; /* input packets missing pcb cache */ 8716143Swollman u_long udpps_pcbhashmiss; /* input packets not for hashed pcb */ 881541Srgrimes /* output statistics: */ 891541Srgrimes u_long udps_opackets; /* total output packets */ 9028270Swollman u_long udps_fastout; /* output packets on fast path */ 9152904Sshin /* of no socket on port, arrived as multicast */ 9252904Sshin u_long udps_noportmcast; 93170613Sbms u_long udps_filtermcast; /* blocked by multicast filter */ 941541Srgrimes}; 951541Srgrimes 96190962Srwatson#ifdef _KERNEL 97196039Srwatson/* 98196039Srwatson * In-kernel consumers can use these accessor macros directly to update 99196039Srwatson * stats. 100196039Srwatson */ 101190962Srwatson#define UDPSTAT_ADD(name, val) V_udpstat.name += (val) 102190962Srwatson#define UDPSTAT_INC(name) UDPSTAT_ADD(name, 1) 103196039Srwatson 104196039Srwatson/* 105196039Srwatson * Kernel module consumers must use this accessor macro. 106196039Srwatson */ 107196039Srwatsonvoid kmod_udpstat_inc(int statnum); 108196039Srwatson#define KMOD_UDPSTAT_INC(name) \ 109196039Srwatson kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(u_long)) 110190962Srwatson#endif 111190962Srwatson 1121541Srgrimes/* 113166841Srwatson * Names for UDP sysctl objects. 1141541Srgrimes */ 1151541Srgrimes#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ 116166841Srwatson#define UDPCTL_STATS 2 /* statistics (read-only) */ 1176472Swollman#define UDPCTL_MAXDGRAM 3 /* max datagram size */ 1186472Swollman#define UDPCTL_RECVSPACE 4 /* default receive buffer space */ 11936079Swollman#define UDPCTL_PCBLIST 5 /* list of PCBs for UDP sockets */ 120166841Srwatson#define UDPCTL_MAXID 6 1211541Srgrimes 122166841Srwatson#define UDPCTL_NAMES { \ 123166841Srwatson { 0, 0 }, \ 124166841Srwatson { "checksum", CTLTYPE_INT }, \ 125166841Srwatson { "stats", CTLTYPE_STRUCT }, \ 126166841Srwatson { "maxdgram", CTLTYPE_INT }, \ 127166841Srwatson { "recvspace", CTLTYPE_INT }, \ 128166841Srwatson { "pcblist", CTLTYPE_STRUCT }, \ 1291541Srgrimes} 1301541Srgrimes 13155205Speter#ifdef _KERNEL 13244078SdfrSYSCTL_DECL(_net_inet_udp); 13344078Sdfr 134166841Srwatsonextern struct pr_usrreqs udp_usrreqs; 135195699SrwatsonVNET_DECLARE(struct inpcbhead, udb); 136195699SrwatsonVNET_DECLARE(struct inpcbinfo, udbinfo); 137195727Srwatson#define V_udb VNET(udb) 138195727Srwatson#define V_udbinfo VNET(udbinfo) 139195699Srwatson 140166841Srwatsonextern u_long udp_sendspace; 141166841Srwatsonextern u_long udp_recvspace; 142207369SbzVNET_DECLARE(struct udpstat, udpstat); 143207369SbzVNET_DECLARE(int, udp_blackhole); 144207369Sbz#define V_udpstat VNET(udpstat) 145207369Sbz#define V_udp_blackhole VNET(udp_blackhole) 146166842Srwatsonextern int udp_log_in_vain; 1471541Srgrimes 148192649Sbzint udp_newudpcb(struct inpcb *); 149192649Sbzvoid udp_discardcb(struct udpcb *); 150192649Sbz 151166841Srwatsonvoid udp_ctlinput(int, struct sockaddr *, void *); 152217126Sjhbint udp_ctloutput(struct socket *, struct sockopt *); 153166841Srwatsonvoid udp_init(void); 154193731Szec#ifdef VIMAGE 155193731Szecvoid udp_destroy(void); 156193731Szec#endif 157166841Srwatsonvoid udp_input(struct mbuf *, int); 158166841Srwatsonstruct inpcb *udp_notify(struct inpcb *inp, int errno); 159166841Srwatsonint udp_shutdown(struct socket *so); 160186813Srrs 161186813Srrsint udp_set_kernel_tunneling(struct socket *so, udp_tun_func_t f); 1621541Srgrimes#endif 1632169Spaul 1642169Spaul#endif 165