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