]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-identifier.h
network/dhcp: fix maximal DUID data size
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-identifier.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
764aad62
TG
2#pragma once
3
14805b14 4#include "sd-device.h"
07630cea 5#include "sd-id128.h"
764aad62 6
3b75435d 7#include "ether-addr-util.h"
c1ff5570 8#include "macro.h"
764aad62 9#include "sparse-endian.h"
335f80a6 10#include "time-util.h"
9ee18af3 11#include "unaligned.h"
764aad62 12
73c8ced7
SS
13#define SYSTEMD_PEN 43793
14
413708d1 15typedef enum DUIDType {
413708d1
VK
16 DUID_TYPE_LLT = 1,
17 DUID_TYPE_EN = 2,
18 DUID_TYPE_LL = 3,
19 DUID_TYPE_UUID = 4,
20 _DUID_TYPE_MAX,
0979e4ad 21 _DUID_TYPE_INVALID = -EINVAL,
413708d1
VK
22} DUIDType;
23
764aad62
TG
24/* RFC 3315 section 9.1:
25 * A DUID can be no more than 128 octets long (not including the type code).
26 */
27#define MAX_DUID_LEN 128
92914960 28#define MAX_DUID_DATA_LEN (MAX_DUID_LEN - sizeof(be16_t))
764aad62 29
3b6a4e97 30/* https://tools.ietf.org/html/rfc3315#section-9.1 */
764aad62 31struct duid {
413708d1 32 be16_t type;
764aad62
TG
33 union {
34 struct {
3b6a4e97 35 /* DUID_TYPE_LLT */
9d7b8c66
YW
36 be16_t htype;
37 be32_t time;
764aad62
TG
38 uint8_t haddr[0];
39 } _packed_ llt;
40 struct {
3b6a4e97 41 /* DUID_TYPE_EN */
9d7b8c66 42 be32_t pen;
764aad62
TG
43 uint8_t id[8];
44 } _packed_ en;
45 struct {
3b6a4e97 46 /* DUID_TYPE_LL */
9d7b8c66 47 be16_t htype;
764aad62
TG
48 uint8_t haddr[0];
49 } _packed_ ll;
50 struct {
3b6a4e97 51 /* DUID_TYPE_UUID */
764aad62
TG
52 sd_id128_t uuid;
53 } _packed_ uuid;
54 struct {
92914960 55 uint8_t data[MAX_DUID_DATA_LEN];
764aad62
TG
56 } _packed_ raw;
57 };
58} _packed_;
cfb5b380 59
5e1618fa 60int dhcp_validate_duid_len(DUIDType duid_type, size_t duid_len, bool strict);
53488ea3
YW
61int dhcp_identifier_set_duid_llt(
62 const struct hw_addr_data *hw_addr,
63 uint16_t arp_type,
64 usec_t t,
65 struct duid *ret_duid,
66 size_t *ret_len);
67int dhcp_identifier_set_duid_ll(
8cad358e 68 const struct hw_addr_data *hw_addr,
5e1618fa 69 uint16_t arp_type,
53488ea3
YW
70 struct duid *ret_duid,
71 size_t *ret_len);
72int dhcp_identifier_set_duid_en(bool test_mode, struct duid *ret_duid, size_t *ret_len);
73int dhcp_identifier_set_duid_uuid(struct duid *ret_duid, size_t *ret_len);
74int dhcp_identifier_set_duid_raw(
75 DUIDType duid_type,
76 const uint8_t *buf,
77 size_t buf_len,
5e1618fa
YW
78 struct duid *ret_duid,
79 size_t *ret_len);
80int dhcp_identifier_set_iaid(
14805b14 81 sd_device *dev,
3b75435d 82 const struct hw_addr_data *hw_addr,
5e1618fa 83 bool legacy_unstable_byteorder,
5e1618fa 84 void *ret);
f9971018
YW
85
86const char *duid_type_to_string(DUIDType t) _const_;