]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-identifier.h
dhcp: support endianness independent dhcp_identifier_set_iaid()
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-identifier.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
764aad62
TG
2#pragma once
3
07630cea 4#include "sd-id128.h"
764aad62 5
c1ff5570 6#include "macro.h"
764aad62 7#include "sparse-endian.h"
335f80a6 8#include "time-util.h"
9ee18af3 9#include "unaligned.h"
764aad62 10
413708d1 11typedef enum DUIDType {
413708d1
VK
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
764aad62
TG
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
3b6a4e97 25/* https://tools.ietf.org/html/rfc3315#section-9.1 */
764aad62 26struct duid {
413708d1 27 be16_t type;
764aad62
TG
28 union {
29 struct {
3b6a4e97 30 /* DUID_TYPE_LLT */
9d7b8c66
YW
31 be16_t htype;
32 be32_t time;
764aad62
TG
33 uint8_t haddr[0];
34 } _packed_ llt;
35 struct {
3b6a4e97 36 /* DUID_TYPE_EN */
9d7b8c66 37 be32_t pen;
764aad62
TG
38 uint8_t id[8];
39 } _packed_ en;
40 struct {
3b6a4e97 41 /* DUID_TYPE_LL */
9d7b8c66 42 be16_t htype;
764aad62
TG
43 uint8_t haddr[0];
44 } _packed_ ll;
45 struct {
3b6a4e97 46 /* DUID_TYPE_UUID */
764aad62
TG
47 sd_id128_t uuid;
48 } _packed_ uuid;
49 struct {
50 uint8_t data[MAX_DUID_LEN];
51 } _packed_ raw;
52 };
53} _packed_;
cfb5b380 54
3b6a4e97 55int dhcp_validate_duid_len(uint16_t duid_type, size_t duid_len);
335f80a6
YW
56int 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);
57int dhcp_identifier_set_duid_ll(struct duid *duid, const uint8_t *addr, size_t addr_len, uint16_t arp_type, size_t *len);
cfb5b380 58int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len);
27eba50e 59int dhcp_identifier_set_duid_uuid(struct duid *duid, size_t *len);
6d13616b 60int dhcp_identifier_set_iaid(int ifindex, const uint8_t *mac, size_t mac_len, bool legacy_unstable_byteorder, void *_id);