[PATCH 21/44] net: move netmask_to_prefix into header
Ahmad Fatoum
a.fatoum at barebox.org
Mon Aug 11 05:28:01 PDT 2025
This function will become useful for the bfetch command, so move it into
the header.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
commands/ip.c | 13 -------------
include/net.h | 13 +++++++++++++
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/commands/ip.c b/commands/ip.c
index fc46b6c857a2..08848cfbe739 100644
--- a/commands/ip.c
+++ b/commands/ip.c
@@ -7,19 +7,6 @@
#include <linux/list.h>
#include <complete.h>
-/* Function to calculate CIDR prefix from netmask */
-static int netmask_to_prefix(IPaddr_t netmask)
-{
- int prefix = 0;
-
- while (netmask) {
- prefix += netmask & 1;
- netmask >>= 1;
- }
-
- return prefix;
-}
-
/* Function to display network links (`ip l`) */
static int do_ip_link(int argc, char *argv[])
{
diff --git a/include/net.h b/include/net.h
index 8858dc34d4ea..43d718353a76 100644
--- a/include/net.h
+++ b/include/net.h
@@ -623,4 +623,17 @@ struct eth_ethaddr {
extern struct list_head ethaddr_list;
+/* Function to calculate CIDR prefix from netmask */
+static inline int netmask_to_prefix(IPaddr_t netmask)
+{
+ int prefix = 0;
+
+ while (netmask) {
+ prefix += netmask & 1;
+ netmask >>= 1;
+ }
+
+ return prefix;
+}
+
#endif /* __NET_H__ */
--
2.39.5
More information about the barebox
mailing list