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 58298747Srrstypedef void(*udp_tun_func_t)(struct mbuf *, int, struct inpcb *, 59272886Sbryanv const struct sockaddr *, void *); 60298747Srrstypedef void(*udp_tun_icmp_t)(int, struct sockaddr *, void *, void *); 61298747Srrs 62192649Sbz/* 63192649Sbz * UDP control block; one per udp. 64192649Sbz */ 65192649Sbzstruct udpcb { 66192649Sbz udp_tun_func_t u_tun_func; /* UDP kernel tunneling callback. */ 67298747Srrs udp_tun_icmp_t u_icmp_func; /* UDP kernel tunneling icmp callback */ 68192649Sbz u_int u_flags; /* Generic UDP flags. */ 69264212Skevlo uint16_t u_rxcslen; /* Coverage for incoming datagrams. */ 70264212Skevlo uint16_t u_txcslen; /* Coverage for outgoing datagrams. */ 71272886Sbryanv void *u_tun_ctx; /* Tunneling callback context. */ 72192649Sbz}; 73192649Sbz 74192649Sbz#define intoudpcb(ip) ((struct udpcb *)(ip)->inp_ppcb) 75192649Sbz#define sotoudpcb(so) (intoudpcb(sotoinpcb(so))) 76192649Sbz 77194062Svanhu /* IPsec: ESP in UDP tunneling: */ 78194062Svanhu#define UF_ESPINUDP_NON_IKE 0x00000001 /* w/ non-IKE marker .. */ 79194062Svanhu /* .. per draft-ietf-ipsec-nat-t-ike-0[01], 80194062Svanhu * and draft-ietf-ipsec-udp-encaps-(00/)01.txt */ 81194062Svanhu#define UF_ESPINUDP 0x00000002 /* w/ non-ESP marker. */ 82194062Svanhu 83166841Srwatsonstruct udpstat { 841541Srgrimes /* input statistics: */ 85253081Sae uint64_t udps_ipackets; /* total input packets */ 86253081Sae uint64_t udps_hdrops; /* packet shorter than header */ 87253081Sae uint64_t udps_badsum; /* checksum error */ 88253081Sae uint64_t udps_nosum; /* no checksum */ 89253081Sae uint64_t udps_badlen; /* data length larger than packet */ 90253081Sae uint64_t udps_noport; /* no socket on port */ 91253081Sae uint64_t udps_noportbcast; /* of above, arrived as broadcast */ 92253081Sae uint64_t udps_fullsock; /* not delivered, input socket full */ 93253081Sae uint64_t udpps_pcbcachemiss; /* input packets missing pcb cache */ 94253081Sae uint64_t udpps_pcbhashmiss; /* input packets not for hashed pcb */ 951541Srgrimes /* output statistics: */ 96253081Sae uint64_t udps_opackets; /* total output packets */ 97253081Sae uint64_t udps_fastout; /* output packets on fast path */ 9852904Sshin /* of no socket on port, arrived as multicast */ 99253081Sae uint64_t udps_noportmcast; 100253081Sae uint64_t udps_filtermcast; /* blocked by multicast filter */ 1011541Srgrimes}; 1021541Srgrimes 103190962Srwatson#ifdef _KERNEL 104253084Sae#include <sys/counter.h> 105253084Sae 106253084SaeVNET_PCPUSTAT_DECLARE(struct udpstat, udpstat); 107196039Srwatson/* 108196039Srwatson * In-kernel consumers can use these accessor macros directly to update 109196039Srwatson * stats. 110196039Srwatson */ 111253084Sae#define UDPSTAT_ADD(name, val) \ 112253084Sae VNET_PCPUSTAT_ADD(struct udpstat, udpstat, name, (val)) 113190962Srwatson#define UDPSTAT_INC(name) UDPSTAT_ADD(name, 1) 114196039Srwatson 115196039Srwatson/* 116196039Srwatson * Kernel module consumers must use this accessor macro. 117196039Srwatson */ 118196039Srwatsonvoid kmod_udpstat_inc(int statnum); 119253084Sae#define KMOD_UDPSTAT_INC(name) \ 120253084Sae kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(uint64_t)) 121190962Srwatson#endif 122190962Srwatson 1231541Srgrimes/* 124262489Sjhb * Identifiers for UDP sysctl nodes. 1251541Srgrimes */ 1261541Srgrimes#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ 127166841Srwatson#define UDPCTL_STATS 2 /* statistics (read-only) */ 1286472Swollman#define UDPCTL_MAXDGRAM 3 /* max datagram size */ 1296472Swollman#define UDPCTL_RECVSPACE 4 /* default receive buffer space */ 13036079Swollman#define UDPCTL_PCBLIST 5 /* list of PCBs for UDP sockets */ 1311541Srgrimes 13255205Speter#ifdef _KERNEL 133266990Skevlo#include <netinet/in_pcb.h> 13444078SdfrSYSCTL_DECL(_net_inet_udp); 13544078Sdfr 136166841Srwatsonextern struct pr_usrreqs udp_usrreqs; 137195699SrwatsonVNET_DECLARE(struct inpcbhead, udb); 138195699SrwatsonVNET_DECLARE(struct inpcbinfo, udbinfo); 139264212SkevloVNET_DECLARE(struct inpcbhead, ulitecb); 140264212SkevloVNET_DECLARE(struct inpcbinfo, ulitecbinfo); 141195727Srwatson#define V_udb VNET(udb) 142195727Srwatson#define V_udbinfo VNET(udbinfo) 143264212Skevlo#define V_ulitecb VNET(ulitecb) 144264212Skevlo#define V_ulitecbinfo VNET(ulitecbinfo) 145195699Srwatson 146166841Srwatsonextern u_long udp_sendspace; 147166841Srwatsonextern u_long udp_recvspace; 148233554SbzVNET_DECLARE(int, udp_cksum); 149207369SbzVNET_DECLARE(int, udp_blackhole); 150233554Sbz#define V_udp_cksum VNET(udp_cksum) 151207369Sbz#define V_udp_blackhole VNET(udp_blackhole) 152166842Srwatsonextern int udp_log_in_vain; 1531541Srgrimes 154264212Skevlostatic __inline struct inpcbinfo * 155287211Sbzudp_get_inpcbinfo(int protocol) 156264212Skevlo{ 157264212Skevlo return (protocol == IPPROTO_UDP) ? &V_udbinfo : &V_ulitecbinfo; 158264212Skevlo} 159264212Skevlo 160264212Skevlostatic __inline struct inpcbhead * 161287211Sbzudp_get_pcblist(int protocol) 162264212Skevlo{ 163264212Skevlo return (protocol == IPPROTO_UDP) ? &V_udb : &V_ulitecb; 164264212Skevlo} 165264212Skevlo 166264213Skevloint udp_newudpcb(struct inpcb *); 167264213Skevlovoid udp_discardcb(struct udpcb *); 168192649Sbz 169264213Skevlovoid udp_ctlinput(int, struct sockaddr *, void *); 170264213Skevlovoid udplite_ctlinput(int, struct sockaddr *, void *); 171264213Skevloint udp_ctloutput(struct socket *, struct sockopt *); 172264213Skevlovoid udp_init(void); 173264213Skevlovoid udplite_init(void); 174269699Skevloint udp_input(struct mbuf **, int *, int); 175264213Skevlovoid udplite_input(struct mbuf *, int); 176166841Srwatsonstruct inpcb *udp_notify(struct inpcb *inp, int errno); 177264213Skevloint udp_shutdown(struct socket *so); 178186813Srrs 179272886Sbryanvint udp_set_kernel_tunneling(struct socket *so, udp_tun_func_t f, 180298747Srrs udp_tun_icmp_t i, void *ctx); 1812169Spaul 182264212Skevlo#endif /* _KERNEL */ 183264212Skevlo 184264212Skevlo#endif /* _NETINET_UDP_VAR_H_ */ 185