Skip to content

Commit

Permalink
Merge pull request systemd#30593 from yuwata/sd-dhcp-duid
Browse files Browse the repository at this point in the history
dhcp: introduce sd_dhcp_duid and relevant functions
  • Loading branch information
bluca authored Jan 1, 2024
2 parents e191de6 + 3a6c222 commit 9d75598
Show file tree
Hide file tree
Showing 19 changed files with 473 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
#pragma once

#include "sd-device.h"
#include "sd-dhcp-duid.h"
#include "sd-id128.h"

#include "ether-addr-util.h"
#include "macro.h"
#include "sparse-endian.h"
#include "time-util.h"
#include "unaligned.h"

#define SYSTEMD_PEN 43793

typedef enum DUIDType {
DUID_TYPE_LLT = 1,
DUID_TYPE_EN = 2,
DUID_TYPE_LL = 3,
DUID_TYPE_UUID = 4,
DUID_TYPE_LLT = SD_DUID_TYPE_LLT,
DUID_TYPE_EN = SD_DUID_TYPE_EN,
DUID_TYPE_LL = SD_DUID_TYPE_LL,
DUID_TYPE_UUID = SD_DUID_TYPE_UUID,
_DUID_TYPE_MAX,
_DUID_TYPE_INVALID = -EINVAL,
_DUID_TYPE_FORCE_U16 = UINT16_MAX,
_DUID_TYPE_INVALID = -EINVAL,
} DUIDType;

/* RFC 8415 section 11.1:
* A DUID consists of a 2-octet type code represented in network byte order, followed by a variable number of
* octets that make up the actual identifier. The length of the DUID (not including the type code) is at
* least 1 octet and at most 128 octets. */
#define MIN_DUID_DATA_LEN 1
#define MAX_DUID_DATA_LEN 128
#define MIN_DUID_LEN (sizeof(be16_t) + MIN_DUID_DATA_LEN)
#define MAX_DUID_LEN (sizeof(be16_t) + MAX_DUID_DATA_LEN)

/* https://tools.ietf.org/html/rfc3315#section-9.1 */
Expand All @@ -53,35 +53,31 @@ struct duid {
/* DUID_TYPE_UUID */
sd_id128_t uuid;
} _packed_ uuid;
struct {
uint8_t data[MAX_DUID_DATA_LEN];
} _packed_ raw;
uint8_t data[MAX_DUID_DATA_LEN];
};
} _packed_;

int dhcp_identifier_set_duid_llt(
const struct hw_addr_data *hw_addr,
uint16_t arp_type,
usec_t t,
struct duid *ret_duid,
size_t *ret_len);
int dhcp_identifier_set_duid_ll(
const struct hw_addr_data *hw_addr,
uint16_t arp_type,
struct duid *ret_duid,
size_t *ret_len);
int dhcp_identifier_set_duid_en(struct duid *ret_duid, size_t *ret_len);
int dhcp_identifier_set_duid_uuid(struct duid *ret_duid, size_t *ret_len);
int dhcp_identifier_set_duid_raw(
DUIDType duid_type,
const uint8_t *buf,
size_t buf_len,
struct duid *ret_duid,
size_t *ret_len);
typedef struct sd_dhcp_duid {
size_t size;
union {
struct duid duid;
uint8_t raw[MAX_DUID_LEN];
};
} sd_dhcp_duid;

static inline bool duid_size_is_valid(size_t size) {
return size >= MIN_DUID_LEN && size <= MAX_DUID_LEN;
}

static inline bool duid_data_size_is_valid(size_t size) {
return size >= MIN_DUID_DATA_LEN && size <= MAX_DUID_DATA_LEN;
}

const char *duid_type_to_string(DUIDType t) _const_;
int dhcp_duid_to_string_internal(uint16_t type, const void *data, size_t data_size, char **ret);

int dhcp_identifier_set_iaid(
sd_device *dev,
const struct hw_addr_data *hw_addr,
bool legacy_unstable_byteorder,
void *ret);

const char *duid_type_to_string(DUIDType t) _const_;
209 changes: 0 additions & 209 deletions src/libsystemd-network/dhcp-identifier.c

This file was deleted.

5 changes: 2 additions & 3 deletions src/libsystemd-network/dhcp6-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "sd-event.h"
#include "sd-dhcp6-client.h"

#include "dhcp-identifier.h"
#include "dhcp-duid-internal.h"
#include "dhcp6-client-internal.h"
#include "dhcp6-option.h"
#include "dhcp6-protocol.h"
Expand Down Expand Up @@ -64,8 +64,7 @@ struct sd_dhcp6_client {
DHCP6IA ia_na;
DHCP6IA ia_pd;
DHCP6RequestIA request_ia;
struct duid duid;
size_t duid_len;
sd_dhcp_duid duid;
be16_t *req_opts;
size_t n_req_opts;
char *fqdn;
Expand Down
2 changes: 1 addition & 1 deletion src/libsystemd-network/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

sources = files(
'arp-util.c',
'dhcp-identifier.c',
'dhcp-network.c',
'dhcp-option.c',
'dhcp-packet.c',
Expand All @@ -17,6 +16,7 @@ sources = files(
'network-common.c',
'network-internal.c',
'sd-dhcp-client.c',
'sd-dhcp-duid.c',
'sd-dhcp-lease.c',
'sd-dhcp-server.c',
'sd-dhcp6-client.c',
Expand Down
Loading

0 comments on commit 9d75598

Please sign in to comment.