]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp-identifier.h
sd-dhcp: use application specific machine ID when DUIDType=uuid but DUIDRawData=...
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-identifier.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "sd-id128.h"
5
6 #include "macro.h"
7 #include "sparse-endian.h"
8 #include "unaligned.h"
9
10 typedef enum DUIDType {
11 DUID_TYPE_LLT = 1,
12 DUID_TYPE_EN = 2,
13 DUID_TYPE_LL = 3,
14 DUID_TYPE_UUID = 4,
15 _DUID_TYPE_MAX,
16 _DUID_TYPE_INVALID = -1,
17 } DUIDType;
18
19 /* RFC 3315 section 9.1:
20 * A DUID can be no more than 128 octets long (not including the type code).
21 */
22 #define MAX_DUID_LEN 128
23
24 /* https://tools.ietf.org/html/rfc3315#section-9.1 */
25 struct duid {
26 be16_t type;
27 union {
28 struct {
29 /* DUID_TYPE_LLT */
30 uint16_t htype;
31 uint32_t time;
32 uint8_t haddr[0];
33 } _packed_ llt;
34 struct {
35 /* DUID_TYPE_EN */
36 uint32_t pen;
37 uint8_t id[8];
38 } _packed_ en;
39 struct {
40 /* DUID_TYPE_LL */
41 int16_t htype;
42 uint8_t haddr[0];
43 } _packed_ ll;
44 struct {
45 /* DUID_TYPE_UUID */
46 sd_id128_t uuid;
47 } _packed_ uuid;
48 struct {
49 uint8_t data[MAX_DUID_LEN];
50 } _packed_ raw;
51 };
52 } _packed_;
53
54 int dhcp_validate_duid_len(uint16_t duid_type, size_t duid_len);
55 int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len);
56 int dhcp_identifier_set_duid_uuid(struct duid *duid, size_t *len);
57 int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_id);