1 Star 0 Fork 48

flying-eagle/lwip

forked from src-openEuler/lwip 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0125-add-MCAST_JOIN_SOURCE_GROUP-to-setsockopt-for-mldv2.patch 4.23 KB
一键复制 编辑 原始数据 按行查看 历史
From c822d404bae65db647d7c0ddec4647f8b0cce1e1 Mon Sep 17 00:00:00 2001
From: wanfeng <wanfeng@kylinos.cn>
Date: Tue, 16 Apr 2024 15:23:46 +0800
Subject: [PATCH] add MCAST_JOIN_SOURCE_GROUP to setsockopt for mldv2
---
src/api/sockets.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/src/api/sockets.c b/src/api/sockets.c
index 6b2f5ee..50fa335 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -3976,6 +3976,29 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
}
}
break;
+ case MCAST_JOIN_SOURCE_GROUP:
+ case MCAST_LEAVE_SOURCE_GROUP:
+ LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, struct group_source_req);
+ if ((((const struct group_source_req *)optval)->gsr_group.ss_family != AF_INET6) ||
+ (((const struct group_source_req *)optval)->gsr_source.ss_family != AF_INET6)) {
+ done_socket(sock);
+ return EINVAL;
+ }
+#if LWIP_UDP
+ if (NETCONNTYPE_GROUPV6(netconn_type(sock->conn)) == NETCONN_UDP_IPV6) {
+ err = mcast_sock_join_leave_source_group(s, &sock->conn->pcb.udp->ipmc, optname, (const struct group_source_req *)optval);
+ } else
+#endif /* LWIP_UDP */
+#if LWIP_RAW
+ if (NETCONNTYPE_GROUPV6(netconn_type(sock->conn)) == NETCONN_RAW_IPV6) {
+ err = mcast_sock_join_leave_source_group(s, &sock->conn->pcb.raw->ipmc, optname, (const struct group_source_req *)optval);
+ } else
+#endif /* LWIP_RAW */
+ {
+ done_socket(sock);
+ return ENOPROTOOPT;
+ }
+ break;
#endif /* LWIP_IPV6_MLD */
default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IPV6, UNIMPL: optname=0x%x, ..)\n",
@@ -4869,6 +4892,77 @@ out:
return err_to_errno(err);
}
+/**
+ * setsockopt() MCAST_JOIN_SOURCE_GROUP / MCAST_LEAVE_SOURCE_GROUP command
+ */
+int
+mcast_sock_join_leave_source_group(int s, struct ip_mc *ipmc, int optname, const struct group_source_req *gsr)
+{
+ struct netif *netif;
+ ip_addr_t multi_addr;
+ ip_addr_t src_addr;
+ err_t err;
+ u8_t if_idx;
+
+ if (gsr->gsr_group.ss_family == AF_INET) {
+ inet_addr_to_ip4addr(ip_2_ip4(&multi_addr), &(((struct sockaddr_in *)&(gsr->gsr_group))->sin_addr));
+ inet_addr_to_ip4addr(ip_2_ip4(&src_addr), &(((struct sockaddr_in *)&(gsr->gsr_source))->sin_addr));
+ IP_SET_TYPE_VAL(multi_addr, IPADDR_TYPE_V4);
+ IP_SET_TYPE_VAL(src_addr, IPADDR_TYPE_V4);
+ if (!ip4_addr_ismulticast(ip_2_ip4(&multi_addr)) || ip4_addr_isany(ip_2_ip4(&src_addr))) {
+ return EADDRNOTAVAIL;
+ }
+
+ } else if (gsr->gsr_group.ss_family == AF_INET6) {
+ inet6_addr_to_ip6addr(ip_2_ip6(&multi_addr), &(((struct sockaddr_in6 *)&(gsr->gsr_group))->sin6_addr));
+ inet6_addr_to_ip6addr(ip_2_ip6(&src_addr), &(((struct sockaddr_in6 *)&(gsr->gsr_source))->sin6_addr));
+ IP_SET_TYPE_VAL(multi_addr, IPADDR_TYPE_V6);
+ IP_SET_TYPE_VAL(src_addr, IPADDR_TYPE_V6);
+ if (!ip6_addr_ismulticast(ip_2_ip6(&multi_addr)) || ip6_addr_isany(ip_2_ip6(&src_addr))) {
+ return EADDRNOTAVAIL;
+ }
+
+ } else {
+ return EADDRNOTAVAIL;
+ }
+
+ if (gsr->gsr_interface) {
+ netif = netif_get_by_index((u8_t)gsr->gsr_interface);
+ } else {
+ netif = netif_default; /* To default network interface */
+ }
+ if (netif == NULL) {
+ return ENXIO;
+ }
+
+ if_idx = netif_get_index(netif);
+ if (optname == MCAST_JOIN_SOURCE_GROUP) {
+#if LWIP_IPV4 && LWIP_IGMP
+ if (IP_IS_V4(&multi_addr)) {
+ if (!lwip_socket_register_membership(s, if_idx, ip_2_ip4(&multi_addr))) {
+ /* cannot track membership (out of memory) */
+ err = ENOMEM;
+ goto out;
+ }
+ } else
+#endif
+ {
+#if LWIP_IPV6 && LWIP_IPV6_MLD
+ if (!lwip_socket_register_mld6_membership(s, if_idx, ip_2_ip6(&multi_addr))) {
+ /* cannot track membership (out of memory) */
+ err = ENOMEM;
+ goto out;
+ }
+#endif
+ }
+ err = mcast_join_netif(ipmc, netif, &multi_addr, &src_addr);
+ } else {
+ err = mcast_leave_netif(ipmc, netif, &multi_addr, &src_addr);
+ }
+out:
+ return err_to_errno(err);
+}
+
/**
* setsockopt() IPV6_JOIN_GROUP / IPV6_LEAVE_GROUP command
*/
--
2.25.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/flying-eagle12138/lwip.git
git@gitee.com:flying-eagle12138/lwip.git
flying-eagle12138
lwip
lwip
master

搜索帮助