From: "its_Giaan (Code Review)" Date: Mon, 13 Apr 2026 15:17:41 +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="GmrmXsJOldY="; 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 --GmrmXsJOldY= 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 (#2). 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. 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, 21 insertions(+), 4 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/2 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/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..e1c3b7d 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, "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; =20 @@ -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: 2 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: its_Giaan Gerrit-Attention: flichtenheld --GmrmXsJOldY= 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 #2 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.

= Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Signed-off-by: Gian= marco De Gregori <gianmarco@...2726...>
---
M doc/man-sections/= link-options.rst
M doc/man-sections/vpn-network-options.rst
M src/ope= nvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
5 fi= les changed, 21 insertions(+), 4 deletions(-)

gi=
t pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/2
<= pre style=3D"font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/doc/man-sections/link-options.rst b/doc/man-sections/link-op= tions.rst
index edda1ca..4b3200a 100644
---= a/doc/man-sections/link-options.rst
+++ b/doc/man-sections= /link-options.rst
@@ -111,7 +111,7 @@
Va= lid syntax:
::

- local host|* [port] [protocol]<= br>+ local host|* [port] [p= rotocol] [bind device]

Local host name= or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfa= ces.
diff --git a/doc/man-sections/vpn-network-options.rst = b/doc/man-sections/vpn-network-options.rst
index 33ebedb..3= b30ed9 100644
--- a/doc/man-sections/vpn-network-options.rs= t
+++ 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 an= d Forwarding`_ device
+ This option can also be used inside a ``--local`` statement
<= span style=3D"color: hsl(120, 100%, 40%);">+ allowing to bind a single soc= ket 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/openv= pn/options.c
index 70af6d2..e1c3b7d 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 lis= t for every outgoing connection */
@@ -5972,7 +5973,7 @@
VERIFY_PERMISSION(OPT_P_UP);
= options->ifconfig_nowarn =3D true;
}
- else if (streq(p[0], "loc= al") && p[1] && !p[4])

+ else if (streq(p[0], "local") &&a= mp; p[1] && !p[5])
{
= struct local_entry *e;

@@ -5998,6 +5999,1= 7 @@
{
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 s= ystems");
+ = }
+#endif }
else if (streq(p[0], "remote-rando= m") && !p[1])
{
diff --gi= t a/src/openvpn/options.h b/src/openvpn/options.h
index a11= 1cf8..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;
};
<= /span>
struct connection_entry
diff --git a/src/o= penvpn/socket.c b/src/openvpn/socket.c
index 624ce4f..018d1= 2d 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]->loc= al;
const char *port =3D o->ce.local_list->array= [sock_index]->port;
int proto =3D o->ce.local_li= st->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-&= gt;bind_dev =3D o->bind_dev;
+ /* bind_dev from local_list will trump the global option */=
+ sock->bind_d= ev =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 unsubscrib= e, 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: 2
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...>
= --GmrmXsJOldY=--