| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-dhcp-client-id.h" |
| 5 |
|
| 6 |
#include "dhcp-duid-internal.h" |
| 7 |
#include "dhcp-forward.h" |
| 8 |
#include "ether-addr-util.h" |
| 9 |
|
| 10 |
/* RFC 2132 section 9.14: its minimum length is 2. |
| 11 |
* Note, its maximum is not mentioend in the RFC. Hence, 255. */ |
| 12 |
#define MIN_CLIENT_ID_LEN 2 |
| 13 |
#define MAX_CLIENT_ID_LEN 255 |
| 14 |
#define MIN_CLIENT_ID_DATA_LEN (MIN_CLIENT_ID_LEN - sizeof(uint8_t)) |
| 15 |
#define MAX_CLIENT_ID_DATA_LEN (MAX_CLIENT_ID_LEN - sizeof(uint8_t)) |
| 16 |
|
| 17 |
typedef struct sd_dhcp_client_id { |
| 18 |
size_t size; |
| 19 |
union { |
| 20 |
struct { |
| 21 |
uint8_t type; |
| 22 |
union { |
| 23 |
struct { |
| 24 |
/* 0: Generic (non-LL) (RFC 2132) */ |
| 25 |
uint8_t data[MAX_CLIENT_ID_DATA_LEN]; |
| 26 |
} _packed_ gen; |
| 27 |
struct { |
| 28 |
/* 1: Ethernet Link-Layer (RFC 2132) */ |
| 29 |
uint8_t haddr[ETH_ALEN]; |
| 30 |
} _packed_ eth; |
| 31 |
struct { |
| 32 |
/* 2 - 254: ARP/Link-Layer (RFC 2132) */ |
| 33 |
uint8_t haddr[HW_ADDR_MAX_SIZE]; |
| 34 |
} _packed_ ll; |
| 35 |
struct { |
| 36 |
/* 255: Node-specific (RFC 4361) */ |
| 37 |
be32_t iaid; |
| 38 |
struct duid duid; |
| 39 |
} _packed_ ns; |
| 40 |
uint8_t data[MAX_CLIENT_ID_DATA_LEN]; |
| 41 |
}; |
| 42 |
} _packed_ id; |
| 43 |
uint8_t raw[MAX_CLIENT_ID_LEN]; |
| 44 |
}; |
| 45 |
} sd_dhcp_client_id; |
| 46 |
|
| 47 |
assert_cc(sizeof_field(sd_dhcp_client_id, id) <= MAX_CLIENT_ID_LEN); |
| 48 |
|
| 49 |
static inline bool client_id_size_is_valid(size_t size) { |
| 50 |
return size >= MIN_CLIENT_ID_LEN && size <= MAX_CLIENT_ID_LEN; |
| 51 |
} |
| 52 |
|
| 53 |
static inline bool client_id_data_size_is_valid(size_t size) { |
| 54 |
return size >= MIN_CLIENT_ID_DATA_LEN && size <= MAX_CLIENT_ID_DATA_LEN; |
| 55 |
} |
| 56 |
|
| 57 |
void client_id_hash_func(const sd_dhcp_client_id *client_id, struct siphash *state); |
| 58 |
int client_id_compare_func(const sd_dhcp_client_id *a, const sd_dhcp_client_id *b); |
| 59 |
|
| 60 |
int json_dispatch_client_id(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata); |