ip_var.h revision 182146
1131826Sharti/*- 2131826Sharti * Copyright (c) 1982, 1986, 1993 3131826Sharti * The Regents of the University of California. All rights reserved. 4131826Sharti * 5131826Sharti * Redistribution and use in source and binary forms, with or without 6131826Sharti * modification, are permitted provided that the following conditions 7131826Sharti * are met: 8131826Sharti * 1. Redistributions of source code must retain the above copyright 9131826Sharti * notice, this list of conditions and the following disclaimer. 10131826Sharti * 2. Redistributions in binary form must reproduce the above copyright 11131826Sharti * notice, this list of conditions and the following disclaimer in the 12131826Sharti * documentation and/or other materials provided with the distribution. 13131826Sharti * 4. Neither the name of the University nor the names of its contributors 14131826Sharti * may be used to endorse or promote products derived from this software 15131826Sharti * without specific prior written permission. 16131826Sharti * 17131826Sharti * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18131826Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19131826Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20131826Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21131826Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22131826Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23131826Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24131826Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25131826Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26131826Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27131826Sharti * SUCH DAMAGE. 28131826Sharti * 29131826Sharti * @(#)ip_var.h 8.2 (Berkeley) 1/9/95 30131826Sharti * $FreeBSD: head/sys/netinet/ip_var.h 182146 2008-08-25 05:49:16Z julian $ 31131826Sharti */ 32131826Sharti 33131826Sharti#ifndef _NETINET_IP_VAR_H_ 34131826Sharti#define _NETINET_IP_VAR_H_ 35131826Sharti 36131826Sharti#include <sys/queue.h> 37131826Sharti#ifdef _KERNEL 38131826Sharti#include <sys/vimage.h> 39131826Sharti#endif 40131826Sharti 41131826Sharti/* 42131826Sharti * Overlay for ip header used by other protocols (tcp, udp). 43131826Sharti */ 44131826Shartistruct ipovly { 45131826Sharti u_char ih_x1[9]; /* (unused) */ 46131826Sharti u_char ih_pr; /* protocol */ 47131826Sharti u_short ih_len; /* protocol length */ 48131826Sharti struct in_addr ih_src; /* source internet address */ 49131826Sharti struct in_addr ih_dst; /* destination internet address */ 50131826Sharti}; 51131826Sharti 52131826Sharti#ifdef _KERNEL 53131826Sharti/* 54131826Sharti * Ip reassembly queue structure. Each fragment 55131826Sharti * being reassembled is attached to one of these structures. 56131826Sharti * They are timed out after ipq_ttl drops to 0, and may also 57131826Sharti * be reclaimed if memory becomes tight. 58131826Sharti */ 59131826Shartistruct ipq { 60131826Sharti TAILQ_ENTRY(ipq) ipq_list; /* to other reass headers */ 61131826Sharti u_char ipq_ttl; /* time for reass q to live */ 62131826Sharti u_char ipq_p; /* protocol of this fragment */ 63131826Sharti u_short ipq_id; /* sequence id for reassembly */ 64131826Sharti struct mbuf *ipq_frags; /* to ip headers of fragments */ 65131826Sharti struct in_addr ipq_src,ipq_dst; 66131826Sharti u_char ipq_nfrags; /* # frags in this packet */ 67131826Sharti struct label *ipq_label; /* MAC label */ 68131826Sharti}; 69131826Sharti#endif /* _KERNEL */ 70131826Sharti 71131826Sharti/* 72131826Sharti * Structure stored in mbuf in inpcb.ip_options 73131826Sharti * and passed to ip_output when ip options are in use. 74131826Sharti * The actual length of the options (including ipopt_dst) 75131826Sharti * is in m_len. 76131826Sharti */ 77131826Sharti#define MAX_IPOPTLEN 40 78131826Sharti 79131826Shartistruct ipoption { 80131826Sharti struct in_addr ipopt_dst; /* first-hop dst if source routed */ 81131826Sharti char ipopt_list[MAX_IPOPTLEN]; /* options proper */ 82131826Sharti}; 83131826Sharti 84131826Sharti/* 85131826Sharti * Multicast source list entry. 86131826Sharti */ 87131826Shartistruct in_msource { 88131826Sharti TAILQ_ENTRY(in_msource) ims_next; /* next source */ 89131826Sharti struct sockaddr_storage ims_addr; /* address of this source */ 90131826Sharti}; 91131826Sharti 92131826Sharti/* 93131826Sharti * Multicast filter descriptor; there is one instance per group membership 94131826Sharti * on a socket, allocated as an expandable vector hung off ip_moptions. 95131826Sharti * struct in_multi contains separate IPv4-stack-wide state for IGMPv3. 96131826Sharti */ 97131826Shartistruct in_mfilter { 98131826Sharti uint16_t imf_fmode; /* filter mode for this socket/group */ 99131826Sharti uint16_t imf_nsources; /* # of sources for this socket/group */ 100131826Sharti TAILQ_HEAD(, in_msource) imf_sources; /* source list */ 101131826Sharti}; 102131826Sharti 103131826Sharti/* 104131826Sharti * Structure attached to inpcb.ip_moptions and 105131826Sharti * passed to ip_output when IP multicast options are in use. 106131826Sharti * This structure is lazy-allocated. 107131826Sharti */ 108131826Shartistruct ip_moptions { 109131826Sharti struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */ 110131826Sharti struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */ 111131826Sharti u_long imo_multicast_vif; /* vif num outgoing multicasts */ 112131826Sharti u_char imo_multicast_ttl; /* TTL for outgoing multicasts */ 113131826Sharti u_char imo_multicast_loop; /* 1 => hear sends if a member */ 114131826Sharti u_short imo_num_memberships; /* no. memberships this socket */ 115131826Sharti u_short imo_max_memberships; /* max memberships this socket */ 116131826Sharti struct in_multi **imo_membership; /* group memberships */ 117131826Sharti struct in_mfilter *imo_mfilters; /* source filters */ 118131826Sharti}; 119131826Sharti 120131826Shartistruct ipstat { 121131826Sharti u_long ips_total; /* total packets received */ 122131826Sharti u_long ips_badsum; /* checksum bad */ 123131826Sharti u_long ips_tooshort; /* packet too short */ 124131826Sharti u_long ips_toosmall; /* not enough data */ 125131826Sharti u_long ips_badhlen; /* ip header length < data size */ 126131826Sharti u_long ips_badlen; /* ip length < ip header length */ 127131826Sharti u_long ips_fragments; /* fragments received */ 128131826Sharti u_long ips_fragdropped; /* frags dropped (dups, out of space) */ 129131826Sharti u_long ips_fragtimeout; /* fragments timed out */ 130131826Sharti u_long ips_forward; /* packets forwarded */ 131131826Sharti u_long ips_fastforward; /* packets fast forwarded */ 132131826Sharti u_long ips_cantforward; /* packets rcvd for unreachable dest */ 133131826Sharti u_long ips_redirectsent; /* packets forwarded on same net */ 134131826Sharti u_long ips_noproto; /* unknown or unsupported protocol */ 135131826Sharti u_long ips_delivered; /* datagrams delivered to upper level*/ 136131826Sharti u_long ips_localout; /* total ip packets generated here */ 137131826Sharti u_long ips_odropped; /* lost packets due to nobufs, etc. */ 138131826Sharti u_long ips_reassembled; /* total packets reassembled ok */ 139131826Sharti u_long ips_fragmented; /* datagrams successfully fragmented */ 140131826Sharti u_long ips_ofragments; /* output fragments created */ 141131826Sharti u_long ips_cantfrag; /* don't fragment flag was set, etc. */ 142131826Sharti u_long ips_badoptions; /* error in option processing */ 143131826Sharti u_long ips_noroute; /* packets discarded due to no route */ 144131826Sharti u_long ips_badvers; /* ip version != 4 */ 145131826Sharti u_long ips_rawout; /* total raw ip packets generated */ 146131826Sharti u_long ips_toolong; /* ip length > max ip packet size */ 147131826Sharti u_long ips_notmember; /* multicasts for unregistered grps */ 148131826Sharti u_long ips_nogif; /* no match gif found */ 149131826Sharti u_long ips_badaddr; /* invalid address on header */ 150131826Sharti}; 151131826Sharti 152131826Sharti#ifdef _KERNEL 153131826Sharti 154131826Sharti/* flags passed to ip_output as last parameter */ 155131826Sharti#define IP_FORWARDING 0x1 /* most of ip header exists */ 156131826Sharti#define IP_RAWOUTPUT 0x2 /* raw ip header exists */ 157131826Sharti#define IP_SENDONES 0x4 /* send all-ones broadcast */ 158131826Sharti#define IP_SENDTOIF 0x8 /* send on specific ifnet */ 159131826Sharti#define IP_ROUTETOIF SO_DONTROUTE /* 0x10 bypass routing tables */ 160131826Sharti#define IP_ALLOWBROADCAST SO_BROADCAST /* 0x20 can send broadcast packets */ 161131826Sharti 162131826Sharti/* 163131826Sharti * mbuf flag used by ip_fastfwd 164131826Sharti */ 165131826Sharti#define M_FASTFWD_OURS M_PROTO1 /* changed dst to local */ 166131826Sharti 167131826Sharti#ifdef __NO_STRICT_ALIGNMENT 168131826Sharti#define IP_HDR_ALIGNED_P(ip) 1 169131826Sharti#else 170131826Sharti#define IP_HDR_ALIGNED_P(ip) ((((intptr_t) (ip)) & 3) == 0) 171131826Sharti#endif 172131826Sharti 173131826Shartistruct ip; 174131826Shartistruct inpcb; 175131826Shartistruct route; 176131826Shartistruct sockopt; 177131826Sharti 178131826Shartiextern struct ipstat ipstat; 179131826Shartiextern u_short ip_id; /* ip packet ctr, for ids */ 180131826Shartiextern int ip_defttl; /* default IP ttl */ 181131826Shartiextern int ipforwarding; /* ip forwarding */ 182131826Sharti#ifdef IPSTEALTH 183131826Shartiextern int ipstealth; /* stealth forwarding */ 184131826Sharti#endif 185131826Shartiextern u_char ip_protox[]; 186131826Shartiextern struct socket *ip_rsvpd; /* reservation protocol daemon */ 187131826Shartiextern struct socket *ip_mrouter; /* multicast routing daemon */ 188131826Shartiextern int (*legal_vif_num)(int); 189131826Shartiextern u_long (*ip_mcast_src)(int); 190131826Shartiextern int rsvp_on; 191131826Shartiextern struct pr_usrreqs rip_usrreqs; 192131826Sharti 193131826Shartivoid inp_freemoptions(struct ip_moptions *); 194131826Shartiint inp_getmoptions(struct inpcb *, struct sockopt *); 195131826Shartiint inp_setmoptions(struct inpcb *, struct sockopt *); 196131826Sharti 197131826Shartiint ip_ctloutput(struct socket *, struct sockopt *sopt); 198131826Shartivoid ip_drain(void); 199131826Shartivoid ip_fini(void *xtp); 200131826Shartiint ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu, 201131826Sharti u_long if_hwassist_flags, int sw_csum); 202131826Shartivoid ip_forward(struct mbuf *m, int srcrt); 203131826Shartivoid ip_init(void); 204131826Shartiextern int 205131826Sharti (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *, 206131826Sharti struct ip_moptions *); 207131826Shartiint ip_output(struct mbuf *, 208131826Sharti struct mbuf *, struct route *, int, struct ip_moptions *, 209131826Sharti struct inpcb *); 210131826Shartiint ipproto_register(u_char); 211131826Shartiint ipproto_unregister(u_char); 212131826Shartistruct mbuf * 213131826Sharti ip_reass(struct mbuf *); 214131826Shartistruct in_ifaddr * 215131826Sharti ip_rtaddr(struct in_addr, u_int fibnum); 216131826Shartivoid ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *, 217131826Sharti struct mbuf *); 218131826Shartivoid ip_slowtimo(void); 219131826Shartiu_int16_t ip_randomid(void); 220131826Shartiint rip_ctloutput(struct socket *, struct sockopt *); 221131826Shartivoid rip_ctlinput(int, struct sockaddr *, void *); 222131826Shartivoid rip_init(void); 223131826Shartivoid rip_input(struct mbuf *, int); 224131826Shartiint rip_output(struct mbuf *, struct socket *, u_long); 225131826Shartivoid ipip_input(struct mbuf *, int); 226131826Shartivoid rsvp_input(struct mbuf *, int); 227131826Shartiint ip_rsvp_init(struct socket *); 228131826Shartiint ip_rsvp_done(void); 229131826Shartiextern int (*ip_rsvp_vif)(struct socket *, struct sockopt *); 230131826Shartiextern void (*ip_rsvp_force_done)(struct socket *); 231131826Shartiextern void (*rsvp_input_p)(struct mbuf *m, int off); 232131826Sharti 233131826Shartiextern struct pfil_head inet_pfil_hook; /* packet filter hooks */ 234131826Sharti 235131826Shartivoid in_delayed_cksum(struct mbuf *m); 236131826Sharti 237131826Shartistatic __inline uint16_t ip_newid(void); 238131826Shartiextern int ip_do_randomid; 239131826Sharti 240131826Shartistatic __inline uint16_t 241131826Shartiip_newid(void) 242131826Sharti{ 243131826Sharti if (V_ip_do_randomid) 244131826Sharti return ip_randomid(); 245131826Sharti 246131826Sharti return htons(V_ip_id++); 247131826Sharti} 248131826Sharti 249131826Sharti#endif /* _KERNEL */ 250131826Sharti 251131826Sharti#endif /* !_NETINET_IP_VAR_H_ */ 252131826Sharti