Skip to content

Commit cdffcde

Browse files
committed
net: lib: dhcpv4_server: Add client hardware ID to client_id
This is useful if you specifically need the hardware address and not the client_id option. Signed-off-by: Andreas Ålgård <[email protected]>
1 parent 0b52928 commit cdffcde

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

include/zephyr/net/dhcpv4_server.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ struct net_if;
3333

3434
#define DHCPV4_CLIENT_ID_MAX_SIZE 20
3535

36+
/**
37+
* Max DHCP hardware address size is defined in RFC2131
38+
* https://www.rfc-editor.org/rfc/rfc2131
39+
*/
40+
#define DHCPV4_HARDWARE_ADDRESS_MAX_SIZE 16
41+
3642
enum dhcpv4_server_addr_state {
3743
DHCPV4_SERVER_ADDR_FREE,
3844
DHCPV4_SERVER_ADDR_RESERVED,
@@ -41,6 +47,10 @@ enum dhcpv4_server_addr_state {
4147
};
4248

4349
struct dhcpv4_client_id {
50+
uint8_t hw_addr_type;
51+
uint8_t hw_addr_buf[DHCPV4_HARDWARE_ADDRESS_MAX_SIZE];
52+
uint8_t hw_addr_len;
53+
4454
uint8_t buf[DHCPV4_CLIENT_ID_MAX_SIZE];
4555
uint8_t len;
4656
};

subsys/net/lib/dhcpv4/dhcpv4_server.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ static int dhcpv4_get_client_id(struct dhcp_msg *msg, uint8_t *options,
741741
{
742742
int ret;
743743

744+
client_id->hw_addr_type = msg->htype;
745+
memcpy(client_id->hw_addr_buf, msg->chaddr, msg->hlen);
746+
client_id->hw_addr_len = msg->hlen;
747+
744748
client_id->len = sizeof(client_id->buf);
745749

746750
ret = dhcpv4_find_client_id_option(options, optlen, client_id->buf,

0 commit comments

Comments
 (0)