From patchwork Mon Nov 8 13:53:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Openvpn-devel] tun: improve DHCP server address calculation for small subnets X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 2068 Message-Id: <20211108135314.148-1-lstipakov@gmail.com> To: openvpn-devel@lists.sourceforge.net Cc: Lev Stipakov Date: Mon, 8 Nov 2021 15:53:14 +0200 From: Lev Stipakov List-Id: From: Lev Stipakov When /30 subnet is pushed (like in the case of OpenVPN Cloud), DHCP server address is calculated to be the same as local address, which causes collision and therefore connection is not established. To fix that, use openvpn3 approach, which sets DHCP server address to a network address for small subnets Signed-off-by: Lev Stipakov Signed-off-by: Lev Stipakov <lev@openvpn.net>
--- src/openvpn/tun.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 28f803ec..994e3751 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -6363,7 +6363,9 @@ tuntap_dhcp_mask(const struct tuntap *tt, const char *device_guid) } else { - ep[2] = dhcp_masq_addr(tt->local, tt->remote_netmask, -1); + int prefix_len = netmask_to_netbits2(tt->adapter_netmask); + /* use network address as DHCP server for small subnets, otherwise last address before broadcast */ + ep[2] = dhcp_masq_addr(tt->local, tt->remote_netmask, prefix_len < 28 ? -1 : 0); } } else