From: "its_Giaan (Code Review)" Date: Wed, 15 Apr 2026 15:32:29 +0000 In-Reply-To: References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="SOndQkFVdAo="; 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 , flichtenheld Cc: openvpn-devel --SOndQkFVdAo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, its_Giaan, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=3Demail to look at the new patch set (#3). The following approvals got outdated and were removed: Code-Review-1 by flichtenheld 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. While at it, improved the man-section for --local. Change-Id: I6319c951327a9b994ffae0ba35270b0887455203 Signed-off-by: Gianmarco De Gregori --- M doc/man-sections/link-options.rst M doc/man-sections/vpn-network-options.rst M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/socket.c 5 files changed, 29 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/3 diff --git a/doc/man-sections/link-options.rst b/doc/man-sections/link-opti= ons.rst index edda1ca..0c4df71 100644 --- a/doc/man-sections/link-options.rst +++ b/doc/man-sections/link-options.rst @@ -111,12 +111,17 @@ 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. '*' can be used as hostname and means 'any host' (OpenVPN will listen on= what is returned by the OS). + + The optional arguments correspond to existing options: ``port`` to + ``--lport``, ``protocol`` to ``--proto``, and ``bind device`` to + ``--bind-dev``. + On a client, or in point-to-point mode, this can only be specified once = (1 socket). On an OpenVPN setup running as ``--server``, this can be specified multi= ple times diff --git a/doc/man-sections/vpn-network-options.rst b/doc/man-sections/vp= n-network-options.rst index 33ebedb..3b30ed9 100644 --- a/doc/man-sections/vpn-network-options.rst +++ b/doc/man-sections/vpn-network-options.rst @@ -6,8 +6,10 @@ routing. --bind-dev device - (Linux only) Set ``device`` to bind the server socket to a + (Linux only) Set ``device`` to bind all the server sockets to a `Virtual Routing and Forwarding`_ device + This option can also be used inside a ``--local`` statement + allowing to bind a single socket to specific device. --block-ipv6 On the client, instead of sending IPv6 packets over the VPN tunnel, all diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 70af6d2..63db6db 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -128,10 +128,12 @@ "--version : Show copyright and version information.\n" "\n" "Tunnel Options:\n" - "--local host|* [port]: Local host name or IP address and port for bin= d.\n" + "--local host|* [port] [protocol] [bind-dev]: Local host name or IP ad= dress and port for bind.\n" " If specified, OpenVPN will bindto this addres= s. If unspecified,\n" " OpenVPN will bind to all interfaces. '*' can = be used as hostname\n" " and means 'any host' (OpenVPN will listen on = what is returned by the OS).\n" + " The optional arguments correspond to existing= options: ``port`` to ``--lport``,\n" + " ``protocol`` to ``--proto``, and ``bind devic= e`` to --bind-dev``.\n" " On a client, or in point-to-point mode, this = can only be specified once (1 socket).\n" " On an OpenVPN setup running as ``--server``, = this can be specified multiple times\n" " to open multiple listening sockets on differe= nt addresses and/or different ports.\n" @@ -3830,6 +3832,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 +5975,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 +6001,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, "Note: bind_dev is ignored on non-Linux systems"); + } +#endif } else if (streq(p[0], "remote-random") && !p[1]) { diff --git a/src/openvpn/options.h b/src/openvpn/options.h index a111cf8..c9f61d1 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..018d12d 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 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: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203 Gerrit-Change-Number: 1625 Gerrit-PatchSet: 3 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: its_Giaan Gerrit-Attention: flichtenheld --SOndQkFVdAo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

its_Giaan uploaded patch set #3 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1625?usp=3Demail">View Chan= ge

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

Enable per-socket bind_dev v=
ia --local

A bind device can now be specified within a
--local st= atement allowing to bind
different sockets to different devices.

= While at it, improved the man-section for
--local.

Change-Id: I63= 19c951327a9b994ffae0ba35270b0887455203
Signed-off-by: Gianmarco De Grego= ri <gianmarco@...2726...>
---
M doc/man-sections/link-options.r= st
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c=
M src/openvpn/options.h
M src/openvpn/socket.c
5 files changed, 2= 9 insertions(+), 5 deletions(-)

git pull ssh://g=
errit.openvpn.net:29418/openvpn refs/changes/25/1625/3
diff --git a=
/doc/man-sections/link-options.rst b/doc/man-sections/link-options.rst
index edda1ca..0c4df71 100644
--- a/doc/man-sec= tions/link-options.rst
+++ b/doc/man-sections/link-options.= rst
@@ -111,12 +111,17 @@
Valid syntax:<= /span>
::

- local host|* [port] [protocol]
+ local host|* [port] [protocol] [bind= device]

Local host name or IP address= and port for bind. If specified, OpenVPN will bind
to t= his address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' = (OpenVPN will listen on what
is returned by the OS).
+
+ The optional arguments correspond to ex= isting options: ``port`` to
+ ``--lport``, ``protocol`` to ``--proto``, and ``bind device`` to<= /span>
+ ``--bind-dev``.
+
On= a client, or in point-to-point mode, this can only be specified once (1 so= cket).

On an OpenVPN setup running as = ``--server``, this can be specified multiple times
diff --g= it a/doc/man-sections/vpn-network-options.rst b/doc/man-sections/vpn-networ= k-options.rst
index 33ebedb..3b30ed9 100644
--- a/doc/man-sections/vpn-network-options.rst

+++ b/doc/m= an-sections/vpn-network-options.rst
@@ -6,8 +6,10 @@=
routing.

--bind-dev device
- (Linux only) Set ``dev= ice`` to bind the server socket to a
+ (Linux only) Set ``device`` to bind all the server socke= ts to a
`Virtual Routing and Forwarding`_ device<= br>+ This option can also be u= sed inside a ``--local`` statement
+ allowing to bind a single socket to specific device.

--block-ipv6
On the client= , instead of sending IPv6 packets over the VPN tunnel, all
= diff --git a/src/openvpn/options.c b/src/openvpn/options.c
= index 70af6d2..63db6db 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -128,10 +128,= 12 @@
"--version : Show copyright and versi= on information.\n"
"\n"
"Tunnel Options:\n"

- "--local host|* [port]: Local host name or IP addres= s and port for bind.\n"
+ "--local host|* [port] [protocol] [bind-dev]: Local host = name or IP address and port for bind.\n"
" = If specified, OpenVPN will bindto this address. If un= specified,\n"
" OpenV= PN will bind to all interfaces. '*' can be used as hostname\n"=
" and means 'any host= ' (OpenVPN will listen on what is returned by the OS).\n"+ " = The optional arguments correspond to existing options: ``port`` to ``= --lport``,\n"
+ = " ``protocol`` to ``--proto``, and ``bind de= vice`` to --bind-dev``.\n"
" = On a client, or in point-to-point mode, this can only be specified = once (1 socket).\n"
" = On an OpenVPN setup running as ``--server``, this can be specified multipl= e times\n"
" to open = multiple listening sockets on different addresses and/or different ports.\n= "
@@ -3830,6 +3832,7 @@
ASSER= T(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 +59= 75,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 +6001,17 @@
{
e-&g= t;proto =3D ascii2proto(p[3]);
}
+#if defined(TARGET_LINUX)
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (p[4])

+ {

+ e->bind_dev =3D p[4];
+ }
+#else

+ if (p[4])
+ {
+ msg(M_WARN, "Note: bind_dev is ignored on n= on-Linux systems");
+ }
+#endi= f
}
else if (streq(p[0], "re= mote-random") && !p[1])
{
diff --git a/src/openvpn/options.h b/src/openvpn/options.h

index a111cf8..c9f61d1 100644

--- a/src/openvpn/options.h<= /span>
+++ b/src/openvpn/options.h
@@ -101,6 +101,= 7 @@
const char *local;
const cha= r *port;
int proto;
+ const char *bind_dev;
};
struct connection_entry
diff --g= it a/src/openvpn/socket.c b/src/openvpn/socket.c
index 624c= e4f..018d12d 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_inde= x]->local;
const char *port =3D o->ce.local_list= ->array[sock_index]->port;
int proto =3D o->c= e.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 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.re= mote_float;

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

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba352= 70b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
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: its_Giaan <gianmarco@...1665...= 726...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --SOndQkFVdAo=--