xref: /csrg-svn/sys/netinet/ip_var.h (revision 68170)
123185Smckusick /*
263218Sbostic  * Copyright (c) 1982, 1986, 1993
363218Sbostic  *	The Regents of the University of California.  All rights reserved.
423185Smckusick  *
544482Sbostic  * %sccs.include.redist.c%
632787Sbostic  *
7*68170Scgd  *	@(#)ip_var.h	8.2 (Berkeley) 01/09/95
823185Smckusick  */
94893Swnj 
104893Swnj /*
114893Swnj  * Overlay for ip header used by other protocols (tcp, udp).
124893Swnj  */
134893Swnj struct ipovly {
144899Swnj 	caddr_t	ih_next, ih_prev;	/* for protocol sequence q's */
154899Swnj 	u_char	ih_x1;			/* (unused) */
164899Swnj 	u_char	ih_pr;			/* protocol */
174924Swnj 	short	ih_len;			/* protocol length */
184924Swnj 	struct	in_addr ih_src;		/* source internet address */
194924Swnj 	struct	in_addr ih_dst;		/* destination internet address */
204893Swnj };
214893Swnj 
224893Swnj /*
234893Swnj  * Ip reassembly queue structure.  Each fragment
244893Swnj  * being reassembled is attached to one of these structures.
254893Swnj  * They are timed out after ipq_ttl drops to 0, and may also
264893Swnj  * be reclaimed if memory becomes tight.
274893Swnj  */
284893Swnj struct ipq {
294893Swnj 	struct	ipq *next,*prev;	/* to other reass headers */
304893Swnj 	u_char	ipq_ttl;		/* time for reass q to live */
314893Swnj 	u_char	ipq_p;			/* protocol of this fragment */
324893Swnj 	u_short	ipq_id;			/* sequence id for reassembly */
334893Swnj 	struct	ipasfrag *ipq_next,*ipq_prev;
344893Swnj 					/* to ip headers of fragments */
354924Swnj 	struct	in_addr ipq_src,ipq_dst;
364893Swnj };
374893Swnj 
384893Swnj /*
394893Swnj  * Ip header, when holding a fragment.
409185Ssam  *
419185Ssam  * Note: ipf_next must be at same offset as ipq_next above
424893Swnj  */
434893Swnj struct	ipasfrag {
4433283Skarels #if BYTE_ORDER == LITTLE_ENDIAN
454893Swnj 	u_char	ip_hl:4,
464893Swnj 		ip_v:4;
479992Ssam #endif
4833283Skarels #if BYTE_ORDER == BIG_ENDIAN
4929923Skarels 	u_char	ip_v:4,
5029923Skarels 		ip_hl:4;
5129923Skarels #endif
5257965Sandrew 	u_char	ipf_mff;		/* XXX overlays ip_tos: use low bit
5357965Sandrew 					 * to avoid destroying tos;
5457965Sandrew 					 * copied from (ip_off&IP_MF) */
554893Swnj 	short	ip_len;
564893Swnj 	u_short	ip_id;
574893Swnj 	short	ip_off;
584893Swnj 	u_char	ip_ttl;
594893Swnj 	u_char	ip_p;
604893Swnj 	u_short	ip_sum;
614899Swnj 	struct	ipasfrag *ipf_next;	/* next fragment */
624899Swnj 	struct	ipasfrag *ipf_prev;	/* previous fragment */
634893Swnj };
644893Swnj 
6524815Skarels /*
6624815Skarels  * Structure stored in mbuf in inpcb.ip_options
6724815Skarels  * and passed to ip_output when ip options are in use.
6824815Skarels  * The actual length of the options (including ipopt_dst)
6924815Skarels  * is in m_len.
7024815Skarels  */
7124815Skarels #define MAX_IPOPTLEN	40
7224815Skarels 
7324815Skarels struct ipoption {
7424815Skarels 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
7524815Skarels 	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
7624815Skarels };
7724815Skarels 
7854716Ssklower /*
7954716Ssklower  * Structure attached to inpcb.ip_moptions and
8054716Ssklower  * passed to ip_output when IP multicast options are in use.
8154716Ssklower  */
8254716Ssklower struct ip_moptions {
8354716Ssklower 	struct	ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
8454716Ssklower 	u_char	imo_multicast_ttl;	/* TTL for outgoing multicasts */
8554716Ssklower 	u_char	imo_multicast_loop;	/* 1 => hear sends if a member */
8654716Ssklower 	u_short	imo_num_memberships;	/* no. memberships this socket */
8754716Ssklower 	struct	in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
8854716Ssklower };
8954716Ssklower 
904924Swnj struct	ipstat {
9157433Sandrew 	u_long	ips_total;		/* total packets received */
9257433Sandrew 	u_long	ips_badsum;		/* checksum bad */
9357433Sandrew 	u_long	ips_tooshort;		/* packet too short */
9457433Sandrew 	u_long	ips_toosmall;		/* not enough data */
9557433Sandrew 	u_long	ips_badhlen;		/* ip header length < data size */
9657433Sandrew 	u_long	ips_badlen;		/* ip length < ip header length */
9757433Sandrew 	u_long	ips_fragments;		/* fragments received */
9857433Sandrew 	u_long	ips_fragdropped;	/* frags dropped (dups, out of space) */
9957433Sandrew 	u_long	ips_fragtimeout;	/* fragments timed out */
10057433Sandrew 	u_long	ips_forward;		/* packets forwarded */
10157433Sandrew 	u_long	ips_cantforward;	/* packets rcvd for unreachable dest */
10257433Sandrew 	u_long	ips_redirectsent;	/* packets forwarded on same net */
10357433Sandrew 	u_long	ips_noproto;		/* unknown or unsupported protocol */
10457433Sandrew 	u_long	ips_delivered;		/* datagrams delivered to upper level*/
10557433Sandrew 	u_long	ips_localout;		/* total ip packets generated here */
10657433Sandrew 	u_long	ips_odropped;		/* lost packets due to nobufs, etc. */
10757433Sandrew 	u_long	ips_reassembled;	/* total packets reassembled ok */
10857433Sandrew 	u_long	ips_fragmented;		/* datagrams sucessfully fragmented */
10957433Sandrew 	u_long	ips_ofragments;		/* output fragments created */
11057433Sandrew 	u_long	ips_cantfrag;		/* don't fragment flag was set, etc. */
11157433Sandrew 	u_long	ips_badoptions;		/* error in option processing */
11257965Sandrew 	u_long	ips_noroute;		/* packets discarded due to no route */
11357965Sandrew 	u_long	ips_badvers;		/* ip version != 4 */
11457965Sandrew 	u_long	ips_rawout;		/* total raw ip packets generated */
1154924Swnj };
1164924Swnj 
1174893Swnj #ifdef KERNEL
11812418Ssam /* flags passed to ip_output as last parameter */
11917051Skarels #define	IP_FORWARDING		0x1		/* most of ip header exists */
12057965Sandrew #define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
12117051Skarels #define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
12217051Skarels #define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
12312418Ssam 
1244924Swnj struct	ipstat	ipstat;
1254893Swnj struct	ipq	ipq;			/* ip reass. queue */
1264893Swnj u_short	ip_id;				/* ip packet ctr, for ids */
12759130Smckusick int	ip_defttl;			/* default IP ttl */
12824815Skarels 
129*68170Scgd int	 in_control __P((struct socket *, u_long, caddr_t, struct ifnet *));
13061335Sbostic int	 ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
13161335Sbostic void	 ip_deq __P((struct ipasfrag *));
13261335Sbostic int	 ip_dooptions __P((struct mbuf *));
13361335Sbostic void	 ip_drain __P((void));
13461335Sbostic void	 ip_enq __P((struct ipasfrag *, struct ipasfrag *));
13561335Sbostic void	 ip_forward __P((struct mbuf *, int));
13661335Sbostic void	 ip_freef __P((struct ipq *));
13761335Sbostic void	 ip_freemoptions __P((struct ip_moptions *));
13861335Sbostic int	 ip_getmoptions __P((int, struct ip_moptions *, struct mbuf **));
13961335Sbostic void	 ip_init __P((void));
14061335Sbostic int	 ip_mforward __P((struct mbuf *, struct ifnet *));
14161335Sbostic int	 ip_optcopy __P((struct ip *, struct ip *));
14261335Sbostic int	 ip_output __P((struct mbuf *,
14361335Sbostic 	    struct mbuf *, struct route *, int, struct ip_moptions *));
14461335Sbostic int	 ip_pcbopts __P((struct mbuf **, struct mbuf *));
14561335Sbostic struct ip *
14661335Sbostic 	 ip_reass __P((struct ipasfrag *, struct ipq *));
14761335Sbostic struct in_ifaddr *
14861335Sbostic 	 ip_rtaddr __P((struct in_addr));
14961335Sbostic int	 ip_setmoptions __P((int, struct ip_moptions **, struct mbuf *));
15061335Sbostic void	 ip_slowtimo __P((void));
15161335Sbostic struct mbuf *
15261335Sbostic 	 ip_srcroute __P((void));
15361335Sbostic void	 ip_stripoptions __P((struct mbuf *, struct mbuf *));
15461335Sbostic int	 ip_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
15561335Sbostic void	 ipintr __P((void));
15661335Sbostic int	 rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
15761335Sbostic void	 rip_init __P((void));
15861335Sbostic void	 rip_input __P((struct mbuf *));
15961335Sbostic int	 rip_output __P((struct mbuf *, struct socket *, u_long));
16061335Sbostic int	 rip_usrreq __P((struct socket *,
16161335Sbostic 	    int, struct mbuf *, struct mbuf *, struct mbuf *));
1624893Swnj #endif
163