This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new c44834fb920 nuttx/net: Expose the net_ipv6addr_maskcmp interface to 
user-mode calls
c44834fb920 is described below

commit c44834fb9209fc995bd13fb3c72363e4f71fe946
Author: zhangshuai39 <[email protected]>
AuthorDate: Fri Feb 7 17:01:33 2025 +0800

    nuttx/net: Expose the net_ipv6addr_maskcmp interface to user-mode calls
    
    This interface needs to be called in the libc library, but the interface is 
implemented in the kernel, so this interface needs to be exposed
    
    Signed-off-by: zhangshuai39 <[email protected]>
---
 include/nuttx/net/ip.h       | 27 +++++++++++++--
 net/utils/CMakeLists.txt     |  2 +-
 net/utils/Make.defs          |  2 +-
 net/utils/net_ipv6_maskcmp.c | 80 --------------------------------------------
 4 files changed, 26 insertions(+), 85 deletions(-)

diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h
index fca8a3038e5..f810127d9bc 100644
--- a/include/nuttx/net/ip.h
+++ b/include/nuttx/net/ip.h
@@ -592,9 +592,30 @@ extern "C"
 #endif
 
 #ifdef CONFIG_NET_IPv6
-bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
-                          const net_ipv6addr_t addr2,
-                          const net_ipv6addr_t mask);
+static inline_function bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
+                                                 const net_ipv6addr_t addr2,
+                                                 const net_ipv6addr_t mask)
+{
+  int i;
+
+  /* Start from the "bottom" where the addresses will most likely differ */
+
+  for (i = 7; i >= 0; i--)
+    {
+      /* Same? */
+
+      if ((addr1[i] & mask[i]) != (addr2[i] & mask[i]))
+        {
+          /* No.. the addresses are different */
+
+          return false;
+        }
+    }
+
+  /* The addresses are the same */
+
+  return true;
+}
 #endif
 
 /****************************************************************************
diff --git a/net/utils/CMakeLists.txt b/net/utils/CMakeLists.txt
index a960501fdbd..edde35684c9 100644
--- a/net/utils/CMakeLists.txt
+++ b/net/utils/CMakeLists.txt
@@ -39,7 +39,7 @@ set(SRCS
 # IPv6 utilities
 
 if(CONFIG_NET_IPv6)
-  list(APPEND SRCS net_ipv6_maskcmp.c net_ipv6_pref2mask.c net_ipv6_payload.c)
+  list(APPEND SRCS net_ipv6_pref2mask.c net_ipv6_payload.c)
 endif()
 
 # TCP utilities
diff --git a/net/utils/Make.defs b/net/utils/Make.defs
index a279cd22151..2a7ce45940e 100644
--- a/net/utils/Make.defs
+++ b/net/utils/Make.defs
@@ -30,7 +30,7 @@ NET_CSRCS += net_bufpool.c
 # IPv6 utilities
 
 ifeq ($(CONFIG_NET_IPv6),y)
-NET_CSRCS += net_ipv6_maskcmp.c net_ipv6_pref2mask.c net_ipv6_payload.c
+NET_CSRCS += net_ipv6_pref2mask.c net_ipv6_payload.c
 endif
 
 # TCP utilities
diff --git a/net/utils/net_ipv6_maskcmp.c b/net/utils/net_ipv6_maskcmp.c
deleted file mode 100644
index 968bcf2a1d3..00000000000
--- a/net/utils/net_ipv6_maskcmp.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
- * net/utils/net_ipv6_maskcmp.c
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <nuttx/net/ip.h>
-
-#ifdef CONFIG_NET_IPv6
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: net_ipv6addr_maskcmp
- *
- * Description:
- *   Compare two IPv6 addresses under a netmask.  The mask is used to mask
- *   out the bits that are to be compared:  Buts within the mask much
- *   match exactly; bits outside if the mask are ignored.
- *
- * Input Parameters:
- *   addr1 - The first IP address.
- *   addr2 - The second IP address.
- *   mask  - The netmask.
- *
- * Returned Value:
- *   True if the address under the mask are equal
- *
- ****************************************************************************/
-
-bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
-                          const net_ipv6addr_t addr2,
-                          const net_ipv6addr_t mask)
-{
-  int i;
-
-  /* Start from the "bottom" where the addresses will most likely differ */
-
-  for (i = 7; i >= 0; i--)
-    {
-      /* Same? */
-
-      if ((addr1[i] & mask[i]) != (addr2[i] & mask[i]))
-        {
-          /* No.. the addresses are different */
-
-          return false;
-        }
-    }
-
-  /* The addresses are the same */
-
-  return true;
-}
-
-#endif /* CONFIG_NET_IPv6 */

Reply via email to