]>
Commit | Line | Data |
---|---|---|
a032b68d | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
663996b3 MS |
2 | #pragma once |
3 | ||
a032b68d | 4 | #include <linux/if_infiniband.h> |
f47781d8 | 5 | #include <net/ethernet.h> |
aa27b158 | 6 | #include <stdbool.h> |
663996b3 | 7 | |
b012e921 MB |
8 | #include "hash-funcs.h" |
9 | ||
a032b68d MB |
10 | /* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h |
11 | * defines a macro of the same name with a much lower size. */ | |
12 | #define HW_ADDR_MAX_SIZE 32 | |
13 | ||
8b3d4ff0 | 14 | struct hw_addr_data { |
a032b68d | 15 | size_t length; |
8b3d4ff0 MB |
16 | union { |
17 | struct ether_addr ether; | |
18 | uint8_t infiniband[INFINIBAND_ALEN]; | |
19 | uint8_t bytes[HW_ADDR_MAX_SIZE]; | |
20 | }; | |
21 | }; | |
a032b68d MB |
22 | |
23 | #define HW_ADDR_TO_STRING_MAX (3*HW_ADDR_MAX_SIZE) | |
8b3d4ff0 | 24 | char* hw_addr_to_string(const struct hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]); |
a032b68d MB |
25 | |
26 | /* Use only as function argument, never stand-alone! */ | |
27 | #define HW_ADDR_TO_STR(hw_addr) hw_addr_to_string((hw_addr), (char[HW_ADDR_TO_STRING_MAX]){}) | |
28 | ||
8b3d4ff0 MB |
29 | #define HW_ADDR_NULL ((const struct hw_addr_data){}) |
30 | ||
31 | int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b); | |
32 | static inline bool hw_addr_equal(const struct hw_addr_data *a, const struct hw_addr_data *b) { | |
33 | return hw_addr_compare(a, b) == 0; | |
34 | } | |
35 | static inline bool hw_addr_is_null(const struct hw_addr_data *addr) { | |
36 | return hw_addr_equal(addr, &HW_ADDR_NULL); | |
37 | } | |
a032b68d | 38 | |
f47781d8 MP |
39 | #define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X" |
40 | #define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5] | |
db2df898 MP |
41 | |
42 | #define ETHER_ADDR_TO_STRING_MAX (3*6) | |
db2df898 | 43 | char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]); |
8b3d4ff0 MB |
44 | int ether_addr_to_string_alloc(const struct ether_addr *addr, char **ret); |
45 | /* Use only as function argument, never stand-alone! */ | |
46 | #define ETHER_ADDR_TO_STR(addr) ether_addr_to_string((addr), (char[ETHER_ADDR_TO_STRING_MAX]){}) | |
aa27b158 | 47 | |
6e866b33 | 48 | int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b); |
b012e921 MB |
49 | static inline bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) { |
50 | return ether_addr_compare(a, b) == 0; | |
51 | } | |
aa27b158 MP |
52 | |
53 | #define ETHER_ADDR_NULL ((const struct ether_addr){}) | |
54 | ||
55 | static inline bool ether_addr_is_null(const struct ether_addr *addr) { | |
56 | return ether_addr_equal(addr, ÐER_ADDR_NULL); | |
57 | } | |
58 | ||
b012e921 MB |
59 | int ether_addr_from_string(const char *s, struct ether_addr *ret); |
60 | ||
61 | extern const struct hash_ops ether_addr_hash_ops; |