1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 333271ad14SGarrett Wollman * @(#)ip_var.h 8.2 (Berkeley) 1/9/95 345e26bd9aSBruce Evans * $Id: ip_var.h,v 1.21 1996/07/10 19:44:27 julian Exp $ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37707f139eSPaul Richards #ifndef _NETINET_IP_VAR_H_ 38707f139eSPaul Richards #define _NETINET_IP_VAR_H_ 39707f139eSPaul Richards 40df8bae1dSRodney W. Grimes /* 41df8bae1dSRodney W. Grimes * Overlay for ip header used by other protocols (tcp, udp). 42df8bae1dSRodney W. Grimes */ 43df8bae1dSRodney W. Grimes struct ipovly { 44df8bae1dSRodney W. Grimes caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 45df8bae1dSRodney W. Grimes u_char ih_x1; /* (unused) */ 46df8bae1dSRodney W. Grimes u_char ih_pr; /* protocol */ 47df8bae1dSRodney W. Grimes short ih_len; /* protocol length */ 48df8bae1dSRodney W. Grimes struct in_addr ih_src; /* source internet address */ 49df8bae1dSRodney W. Grimes struct in_addr ih_dst; /* destination internet address */ 50df8bae1dSRodney W. Grimes }; 51df8bae1dSRodney W. Grimes 52df8bae1dSRodney W. Grimes /* 53df8bae1dSRodney W. Grimes * Ip reassembly queue structure. Each fragment 54df8bae1dSRodney W. Grimes * being reassembled is attached to one of these structures. 55df8bae1dSRodney W. Grimes * They are timed out after ipq_ttl drops to 0, and may also 56df8bae1dSRodney W. Grimes * be reclaimed if memory becomes tight. 57df8bae1dSRodney W. Grimes */ 58df8bae1dSRodney W. Grimes struct ipq { 59df8bae1dSRodney W. Grimes struct ipq *next,*prev; /* to other reass headers */ 60df8bae1dSRodney W. Grimes u_char ipq_ttl; /* time for reass q to live */ 61df8bae1dSRodney W. Grimes u_char ipq_p; /* protocol of this fragment */ 62df8bae1dSRodney W. Grimes u_short ipq_id; /* sequence id for reassembly */ 63df8bae1dSRodney W. Grimes struct ipasfrag *ipq_next,*ipq_prev; 64df8bae1dSRodney W. Grimes /* to ip headers of fragments */ 65df8bae1dSRodney W. Grimes struct in_addr ipq_src,ipq_dst; 6693e0e116SJulian Elischer #ifdef IPDIVERT 6793e0e116SJulian Elischer u_short ipq_divert; /* divert protocol port */ 6893e0e116SJulian Elischer #endif 69df8bae1dSRodney W. Grimes }; 70df8bae1dSRodney W. Grimes 71df8bae1dSRodney W. Grimes /* 72df8bae1dSRodney W. Grimes * Ip header, when holding a fragment. 73df8bae1dSRodney W. Grimes * 74df8bae1dSRodney W. Grimes * Note: ipf_next must be at same offset as ipq_next above 75df8bae1dSRodney W. Grimes */ 76df8bae1dSRodney W. Grimes struct ipasfrag { 77df8bae1dSRodney W. Grimes #if BYTE_ORDER == LITTLE_ENDIAN 78df8bae1dSRodney W. Grimes u_char ip_hl:4, 79df8bae1dSRodney W. Grimes ip_v:4; 80df8bae1dSRodney W. Grimes #endif 81df8bae1dSRodney W. Grimes #if BYTE_ORDER == BIG_ENDIAN 82df8bae1dSRodney W. Grimes u_char ip_v:4, 83df8bae1dSRodney W. Grimes ip_hl:4; 84df8bae1dSRodney W. Grimes #endif 85df8bae1dSRodney W. Grimes u_char ipf_mff; /* XXX overlays ip_tos: use low bit 86df8bae1dSRodney W. Grimes * to avoid destroying tos; 87df8bae1dSRodney W. Grimes * copied from (ip_off&IP_MF) */ 88df8bae1dSRodney W. Grimes short ip_len; 89df8bae1dSRodney W. Grimes u_short ip_id; 90df8bae1dSRodney W. Grimes short ip_off; 91df8bae1dSRodney W. Grimes u_char ip_ttl; 92df8bae1dSRodney W. Grimes u_char ip_p; 93df8bae1dSRodney W. Grimes u_short ip_sum; 94df8bae1dSRodney W. Grimes struct ipasfrag *ipf_next; /* next fragment */ 95df8bae1dSRodney W. Grimes struct ipasfrag *ipf_prev; /* previous fragment */ 96df8bae1dSRodney W. Grimes }; 97df8bae1dSRodney W. Grimes 98df8bae1dSRodney W. Grimes /* 99df8bae1dSRodney W. Grimes * Structure stored in mbuf in inpcb.ip_options 100df8bae1dSRodney W. Grimes * and passed to ip_output when ip options are in use. 101df8bae1dSRodney W. Grimes * The actual length of the options (including ipopt_dst) 102df8bae1dSRodney W. Grimes * is in m_len. 103df8bae1dSRodney W. Grimes */ 104df8bae1dSRodney W. Grimes #define MAX_IPOPTLEN 40 105df8bae1dSRodney W. Grimes 106df8bae1dSRodney W. Grimes struct ipoption { 107df8bae1dSRodney W. Grimes struct in_addr ipopt_dst; /* first-hop dst if source routed */ 108df8bae1dSRodney W. Grimes char ipopt_list[MAX_IPOPTLEN]; /* options proper */ 109df8bae1dSRodney W. Grimes }; 110df8bae1dSRodney W. Grimes 111df8bae1dSRodney W. Grimes /* 112df8bae1dSRodney W. Grimes * Structure attached to inpcb.ip_moptions and 113df8bae1dSRodney W. Grimes * passed to ip_output when IP multicast options are in use. 114df8bae1dSRodney W. Grimes */ 115df8bae1dSRodney W. Grimes struct ip_moptions { 116df8bae1dSRodney W. Grimes struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */ 117df8bae1dSRodney W. Grimes u_char imo_multicast_ttl; /* TTL for outgoing multicasts */ 118df8bae1dSRodney W. Grimes u_char imo_multicast_loop; /* 1 => hear sends if a member */ 119df8bae1dSRodney W. Grimes u_short imo_num_memberships; /* no. memberships this socket */ 120df8bae1dSRodney W. Grimes struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS]; 1211c5de19aSGarrett Wollman u_long imo_multicast_vif; /* vif num outgoing multicasts */ 122df8bae1dSRodney W. Grimes }; 123df8bae1dSRodney W. Grimes 124df8bae1dSRodney W. Grimes struct ipstat { 125df8bae1dSRodney W. Grimes u_long ips_total; /* total packets received */ 126df8bae1dSRodney W. Grimes u_long ips_badsum; /* checksum bad */ 127df8bae1dSRodney W. Grimes u_long ips_tooshort; /* packet too short */ 128df8bae1dSRodney W. Grimes u_long ips_toosmall; /* not enough data */ 129df8bae1dSRodney W. Grimes u_long ips_badhlen; /* ip header length < data size */ 130df8bae1dSRodney W. Grimes u_long ips_badlen; /* ip length < ip header length */ 131df8bae1dSRodney W. Grimes u_long ips_fragments; /* fragments received */ 132df8bae1dSRodney W. Grimes u_long ips_fragdropped; /* frags dropped (dups, out of space) */ 133df8bae1dSRodney W. Grimes u_long ips_fragtimeout; /* fragments timed out */ 134df8bae1dSRodney W. Grimes u_long ips_forward; /* packets forwarded */ 135df8bae1dSRodney W. Grimes u_long ips_cantforward; /* packets rcvd for unreachable dest */ 136df8bae1dSRodney W. Grimes u_long ips_redirectsent; /* packets forwarded on same net */ 137df8bae1dSRodney W. Grimes u_long ips_noproto; /* unknown or unsupported protocol */ 138df8bae1dSRodney W. Grimes u_long ips_delivered; /* datagrams delivered to upper level*/ 139df8bae1dSRodney W. Grimes u_long ips_localout; /* total ip packets generated here */ 140df8bae1dSRodney W. Grimes u_long ips_odropped; /* lost packets due to nobufs, etc. */ 141df8bae1dSRodney W. Grimes u_long ips_reassembled; /* total packets reassembled ok */ 1426c5e9bbdSMike Pritchard u_long ips_fragmented; /* datagrams successfully fragmented */ 143df8bae1dSRodney W. Grimes u_long ips_ofragments; /* output fragments created */ 144df8bae1dSRodney W. Grimes u_long ips_cantfrag; /* don't fragment flag was set, etc. */ 145df8bae1dSRodney W. Grimes u_long ips_badoptions; /* error in option processing */ 146df8bae1dSRodney W. Grimes u_long ips_noroute; /* packets discarded due to no route */ 147df8bae1dSRodney W. Grimes u_long ips_badvers; /* ip version != 4 */ 148df8bae1dSRodney W. Grimes u_long ips_rawout; /* total raw ip packets generated */ 149df8bae1dSRodney W. Grimes }; 150df8bae1dSRodney W. Grimes 151df8bae1dSRodney W. Grimes #ifdef KERNEL 152df8bae1dSRodney W. Grimes /* flags passed to ip_output as last parameter */ 153df8bae1dSRodney W. Grimes #define IP_FORWARDING 0x1 /* most of ip header exists */ 154df8bae1dSRodney W. Grimes #define IP_RAWOUTPUT 0x2 /* raw ip header exists */ 155df8bae1dSRodney W. Grimes #define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */ 156df8bae1dSRodney W. Grimes #define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */ 157df8bae1dSRodney W. Grimes 1585e26bd9aSBruce Evans struct route; 1595e26bd9aSBruce Evans 160f23b4c91SGarrett Wollman extern struct ipstat ipstat; 161f23b4c91SGarrett Wollman extern struct ipq ipq; /* ip reass. queue */ 162f23b4c91SGarrett Wollman extern u_short ip_id; /* ip packet ctr, for ids */ 163f23b4c91SGarrett Wollman extern int ip_defttl; /* default IP ttl */ 164b5e8ce9fSBruce Evans extern u_char ip_protox[]; 165f0068c4aSGarrett Wollman extern struct socket *ip_rsvpd; /* reservation protocol daemon */ 166f0068c4aSGarrett Wollman extern struct socket *ip_mrouter; /* multicast routing daemon */ 167b5e8ce9fSBruce Evans extern int (*legal_vif_num) __P((int)); 1681c5de19aSGarrett Wollman extern u_long (*ip_mcast_src) __P((int)); 169b124e4f2SGarrett Wollman extern int rsvp_on; 170df8bae1dSRodney W. Grimes 171df8bae1dSRodney W. Grimes int ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 172df8bae1dSRodney W. Grimes void ip_drain __P((void)); 173df8bae1dSRodney W. Grimes void ip_freemoptions __P((struct ip_moptions *)); 174df8bae1dSRodney W. Grimes void ip_init __P((void)); 1755e9ae478SGarrett Wollman extern int (*ip_mforward) __P((struct ip *, struct ifnet *, struct mbuf *, 176f0068c4aSGarrett Wollman struct ip_moptions *)); 177df8bae1dSRodney W. Grimes int ip_output __P((struct mbuf *, 178df8bae1dSRodney W. Grimes struct mbuf *, struct route *, int, struct ip_moptions *)); 179df8bae1dSRodney W. Grimes void ip_slowtimo __P((void)); 180df8bae1dSRodney W. Grimes struct mbuf * 181df8bae1dSRodney W. Grimes ip_srcroute __P((void)); 182df8bae1dSRodney W. Grimes void ip_stripoptions __P((struct mbuf *, struct mbuf *)); 183df8bae1dSRodney W. Grimes int rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 184df8bae1dSRodney W. Grimes void rip_init __P((void)); 185e62b8c49SBill Fenner void rip_input __P((struct mbuf *, int)); 186df8bae1dSRodney W. Grimes int rip_output __P((struct mbuf *, struct socket *, u_long)); 187df8bae1dSRodney W. Grimes int rip_usrreq __P((struct socket *, 188df8bae1dSRodney W. Grimes int, struct mbuf *, struct mbuf *, struct mbuf *)); 189e62b8c49SBill Fenner void ipip_input __P((struct mbuf *, int)); 190e62b8c49SBill Fenner void rsvp_input __P((struct mbuf *, int)); 191c178994dSPoul-Henning Kamp int ip_rsvp_init __P((struct socket *)); 192c178994dSPoul-Henning Kamp int ip_rsvp_done __P((void)); 193e9ce2e7dSDavid Greenman int ip_rsvp_vif_init __P((struct socket *, struct mbuf *)); 194e9ce2e7dSDavid Greenman int ip_rsvp_vif_done __P((struct socket *, struct mbuf *)); 195e9ce2e7dSDavid Greenman void ip_rsvp_force_done __P((struct socket *)); 196d99c7a23SGarrett Wollman 19793e0e116SJulian Elischer #ifdef IPDIVERT 19893e0e116SJulian Elischer void div_init __P((void)); 19993e0e116SJulian Elischer void div_input __P((struct mbuf *, int)); 20093e0e116SJulian Elischer int div_usrreq __P((struct socket *, 20193e0e116SJulian Elischer int, struct mbuf *, struct mbuf *, struct mbuf *)); 20293e0e116SJulian Elischer extern u_short ip_divert_port; 20393e0e116SJulian Elischer extern u_short ip_divert_ignore; 20493e0e116SJulian Elischer #endif /* IPDIVERT */ 20593e0e116SJulian Elischer 20693e0e116SJulian Elischer #endif /* KERNEL */ 207707f139eSPaul Richards 2085e26bd9aSBruce Evans #endif /* _NETINET_IP_VAR_H_ */ 209