Attention is currently required from: Arne Schwabe, Marco Baffo.
Hello Arne Schwabe, Răzvan Cojocaru,
I'd like you to reexamine a change. Please visit
https://gerrit.openvpn.net/c/openvpn/+/2062?usp=email
to look at the new patch set (#2).
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.
Change subject: dco: add an API to update peer virtual addresses on Linux
......................................................................
dco: add an API to update peer virtual addresses on Linux
Add a context wrapper and a Linux OVPN_CMD_PEER_SET implementation that
updates or clears only the requested address families. Supply no-op stubs
for non-DCO builds, FreeBSD and Windows.
Change-Id: I133e9368f9dfa9f10b4df8e503c3cf42f3a6d582
Signed-off-by: Marco Baffo <[email protected]>
---
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
5 files changed, 129 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/62/2062/2
diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c
index f807002..aaf074b 100644
--- a/src/openvpn/dco.c
+++ b/src/openvpn/dco.c
@@ -676,6 +676,40 @@
return 0;
}
+int
+dco_multi_update_peer_addr(struct context *c, int flags)
+{
+ if (!flags || c->c2.tls_multi->dco_peer_id == -1)
+ {
+ return 0;
+ }
+
+ int peer_id = c->c2.tls_multi->dco_peer_id;
+
+ /* In server mode we need to fetch the remote addresses from the push
config */
+ struct in_addr vpn_ip4 = { 0 };
+ const struct in_addr *vpn_addr4 = NULL;
+ if (c->c2.push_ifconfig_defined)
+ {
+ vpn_ip4.s_addr = htonl(c->c2.push_ifconfig_local);
+ vpn_addr4 = &vpn_ip4;
+ }
+
+ const struct in6_addr *vpn_addr6 = NULL;
+ if (c->c2.push_ifconfig_ipv6_defined)
+ {
+ vpn_addr6 = &c->c2.push_ifconfig_ipv6_local;
+ }
+
+ int ret = dco_update_peer_addr(&c->c1.tuntap->dco, peer_id, vpn_addr4,
vpn_addr6, flags);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ return 0;
+}
+
void
dco_install_iroute(struct multi_context *m, struct multi_instance *mi, const
struct mroute_addr *addr)
{
diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h
index ce44331..7005bd2 100644
--- a/src/openvpn/dco.h
+++ b/src/openvpn/dco.h
@@ -191,6 +191,31 @@
int keepalive_timeout, int mss);
/**
+ * Update the peer's virtual address(es) in the DCO to the current value(s)
+ *
+ * @param dco DCO device context
+ * @param peerid the ID of the peer to be modified
+ * @param vpn_ipv4 new IPv4 or NULL to remove the outdated one, only used
when `(1 << AF_INET)` flag is present
+ * @param vpn_ipv6 new IPv6 or NULL to remove the outdated one, only used
when `(1 << AF_INET6)` flag is present
+ * @param flags `(1 << AF_INET)`, `(1 << AF_INET6)` or `(1 << AF_INET) |
(1 << AF_INET6)` depending on which address has changed
+ * @return int the DCO message status on success or a negative error code
otherwise
+ */
+int
+dco_update_peer_addr(dco_context_t *dco, unsigned int peerid,
+ const struct in_addr *vpn_ipv4, const struct in6_addr
*vpn_ipv6,
+ int flags);
+
+/**
+ * Update the peer's virtual address(es) in the DCO to the current value(s)
+ *
+ * @param c peer context
+ * @param flags `(1 << AF_INET)`, `(1 << AF_INET6)` or `(1 << AF_INET) |
(1 << AF_INET6)` depending on which address has changed
+ * @return int 0 on success or a negative error code otherwise
+ */
+int
+dco_multi_update_peer_addr(struct context *c, int flags);
+
+/**
* Remove a peer from DCO
*
* @param c the main instance context of the peer to remove
@@ -352,6 +377,20 @@
return 0;
}
+static inline int
+dco_update_peer_addr(dco_context_t *dco, unsigned int peerid,
+ const struct in_addr *vpn_ipv4, const struct in6_addr
*vpn_ipv6,
+ int flags)
+{
+ return 0;
+}
+
+static inline int
+dco_multi_update_peer_addr(struct context *c, int flags)
+{
+ return 0;
+}
+
static inline void
dco_remove_peer(struct context *c)
{
diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
index 3148f10..d85104a 100644
--- a/src/openvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
@@ -559,6 +559,12 @@
return ret;
}
+int
+dco_update_peer_addr(dco_context_t *dco, unsigned int peerid, const struct
in_addr *vpn_ipv4, const struct in6_addr *vpn_ipv6, int flags)
+{
+ return 0;
+}
+
static void
dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const nvlist_t
*nvl)
{
diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c
index 4412ad0..744d687 100644
--- a/src/openvpn/dco_linux.c
+++ b/src/openvpn/dco_linux.c
@@ -724,6 +724,50 @@
return ret;
}
+int
+dco_update_peer_addr(dco_context_t *dco, unsigned int peerid, const struct
in_addr *vpn_ipv4, const struct in6_addr *vpn_ipv6, int flags)
+{
+ msg(D_DCO_DEBUG, "%s: peer-id %u", __func__, peerid);
+
+ if (!flags)
+ {
+ return 0;
+ }
+
+ struct nl_msg *nl_msg = ovpn_dco_nlmsg_create(dco, OVPN_CMD_PEER_SET);
+ if (!nl_msg)
+ {
+ return -ENOMEM;
+ }
+
+ struct nlattr *attr = nla_nest_start(nl_msg, OVPN_A_PEER);
+ int ret = -EMSGSIZE;
+ NLA_PUT_U32(nl_msg, OVPN_A_PEER_ID, peerid);
+
+ if (flags & (1 << AF_INET))
+ {
+ NLA_PUT_U32(nl_msg, OVPN_A_PEER_VPN_IPV4, vpn_ipv4 ? vpn_ipv4->s_addr
: 0);
+ }
+
+ if (flags & (1 << AF_INET6))
+ {
+ struct in6_addr addr6;
+ if (!vpn_ipv6)
+ {
+ CLEAR(addr6);
+ vpn_ipv6 = &addr6;
+ }
+ NLA_PUT(nl_msg, OVPN_A_PEER_VPN_IPV6, sizeof(struct in6_addr),
vpn_ipv6);
+ }
+
+ nla_nest_end(nl_msg, attr);
+ ret = ovpn_nl_msg_send(dco, nl_msg, __func__);
+
+nla_put_failure:
+ nlmsg_free(nl_msg);
+ return ret;
+}
+
/* This function parses the reply provided by the kernel to the
CTRL_CMD_GETFAMILY
* message. We parse the reply and we retrieve the multicast group ID
associated
* with the "ovpn-dco" netlink family.
diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c
index 68ae7c5..8f7c8f62 100644
--- a/src/openvpn/dco_win.c
+++ b/src/openvpn/dco_win.c
@@ -519,6 +519,12 @@
}
int
+dco_update_peer_addr(dco_context_t *dco, unsigned int peerid, const struct
in_addr *vpn_ipv4, const struct in6_addr *vpn_ipv6, int flags)
+{
+ return 0;
+}
+
+int
dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_slot_t
slot,
const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const
uint8_t *decrypt_key,
const uint8_t *decrypt_iv, const char *ciphername, bool epoch)
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2062?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I133e9368f9dfa9f10b4df8e503c3cf42f3a6d582
Gerrit-Change-Number: 2062
Gerrit-PatchSet: 2
Gerrit-Owner: Marco Baffo <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Marco Baffo <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel