1*4a5d661aSToomas Soome /*- 2*4a5d661aSToomas Soome * Copyright (c) 1982, 1986, 1989, 1993 3*4a5d661aSToomas Soome * The Regents of the University of California. 4*4a5d661aSToomas Soome * All rights reserved. 5*4a5d661aSToomas Soome * 6*4a5d661aSToomas Soome * Redistribution and use in source and binary forms, with or without 7*4a5d661aSToomas Soome * modification, are permitted provided that the following conditions 8*4a5d661aSToomas Soome * are met: 9*4a5d661aSToomas Soome * 1. Redistributions of source code must retain the above copyright 10*4a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer. 11*4a5d661aSToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 12*4a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer in the 13*4a5d661aSToomas Soome * documentation and/or other materials provided with the distribution. 14*4a5d661aSToomas Soome * 4. Neither the name of the University nor the names of its contributors 15*4a5d661aSToomas Soome * may be used to endorse or promote products derived from this software 16*4a5d661aSToomas Soome * without specific prior written permission. 17*4a5d661aSToomas Soome * 18*4a5d661aSToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19*4a5d661aSToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*4a5d661aSToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*4a5d661aSToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22*4a5d661aSToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*4a5d661aSToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*4a5d661aSToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*4a5d661aSToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*4a5d661aSToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*4a5d661aSToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*4a5d661aSToomas Soome * SUCH DAMAGE. 29*4a5d661aSToomas Soome * 30*4a5d661aSToomas Soome * @(#)udp_var.h 8.1 (Berkeley) 6/10/93 31*4a5d661aSToomas Soome * $FreeBSD$ 32*4a5d661aSToomas Soome */ 33*4a5d661aSToomas Soome 34*4a5d661aSToomas Soome #ifndef _NETINET_UDP_VAR_H_ 35*4a5d661aSToomas Soome #define _NETINET_UDP_VAR_H_ 36*4a5d661aSToomas Soome 37*4a5d661aSToomas Soome /* 38*4a5d661aSToomas Soome * UDP kernel structures and variables. 39*4a5d661aSToomas Soome */ 40*4a5d661aSToomas Soome struct udpiphdr { 41*4a5d661aSToomas Soome struct ipovly ui_i; /* overlaid ip structure */ 42*4a5d661aSToomas Soome struct udphdr ui_u; /* udp header */ 43*4a5d661aSToomas Soome }; 44*4a5d661aSToomas Soome #define ui_x1 ui_i.ih_x1 45*4a5d661aSToomas Soome #define ui_v ui_i.ih_x1[0] 46*4a5d661aSToomas Soome #define ui_pr ui_i.ih_pr 47*4a5d661aSToomas Soome #define ui_len ui_i.ih_len 48*4a5d661aSToomas Soome #define ui_src ui_i.ih_src 49*4a5d661aSToomas Soome #define ui_dst ui_i.ih_dst 50*4a5d661aSToomas Soome #define ui_sport ui_u.uh_sport 51*4a5d661aSToomas Soome #define ui_dport ui_u.uh_dport 52*4a5d661aSToomas Soome #define ui_ulen ui_u.uh_ulen 53*4a5d661aSToomas Soome #define ui_sum ui_u.uh_sum 54*4a5d661aSToomas Soome 55*4a5d661aSToomas Soome struct inpcb; 56*4a5d661aSToomas Soome struct mbuf; 57*4a5d661aSToomas Soome 58*4a5d661aSToomas Soome typedef void(*udp_tun_func_t)(struct mbuf *, int off, struct inpcb *, 59*4a5d661aSToomas Soome const struct sockaddr *, void *); 60*4a5d661aSToomas Soome 61*4a5d661aSToomas Soome /* 62*4a5d661aSToomas Soome * UDP control block; one per udp. 63*4a5d661aSToomas Soome */ 64*4a5d661aSToomas Soome struct udpcb { 65*4a5d661aSToomas Soome udp_tun_func_t u_tun_func; /* UDP kernel tunneling callback. */ 66*4a5d661aSToomas Soome u_int u_flags; /* Generic UDP flags. */ 67*4a5d661aSToomas Soome uint16_t u_rxcslen; /* Coverage for incoming datagrams. */ 68*4a5d661aSToomas Soome uint16_t u_txcslen; /* Coverage for outgoing datagrams. */ 69*4a5d661aSToomas Soome void *u_tun_ctx; /* Tunneling callback context. */ 70*4a5d661aSToomas Soome }; 71*4a5d661aSToomas Soome 72*4a5d661aSToomas Soome #define intoudpcb(ip) ((struct udpcb *)(ip)->inp_ppcb) 73*4a5d661aSToomas Soome #define sotoudpcb(so) (intoudpcb(sotoinpcb(so))) 74*4a5d661aSToomas Soome 75*4a5d661aSToomas Soome /* IPsec: ESP in UDP tunneling: */ 76*4a5d661aSToomas Soome #define UF_ESPINUDP_NON_IKE 0x00000001 /* w/ non-IKE marker .. */ 77*4a5d661aSToomas Soome /* .. per draft-ietf-ipsec-nat-t-ike-0[01], 78*4a5d661aSToomas Soome * and draft-ietf-ipsec-udp-encaps-(00/)01.txt */ 79*4a5d661aSToomas Soome #define UF_ESPINUDP 0x00000002 /* w/ non-ESP marker. */ 80*4a5d661aSToomas Soome 81*4a5d661aSToomas Soome struct udpstat { 82*4a5d661aSToomas Soome /* input statistics: */ 83*4a5d661aSToomas Soome uint64_t udps_ipackets; /* total input packets */ 84*4a5d661aSToomas Soome uint64_t udps_hdrops; /* packet shorter than header */ 85*4a5d661aSToomas Soome uint64_t udps_badsum; /* checksum error */ 86*4a5d661aSToomas Soome uint64_t udps_nosum; /* no checksum */ 87*4a5d661aSToomas Soome uint64_t udps_badlen; /* data length larger than packet */ 88*4a5d661aSToomas Soome uint64_t udps_noport; /* no socket on port */ 89*4a5d661aSToomas Soome uint64_t udps_noportbcast; /* of above, arrived as broadcast */ 90*4a5d661aSToomas Soome uint64_t udps_fullsock; /* not delivered, input socket full */ 91*4a5d661aSToomas Soome uint64_t udpps_pcbcachemiss; /* input packets missing pcb cache */ 92*4a5d661aSToomas Soome uint64_t udpps_pcbhashmiss; /* input packets not for hashed pcb */ 93*4a5d661aSToomas Soome /* output statistics: */ 94*4a5d661aSToomas Soome uint64_t udps_opackets; /* total output packets */ 95*4a5d661aSToomas Soome uint64_t udps_fastout; /* output packets on fast path */ 96*4a5d661aSToomas Soome /* of no socket on port, arrived as multicast */ 97*4a5d661aSToomas Soome uint64_t udps_noportmcast; 98*4a5d661aSToomas Soome uint64_t udps_filtermcast; /* blocked by multicast filter */ 99*4a5d661aSToomas Soome }; 100*4a5d661aSToomas Soome 101*4a5d661aSToomas Soome #ifdef _KERNEL 102*4a5d661aSToomas Soome #include <sys/counter.h> 103*4a5d661aSToomas Soome 104*4a5d661aSToomas Soome VNET_PCPUSTAT_DECLARE(struct udpstat, udpstat); 105*4a5d661aSToomas Soome /* 106*4a5d661aSToomas Soome * In-kernel consumers can use these accessor macros directly to update 107*4a5d661aSToomas Soome * stats. 108*4a5d661aSToomas Soome */ 109*4a5d661aSToomas Soome #define UDPSTAT_ADD(name, val) \ 110*4a5d661aSToomas Soome VNET_PCPUSTAT_ADD(struct udpstat, udpstat, name, (val)) 111*4a5d661aSToomas Soome #define UDPSTAT_INC(name) UDPSTAT_ADD(name, 1) 112*4a5d661aSToomas Soome 113*4a5d661aSToomas Soome /* 114*4a5d661aSToomas Soome * Kernel module consumers must use this accessor macro. 115*4a5d661aSToomas Soome */ 116*4a5d661aSToomas Soome void kmod_udpstat_inc(int statnum); 117*4a5d661aSToomas Soome #define KMOD_UDPSTAT_INC(name) \ 118*4a5d661aSToomas Soome kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(uint64_t)) 119*4a5d661aSToomas Soome #endif 120*4a5d661aSToomas Soome 121*4a5d661aSToomas Soome /* 122*4a5d661aSToomas Soome * Identifiers for UDP sysctl nodes. 123*4a5d661aSToomas Soome */ 124*4a5d661aSToomas Soome #define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ 125*4a5d661aSToomas Soome #define UDPCTL_STATS 2 /* statistics (read-only) */ 126*4a5d661aSToomas Soome #define UDPCTL_MAXDGRAM 3 /* max datagram size */ 127*4a5d661aSToomas Soome #define UDPCTL_RECVSPACE 4 /* default receive buffer space */ 128*4a5d661aSToomas Soome #define UDPCTL_PCBLIST 5 /* list of PCBs for UDP sockets */ 129*4a5d661aSToomas Soome 130*4a5d661aSToomas Soome #ifdef _KERNEL 131*4a5d661aSToomas Soome #include <netinet/in_pcb.h> 132*4a5d661aSToomas Soome SYSCTL_DECL(_net_inet_udp); 133*4a5d661aSToomas Soome 134*4a5d661aSToomas Soome extern struct pr_usrreqs udp_usrreqs; 135*4a5d661aSToomas Soome VNET_DECLARE(struct inpcbhead, udb); 136*4a5d661aSToomas Soome VNET_DECLARE(struct inpcbinfo, udbinfo); 137*4a5d661aSToomas Soome VNET_DECLARE(struct inpcbhead, ulitecb); 138*4a5d661aSToomas Soome VNET_DECLARE(struct inpcbinfo, ulitecbinfo); 139*4a5d661aSToomas Soome #define V_udb VNET(udb) 140*4a5d661aSToomas Soome #define V_udbinfo VNET(udbinfo) 141*4a5d661aSToomas Soome #define V_ulitecb VNET(ulitecb) 142*4a5d661aSToomas Soome #define V_ulitecbinfo VNET(ulitecbinfo) 143*4a5d661aSToomas Soome 144*4a5d661aSToomas Soome extern u_long udp_sendspace; 145*4a5d661aSToomas Soome extern u_long udp_recvspace; 146*4a5d661aSToomas Soome VNET_DECLARE(int, udp_cksum); 147*4a5d661aSToomas Soome VNET_DECLARE(int, udp_blackhole); 148*4a5d661aSToomas Soome #define V_udp_cksum VNET(udp_cksum) 149*4a5d661aSToomas Soome #define V_udp_blackhole VNET(udp_blackhole) 150*4a5d661aSToomas Soome extern int udp_log_in_vain; 151*4a5d661aSToomas Soome 152*4a5d661aSToomas Soome static __inline struct inpcbinfo * 153*4a5d661aSToomas Soome udp_get_inpcbinfo(int protocol) 154*4a5d661aSToomas Soome { 155*4a5d661aSToomas Soome return (protocol == IPPROTO_UDP) ? &V_udbinfo : &V_ulitecbinfo; 156*4a5d661aSToomas Soome } 157*4a5d661aSToomas Soome 158*4a5d661aSToomas Soome static __inline struct inpcbhead * 159*4a5d661aSToomas Soome udp_get_pcblist(int protocol) 160*4a5d661aSToomas Soome { 161*4a5d661aSToomas Soome return (protocol == IPPROTO_UDP) ? &V_udb : &V_ulitecb; 162*4a5d661aSToomas Soome } 163*4a5d661aSToomas Soome 164*4a5d661aSToomas Soome int udp_newudpcb(struct inpcb *); 165*4a5d661aSToomas Soome void udp_discardcb(struct udpcb *); 166*4a5d661aSToomas Soome 167*4a5d661aSToomas Soome void udp_ctlinput(int, struct sockaddr *, void *); 168*4a5d661aSToomas Soome void udplite_ctlinput(int, struct sockaddr *, void *); 169*4a5d661aSToomas Soome int udp_ctloutput(struct socket *, struct sockopt *); 170*4a5d661aSToomas Soome void udp_init(void); 171*4a5d661aSToomas Soome void udplite_init(void); 172*4a5d661aSToomas Soome #ifdef VIMAGE 173*4a5d661aSToomas Soome void udp_destroy(void); 174*4a5d661aSToomas Soome void udplite_destroy(void); 175*4a5d661aSToomas Soome #endif 176*4a5d661aSToomas Soome int udp_input(struct mbuf **, int *, int); 177*4a5d661aSToomas Soome void udplite_input(struct mbuf *, int); 178*4a5d661aSToomas Soome struct inpcb *udp_notify(struct inpcb *inp, int errno); 179*4a5d661aSToomas Soome int udp_shutdown(struct socket *so); 180*4a5d661aSToomas Soome 181*4a5d661aSToomas Soome int udp_set_kernel_tunneling(struct socket *so, udp_tun_func_t f, 182*4a5d661aSToomas Soome void *ctx); 183*4a5d661aSToomas Soome 184*4a5d661aSToomas Soome #endif /* _KERNEL */ 185*4a5d661aSToomas Soome 186*4a5d661aSToomas Soome #endif /* _NETINET_UDP_VAR_H_ */ 187