dhcp: add MUD URL implementation

This commit is contained in:
Jan Romann 2021-12-10 15:38:51 +01:00 committed by Jan Romann
parent 5571762829
commit b633639621
2 changed files with 40 additions and 0 deletions

View File

@ -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.
*

View File

@ -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
/**
* @}
*/