Skip to content

Commit

Permalink
avoid double negation for listener check and move do_pm_add_addr
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-a-itl committed Aug 7, 2024
1 parent 7683e3b commit 4e45fa6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 45 deletions.
31 changes: 17 additions & 14 deletions include/mptcpd/private/path_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +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] nolst Don't create 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 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.
Expand All @@ -159,7 +162,7 @@ struct mptcpd_pm_cmd_ops
struct sockaddr *addr,
mptcpd_aid_t id,
mptcpd_token_t token,
bool nolst);
bool listener);

/**
* @brief Stop advertising network address to peers.
Expand Down
54 changes: 27 additions & 27 deletions lib/path_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,6 @@ 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,
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 @@ -263,20 +238,45 @@ int mptcpd_kpm_set_flags(struct mptcpd_pm *pm,

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

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;

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

int mptcpd_pm_remove_addr(struct mptcpd_pm *pm,
Expand Down
4 changes: 2 additions & 2 deletions src/netlink_pm_mptcp_org.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ static int mptcp_org_add_addr(struct mptcpd_pm *pm,
struct sockaddr *addr,
mptcpd_aid_t id,
mptcpd_token_t token,
bool nolst)
bool listener)
{
(void) nolst;
(void) listener;

/*
Payload:
Expand Down
4 changes: 2 additions & 2 deletions src/netlink_pm_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ static int upstream_announce(struct mptcpd_pm *pm,
struct sockaddr *addr,
mptcpd_aid_t id,
mptcpd_token_t token,
bool nolst)
bool listener)
{
if (!nolst) {
if (listener) {
/**
* Set up MPTCP listening socket.
*
Expand Down

0 comments on commit 4e45fa6

Please sign in to comment.