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$ 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 45254889Smarkj#define ui_v ui_i.ih_x1[0] 461541Srgrimes#define ui_pr ui_i.ih_pr 471541Srgrimes#define ui_len ui_i.ih_len 481541Srgrimes#define ui_src ui_i.ih_src 491541Srgrimes#define ui_dst ui_i.ih_dst 501541Srgrimes#define ui_sport ui_u.uh_sport 511541Srgrimes#define ui_dport ui_u.uh_dport 521541Srgrimes#define ui_ulen ui_u.uh_ulen 531541Srgrimes#define ui_sum ui_u.uh_sum 541541Srgrimes 55226431Sedstruct inpcb; 56226431Sedstruct mbuf; 57226431Sed 58192649Sbztypedef void(*udp_tun_func_t)(struct mbuf *, int off, struct inpcb *); 59192649Sbz 60192649Sbz/* 61192649Sbz * UDP control block; one per udp. 62192649Sbz */ 63192649Sbzstruct udpcb { 64192649Sbz udp_tun_func_t u_tun_func; /* UDP kernel tunneling callback. */ 65192649Sbz u_int u_flags; /* Generic UDP flags. */ 66192649Sbz}; 67192649Sbz 68192649Sbz#define intoudpcb(ip) ((struct udpcb *)(ip)->inp_ppcb) 69192649Sbz#define sotoudpcb(so) (intoudpcb(sotoinpcb(so))) 70192649Sbz 71194062Svanhu /* IPsec: ESP in UDP tunneling: */ 72194062Svanhu#define UF_ESPINUDP_NON_IKE 0x00000001 /* w/ non-IKE marker .. */ 73194062Svanhu /* .. per draft-ietf-ipsec-nat-t-ike-0[01], 74194062Svanhu * and draft-ietf-ipsec-udp-encaps-(00/)01.txt */ 75194062Svanhu#define UF_ESPINUDP 0x00000002 /* w/ non-ESP marker. */ 76194062Svanhu 77166841Srwatsonstruct udpstat { 781541Srgrimes /* input statistics: */ 79253081Sae uint64_t udps_ipackets; /* total input packets */ 80253081Sae uint64_t udps_hdrops; /* packet shorter than header */ 81253081Sae uint64_t udps_badsum; /* checksum error */ 82253081Sae uint64_t udps_nosum; /* no checksum */ 83253081Sae uint64_t udps_badlen; /* data length larger than packet */ 84253081Sae uint64_t udps_noport; /* no socket on port */ 85253081Sae uint64_t udps_noportbcast; /* of above, arrived as broadcast */ 86253081Sae uint64_t udps_fullsock; /* not delivered, input socket full */ 87253081Sae uint64_t udpps_pcbcachemiss; /* input packets missing pcb cache */ 88253081Sae uint64_t udpps_pcbhashmiss; /* input packets not for hashed pcb */ 891541Srgrimes /* output statistics: */ 90253081Sae uint64_t udps_opackets; /* total output packets */ 91253081Sae uint64_t udps_fastout; /* output packets on fast path */ 9252904Sshin /* of no socket on port, arrived as multicast */ 93253081Sae uint64_t udps_noportmcast; 94253081Sae uint64_t udps_filtermcast; /* blocked by multicast filter */ 951541Srgrimes}; 961541Srgrimes 97190962Srwatson#ifdef _KERNEL 98253084Sae#include <sys/counter.h> 99253084Sae 100253084SaeVNET_PCPUSTAT_DECLARE(struct udpstat, udpstat); 101196039Srwatson/* 102196039Srwatson * In-kernel consumers can use these accessor macros directly to update 103196039Srwatson * stats. 104196039Srwatson */ 105253084Sae#define UDPSTAT_ADD(name, val) \ 106253084Sae VNET_PCPUSTAT_ADD(struct udpstat, udpstat, name, (val)) 107190962Srwatson#define UDPSTAT_INC(name) UDPSTAT_ADD(name, 1) 108196039Srwatson 109196039Srwatson/* 110196039Srwatson * Kernel module consumers must use this accessor macro. 111196039Srwatson */ 112196039Srwatsonvoid kmod_udpstat_inc(int statnum); 113253084Sae#define KMOD_UDPSTAT_INC(name) \ 114253084Sae kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(uint64_t)) 115190962Srwatson#endif 116190962Srwatson 1171541Srgrimes/* 118166841Srwatson * Names for UDP sysctl objects. 1191541Srgrimes */ 1201541Srgrimes#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ 121166841Srwatson#define UDPCTL_STATS 2 /* statistics (read-only) */ 1226472Swollman#define UDPCTL_MAXDGRAM 3 /* max datagram size */ 1236472Swollman#define UDPCTL_RECVSPACE 4 /* default receive buffer space */ 12436079Swollman#define UDPCTL_PCBLIST 5 /* list of PCBs for UDP sockets */ 125166841Srwatson#define UDPCTL_MAXID 6 1261541Srgrimes 12755205Speter#ifdef _KERNEL 12844078SdfrSYSCTL_DECL(_net_inet_udp); 12944078Sdfr 130166841Srwatsonextern struct pr_usrreqs udp_usrreqs; 131195699SrwatsonVNET_DECLARE(struct inpcbhead, udb); 132195699SrwatsonVNET_DECLARE(struct inpcbinfo, udbinfo); 133195727Srwatson#define V_udb VNET(udb) 134195727Srwatson#define V_udbinfo VNET(udbinfo) 135195699Srwatson 136166841Srwatsonextern u_long udp_sendspace; 137166841Srwatsonextern u_long udp_recvspace; 138233554SbzVNET_DECLARE(int, udp_cksum); 139207369SbzVNET_DECLARE(int, udp_blackhole); 140233554Sbz#define V_udp_cksum VNET(udp_cksum) 141207369Sbz#define V_udp_blackhole VNET(udp_blackhole) 142166842Srwatsonextern int udp_log_in_vain; 1431541Srgrimes 144192649Sbzint udp_newudpcb(struct inpcb *); 145192649Sbzvoid udp_discardcb(struct udpcb *); 146192649Sbz 147166841Srwatsonvoid udp_ctlinput(int, struct sockaddr *, void *); 148217126Sjhbint udp_ctloutput(struct socket *, struct sockopt *); 149166841Srwatsonvoid udp_init(void); 150193731Szec#ifdef VIMAGE 151193731Szecvoid udp_destroy(void); 152193731Szec#endif 153166841Srwatsonvoid udp_input(struct mbuf *, int); 154166841Srwatsonstruct inpcb *udp_notify(struct inpcb *inp, int errno); 155166841Srwatsonint udp_shutdown(struct socket *so); 156186813Srrs 157186813Srrsint udp_set_kernel_tunneling(struct socket *so, udp_tun_func_t f); 1581541Srgrimes#endif 1592169Spaul 1602169Spaul#endif 161