From 645d5ebb55968150e6e41776818d627cae4c3859 Mon Sep 17 00:00:00 2001 From: hiura Date: Wed, 6 Mar 2024 11:33:56 +0900 Subject: [PATCH 1/2] Change bridge function: Make the NIC appear in the 'Local Bridge Settings' list regardless of a NULL character consisted in 'FriendlyName' --- src/Cedar/BridgeWin32.c | 24 ++++++++++++++++-------- src/Cedar/SeLowUser.c | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Cedar/BridgeWin32.c b/src/Cedar/BridgeWin32.c index 00d3ada0..b5df92f2 100644 --- a/src/Cedar/BridgeWin32.c +++ b/src/Cedar/BridgeWin32.c @@ -1161,7 +1161,9 @@ void Win32EthMakeCombinedName(char *dst, UINT dst_size, char *nicname, char *gui if (IsEmptyStr(guid) == false) { - Format(dst, dst_size, "%s (ID=%010u)", nicname, Win32EthGenIdFromGuid(guid)); + // Allow to combine "FriendlyName" consisting of a NULL character and ID. + //Format(dst, dst_size, "%s (ID=%010u)", nicname, Win32EthGenIdFromGuid(guid)); + Format(dst, dst_size, "%s(ID=%010u)", nicname, Win32EthGenIdFromGuid(guid)); } else { @@ -1185,18 +1187,19 @@ UINT Win32EthGetNameAndIdFromCombinedName(char *name, UINT name_size, char *str) len = StrLen(str); - if (len >= 16) + // Allow to combine "FriendlyName" consisting of a NULL character and ID. + if (len >= 15) { - StrCpy(id_str, sizeof(id_str), str + len - 16); + StrCpy(id_str, sizeof(id_str), str + len - 15); - if (StartWith(id_str, " (ID=")) + if (StartWith(id_str, "(ID=")) { if (EndWith(id_str, ")")) { char num[MAX_SIZE]; Zero(num, sizeof(num)); - StrCpy(num, sizeof(num), id_str + 5); + StrCpy(num, sizeof(num), id_str + 4); num[StrLen(num) - 1] = 0; @@ -1204,7 +1207,7 @@ UINT Win32EthGetNameAndIdFromCombinedName(char *name, UINT name_size, char *str) if (ret != 0) { - name[len - 16] = 0; + name[len - 15] = 0; } } } @@ -1346,6 +1349,8 @@ TOKEN_LIST *GetEthListEx(UINT *total_num_including_hidden, bool enum_normal, boo Debug("%s - %s\n", a->Guid, a->Title); } + // Make sure that "FriendlyName" does not cosist a NULL character. + Debug("%s,- s=%d, t=%s, %s,\n", a->Guid, show, tmp, a->Title[0] == 0 ? "check=NG FriendlyName(Title) is NULL !" : "check=OK"); } *total_num_including_hidden = ret->NumTokens; @@ -1405,7 +1410,8 @@ LIST *GetEthAdapterListInternal() UINT size; char *buf; UINT i, j; - char *qos_tag = " (Microsoft's Packet Scheduler)"; + //char *qos_tag = " (Microsoft's Packet Scheduler)"; + char *qos_tag = "(Microsoft's Packet Scheduler)"; // Allow to combine "FriendlyName" consisting of a NULL character and QOS. SU *su = NULL; LIST *su_adapter_list = NULL; @@ -1660,7 +1666,9 @@ ANSI_STR: } else { - Format(tmp, sizeof(tmp), "%s (%u)", a->Title, k + 1); + // Allow to combine "FriendlyName" consisting of a NULL character and ID. + //Format(tmp, sizeof(tmp), "%s (%u)", a->Title, k + 1); + Format(tmp, sizeof(tmp), "%s(%u)", a->Title, k + 1); } ok = true; diff --git a/src/Cedar/SeLowUser.c b/src/Cedar/SeLowUser.c index f6b40777..29967464 100644 --- a/src/Cedar/SeLowUser.c +++ b/src/Cedar/SeLowUser.c @@ -827,7 +827,9 @@ SU_ADAPTER_LIST *SuAdapterInfoToAdapterList(SL_ADAPTER_INFO *info) Copy(&t.Info, info, sizeof(SL_ADAPTER_INFO)); UniToStr(tmp, sizeof(tmp), info->AdapterId); - if (IsEmptyStr(tmp) || IsEmptyStr(info->FriendlyName) || StartWith(tmp, SL_ADAPTER_ID_PREFIX) == false) + // Make the NIC appear in the "Local Bridge Settings" list regardless of a NULL character consisted in "FriendlyName". + //if (IsEmptyStr(tmp) || IsEmptyStr(info->FriendlyName) || StartWith(tmp, SL_ADAPTER_ID_PREFIX) == false) + if (IsEmptyStr(tmp) || StartWith(tmp, SL_ADAPTER_ID_PREFIX) == false) { // Name is invalid return NULL; From 64cb8e1efff329add2904b8ece3186fe0f1adbfc Mon Sep 17 00:00:00 2001 From: hiura Date: Mon, 11 Mar 2024 00:16:22 +0900 Subject: [PATCH 2/2] Change bridge function: Make the NIC appear in the 'Local Bridge Settings' list No.2 --- src/Cedar/BridgeWin32.c | 9 +++------ src/Cedar/SeLowUser.c | 43 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/Cedar/BridgeWin32.c b/src/Cedar/BridgeWin32.c index b5df92f2..2941ae81 100644 --- a/src/Cedar/BridgeWin32.c +++ b/src/Cedar/BridgeWin32.c @@ -1162,7 +1162,6 @@ void Win32EthMakeCombinedName(char *dst, UINT dst_size, char *nicname, char *gui if (IsEmptyStr(guid) == false) { // Allow to combine "FriendlyName" consisting of a NULL character and ID. - //Format(dst, dst_size, "%s (ID=%010u)", nicname, Win32EthGenIdFromGuid(guid)); Format(dst, dst_size, "%s(ID=%010u)", nicname, Win32EthGenIdFromGuid(guid)); } else @@ -1187,7 +1186,7 @@ UINT Win32EthGetNameAndIdFromCombinedName(char *name, UINT name_size, char *str) len = StrLen(str); - // Allow to combine "FriendlyName" consisting of a NULL character and ID. + // Allow to combine "FriendlyName" consisting of a NULL character and ID beginning with "(ID=". if (len >= 15) { StrCpy(id_str, sizeof(id_str), str + len - 15); @@ -1410,8 +1409,7 @@ LIST *GetEthAdapterListInternal() UINT size; char *buf; UINT i, j; - //char *qos_tag = " (Microsoft's Packet Scheduler)"; - char *qos_tag = "(Microsoft's Packet Scheduler)"; // Allow to combine "FriendlyName" consisting of a NULL character and QOS. + char *qos_tag = "(Microsoft's Packet Scheduler)"; // Allow to combine "FriendlyName" consisting of a NULL character and QOS tag. SU *su = NULL; LIST *su_adapter_list = NULL; @@ -1666,8 +1664,7 @@ ANSI_STR: } else { - // Allow to combine "FriendlyName" consisting of a NULL character and ID. - //Format(tmp, sizeof(tmp), "%s (%u)", a->Title, k + 1); + // Allow to combine "FriendlyName" consisting of a NULL character and SEQ number. Format(tmp, sizeof(tmp), "%s(%u)", a->Title, k + 1); } diff --git a/src/Cedar/SeLowUser.c b/src/Cedar/SeLowUser.c index 29967464..1074adf9 100644 --- a/src/Cedar/SeLowUser.c +++ b/src/Cedar/SeLowUser.c @@ -753,11 +753,45 @@ LIST *SuGetAdapterList(SU *u) for (i = 0;i < u->AdapterInfoList.NumAdapters;i++) { SL_ADAPTER_INFO *info = &u->AdapterInfoList.Adapters[i]; - SU_ADAPTER_LIST *a = SuAdapterInfoToAdapterList(info); - if (a != NULL) + if (IsEmptyStr(info->FriendlyName)) { - Add(ret, a); + // Some NetAdapterCx drivers doesn't report the FriendlyName in the kernel mode. + // So we attempt to obtain the DriverDesc string from NetCfg registry key alternatively. + char regkey[MAX_PATH] = {0}; + char tmp[MAX_PATH] = {0}; + char adapter_guid[MAX_PATH] = {0}; + + UniToStr(adapter_guid, sizeof(adapter_guid), info->AdapterId + StrLen(SL_ADAPTER_ID_PREFIX)); + + if (GetClassRegKeyWin32(regkey, sizeof(regkey), tmp, sizeof(tmp), adapter_guid)) + { + char *driver_desc = MsRegReadStrEx2(REG_LOCAL_MACHINE, regkey, "DriverDesc", false, true); + + if (driver_desc != NULL) + { + StrCpy(info->FriendlyName, sizeof(info->FriendlyName), driver_desc); + Free(driver_desc); + } + } + } + + { + SU_ADAPTER_LIST *a = SuAdapterInfoToAdapterList(info); + + char macstr[128] = {0}; + BinToStr(macstr, sizeof(macstr), info->MacAddress, sizeof(info->MacAddress)); + + if (a != NULL) + { + // Debug("SU: Adapter %u (OK): ID=%S, MAC=%s, FriendlyName=%s\n", i, info->AdapterId, macstr, info->FriendlyName); + + Add(ret, a); + } + else + { + // Debug("SU: Adapter %u (NG): ID=%S, MAC=%s, FriendlyName=%s\n", i, info->AdapterId, macstr, info->FriendlyName); + } } } @@ -828,8 +862,7 @@ SU_ADAPTER_LIST *SuAdapterInfoToAdapterList(SL_ADAPTER_INFO *info) UniToStr(tmp, sizeof(tmp), info->AdapterId); // Make the NIC appear in the "Local Bridge Settings" list regardless of a NULL character consisted in "FriendlyName". - //if (IsEmptyStr(tmp) || IsEmptyStr(info->FriendlyName) || StartWith(tmp, SL_ADAPTER_ID_PREFIX) == false) - if (IsEmptyStr(tmp) || StartWith(tmp, SL_ADAPTER_ID_PREFIX) == false) + if (IsEmptyStr(tmp) || /* IsEmptyStr(info->FriendlyName) || */ StartWith(tmp, SL_ADAPTER_ID_PREFIX) == false) { // Name is invalid return NULL;