From dde1e89b8c78733b5b97b8fd27a1844e71edac42 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 31 Oct 2018 14:10:19 -0600 Subject: [PATCH] net/mld: Add basic build structure for Multicast Listener Discovery (MLD). No real MLD logic yet. Only a few hooks to capture and dispatch MLD ICMPv6 packets. --- include/nuttx/net/icmpv6.h | 6 +- include/nuttx/net/mld.h | 1 + net/Kconfig | 1 + net/Makefile | 1 + net/README.txt | 1 + net/icmpv6/icmpv6_input.c | 75 +++++++++++++++++++ net/mld/Kconfig | 18 +++++ net/mld/Make.defs | 47 ++++++++++++ net/mld/mld.h | 149 +++++++++++++++++++++++++++++++++++++ net/net_initialize.c | 7 ++ net/netlink/netlink.h | 2 +- 11 files changed, 304 insertions(+), 4 deletions(-) create mode 100644 net/mld/Kconfig create mode 100644 net/mld/Make.defs create mode 100644 net/mld/mld.h diff --git a/include/nuttx/net/icmpv6.h b/include/nuttx/net/icmpv6.h index fe51067730..33e75bdb69 100644 --- a/include/nuttx/net/icmpv6.h +++ b/include/nuttx/net/icmpv6.h @@ -71,9 +71,9 @@ #define ICMPv6_RESERVED_ERROR_MSG 127 #define ICMPv6_ECHO_REQUEST 128 #define ICMPv6_ECHO_REPLY 129 -#define ICMPV6_MCAST_LISTEN_QUERY 130 /* RFC 2710 */ -#define ICMPV6_MCAST_LISTEN_REPORT 131 -#define ICMPV6_MCAST_LISTEN_DONE 132 +#define ICMPV6_MCAST_LISTEN_QUERY 130 /* RFC 2710 and 3810 */ +#define ICMPV6_MCAST_LISTEN_REPORT_V1 131 /* RFC 2710 */ +#define ICMPV6_MCAST_LISTEN_DONE_V1 132 /* RFC 2710 */ #define ICMPV6_ROUTER_SOLICIT 133 /* RFC 4861 */ #define ICMPV6_ROUTER_ADVERTISE 134 #define ICMPv6_NEIGHBOR_SOLICIT 135 diff --git a/include/nuttx/net/mld.h b/include/nuttx/net/mld.h index e934928ac3..5642da9380 100644 --- a/include/nuttx/net/mld.h +++ b/include/nuttx/net/mld.h @@ -1,5 +1,6 @@ /**************************************************************************** * include/nuttx/net/mld.h + * Multicast Listener Discovery (MLD) Definitions * * Copyright (C) 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/net/Kconfig b/net/Kconfig index 492beeaa6f..52b686acd7 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -306,6 +306,7 @@ source "net/bluetooth/Kconfig" source "net/ieee802154/Kconfig" source "net/icmp/Kconfig" source "net/icmpv6/Kconfig" +source "net/mld/Kconfig" source "net/igmp/Kconfig" source "net/arp/Kconfig" source "net/loopback/Kconfig" diff --git a/net/Makefile b/net/Makefile index 2e50dbefb8..dfdbbb97f7 100644 --- a/net/Makefile +++ b/net/Makefile @@ -65,6 +65,7 @@ include neighbor/Make.defs include igmp/Make.defs include pkt/Make.defs include local/Make.defs +include mld/Make.defs include netlink/Make.defs include tcp/Make.defs include udp/Make.defs diff --git a/net/README.txt b/net/README.txt index c1fa72eab0..98d1b6d27a 100644 --- a/net/README.txt +++ b/net/README.txt @@ -18,6 +18,7 @@ Directory Structure +- ipforward - IP forwarding logic +- local - Unix domain (local) sockets +- loopback - Local loopback + +- mld - Multicast Listener Discovery (MLD) +- neighbor - Neighbor Discovery Protocol (IPv6) +- netdev - Socket network device interface +- netlink - Netlink IPC socket interface diff --git a/net/icmpv6/icmpv6_input.c b/net/icmpv6/icmpv6_input.c index 38b7b1885b..385ca260d1 100644 --- a/net/icmpv6/icmpv6_input.c +++ b/net/icmpv6/icmpv6_input.c @@ -57,6 +57,7 @@ #include "neighbor/neighbor.h" #include "utils/utils.h" #include "icmpv6/icmpv6.h" +#include "mld/mld.h" #ifdef CONFIG_NET_ICMPv6 @@ -82,6 +83,15 @@ #define ICMPv6RADVERTISE \ ((struct icmpv6_router_advertise_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) +#define MLDQUEURY \ + ((FAR struct mld_mcast_listen_query_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) +#define MLDREPORT_V1 \ + ((FAR struct mld_mcast_listen_report_v1_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) +#define MLDREPORT_V2 \ + ((FAR struct mld_mcast_listen_report_v2_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) +#define MLDDONE_V1 \ + ((FAR struct mld_mcast_listen_done_v1_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -475,6 +485,71 @@ void icmpv6_input(FAR struct net_driver_s *dev) break; #endif +#ifdef CONFIG_NET_MLD + /* Dispatch received Multicast Listener Discovery (MLD) packets. */ + + case ICMPV6_MCAST_LISTEN_QUERY: /* Multicast Listener Query, RFC 2710 and RFC 3810 */ + { + FAR struct mld_mcast_listen_query_s *query = MLDQUEURY; + int ret; + + ret = mld_query_input(dev, query); + if (ret < 0) + { + goto icmpv6_drop_packet; + } + + goto icmpv6_send_nothing; /* REVISIT */ + } + break; + + case ICMPV6_MCAST_LISTEN_REPORT_V1: /* Version 1 Multicast Listener Report, RFC 2710 */ + { + FAR struct mld_mcast_listen_report_v1_s *report = MLDREPORT_V1; + int ret; + + ret = mld_report_v1(dev, report); + if (ret < 0) + { + goto icmpv6_drop_packet; + } + + goto icmpv6_send_nothing; /* REVISIT */ + } + break; + + + case ICMPV6_MCAST_LISTEN_REPORT_V2: /* Version 2 Multicast Listener Report, RFC 3810 */ + { + FAR struct mld_mcast_listen_report_v2_s *report = MLDREPORT_V2; + int ret; + + ret = mld_report_v2(dev, report); + if (ret < 0) + { + goto icmpv6_drop_packet; + } + + goto icmpv6_send_nothing; /* REVISIT */ + } + break; + + case ICMPV6_MCAST_LISTEN_DONE_V1: /* Version 1 Multicast Listener Done, RFC 2710 */ + { + FAR struct mld_mcast_listen_done_v1_s *done = MLDDONE_V1; + int ret; + + ret = mld_done_v1(dev, done); + if (ret < 0) + { + goto icmpv6_drop_packet; + } + + goto icmpv6_send_nothing; /* REVISIT */ + } + break; +#endif + default: { nwarn("WARNING: Unknown ICMPv6 type: %d\n", ipicmp->type); diff --git a/net/mld/Kconfig b/net/mld/Kconfig new file mode 100644 index 0000000000..a19b70ef00 --- /dev/null +++ b/net/mld/Kconfig @@ -0,0 +1,18 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if NET_ICMPv6 + +menuconfig NET_MLD + bool "Multicast Listener Discovery (MLD)" + default n + depends on EXPERIMENTAL + ---help--- + Enable Multicast Listener Discovery (MLD) support. + +if NET_MLD + +endif # NET_MLD +endif # NET_ICMPv6 diff --git a/net/mld/Make.defs b/net/mld/Make.defs new file mode 100644 index 0000000000..4e90232b27 --- /dev/null +++ b/net/mld/Make.defs @@ -0,0 +1,47 @@ +############################################################################ +# net/mld/Make.defs +# +# Copyright (C) 2018 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Logic specific to Multicast Listener Discovery (MLD) + +ifeq ($(CONFIG_NET_MLD),y) + +SOCK_CSRCS += +NET_CSRCS += + +# Include MLD build support + +DEPPATH += --dep-path mld +VPATH += :mld +endif diff --git a/net/mld/mld.h b/net/mld/mld.h new file mode 100644 index 0000000000..412c068eed --- /dev/null +++ b/net/mld/mld.h @@ -0,0 +1,149 @@ +/**************************************************************************** + * net/mld/mld.h + * Multicast Listener Discovery (MLD) Definitions + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NET_NETLINK_MLD_H +#define __NET_NETLINK_MLD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "devif/devif.h" +#include "socket/socket.h" + +#ifdef CONFIG_NET_MLD + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +# define EXTERN extern "C" +extern "C" +{ +#else +# define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +struct net_driver_s; /* Forward reference */ +struct mld_mcast_listen_query_s; /* Forward reference */ +struct mld_mcast_listen_report_v1_s; /* Forward reference */ +struct mld_mcast_listen_report_v2_s; /* Forward reference */ +struct mld_mcast_listen_done_v1_s; /* Forward reference */ + +/**************************************************************************** + * Name: mld_initialize() + * + * Description: + * Initialize the MLD structures. Called once and only from the + * networking layer. + * + ****************************************************************************/ + +void mld_initialize(void); + +/**************************************************************************** + * Name: mld_query + * + * Description: + * Called from icmpv6_input() when a Multicast Listener Query is received. + * + ****************************************************************************/ + +int mld_query_input(FAR struct net_driver_s *dev, + FAR const struct mld_mcast_listen_query_s *query); + +/**************************************************************************** + * Name: mld_report_v1 + * + * Description: + * Called from icmpv6_input() when a Version 1 Multicast Listener Report is + * received. + * + ****************************************************************************/ + +int mld_report_v1(FAR struct net_driver_s *dev, + FAR const struct mld_mcast_listen_report_v1_s *report); + +/**************************************************************************** + * Name: mld_report_v2 + * + * Description: + * Called from icmpv6_input() when a Version 2 Multicast Listener Report is + * received. + * + ****************************************************************************/ + +int mld_report_v2(FAR struct net_driver_s *dev, + FAR const struct mld_mcast_listen_report_v2_s *report); + +/**************************************************************************** + * Name: mld_done_v1 + * + * Description: + * Called from icmpv6_input() when a Version 1 Multicast Listener Done is + * received. + * + ****************************************************************************/ + +int mld_done_v1(FAR struct net_driver_s *dev, + FAR const struct mld_mcast_listen_done_v1_s *done); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_NET_MLD */ +#endif /* __NET_NETLINK_MLD_H */ diff --git a/net/net_initialize.c b/net/net_initialize.c index 036cdd2c88..8cbcecaf08 100644 --- a/net/net_initialize.c +++ b/net/net_initialize.c @@ -54,6 +54,7 @@ #include "neighbor/neighbor.h" #include "icmp/icmp.h" #include "icmpv6/icmpv6.h" +#include "mld/mld.h" #include "tcp/tcp.h" #include "udp/udp.h" #include "pkt/pkt.h" @@ -108,6 +109,12 @@ void net_setup(void) neighbor_initialize(); +#ifdef CONFIG_NET_MLD + /* Initialize ICMPv6 Multicast Listener Discovery (MLD) logic */ + + mld_initialize(); +#endif + #ifdef CONFIG_NET_6LOWPAN /* Initialize 6LoWPAN data structures */ diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h index 2dfe8024e7..971047f628 100644 --- a/net/netlink/netlink.h +++ b/net/netlink/netlink.h @@ -91,7 +91,7 @@ EXTERN const struct sock_intf_s g_netlink_sockif; * Name: netlink_initialize() * * Description: - * Initialize the User Socket connection structures. Called once and only + * Initialize the NetLink connection structures. Called once and only * from the networking layer. * ****************************************************************************/