From ae162903ab65eaeb65ea2e18db75408ceb86c298 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 5 Dec 2024 11:53:56 +0000 Subject: [PATCH] LwIP: Support Server Multicast registration --- examples/lwip/Makefile | 3 ++- examples/lwip/config/lwipopts.h | 11 ++++++++++- examples/lwip/server.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/examples/lwip/Makefile b/examples/lwip/Makefile index 5bbadc95ad..b7b556d2f3 100644 --- a/examples/lwip/Makefile +++ b/examples/lwip/Makefile @@ -105,7 +105,8 @@ CFLAGS += -Ilwip/src/include/ -Ilwip/src/include/ipv4/ \ LWIP_SRC = def.c init.c tapif.c etharp.c netif.c timeouts.c stats.c udp.c \ tcp.c pbuf.c ip4_addr.c ip4.c inet_chksum.c tcp_in.c tcp_out.c \ - icmp.c raw.c ip4_frag.c sys_arch.c ethernet.c ip.c mem.c memp.c tcpip.c + icmp.c raw.c ip4_frag.c sys_arch.c ethernet.c ip.c mem.c memp.c \ + igmp.c tcpip.c vpath %.c lwip/src/core/ lwip/contrib/ports/unix/proj/minimal/ \ lwip/src/netif/ lwip/src/core/ipv4/ lwip/contrib/ports/unix/port/ \ lwip/contrib/ports/unix/port/netif/ lwip/src/api/ diff --git a/examples/lwip/config/lwipopts.h b/examples/lwip/config/lwipopts.h index 78bdea24a6..9361c13fe1 100644 --- a/examples/lwip/config/lwipopts.h +++ b/examples/lwip/config/lwipopts.h @@ -27,12 +27,21 @@ #define LWIP_IPV6 1 #define LWIP_IPV6_REASS 0 -#define LWIP_IPV6_MLD 0 #define LWIP_ICMP6 (LWIP_IPV6==1) /* Set to 1 if TCP support is required */ #define LWIP_TCP 0 +#if LWIP_IPV4 +/* Set to 1 if Multicast registration support is required for IPv4 */ +#define LWIP_IGMP 0 +#endif + +#if LWIP_IPV6 +/* Set to 1 if Multicast registration support is required for IPv6 */ +#define LWIP_IPV6_MLD 0 +#endif + #ifndef netif_get_index #define netif_get_index(netif) ((u8_t)((netif)->num + 1)) #endif diff --git a/examples/lwip/server.c b/examples/lwip/server.c index 91662156b1..356a4788de 100644 --- a/examples/lwip/server.c +++ b/examples/lwip/server.c @@ -38,6 +38,12 @@ #include #include +#if LWIP_IGMP && LWIP_IPV4 +#include +#endif /* LWIP_IGMP && LWIP_IPV4 */ +#if LWIP_IPV6_MLD && LWIP_IPV6 +#include +#endif /* LWIP_IPV6_MLD && LWIP_IPV6 */ #include #include @@ -46,8 +52,17 @@ #if LWIP_IPV4 static ip4_addr_t ipaddr, netmask, gw; +#if LWIP_IGMP +static ip4_addr_t v4group; +#endif /* LWIP_IGMP */ #endif /* LWIP_IPV4 */ +#if LWIP_IPV6 +#if LWIP_IPV6_MLD +static ip6_addr_t v6group; +#endif /* LWIP_IPV6_MLD */ +#endif /* LWIP_IPV6 */ + static int quit = 0; void @@ -100,7 +115,13 @@ main(int argc, char **argv) { IP4_ADDR(&gw, 192,168,113,1); IP4_ADDR(&ipaddr, 192,168,113,2); IP4_ADDR(&netmask, 255,255,255,0); +#if LWIP_IGMP + IP4_ADDR(&v4group, 224,0,1,187); +#endif /* LWIP_IGMP */ #endif /* LWIP_IPV4 */ +#if LWIP_IPV6_MLD + IP6_ADDR(&v6group, PP_HTONL(0xff020000),0,0,PP_HTONL(0xfd)); +#endif /* LWIP_IPV6_MLD */ #if NO_SYS lwip_init(); @@ -120,6 +141,11 @@ main(int argc, char **argv) { netif_set_up(&netif); #if LWIP_IPV4 printf("IP4 %s\n", ip4addr_ntoa(ip_2_ip4(&netif.ip_addr))); +#if LWIP_IGMP + if (igmp_joingroup_netif(&netif, &v4group) == ERR_OK) { + printf("mIP4 %s\n", ip4addr_ntoa(&v4group)); + } +#endif /* LWIP_IGMP */ #endif /* LWIP_IPV4 */ #if LWIP_IPV6 netif_create_ip6_linklocal_address(&netif, 1); @@ -128,6 +154,11 @@ main(int argc, char **argv) { #else /* ! LWIP_IPV4 */ printf("IP6 [%s]\n", ip6addr_ntoa(&netif.ip6_addr[0].addr)); #endif /* ! LWIP_IPV4 */ +#if LWIP_IPV6_MLD + if (mld6_joingroup_netif(&netif, &v6group) == ERR_OK) { + printf("mIP6 [%s]\n", ip6addr_ntoa(&v6group)); + } +#endif /* LWIP_IPV6_MLD */ #endif /* LWIP_IPV6 */ /* start applications here */