From: "d12fk (Code Review)" Date: Mon, 27 Oct 2025 11:41:14 +0000 References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <828b963e737c9262baa272e357d5822cbc39adcc-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="yjJuF6TStV4="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: iservice: use interface index with netsh List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --yjJuF6TStV4= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1308?usp=3Demail to review the following change. Change subject: iservice: use interface index with netsh ...................................................................... iservice: use interface index with netsh We use the interface index with netsh everywhere else, so convert this invocation of netsh to index use as well. Change-Id: I329b407693b97dd048bd3788ecad345d6e25dab2 Signed-off-by: Heiko Hund --- M src/openvpnserv/interactive.c 1 file changed, 25 insertions(+), 37 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1308/1 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index ce0d4dd..029c1d7 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -995,16 +995,16 @@ } /** - * Run the command: netsh interface ip $action wins $if_name [static] $addr + * Run the command: netsh interface ip $action wins $if_index [static] $ad= dr * @param action "delete", "add" or "set" - * @param if_name "name_of_interface" + * @param if_index index of the interface to modify WINS for * @param addr IPv4 address as a string * * If addr is null and action =3D "delete" all addresses are deleted. * if action =3D "set" then "static" is added before $addr */ static DWORD -netsh_wins_cmd(const wchar_t *action, const wchar_t *if_name, const wchar_= t *addr) +netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr) { DWORD err =3D 0; int timeout =3D 30000; /* in msec */ @@ -1030,10 +1030,10 @@ /* cmd template: * netsh interface ip $action wins $if_name $static $addr */ - const wchar_t *fmt =3D L"netsh interface ip %ls wins \"%ls\" %ls %ls"; + const wchar_t *fmt =3D L"netsh interface ip %ls wins %d %ls %ls"; /* max cmdline length in wchars -- include room for worst case and som= e */ - size_t ncmdline =3D wcslen(fmt) + wcslen(if_name) + wcslen(action) + w= cslen(addr) + size_t ncmdline =3D wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + w= cslen(addr) + wcslen(addr_static) + 32 + 1; cmdline =3D malloc(ncmdline * sizeof(wchar_t)); if (!cmdline) @@ -1042,7 +1042,7 @@ goto out; } - swprintf(cmdline, ncmdline, fmt, action, if_name, addr_static, addr); + swprintf(cmdline, ncmdline, fmt, action, if_index, addr_static, addr); err =3D ExecCommand(argv0, cmdline, timeout); @@ -2882,7 +2882,7 @@ static DWORD HandleWINSConfigMessage(const wins_cfg_message_t *msg, undo_lists_t *lists) { - DWORD err =3D 0; + DWORD err =3D NO_ERROR; wchar_t addr[16]; /* large enough to hold string representation of an = ipv4 */ int addr_len =3D msg->addr_len; @@ -2892,38 +2892,25 @@ addr_len =3D _countof(msg->addr); } - if (!msg->iface.name[0]) /* interface name is required */ + if (!msg->iface.index) /* interface index is required */ { return ERROR_MESSAGE_DATA; } - /* use a non-const reference with limited scope to enforce null-termin= ation of strings from - * client */ - { - wins_cfg_message_t *msgptr =3D (wins_cfg_message_t *)msg; - msgptr->iface.name[_countof(msg->iface.name) - 1] =3D '\0'; - } - - wchar_t *wide_name =3D utf8to16(msg->iface.name); /* utf8 to wide-char= */ - if (!wide_name) - { - return ERROR_OUTOFMEMORY; - } - /* We delete all current addresses before adding any * OR if the message type is del_wins_cfg */ if (addr_len > 0 || msg->header.type =3D=3D msg_del_wins_cfg) { - err =3D netsh_wins_cmd(L"delete", wide_name, NULL); + err =3D netsh_wins_cmd(L"delete", msg->iface.index, NULL); if (err) { goto out; } - free(RemoveListItem(&(*lists)[undo_wins], CmpWString, wide_name)); + free(RemoveListItem(&(*lists)[undo_wins], CmpAny, NULL)); } - if (msg->header.type =3D=3D msg_del_wins_cfg) + if (addr_len =3D=3D 0 || msg->header.type =3D=3D msg_del_wins_cfg) { goto out; /* job done */ } @@ -2931,7 +2918,7 @@ for (int i =3D 0; i < addr_len; ++i) { RtlIpv4AddressToStringW(&msg->addr[i].ipv4, addr); - err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L"add", wide_name, ad= dr); + err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L"add", msg->iface.in= dex, addr); if (i =3D=3D 0 && err) { goto out; @@ -2941,22 +2928,23 @@ */ } - err =3D 0; - - if (addr_len > 0) + int *if_index =3D malloc(sizeof(msg->iface.index)); + if (if_index) { - wchar_t *tmp_name =3D _wcsdup(wide_name); - if (!tmp_name || AddListItem(&(*lists)[undo_wins], tmp_name)) - { - free(tmp_name); - netsh_wins_cmd(L"delete", wide_name, NULL); - err =3D ERROR_OUTOFMEMORY; - goto out; - } + *if_index =3D msg->iface.index; } + if (!if_index || AddListItem(&(*lists)[undo_wins], if_index)) + { + free(if_index); + netsh_wins_cmd(L"delete", msg->iface.index, NULL); + err =3D ERROR_OUTOFMEMORY; + goto out; + } + + err =3D 0; + out: - free(wide_name); return err; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1308?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I329b407693b97dd048bd3788ecad345d6e25dab2 Gerrit-Change-Number: 1308 Gerrit-PatchSet: 1 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --yjJuF6TStV4= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld, plaisthos.

d12fk would like plaisthos and flichtenheld to review t= his change.

V= iew Change

iservice: use interface index with netsh
We use the interface index with netsh everywhere else, so convert this=
invocation of netsh to index use as well.

Change-Id: I329b407693= b97dd048bd3788ecad345d6e25dab2
Signed-off-by: Heiko Hund <heiko@...2375...= 62...>
---
M src/openvpnserv/interactive.c
1 file changed, 25 i= nsertions(+), 37 deletions(-)

git pull ssh://ger=
rit.openvpn.net:29418/openvpn refs/changes/08/1308/1
diff --git a/s=
rc/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index ce0d4dd..029c1d7 100644
--- a/src/openvpnserv/inter= active.c
+++ b/src/openvpnserv/interactive.c
@@ -995,16 +995,16 @@
}

/**
- * Run the comm= and: netsh interface ip $action wins $if_name [static] $addr
+ * Run the command: netsh interfac= e ip $action wins $if_index [static] $addr
* @param acti= on "delete", "add" or "set"
- * @param if_name "name_= of_interface"
+ = * @param if_index index of the interface to modify WINS for
<= span> * @param addr IPv4 address as a string
*
* If addr is null and action =3D "delete" all ad= dresses are deleted.
* if action =3D "set" then= "static" is added before $addr
*/
static DWORD

-nets= h_wins_cmd(const wchar_t *action, const wchar_t *if_name, const wchar_t *ad= dr)
+netsh_wins_cmd(c= onst wchar_t *action, int if_index, const wchar_t *addr)
{=
DWORD err =3D 0;
int timeout =3D= 30000; /* in msec */
@@ -1030,10 +1030,10 @@
/* cmd template:
* netsh interface ip $action= wins $if_name $static $addr
*/
- const wchar_t *fmt =3D L"netsh int= erface ip %ls wins \"%ls\" %ls %ls";
+ const wchar_t *fmt =3D L"netsh i= nterface ip %ls wins %d %ls %ls";

= /* max cmdline length in wchars -- include room for worst case and some = */
- size_t ncmdline= =3D wcslen(fmt) + wcslen(if_name) + wcslen(action) + wcslen(addr)+ size_t ncmdline =3D wcsl= en(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
= + wcslen(addr_static) + 32 + 1;
= cmdline =3D malloc(ncmdline * sizeof(wchar_t));
if (!c= mdline)
@@ -1042,7 +1042,7 @@
goto= out;
}

- swprintf(cmdline, ncmdline, fmt, action, if_na= me, addr_static, addr);
+ swprintf(cmdline, ncmdline, fmt, action, if_index, addr_static, add= r);

err =3D ExecCommand(argv0, cmdli= ne, timeout);

@@ -2882,7 +2882,7 @@
static DWORD
HandleWINSConfigMessage(const win= s_cfg_message_t *msg, undo_lists_t *lists)
{
- DWORD err =3D 0;

+ DWORD err =3D NO_ERROR;=
wchar_t addr[16]; /* large enough to hold string representat= ion of an ipv4 */
int addr_len =3D msg->addr_len;

@@ -2892,38 +2892,25 @@
= addr_len =3D _countof(msg->addr);
}
- if (!msg= ->iface.name[0]) /* interface name is required */
+ if (!msg->iface.index) /* interfac= e index is required */
{
retu= rn ERROR_MESSAGE_DATA;
}

<= span style=3D"color: hsl(0, 100%, 40%);">- /* use a non-const reference = with limited scope to enforce null-termination of strings from

- * client */
- {
- wins_cfg_message_t *msgptr =3D (wins_cfg_messag= e_t *)msg;
- msg= ptr->iface.name[_countof(msg->iface.name) - 1] =3D '\0';

- }
-
- wchar_t *wide_name =3D utf8to16(msg->iface.name); /* utf= 8 to wide-char */
- = if (!wide_name)
- {<= /span>
- return ERROR_O= UTOFMEMORY;
- }

-
/* W= e delete all current addresses before adding any
* OR= if the message type is del_wins_cfg
*/
if (addr_len > 0 || msg->header.type =3D=3D msg_del_wins_cfg)=
{
- err =3D netsh_wins_cmd(L"delete", wide_name, NULL);

+ err =3D netsh_w= ins_cmd(L"delete", msg->iface.index, NULL);
= if (err)
{
got= o out;
}
- free(RemoveListItem(&(*lists)[undo_wins], CmpWStrin= g, wide_name));
+ = free(RemoveListItem(&(*lists)[undo_wins], CmpAny, NULL)); }

- if (msg->header.type =3D=3D msg_del_wins_cfg)
+ if (addr_len =3D=3D 0 || msg= ->header.type =3D=3D msg_del_wins_cfg)
{
= goto out; /* job done */
}
@@ -2931,7 +2918,7 @@
for (int i =3D 0; i < add= r_len; ++i)
{
RtlIpv4AddressT= oStringW(&msg->addr[i].ipv4, addr);
- err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set= " : L"add", wide_name, addr);
+ err =3D netsh_wins_cmd(i =3D=3D 0 ? L"= ;set" : L"add", msg->iface.index, addr);
= if (i =3D=3D 0 && err)
{ goto out;
@@ -2941,22 +2928,23 @@

*/
}
- err =3D 0;
-
- if (addr_len > 0)
+ int *if_index =3D malloc(sizeof(msg->iface.inde= x));
+ if (if_inde= x)
{
- wchar_t *tmp_name =3D _wcsdup(wide_name);
- if (!tmp_name || AddListItem(&(= *lists)[undo_wins], tmp_name))
- {
- = free(tmp_name);
- err =3D ERROR_OU= TOFMEMORY;
- = goto out;
- }
+ *if_index =3D= msg->iface.index;
}

+ if (!if_index || AddListItem= (&(*lists)[undo_wins], if_index))

+ {
+ free(if_index);
+ netsh_wins_cmd(L"delete", msg->iface.index, NU= LL);
+ err =3D= ERROR_OUTOFMEMORY;
+= goto out;
+ = }
+
+ err =3D 0;
+
out:
- free(wide_name);
= return err;
}

=

To view, visit change 1308. To unsubscribe, or for help writing ma= il filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I329b407693b97dd048bd3788eca= d345d6e25dab2
Gerrit-Change-Number: 1308
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --yjJuF6TStV4=--