xref: /illumos-gate/usr/src/stand/lib/inet/ipv4_impl.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  *
26*7c478bd9Sstevel@tonic-gate  * Internal IPv4 implementation-specific definitions
27*7c478bd9Sstevel@tonic-gate  */
29*7c478bd9Sstevel@tonic-gate #ifndef _IPV4_IMPL_H
30*7c478bd9Sstevel@tonic-gate #define	_IPV4_IMPL_H
32*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
34*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
35*7c478bd9Sstevel@tonic-gate extern "C" {
36*7c478bd9Sstevel@tonic-gate #endif
38*7c478bd9Sstevel@tonic-gate #define	FRAG_MAX	(40)	/* max number of IP fragments per datagram */
39*7c478bd9Sstevel@tonic-gate #define	FRAG_SUCCESS	(0)	/* datagram reassembled ok */
40*7c478bd9Sstevel@tonic-gate #define	FRAG_DUP	(1)	/* duplicate ip fragment */
41*7c478bd9Sstevel@tonic-gate #define	FRAG_NOSLOTS	(2)	/* no more ip fragment slots */
42*7c478bd9Sstevel@tonic-gate #define	FRAG_ATTEMPTS	1	/* Try twice to get all the fragments */
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * IP fragmentation data structure
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate struct ip_frag {
48*7c478bd9Sstevel@tonic-gate 	int16_t		more;	/* Fragment bit (TRUE == MF, FALSE == No more */
49*7c478bd9Sstevel@tonic-gate 	int16_t		offset;	/* Offset within the encapsulated datagram */
50*7c478bd9Sstevel@tonic-gate 	mblk_t		*mp;	/* Fragment including IP header */
51*7c478bd9Sstevel@tonic-gate 	uint16_t	ipid;	/* fragment ident */
52*7c478bd9Sstevel@tonic-gate 	int16_t		iplen;	/* IP datagram's length */
53*7c478bd9Sstevel@tonic-gate 	int16_t		iphlen;	/* Len of IP header */
54*7c478bd9Sstevel@tonic-gate 	uint8_t		ipp;	/* IP protocol */
55*7c478bd9Sstevel@tonic-gate };
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * true offset is in 8 octet units. The high order 3 bits of the IP header
59*7c478bd9Sstevel@tonic-gate  * offset field are therefore used for fragmentation flags. Shift these
60*7c478bd9Sstevel@tonic-gate  * bits off to produce the true offset. The high order flag bit is unused
61*7c478bd9Sstevel@tonic-gate  * (what would be considered the sign bit). Still, we cast the callers
62*7c478bd9Sstevel@tonic-gate  * value as an unsigned quantity to ensure it is treated as positive.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate #define	IPV4_OFFSET(a)	((uint16_t)(a) << 3)
66*7c478bd9Sstevel@tonic-gate #define	IPV4_VERSION	4
67*7c478bd9Sstevel@tonic-gate #define	IPH_HDR_LENGTH(iph)	(((struct ip *)(iph))->ip_hl << 2)
69*7c478bd9Sstevel@tonic-gate /* ECN code points for IPv4 TOS byte and IPv6 traffic class octet. */
70*7c478bd9Sstevel@tonic-gate #define	IPH_ECN_NECT	0x0	/* Not ECN-Capabable Transport */
71*7c478bd9Sstevel@tonic-gate #define	IPH_ECN_ECT1	0x1	/* ECN-Capable Transport, ECT(1) */
72*7c478bd9Sstevel@tonic-gate #define	IPH_ECN_ECT0	0x2	/* ECN-Capable Transport, ECT(0) */
73*7c478bd9Sstevel@tonic-gate #define	IPH_ECN_CE	0x3	/* ECN-Congestion Experienced (CE) */
75*7c478bd9Sstevel@tonic-gate #define	IPV4_VERSION			4
76*7c478bd9Sstevel@tonic-gate #define	IP_VERSION			IPV4_VERSION
77*7c478bd9Sstevel@tonic-gate #define	IP_SIMPLE_HDR_LENGTH_IN_WORDS	5
78*7c478bd9Sstevel@tonic-gate #define	IP_SIMPLE_HDR_LENGTH		20
79*7c478bd9Sstevel@tonic-gate #define	IP_MAX_HDR_LENGTH		60
81*7c478bd9Sstevel@tonic-gate #define	IP_MIN_MTU			(IP_MAX_HDR_LENGTH + 8)	/* 68 bytes */
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate  * IP routing table. IP addresses are in network-order.
85*7c478bd9Sstevel@tonic-gate  */
86*7c478bd9Sstevel@tonic-gate struct routing {
87*7c478bd9Sstevel@tonic-gate 	struct in_addr	dest;
88*7c478bd9Sstevel@tonic-gate 	struct in_addr	gateway;
89*7c478bd9Sstevel@tonic-gate 	uint8_t		flag;
90*7c478bd9Sstevel@tonic-gate };
92*7c478bd9Sstevel@tonic-gate extern void		ipv4_raw_socket(struct inetboot_socket *, uint8_t);
93*7c478bd9Sstevel@tonic-gate extern void		ipv4_socket_init(struct inetboot_socket *);
94*7c478bd9Sstevel@tonic-gate extern int		ipv4_header_len(struct inetgram *);
95*7c478bd9Sstevel@tonic-gate extern int		ipv4_input(int);
96*7c478bd9Sstevel@tonic-gate extern int		ipv4_output(int, struct inetgram *);
97*7c478bd9Sstevel@tonic-gate extern int		ipv4_tcp_output(int, mblk_t *);
98*7c478bd9Sstevel@tonic-gate extern struct in_addr	*ipv4_get_route(uint8_t, struct in_addr *,
99*7c478bd9Sstevel@tonic-gate 			    struct in_addr *);
101*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate #endif
105*7c478bd9Sstevel@tonic-gate #endif /* _IPV4_IMPL_H */