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