Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make listening socket creation optional for userspace path manager plugins #297

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion include/mptcpd/private/path_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ struct mptcpd_pm_cmd_ops
* network byte order.
* @param[in] id MPTCP local address ID.
* @param[in] token MPTCP connection token.
* @param[in] nolst Don't 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 nolst);

/**
* @brief Stop advertising network address to peers.
Expand Down
48 changes: 33 additions & 15 deletions lib/path_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ static bool is_pm_ready(struct mptcpd_pm const *pm, char const *fname)
return ready;
}

static int do_pm_add_addr(struct mptcpd_pm *pm,
matttbe marked this conversation as resolved.
Show resolved Hide resolved
struct sockaddr *addr,
mptcpd_aid_t address_id,
mptcpd_token_t token,
bool nolst)
{
if (pm == NULL || addr == NULL || address_id == 0)
return EINVAL;

if (!is_pm_ready(pm, __func__))
return EAGAIN;

struct mptcpd_pm_cmd_ops const *const ops =
pm->netlink_pm->cmd_ops;

if (ops == NULL || ops->add_addr == NULL)
return ENOTSUP;

return ops->add_addr(pm,
addr,
address_id,
token,
nolst);
}

// --------------------------------------------------------------------

bool mptcpd_pm_register_ops(struct mptcpd_pm *pm,
Expand Down Expand Up @@ -243,22 +268,15 @@ int mptcpd_pm_add_addr(struct mptcpd_pm *pm,
mptcpd_aid_t address_id,
mptcpd_token_t token)
{
if (pm == NULL || addr == NULL || address_id == 0)
return EINVAL;

if (!is_pm_ready(pm, __func__))
return EAGAIN;

struct mptcpd_pm_cmd_ops const *const ops =
pm->netlink_pm->cmd_ops;

if (ops == NULL || ops->add_addr == NULL)
return ENOTSUP;
return do_pm_add_addr(pm, addr, address_id, token, false);
}

return ops->add_addr(pm,
addr,
address_id,
token);
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, true);
}

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 nolst)
{
(void) nolst;

/*
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 nolst)
{
/**
* 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 (!nolst) {
matttbe marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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
Loading