udp_var.h revision 195727
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 195727 2009-07-16 21:13:04Z rwatson $ 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 54192649Sbztypedef void(*udp_tun_func_t)(struct mbuf *, int off, struct inpcb *); 55192649Sbz 56192649Sbz/* 57192649Sbz * UDP control block; one per udp. 58192649Sbz */ 59192649Sbzstruct udpcb { 60192649Sbz udp_tun_func_t u_tun_func; /* UDP kernel tunneling callback. */ 61192649Sbz u_int u_flags; /* Generic UDP flags. */ 62192649Sbz}; 63192649Sbz 64192649Sbz#define intoudpcb(ip) ((struct udpcb *)(ip)->inp_ppcb) 65192649Sbz#define sotoudpcb(so) (intoudpcb(sotoinpcb(so))) 66192649Sbz 67194062Svanhu /* IPsec: ESP in UDP tunneling: */ 68194062Svanhu#define UF_ESPINUDP_NON_IKE 0x00000001 /* w/ non-IKE marker .. */ 69194062Svanhu /* .. per draft-ietf-ipsec-nat-t-ike-0[01], 70194062Svanhu * and draft-ietf-ipsec-udp-encaps-(00/)01.txt */ 71194062Svanhu#define UF_ESPINUDP 0x00000002 /* w/ non-ESP marker. */ 72194062Svanhu 73166841Srwatsonstruct udpstat { 741541Srgrimes /* input statistics: */ 751541Srgrimes u_long udps_ipackets; /* total input packets */ 761541Srgrimes u_long udps_hdrops; /* packet shorter than header */ 771541Srgrimes u_long udps_badsum; /* checksum error */ 7852904Sshin u_long udps_nosum; /* no checksum */ 791541Srgrimes u_long udps_badlen; /* data length larger than packet */ 801541Srgrimes u_long udps_noport; /* no socket on port */ 811541Srgrimes u_long udps_noportbcast; /* of above, arrived as broadcast */ 821541Srgrimes u_long udps_fullsock; /* not delivered, input socket full */ 831541Srgrimes u_long udpps_pcbcachemiss; /* input packets missing pcb cache */ 8416143Swollman u_long udpps_pcbhashmiss; /* input packets not for hashed pcb */ 851541Srgrimes /* output statistics: */ 861541Srgrimes u_long udps_opackets; /* total output packets */ 8728270Swollman u_long udps_fastout; /* output packets on fast path */ 8852904Sshin /* of no socket on port, arrived as multicast */ 8952904Sshin u_long udps_noportmcast; 90170613Sbms u_long udps_filtermcast; /* blocked by multicast filter */ 911541Srgrimes}; 921541Srgrimes 93190962Srwatson#ifdef _KERNEL 94190962Srwatson#define UDPSTAT_ADD(name, val) V_udpstat.name += (val) 95190962Srwatson#define UDPSTAT_INC(name) UDPSTAT_ADD(name, 1) 96190962Srwatson#endif 97190962Srwatson 981541Srgrimes/* 99166841Srwatson * Names for UDP sysctl objects. 1001541Srgrimes */ 1011541Srgrimes#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ 102166841Srwatson#define UDPCTL_STATS 2 /* statistics (read-only) */ 1036472Swollman#define UDPCTL_MAXDGRAM 3 /* max datagram size */ 1046472Swollman#define UDPCTL_RECVSPACE 4 /* default receive buffer space */ 10536079Swollman#define UDPCTL_PCBLIST 5 /* list of PCBs for UDP sockets */ 106166841Srwatson#define UDPCTL_MAXID 6 1071541Srgrimes 108166841Srwatson#define UDPCTL_NAMES { \ 109166841Srwatson { 0, 0 }, \ 110166841Srwatson { "checksum", CTLTYPE_INT }, \ 111166841Srwatson { "stats", CTLTYPE_STRUCT }, \ 112166841Srwatson { "maxdgram", CTLTYPE_INT }, \ 113166841Srwatson { "recvspace", CTLTYPE_INT }, \ 114166841Srwatson { "pcblist", CTLTYPE_STRUCT }, \ 1151541Srgrimes} 1161541Srgrimes 11755205Speter#ifdef _KERNEL 11844078SdfrSYSCTL_DECL(_net_inet_udp); 11944078Sdfr 120166841Srwatsonextern struct pr_usrreqs udp_usrreqs; 121185937Sbz 122195699SrwatsonVNET_DECLARE(struct inpcbhead, udb); 123195699SrwatsonVNET_DECLARE(struct inpcbinfo, udbinfo); 124195699SrwatsonVNET_DECLARE(struct udpstat, udpstat); 125195699SrwatsonVNET_DECLARE(int, udp_blackhole); 126195699Srwatson 127195727Srwatson#define V_udb VNET(udb) 128195727Srwatson#define V_udbinfo VNET(udbinfo) 129195727Srwatson#define V_udpstat VNET(udpstat) 130195727Srwatson#define V_udp_blackhole VNET(udp_blackhole) 131195699Srwatson 132166841Srwatsonextern u_long udp_sendspace; 133166841Srwatsonextern u_long udp_recvspace; 134166842Srwatsonextern int udp_log_in_vain; 1351541Srgrimes 136192649Sbzint udp_newudpcb(struct inpcb *); 137192649Sbzvoid udp_discardcb(struct udpcb *); 138192649Sbz 139166841Srwatsonvoid udp_ctlinput(int, struct sockaddr *, void *); 140194062Svanhuint udp_ctloutput(struct socket *, struct sockopt *); 141166841Srwatsonvoid udp_init(void); 142193731Szec#ifdef VIMAGE 143193731Szecvoid udp_destroy(void); 144193731Szec#endif 145166841Srwatsonvoid udp_input(struct mbuf *, int); 146166841Srwatsonstruct inpcb *udp_notify(struct inpcb *inp, int errno); 147166841Srwatsonint udp_shutdown(struct socket *so); 148186813Srrs 149186813Srrsint udp_set_kernel_tunneling(struct socket *so, udp_tun_func_t f); 1501541Srgrimes#endif 1512169Spaul 1522169Spaul#endif 153