ip_var.h revision 22900
129759Swollman/* 229759Swollman * Copyright (c) 1982, 1986, 1993 329759Swollman * The Regents of the University of California. All rights reserved. 429759Swollman * 529759Swollman * Redistribution and use in source and binary forms, with or without 629759Swollman * modification, are permitted provided that the following conditions 729759Swollman * are met: 829759Swollman * 1. Redistributions of source code must retain the above copyright 929759Swollman * notice, this list of conditions and the following disclaimer. 1029759Swollman * 2. Redistributions in binary form must reproduce the above copyright 1129759Swollman * notice, this list of conditions and the following disclaimer in the 1229759Swollman * documentation and/or other materials provided with the distribution. 1329759Swollman * 3. All advertising materials mentioning features or use of this software 1429759Swollman * must display the following acknowledgement: 1529759Swollman * This product includes software developed by the University of 1629759Swollman * California, Berkeley and its contributors. 1729759Swollman * 4. Neither the name of the University nor the names of its contributors 1829759Swollman * may be used to endorse or promote products derived from this software 1929759Swollman * without specific prior written permission. 2029759Swollman * 2129759Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2229759Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2329759Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2429759Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2529759Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2629759Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2729759Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2829759Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2929759Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3029759Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3129759Swollman * SUCH DAMAGE. 3229759Swollman * 3329759Swollman * @(#)ip_var.h 8.2 (Berkeley) 1/9/95 3487715Smarkm * $FreeBSD: head/sys/netinet/ip_var.h 22900 1997-02-18 20:46:36Z wollman $ 3587715Smarkm */ 3687715Smarkm 3787715Smarkm#ifndef _NETINET_IP_VAR_H_ 3887715Smarkm#define _NETINET_IP_VAR_H_ 3987715Smarkm 4087715Smarkm/* 4187715Smarkm * Overlay for ip header used by other protocols (tcp, udp). 4229759Swollman */ 4387715Smarkmstruct ipovly { 4429759Swollman caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 4529759Swollman u_char ih_x1; /* (unused) */ 4629759Swollman u_char ih_pr; /* protocol */ 4729759Swollman u_short ih_len; /* protocol length */ 4829759Swollman struct in_addr ih_src; /* source internet address */ 4929759Swollman struct in_addr ih_dst; /* destination internet address */ 5029759Swollman}; 5129759Swollman 5229759Swollman/* 5329759Swollman * Ip reassembly queue structure. Each fragment 5429759Swollman * being reassembled is attached to one of these structures. 5529759Swollman * They are timed out after ipq_ttl drops to 0, and may also 5629759Swollman * be reclaimed if memory becomes tight. 57200462Sdelphij */ 5829759Swollmanstruct ipq { 59200462Sdelphij struct ipq *next,*prev; /* to other reass headers */ 6029759Swollman u_char ipq_ttl; /* time for reass q to live */ 6129759Swollman u_char ipq_p; /* protocol of this fragment */ 6229759Swollman u_short ipq_id; /* sequence id for reassembly */ 6329759Swollman struct ipasfrag *ipq_next,*ipq_prev; 6429759Swollman /* to ip headers of fragments */ 6529759Swollman struct in_addr ipq_src,ipq_dst; 6629759Swollman#ifdef IPDIVERT 6729759Swollman u_short ipq_divert; /* divert protocol port */ 6829759Swollman#endif 69158160Sbde}; 70158160Sbde 71158160Sbde/* 72158160Sbde * Ip header, when holding a fragment. 73158160Sbde * 74158160Sbde * Note: ipf_next must be at same offset as ipq_next above 75158160Sbde */ 76158160Sbdestruct ipasfrag { 77158160Sbde#if BYTE_ORDER == LITTLE_ENDIAN 78158160Sbde u_char ip_hl:4, 79158160Sbde ip_v:4; 80158160Sbde#endif 81158160Sbde#if BYTE_ORDER == BIG_ENDIAN 82158160Sbde u_char ip_v:4, 83158160Sbde ip_hl:4; 84158160Sbde#endif 85158160Sbde u_char ipf_mff; /* XXX overlays ip_tos: use low bit 86158160Sbde * to avoid destroying tos; 8729759Swollman * copied from (ip_off&IP_MF) */ 8829759Swollman u_short ip_len; 8929759Swollman u_short ip_id; 9029759Swollman u_short ip_off; 9129759Swollman u_char ip_ttl; 9229759Swollman u_char ip_p; 9329759Swollman u_short ip_sum; 9429759Swollman struct ipasfrag *ipf_next; /* next fragment */ 95158160Sbde struct ipasfrag *ipf_prev; /* previous fragment */ 9629759Swollman}; 9729759Swollman 9829759Swollman/* 99175387Sdelphij * Structure stored in mbuf in inpcb.ip_options 10029759Swollman * and passed to ip_output when ip options are in use. 10129759Swollman * The actual length of the options (including ipopt_dst) 10229759Swollman * is in m_len. 10329759Swollman */ 10429759Swollman#define MAX_IPOPTLEN 40 10529759Swollman 10629759Swollmanstruct ipoption { 10729759Swollman struct in_addr ipopt_dst; /* first-hop dst if source routed */ 10829759Swollman char ipopt_list[MAX_IPOPTLEN]; /* options proper */ 10929759Swollman}; 11029759Swollman 11129759Swollman/* 11229759Swollman * Structure attached to inpcb.ip_moptions and 11329759Swollman * passed to ip_output when IP multicast options are in use. 114158160Sbde */ 115158160Sbdestruct ip_moptions { 116158160Sbde struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */ 117158160Sbde u_char imo_multicast_ttl; /* TTL for outgoing multicasts */ 118158160Sbde u_char imo_multicast_loop; /* 1 => hear sends if a member */ 119158160Sbde u_short imo_num_memberships; /* no. memberships this socket */ 120158160Sbde struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS]; 121158160Sbde u_long imo_multicast_vif; /* vif num outgoing multicasts */ 122158160Sbde}; 12329759Swollman 124158160Sbdestruct ipstat { 125158160Sbde u_long ips_total; /* total packets received */ 126158160Sbde u_long ips_badsum; /* checksum bad */ 127158160Sbde u_long ips_tooshort; /* packet too short */ 128158160Sbde u_long ips_toosmall; /* not enough data */ 129158160Sbde u_long ips_badhlen; /* ip header length < data size */ 130158160Sbde u_long ips_badlen; /* ip length < ip header length */ 13129759Swollman u_long ips_fragments; /* fragments received */ 13229759Swollman u_long ips_fragdropped; /* frags dropped (dups, out of space) */ 13329759Swollman u_long ips_fragtimeout; /* fragments timed out */ 13429759Swollman u_long ips_forward; /* packets forwarded */ 13529759Swollman u_long ips_cantforward; /* packets rcvd for unreachable dest */ 13629759Swollman u_long ips_redirectsent; /* packets forwarded on same net */ 13729759Swollman u_long ips_noproto; /* unknown or unsupported protocol */ 13829759Swollman u_long ips_delivered; /* datagrams delivered to upper level*/ 13929759Swollman u_long ips_localout; /* total ip packets generated here */ 14029759Swollman u_long ips_odropped; /* lost packets due to nobufs, etc. */ 14129759Swollman u_long ips_reassembled; /* total packets reassembled ok */ 14229759Swollman u_long ips_fragmented; /* datagrams successfully fragmented */ 14329759Swollman u_long ips_ofragments; /* output fragments created */ 14429759Swollman u_long ips_cantfrag; /* don't fragment flag was set, etc. */ 14529759Swollman u_long ips_badoptions; /* error in option processing */ 14629759Swollman u_long ips_noroute; /* packets discarded due to no route */ 14729759Swollman u_long ips_badvers; /* ip version != 4 */ 14829759Swollman u_long ips_rawout; /* total raw ip packets generated */ 14929759Swollman u_long ips_toolong; /* ip length > max ip packet size */ 15029759Swollman u_long ips_notmember; /* multicasts for unregistered grps */ 15129759Swollman}; 15229759Swollman 15329759Swollman#ifdef KERNEL 15429759Swollman/* flags passed to ip_output as last parameter */ 15529759Swollman#define IP_FORWARDING 0x1 /* most of ip header exists */ 15629759Swollman#define IP_RAWOUTPUT 0x2 /* raw ip header exists */ 15729759Swollman#define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */ 15829759Swollman#define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */ 15929759Swollman 16029759Swollmanstruct inpcb; 16129759Swollmanstruct route; 16229759Swollman 16329759Swollmanextern struct ipstat ipstat; 16429759Swollmanextern struct ipq ipq; /* ip reass. queue */ 16529759Swollmanextern u_short ip_id; /* ip packet ctr, for ids */ 16629759Swollmanextern int ip_defttl; /* default IP ttl */ 16729759Swollmanextern u_char ip_protox[]; 16829759Swollmanextern struct socket *ip_rsvpd; /* reservation protocol daemon */ 16929759Swollmanextern struct socket *ip_mrouter; /* multicast routing daemon */ 17029759Swollmanextern int (*legal_vif_num) __P((int)); 17129759Swollmanextern u_long (*ip_mcast_src) __P((int)); 17229759Swollmanextern int rsvp_on; 17329759Swollmanextern struct pr_usrreqs rip_usrreqs; 17429759Swollman 17529759Swollmanint ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 176158161Sbdevoid ip_drain __P((void)); 17729759Swollmanvoid ip_freemoptions __P((struct ip_moptions *)); 17829759Swollmanvoid ip_init __P((void)); 17929759Swollmanextern int (*ip_mforward) __P((struct ip *, struct ifnet *, struct mbuf *, 18029759Swollman struct ip_moptions *)); 18129759Swollmanint ip_output __P((struct mbuf *, 18229759Swollman struct mbuf *, struct route *, int, struct ip_moptions *)); 18329759Swollmanvoid ip_savecontrol __P((struct inpcb *, struct mbuf **, struct ip *, 18429759Swollman struct mbuf *)); 18529759Swollmanvoid ip_slowtimo __P((void)); 18629759Swollmanstruct mbuf * 18729759Swollman ip_srcroute __P((void)); 18829759Swollmanvoid ip_stripoptions __P((struct mbuf *, struct mbuf *)); 18929759Swollmanint rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 190158161Sbdevoid rip_ctlinput __P((int, struct sockaddr *, void *)); 19129759Swollmanvoid rip_init __P((void)); 192158160Sbdevoid rip_input __P((struct mbuf *, int)); 193158160Sbdeint rip_output __P((struct mbuf *, struct socket *, u_long)); 19429759Swollmanvoid ipip_input __P((struct mbuf *, int)); 19529759Swollmanvoid rsvp_input __P((struct mbuf *, int)); 19629759Swollmanint ip_rsvp_init __P((struct socket *)); 19729759Swollmanint ip_rsvp_done __P((void)); 198158160Sbdeint ip_rsvp_vif_init __P((struct socket *, struct mbuf *)); 199158160Sbdeint ip_rsvp_vif_done __P((struct socket *, struct mbuf *)); 200158160Sbdevoid ip_rsvp_force_done __P((struct socket *)); 201158160Sbde 202158160Sbde#ifdef IPDIVERT 203158160Sbdevoid div_init __P((void)); 204158160Sbdevoid div_input __P((struct mbuf *, int)); 205158160Sbdeint div_usrreq __P((struct socket *, 206158160Sbde int, struct mbuf *, struct mbuf *, struct mbuf *)); 207158160Sbdeextern u_short ip_divert_port; 20829759Swollmanextern u_short ip_divert_ignore; 20929759Swollman#endif /* IPDIVERT */ 210158160Sbde 211158160Sbde#endif /* KERNEL */ 212158160Sbde 213158160Sbde#endif /* _NETINET_IP_VAR_H_ */ 214158160Sbde