| /************************************************************* |
| * |
| * This Software is the property of VIA Telecom, Inc. and may only be used pursuant to a license from VIA Telecom, Inc. |
| * |
| * Any unauthorized use inconsistent with the terms of such license is strictly prohibited. |
| * |
| * Copyright (c) 2002-2010 VIA Telecom, Inc. All rights reserved. |
| * |
| *************************************************************/ |
| /************************************************************************* |
| * |
| * File Name: ip.h |
| * Project: TCP/IP |
| * |
| * Original Author: Steve Pye |
| * Creation Date: Based on PVCS Rev 1.1 (15 Apr 1998) |
| * |
| * Description: IP Data Structures |
| * Restrictions: |
| * Dependencies: |
| * |
| ************************************************************************/ |
| |
| #ifndef _IP_H_ |
| #define _IP_H_ 1 |
| |
| #include "IP_TYPE.H" |
| |
| |
| /* IP Protocol Types */ |
| |
| #define IP_ICMP 1 /* IP control message protocol */ |
| #define IP_ICMPv6 58 |
| #define IP_TCP 6 /* transmission control protocol */ |
| #define IP_UDP 17 /* user datagram protocol */ |
| |
| /* |
| * Address families. |
| */ |
| #define AF_UNSPEC 0 /* unspecified */ |
| #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ |
| #define AF_INET6 28 /* IPv6 */ |
| |
| /* Note that ip_len and ip_off are declared to be signed integers rather |
| than unsigned since unsigned comparisons can result during arithmetic |
| operations of unsigned and signed integers. Such comparisons can fail |
| in subtle ways. */ |
| |
| |
| /* IP datagram identifier field fragmentation bit flags. Note that these |
| bit masks can be applied only after the field has been converted to |
| HOST-ENDIAN format. */ |
| |
| #define IP_DF 0x4000 /* dont fragment bit flag */ |
| #define IP_MF 0x2000 /* more fragments bit flag */ |
| |
| |
| /* IP constant sizes */ |
| |
| #define IP_ADDRSIZE 4 /* IP dotted 4-tuple host address */ |
| #define IP_HEADERSIZE 20 /* default IP header size */ |
| #define IP_MAXHDRSIZE 60 /* max header + options size */ |
| #define IP_MAXDGMSIZE 576 /* default max header+options+data */ |
| #define IP_MAXPKTSIZE 65535 /* max header+options+data size */ |
| #define IP_EXTHDRSIZE 12 /* TCP/UDP extended header size */ |
| #define IP_EXTHDROFF 8 /* offset from start of IP header */ |
| |
| |
| /* IP addresses and masks. The masks are applied to IP addresses in |
| NET-endian format, yielding results also in NET-endian format. */ |
| |
| #define IP_ANYADDR 0x00000000 |
| #define IP_ANYPORT 0x0000 |
| |
| #if HOST_ENDIAN == NET_ENDIAN |
| |
| #define IP_BROADCAST_ADDR 0xFFFFFFFFUL |
| #define IP_OLD_BROADCAST 0x00000000UL |
| #define IP_LOOPBACK_ADDR 0x7F000001UL |
| #define IP_CLASSA_MASK 0x80000000UL |
| #define IP_CLASSB_MASK 0xC0000000UL |
| #define IP_CLASSC_MASK 0xE0000000UL |
| #define IP_CLASSA_BITS 0x00000000UL |
| #define IP_CLASSB_BITS 0x80000000UL |
| #define IP_CLASSC_BITS 0xC0000000UL |
| #define IP_CLASSA_NET 0xFF000000UL |
| #define IP_CLASSB_NET 0xFFFF0000UL |
| #define IP_CLASSC_NET 0xFFFFFF00UL |
| #define IP_CLASSA_HOST 0x00FFFFFFUL |
| #define IP_CLASSB_HOST 0x0000FFFFUL |
| #define IP_CLASSC_HOST 0x000000FFUL |
| |
| #else /* HOST_ENDIAN == LITTLE_ENDIAN */ |
| |
| #define IP_BROADCAST_ADDR 0xFFFFFFFFUL |
| #define IP_OLD_BROADCAST 0x00000000UL |
| #define IP_LOOPBACK_ADDR 0x0100007FUL |
| #define IP_CLASSA_MASK 0x00000080UL |
| #define IP_CLASSB_MASK 0x000000C0UL |
| #define IP_CLASSC_MASK 0x000000E0UL |
| #define IP_CLASSA_BITS 0x00000000UL |
| #define IP_CLASSB_BITS 0x00000080UL |
| #define IP_CLASSC_BITS 0x000000C0UL |
| #define IP_CLASSA_NET 0x000000FFUL |
| #define IP_CLASSB_NET 0x0000FFFFUL |
| #define IP_CLASSC_NET 0x00FFFFFFUL |
| #define IP_CLASSA_HOST 0xFFFFFF00UL |
| #define IP_CLASSB_HOST 0xFFFF0000UL |
| #define IP_CLASSC_HOST 0xFF000000UL |
| #endif |
| |
| |
| /* IP address class macros */ |
| |
| #define IP_CLASSA_ADDR( a ) \ |
| ((((kal_uint32)(a))&IP_CLASSA_MASK)==IP_CLASSA_BITS) |
| |
| #define IP_CLASSB_ADDR( a ) \ |
| ((((kal_uint32)(a))&IP_CLASSB_MASK)==IP_CLASSB_BITS) |
| |
| #define IP_CLASSC_ADDR( a ) \ |
| ((((kal_uint32)(a))&IP_CLASSC_MASK)==IP_CLASSC_BITS) |
| |
| |
| /* IP Version Number */ |
| |
| #define IP_VERSION 4 |
| |
| |
| /* IP Type-of-Service */ |
| |
| #define IPTOS_LOWDELAY 0x10 |
| #define IPTOS_THROUGHPUT 0x08 |
| #define IPTOS_RELIABILITY 0x04 |
| |
| |
| /* IP Type-of-Service Precedence Fields (usually unused)*/ |
| |
| #define IPTOS_NETCONTROL 0xE0 |
| #define IPTOS_INETCONTROL 0xC0 |
| #define IPTOS_CRITIC_ECP 0xA0 |
| #define IPTOS_FLASHOVERRIDE 0x80 |
| #define IPTOS_FLASH 0x60 |
| #define IPTOS_IMMEDIATE 0x40 |
| #define IPTOS_PRIORITY 0x20 |
| #define IPTOS_ROUTINE 0x10 |
| |
| |
| /* IP Option Types */ |
| |
| #define IPOPT_EOL 0 /* end of option list */ |
| #define IPOPT_NOP 1 /* no operation */ |
| #define IPOPT_RR 7 /* record packet route */ |
| #define IPOPT_TS 68 /* timestamp */ |
| #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ |
| #define IPOPT_LSRR 131 /* loose source route */ |
| #define IPOPT_SATID 136 /* satnet id */ |
| #define IPOPT_SSRR 137 /* strict source route */ |
| |
| |
| /* IP Multi-Byte Option Format */ |
| |
| #define IPOPT_HEADERSIZE 3 /* option header size */ |
| #define IPOPT_TYPE 0 /* option type field offset */ |
| #define IPOPT_LEN 1 /* option length field offset */ |
| #define IPOPT_OFF 2 /* option pointer field offset */ |
| |
| #define IPOPT_MINOFF 4 /* pointer field is offset from */ |
| /* start of option + 1 */ |
| |
| #define IP_MAXOPTSIZE 40 /* max IP header options */ |
| #define IPOPT_MAXROUTEHOPS ((IP_MAXOPTSIZE-IPOPT_HEADERSIZE)/IP_ADDRSIZE) |
| |
| |
| /* IP Implementation Parameters */ |
| |
| #define IP_MAXTTL 255 /* maximum time-to-live (seconds) */ |
| #define IP_FRAGTTL 60 /* time-to-live for fragments */ |
| |
| |
| /* IP Source Port Selection Boundaries */ |
| #define IP_MINSPORT 0x1000 |
| #define IP_MAXSPORT 0xffff |
| |
| |
| /* IP Checksum Structure */ |
| |
| union ip_checksum |
| { |
| kal_uint32 u; |
| kal_uint16 w[2]; |
| }; |
| |
| |
| /* IP Header */ |
| |
| struct ip_header |
| { |
| kal_uint8 hlen; /* [7:3] version [3:0] header len */ |
| kal_uint8 tos; /* type-of-service */ |
| kal_uint16 len; /* total length */ |
| kal_uint16 id; /* datagram identifier */ |
| kal_uint16 off; /* fragment offset */ |
| kal_uint8 ttl; /* time-to-live */ |
| kal_uint8 pro; /* higher-level protocol id */ |
| kal_uint16 chk; /* header checksum */ |
| kal_uint32 src; /* source host address */ |
| kal_uint32 dst; /* destination host address */ |
| }; |
| |
| |
| /* IP source route descriptor */ |
| |
| struct ip_srcroute |
| { |
| kal_uint32 addr; |
| kal_uint32 nhops; |
| kal_uint8 nop; |
| kal_uint8 opt[ IPOPT_HEADERSIZE ]; |
| kal_uint32 list[ IPOPT_MAXROUTEHOPS ]; |
| }; |
| |
| |
| #endif /* _IP_H_ */ |
| |
| |