Home | History | Annotate | Line # | Download | only in netinet
ip_var.h revision 1.129
      1  1.129     ozaki /*	$NetBSD: ip_var.h,v 1.129 2020/08/28 06:19:13 ozaki-r 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.1       cgd /*
     52   1.99  liamjfoy  * IP Flow structure
     53   1.99  liamjfoy  */
     54   1.99  liamjfoy struct ipflow {
     55  1.115  knakahar 	TAILQ_ENTRY(ipflow) ipf_list;	/* next in active list */
     56  1.115  knakahar 	TAILQ_ENTRY(ipflow) ipf_hash;	/* next ipflow in bucket */
     57  1.115  knakahar 	size_t ipf_hashidx;		/* own hash index of ipflowtable[] */
     58   1.99  liamjfoy 	struct in_addr ipf_dst;		/* destination address */
     59   1.99  liamjfoy 	struct in_addr ipf_src;		/* source address */
     60   1.99  liamjfoy 	uint8_t ipf_tos;		/* type-of-service */
     61   1.99  liamjfoy 	struct route ipf_ro;		/* associated route entry */
     62   1.99  liamjfoy 	u_long ipf_uses;		/* number of uses in this period */
     63   1.99  liamjfoy 	u_long ipf_last_uses;		/* number of uses in last period */
     64   1.99  liamjfoy 	u_long ipf_dropped;		/* ENOBUFS retured by if_output */
     65   1.99  liamjfoy 	u_long ipf_errors;		/* other errors returned by if_output */
     66   1.99  liamjfoy 	u_int ipf_timer;		/* lifetime timer */
     67   1.99  liamjfoy };
     68   1.99  liamjfoy 
     69   1.99  liamjfoy /*
     70  1.124      maxv  * TCP sequence queue structure.
     71   1.15       cgd  */
     72   1.47      matt TAILQ_HEAD(ipqehead, ipqent);
     73   1.15       cgd struct ipqent {
     74   1.47      matt 	TAILQ_ENTRY(ipqent) ipqe_q;
     75  1.125      maxv 	struct mbuf *ipqe_m;
     76   1.47      matt 	TAILQ_ENTRY(ipqent) ipqe_timeq;
     77   1.28      matt 	u_int32_t ipqe_seq;
     78   1.28      matt 	u_int32_t ipqe_len;
     79   1.28      matt 	u_int32_t ipqe_flags;
     80   1.15       cgd };
     81   1.15       cgd 
     82    1.1       cgd /*
     83    1.1       cgd  * Structure stored in mbuf in inpcb.ip_options
     84    1.1       cgd  * and passed to ip_output when ip options are in use.
     85    1.1       cgd  * The actual length of the options (including ipopt_dst)
     86    1.1       cgd  * is in m_len.
     87    1.1       cgd  */
     88    1.5   mycroft #define	MAX_IPOPTLEN	40
     89    1.1       cgd 
     90    1.1       cgd struct ipoption {
     91    1.1       cgd 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
     92   1.12       cgd 	int8_t	ipopt_list[MAX_IPOPTLEN];	/* options proper */
     93    1.1       cgd };
     94    1.1       cgd 
     95    1.4   hpeyerl /*
     96    1.4   hpeyerl  * Structure attached to inpcb.ip_moptions and
     97    1.4   hpeyerl  * passed to ip_output when IP multicast options are in use.
     98    1.4   hpeyerl  */
     99    1.4   hpeyerl struct ip_moptions {
    100  1.114     ozaki 	if_index_t imo_multicast_if_index; /* I/F for outgoing multicasts */
    101   1.44    itojun 	struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
    102   1.12       cgd 	u_int8_t  imo_multicast_ttl;	/* TTL for outgoing multicasts */
    103   1.12       cgd 	u_int8_t  imo_multicast_loop;	/* 1 => hear sends if a member */
    104   1.12       cgd 	u_int16_t imo_num_memberships;	/* no. memberships this socket */
    105   1.12       cgd 	struct	  in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
    106    1.4   hpeyerl };
    107    1.4   hpeyerl 
    108  1.120       ryo struct ip_pktopts {
    109  1.120       ryo 	struct sockaddr_in ippo_laddr;	/* source address */
    110  1.120       ryo 	struct ip_moptions *ippo_imo;	/* inp->inp_moptions or &ippo_imobuf */
    111  1.120       ryo 	struct ip_moptions ippo_imobuf;	/* use when IP_PKTINFO */
    112  1.120       ryo };
    113  1.120       ryo 
    114   1.85   thorpej /*
    115   1.85   thorpej  * IP statistics.
    116   1.85   thorpej  * Each counter is an unsigned 64-bit value.
    117   1.85   thorpej  */
    118   1.85   thorpej #define	IP_STAT_TOTAL		0	/* total packets received */
    119   1.85   thorpej #define	IP_STAT_BADSUM		1	/* checksum bad */
    120   1.85   thorpej #define	IP_STAT_TOOSHORT	2	/* packet too short */
    121   1.85   thorpej #define	IP_STAT_TOOSMALL	3	/* not enough data */
    122   1.85   thorpej #define	IP_STAT_BADHLEN		4	/* ip header length < data size */
    123   1.85   thorpej #define	IP_STAT_BADLEN		5	/* ip length < ip header length */
    124   1.85   thorpej #define	IP_STAT_FRAGMENTS	6	/* fragments received */
    125   1.85   thorpej #define	IP_STAT_FRAGDROPPED	7	/* frags dropped (dups, out of space) */
    126   1.85   thorpej #define	IP_STAT_FRAGTIMEOUT	8	/* fragments timed out */
    127   1.85   thorpej #define	IP_STAT_FORWARD		9	/* packets forwarded */
    128   1.85   thorpej #define	IP_STAT_FASTFORWARD	10	/* packets fast forwarded */
    129   1.85   thorpej #define	IP_STAT_CANTFORWARD	11	/* packets rcvd for unreachable dest */
    130   1.85   thorpej #define	IP_STAT_REDIRECTSENT	12	/* packets forwareded on same net */
    131   1.85   thorpej #define	IP_STAT_NOPROTO		13	/* unknown or unsupported protocol */
    132   1.85   thorpej #define	IP_STAT_DELIVERED	14	/* datagrams delivered to upper level */
    133   1.85   thorpej #define	IP_STAT_LOCALOUT	15	/* total ip packets generated here */
    134   1.85   thorpej #define	IP_STAT_ODROPPED	16	/* lost packets due to nobufs, etc. */
    135   1.85   thorpej #define	IP_STAT_REASSEMBLED	17	/* total packets reassembled ok */
    136   1.85   thorpej #define	IP_STAT_FRAGMENTED	18	/* datagrams successfully fragmented */
    137   1.85   thorpej #define	IP_STAT_OFRAGMENTS	19	/* output fragments created */
    138   1.85   thorpej #define	IP_STAT_CANTFRAG	20	/* don't fragment flag was set, etc. */
    139   1.85   thorpej #define	IP_STAT_BADOPTIONS	21	/* error in option processing */
    140   1.85   thorpej #define	IP_STAT_NOROUTE		22	/* packets discarded due to no route */
    141   1.85   thorpej #define	IP_STAT_BADVERS		23	/* ip version != 4 */
    142   1.85   thorpej #define	IP_STAT_RAWOUT		24	/* total raw ip packets generated */
    143   1.85   thorpej #define	IP_STAT_BADFRAGS	25	/* malformed fragments (bad length) */
    144   1.85   thorpej #define	IP_STAT_RCVMEMDROP	26	/* frags dropped for lack of memory */
    145   1.85   thorpej #define	IP_STAT_TOOLONG		27	/* ip length > max ip packet size */
    146   1.85   thorpej #define	IP_STAT_NOGIF		28	/* no match gif found */
    147   1.85   thorpej #define	IP_STAT_BADADDR		29	/* invalid address on header */
    148  1.117  knakahar #define	IP_STAT_NOL2TP		30	/* no match l2tp found */
    149  1.122  knakahar #define	IP_STAT_NOIPSEC		31	/* no match ipsec(4) found */
    150  1.128     ozaki #define	IP_STAT_PFILDROP_IN	32	/* dropped by pfil (PFIL_IN) */
    151  1.128     ozaki #define	IP_STAT_PFILDROP_OUT	33	/* dropped by pfil (PFIL_OUT) */
    152  1.129     ozaki #define	IP_STAT_IPSECDROP_IN	34	/* dropped by IPsec SP check */
    153  1.129     ozaki #define	IP_STAT_IPSECDROP_OUT	35	/* dropped by IPsec SP check */
    154   1.85   thorpej 
    155  1.129     ozaki #define	IP_NSTATS		36
    156    1.1       cgd 
    157   1.11       jtc #ifdef _KERNEL
    158   1.54    martin 
    159   1.54    martin #ifdef _KERNEL_OPT
    160   1.54    martin #include "opt_gateway.h"
    161   1.54    martin #include "opt_mbuftrace.h"
    162   1.54    martin #endif
    163   1.54    martin 
    164  1.104     rmind /*
    165  1.104     rmind  * The following flags can be passed to ip_output() as last parameter
    166  1.104     rmind  */
    167  1.104     rmind #define	IP_FORWARDING		0x0001		/* most of ip header exists */
    168  1.104     rmind #define	IP_RAWOUTPUT		0x0002		/* raw ip header exists */
    169  1.104     rmind #define	IP_RETURNMTU		0x0004		/* pass back mtu on EMSGSIZE */
    170  1.104     rmind #define	IP_NOIPNEWID		0x0008		/* don't fill in ip_id */
    171  1.105     rmind __CTASSERT(SO_DONTROUTE ==	0x0010);
    172  1.105     rmind __CTASSERT(SO_BROADCAST ==	0x0020);
    173    1.1       cgd #define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
    174    1.1       cgd #define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
    175  1.104     rmind 
    176  1.104     rmind #define	IP_IGMP_MCAST		0x0040		/* IGMP for mcast join/leave */
    177   1.43   thorpej #define	IP_MTUDISC		0x0400		/* Path MTU Discovery; set DF */
    178  1.120       ryo #define	IP_ROUTETOIFINDEX	0x0800	/* force route imo_multicast_if_index */
    179   1.48   thorpej 
    180   1.68      matt extern struct domain inetdomain;
    181  1.100     rmind extern const struct pr_usrreqs rip_usrreqs;
    182   1.68      matt 
    183   1.29      matt extern int   ip_defttl;			/* default IP ttl */
    184   1.29      matt extern int   ipforwarding;		/* ip forwarding */
    185   1.27       kml extern int   ip_mtudisc;		/* mtu discovery */
    186   1.49    itojun extern int   ip_mtudisc_timeout;	/* seconds to timeout mtu discovery */
    187   1.27       kml extern int   anonportmin;		/* minimum ephemeral port */
    188   1.27       kml extern int   anonportmax;		/* maximum ephemeral port */
    189   1.42      tron extern int   lowportmin;		/* minimum reserved port */
    190   1.42      tron extern int   lowportmax;		/* maximum reserved port */
    191   1.69   thorpej extern int   ip_do_loopback_cksum;	/* do IP checksum on loopback? */
    192   1.27       kml extern struct rttimer_queue *ip_mtudisc_timeout_q;
    193   1.51      matt #ifdef MBUFTRACE
    194   1.51      matt extern struct mowner ip_rx_mowner;
    195   1.51      matt extern struct mowner ip_tx_mowner;
    196   1.51      matt #endif
    197   1.19   thorpej struct	 inpcb;
    198   1.88    plunky struct   sockopt;
    199   1.19   thorpej 
    200  1.101     rmind void	ip_init(void);
    201  1.101     rmind void	in_init(void);
    202  1.101     rmind 
    203   1.88    plunky int	 ip_ctloutput(int, struct socket *, struct sockopt *);
    204  1.120       ryo int	 ip_setpktopts(struct mbuf *, struct ip_pktopts *, int *,
    205  1.121       ryo 	    struct inpcb *, kauth_cred_t);
    206   1.67    itojun void	 ip_drain(void);
    207   1.97    dyoung void	 ip_drainstub(void);
    208   1.67    itojun void	 ip_freemoptions(struct ip_moptions *);
    209   1.67    itojun int	 ip_optcopy(struct ip *, struct ip *);
    210   1.67    itojun u_int	 ip_optlen(struct inpcb *);
    211  1.110  riastrad int	 ip_output(struct mbuf *, struct mbuf *, struct route *, int,
    212  1.118     ozaki 	    struct ip_moptions *, struct inpcb *);
    213   1.67    itojun int	 ip_fragment(struct mbuf *, struct ifnet *, u_long);
    214   1.92     rmind 
    215   1.93     rmind void	 ip_reass_init(void);
    216  1.126      maxv int	 ip_reass_packet(struct mbuf **);
    217   1.92     rmind void	 ip_reass_slowtimo(void);
    218   1.92     rmind void	 ip_reass_drain(void);
    219   1.92     rmind 
    220   1.67    itojun void	 ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
    221   1.66      matt 	   struct mbuf *);
    222   1.67    itojun void	 ip_slowtimo(void);
    223   1.97    dyoung void	 ip_fasttimo(void);
    224    1.6   mycroft struct mbuf *
    225  1.119     ozaki 	 ip_srcroute(struct mbuf *);
    226   1.67    itojun int	 ip_sysctl(int *, u_int, void *, size_t *, void *, size_t);
    227   1.87   thorpej void	 ip_statinc(u_int);
    228   1.78    dyoung void *	 rip_ctlinput(int, const struct sockaddr *, void *);
    229   1.88    plunky int	 rip_ctloutput(int, struct socket *, struct sockopt *);
    230   1.67    itojun void	 rip_init(void);
    231  1.127      maxv void	 rip_input(struct mbuf *, int, int);
    232  1.120       ryo int	 rip_output(struct mbuf *, struct inpcb *, struct mbuf *, struct lwp *);
    233   1.67    itojun int	 rip_usrreq(struct socket *,
    234   1.75  christos 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
    235  1.101     rmind 
    236  1.107  christos int	ip_setmoptions(struct ip_moptions **, const struct sockopt *sopt);
    237  1.107  christos int	ip_getmoptions(struct ip_moptions *, struct sockopt *sopt);
    238  1.107  christos 
    239  1.111     ozaki int	ip_if_output(struct ifnet * const, struct mbuf * const,
    240  1.112     ozaki 	    const struct sockaddr * const, const struct rtentry *);
    241  1.108     ozaki 
    242  1.101     rmind /* IP Flow interface. */
    243  1.101     rmind void	ipflow_init(void);
    244   1.91     pooka void	ipflow_poolinit(void);
    245  1.116     ozaki void	ipflow_create(struct route *, struct mbuf *);
    246   1.67    itojun void	ipflow_slowtimo(void);
    247   1.79  liamjfoy int	ipflow_invalidate_all(int);
    248   1.59    itojun 
    249   1.60  jonathan #endif  /* _KERNEL */
    250   1.25     perry 
    251   1.74      elad #endif /* !_NETINET_IP_VAR_H_ */
    252