diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index d9ed8b0f..e129a037 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -265,6 +265,9 @@ static u16_t dhcp_option_long(u16_t options_out_len, u8_t *options, u32_t value) #if LWIP_NETIF_HOSTNAME static u16_t dhcp_option_hostname(u16_t options_out_len, u8_t *options, struct netif *netif); #endif /* LWIP_NETIF_HOSTNAME */ +#if LWIP_DHCP_MUD_URL +static u16_t dhcp_option_mud_url(u16_t options_out_len, u8_t *options, char *mud_url); +#endif /* LWIP_DHCP_MUD_URL */ /* always add the DHCP options trailer to end and pad */ static void dhcp_option_trailer(u16_t options_out_len, u8_t *options, struct pbuf *p_out); @@ -482,6 +485,11 @@ dhcp_select(struct netif *netif) options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif); #endif /* LWIP_NETIF_HOSTNAME */ + +#if LWIP_DHCP_MUD_URL + options_out_len = dhcp_option_mud_url(options_out_len, msg_out->options, LWIP_MUD_URL_STRING); +#endif /* LWIP_DHCP_MUD_URL */ + LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REQUESTING, msg_out, DHCP_REQUEST, &options_out_len); dhcp_option_trailer(options_out_len, msg_out->options, p_out); @@ -1499,6 +1507,31 @@ dhcp_option_hostname(u16_t options_out_len, u8_t *options, struct netif *netif) } #endif /* LWIP_NETIF_HOSTNAME */ +#if LWIP_DHCP_MUD_URL +static u16_t +dhcp_option_mud_url(u16_t options_out_len, u8_t *options, char *mud_url) +{ + size_t mud_url_len = strlen(mud_url); + LWIP_ASSERT("DHCP: MUD URLs must start with https://", + strncmp(mud_url, "https://", 8) == 0); + + size_t option_header_len = sizeof(u8_t) * 2; + size_t len; + const char *p = mud_url; + size_t available = DHCP_OPTIONS_LEN - options_out_len - option_header_len; + LWIP_ASSERT("DHCP: MUD URL is too long!", mud_url_len <= available); + len = LWIP_MIN(mud_url_len, available); + LWIP_ASSERT("DHCP: MUD URL is too long!", len < 0xFF - option_header_len); + options_out_len = dhcp_option(options_out_len, options, DHCP_OPTION_MUD_URL_V4, (u8_t)len); + + while (len--) { + options_out_len = dhcp_option_byte(options_out_len, options, *p++); + } + + return options_out_len; +} +#endif /* LWIP_DHCP_MUD_URL */ + /** * Extract the DHCP message and the DHCP options. * diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index c27dd034..035596d9 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -976,6 +976,13 @@ #if !defined LWIP_DHCP_DISCOVER_ADD_HOSTNAME || defined __DOXYGEN__ #define LWIP_DHCP_DISCOVER_ADD_HOSTNAME 0 #endif /* LWIP_DHCP_DISCOVER_ADD_HOSTNAME */ + +/** + * LWIP_DHCP_MUD_URL == 1: Emit Manufacturer Usage Description (MUD) URL (RFC 8520) via DHCP. + */ +#if !defined LWIP_DHCP_MUD_URL || defined __DOXYGEN__ +#define LWIP_DHCP_MUD_URL 0 +#endif /** * @} */