ip_var.h revision 98663
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1982, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3310942Swollman *	@(#)ip_var.h	8.2 (Berkeley) 1/9/95
3450477Speter * $FreeBSD: head/sys/netinet/ip_var.h 98663 2002-06-23 09:03:42Z luigi $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_IP_VAR_H_
3818940Sbde#define	_NETINET_IP_VAR_H_
392169Spaul
4078064Sume#include <sys/queue.h>
4178064Sume
421541Srgrimes/*
431541Srgrimes * Overlay for ip header used by other protocols (tcp, udp).
441541Srgrimes */
451541Srgrimesstruct ipovly {
4638513Sdfr	u_char	ih_x1[9];		/* (unused) */
471541Srgrimes	u_char	ih_pr;			/* protocol */
4819183Sfenner	u_short	ih_len;			/* protocol length */
491541Srgrimes	struct	in_addr ih_src;		/* source internet address */
501541Srgrimes	struct	in_addr ih_dst;		/* destination internet address */
511541Srgrimes};
521541Srgrimes
531541Srgrimes/*
541541Srgrimes * Ip reassembly queue structure.  Each fragment
551541Srgrimes * being reassembled is attached to one of these structures.
561541Srgrimes * They are timed out after ipq_ttl drops to 0, and may also
571541Srgrimes * be reclaimed if memory becomes tight.
581541Srgrimes */
591541Srgrimesstruct ipq {
6074362Sphk	TAILQ_ENTRY(ipq) ipq_list;	/* to other reass headers */
611541Srgrimes	u_char	ipq_ttl;		/* time for reass q to live */
621541Srgrimes	u_char	ipq_p;			/* protocol of this fragment */
631541Srgrimes	u_short	ipq_id;			/* sequence id for reassembly */
6438513Sdfr	struct mbuf *ipq_frags;		/* to ip headers of fragments */
651541Srgrimes	struct	in_addr ipq_src,ipq_dst;
6617072Sjulian#ifdef IPDIVERT
6754175Sarchie	u_int32_t ipq_div_info;		/* ipfw divert port & flags */
6854175Sarchie	u_int16_t ipq_div_cookie;	/* ipfw divert cookie */
6917072Sjulian#endif
701541Srgrimes};
711541Srgrimes
721541Srgrimes/*
731541Srgrimes * Structure stored in mbuf in inpcb.ip_options
741541Srgrimes * and passed to ip_output when ip options are in use.
751541Srgrimes * The actual length of the options (including ipopt_dst)
761541Srgrimes * is in m_len.
771541Srgrimes */
781541Srgrimes#define MAX_IPOPTLEN	40
791541Srgrimes
801541Srgrimesstruct ipoption {
811541Srgrimes	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
821541Srgrimes	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
831541Srgrimes};
841541Srgrimes
851541Srgrimes/*
861541Srgrimes * Structure attached to inpcb.ip_moptions and
871541Srgrimes * passed to ip_output when IP multicast options are in use.
881541Srgrimes */
891541Srgrimesstruct ip_moptions {
901541Srgrimes	struct	ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
9178064Sume	struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
921541Srgrimes	u_char	imo_multicast_ttl;	/* TTL for outgoing multicasts */
931541Srgrimes	u_char	imo_multicast_loop;	/* 1 => hear sends if a member */
941541Srgrimes	u_short	imo_num_memberships;	/* no. memberships this socket */
951541Srgrimes	struct	in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
969209Swollman	u_long	imo_multicast_vif;	/* vif num outgoing multicasts */
971541Srgrimes};
981541Srgrimes
991541Srgrimesstruct	ipstat {
1001541Srgrimes	u_long	ips_total;		/* total packets received */
1011541Srgrimes	u_long	ips_badsum;		/* checksum bad */
1021541Srgrimes	u_long	ips_tooshort;		/* packet too short */
1031541Srgrimes	u_long	ips_toosmall;		/* not enough data */
1041541Srgrimes	u_long	ips_badhlen;		/* ip header length < data size */
1051541Srgrimes	u_long	ips_badlen;		/* ip length < ip header length */
1061541Srgrimes	u_long	ips_fragments;		/* fragments received */
1071541Srgrimes	u_long	ips_fragdropped;	/* frags dropped (dups, out of space) */
1081541Srgrimes	u_long	ips_fragtimeout;	/* fragments timed out */
1091541Srgrimes	u_long	ips_forward;		/* packets forwarded */
11036192Sdg	u_long	ips_fastforward;	/* packets fast forwarded */
1111541Srgrimes	u_long	ips_cantforward;	/* packets rcvd for unreachable dest */
1121541Srgrimes	u_long	ips_redirectsent;	/* packets forwarded on same net */
1131541Srgrimes	u_long	ips_noproto;		/* unknown or unsupported protocol */
1141541Srgrimes	u_long	ips_delivered;		/* datagrams delivered to upper level*/
1151541Srgrimes	u_long	ips_localout;		/* total ip packets generated here */
1161541Srgrimes	u_long	ips_odropped;		/* lost packets due to nobufs, etc. */
1171541Srgrimes	u_long	ips_reassembled;	/* total packets reassembled ok */
11813765Smpp	u_long	ips_fragmented;		/* datagrams successfully fragmented */
1191541Srgrimes	u_long	ips_ofragments;		/* output fragments created */
1201541Srgrimes	u_long	ips_cantfrag;		/* don't fragment flag was set, etc. */
1211541Srgrimes	u_long	ips_badoptions;		/* error in option processing */
1221541Srgrimes	u_long	ips_noroute;		/* packets discarded due to no route */
1231541Srgrimes	u_long	ips_badvers;		/* ip version != 4 */
1241541Srgrimes	u_long	ips_rawout;		/* total raw ip packets generated */
12519183Sfenner	u_long	ips_toolong;		/* ip length > max ip packet size */
12621932Swollman	u_long	ips_notmember;		/* multicasts for unregistered grps */
12752904Sshin	u_long	ips_nogif;		/* no match gif found */
12878064Sume	u_long	ips_badaddr;		/* invalid address on header */
1291541Srgrimes};
1301541Srgrimes
13155205Speter#ifdef _KERNEL
13237625Sbde
1331541Srgrimes/* flags passed to ip_output as last parameter */
1341541Srgrimes#define	IP_FORWARDING		0x1		/* most of ip header exists */
1351541Srgrimes#define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
1361541Srgrimes#define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
1371541Srgrimes#define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
1381541Srgrimes
13938482Swollmanstruct ip;
14019669Sbdestruct inpcb;
14118940Sbdestruct route;
14238482Swollmanstruct sockopt;
14318940Sbde
1442112Swollmanextern struct	ipstat	ipstat;
14577574Skris#ifndef RANDOM_IP_ID
1462112Swollmanextern u_short	ip_id;				/* ip packet ctr, for ids */
14777574Skris#endif
1482112Swollmanextern int	ip_defttl;			/* default IP ttl */
14936192Sdgextern int	ipforwarding;			/* ip forwarding */
15074454Sruextern struct route ipforward_rt;		/* ip forwarding cached route */
1517090Sbdeextern u_char	ip_protox[];
1522531Swollmanextern struct socket *ip_rsvpd;	/* reservation protocol daemon */
1532531Swollmanextern struct socket *ip_mrouter; /* multicast routing daemon */
15492723Salfredextern int	(*legal_vif_num)(int);
15592723Salfredextern u_long	(*ip_mcast_src)(int);
1569728Swollmanextern int rsvp_on;
15722900Swollmanextern struct	pr_usrreqs rip_usrreqs;
1581541Srgrimes
15992723Salfredint	 ip_ctloutput(struct socket *, struct sockopt *sopt);
16092723Salfredvoid	 ip_drain(void);
16192723Salfredvoid	 ip_freemoptions(struct ip_moptions *);
16292723Salfredvoid	 ip_init(void);
16392723Salfredextern int	 (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
16492723Salfred			  struct ip_moptions *);
16592723Salfredint	 ip_output(struct mbuf *,
16692723Salfred	    struct mbuf *, struct route *, int, struct ip_moptions *);
16787120Srustruct in_ifaddr *
16892723Salfred	 ip_rtaddr(struct in_addr, struct route *);
16992723Salfredvoid	 ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
17092723Salfred		struct mbuf *);
17192723Salfredvoid	 ip_slowtimo(void);
1721541Srgrimesstruct mbuf *
17392723Salfred	 ip_srcroute(void);
17492723Salfredvoid	 ip_stripoptions(struct mbuf *, struct mbuf *);
17577574Skris#ifdef RANDOM_IP_ID
17677574Skrisu_int16_t
17792723Salfred	 ip_randomid(void);
17877574Skris#endif
17998663Sluigiint	rip_ctloutput(struct socket *, struct sockopt *);
18098663Sluigivoid	rip_ctlinput(int, struct sockaddr *, void *);
18198663Sluigivoid	rip_init(void);
18298663Sluigivoid	rip_input(struct mbuf *, int);
18398663Sluigiint	rip_output(struct mbuf *, struct socket *, u_long);
18492723Salfredvoid	ipip_input(struct mbuf *, int);
18592723Salfredvoid	rsvp_input(struct mbuf *, int);
18692723Salfredint	ip_rsvp_init(struct socket *);
18792723Salfredint	ip_rsvp_done(void);
18892723Salfredint	ip_rsvp_vif_init(struct socket *, struct sockopt *);
18992723Salfredint	ip_rsvp_vif_done(struct socket *, struct sockopt *);
19092723Salfredvoid	ip_rsvp_force_done(struct socket *);
1917083Swollman
19217072Sjulian#ifdef IPDIVERT
19392723Salfredvoid	div_init(void);
19492723Salfredvoid	div_input(struct mbuf *, int);
19598613Sluigivoid	divert_packet(struct mbuf *m, int incoming, int port, int rule);
19626113Speterextern struct pr_usrreqs div_usrreqs;
19737625Sbde#endif
1982169Spaul
19960765Sjlemonvoid	in_delayed_cksum(struct mbuf *m);
20060765Sjlemon
20155205Speter#endif /* _KERNEL */
20217072Sjulian
20337625Sbde#endif /* !_NETINET_IP_VAR_H_ */
204