1 /* 2 * Copyright (C) 1999-2009, Broadcom Corporation 3 * 4 * Unless you and Broadcom execute a separate written software license 5 * agreement governing use of this software, this software is licensed to you 6 * under the terms of the GNU General Public License version 2 (the "GPL"), 7 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 8 * following added to such license: 9 * 10 * As a special exception, the copyright holders of this software give you 11 * permission to link this software with independent modules, and to copy and 12 * distribute the resulting executable under terms of your choice, provided that 13 * you also meet, for each linked independent module, the terms and conditions of 14 * the license of that module. An independent module is a module which is not 15 * derived from this software. The special exception does not apply to any 16 * modifications of the software. 17 * 18 * Notwithstanding the above, under no circumstances may you combine this 19 * software in any way with any other Broadcom software provided under a license 20 * other than the GPL, without Broadcom's express prior written consent. 21 * 22 * Fundamental constants relating to IP Protocol 23 * 24 * $Id: bcmip.h,v 9.16.186.4 2009/01/27 04:25:25 Exp $ 25 */ 26 27 28 #ifndef _bcmip_h_ 29 #define _bcmip_h_ 30 31 #ifndef _TYPEDEFS_H_ 32 #include <typedefs.h> 33 #endif 34 35 36 #include <packed_section_start.h> 37 38 39 40 #define IP_VER_OFFSET 0x0 41 #define IP_VER_MASK 0xf0 42 #define IP_VER_SHIFT 4 43 #define IP_VER_4 4 44 #define IP_VER_6 6 45 46 #define IP_VER(ip_body) \ 47 ((((uint8 *)(ip_body))[IP_VER_OFFSET] & IP_VER_MASK) >> IP_VER_SHIFT) 48 49 #define IP_PROT_ICMP 0x1 50 #define IP_PROT_TCP 0x6 51 #define IP_PROT_UDP 0x11 52 53 54 #define IPV4_VER_HL_OFFSET 0 55 #define IPV4_TOS_OFFSET 1 56 #define IPV4_PKTLEN_OFFSET 2 57 #define IPV4_PKTFLAG_OFFSET 6 58 #define IPV4_PROT_OFFSET 9 59 #define IPV4_CHKSUM_OFFSET 10 60 #define IPV4_SRC_IP_OFFSET 12 61 #define IPV4_DEST_IP_OFFSET 16 62 #define IPV4_OPTIONS_OFFSET 20 63 64 65 #define IPV4_VER_MASK 0xf0 66 #define IPV4_VER_SHIFT 4 67 68 #define IPV4_HLEN_MASK 0x0f 69 #define IPV4_HLEN(ipv4_body) (4 * (((uint8 *)(ipv4_body))[IPV4_VER_HL_OFFSET] & IPV4_HLEN_MASK)) 70 71 #define IPV4_ADDR_LEN 4 72 73 #define IPV4_ADDR_NULL(a) ((((uint8 *)(a))[0] | ((uint8 *)(a))[1] | \ 74 ((uint8 *)(a))[2] | ((uint8 *)(a))[3]) == 0) 75 76 #define IPV4_ADDR_BCAST(a) ((((uint8 *)(a))[0] & ((uint8 *)(a))[1] & \ 77 ((uint8 *)(a))[2] & ((uint8 *)(a))[3]) == 0xff) 78 79 #define IPV4_TOS_DSCP_MASK 0xfc 80 #define IPV4_TOS_DSCP_SHIFT 2 81 82 #define IPV4_TOS(ipv4_body) (((uint8 *)(ipv4_body))[IPV4_TOS_OFFSET]) 83 84 #define IPV4_TOS_PREC_MASK 0xe0 85 #define IPV4_TOS_PREC_SHIFT 5 86 87 #define IPV4_TOS_LOWDELAY 0x10 88 #define IPV4_TOS_THROUGHPUT 0x8 89 #define IPV4_TOS_RELIABILITY 0x4 90 91 #define IPV4_PROT(ipv4_body) (((uint8 *)(ipv4_body))[IPV4_PROT_OFFSET]) 92 93 #define IPV4_FRAG_RESV 0x8000 94 #define IPV4_FRAG_DONT 0x4000 95 #define IPV4_FRAG_MORE 0x2000 96 #define IPV4_FRAG_OFFSET_MASK 0x1fff 97 98 #define IPV4_ADDR_STR_LEN 16 99 100 101 BWL_PRE_PACKED_STRUCT struct ipv4_addr { 102 uint8 addr[IPV4_ADDR_LEN]; 103 } BWL_POST_PACKED_STRUCT; 104 105 BWL_PRE_PACKED_STRUCT struct ipv4_hdr { 106 uint8 version_ihl; 107 uint8 tos; 108 uint16 tot_len; 109 uint16 id; 110 uint16 frag; 111 uint8 ttl; 112 uint8 prot; 113 uint16 hdr_chksum; 114 uint8 src_ip[IPV4_ADDR_LEN]; 115 uint8 dst_ip[IPV4_ADDR_LEN]; 116 } BWL_POST_PACKED_STRUCT; 117 118 119 #define IPV6_PAYLOAD_LEN_OFFSET 4 120 #define IPV6_NEXT_HDR_OFFSET 6 121 #define IPV6_HOP_LIMIT_OFFSET 7 122 #define IPV6_SRC_IP_OFFSET 8 123 #define IPV6_DEST_IP_OFFSET 24 124 125 126 #define IPV6_TRAFFIC_CLASS(ipv6_body) \ 127 (((((uint8 *)(ipv6_body))[0] & 0x0f) << 4) | \ 128 ((((uint8 *)(ipv6_body))[1] & 0xf0) >> 4)) 129 130 #define IPV6_FLOW_LABEL(ipv6_body) \ 131 (((((uint8 *)(ipv6_body))[1] & 0x0f) << 16) | \ 132 (((uint8 *)(ipv6_body))[2] << 8) | \ 133 (((uint8 *)(ipv6_body))[3])) 134 135 #define IPV6_PAYLOAD_LEN(ipv6_body) \ 136 ((((uint8 *)(ipv6_body))[IPV6_PAYLOAD_LEN_OFFSET + 0] << 8) | \ 137 ((uint8 *)(ipv6_body))[IPV6_PAYLOAD_LEN_OFFSET + 1]) 138 139 #define IPV6_NEXT_HDR(ipv6_body) \ 140 (((uint8 *)(ipv6_body))[IPV6_NEXT_HDR_OFFSET]) 141 142 #define IPV6_PROT(ipv6_body) IPV6_NEXT_HDR(ipv6_body) 143 144 #define IPV6_ADDR_LEN 16 145 146 147 #ifndef IP_TOS 148 #define IP_TOS(ip_body) \ 149 (IP_VER(ip_body) == IP_VER_4 ? IPV4_TOS(ip_body) : \ 150 IP_VER(ip_body) == IP_VER_6 ? IPV6_TRAFFIC_CLASS(ip_body) : 0) 151 #endif 152 153 154 155 #include <packed_section_end.h> 156 157 #endif 158