diff --git a/include/mptcpd/path_manager.h b/include/mptcpd/path_manager.h index 89eab470..9e57c5a3 100644 --- a/include/mptcpd/path_manager.h +++ b/include/mptcpd/path_manager.h @@ -126,6 +126,24 @@ MPTCPD_API int mptcpd_pm_add_addr(struct mptcpd_pm *pm, mptcpd_aid_t id, mptcpd_token_t token); +/** + * @brief Advertise new network address to peers without creating a listener. + * + * @param[in] pm The mptcpd path manager object. + * @param[in,out] addr Local IP address and port to be advertised + * through the MPTCP protocol @c ADD_ADDR + * option. If the port is zero no port will be + * specified on the underlying protocol level. + * @param[in] id MPTCP local address ID. + * @param[in] token MPTCP connection token. + * + * @return @c 0 if operation was successful. -1 or @c errno otherwise. + */ +MPTCPD_API int mptcpd_pm_add_addr_no_listener(struct mptcpd_pm *pm, + struct sockaddr *addr, + mptcpd_aid_t id, + mptcpd_token_t token); + /** * @brief Stop advertising network address to peers. * diff --git a/include/mptcpd/private/path_manager.h b/include/mptcpd/private/path_manager.h index a560f13b..90ce0aa5 100644 --- a/include/mptcpd/private/path_manager.h +++ b/include/mptcpd/private/path_manager.h @@ -138,18 +138,22 @@ struct mptcpd_pm_cmd_ops /** * @brief Advertise new network address to peers. * - * @param[in] pm The mptcpd path manager object. - * @param[in,out] addr Local IP address and port to be - * advertised through the MPTCP protocol - * @c ADD_ADDR option. If the port is - * zero an ephemeral port will be chosen, - * and assigned to the appropriate - * underlying address family-specific - * port member, e.g. @c sin_port or - * @c sin6_port. The port will be in - * network byte order. - * @param[in] id MPTCP local address ID. - * @param[in] token MPTCP connection token. + * @param[in] pm The mptcpd path manager object. + * @param[in,out] addr Local IP address and port to be + * advertised through the MPTCP protocol + * @c ADD_ADDR option. If the port is + * zero an ephemeral port will be chosen, + * and assigned to the appropriate + * underlying address family-specific + * port member, e.g. @c sin_port or + * @c sin6_port. The port will be in + * network byte order. + * If listener is not created, port zero + * will cause no port specification at + * protocol level. + * @param[in] id MPTCP local address ID. + * @param[in] token MPTCP connection token. + * @param[in] listener Create listener. * * @return @c 0 if operation was successful. -1 or @c errno * otherwise. @@ -157,7 +161,8 @@ struct mptcpd_pm_cmd_ops int (*add_addr)(struct mptcpd_pm *pm, struct sockaddr *addr, mptcpd_aid_t id, - mptcpd_token_t token); + mptcpd_token_t token, + bool listener); /** * @brief Stop advertising network address to peers. diff --git a/lib/path_manager.c b/lib/path_manager.c index c4891a58..b2413d3b 100644 --- a/lib/path_manager.c +++ b/lib/path_manager.c @@ -238,10 +238,11 @@ int mptcpd_kpm_set_flags(struct mptcpd_pm *pm, // ------------------------------------------------------------------- -int mptcpd_pm_add_addr(struct mptcpd_pm *pm, - struct sockaddr *addr, - mptcpd_aid_t address_id, - mptcpd_token_t token) +static int do_pm_add_addr(struct mptcpd_pm *pm, + struct sockaddr *addr, + mptcpd_aid_t address_id, + mptcpd_token_t token, + bool listener) { if (pm == NULL || addr == NULL || address_id == 0) return EINVAL; @@ -258,7 +259,24 @@ int mptcpd_pm_add_addr(struct mptcpd_pm *pm, return ops->add_addr(pm, addr, address_id, - token); + token, + listener); +} + +int mptcpd_pm_add_addr(struct mptcpd_pm *pm, + struct sockaddr *addr, + mptcpd_aid_t address_id, + mptcpd_token_t token) +{ + return do_pm_add_addr(pm, addr, address_id, token, true); +} + +int mptcpd_pm_add_addr_no_listener(struct mptcpd_pm *pm, + struct sockaddr *addr, + mptcpd_aid_t address_id, + mptcpd_token_t token) +{ + return do_pm_add_addr(pm, addr, address_id, token, false); } int mptcpd_pm_remove_addr(struct mptcpd_pm *pm, diff --git a/src/netlink_pm_mptcp_org.c b/src/netlink_pm_mptcp_org.c index 4b518ac2..ff9b0df0 100644 --- a/src/netlink_pm_mptcp_org.c +++ b/src/netlink_pm_mptcp_org.c @@ -155,8 +155,11 @@ static bool append_remote_addr_attr(struct l_genl_msg *msg, static int mptcp_org_add_addr(struct mptcpd_pm *pm, struct sockaddr *addr, mptcpd_aid_t id, - mptcpd_token_t token) + mptcpd_token_t token, + bool listener) { + (void) listener; + /* Payload: Token diff --git a/src/netlink_pm_upstream.c b/src/netlink_pm_upstream.c index 328dc805..2f718c22 100644 --- a/src/netlink_pm_upstream.c +++ b/src/netlink_pm_upstream.c @@ -219,20 +219,21 @@ static int send_add_addr(struct mptcpd_pm *pm, static int upstream_announce(struct mptcpd_pm *pm, struct sockaddr *addr, mptcpd_aid_t id, - mptcpd_token_t token) + mptcpd_token_t token, + bool listener) { - /** - * Set up MPTCP listening socket. - * - * @note An ephemeral port will be assigned to the port in - * @a addr if it is zero. - * - * @todo This should be optional. - */ - int const r = mptcpd_lm_listen(pm->lm, addr); + if (listener) { + /** + * Set up MPTCP listening socket. + * + * @note An ephemeral port will be assigned to the port in + * @a addr if it is zero. + */ + int const r = mptcpd_lm_listen(pm->lm, addr); - if (r != 0) - return r; + if (r != 0) + return r; + } /** * @todo Add support for the optional network interface index