diff --git a/0154-add-IP_MSFILTER-to-setsockopt-for-IGMPv3.patch b/0154-add-IP_MSFILTER-to-setsockopt-for-IGMPv3.patch new file mode 100644 index 0000000000000000000000000000000000000000..23d8c3fd3449a2703970a75e1b8df013742f47b7 --- /dev/null +++ b/0154-add-IP_MSFILTER-to-setsockopt-for-IGMPv3.patch @@ -0,0 +1,157 @@ +From 3e2fcbbc17e5fd7386d54542d29416185b628038 Mon Sep 17 00:00:00 2001 +From: wanfeng +Date: Thu, 11 Jul 2024 14:01:55 +0800 +Subject: [PATCH] add IP_MSFILTER to setsockopt for IGMPv3 of IPv4 + +--- + src/api/sockets.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 113 insertions(+) + +diff --git a/src/api/sockets.c b/src/api/sockets.c +index ae14407..d82cb4e 100644 +--- a/src/api/sockets.c ++++ b/src/api/sockets.c +@@ -3871,6 +3871,23 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ + if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_RAW) { + err = mcast_sock_add_drop_source_membership(s, &sock->conn->pcb.raw->ipmc, optname, (const struct ip_mreq_source *)optval); + } else ++#endif /* LWIP_RAW */ ++ { ++ done_socket(sock); ++ return ENOPROTOOPT; ++ } ++ break; ++ case IP_MSFILTER: ++ LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, struct ip_msfilter); ++#if LWIP_UDP ++ if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_UDP) { ++ err = mcast_sock_set_msfilter(&sock->conn->pcb.udp->ipmc, optname, (const struct ip_msfilter *)optval); ++ } else ++#endif /* LWIP_UDP */ ++#if LWIP_RAW ++ if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_RAW) { ++ err = mcast_sock_set_msfilter(&sock->conn->pcb.raw->ipmc, optname, (const struct ip_msfilter *)optval); ++ } else + #endif /* LWIP_RAW */ + { + done_socket(sock); +@@ -4771,6 +4788,58 @@ lwip_socket_drop_registered_mld6_memberships(int s) + } + #endif /* LWIP_IPV6_MLD */ + ++#if LWIP_SOCKET ++/** Set filter to a multicast group (ip_msfilter) ++ * ++ * @param ipmc multicast filter control block ++ * @param netif the network interface which group we already join. ++ * @param multi_addr the address of the group to add source ++ * @param imsf filter ++ * @return lwIP error definitions ++ */ ++err_t ++mcast_set_msfilter_netif(struct ip_mc *ipmc, struct netif *netif, const ip_addr_t *multi_addr, const struct ip_msfilter *imsf) ++{ ++#if LWIP_IPV4 && LWIP_IGMP ++ if (IP_IS_V4(multi_addr)) { ++ struct ip4_mc *mc; ++ struct igmp_src *src, *head = NULL; ++ u32_t i; ++ ++ if (imsf->imsf_numsrc > LWIP_MCAST_SRC_TBL_SIZE) { ++ return ERR_VAL; ++ } ++ mc = mcast_ip4_mc_find(ipmc, netif, ip_2_ip4(multi_addr), NULL); ++ if (mc == NULL) { ++ return ERR_VAL; ++ } ++ ++ for (i = 0; i < imsf->imsf_numsrc; i++) { ++ src = (struct igmp_src *)mem_malloc(sizeof(struct igmp_src)); ++ if (src == NULL) { ++ mcast_ip4_mc_src_remove(head); ++ return ERR_MEM; ++ } ++ inet_addr_to_ip4addr(&src->src_addr, &imsf->imsf_slist[i]); ++ src->next = head; ++ head = src; ++ mc->num_src++; ++ } ++ ++ mc->fmode = (u8_t)imsf->imsf_fmode; ++ mcast_ip4_mc_src_remove(mc->src); ++ mc->src = head; ++ IP4_MC_TRIGGER_CALL(netif, ip_2_ip4(multi_addr)); /* trigger a report */ ++ } else ++#endif /* LWIP_IPV4 && LWIP_IGMP */ ++ { ++#if LWIP_IPV6 && LWIP_IPV6_MLD ++ return EADDRNOTAVAIL; ++#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ ++ } ++ return ERR_OK; ++} ++ + /** Set filter to a multicast group (group_filter) + * + * @param ipmc multicast filter control block +@@ -4842,6 +4911,7 @@ mcast_set_groupfilter_netif(struct ip_mc *ipmc, struct netif *netif, const ip_ad + } + return ERR_OK; + } ++#endif /* LWIP_SOCKET */ + + /** Remove multicast filter when pcb remove + * +@@ -5114,6 +5184,49 @@ out: + return err_to_errno(err); + } + ++/** ++ * setsockopt() IP_MSFILTER command ++ */ ++int ++mcast_sock_set_msfilter(struct ip_mc *ipmc, int optname, const struct ip_msfilter *imsf) ++{ ++ struct netif *netif; ++ ip_addr_t if_addr; ++ ip_addr_t multi_addr; ++ ++ LWIP_UNUSED_ARG(optname); ++ ++ inet_addr_to_ip4addr(ip_2_ip4(&if_addr), &imsf->imsf_interface); ++ inet_addr_to_ip4addr(ip_2_ip4(&multi_addr), &imsf->imsf_multiaddr); ++ IP_SET_TYPE_VAL(if_addr, IPADDR_TYPE_V4); ++ IP_SET_TYPE_VAL(multi_addr, IPADDR_TYPE_V4); ++ ++ if (!ip4_addr_ismulticast(ip_2_ip4(&multi_addr))) { ++ return EADDRNOTAVAIL; ++ } ++ ++ if (!(ip_2_ip4(&if_addr)->addr & PP_HTONL(IP_CLASSA_NET))) { /* IS a BSD style index ? */ ++ u8_t idx = (u8_t)PP_NTOHL(ip_2_ip4(&if_addr)->addr); ++ netif = netif_get_by_index(idx); ++ if (netif == NULL) { ++ return ENXIO; ++ } ++ *ip_2_ip4(&if_addr) = *netif_ip4_addr(netif); ++ ++ } else { ++ NETIF_FOREACH(netif) { ++ if (ip4_addr_cmp(ip_2_ip4(&if_addr), netif_ip4_addr(netif))) { ++ break; ++ } ++ } ++ if (netif == NULL) { ++ return ENXIO; ++ } ++ } ++ ++ return err_to_errno(mcast_set_msfilter_netif(ipmc, netif, &multi_addr, imsf)); ++} ++ + /** + * setsockopt() MCAST_JOIN_GROUP / MCAST_LEAVE_GROUP command + */ +-- +2.25.1 + diff --git a/lwip.spec b/lwip.spec index a66c4a7bbec072a9e0b2c49d5a1f5947ce147725..4833bc2333e4074017081fea437dc720cde83273 100644 --- a/lwip.spec +++ b/lwip.spec @@ -4,7 +4,7 @@ Summary: lwip is a small independent implementation of the TCP/IP protocol suite Name: lwip Version: 2.2.0 -Release: 45 +Release: 46 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -165,6 +165,7 @@ Patch9149: 0150-cleancode-refactor-posix_api.patch Patch9150: 0151-cleancode-refactor-lwipgz_list.h.patch Patch9151: 0152-cleancode-refactor-lwipgz_hlist.h.patch Patch9152: 0153-cleancode-move-options-from-opt.h-to-lwipopts.h.patch +Patch9153: 0154-add-IP_MSFILTER-to-setsockopt-for-IGMPv3.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -194,6 +195,9 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Fri Jul 19 2024 wanfeng - 2.2.0-46 +- add IP_MSFILTER to setsockopt for IGMPv3 of IPv4 + * Thu Jul 18 2024 LemmyHuang - 2.2.0-45 - cleancode: move options from opt.h to lwipopts.h