ip_var.h revision 37409
160897Smsmith/* 260897Smsmith * Copyright (c) 1982, 1986, 1993 360897Smsmith * The Regents of the University of California. All rights reserved. 460897Smsmith * 560897Smsmith * Redistribution and use in source and binary forms, with or without 660897Smsmith * modification, are permitted provided that the following conditions 760897Smsmith * are met: 860897Smsmith * 1. Redistributions of source code must retain the above copyright 960897Smsmith * notice, this list of conditions and the following disclaimer. 1060897Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1160897Smsmith * notice, this list of conditions and the following disclaimer in the 1260897Smsmith * documentation and/or other materials provided with the distribution. 1379727Sschweikh * 3. All advertising materials mentioning features or use of this software 1460897Smsmith * must display the following acknowledgement: 1560897Smsmith * This product includes software developed by the University of 1660897Smsmith * California, Berkeley and its contributors. 1760897Smsmith * 4. Neither the name of the University nor the names of its contributors 1860897Smsmith * may be used to endorse or promote products derived from this software 1960897Smsmith * without specific prior written permission. 2060897Smsmith * 2160897Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2260897Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2360897Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2460897Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2560897Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2660897Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27133758Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2860897Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2960897Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3060897Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3160897Smsmith * SUCH DAMAGE. 32142648Sbrueffer * 3360897Smsmith * @(#)ip_var.h 8.2 (Berkeley) 1/9/95 34158762Sbrueffer * $Id: ip_var.h,v 1.41 1998/06/08 09:47:42 bde Exp $ 35158762Sbrueffer */ 36158762Sbrueffer 37158762Sbrueffer#ifndef _NETINET_IP_VAR_H_ 38158762Sbrueffer#define _NETINET_IP_VAR_H_ 39158762Sbrueffer 40158762Sbrueffer/* 41158762Sbrueffer * Overlay for ip header used by other protocols (tcp, udp). 42158762Sbrueffer */ 43158762Sbruefferstruct ipovly { 44158762Sbrueffer caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 45158762Sbrueffer u_char ih_x1; /* (unused) */ 46158762Sbrueffer u_char ih_pr; /* protocol */ 47158762Sbrueffer u_short ih_len; /* protocol length */ 4860897Smsmith struct in_addr ih_src; /* source internet address */ 4960897Smsmith struct in_addr ih_dst; /* destination internet address */ 5060897Smsmith}; 51133758Ssimon 52142648Sbrueffer/* 53145322Sbrueffer * Ip reassembly queue structure. Each fragment 54133758Ssimon * being reassembled is attached to one of these structures. 55131570Ssimon * They are timed out after ipq_ttl drops to 0, and may also 56133758Ssimon * be reclaimed if memory becomes tight. 57131570Ssimon */ 58131570Ssimonstruct ipq { 59131570Ssimon struct ipq *next,*prev; /* to other reass headers */ 60131570Ssimon u_char ipq_ttl; /* time for reass q to live */ 61142648Sbrueffer u_char ipq_p; /* protocol of this fragment */ 62117665Sps u_short ipq_id; /* sequence id for reassembly */ 63117665Sps struct ipasfrag *ipq_next,*ipq_prev; 64117665Sps /* to ip headers of fragments */ 65117665Sps struct in_addr ipq_src,ipq_dst; 66133758Ssimon#ifdef IPDIVERT 67117665Sps u_short ipq_divert; /* divert protocol port */ 68133758Ssimon u_short ipq_div_cookie; /* divert protocol cookie */ 69117665Sps#endif 70133758Ssimon}; 71117665Sps 72133758Ssimon/* 73133758Ssimon * Ip header, when holding a fragment. 74133758Ssimon * 75133758Ssimon * Note: ipf_next must be at same offset as ipq_next above 76133758Ssimon */ 77133758Ssimonstruct ipasfrag { 78133758Ssimon#if BYTE_ORDER == LITTLE_ENDIAN 79133758Ssimon u_int ip_hl:4, 80133758Ssimon ip_v:4; 81133758Ssimon#endif 82133758Ssimon#if BYTE_ORDER == BIG_ENDIAN 83133758Ssimon u_int ip_v:4, 84133758Ssimon ip_hl:4; 85133758Ssimon#endif 86133758Ssimon u_char ipf_mff; /* XXX overlays ip_tos: use low bit 87133758Ssimon * to avoid destroying tos; 88133758Ssimon * copied from (ip_off&IP_MF) */ 89133758Ssimon u_short ip_len; 90133758Ssimon u_short ip_id; 91133758Ssimon u_short ip_off; 92133758Ssimon u_char ip_ttl; 93133758Ssimon u_char ip_p; 94133758Ssimon u_short ip_sum; 95133758Ssimon struct ipasfrag *ipf_next; /* next fragment */ 96133758Ssimon struct ipasfrag *ipf_prev; /* previous fragment */ 97133758Ssimon}; 98133758Ssimon 99133758Ssimon/* 100133758Ssimon * Structure stored in mbuf in inpcb.ip_options 101133758Ssimon * and passed to ip_output when ip options are in use. 102133758Ssimon * The actual length of the options (including ipopt_dst) 103117665Sps * is in m_len. 10460897Smsmith */ 10561941Ssheldonh#define MAX_IPOPTLEN 40 10660897Smsmith 10760897Smsmithstruct ipoption { 10860897Smsmith struct in_addr ipopt_dst; /* first-hop dst if source routed */ 10961941Ssheldonh char ipopt_list[MAX_IPOPTLEN]; /* options proper */ 11061941Ssheldonh}; 11161941Ssheldonh 11260897Smsmith/* 11360897Smsmith * Structure attached to inpcb.ip_moptions and 11460897Smsmith * passed to ip_output when IP multicast options are in use. 11560897Smsmith */ 11660897Smsmithstruct ip_moptions { 11760897Smsmith struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */ 11860897Smsmith u_char imo_multicast_ttl; /* TTL for outgoing multicasts */ 11961941Ssheldonh u_char imo_multicast_loop; /* 1 => hear sends if a member */ 12061941Ssheldonh u_short imo_num_memberships; /* no. memberships this socket */ 12161941Ssheldonh struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS]; 12260897Smsmith u_long imo_multicast_vif; /* vif num outgoing multicasts */ 12360897Smsmith}; 12460897Smsmith 12561941Ssheldonhstruct ipstat { 12661941Ssheldonh u_long ips_total; /* total packets received */ 12770466Sru u_long ips_badsum; /* checksum bad */ 12861941Ssheldonh u_long ips_tooshort; /* packet too short */ 12960897Smsmith u_long ips_toosmall; /* not enough data */ 13060897Smsmith u_long ips_badhlen; /* ip header length < data size */ 13160897Smsmith u_long ips_badlen; /* ip length < ip header length */ 13260897Smsmith u_long ips_fragments; /* fragments received */ 13360897Smsmith u_long ips_fragdropped; /* frags dropped (dups, out of space) */ 13460897Smsmith u_long ips_fragtimeout; /* fragments timed out */ 13560897Smsmith u_long ips_forward; /* packets forwarded */ 13660897Smsmith u_long ips_fastforward; /* packets fast forwarded */ 13760897Smsmith u_long ips_cantforward; /* packets rcvd for unreachable dest */ 13861941Ssheldonh u_long ips_redirectsent; /* packets forwarded on same net */ 13961941Ssheldonh u_long ips_noproto; /* unknown or unsupported protocol */ 14060897Smsmith u_long ips_delivered; /* datagrams delivered to upper level*/ 14160897Smsmith u_long ips_localout; /* total ip packets generated here */ 14260897Smsmith u_long ips_odropped; /* lost packets due to nobufs, etc. */ 14360897Smsmith u_long ips_reassembled; /* total packets reassembled ok */ 14467877Sasmodai u_long ips_fragmented; /* datagrams successfully fragmented */ 14567877Sasmodai u_long ips_ofragments; /* output fragments created */ 14667877Sasmodai u_long ips_cantfrag; /* don't fragment flag was set, etc. */ 14760897Smsmith u_long ips_badoptions; /* error in option processing */ 14860897Smsmith u_long ips_noroute; /* packets discarded due to no route */ 14960897Smsmith u_long ips_badvers; /* ip version != 4 */ 150146159Sbrueffer u_long ips_rawout; /* total raw ip packets generated */ 15167877Sasmodai u_long ips_toolong; /* ip length > max ip packet size */ 15261941Ssheldonh u_long ips_notmember; /* multicasts for unregistered grps */ 15370466Sru}; 15467877Sasmodai 15567877Sasmodai#ifdef KERNEL 15667877Sasmodai/* flags passed to ip_output as last parameter */ 15767877Sasmodai#define IP_FORWARDING 0x1 /* most of ip header exists */ 15860897Smsmith#define IP_RAWOUTPUT 0x2 /* raw ip header exists */ 15967877Sasmodai#define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */ 16067877Sasmodai#define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */ 16167877Sasmodai 16267877Sasmodaistruct inpcb; 16367877Sasmodaistruct route; 16467877Sasmodai 16567877Sasmodaiextern struct ipstat ipstat; 16667877Sasmodaiextern u_short ip_id; /* ip packet ctr, for ids */ 16767877Sasmodaiextern int ip_defttl; /* default IP ttl */ 16867877Sasmodaiextern int ipforwarding; /* ip forwarding */ 16960897Smsmithextern u_char ip_protox[]; 17067877Sasmodaiextern struct socket *ip_rsvpd; /* reservation protocol daemon */ 17167877Sasmodaiextern struct socket *ip_mrouter; /* multicast routing daemon */ 17267877Sasmodaiextern int (*legal_vif_num) __P((int)); 17367877Sasmodaiextern u_long (*ip_mcast_src) __P((int)); 17467877Sasmodaiextern int rsvp_on; 17567877Sasmodaiextern struct pr_usrreqs rip_usrreqs; 17667877Sasmodai 17767877Sasmodaiint ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **, 17867877Sasmodai struct proc *)); 17967877Sasmodaivoid ip_drain __P((void)); 18067877Sasmodaivoid ip_freemoptions __P((struct ip_moptions *)); 18167877Sasmodaivoid ip_init __P((void)); 18267877Sasmodaiextern int (*ip_mforward) __P((struct ip *, struct ifnet *, struct mbuf *, 18367877Sasmodai struct ip_moptions *)); 18467877Sasmodaiint ip_output __P((struct mbuf *, 18567877Sasmodai struct mbuf *, struct route *, int, struct ip_moptions *)); 18660897Smsmithvoid ip_savecontrol __P((struct inpcb *, struct mbuf **, struct ip *, 18767877Sasmodai struct mbuf *)); 18867877Sasmodaivoid ip_slowtimo __P((void)); 18967877Sasmodaistruct mbuf * 19067877Sasmodai ip_srcroute __P((void)); 19167877Sasmodaivoid ip_stripoptions __P((struct mbuf *, struct mbuf *)); 19267877Sasmodaiint rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **, 19367877Sasmodai struct proc *p)); 19467877Sasmodaivoid rip_ctlinput __P((int, struct sockaddr *, void *)); 19567877Sasmodaivoid rip_init __P((void)); 19667877Sasmodaivoid rip_input __P((struct mbuf *, int)); 19767877Sasmodaiint rip_output __P((struct mbuf *, struct socket *, u_long)); 19867877Sasmodaivoid ipip_input __P((struct mbuf *, int)); 19967879Sasmodaivoid rsvp_input __P((struct mbuf *, int)); 20067879Sasmodaiint ip_rsvp_init __P((struct socket *)); 20167877Sasmodaiint ip_rsvp_done __P((void)); 20267877Sasmodaiint ip_rsvp_vif_init __P((struct socket *, struct mbuf *)); 20367877Sasmodaiint ip_rsvp_vif_done __P((struct socket *, struct mbuf *)); 20467877Sasmodaivoid ip_rsvp_force_done __P((struct socket *)); 20567877Sasmodai 20667877Sasmodai#ifdef IPDIVERT 20767877Sasmodaivoid div_init __P((void)); 20867877Sasmodaivoid div_input __P((struct mbuf *, int)); 20967877Sasmodaiextern struct pr_usrreqs div_usrreqs; 21067877Sasmodaiextern u_short ip_divert_port; 21167877Sasmodaiextern u_short ip_divert_cookie; 21267877Sasmodai#endif /* IPDIVERT */ 21367877Sasmodai 21467877Sasmodaistruct sockaddr_in; 21567877Sasmodaiextern struct sockaddr_in *ip_fw_fwd_addr; 21667877Sasmodai 21767877Sasmodai#endif /* KERNEL */ 21867877Sasmodai 21960897Smsmith#endif /* _NETINET_IP_VAR_H_ */ 22060897Smsmith