Skip to content

Commit

Permalink
Make listening socket creation optional. (#297)
Browse files Browse the repository at this point in the history
In some cases, it is known in advanced that external applications have
created or will create listening sockets, and mptcpd doesn't need to do
that to avoid reporting failures because the address and port are
already in use.

This commit makes listening socket creation optional for userspace path
manager plugins by extending the API: it is now possible to call
`mptcpd_pm_add_addr_no_listener()` instead of `mptcpd_pm_add_addr()` to
announce a new address without creating a new listener socket.

Fixes #296.
  • Loading branch information
marco-a-itl authored Aug 23, 2024
1 parent b102523 commit 334bb9c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 31 deletions.
18 changes: 18 additions & 0 deletions include/mptcpd/path_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
31 changes: 18 additions & 13 deletions include/mptcpd/private/path_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,31 @@ 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.
*/
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.
Expand Down
28 changes: 23 additions & 5 deletions lib/path_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/netlink_pm_mptcp_org.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions src/netlink_pm_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 334bb9c

Please sign in to comment.