From 174f7d9d959bd129675651ccf7ef460794188b63 Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Wed, 5 Jun 2024 10:40:22 +0800
Subject: [PATCH 104/108] bugfix:adapt network name max len

Signed-off-by: liuxu <liuxu156@huawei.com>
---
 CI/test_cases/network_cases/network_create.sh | 5 +++--
 src/utils/cutils/utils.h                      | 7 ++++++-
 test/cutils/utils_network/utils_network_ut.cc | 4 ++--
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/CI/test_cases/network_cases/network_create.sh b/CI/test_cases/network_cases/network_create.sh
index 3107da12..da54fdd0 100755
--- a/CI/test_cases/network_cases/network_create.sh
+++ b/CI/test_cases/network_cases/network_create.sh
@@ -33,8 +33,9 @@ function test_network_create()
     local name1="cni1"
     local name2="cni2"
     local name3="a"
-    for i in $(seq 1 7);do
-        name3=${name3}${name3}
+    local basechar="a"
+    for i in $(seq 1 199);do
+        name3=${name3}${basechar}
     done
     local name4=${name3}b
     local invalid_name=".xx"
diff --git a/src/utils/cutils/utils.h b/src/utils/cutils/utils.h
index 4417a165..ce0ca703 100644
--- a/src/utils/cutils/utils.h
+++ b/src/utils/cutils/utils.h
@@ -99,7 +99,12 @@ int malloc_trim(size_t pad);
 #define MAX_IMAGE_REF_LEN 384
 #define MAX_CONTAINER_NAME_LEN 1024
 #define MAX_RUNTIME_NAME_LEN 32
-#define MAX_NETWORK_NAME_LEN 255
+/* 
+ * Linux limits the length of the file name to 255,
+ * isulad will create file by name "${ISULAD_CNI_NETWORK_CONF_FILE_PRE}${network_name}.conflist"
+ * when create native network,so we limit the length of the network name to 200.
+ */
+#define MAX_NETWORK_NAME_LEN 200
 
 #define LOGIN_USERNAME_LEN 255
 #define LOGIN_PASSWORD_LEN 255
diff --git a/test/cutils/utils_network/utils_network_ut.cc b/test/cutils/utils_network/utils_network_ut.cc
index 68f6f011..be85e398 100644
--- a/test/cutils/utils_network/utils_network_ut.cc
+++ b/test/cutils/utils_network/utils_network_ut.cc
@@ -344,8 +344,8 @@ TEST(utils_network, test_net_contain_ip)
 TEST(utils_network, test_validate_network_name)
 {
     ASSERT_EQ(util_validate_network_name(nullptr), false);
-    ASSERT_EQ(util_validate_network_name(std::string(255, 'a').c_str()), true);
-    ASSERT_EQ(util_validate_network_name(std::string(256, 'a').c_str()), false);
+    ASSERT_EQ(util_validate_network_name(std::string(200, 'a').c_str()), true);
+    ASSERT_EQ(util_validate_network_name(std::string(201, 'a').c_str()), false);
     ASSERT_EQ(util_validate_network_name(std::string(".abce").c_str()), false);
 }
 
-- 
2.25.1

