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

Implement set_backup() for upstream kernel. #254

Merged
merged 4 commits into from
Aug 11, 2022
Merged
Changes from all 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
126 changes: 92 additions & 34 deletions src/netlink_pm_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ static int send_add_addr(struct mptcpd_pm *pm,

/*
Payload (nested):
Local address family
Local address
Local port (optional)
Local address ID (optional)
(nested)
Local address family
Local address
Local port (optional)
Local address ID (optional)
Flags (optional)
Network interface index (optional)
Token (required for user space MPTCP_PM_CMD_ANNOUNCE)
Flags (optional)
Network inteface index (optional)
*/

// Types chosen to match MPTCP genl API.
Expand Down Expand Up @@ -346,16 +347,25 @@ static int upstream_add_subflow(struct mptcpd_pm *pm,
(void) remote_id;
(void) backup;

/**
* @todo Flags, like @c MPTCP_PM_ADDR_FLAG_BACKUP are not
* parsed in the kernel when the user space creates a
* subflow. Should we call @c upstream_set_backup() if
* @a backup is @c true or just drop the @a backup
* parameter altogether?
*/

/*
Payload (nested):
Payload:
Token
Local address ID
Local address family
Local address
Remote address family
Remote address
Remote port

(nested)
Local address ID
Local address family
Local address
(nested)
Remote address family
Remote address
Remote port
*/

/**
Expand Down Expand Up @@ -412,15 +422,16 @@ static int upstream_remove_subflow(struct mptcpd_pm *pm,
struct sockaddr const *remote_addr)
{
/*
Payload (nested):
Payload:
Token
Local address family
Local address
Local port
Remote address family
Remote address
Remote port

(nested)
Local address family
Local address
Local port
(nested)
Remote address family
Remote address
Remote port
*/

struct addr_info local = {
Expand Down Expand Up @@ -472,13 +483,63 @@ static int upstream_set_backup(struct mptcpd_pm *pm,
struct sockaddr const *remote_addr,
bool backup)
{
(void) pm;
(void) token;
(void) local_addr;
(void) remote_addr;
(void) backup;
/*
Payload:
Token
(nested)
Local address family
Local address
Local port
Local flags (backup)
(nested)
Remote address family
Remote address
Remote port
*/

struct addr_info local = {
.addr = local_addr,
.flags = (backup ? MPTCP_PM_ADDR_FLAG_BACKUP : 0)
};

struct addr_info remote = {
.addr = remote_addr,
};

return ENOTSUP;
size_t const payload_size =
MPTCPD_NLA_ALIGN(token)
+ MPTCPD_NLA_ALIGN(sizeof(uint16_t)) // local family
+ MPTCPD_NLA_ALIGN_ADDR(local_addr)
+ MPTCPD_NLA_ALIGN(sizeof(uint16_t)) // local port
+ MPTCPD_NLA_ALIGN(sizeof(local.flags))
+ MPTCPD_NLA_ALIGN(sizeof(uint16_t)) // remote family
+ MPTCPD_NLA_ALIGN_ADDR(remote_addr)
+ MPTCPD_NLA_ALIGN(sizeof(uint16_t)); // remote port

struct l_genl_msg *const msg =
l_genl_msg_new_sized(MPTCP_PM_CMD_SET_FLAGS,
payload_size);

bool const appended =
l_genl_msg_append_attr(
msg,
MPTCP_PM_ATTR_TOKEN,
sizeof(token), // sizeof(uint32_t)
&token)
&& append_local_addr_attr(msg, &local)
&& append_remote_addr_attr(msg, &remote);

if (!appended) {
l_genl_msg_unref(msg);

return ENOMEM;
}

return l_genl_family_send(pm->family,
msg,
mptcpd_family_send_callback,
"set_backup", /* user data */
NULL /* destroy */) == 0;
}

// --------------------------------------------------------------
Expand Down Expand Up @@ -652,7 +713,7 @@ static void get_addr_callback(struct l_genl_msg *msg, void *user_data)
Network address
Address ID
Flags
Network
Network interface index
*/

uint16_t type;
Expand Down Expand Up @@ -753,11 +814,8 @@ static void get_limits_callback(struct l_genl_msg *msg, void *user_data)
}

/*
Payload (nested):
Network address
Address ID
Flags
Network
Payload:
MPTCP limit
*/

uint16_t type;
Expand Down