blob: 4065fb83d258d472d1c664b025340829da903fc1 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*************************************************************
2*
3* This Software is the property of VIA Telecom, Inc. and may only be used pursuant to a license from VIA Telecom, Inc.
4*
5* Any unauthorized use inconsistent with the terms of such license is strictly prohibited.
6*
7* Copyright (c) 2002-2010 VIA Telecom, Inc. All rights reserved.
8*
9*************************************************************/
10/*************************************************************************
11 *
12 * File Name: ip.h
13 * Project: TCP/IP
14 *
15 * Original Author: Steve Pye
16 * Creation Date: Based on PVCS Rev 1.1 (15 Apr 1998)
17 *
18 * Description: IP Data Structures
19 * Restrictions:
20 * Dependencies:
21 *
22 ************************************************************************/
23
24#ifndef _IP_H_
25#define _IP_H_ 1
26
27#include "IP_TYPE.H"
28
29
30/* IP Protocol Types */
31
32#define IP_ICMP 1 /* IP control message protocol */
33#define IP_ICMPv6 58
34#define IP_TCP 6 /* transmission control protocol */
35#define IP_UDP 17 /* user datagram protocol */
36
37/*
38 * Address families.
39 */
40#define AF_UNSPEC 0 /* unspecified */
41#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
42#define AF_INET6 28 /* IPv6 */
43
44/* Note that ip_len and ip_off are declared to be signed integers rather
45 than unsigned since unsigned comparisons can result during arithmetic
46 operations of unsigned and signed integers. Such comparisons can fail
47 in subtle ways. */
48
49
50/* IP datagram identifier field fragmentation bit flags. Note that these
51 bit masks can be applied only after the field has been converted to
52 HOST-ENDIAN format. */
53
54#define IP_DF 0x4000 /* dont fragment bit flag */
55#define IP_MF 0x2000 /* more fragments bit flag */
56
57
58/* IP constant sizes */
59
60#define IP_ADDRSIZE 4 /* IP dotted 4-tuple host address */
61#define IP_HEADERSIZE 20 /* default IP header size */
62#define IP_MAXHDRSIZE 60 /* max header + options size */
63#define IP_MAXDGMSIZE 576 /* default max header+options+data */
64#define IP_MAXPKTSIZE 65535 /* max header+options+data size */
65#define IP_EXTHDRSIZE 12 /* TCP/UDP extended header size */
66#define IP_EXTHDROFF 8 /* offset from start of IP header */
67
68
69/* IP addresses and masks. The masks are applied to IP addresses in
70 NET-endian format, yielding results also in NET-endian format. */
71
72#define IP_ANYADDR 0x00000000
73#define IP_ANYPORT 0x0000
74
75#if HOST_ENDIAN == NET_ENDIAN
76
77#define IP_BROADCAST_ADDR 0xFFFFFFFFUL
78#define IP_OLD_BROADCAST 0x00000000UL
79#define IP_LOOPBACK_ADDR 0x7F000001UL
80#define IP_CLASSA_MASK 0x80000000UL
81#define IP_CLASSB_MASK 0xC0000000UL
82#define IP_CLASSC_MASK 0xE0000000UL
83#define IP_CLASSA_BITS 0x00000000UL
84#define IP_CLASSB_BITS 0x80000000UL
85#define IP_CLASSC_BITS 0xC0000000UL
86#define IP_CLASSA_NET 0xFF000000UL
87#define IP_CLASSB_NET 0xFFFF0000UL
88#define IP_CLASSC_NET 0xFFFFFF00UL
89#define IP_CLASSA_HOST 0x00FFFFFFUL
90#define IP_CLASSB_HOST 0x0000FFFFUL
91#define IP_CLASSC_HOST 0x000000FFUL
92
93#else /* HOST_ENDIAN == LITTLE_ENDIAN */
94
95#define IP_BROADCAST_ADDR 0xFFFFFFFFUL
96#define IP_OLD_BROADCAST 0x00000000UL
97#define IP_LOOPBACK_ADDR 0x0100007FUL
98#define IP_CLASSA_MASK 0x00000080UL
99#define IP_CLASSB_MASK 0x000000C0UL
100#define IP_CLASSC_MASK 0x000000E0UL
101#define IP_CLASSA_BITS 0x00000000UL
102#define IP_CLASSB_BITS 0x00000080UL
103#define IP_CLASSC_BITS 0x000000C0UL
104#define IP_CLASSA_NET 0x000000FFUL
105#define IP_CLASSB_NET 0x0000FFFFUL
106#define IP_CLASSC_NET 0x00FFFFFFUL
107#define IP_CLASSA_HOST 0xFFFFFF00UL
108#define IP_CLASSB_HOST 0xFFFF0000UL
109#define IP_CLASSC_HOST 0xFF000000UL
110#endif
111
112
113/* IP address class macros */
114
115#define IP_CLASSA_ADDR( a ) \
116((((kal_uint32)(a))&IP_CLASSA_MASK)==IP_CLASSA_BITS)
117
118#define IP_CLASSB_ADDR( a ) \
119((((kal_uint32)(a))&IP_CLASSB_MASK)==IP_CLASSB_BITS)
120
121#define IP_CLASSC_ADDR( a ) \
122((((kal_uint32)(a))&IP_CLASSC_MASK)==IP_CLASSC_BITS)
123
124
125/* IP Version Number */
126
127#define IP_VERSION 4
128
129
130/* IP Type-of-Service */
131
132#define IPTOS_LOWDELAY 0x10
133#define IPTOS_THROUGHPUT 0x08
134#define IPTOS_RELIABILITY 0x04
135
136
137/* IP Type-of-Service Precedence Fields (usually unused)*/
138
139#define IPTOS_NETCONTROL 0xE0
140#define IPTOS_INETCONTROL 0xC0
141#define IPTOS_CRITIC_ECP 0xA0
142#define IPTOS_FLASHOVERRIDE 0x80
143#define IPTOS_FLASH 0x60
144#define IPTOS_IMMEDIATE 0x40
145#define IPTOS_PRIORITY 0x20
146#define IPTOS_ROUTINE 0x10
147
148
149/* IP Option Types */
150
151#define IPOPT_EOL 0 /* end of option list */
152#define IPOPT_NOP 1 /* no operation */
153#define IPOPT_RR 7 /* record packet route */
154#define IPOPT_TS 68 /* timestamp */
155#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
156#define IPOPT_LSRR 131 /* loose source route */
157#define IPOPT_SATID 136 /* satnet id */
158#define IPOPT_SSRR 137 /* strict source route */
159
160
161/* IP Multi-Byte Option Format */
162
163#define IPOPT_HEADERSIZE 3 /* option header size */
164#define IPOPT_TYPE 0 /* option type field offset */
165#define IPOPT_LEN 1 /* option length field offset */
166#define IPOPT_OFF 2 /* option pointer field offset */
167
168#define IPOPT_MINOFF 4 /* pointer field is offset from */
169 /* start of option + 1 */
170
171#define IP_MAXOPTSIZE 40 /* max IP header options */
172#define IPOPT_MAXROUTEHOPS ((IP_MAXOPTSIZE-IPOPT_HEADERSIZE)/IP_ADDRSIZE)
173
174
175/* IP Implementation Parameters */
176
177#define IP_MAXTTL 255 /* maximum time-to-live (seconds) */
178#define IP_FRAGTTL 60 /* time-to-live for fragments */
179
180
181/* IP Source Port Selection Boundaries */
182#define IP_MINSPORT 0x1000
183#define IP_MAXSPORT 0xffff
184
185
186/* IP Checksum Structure */
187
188union ip_checksum
189 {
190 kal_uint32 u;
191 kal_uint16 w[2];
192 };
193
194
195/* IP Header */
196
197struct ip_header
198 {
199 kal_uint8 hlen; /* [7:3] version [3:0] header len */
200 kal_uint8 tos; /* type-of-service */
201 kal_uint16 len; /* total length */
202 kal_uint16 id; /* datagram identifier */
203 kal_uint16 off; /* fragment offset */
204 kal_uint8 ttl; /* time-to-live */
205 kal_uint8 pro; /* higher-level protocol id */
206 kal_uint16 chk; /* header checksum */
207 kal_uint32 src; /* source host address */
208 kal_uint32 dst; /* destination host address */
209 };
210
211
212/* IP source route descriptor */
213
214struct ip_srcroute
215 {
216 kal_uint32 addr;
217 kal_uint32 nhops;
218 kal_uint8 nop;
219 kal_uint8 opt[ IPOPT_HEADERSIZE ];
220 kal_uint32 list[ IPOPT_MAXROUTEHOPS ];
221 };
222
223
224#endif /* _IP_H_ */
225
226