ip_var.h revision 193731
1139823Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2910942Swollman * @(#)ip_var.h 8.2 (Berkeley) 1/9/95 3050477Speter * $FreeBSD: head/sys/netinet/ip_var.h 193731 2009-06-08 17:15:40Z zec $ 311541Srgrimes */ 321541Srgrimes 332169Spaul#ifndef _NETINET_IP_VAR_H_ 3418940Sbde#define _NETINET_IP_VAR_H_ 352169Spaul 3678064Sume#include <sys/queue.h> 37181803Sbz#ifdef _KERNEL 38181803Sbz#include <sys/vimage.h> 39181803Sbz#endif 4078064Sume 411541Srgrimes/* 421541Srgrimes * Overlay for ip header used by other protocols (tcp, udp). 431541Srgrimes */ 441541Srgrimesstruct ipovly { 4538513Sdfr u_char ih_x1[9]; /* (unused) */ 461541Srgrimes u_char ih_pr; /* protocol */ 4719183Sfenner u_short ih_len; /* protocol length */ 481541Srgrimes struct in_addr ih_src; /* source internet address */ 491541Srgrimes struct in_addr ih_dst; /* destination internet address */ 501541Srgrimes}; 511541Srgrimes 52100419Srwatson#ifdef _KERNEL 531541Srgrimes/* 541541Srgrimes * Ip reassembly queue structure. Each fragment 551541Srgrimes * being reassembled is attached to one of these structures. 561541Srgrimes * They are timed out after ipq_ttl drops to 0, and may also 571541Srgrimes * be reclaimed if memory becomes tight. 581541Srgrimes */ 591541Srgrimesstruct ipq { 6074362Sphk TAILQ_ENTRY(ipq) ipq_list; /* to other reass headers */ 611541Srgrimes u_char ipq_ttl; /* time for reass q to live */ 621541Srgrimes u_char ipq_p; /* protocol of this fragment */ 631541Srgrimes u_short ipq_id; /* sequence id for reassembly */ 6438513Sdfr struct mbuf *ipq_frags; /* to ip headers of fragments */ 651541Srgrimes struct in_addr ipq_src,ipq_dst; 66111244Ssilby u_char ipq_nfrags; /* # frags in this packet */ 67168365Sandre struct label *ipq_label; /* MAC label */ 681541Srgrimes}; 69100419Srwatson#endif /* _KERNEL */ 701541Srgrimes 711541Srgrimes/* 72152608Sandre * Structure stored in mbuf in inpcb.ip_options 73152608Sandre * and passed to ip_output when ip options are in use. 74152608Sandre * The actual length of the options (including ipopt_dst) 75152608Sandre * is in m_len. 76152608Sandre */ 77152608Sandre#define MAX_IPOPTLEN 40 78152608Sandre 79152608Sandrestruct ipoption { 80152608Sandre struct in_addr ipopt_dst; /* first-hop dst if source routed */ 81152608Sandre char ipopt_list[MAX_IPOPTLEN]; /* options proper */ 82152608Sandre}; 83152608Sandre 84152608Sandre/* 851541Srgrimes * Structure attached to inpcb.ip_moptions and 861541Srgrimes * passed to ip_output when IP multicast options are in use. 87170613Sbms * This structure is lazy-allocated. 881541Srgrimes */ 891541Srgrimesstruct ip_moptions { 901541Srgrimes struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */ 9178064Sume struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */ 92158563Sbms u_long imo_multicast_vif; /* vif num outgoing multicasts */ 931541Srgrimes u_char imo_multicast_ttl; /* TTL for outgoing multicasts */ 941541Srgrimes u_char imo_multicast_loop; /* 1 => hear sends if a member */ 951541Srgrimes u_short imo_num_memberships; /* no. memberships this socket */ 96158563Sbms u_short imo_max_memberships; /* max memberships this socket */ 97158563Sbms struct in_multi **imo_membership; /* group memberships */ 98170613Sbms struct in_mfilter *imo_mfilters; /* source filters */ 991541Srgrimes}; 1001541Srgrimes 1011541Srgrimesstruct ipstat { 1021541Srgrimes u_long ips_total; /* total packets received */ 1031541Srgrimes u_long ips_badsum; /* checksum bad */ 1041541Srgrimes u_long ips_tooshort; /* packet too short */ 1051541Srgrimes u_long ips_toosmall; /* not enough data */ 1061541Srgrimes u_long ips_badhlen; /* ip header length < data size */ 1071541Srgrimes u_long ips_badlen; /* ip length < ip header length */ 1081541Srgrimes u_long ips_fragments; /* fragments received */ 1091541Srgrimes u_long ips_fragdropped; /* frags dropped (dups, out of space) */ 1101541Srgrimes u_long ips_fragtimeout; /* fragments timed out */ 1111541Srgrimes u_long ips_forward; /* packets forwarded */ 11236192Sdg u_long ips_fastforward; /* packets fast forwarded */ 1131541Srgrimes u_long ips_cantforward; /* packets rcvd for unreachable dest */ 1141541Srgrimes u_long ips_redirectsent; /* packets forwarded on same net */ 1151541Srgrimes u_long ips_noproto; /* unknown or unsupported protocol */ 1161541Srgrimes u_long ips_delivered; /* datagrams delivered to upper level*/ 1171541Srgrimes u_long ips_localout; /* total ip packets generated here */ 1181541Srgrimes u_long ips_odropped; /* lost packets due to nobufs, etc. */ 1191541Srgrimes u_long ips_reassembled; /* total packets reassembled ok */ 12013765Smpp u_long ips_fragmented; /* datagrams successfully fragmented */ 1211541Srgrimes u_long ips_ofragments; /* output fragments created */ 1221541Srgrimes u_long ips_cantfrag; /* don't fragment flag was set, etc. */ 1231541Srgrimes u_long ips_badoptions; /* error in option processing */ 1241541Srgrimes u_long ips_noroute; /* packets discarded due to no route */ 1251541Srgrimes u_long ips_badvers; /* ip version != 4 */ 1261541Srgrimes u_long ips_rawout; /* total raw ip packets generated */ 12719183Sfenner u_long ips_toolong; /* ip length > max ip packet size */ 12821932Swollman u_long ips_notmember; /* multicasts for unregistered grps */ 12952904Sshin u_long ips_nogif; /* no match gif found */ 13078064Sume u_long ips_badaddr; /* invalid address on header */ 1311541Srgrimes}; 1321541Srgrimes 13355205Speter#ifdef _KERNEL 13437625Sbde 135190951Srwatson#define IPSTAT_ADD(name, val) V_ipstat.name += (val) 136190951Srwatson#define IPSTAT_SUB(name, val) V_ipstat.name -= (val) 137190951Srwatson#define IPSTAT_INC(name) IPSTAT_ADD(name, 1) 138190951Srwatson#define IPSTAT_DEC(name) IPSTAT_SUB(name, 1) 139190951Srwatson 140170613Sbms/* flags passed to ip_output as last parameter */ 141170613Sbms#define IP_FORWARDING 0x1 /* most of ip header exists */ 142170613Sbms#define IP_RAWOUTPUT 0x2 /* raw ip header exists */ 143170613Sbms#define IP_SENDONES 0x4 /* send all-ones broadcast */ 144170613Sbms#define IP_SENDTOIF 0x8 /* send on specific ifnet */ 145168365Sandre#define IP_ROUTETOIF SO_DONTROUTE /* 0x10 bypass routing tables */ 146168365Sandre#define IP_ALLOWBROADCAST SO_BROADCAST /* 0x20 can send broadcast packets */ 1471541Srgrimes 148168365Sandre/* 149168365Sandre * mbuf flag used by ip_fastfwd 150168365Sandre */ 151126239Smlaier#define M_FASTFWD_OURS M_PROTO1 /* changed dst to local */ 152126239Smlaier 153147744Sthompsa#ifdef __NO_STRICT_ALIGNMENT 154147744Sthompsa#define IP_HDR_ALIGNED_P(ip) 1 155147744Sthompsa#else 156147744Sthompsa#define IP_HDR_ALIGNED_P(ip) ((((intptr_t) (ip)) & 3) == 0) 157147744Sthompsa#endif 158147744Sthompsa 15938482Swollmanstruct ip; 16019669Sbdestruct inpcb; 16118940Sbdestruct route; 16238482Swollmanstruct sockopt; 16318940Sbde 164185937Sbz#ifdef VIMAGE_GLOBALS 1652112Swollmanextern struct ipstat ipstat; 166168365Sandreextern u_short ip_id; /* ip packet ctr, for ids */ 167185895Szecextern int ip_do_randomid; 168168365Sandreextern int ip_defttl; /* default IP ttl */ 169168365Sandreextern int ipforwarding; /* ip forwarding */ 170122723Sandre#ifdef IPSTEALTH 171168365Sandreextern int ipstealth; /* stealth forwarding */ 172122723Sandre#endif 173185937Sbzextern int rsvp_on; 174168365Sandreextern struct socket *ip_rsvpd; /* reservation protocol daemon */ 175168365Sandreextern struct socket *ip_mrouter; /* multicast routing daemon */ 176193502Sluigi#endif /* VIMAGE_GLOBALS */ 177193502Sluigi 178185937Sbzextern u_char ip_protox[]; 17992723Salfredextern int (*legal_vif_num)(int); 18092723Salfredextern u_long (*ip_mcast_src)(int); 18122900Swollmanextern struct pr_usrreqs rip_usrreqs; 1821541Srgrimes 183170613Sbmsvoid inp_freemoptions(struct ip_moptions *); 184170613Sbmsint inp_getmoptions(struct inpcb *, struct sockopt *); 185170613Sbmsint inp_setmoptions(struct inpcb *, struct sockopt *); 186170613Sbms 187168365Sandreint ip_ctloutput(struct socket *, struct sockopt *sopt); 188168365Sandrevoid ip_drain(void); 189168365Sandrevoid ip_fini(void *xtp); 190168365Sandreint ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu, 191118622Shsu u_long if_hwassist_flags, int sw_csum); 192168365Sandrevoid ip_forward(struct mbuf *m, int srcrt); 193168365Sandrevoid ip_init(void); 194168365Sandreextern int 195168365Sandre (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *, 196168365Sandre struct ip_moptions *); 197168365Sandreint ip_output(struct mbuf *, 198105194Ssam struct mbuf *, struct route *, int, struct ip_moptions *, 199105194Ssam struct inpcb *); 200168365Sandreint ipproto_register(u_char); 201168365Sandreint ipproto_unregister(u_char); 202133920Sandrestruct mbuf * 203168365Sandre ip_reass(struct mbuf *); 20487120Srustruct in_ifaddr * 205178888Sjulian ip_rtaddr(struct in_addr, u_int fibnum); 206168365Sandrevoid ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *, 207168365Sandre struct mbuf *); 208168365Sandrevoid ip_slowtimo(void); 209133720Sdwmaloneu_int16_t ip_randomid(void); 21098663Sluigiint rip_ctloutput(struct socket *, struct sockopt *); 21198663Sluigivoid rip_ctlinput(int, struct sockaddr *, void *); 21298663Sluigivoid rip_init(void); 213193731Szec#ifdef VIMAGE 214193731Szecvoid rip_destroy(void); 215193731Szec#endif 21698663Sluigivoid rip_input(struct mbuf *, int); 21798663Sluigiint rip_output(struct mbuf *, struct socket *, u_long); 21892723Salfredvoid ipip_input(struct mbuf *, int); 21992723Salfredvoid rsvp_input(struct mbuf *, int); 22092723Salfredint ip_rsvp_init(struct socket *); 22192723Salfredint ip_rsvp_done(void); 222106968Sluigiextern int (*ip_rsvp_vif)(struct socket *, struct sockopt *); 223106968Sluigiextern void (*ip_rsvp_force_done)(struct socket *); 224106968Sluigiextern void (*rsvp_input_p)(struct mbuf *m, int off); 2257083Swollman 226134383Sandreextern struct pfil_head inet_pfil_hook; /* packet filter hooks */ 227120386Ssam 22860765Sjlemonvoid in_delayed_cksum(struct mbuf *m); 22960765Sjlemon 230193502Sluigi/* ipfw and dummynet hooks. Most are declared in raw_ip.c */ 231193502Sluigistruct ip_fw_args; 232193502Sluigiextern int (*ip_fw_chk_ptr)(struct ip_fw_args *args); 233193502Sluigiextern int (*ip_fw_ctl_ptr)(struct sockopt *); 234193502Sluigiextern int (*ip_dn_ctl_ptr)(struct sockopt *); 235193502Sluigiextern int (*ip_dn_io_ptr)(struct mbuf **m, int dir, struct ip_fw_args *fwa); 236193502Sluigiextern void (*ip_dn_ruledel_ptr)(void *); /* in ip_fw2.c */ 23755205Speter#endif /* _KERNEL */ 23817072Sjulian 23937625Sbde#endif /* !_NETINET_IP_VAR_H_ */ 240