]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp-identifier.h
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[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 "time-util.h"
9 #include "unaligned.h"
10
11 typedef enum DUIDType {
12 DUID_TYPE_LLT = 1,
13 DUID_TYPE_EN = 2,
14 DUID_TYPE_LL = 3,
15 DUID_TYPE_UUID = 4,
16 _DUID_TYPE_MAX,
17 _DUID_TYPE_INVALID = -1,
18 } DUIDType;
19
20 /* RFC 3315 section 9.1:
21 * A DUID can be no more than 128 octets long (not including the type code).
22 */
23 #define MAX_DUID_LEN 128
24
25 /* https://tools.ietf.org/html/rfc3315#section-9.1 */
26 struct duid {
27 be16_t type;
28 union {
29 struct {
30 /* DUID_TYPE_LLT */
31 be16_t htype;
32 be32_t time;
33 uint8_t haddr[0];
34 } _packed_ llt;
35 struct {
36 /* DUID_TYPE_EN */
37 be32_t pen;
38 uint8_t id[8];
39 } _packed_ en;
40 struct {
41 /* DUID_TYPE_LL */
42 be16_t htype;
43 uint8_t haddr[0];
44 } _packed_ ll;
45 struct {
46 /* DUID_TYPE_UUID */
47 sd_id128_t uuid;
48 } _packed_ uuid;
49 struct {
50 uint8_t data[MAX_DUID_LEN];
51 } _packed_ raw;
52 };
53 } _packed_;
54
55 int dhcp_validate_duid_len(uint16_t duid_type, size_t duid_len);
56 int dhcp_identifier_set_duid_llt(struct duid *duid, usec_t t, const uint8_t *addr, size_t addr_len, uint16_t arp_type, size_t *len);
57 int dhcp_identifier_set_duid_ll(struct duid *duid, const uint8_t *addr, size_t addr_len, uint16_t arp_type, size_t *len);
58 int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len);
59 int dhcp_identifier_set_duid_uuid(struct duid *duid, size_t *len);
60 int dhcp_identifier_set_iaid(int ifindex, const uint8_t *mac, size_t mac_len, bool legacy_unstable_byteorder, void *_id);