Also, please make sure to use new mailing list address:
libndp(a)lists.fedorahosted.org
Mon, Dec 11, 2023 at 02:51:08PM CET, mail(a)sandropischinger.de wrote:
>---
>This patch adds support for handling the Captive Portal URI option as
>described in rfc8910. Feel free to tell me a strategy on how to properly
>test this. Ideally some unit-test could be introduced. Best wishes,
>Sandro
> include/ndp.h | 2 ++
> libndp/libndp.c | 38 ++++++++++++++++++++++++++++++++++++++
> libndp/ndp_private.h | 7 +++++++
> 3 files changed, 47 insertions(+)
>
>diff --git a/include/ndp.h b/include/ndp.h
>index 7bf8794..3b3bf92 100644
>--- a/include/ndp.h
>+++ b/include/ndp.h
>@@ -124,6 +124,7 @@ enum ndp_msg_opt_type {
> NDP_MSG_OPT_ROUTE, /* Route Information */
> NDP_MSG_OPT_RDNSS, /* Recursive DNS Server */
> NDP_MSG_OPT_DNSSL, /* DNS Search List */
>+ NDP_MSG_OPT_CAPTIVE_PORTAL, /* Captive Portal URI */
> };
>
> int ndp_msg_next_opt_offset(struct ndp_msg *msg, int offset,
>@@ -175,6 +176,7 @@ char *ndp_msg_opt_dnssl_domain(struct ndp_msg *msg, int offset,
> domain; \
> domain = ndp_msg_opt_dnssl_domain(msg, offset, ++domain_index))
>
>+char *ndp_msg_opt_captive_portal(struct ndp_msg *msg, int offset);
> typedef int (*ndp_msgrcv_handler_func_t)(struct ndp *ndp, struct ndp_msg *msg,
> void *priv);
> int ndp_msgrcv_handler_register(struct ndp *ndp, ndp_msgrcv_handler_func_t func,
>diff --git a/libndp/libndp.c b/libndp/libndp.c
>index 6314717..744fae1 100644
>--- a/libndp/libndp.c
>+++ b/libndp/libndp.c
>@@ -1266,6 +1266,10 @@ static struct ndp_msg_opt_type_info ndp_msg_opt_type_info_list[] =
> .raw_type = __ND_OPT_DNSSL,
> .raw_struct_size = sizeof(struct __nd_opt_dnssl),
> },
>+ [NDP_MSG_OPT_CAPTIVE_PORTAL] = {
>+ .raw_type = __ND_OPT_CAPTIVE_PORTAL,
>+ .raw_struct_size = sizeof(struct __nd_opt_captive_portal),
>+ },
> };
>
> #define NDP_MSG_OPT_TYPE_LIST_SIZE ARRAY_SIZE(ndp_msg_opt_type_info_list)
>@@ -1810,6 +1814,40 @@ char *ndp_msg_opt_dnssl_domain(struct ndp_msg *msg, int offset,
> return NULL;
> }
>
>+/**
>+ * ndp_msg_option_captive_portal:
>+ * @msg: message structure
>+ * @offset: in-message offset
>+ *
>+ * Get Captive-Portal URI.
>+ *
>+ * Returns: uri.
>+ **/
>+NDP_EXPORT
>+char *ndp_msg_opt_captive_portal(struct ndp_msg *msg, int offset)
>+{
>+ static NDP_THREAD char buf[256];
>+ struct __nd_opt_captive_portal *cap_port =
>+ ndp_msg_payload_opts_offset(msg, offset);
>+ size_t len = cap_port->nd_opt_captive_portal_len << 3; /* convert to bytes */
>+ char *ptr;
>+
>+ len -= in_struct_offset(struct __nd_opt_captive_portal, nd_opt_captive_portal_uri);
>+ ptr = cap_port->nd_opt_captive_portal_uri;
>+
>+ if (len + 1 > sizeof(buf)) {
>+ return NULL;
>+ }
>+
>+ if (len > 0 && *ptr) {
>+ memcpy(buf, ptr, len);
>+ buf[len - 1] = '\0';
>+ return buf;
>+ }
>+
>+ return NULL;
>+}
>+
> static int ndp_call_handlers(struct ndp *ndp, struct ndp_msg *msg);
>
> static int ndp_sock_recv(struct ndp *ndp)
>diff --git a/libndp/ndp_private.h b/libndp/ndp_private.h
>index a75587f..bbadff1 100644
>--- a/libndp/ndp_private.h
>+++ b/libndp/ndp_private.h
>@@ -86,6 +86,7 @@ ndp_log_null(struct ndp *ndp, const char *format, ...) {}
> #define __ND_OPT_ROUTE_INFO 24 /* rfc4191 */
> #define __ND_OPT_RDNSS 25 /* rfc6106 */
> #define __ND_OPT_DNSSL 31 /* rfc6106 */
>+#define __ND_OPT_CAPTIVE_PORTAL 37 /* rfc8910 */
>
> struct __nd_opt_route_info { /* route information */
> uint8_t nd_opt_ri_type;
>@@ -112,5 +113,11 @@ struct __nd_opt_dnssl { /* DNS Search List */
> char nd_opt_dnssl_domains[0];
> };
>
>+struct __nd_opt_captive_portal { /* Captive Portal URI */
>+ uint8_t nd_opt_captive_portal_type;
>+ uint8_t nd_opt_captive_portal_len;
>+ char nd_opt_captive_portal_uri[0];
>+};
>+
>
> #endif /* _NDP_PRIVATE_H_ */
>--
>2.43.0
>