Home | History | Annotate | Line # | Download | only in netinet
ip_var.h revision 1.36
      1 /*	$NetBSD: ip_var.h,v 1.36 1998/10/08 01:41:46 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)ip_var.h	8.2 (Berkeley) 1/9/95
     36  */
     37 
     38 #ifndef _NETINET_IP_VAR_H_
     39 #define _NETINET_IP_VAR_H_
     40 
     41 #include <sys/queue.h>
     42 #include <net/route.h>
     43 
     44 /*
     45  * Overlay for ip header used by other protocols (tcp, udp).
     46  */
     47 struct ipovly {
     48 	u_int8_t  ih_x1[9];		/* (unused) */
     49 	u_int8_t  ih_pr;		/* protocol */
     50 	u_int16_t ih_len;		/* protocol length */
     51 	struct	  in_addr ih_src;	/* source internet address */
     52 	struct	  in_addr ih_dst;	/* destination internet address */
     53 };
     54 
     55 /*
     56  * Ip (reassembly or sequence) queue structures.
     57  *
     58  * XXX -- The following explains why the ipqe_m field is here, for TCP's use:
     59  * We want to avoid doing m_pullup on incoming packets but that
     60  * means avoiding dtom on the tcp reassembly code.  That in turn means
     61  * keeping an mbuf pointer in the reassembly queue (since we might
     62  * have a cluster).  As a quick hack, the source & destination
     63  * port numbers (which are no longer needed once we've located the
     64  * tcpcb) are overlayed with an mbuf pointer.
     65  */
     66 LIST_HEAD(ipqehead, ipqent);
     67 struct ipqent {
     68 	LIST_ENTRY(ipqent) ipqe_q;
     69 	union {
     70 		struct ip	*_ip;
     71 		struct tcpiphdr *_tcp;
     72 	} _ipqe_u1;
     73 	struct mbuf	*ipqe_m;	/* mbuf contains packet */
     74 	u_int8_t	ipqe_mff;	/* for IP fragmentation */
     75 	/*
     76 	 * The following are used in TCP reassembly
     77 	 */
     78 	LIST_ENTRY(ipqent) ipqe_timeq;
     79 	u_int32_t ipqe_seq;
     80 	u_int32_t ipqe_len;
     81 	u_int32_t ipqe_flags;
     82 };
     83 #define	ipqe_ip		_ipqe_u1._ip
     84 #define	ipqe_tcp	_ipqe_u1._tcp
     85 
     86 /*
     87  * Ip reassembly queue structure.  Each fragment
     88  * being reassembled is attached to one of these structures.
     89  * They are timed out after ipq_ttl drops to 0, and may also
     90  * be reclaimed if memory becomes tight.
     91  */
     92 struct ipq {
     93 	LIST_ENTRY(ipq) ipq_q;		/* to other reass headers */
     94 	u_int8_t  ipq_ttl;		/* time for reass q to live */
     95 	u_int8_t  ipq_p;		/* protocol of this fragment */
     96 	u_int16_t ipq_id;		/* sequence id for reassembly */
     97 	struct	  ipqehead ipq_fragq;	/* to ip fragment queue */
     98 	struct	  in_addr ipq_src, ipq_dst;
     99 };
    100 
    101 /*
    102  * Structure stored in mbuf in inpcb.ip_options
    103  * and passed to ip_output when ip options are in use.
    104  * The actual length of the options (including ipopt_dst)
    105  * is in m_len.
    106  */
    107 #define	MAX_IPOPTLEN	40
    108 
    109 struct ipoption {
    110 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
    111 	int8_t	ipopt_list[MAX_IPOPTLEN];	/* options proper */
    112 };
    113 
    114 /*
    115  * Structure attached to inpcb.ip_moptions and
    116  * passed to ip_output when IP multicast options are in use.
    117  */
    118 struct ip_moptions {
    119 	struct	  ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
    120 	u_int8_t  imo_multicast_ttl;	/* TTL for outgoing multicasts */
    121 	u_int8_t  imo_multicast_loop;	/* 1 => hear sends if a member */
    122 	u_int16_t imo_num_memberships;	/* no. memberships this socket */
    123 	struct	  in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
    124 };
    125 
    126 struct	ipstat {
    127 	u_long	ips_total;		/* total packets received */
    128 	u_long	ips_badsum;		/* checksum bad */
    129 	u_long	ips_tooshort;		/* packet too short */
    130 	u_long	ips_toosmall;		/* not enough data */
    131 	u_long	ips_badhlen;		/* ip header length < data size */
    132 	u_long	ips_badlen;		/* ip length < ip header length */
    133 	u_long	ips_fragments;		/* fragments received */
    134 	u_long	ips_fragdropped;	/* frags dropped (dups, out of space) */
    135 	u_long	ips_fragtimeout;	/* fragments timed out */
    136 	u_long	ips_forward;		/* packets forwarded */
    137 	u_long	ips_fastforward;	/* packets fast forwarded */
    138 	u_long	ips_cantforward;	/* packets rcvd for unreachable dest */
    139 	u_long	ips_redirectsent;	/* packets forwarded on same net */
    140 	u_long	ips_noproto;		/* unknown or unsupported protocol */
    141 	u_long	ips_delivered;		/* datagrams delivered to upper level*/
    142 	u_long	ips_localout;		/* total ip packets generated here */
    143 	u_long	ips_odropped;		/* lost packets due to nobufs, etc. */
    144 	u_long	ips_reassembled;	/* total packets reassembled ok */
    145 	u_long	ips_fragmented;		/* datagrams sucessfully fragmented */
    146 	u_long	ips_ofragments;		/* output fragments created */
    147 	u_long	ips_cantfrag;		/* don't fragment flag was set, etc. */
    148 	u_long	ips_badoptions;		/* error in option processing */
    149 	u_long	ips_noroute;		/* packets discarded due to no route */
    150 	u_long	ips_badvers;		/* ip version != 4 */
    151 	u_long	ips_rawout;		/* total raw ip packets generated */
    152 	u_long	ips_badfrags;		/* malformed fragments (bad length) */
    153 	u_long	ips_rcvmemdrop;		/* frags dropped for lack of memory */
    154 	u_long	ips_toolong;		/* ip length > max ip packet size */
    155 };
    156 
    157 #define	IPFLOW_HASHBITS			6 /* should not be a multiple of 8 */
    158 struct ipflow {
    159 	LIST_ENTRY(ipflow) ipf_list;	/* next in active list */
    160 	LIST_ENTRY(ipflow) ipf_hash;	/* next ipflow in bucket */
    161 	struct in_addr ipf_dst;		/* destination address */
    162 	struct in_addr ipf_src;		/* source address */
    163 	u_int8_t ipf_tos;		/* type-of-service */
    164 	struct route ipf_ro;		/* associated route entry */
    165 	u_long ipf_uses;		/* number of uses in this period */
    166 	u_long ipf_last_uses;		/* number of uses in last period */
    167 	u_long ipf_dropped;		/* ENOBUFS returned by if_output */
    168 	u_long ipf_errors;		/* other errors returned by if_output */
    169 	u_int ipf_timer;		/* lifetime timer */
    170 	time_t ipf_start;		/* creation time */
    171 };
    172 
    173 #ifdef _KERNEL
    174 /* flags passed to ip_output as last parameter */
    175 #define	IP_FORWARDING		0x1		/* most of ip header exists */
    176 #define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
    177 #define	IP_RETURNMTU		0x4		/* pass back mtu on EMSGSIZE */
    178 #define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
    179 #define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
    180 
    181 extern struct ipstat ipstat;		/* ip statistics */
    182 extern LIST_HEAD(ipqhead, ipq) ipq;	/* ip reass. queue */
    183 extern u_int16_t ip_id;			/* ip packet ctr, for ids */
    184 extern int   ip_defttl;			/* default IP ttl */
    185 extern int   ipforwarding;		/* ip forwarding */
    186 extern int   ip_mtudisc;		/* mtu discovery */
    187 extern u_int ip_mtudisc_timeout;	/* seconds to timeout mtu discovery */
    188 extern int   anonportmin;		/* minimum ephemeral port */
    189 extern int   anonportmax;		/* maximum ephemeral port */
    190 extern struct rttimer_queue *ip_mtudisc_timeout_q;
    191 #ifdef GATEWAY
    192 extern int ip_maxflows;
    193 #endif
    194 extern struct pool ipqent_pool;
    195 struct	 inpcb;
    196 
    197 int	 ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
    198 int	 ip_dooptions __P((struct mbuf *));
    199 void	 ip_drain __P((void));
    200 void	 ip_forward __P((struct mbuf *, int));
    201 void	 ip_freef __P((struct ipq *));
    202 void	 ip_freemoptions __P((struct ip_moptions *));
    203 int	 ip_getmoptions __P((int, struct ip_moptions *, struct mbuf **));
    204 void	 ip_init __P((void));
    205 int	 ip_mforward __P((struct mbuf *, struct ifnet *));
    206 int	 ip_optcopy __P((struct ip *, struct ip *));
    207 u_int	 ip_optlen __P((struct inpcb *));
    208 int	 ip_output __P((struct mbuf *, ...));
    209 int	 ip_pcbopts __P((struct mbuf **, struct mbuf *));
    210 struct mbuf *
    211 	 ip_reass __P((struct ipqent *, struct ipq *));
    212 struct in_ifaddr *
    213 	 ip_rtaddr __P((struct in_addr));
    214 void	 ip_savecontrol __P((struct inpcb *, struct mbuf **, struct ip *,
    215 	   struct mbuf *));
    216 int	 ip_setmoptions __P((int, struct ip_moptions **, struct mbuf *));
    217 void	 ip_slowtimo __P((void));
    218 struct mbuf *
    219 	 ip_srcroute __P((void));
    220 void	 ip_stripoptions __P((struct mbuf *, struct mbuf *));
    221 int	 ip_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
    222 void	 ipintr __P((void));
    223 int	 rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
    224 void	 rip_init __P((void));
    225 void	 rip_input __P((struct mbuf *, ...));
    226 int	 rip_output __P((struct mbuf *, ...));
    227 int	 rip_usrreq __P((struct socket *,
    228 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *));
    229 void	ipflow_init __P((void));
    230 struct	ipflow *ipflow_reap __P((int));
    231 void	ipflow_create __P((const struct route *, struct mbuf *));
    232 void	ipflow_slowtimo __P((void));
    233 #endif
    234 
    235 #endif /* _NETINET_IP_VAR_H_ */
    236