加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
treat-underscore-as-valid-hostname-char.patch 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
胡宇彪 提交于 2024-02-18 11:25 . allow underscore in hostname
From c04904a4f54f8949a6a7821a0859e2732366259b Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Tue, 24 Nov 2020 19:57:38 +0800
Subject: [PATCH] treat underscore as valid hostname char
---
src/basic/hostname-util.c | 14 ++++++++++++--
test/test-network-generator-conversion.sh | 2 +-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c
index e743033..8464164 100644
--- a/src/basic/hostname-util.c
+++ b/src/basic/hostname-util.c
@@ -80,6 +80,16 @@ bool valid_ldh_char(char c) {
c == '-';
}
+static bool hostname_valid_char(char c) {
+ return
+ (c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') ||
+ c == '-' ||
+ c == '_' ||
+ c == '.';
+}
+
bool hostname_is_valid(const char *s, ValidHostnameFlags flags) {
unsigned n_dots = 0;
const char *p;
@@ -116,7 +126,7 @@ bool hostname_is_valid(const char *s, ValidHostnameFlags flags) {
hyphen = true;
} else {
- if (!valid_ldh_char(*p))
+ if (!hostname_valid_char(*p))
return false;
dot = false;
@@ -158,7 +168,7 @@ char* hostname_cleanup(char *s) {
dot = false;
hyphen = true;
- } else if (valid_ldh_char(*p)) {
+ } else if (hostname_valid_char(*p)) {
*(d++) = *p;
dot = false;
hyphen = false;
diff --git a/test/test-network-generator-conversion.sh b/test/test-network-generator-conversion.sh
index 6224a4d..05ef833 100755
--- a/test/test-network-generator-conversion.sh
+++ b/test/test-network-generator-conversion.sh
@@ -283,6 +283,7 @@ COMMAND_LINES=(
"ip=:::::dhcp99:dhcp6:10.0.0.128:[fdef:c400:bd01:1096::bbbb]"
"ip=::::::any"
"ip=::::::ibft"
+ "ip=10.0.0.1:::255.255.255.0:valid_hostname:foo99:off"
)
for cmdline in "${COMMAND_LINES[@]}"; do
check_one_long "$cmdline"
@@ -294,7 +295,6 @@ INVALID_COMMAND_LINES=(
"ip=:::::::foo"
"ip=10.0.0:::255.255.255.0::foo99:off"
"ip=10.0.0.1:::255.255.255::foo99:off"
- "ip=10.0.0.1:::255.255.255.0:invalid_hostname:foo99:off"
"ip=10.0.0.1:::255.255.255.0::verylonginterfacename:off"
"ip=:::::dhcp99:dhcp6:0"
"ip=:::::dhcp99:dhcp6:-1"
--
2.39.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化