From: "its_Giaan (Code Review)" Date: Thu, 9 Apr 2026 13:33:36 +0000 References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="BAS5GZnLte0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Enable per-socket bind_dev via --local List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --BAS5GZnLte0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=3Demail to review the following change. Change subject: Enable per-socket bind_dev via --local ...................................................................... Enable per-socket bind_dev via --local A bind device can now be specified within a --local statement allowing to bind different sockets to different devices. Change-Id: I6319c951327a9b994ffae0ba35270b0887455203 Signed-off-by: Gianmarco De Gregori --- M doc/man-sections/link-options.rst M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/socket.c 4 files changed, 19 insertions(+), 4 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/1 diff --git a/doc/man-sections/link-options.rst b/doc/man-sections/link-opti= ons.rst index edda1ca..4b3200a 100644 --- a/doc/man-sections/link-options.rst +++ b/doc/man-sections/link-options.rst @@ -111,7 +111,7 @@ Valid syntax: :: - local host|* [port] [protocol] + local host|* [port] [protocol] [bind device] Local host name or IP address and port for bind. If specified, OpenVPN w= ill bind to this address. If unspecified, OpenVPN will bind to all interfaces. diff --git a/src/openvpn/options.c b/src/openvpn/options.c index b8d0f5a..6958953 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -3830,6 +3830,7 @@ ASSERT(e); e->port =3D o->ce.local_port; e->proto =3D o->ce.proto; + e->bind_dev =3D o->bind_dev; } /* use the same listen list for every outgoing connection */ @@ -5972,7 +5973,7 @@ VERIFY_PERMISSION(OPT_P_UP); options->ifconfig_nowarn =3D true; } - else if (streq(p[0], "local") && p[1] && !p[4]) + else if (streq(p[0], "local") && p[1] && !p[5]) { struct local_entry *e; @@ -5998,6 +5999,17 @@ { e->proto =3D ascii2proto(p[3]); } +#if defined(TARGET_LINUX) + if (p[4]) + { + e->bind_dev =3D p[4]; + } +#else + if (p[4]) + { + msg(M_WARN | M_ERRNO, "Note: bind_dev is ignored on non-Linux = systems"); + } +#endif } else if (streq(p[0], "remote-random") && !p[1]) { @@ -6526,7 +6538,7 @@ } } } -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX) else if (streq(p[0], "bind-dev") && p[1]) { VERIFY_PERMISSION(OPT_P_SOCKFLAGS); diff --git a/src/openvpn/options.h b/src/openvpn/options.h index 422820c..0c4d11c 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -101,6 +101,7 @@ const char *local; const char *port; int proto; + const char *bind_dev; }; struct connection_entry diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 624ce4f..9c69ca4 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -1349,6 +1349,7 @@ const char *host =3D o->ce.local_list->array[sock_index]->local; const char *port =3D o->ce.local_list->array[sock_index]->port; int proto =3D o->ce.local_list->array[sock_index]->proto; + const char *bind_dev =3D o->ce.local_list->array[sock_index]->bind_dev; const char *remote_host =3D o->ce.remote; const char *remote_port =3D o->ce.remote_port; @@ -1409,7 +1410,8 @@ #endif sock->mark =3D o->mark; - sock->bind_dev =3D o->bind_dev; + /* bind_dev from local_list will trump on the global option. */ + sock->bind_dev =3D bind_dev ? bind_dev : o->bind_dev; sock->info.proto =3D proto; sock->info.af =3D o->ce.af; sock->info.remote_float =3D o->ce.remote_float; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?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: I6319c951327a9b994ffae0ba35270b0887455203 Gerrit-Change-Number: 1625 Gerrit-PatchSet: 1 Gerrit-Owner: its_Giaan Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --BAS5GZnLte0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

its_Giaan would like plaisthos to review this change.

V= iew Change

Enable per-socket bind_dev via --local
<= br>A bind device can now be specified within a
--local statement allowin= g to bind
different sockets to different devices.

Change-Id: I631= 9c951327a9b994ffae0ba35270b0887455203
Signed-off-by: Gianmarco De Gregor= i <gianmarco@...2726...>
---
M doc/man-sections/link-options.rs= t
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/so= cket.c
4 files changed, 19 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25= /1625/1
diff --git a/doc/man-sections/link-options.rst b/doc/man-se=
ctions/link-options.rst
index edda1ca..4b3200a 100644
--- a/doc/man-sections/link-options.rst
+++ b/do= c/man-sections/link-options.rst
@@ -111,7 +111,7 @@<= br> Valid syntax:
::
- local host|* [port] [proto= col]
+ local host= |* [port] [protocol] [bind device]

Loc= al host name or IP address and port for bind. If specified, OpenVPN will bi= nd
to this address. If unspecified, OpenVPN will bind to= all interfaces.
diff --git a/src/openvpn/options.c b/src/o= penvpn/options.c
index b8d0f5a..6958953 100644
--- a/src/openvpn/options.c

+++ b/src/openvpn/options.c=
@@ -3830,6 +3830,7 @@
ASSERT(e);<= /span>
e->port =3D o->ce.local_port;
e->proto =3D o->ce.proto;

+ e->bind_dev =3D o->bind_dev; }

/* use the same listen= list for every outgoing connection */
@@ -5972,7 +5973,7 @= @
VERIFY_PERMISSION(OPT_P_UP);
= options->ifconfig_nowarn =3D true;
}- else if (streq(p[0], "= ;local") && p[1] && !p[4])
+ else if (streq(p[0], "local") &am= p;& p[1] && !p[5])
{
= struct local_entry *e;

@@ -5998,6 +59= 99,17 @@
{
e->prot= o =3D ascii2proto(p[3]);
}
+#if defined(TARGET_LINUX)
+ if (p[4])
+ {
+ e->bind_dev =3D p[4];
= + }
+#else
+ if (p[4])
+ {
+ msg(M_WARN | M_ERRNO, "Note: bind_dev is ignored = on non-Linux systems");
+ }
+#= endif
}
else if (streq(p[0], &quo= t;remote-random") && !p[1])
{
<= span>@@ -6526,7 +6538,7 @@
}
= }
}
-#ifdef TARGET_LINUX
+#if defined(TARGET_LINUX)
else if (streq(p[= 0], "bind-dev") && p[1])
{ VERIFY_PERMISSION(OPT_P_SOCKFLAGS);
diff --= git a/src/openvpn/options.h b/src/openvpn/options.h
index 4= 22820c..0c4d11c 100644
--- a/src/openvpn/options.h+++ b/src/openvpn/options.h
@@ -101,6 +101,7 @@
const char *local;
const char *port;=
int proto;
+ const char *bind_dev;
};
=
struct connection_entry
diff --git a/src= /openvpn/socket.c b/src/openvpn/socket.c
index 624ce4f..9c6= 9ca4 100644
--- a/src/openvpn/socket.c
+++ = b/src/openvpn/socket.c
@@ -1349,6 +1349,7 @@
const char *host =3D o->ce.local_list->array[sock_index]->l= ocal;

const char *port =3D o->ce.local_list->arr= ay[sock_index]->port;
int proto =3D o->ce.local_= list->array[sock_index]->proto;
+ const char *bind_dev =3D o->ce.local_list->arra= y[sock_index]->bind_dev;
const char *remote_host = =3D o->ce.remote;
const char *remote_port =3D o->= ;ce.remote_port;

@@ -1409,7 +1410,8 @@
#endif

sock->mark = =3D o->mark;
- so= ck->bind_dev =3D o->bind_dev;
+ /* bind_dev from local_list will trump on the global op= tion. */
+ sock-&g= t;bind_dev =3D bind_dev ? bind_dev : o->bind_dev;
s= ock->info.proto =3D proto;
sock->info.af =3D o-&= gt;ce.af;
sock->info.remote_float =3D o->ce.remo= te_float;

To view, visit change 1625. To un= subscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba352= 70b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --BAS5GZnLte0=--