Home | History | Annotate | Line # | Download | only in netinet
ip_var.h revision 1.93
      1  1.93     rmind /*	$NetBSD: ip_var.h,v 1.93 2010/07/19 14:09:45 rmind Exp $	*/
      2  1.10       cgd 
      3   1.1       cgd /*
      4   1.9   mycroft  * Copyright (c) 1982, 1986, 1993
      5   1.9   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15  1.57       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  *
     31  1.24   thorpej  *	@(#)ip_var.h	8.2 (Berkeley) 1/9/95
     32   1.1       cgd  */
     33   1.1       cgd 
     34  1.25     perry #ifndef _NETINET_IP_VAR_H_
     35  1.25     perry #define _NETINET_IP_VAR_H_
     36  1.53    martin 
     37  1.15       cgd #include <sys/queue.h>
     38  1.30   thorpej #include <net/route.h>
     39  1.15       cgd 
     40   1.1       cgd /*
     41   1.1       cgd  * Overlay for ip header used by other protocols (tcp, udp).
     42   1.1       cgd  */
     43   1.1       cgd struct ipovly {
     44  1.18   thorpej 	u_int8_t  ih_x1[9];		/* (unused) */
     45  1.18   thorpej 	u_int8_t  ih_pr;		/* protocol */
     46  1.18   thorpej 	u_int16_t ih_len;		/* protocol length */
     47  1.18   thorpej 	struct	  in_addr ih_src;	/* source internet address */
     48  1.18   thorpej 	struct	  in_addr ih_dst;	/* destination internet address */
     49  1.83     perry } __packed;
     50   1.1       cgd 
     51  1.93     rmind #ifdef _KERNEL
     52  1.93     rmind 
     53   1.1       cgd /*
     54  1.15       cgd  * Ip (reassembly or sequence) queue structures.
     55  1.15       cgd  *
     56  1.15       cgd  * XXX -- The following explains why the ipqe_m field is here, for TCP's use:
     57  1.15       cgd  * We want to avoid doing m_pullup on incoming packets but that
     58  1.15       cgd  * means avoiding dtom on the tcp reassembly code.  That in turn means
     59  1.15       cgd  * keeping an mbuf pointer in the reassembly queue (since we might
     60  1.15       cgd  * have a cluster).  As a quick hack, the source & destination
     61  1.15       cgd  * port numbers (which are no longer needed once we've located the
     62  1.15       cgd  * tcpcb) are overlayed with an mbuf pointer.
     63  1.15       cgd  */
     64  1.47      matt TAILQ_HEAD(ipqehead, ipqent);
     65  1.15       cgd struct ipqent {
     66  1.47      matt 	TAILQ_ENTRY(ipqent) ipqe_q;
     67  1.15       cgd 	union {
     68  1.15       cgd 		struct ip	*_ip;
     69  1.15       cgd 		struct tcpiphdr *_tcp;
     70  1.15       cgd 	} _ipqe_u1;
     71  1.47      matt 	struct mbuf	*ipqe_m;	/* point to first mbuf */
     72  1.47      matt 	struct mbuf	*ipre_mlast;	/* point to last mbuf */
     73  1.20   thorpej 	u_int8_t	ipqe_mff;	/* for IP fragmentation */
     74  1.28      matt 	/*
     75  1.28      matt 	 * The following are used in TCP reassembly
     76  1.28      matt 	 */
     77  1.47      matt 	TAILQ_ENTRY(ipqent) ipqe_timeq;
     78  1.28      matt 	u_int32_t ipqe_seq;
     79  1.28      matt 	u_int32_t ipqe_len;
     80  1.28      matt 	u_int32_t ipqe_flags;
     81  1.15       cgd };
     82  1.15       cgd #define	ipqe_ip		_ipqe_u1._ip
     83  1.15       cgd #define	ipqe_tcp	_ipqe_u1._tcp
     84  1.15       cgd 
     85  1.93     rmind #endif  /* _KERNEL */
     86   1.1       cgd 
     87   1.1       cgd /*
     88   1.1       cgd  * Structure stored in mbuf in inpcb.ip_options
     89   1.1       cgd  * and passed to ip_output when ip options are in use.
     90   1.1       cgd  * The actual length of the options (including ipopt_dst)
     91   1.1       cgd  * is in m_len.
     92   1.1       cgd  */
     93   1.5   mycroft #define	MAX_IPOPTLEN	40
     94   1.1       cgd 
     95   1.1       cgd struct ipoption {
     96   1.1       cgd 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
     97  1.12       cgd 	int8_t	ipopt_list[MAX_IPOPTLEN];	/* options proper */
     98   1.1       cgd };
     99   1.1       cgd 
    100   1.4   hpeyerl /*
    101   1.4   hpeyerl  * Structure attached to inpcb.ip_moptions and
    102   1.4   hpeyerl  * passed to ip_output when IP multicast options are in use.
    103   1.4   hpeyerl  */
    104   1.4   hpeyerl struct ip_moptions {
    105  1.12       cgd 	struct	  ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
    106  1.44    itojun 	struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
    107  1.12       cgd 	u_int8_t  imo_multicast_ttl;	/* TTL for outgoing multicasts */
    108  1.12       cgd 	u_int8_t  imo_multicast_loop;	/* 1 => hear sends if a member */
    109  1.12       cgd 	u_int16_t imo_num_memberships;	/* no. memberships this socket */
    110  1.12       cgd 	struct	  in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
    111   1.4   hpeyerl };
    112   1.4   hpeyerl 
    113  1.85   thorpej /*
    114  1.85   thorpej  * IP statistics.
    115  1.85   thorpej  * Each counter is an unsigned 64-bit value.
    116  1.85   thorpej  */
    117  1.85   thorpej #define	IP_STAT_TOTAL		0	/* total packets received */
    118  1.85   thorpej #define	IP_STAT_BADSUM		1	/* checksum bad */
    119  1.85   thorpej #define	IP_STAT_TOOSHORT	2	/* packet too short */
    120  1.85   thorpej #define	IP_STAT_TOOSMALL	3	/* not enough data */
    121  1.85   thorpej #define	IP_STAT_BADHLEN		4	/* ip header length < data size */
    122  1.85   thorpej #define	IP_STAT_BADLEN		5	/* ip length < ip header length */
    123  1.85   thorpej #define	IP_STAT_FRAGMENTS	6	/* fragments received */
    124  1.85   thorpej #define	IP_STAT_FRAGDROPPED	7	/* frags dropped (dups, out of space) */
    125  1.85   thorpej #define	IP_STAT_FRAGTIMEOUT	8	/* fragments timed out */
    126  1.85   thorpej #define	IP_STAT_FORWARD		9	/* packets forwarded */
    127  1.85   thorpej #define	IP_STAT_FASTFORWARD	10	/* packets fast forwarded */
    128  1.85   thorpej #define	IP_STAT_CANTFORWARD	11	/* packets rcvd for unreachable dest */
    129  1.85   thorpej #define	IP_STAT_REDIRECTSENT	12	/* packets forwareded on same net */
    130  1.85   thorpej #define	IP_STAT_NOPROTO		13	/* unknown or unsupported protocol */
    131  1.85   thorpej #define	IP_STAT_DELIVERED	14	/* datagrams delivered to upper level */
    132  1.85   thorpej #define	IP_STAT_LOCALOUT	15	/* total ip packets generated here */
    133  1.85   thorpej #define	IP_STAT_ODROPPED	16	/* lost packets due to nobufs, etc. */
    134  1.85   thorpej #define	IP_STAT_REASSEMBLED	17	/* total packets reassembled ok */
    135  1.85   thorpej #define	IP_STAT_FRAGMENTED	18	/* datagrams successfully fragmented */
    136  1.85   thorpej #define	IP_STAT_OFRAGMENTS	19	/* output fragments created */
    137  1.85   thorpej #define	IP_STAT_CANTFRAG	20	/* don't fragment flag was set, etc. */
    138  1.85   thorpej #define	IP_STAT_BADOPTIONS	21	/* error in option processing */
    139  1.85   thorpej #define	IP_STAT_NOROUTE		22	/* packets discarded due to no route */
    140  1.85   thorpej #define	IP_STAT_BADVERS		23	/* ip version != 4 */
    141  1.85   thorpej #define	IP_STAT_RAWOUT		24	/* total raw ip packets generated */
    142  1.85   thorpej #define	IP_STAT_BADFRAGS	25	/* malformed fragments (bad length) */
    143  1.85   thorpej #define	IP_STAT_RCVMEMDROP	26	/* frags dropped for lack of memory */
    144  1.85   thorpej #define	IP_STAT_TOOLONG		27	/* ip length > max ip packet size */
    145  1.85   thorpej #define	IP_STAT_NOGIF		28	/* no match gif found */
    146  1.85   thorpej #define	IP_STAT_BADADDR		29	/* invalid address on header */
    147  1.85   thorpej 
    148  1.85   thorpej #define	IP_NSTATS		30
    149   1.1       cgd 
    150  1.11       jtc #ifdef _KERNEL
    151  1.54    martin 
    152  1.54    martin #ifdef _KERNEL_OPT
    153  1.54    martin #include "opt_gateway.h"
    154  1.54    martin #include "opt_mbuftrace.h"
    155  1.54    martin #endif
    156  1.54    martin 
    157   1.1       cgd /* flags passed to ip_output as last parameter */
    158   1.1       cgd #define	IP_FORWARDING		0x1		/* most of ip header exists */
    159   1.9   mycroft #define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
    160  1.21   thorpej #define	IP_RETURNMTU		0x4		/* pass back mtu on EMSGSIZE */
    161  1.84      matt #define	IP_NOIPNEWID		0x8		/* don't fill in ip_id */
    162   1.1       cgd #define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
    163   1.1       cgd #define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
    164  1.43   thorpej #define	IP_MTUDISC		0x0400		/* Path MTU Discovery; set DF */
    165  1.48   thorpej 
    166  1.68      matt extern struct domain inetdomain;
    167  1.68      matt 
    168  1.63  jonathan extern LIST_HEAD(ipqhead, ipq) ipq[];	/* ip reass. queue */
    169  1.29      matt extern int   ip_defttl;			/* default IP ttl */
    170  1.29      matt extern int   ipforwarding;		/* ip forwarding */
    171  1.27       kml extern int   ip_mtudisc;		/* mtu discovery */
    172  1.49    itojun extern int   ip_mtudisc_timeout;	/* seconds to timeout mtu discovery */
    173  1.27       kml extern int   anonportmin;		/* minimum ephemeral port */
    174  1.27       kml extern int   anonportmax;		/* maximum ephemeral port */
    175  1.42      tron extern int   lowportmin;		/* minimum reserved port */
    176  1.42      tron extern int   lowportmax;		/* maximum reserved port */
    177  1.69   thorpej extern int   ip_do_loopback_cksum;	/* do IP checksum on loopback? */
    178  1.27       kml extern struct rttimer_queue *ip_mtudisc_timeout_q;
    179  1.51      matt #ifdef MBUFTRACE
    180  1.51      matt extern struct mowner ip_rx_mowner;
    181  1.51      matt extern struct mowner ip_tx_mowner;
    182  1.51      matt #endif
    183  1.31      matt #ifdef GATEWAY
    184  1.31      matt extern int ip_maxflows;
    185  1.79  liamjfoy extern int ip_hashsize;
    186  1.31      matt #endif
    187  1.52      matt extern struct pool inmulti_pool;
    188  1.19   thorpej struct	 inpcb;
    189  1.88    plunky struct   sockopt;
    190  1.19   thorpej 
    191  1.88    plunky int	 ip_ctloutput(int, struct socket *, struct sockopt *);
    192  1.67    itojun int	 ip_dooptions(struct mbuf *);
    193  1.67    itojun void	 ip_drain(void);
    194  1.67    itojun void	 ip_forward(struct mbuf *, int);
    195  1.67    itojun void	 ip_freemoptions(struct ip_moptions *);
    196  1.88    plunky int	 ip_getmoptions(struct ip_moptions *, struct sockopt *);
    197  1.67    itojun void	 ip_init(void);
    198  1.67    itojun int	 ip_optcopy(struct ip *, struct ip *);
    199  1.67    itojun u_int	 ip_optlen(struct inpcb *);
    200  1.67    itojun int	 ip_output(struct mbuf *, ...);
    201  1.67    itojun int	 ip_fragment(struct mbuf *, struct ifnet *, u_long);
    202  1.90    plunky int	 ip_pcbopts(struct mbuf **, const struct sockopt *);
    203  1.92     rmind 
    204  1.93     rmind void	 ip_reass_init(void);
    205  1.93     rmind int	 ip_reass_packet(struct mbuf *, struct ip *, bool, struct mbuf **);
    206  1.92     rmind void	 ip_reass_slowtimo(void);
    207  1.92     rmind void	 ip_reass_drain(void);
    208  1.92     rmind 
    209   1.6   mycroft struct in_ifaddr *
    210  1.67    itojun 	 ip_rtaddr(struct in_addr);
    211  1.67    itojun void	 ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
    212  1.66      matt 	   struct mbuf *);
    213  1.89    plunky int	 ip_setmoptions(struct ip_moptions **, const struct sockopt *);
    214  1.67    itojun void	 ip_slowtimo(void);
    215   1.6   mycroft struct mbuf *
    216  1.67    itojun 	 ip_srcroute(void);
    217  1.67    itojun int	 ip_sysctl(int *, u_int, void *, size_t *, void *, size_t);
    218  1.87   thorpej void	 ip_statinc(u_int);
    219  1.67    itojun void	 ipintr(void);
    220  1.78    dyoung void *	 rip_ctlinput(int, const struct sockaddr *, void *);
    221  1.88    plunky int	 rip_ctloutput(int, struct socket *, struct sockopt *);
    222  1.67    itojun void	 rip_init(void);
    223  1.67    itojun void	 rip_input(struct mbuf *, ...);
    224  1.67    itojun int	 rip_output(struct mbuf *, ...);
    225  1.67    itojun int	 rip_usrreq(struct socket *,
    226  1.75  christos 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
    227  1.79  liamjfoy int	ipflow_init(int);
    228  1.91     pooka void	ipflow_poolinit(void);
    229  1.86   thorpej void	ipflow_prune(void);
    230  1.67    itojun void	ipflow_create(const struct route *, struct mbuf *);
    231  1.67    itojun void	ipflow_slowtimo(void);
    232  1.79  liamjfoy int	ipflow_invalidate_all(int);
    233  1.59    itojun 
    234  1.60  jonathan #endif  /* _KERNEL */
    235  1.25     perry 
    236  1.74      elad #endif /* !_NETINET_IP_VAR_H_ */
    237