| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-dhcp-duid.h" |
| 5 |
#include "sd-id128.h" |
| 6 |
|
| 7 |
#include "dhcp-forward.h" |
| 8 |
#include "ether-addr-util.h" |
| 9 |
|
| 10 |
#define SYSTEMD_PEN 43793 |
| 11 |
|
| 12 |
typedef enum DUIDType { |
| 13 |
DUID_TYPE_LLT = SD_DUID_TYPE_LLT, |
| 14 |
DUID_TYPE_EN = SD_DUID_TYPE_EN, |
| 15 |
DUID_TYPE_LL = SD_DUID_TYPE_LL, |
| 16 |
DUID_TYPE_UUID = SD_DUID_TYPE_UUID, |
| 17 |
_DUID_TYPE_MAX, |
| 18 |
_DUID_TYPE_INVALID = -EINVAL, |
| 19 |
} DUIDType; |
| 20 |
|
| 21 |
/* RFC 8415 section 11.1: |
| 22 |
* A DUID consists of a 2-octet type code represented in network byte order, followed by a variable number of |
| 23 |
* octets that make up the actual identifier. The length of the DUID (not including the type code) is at |
| 24 |
* least 1 octet and at most 128 octets. */ |
| 25 |
#define MIN_DUID_DATA_LEN 1 |
| 26 |
#define MAX_DUID_DATA_LEN 128 |
| 27 |
#define MIN_DUID_LEN (sizeof(be16_t) + MIN_DUID_DATA_LEN) |
| 28 |
#define MAX_DUID_LEN (sizeof(be16_t) + MAX_DUID_DATA_LEN) |
| 29 |
|
| 30 |
/* https://tools.ietf.org/html/rfc3315#section-9.1 */ |
| 31 |
struct duid { |
| 32 |
be16_t type; |
| 33 |
union { |
| 34 |
struct { |
| 35 |
/* DUID_TYPE_LLT */ |
| 36 |
be16_t htype; |
| 37 |
be32_t time; |
| 38 |
uint8_t haddr[HW_ADDR_MAX_SIZE]; |
| 39 |
} _packed_ llt; |
| 40 |
struct { |
| 41 |
/* DUID_TYPE_EN */ |
| 42 |
be32_t pen; |
| 43 |
/* The maximum length of vendor ID is not provided in RFC 8415, but we use 8 bytes. |
| 44 |
* See https://datatracker.ietf.org/doc/html/rfc8415#section-11.3 */ |
| 45 |
uint8_t id[8]; |
| 46 |
} _packed_ en; |
| 47 |
struct { |
| 48 |
/* DUID_TYPE_LL */ |
| 49 |
be16_t htype; |
| 50 |
uint8_t haddr[HW_ADDR_MAX_SIZE]; |
| 51 |
} _packed_ ll; |
| 52 |
struct { |
| 53 |
/* DUID_TYPE_UUID */ |
| 54 |
sd_id128_t uuid; |
| 55 |
} _packed_ uuid; |
| 56 |
uint8_t data[MAX_DUID_DATA_LEN]; |
| 57 |
}; |
| 58 |
} _packed_; |
| 59 |
|
| 60 |
assert_cc(sizeof(struct duid) == MAX_DUID_LEN); |
| 61 |
|
| 62 |
typedef struct sd_dhcp_duid { |
| 63 |
size_t size; |
| 64 |
union { |
| 65 |
struct duid duid; |
| 66 |
uint8_t raw[MAX_DUID_LEN]; |
| 67 |
}; |
| 68 |
} sd_dhcp_duid; |
| 69 |
|
| 70 |
static inline bool duid_size_is_valid(size_t size) { |
| 71 |
return size >= MIN_DUID_LEN && size <= MAX_DUID_LEN; |
| 72 |
} |
| 73 |
|
| 74 |
static inline bool duid_data_size_is_valid(size_t size) { |
| 75 |
return size >= MIN_DUID_DATA_LEN && size <= MAX_DUID_DATA_LEN; |
| 76 |
} |
| 77 |
|
| 78 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING(duid_type, DUIDType); |
| 79 |
int dhcp_duid_to_string_internal(uint16_t type, const void *data, size_t data_size, char **ret); |
| 80 |
|
| 81 |
int dhcp_identifier_set_iaid( |
| 82 |
sd_device *dev, |
| 83 |
const struct hw_addr_data *hw_addr, |
| 84 |
bool legacy_unstable_byteorder, |
| 85 |
void *ret); |