From: "its_Giaan (Code Review)" Date: Wed, 15 Apr 2026 16:12:37 +0000 In-Reply-To: References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <7fb372d63626487b883a41981b6914565f0fe4dd-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="0WGycDwnW9A="; 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 --0WGycDwnW9A= 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 (#4). 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, 31 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/4 diff --git a/doc/man-sections/link-options.rst b/doc/man-sections/link-opti= ons.rst index edda1ca..1dcaba1 100644 --- a/doc/man-sections/link-options.rst +++ b/doc/man-sections/link-options.rst @@ -111,12 +111,19 @@ 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). + + Optional arguments override the corresponding default options: + + - ``port`` overrides ``--lport``. + - ``protocol`` overrides ``--proto``. + - ``bind device`` overrides ``--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..f43382f 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 + The default set by this option can be overridden on a per-socket basis + by specifying a bind device argument via ``--local``. --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: 4 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: its_Giaan Gerrit-Attention: flichtenheld --0WGycDwnW9A= 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 #4 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, 3= 1 insertions(+), 5 deletions(-)

git pull ssh://g=
errit.openvpn.net:29418/openvpn refs/changes/25/1625/4
diff --git a=
/doc/man-sections/link-options.rst b/doc/man-sections/link-options.rst
index edda1ca..1dcaba1 100644
--- a/doc/man-sec= tions/link-options.rst
+++ b/doc/man-sections/link-options.= rst
@@ -111,12 +111,19 @@
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).
+
+ Optional arguments override the corresp= onding default options:
+
+ - ``port`` ov= errides ``--lport``.
= + - ``protocol`` overrides ``--proto``.
+ - ``bind device`` overrides ``--bind-dev``.+
On a cli= ent, or in point-to-point mode, this can only be specified once (1 socket).=

On an OpenVPN setup running as ``--se= rver``, this can be specified multiple times
diff --git a/d= oc/man-sections/vpn-network-options.rst b/doc/man-sections/vpn-network-opti= ons.rst
index 33ebedb..f43382f 100644
--- a= /doc/man-sections/vpn-network-options.rst
+++ b/doc/man-sec= tions/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
+ The default set by this option = can be overridden on a per-socket basis

+ by specifying a bind device argument via ``--local``.=

--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/optio= ns.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 bind.\n"
+ "--local host|* [port] [protocol] [bind-dev]: Local= host name or IP address and port for bind.\n"
&q= uot; If specified, OpenVPN will bindto this address.= If unspecified,\n"
" = OpenVPN will bind to all interfaces. '*' can be used as hostname\n= "
" and means 'an= y 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 ``b= ind device`` to --bind-dev``.\n"
" = On a client, or in point-to-point mode, this can only be spec= ified once (1 socket).\n"
" = On an OpenVPN setup running as ``--server``, this can be specified m= ultiple times\n"
" to= open multiple listening sockets on different addresses and/or different po= rts.\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_de= v;
}

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

{ struct local_entry *e;

@@= -5998,6 +6001,17 @@
{
= e->proto =3D ascii2proto(p[3]);
}
<= span style=3D"color: hsl(120, 100%, 40%);">+#if defined(TARGET_LINUX)
+ if (p[4])<= br>+ {
+ e->bind_dev =3D p[4];<= /span>
+ }
= +#else
+ if (p[4])
+ {
+ msg(M_WARN, "Note: bind_dev is ignored = on non-Linux systems");
+ }
+#= endif
}
else if (streq(p[0], &quo= t;remote-random") && !p[1])
{
<= span>diff --git a/src/openvpn/options.h b/src/openvpn/options.h

<= span>index a111cf8..c9f61d1 100644

--- a/src/openvpn/option= s.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-&= gt;ce.local_list->array[sock_index]->proto;
+ const char *bind_dev =3D o->ce.local_l= ist->array[sock_index]->bind_dev;
const char *re= mote_host =3D o->ce.remote;
const char *remote_port= =3D o->ce.remote_port;

@@ -1409,7 +14= 10,8 @@
#endif

sock= ->mark =3D o->mark;
- sock->bind_dev =3D o->bind_dev;
+ /* bind_dev from local_list will trump the gl= obal option */
+ s= ock->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 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: 4
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...>
= --0WGycDwnW9A=--