]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp-identifier.h
0ccee7a718758033c8b04e661094e33ecccd5ac7
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-identifier.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright (C) 2015 Tom Gundersen <teg@jklmen>
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include "sd-id128.h"
24
25 #include "macro.h"
26 #include "sparse-endian.h"
27 #include "unaligned.h"
28
29 typedef enum DUIDType {
30 DUID_TYPE_LLT = 1,
31 DUID_TYPE_EN = 2,
32 DUID_TYPE_LL = 3,
33 DUID_TYPE_UUID = 4,
34 _DUID_TYPE_MAX,
35 _DUID_TYPE_INVALID = -1,
36 } DUIDType;
37
38 /* RFC 3315 section 9.1:
39 * A DUID can be no more than 128 octets long (not including the type code).
40 */
41 #define MAX_DUID_LEN 128
42
43 /* https://tools.ietf.org/html/rfc3315#section-9.1 */
44 struct duid {
45 be16_t type;
46 union {
47 struct {
48 /* DUID_TYPE_LLT */
49 uint16_t htype;
50 uint32_t time;
51 uint8_t haddr[0];
52 } _packed_ llt;
53 struct {
54 /* DUID_TYPE_EN */
55 uint32_t pen;
56 uint8_t id[8];
57 } _packed_ en;
58 struct {
59 /* DUID_TYPE_LL */
60 int16_t htype;
61 uint8_t haddr[0];
62 } _packed_ ll;
63 struct {
64 /* DUID_TYPE_UUID */
65 sd_id128_t uuid;
66 } _packed_ uuid;
67 struct {
68 uint8_t data[MAX_DUID_LEN];
69 } _packed_ raw;
70 };
71 } _packed_;
72
73 int dhcp_validate_duid_len(uint16_t duid_type, size_t duid_len);
74 int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len);
75 int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_id);