Re: [lwip-users] IPv6 multicast support by Socket API?

2017-08-16 Thread Andrey Butok
Hi Dirk,

The patch is functional.

But to be fully correct, it should also:
- assign IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP to IPPROTO_IPV6 level (not to
IPPROTO_IP).
- implement analog of the IPv4 IP_MULTICAST_TTL option for the IPv6
Multicast hop limit.

Thank you,
Andrey Butok



--
View this message in context: 
http://lwip.100.n7.nabble.com/IPv6-multicast-support-by-Socket-API-tp30442p30507.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] IPv6 multicast support by Socket API?

2017-08-11 Thread Andrey Butok
Hello Dirk,

I will check your patch and let you know if it works with a real
application.

Thanks,
Andrey




--
View this message in context: 
http://lwip.100.n7.nabble.com/IPv6-multicast-support-by-Socket-API-tp30442p30476.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] IPv6 multicast support by Socket API?

2017-08-10 Thread Dirk Ziegelmeier
"We have task #14394 (Improve socket options) for this"

does not mean that somebody is or will be working on it - it is just there
so the issue is not forgotten.

Have you been able to test my patch?

Dirk
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] IPv6 multicast support by Socket API?

2017-08-10 Thread Andrej Butok
Hi Simon,
It is good that this is known issue and you are going to fix it.

I have discovered another issue but with the IPV6_V6ONLY option.
It was not possible to set this option for UDP sockets. Probably, it was caused 
by copy-paste mistake.

The fix is following (sockets.c, line 2515):
case IPV6_V6ONLY:
#if 0 // BUG FIX
  LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_TCP);
#else
  LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, int);
#endif

Please add it to the task #14394

Thanks,
Andrey Butok

Date: Wed, 9 Aug 2017 21:27:45 +0200
From: "goldsi...@gmx.de" <goldsi...@gmx.de>
To: Mailing list for lwIP users <lwip-users@nongnu.org>
Subject: Re: [lwip-users] IPv6 multicast support by Socket API?

Andrej Butok wrote:
> BUT it looks like the lWIP Sockets does not support IPv6 multicast join/leave.
>
> Did I miss something?

No, you're right. This is not yet done.

> Are you going to add this missing functionality?

We have task #14394 (Improve socket options) for this. I'm not sure when this 
will be done though. Patches would be welcome :-)


Simon


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] IPv6 multicast support by Socket API?

2017-08-09 Thread Dirk Ziegelmeier
Andrey,

can you try my patch and tell me if it works? If not, please try to debug
it, I was not able to test it at home.

TODO: Correctly unregister at socket close, try to fix code duplication
with IGMP.

Ciao
Dirk
diff --git a/src/api/sockets.c b/src/api/sockets.c
index a50faf5..21f6481 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -59,7 +59,9 @@
 #include "lwip/udp.h"
 #include "lwip/memp.h"
 #include "lwip/pbuf.h"
+#include "lwip/netif.h"
 #include "lwip/priv/tcpip_priv.h"
+#include "lwip/mld6.h"
 #if LWIP_CHECKSUM_ON_COPY
 #include "lwip/inet_chksum.h"
 #endif
@@ -234,12 +236,12 @@
 #endif /* LWIP_IPV4 */
 };
 
-#if LWIP_IGMP
 /* Define the number of IPv4 multicast memberships, default is one per socket */
 #ifndef LWIP_SOCKET_MAX_MEMBERSHIPS
 #define LWIP_SOCKET_MAX_MEMBERSHIPS NUM_SOCKETS
 #endif
 
+#if LWIP_IGMP
 /* This is to keep track of IP_ADD_MEMBERSHIP calls to drop the membership when
a socket is closed */
 struct lwip_socket_multicast_pair {
@@ -256,6 +258,25 @@
 static int  lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr);
 static void lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr);
 static void lwip_socket_drop_registered_memberships(int s);
+#endif /* LWIP_IGMP */
+
+#if LWIP_IPV6_MLD
+/* This is to keep track of IP_JOIN_GROUP calls to drop the membership when
+   a socket is closed */
+struct lwip_socket_multicast_mld6_pair {
+  /** the socket */
+  struct lwip_sock* sock;
+  /** the interface index */
+  unsigned int if_idx;
+  /** the group address */
+  ip6_addr_t multi_addr;
+};
+
+struct lwip_socket_multicast_mld6_pair socket_ipv6_multicast_memberships[LWIP_SOCKET_MAX_MEMBERSHIPS];
+
+static int  lwip_socket_register_mld6_membership(int s, unsigned int if_idx, const ip6_addr_t *multi_addr);
+static void lwip_socket_unregister_mld6_membership(int s, unsigned int if_idx, const ip6_addr_t *multi_addr);
+static void lwip_socket_drop_registered_mld6_memberships(int s);
 #endif /* LWIP_IGMP */
 
 /** The global array of available sockets */
@@ -709,6 +730,10 @@
   /* drop all possibly joined IGMP memberships */
   lwip_socket_drop_registered_memberships(s);
 #endif /* LWIP_IGMP */
+#if LWIP_IPV6_MLD
+  /* drop all possibly joined MLD6 memberships */
+  lwip_socket_drop_registered_mld6_memberships(s);
+#endif /* LWIP_IPV6_MLD */
 
   err = netconn_delete(sock->conn);
   if (err != ERR_OK) {
@@ -3053,7 +3078,6 @@
 case IP_DROP_MEMBERSHIP:
   {
 /* If this is a TCP or a RAW socket, ignore these options. */
-/* @todo: assign membership to this socket so that it is dropped when closing the socket */
 err_t igmp_err;
 const struct ip_mreq *imr = (const struct ip_mreq *)optval;
 ip4_addr_t if_addr;
@@ -3079,6 +3103,41 @@
   }
   break;
 #endif /* LWIP_IGMP */
+#if LWIP_IPV6_MLD
+case IPV6_JOIN_GROUP:
+case IPV6_LEAVE_GROUP:
+  {
+/* If this is a TCP or a RAW socket, ignore these options. */
+err_t mld6_err;
+struct netif *netif;
+ip6_addr_t multi_addr;
+const struct ipv6_mreq *imr = (const struct ipv6_mreq *)optval;
+LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct ipv6_mreq, NETCONN_UDP);
+inet6_addr_to_ip6addr(_addr, >ipv6mr_multiaddr);
+netif = netif_get_by_index(imr->ipv6mr_interface);
+if (netif == NULL) {
+  err = EADDRNOTAVAIL;
+  break;
+}
+
+if (optname == IPV6_JOIN_GROUP) {
+  if (!lwip_socket_register_mld6_membership(s, imr->ipv6mr_interface, _addr)) {
+/* cannot track membership (out of memory) */
+err = ENOMEM;
+mld6_err = ERR_OK;
+  } else {
+mld6_err = mld6_joingroup_netif(netif, _addr);
+  }
+} else {
+  mld6_err = mld6_leavegroup_netif(netif, _addr);
+  lwip_socket_unregister_mld6_membership(s, imr->ipv6mr_interface, _addr);
+}
+if (mld6_err != ERR_OK) {
+  err = EADDRNOTAVAIL;
+}
+  }
+  break;
+#endif /* LWIP_IPV6_MLD */
 default:
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n",
   s, optname));
@@ -3558,4 +3617,98 @@
   done_socket(sock);
 }
 #endif /* LWIP_IGMP */
+
+#if LWIP_IPV6_MLD
+/** Register a new MLD6 membership. On socket close, the membership is dropped automatically.
+ *
+ * ATTENTION: this function is called from tcpip_thread (or under CORE_LOCK).
+ *
+ * @return 1 on success, 0 on failure
+ */
+static int
+lwip_socket_register_mld6_membership(int s, unsigned int if_idx, const ip6_addr_t *multi_addr)
+{
+  struct lwip_sock *sock = get_socket(s);
+  int i;
+
+  if (!sock) {
+return 0;
+  }
+
+  for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
+if (socket_ipv6_multicast_memberships[i].sock == NULL) {
+  socket_ipv6_multicast_memberships[i].sock   = sock;

[lwip-users] IPv6 multicast support by Socket API?

2017-08-09 Thread Andrej Butok
Hello lwIP developers,

I am using latest  lwIP 2.0.2.
My application have to use lwIP Socket user API and FreeRTOS. And It have to 
join IPv4 and IPv6 multicast groups.
The IPv4 Multicast is supported very well via  the IP_ADD_MEMBERSHIP / 
IP_DROP_MEMBERSHIP socket options.
BUT it looks like the lWIP Sockets does not support IPv6 multicast join/leave.

Did I miss something?
Are you going to add this missing functionality? 
Any suggestion how to work around this issue now?

Thank you,
Andrey

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users