macipadr.h (2347B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: macipadr.h 8 * Purpose: Typedefs for MAC and IP addresses 9 */ 10 11 #ifndef _SYS_MACIPADR_H 12 #define _SYS_MACIPADR_H 13 14 #include <sal/core/libc.h> 15 #include <soc/types.h> 16 #include <shared/l3.h> 17 18 typedef _shr_ip_addr_t ip_addr_t; /* IP Address */ 19 typedef _shr_ip6_addr_t ip6_addr_t; /* IPv6 Address */ 20 21 extern const sal_mac_addr_t _soc_mac_spanning_tree; 22 extern const sal_mac_addr_t _soc_mac_all_routers; 23 extern const sal_mac_addr_t _soc_mac_all_zeroes; 24 extern const sal_mac_addr_t _soc_mac_all_ones; 25 26 /* sal_mac_addr_t mac; Just generate a list of the macs for display */ 27 #define MAC_ADDR_LIST(mac) \ 28 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] 29 30 /* sal_mac_addr_t m1, m2; True if equal */ 31 #define MAC_ADDR_EQUAL(m1, m2) (!sal_memcmp(m1, m2, sizeof(sal_mac_addr_t))) 32 33 /* sal_mac_addr_t m1, m2; like memcmp, returns -1, 0, or 1 */ 34 #define MAC_ADDR_CMP(m1, m2) sal_memcmp(m1, m2, sizeof(sal_mac_addr_t)) 35 36 /* sal_mac_addr_t mac; True if multicast mac address */ 37 #define MAC_IS_MCAST(mac) (((mac)[0] & 0x1) ? TRUE : FALSE) 38 39 #define MACADDR_STR_LEN 18 /* Formatted MAC address */ 40 #define IPADDR_STR_LEN 16 /* Formatted IP address */ 41 #define IP6ADDR_STR_LEN 64 /* Formatted IP address */ 42 43 44 /* Adjust justification for uint32 writes to fields */ 45 /* dst is an array name of type uint32 [] */ 46 #define MAC_ADDR_TO_UINT32(mac, dst) do {\ 47 dst[0] = (((uint32)mac[2]) << 24 | \ 48 ((uint32)mac[3]) << 16 | \ 49 ((uint32)mac[4]) << 8 | \ 50 ((uint32)mac[5])); \ 51 dst[1] = (((uint32)mac[0]) << 8 | \ 52 ((uint32)mac[1])); \ 53 } while (0) 54 55 /* Adjust justification for uint32 writes to fields */ 56 /* dst is an array name of type uint32 [] */ 57 #define MAC_ADDR_FROM_UINT32(mac, src) do {\ 58 mac[0] = (uint8) (src[1] >> 8 & 0xff); \ 59 mac[1] = (uint8) (src[1] & 0xff); \ 60 mac[2] = (uint8) (src[0] >> 24); \ 61 mac[3] = (uint8) (src[0] >> 16 & 0xff); \ 62 mac[4] = (uint8) (src[0] >> 8 & 0xff); \ 63 mac[5] = (uint8) (src[0] & 0xff); \ 64 } while (0) 65 66 #endif /* _SYS_MACIPADR_H */