Skip to contentSkip to conversation

Change in openvpn[master]: Fix check_addr_clash argument order

Openvpn-devel In review ralf_lici (Code Review) 2 participants 7 messages Sep 9, 2024 – Sep 17, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1725890088000.I5adbe0a79f078221c4bb5f3d39391a81b4d8adce@...2715...

#1 lore raw

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/+/737?usp=email

to review the following change.

Change subject: Fix check_addr_clash argument order
......................................................................

Fix check_addr_clash argument order

In init_tun() make sure to pass the --local and --remote addresses in the host order so that they can be compared to the --ifconfig addresses.

Change-Id I5adbe0a79f078221c4bb5f3d39391a81b4d8adce

---
M src/openvpn/tun.c

1 file changed, 4 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/37/737/1

src/openvpn/tun.c +4 -2
index 739e008..1cd6ad2 100644
@@ -877,9 +877,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t local = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("local",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     local,
                                      tt->local,
                                      tt->remote_netmask);
                 }
@@ -889,9 +890,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t remote = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("remote",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     remote,
                                      tt->local,
                                      tt->remote_netmask);
                 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/737?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5adbe0a79f078221c4bb5f3d39391a81b4d8adce
Gerrit-Change-Number: 737
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/737?usp=email )

Change subject: Fix check_addr_clash argument order
......................................................................

Patch Set 1: Code-Review+2

(1 comment)

Patchset:

PS1:
Code change makes sense to me, but I haven' tested it. Is there an easy test case to verify the fix?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/737?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5adbe0a79f078221c4bb5f3d39391a81b4d8adce
Gerrit-Change-Number: 737
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Sep 2024 15:53:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

ralf_lici has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/737?usp=email )

Change subject: Fix check_addr_clash argument order
......................................................................

Patch Set 1:

(1 comment)

Patchset:

PS1:

Quoted 1 line

Code change makes sense to me, but I haven' tested it. […]

If you simply want to evaluate if the order is coherent between the arguments you can enable the debugging code at the beginning of check_addr_clash().

To actually trigger the tun warning I created a tuntap interface (tun0) and set the ip address to 10.10.20.1/24. Then I executed:
openvpn --ifconfig 10.10.20.10 255.255.255.0 --local 10.10.20.1 --dev tun0 --topology subnet ...

The tap warning can be triggered by executing:
openvpn --ifconfig 10.10.20.10 255.255.255.0 --local 10.10.20.1 --dev tap ...

Nevertheless I could not find a way to trigger the first warning in check_addr_clash() (line 564) because I think a previous check already ensures that --local or --remote addresses are not the same as the --ifconfig addresses (but I'm not entirely sure if this is always the case).

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/737?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5adbe0a79f078221c4bb5f3d39391a81b4d8adce
Gerrit-Change-Number: 737
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Sep 2024 16:53:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#4 lore raw

PATCH 1/1 Fix check_addr_clash argument order

In reply to a message not in the archive

From: Ralf Lici <[email protected]...>

In init_tun() make sure to pass the --local and --remote addresses in the host order so that they can be compared to the --ifconfig addresses.

Change-Id I5adbe0a79f078221c4bb5f3d39391a81b4d8adce

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/737
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

src/openvpn/tun.c +4 -2
index 739e008..1cd6ad2 100644
@@ -877,9 +877,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t local = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("local",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     local,
                                      tt->local,
                                      tt->remote_netmask);
                 }
@@ -889,9 +890,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t remote = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("remote",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     remote,
                                      tt->local,
                                      tt->remote_netmask);
                 }
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix check_addr_clash argument order

Good find.

I tested this as instructed in gerrit, also enabling the #if 0 debug code - this is a p2p setup with --topology subnet, to actually have a subnet to check against.

Test 1, "--local" in the "--ifconfig" subnet:

2024-09-17 11:25:45 CHECK_ADDR_CLASH type=2 public=10.204.8.7 local=10.204.8.2, remote_netmask=255.255.255.0
2024-09-17 11:25:45 WARNING: potential conflict between --local address [10.204.8.7] and --ifconfig address pair [10.204.8.2, 255.255.255.0] -- this is a warning only that is triggered when local/remote addresses exist within the same /24 subnet as --ifconfig endpoints. (silence this warning with --ifconfig-nowarn)

"works".

Test 2, "--remote" in the "--ifconfig" subnet:

2024-09-17 11:27:03 CHECK_ADDR_CLASH type=2 public=10.204.8.8 local=10.204.8.2, remote_netmask=255.255.255.0
2024-09-17 11:27:03 WARNING: potential conflict between --remote address [10.204.8.8] and --ifconfig address pair [10.204.8.2, 255.255.255.0] -- this is a warning only that is triggered when local/remote addresses exist within the same /24 subnet as --ifconfig endpoints. (silence this warning with --ifconfig-nowarn)

Test 3, no "--topology subnet":

2024-09-17 11:36:28 CHECK_ADDR_CLASH type=2 public=10.204.8.250 local=10.204.8.2, remote_netmask=10.204.8.1
2024-09-17 11:36:28 WARNING: potential conflict between --local address [10.204.8.250] and --ifconfig address pair [10.204.8.2, 10.204.8.1] -- this is a warning only that is triggered when local/remote addresses exist within the same /24 subnet as --ifconfig endpoints. (silence this warning with --ifconfig-nowarn)
2024-09-17 11:36:28 CHECK_ADDR_CLASH type=2 public=10.204.8.220 local=10.204.8.2, remote_netmask=10.204.8.1
2024-09-17 11:36:28 WARNING: potential conflict between --remote address [10.204.8.220] and --ifconfig address pair [10.204.8.2, 10.204.8.1] -- this is a warning only that is triggered when local/remote addresses exist within the same /24 subnet as --ifconfig endpoints. (silence this warning with --ifconfig-nowarn)

.. it "works as designed", but does raise questions... see below.

So, while this patch is actually fixing the first problem with this code, I have some ideas how to improve things further ;-)

- the line wrapping "one function argument per line" is not how we do things today, so a future (master-only) patch could improve that

- the check as implemented today checks "within the same /24", so if I do "--ifconfig 10.204.8.2 255.255.255.128 --remote 10.204.8.220" (which is perfectly sane) I get

      2024-09-17 11:30:44 CHECK_ADDR_CLASH type=2 public=10.204.8.220 local=10.204.8.2, remote_netmask=255.255.255.128
      2024-09-17 11:30:44 WARNING: potential conflict between --remote address [10.204.8.220] and --ifconfig address pair [10.204.8.2, 255.255.255.128] -- this is a warning only that is triggered when local/remote addresses exist within the same /24 subnet as --ifconfig endpoints. (silence this warning with --ifconfig-nowarn)

... which is not making any sense. Computers can do math, AND the code actually knows the netmask there, but uses /24 always (the TAP check code actually uses the netmask...).

So I think this code needs to be taught about "--topology subnet", and only does the /24 heuristic for p2p/net30 (if at all).

Your patch has been applied to the master and release/26 branch (bugfix).

commit 7d345b19e20f30cb2ecbea71682b5a41e6cff454 (master) commit 7e6723aa7096bee80eb42a473fbfde7de4362b0f (release/2.6)

Author: Ralf Lici
Date:   Tue Sep 17 11:14:33 2024 +0200
     Fix check_addr_clash argument order

     Signed-off-by: Ralf Lici <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg29261.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/737?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: Fix check_addr_clash argument order
......................................................................

Fix check_addr_clash argument order

In init_tun() make sure to pass the --local and --remote addresses in the host order so that they can be compared to the --ifconfig addresses.

Change-Id I5adbe0a79f078221c4bb5f3d39391a81b4d8adce

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29261.html

---
M src/openvpn/tun.c

1 file changed, 4 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/37/737/2

src/openvpn/tun.c +4 -2
index 8b6c34d..d5bad86 100644
@@ -877,9 +877,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t local = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("local",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     local,
                                      tt->local,
                                      tt->remote_netmask);
                 }
@@ -889,9 +890,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t remote = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("remote",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     remote,
                                      tt->local,
                                      tt->remote_netmask);
                 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/737?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5adbe0a79f078221c4bb5f3d39391a81b4d8adce
Gerrit-Change-Number: 737
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#7 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/737?usp=email )

Change subject: Fix check_addr_clash argument order
......................................................................

Fix check_addr_clash argument order

In init_tun() make sure to pass the --local and --remote addresses in the host order so that they can be compared to the --ifconfig addresses.

Change-Id I5adbe0a79f078221c4bb5f3d39391a81b4d8adce

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29261.html

---
M src/openvpn/tun.c

1 file changed, 4 insertions(+), 2 deletions(-)
src/openvpn/tun.c +4 -2
index 8b6c34d..d5bad86 100644
@@ -877,9 +877,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t local = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("local",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     local,
                                      tt->local,
                                      tt->remote_netmask);
                 }
@@ -889,9 +890,10 @@
             {
                 if (curele->ai_family == AF_INET)
                 {
+                    const in_addr_t remote = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
                     check_addr_clash("remote",
                                      tt->type,
-                                     ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr,
+                                     remote,
                                      tt->local,
                                      tt->remote_netmask);
                 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/737?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5adbe0a79f078221c4bb5f3d39391a81b4d8adce
Gerrit-Change-Number: 737
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged