Skip to content

Commit 334bb9c

Browse files
authored
Make listening socket creation optional. (#297)
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.
1 parent b102523 commit 334bb9c

File tree

5 files changed

+76
-31
lines changed

5 files changed

+76
-31
lines changed

include/mptcpd/path_manager.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ MPTCPD_API int mptcpd_pm_add_addr(struct mptcpd_pm *pm,
126126
mptcpd_aid_t id,
127127
mptcpd_token_t token);
128128

129+
/**
130+
* @brief Advertise new network address to peers without creating a listener.
131+
*
132+
* @param[in] pm The mptcpd path manager object.
133+
* @param[in,out] addr Local IP address and port to be advertised
134+
* through the MPTCP protocol @c ADD_ADDR
135+
* option. If the port is zero no port will be
136+
* specified on the underlying protocol level.
137+
* @param[in] id MPTCP local address ID.
138+
* @param[in] token MPTCP connection token.
139+
*
140+
* @return @c 0 if operation was successful. -1 or @c errno otherwise.
141+
*/
142+
MPTCPD_API int mptcpd_pm_add_addr_no_listener(struct mptcpd_pm *pm,
143+
struct sockaddr *addr,
144+
mptcpd_aid_t id,
145+
mptcpd_token_t token);
146+
129147
/**
130148
* @brief Stop advertising network address to peers.
131149
*

include/mptcpd/private/path_manager.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,31 @@ struct mptcpd_pm_cmd_ops
138138
/**
139139
* @brief Advertise new network address to peers.
140140
*
141-
* @param[in] pm The mptcpd path manager object.
142-
* @param[in,out] addr Local IP address and port to be
143-
* advertised through the MPTCP protocol
144-
* @c ADD_ADDR option. If the port is
145-
* zero an ephemeral port will be chosen,
146-
* and assigned to the appropriate
147-
* underlying address family-specific
148-
* port member, e.g. @c sin_port or
149-
* @c sin6_port. The port will be in
150-
* network byte order.
151-
* @param[in] id MPTCP local address ID.
152-
* @param[in] token MPTCP connection token.
141+
* @param[in] pm The mptcpd path manager object.
142+
* @param[in,out] addr Local IP address and port to be
143+
* advertised through the MPTCP protocol
144+
* @c ADD_ADDR option. If the port is
145+
* zero an ephemeral port will be chosen,
146+
* and assigned to the appropriate
147+
* underlying address family-specific
148+
* port member, e.g. @c sin_port or
149+
* @c sin6_port. The port will be in
150+
* network byte order.
151+
* If listener is not created, port zero
152+
* will cause no port specification at
153+
* protocol level.
154+
* @param[in] id MPTCP local address ID.
155+
* @param[in] token MPTCP connection token.
156+
* @param[in] listener Create listener.
153157
*
154158
* @return @c 0 if operation was successful. -1 or @c errno
155159
* otherwise.
156160
*/
157161
int (*add_addr)(struct mptcpd_pm *pm,
158162
struct sockaddr *addr,
159163
mptcpd_aid_t id,
160-
mptcpd_token_t token);
164+
mptcpd_token_t token,
165+
bool listener);
161166

162167
/**
163168
* @brief Stop advertising network address to peers.

lib/path_manager.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,11 @@ int mptcpd_kpm_set_flags(struct mptcpd_pm *pm,
238238

239239
// -------------------------------------------------------------------
240240

241-
int mptcpd_pm_add_addr(struct mptcpd_pm *pm,
242-
struct sockaddr *addr,
243-
mptcpd_aid_t address_id,
244-
mptcpd_token_t token)
241+
static int do_pm_add_addr(struct mptcpd_pm *pm,
242+
struct sockaddr *addr,
243+
mptcpd_aid_t address_id,
244+
mptcpd_token_t token,
245+
bool listener)
245246
{
246247
if (pm == NULL || addr == NULL || address_id == 0)
247248
return EINVAL;
@@ -258,7 +259,24 @@ int mptcpd_pm_add_addr(struct mptcpd_pm *pm,
258259
return ops->add_addr(pm,
259260
addr,
260261
address_id,
261-
token);
262+
token,
263+
listener);
264+
}
265+
266+
int mptcpd_pm_add_addr(struct mptcpd_pm *pm,
267+
struct sockaddr *addr,
268+
mptcpd_aid_t address_id,
269+
mptcpd_token_t token)
270+
{
271+
return do_pm_add_addr(pm, addr, address_id, token, true);
272+
}
273+
274+
int mptcpd_pm_add_addr_no_listener(struct mptcpd_pm *pm,
275+
struct sockaddr *addr,
276+
mptcpd_aid_t address_id,
277+
mptcpd_token_t token)
278+
{
279+
return do_pm_add_addr(pm, addr, address_id, token, false);
262280
}
263281

264282
int mptcpd_pm_remove_addr(struct mptcpd_pm *pm,

src/netlink_pm_mptcp_org.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@ static bool append_remote_addr_attr(struct l_genl_msg *msg,
155155
static int mptcp_org_add_addr(struct mptcpd_pm *pm,
156156
struct sockaddr *addr,
157157
mptcpd_aid_t id,
158-
mptcpd_token_t token)
158+
mptcpd_token_t token,
159+
bool listener)
159160
{
161+
(void) listener;
162+
160163
/*
161164
Payload:
162165
Token

src/netlink_pm_upstream.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,21 @@ static int send_add_addr(struct mptcpd_pm *pm,
219219
static int upstream_announce(struct mptcpd_pm *pm,
220220
struct sockaddr *addr,
221221
mptcpd_aid_t id,
222-
mptcpd_token_t token)
222+
mptcpd_token_t token,
223+
bool listener)
223224
{
224-
/**
225-
* Set up MPTCP listening socket.
226-
*
227-
* @note An ephemeral port will be assigned to the port in
228-
* @a addr if it is zero.
229-
*
230-
* @todo This should be optional.
231-
*/
232-
int const r = mptcpd_lm_listen(pm->lm, addr);
225+
if (listener) {
226+
/**
227+
* Set up MPTCP listening socket.
228+
*
229+
* @note An ephemeral port will be assigned to the port in
230+
* @a addr if it is zero.
231+
*/
232+
int const r = mptcpd_lm_listen(pm->lm, addr);
233233

234-
if (r != 0)
235-
return r;
234+
if (r != 0)
235+
return r;
236+
}
236237

237238
/**
238239
* @todo Add support for the optional network interface index

0 commit comments

Comments
 (0)