refactor mptcp_addr_info and cleanups
Subsystems (2)
Geliang Tang
v2 cover refactor mptcp_addr_info and cleanups
v2:
- Patch 1, avoid changing __mptcp_subflow_connect's parameter, use container_of to get the entry.
- No change in patches 2-7.
The patch set refactored struct mptcp_addr_info, and use it in both mptcp_out_options and mptcp_out_options. Then drop the duplicate code and do cleanups.
Geliang Tang (7):
mptcp: move ifindex and flags out of mptcp_addr_info
mptcp: use mptcp_addr_info in mptcp_out_options
mptcp: use mptcp_addr_info in mptcp_options_received
mptcp: drop MPTCP_ADDR_IPVERSION_4/6
mptcp: unify add_addr(6)_generate_hmac
mptcp: drop OPTION_MPTCP_ADD_ADDR6
mptcp: drop unnecessary CONFIG_MPTCP_IPV6
include/net/mptcp.h | 21 +++-- net/mptcp/options.c | 175 +++++++++++++---------------------------- net/mptcp/pm_netlink.c | 55 +++++-------- net/mptcp/protocol.h | 36 +++------ net/mptcp/subflow.c | 6 +- 5 files changed, 104 insertions(+), 189 deletions(-)
Signature · 1 line
2.30.2
Geliang Tang
PATCH v2 1/7 mptcp: move ifindex and flags out of mptcp_addr_info
This patch moved the ifindex and flags fields from struct mptcp_addr_info to struct mptcp_pm_addr_entry.
It __mptcp_subflow_connect, use container_of to get mptcp_pm_addr_entry from its parameter loc, then read out the entry's ifindex and flags values.
--- net/mptcp/pm_netlink.c | 47 ++++++++++++++++++------------------------ net/mptcp/protocol.h | 11 ++++++++-- net/mptcp/subflow.c | 6 ++++-- 3 files changed, 33 insertions(+), 31 deletions(-)
net/mptcp/pm_netlink.c +20 -27
@@ -22,13 +22,6 @@ static struct genl_family mptcp_genl_family;static int pm_nl_pernet_id; -struct mptcp_pm_addr_entry { -struct list_head list; -struct mptcp_addr_info addr; -struct rcu_head rcu; -struct socket *lsk; -}; -struct mptcp_pm_add_entry {struct list_head list;struct mptcp_addr_info addr;
@@ -168,7 +161,7 @@ select_local_address(const struct pm_nl_pernet *pernet,rcu_read_lock ();__mptcp_flush_join_list (msk);list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) { -if (!(entry->addr.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW )) +if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ))continue ;if (entry->addr.family != sk->sk_family) {
@@ -206,7 +199,7 @@ select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos)* can lead to additional addresses not being announced. */ list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) { -if (!(entry->addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) +if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ))continue ;if (i++ == pos) { ret = entry;
@@ -484,8 +477,8 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) {struct sock *sk = (struct sock *)msk;unsigned int add_addr_accept_max; +struct mptcp_pm_addr_entry local;struct mptcp_addr_info remote; -struct mptcp_addr_info local;unsigned int subflows_max; add_addr_accept_max =mptcp_pm_get_add_addr_accept_max (msk);
@@ -511,10 +504,10 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)if (!remote.port) remote.port = sk->sk_dport;memset (&local,0 ,sizeof (local)); - local.family = remote.family; + local.addr.family = remote.family;spin_unlock_bh (&msk->pm.lock); -__mptcp_subflow_connect (sk, &local, &remote); +__mptcp_subflow_connect (sk, &local.addr, &remote);spin_lock_bh (&msk->pm.lock); add_addr_echo:
@@ -683,7 +676,7 @@ void mptcp_pm_nl_work(struct mptcp_sock *msk)static bool address_use_port (struct mptcp_pm_addr_entry *entry) { -return (entry->addr.flags & +return (entry->flags & (MPTCP_PM_ADDR_FLAG_SIGNAL |MPTCP_PM_ADDR_FLAG_SUBFLOW )) ==MPTCP_PM_ADDR_FLAG_SIGNAL ; }
@@ -735,11 +728,11 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,if (entry->addr.id > pernet->next_id) pernet->next_id = entry->addr.id; -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { addr_max = pernet->add_addr_signal_max;WRITE_ONCE (pernet->add_addr_signal_max, addr_max +1 ); } -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { addr_max = pernet->local_addr_max;WRITE_ONCE (pernet->local_addr_max, addr_max +1 ); }
@@ -841,10 +834,10 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)return -ENOMEM ; entry->addr = skc_local; - entry->addr.ifindex =0 ; - entry->addr.flags =0 ; entry->addr.id =0 ; entry->addr.port =0 ; + entry->ifindex =0 ; + entry->flags =0 ; entry->lsk =NULL ; ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 )
@@ -959,14 +952,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX ]) {u32 val =nla_get_s32 (tb[MPTCP_PM_ADDR_ATTR_IF_IDX ]); - entry->addr.ifindex = val; + entry->ifindex = val; }if (tb[MPTCP_PM_ADDR_ATTR_ID ]) entry->addr.id =nla_get_u8 (tb[MPTCP_PM_ADDR_ATTR_ID ]);if (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]) - entry->addr.flags =nla_get_u32 (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]); + entry->flags =nla_get_u32 (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]);if (tb[MPTCP_PM_ADDR_ATTR_PORT ]) entry->addr.port =htons (nla_get_u16 (tb[MPTCP_PM_ADDR_ATTR_PORT ]));
@@ -1218,11 +1211,11 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)spin_unlock_bh (&pernet->lock);return -EINVAL ; } -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { addr_max = pernet->add_addr_signal_max;WRITE_ONCE (pernet->add_addr_signal_max, addr_max -1 ); } -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { addr_max = pernet->local_addr_max;WRITE_ONCE (pernet->local_addr_max, addr_max -1 ); }
@@ -1338,10 +1331,10 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb, goto nla_put_failure;if (nla_put_u8 (skb,MPTCP_PM_ADDR_ATTR_ID , addr->id)) goto nla_put_failure; -if (nla_put_u32 (skb,MPTCP_PM_ADDR_ATTR_FLAGS , entry->addr.flags)) +if (nla_put_u32 (skb,MPTCP_PM_ADDR_ATTR_FLAGS , entry->flags)) goto nla_put_failure; -if (entry->addr.ifindex && -nla_put_s32 (skb,MPTCP_PM_ADDR_ATTR_IF_IDX , entry->addr.ifindex)) +if (entry->ifindex && +nla_put_s32 (skb,MPTCP_PM_ADDR_ATTR_IF_IDX , entry->ifindex)) goto nla_put_failure; if (addr->family == AF_INET &&
@@ -1569,7 +1562,7 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)if (ret <0 )return ret; -if (addr.addr.flags &MPTCP_PM_ADDR_FLAG_BACKUP ) +if (addr.flags &MPTCP_PM_ADDR_FLAG_BACKUP ) bkup =1 ;list_for_each_entry (entry, &pernet->local_addr_list, list) {
@@ -1579,9 +1572,9 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)return ret;if (bkup) - entry->addr.flags |=MPTCP_PM_ADDR_FLAG_BACKUP ; + entry->flags |=MPTCP_PM_ADDR_FLAG_BACKUP ;else - entry->addr.flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP ; + entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP ; } }
net/mptcp/protocol.h +9 -2
@@ -173,8 +173,6 @@ struct mptcp_addr_info {sa_family_t family;__be16 port;u8 id; -u8 flags; -int ifindex;union {struct in_addr addr;#if IS_ENABLED (CONFIG_MPTCP_IPV6 )
@@ -183,6 +181,15 @@ struct mptcp_addr_info { }; }; +struct mptcp_pm_addr_entry { +struct list_head list; +struct mptcp_addr_info addr; +u8 flags; +int ifindex; +struct rcu_head rcu; +struct socket *lsk; +}; +enum mptcp_pm_status {MPTCP_PM_ADD_ADDR_RECEIVED ,MPTCP_PM_ADD_ADDR_SEND_ACK ,
net/mptcp/subflow.c +4 -2
@@ -1255,6 +1255,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, {struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_subflow_context *subflow; +struct mptcp_pm_addr_entry *entry;struct sockaddr_storage addr;int remote_id = remote->id;int local_id = loc->id;
@@ -1295,7 +1296,8 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,if (addr.ss_family ==AF_INET6 ) addrlen =sizeof (struct sockaddr_in6 );#endif - ssk->sk_bound_dev_if = loc->ifindex; + entry = container_of(loc, struct mptcp_pm_addr_entry, addr); + ssk->sk_bound_dev_if = entry->ifindex; err =kernel_bind (sf, (struct sockaddr *)&addr, addrlen);if (err) goto failed;
@@ -1307,7 +1309,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, subflow->local_id = local_id; subflow->remote_id = remote_id; subflow->request_join =1 ; - subflow->request_bkup = !!(loc->flags &MPTCP_PM_ADDR_FLAG_BACKUP ); + subflow->request_bkup = !!(entry->flags &MPTCP_PM_ADDR_FLAG_BACKUP );mptcp_info2sockaddr (remote, &addr, ssk->sk_family);mptcp_add_pending_subflow (msk, subflow);
Signature · 1 line
2.30.2
Geliang Tang
PATCH v2 2/7 mptcp: use mptcp_addr_info in mptcp_out_options
This patch added a new struct mptcp_addr_info member addr in struct mptcp_out_options, and dropped the original addr, addr6, addr_id and port fields in it. Then we can use opts->addr to get the adding address from PM directly using mptcp_pm_add_addr_signal.
--- include/net/mptcp.h | 21 +++++++++++++-------- net/mptcp/options.c | 42 ++++++++++++++++++------------------------ net/mptcp/protocol.h | 12 ------------ 3 files changed, 31 insertions(+), 44 deletions(-)
include/net/mptcp.h +13 -8
@@ -41,20 +41,25 @@ struct mptcp_rm_list {u8 nr; }; +struct mptcp_addr_info { +u8 id; +sa_family_t family :4 ; +__be16 port; +union { +struct in_addr addr; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +struct in6_addr addr6; +#endif + }; +}; +struct mptcp_out_options {#if IS_ENABLED (CONFIG_MPTCP )u16 suboptions;u64 sndr_key;u64 rcvr_key; -union { -struct in_addr addr; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -struct in6_addr addr6; -#endif - }; -u8 addr_id; -u16 port;u64 ahmac; +struct mptcp_addr_info addr;struct mptcp_rm_list rm_list;u8 join_id;u8 backup;
net/mptcp/options.c +18 -24
110 lines not on this page · raw message
net/mptcp/protocol.h +0 -12
@@ -169,18 +169,6 @@ static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) ((nib & 0xF) << 8) | field); } -struct mptcp_addr_info { -sa_family_t family; -__be16 port; -u8 id; -union { -struct in_addr addr; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -struct in6_addr addr6; -#endif - }; -}; -struct mptcp_pm_addr_entry {struct list_head list;struct mptcp_addr_info addr;
Signature · 1 line
2.30.2
Geliang Tang
PATCH v2 3/7 mptcp: use mptcp_addr_info in mptcp_options_received
This patch added a new struct mptcp_addr_info member addr in struct mptcp_options_received, and dropped the original family, addr_id, addr, addr6 and port fields in it. Then we can pass the parameter mp_opt.addr directly to mptcp_pm_add_addr_received and mptcp_pm_add_addr_echoed.
--- net/mptcp/options.c | 58 +++++++++++++++++--------------------------- net/mptcp/protocol.h | 10 +------- 2 files changed, 23 insertions(+), 45 deletions(-)
net/mptcp/options.c +22 -36
@@ -220,45 +220,45 @@ static void mptcp_parse_option(const struct sk_buff *skb,if (!mp_opt->echo) {if (opsize ==TCPOLEN_MPTCP_ADD_ADDR || opsize ==TCPOLEN_MPTCP_ADD_ADDR_PORT ) - mp_opt->family =MPTCP_ADDR_IPVERSION_4 ; + mp_opt->addr.family =MPTCP_ADDR_IPVERSION_4 ; #if IS_ENABLED(CONFIG_MPTCP_IPV6) else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 || opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT) - mp_opt->family = MPTCP_ADDR_IPVERSION_6; + mp_opt->addr.family = MPTCP_ADDR_IPVERSION_6;#endif else break; }else {if (opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE || opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT ) - mp_opt->family =MPTCP_ADDR_IPVERSION_4 ; + mp_opt->addr.family =MPTCP_ADDR_IPVERSION_4 ; #if IS_ENABLED(CONFIG_MPTCP_IPV6) else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE || opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) - mp_opt->family = MPTCP_ADDR_IPVERSION_6; + mp_opt->addr.family = MPTCP_ADDR_IPVERSION_6;#endif else break; } mp_opt->add_addr =1 ; - mp_opt->addr_id = *ptr++; -if (mp_opt->family ==MPTCP_ADDR_IPVERSION_4 ) { -memcpy ((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr,4 ); + mp_opt->addr.id = *ptr++; +if (mp_opt->addr.family ==MPTCP_ADDR_IPVERSION_4 ) { +memcpy ((u8 *)&mp_opt->addr.addr.s_addr, (u8 *)ptr,4 ); ptr +=4 ;if (opsize ==TCPOLEN_MPTCP_ADD_ADDR_PORT || opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT ) { - mp_opt->port =get_unaligned_be16 (ptr); + mp_opt->addr.port =get_unaligned_be16 (ptr); ptr +=2 ; } }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) else { -memcpy (mp_opt->addr6.s6_addr, (u8 *)ptr,16 ); +memcpy (mp_opt->addr.addr6.s6_addr, (u8 *)ptr,16 ); ptr +=16 ;if (opsize ==TCPOLEN_MPTCP_ADD_ADDR6_PORT || opsize ==TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT ) { - mp_opt->port =get_unaligned_be16 (ptr); + mp_opt->addr.port =get_unaligned_be16 (ptr); ptr +=2 ; } }
@@ -268,8 +268,8 @@ static void mptcp_parse_option(const struct sk_buff *skb, ptr +=8 ; }pr_debug ("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d" , - (mp_opt->family ==MPTCP_ADDR_IPVERSION_6 ) ?"6" :"" , - mp_opt->addr_id, mp_opt->ahmac, mp_opt->echo, mp_opt->port); + (mp_opt->addr.family ==MPTCP_ADDR_IPVERSION_6 ) ?"6" :"" , + mp_opt->addr.id, mp_opt->ahmac, mp_opt->echo,ntohs (mp_opt->addr.port));break ;case MPTCPOPT_RM_ADDR :
@@ -335,7 +335,7 @@ void mptcp_get_options(const struct sk_buff *skb, mp_opt->add_addr =0 ; mp_opt->ahmac =0 ; mp_opt->fastclose =0 ; - mp_opt->port =0 ; + mp_opt->addr.port =0 ; mp_opt->rm_addr =0 ; mp_opt->dss =0 ; mp_opt->mp_prio =0 ;
@@ -992,17 +992,17 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,if (mp_opt->echo)return true; -if (mp_opt->family ==MPTCP_ADDR_IPVERSION_4 ) +if (mp_opt->addr.family ==MPTCP_ADDR_IPVERSION_4 ) hmac =add_addr_generate_hmac (msk->remote_key, msk->local_key, - mp_opt->addr_id, &mp_opt->addr, - mp_opt->port); + mp_opt->addr.id, &mp_opt->addr.addr, + mp_opt->addr.port);#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) else hmac =add_addr6_generate_hmac (msk->remote_key, msk->local_key, - mp_opt->addr_id, &mp_opt->addr6, - mp_opt->port); + mp_opt->addr.id, &mp_opt->addr.addr6, + mp_opt->addr.port);#endif pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
@@ -1044,30 +1044,16 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) }if (mp_opt.add_addr &&add_addr_hmac_valid (msk, &mp_opt)) { -struct mptcp_addr_info addr; - - addr.port =htons (mp_opt.port); - addr.id = mp_opt.addr_id; -if (mp_opt.family ==MPTCP_ADDR_IPVERSION_4 ) { - addr.family =AF_INET ; - addr.addr = mp_opt.addr; - } -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (mp_opt.family == MPTCP_ADDR_IPVERSION_6) { - addr.family =AF_INET6 ; - addr.addr6 = mp_opt.addr6; - } -#endif if (!mp_opt.echo) { -mptcp_pm_add_addr_received (msk, &addr); +mptcp_pm_add_addr_received (msk, &mp_opt.addr);MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_ADDADDR ); }else { -mptcp_pm_add_addr_echoed (msk, &addr); -mptcp_pm_del_add_timer (msk, &addr); +mptcp_pm_add_addr_echoed (msk, &mp_opt.addr); +mptcp_pm_del_add_timer (msk, &mp_opt.addr);MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_ECHOADD ); } -if (mp_opt.port) +if (mp_opt.addr.port)MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_PORTADD ); mp_opt.add_addr =0 ;
net/mptcp/protocol.h +1 -9
@@ -134,7 +134,6 @@ struct mptcp_options_received { add_addr : 1, rm_addr : 1, mp_prio : 1, - family : 4, echo : 1, backup : 1;u32 token;
@@ -149,16 +148,9 @@ struct mptcp_options_received { ack64:1, mpc_map:1, __unused:2; -u8 addr_id; +struct mptcp_addr_info addr;struct mptcp_rm_list rm_list; -union { -struct in_addr addr; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -struct in6_addr addr6; -#endif - };u64 ahmac; -u16 port; u8 reset_reason:4; u8 reset_transient:1; };
Signature · 1 line
2.30.2
Geliang Tang
PATCH v2 4/7 mptcp: drop MPTCP_ADDR_IPVERSION_4/6
Since the type of the address family in struct mptcp_options_received became sa_family_t, we should set AF_INET/AF_INET6 to it, instead of using MPTCP_ADDR_IPVERSION_4/6.
--- net/mptcp/options.c | 14 +++++++------- net/mptcp/protocol.h | 2 -- 2 files changed, 7 insertions(+), 9 deletions(-)
net/mptcp/options.c +7 -7
@@ -220,22 +220,22 @@ static void mptcp_parse_option(const struct sk_buff *skb,if (!mp_opt->echo) {if (opsize ==TCPOLEN_MPTCP_ADD_ADDR || opsize ==TCPOLEN_MPTCP_ADD_ADDR_PORT ) - mp_opt->addr.family =MPTCP_ADDR_IPVERSION_4 ; + mp_opt->addr.family =AF_INET ; #if IS_ENABLED(CONFIG_MPTCP_IPV6) else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 || opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT) - mp_opt->addr.family = MPTCP_ADDR_IPVERSION_6; + mp_opt->addr.family = AF_INET6;#endif else break; }else {if (opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE || opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT ) - mp_opt->addr.family =MPTCP_ADDR_IPVERSION_4 ; + mp_opt->addr.family =AF_INET ; #if IS_ENABLED(CONFIG_MPTCP_IPV6) else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE || opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) - mp_opt->addr.family = MPTCP_ADDR_IPVERSION_6; + mp_opt->addr.family = AF_INET6;#endif else break;
@@ -243,7 +243,7 @@ static void mptcp_parse_option(const struct sk_buff *skb, mp_opt->add_addr =1 ; mp_opt->addr.id = *ptr++; -if (mp_opt->addr.family ==MPTCP_ADDR_IPVERSION_4 ) { +if (mp_opt->addr.family ==AF_INET ) {memcpy ((u8 *)&mp_opt->addr.addr.s_addr, (u8 *)ptr,4 ); ptr +=4 ; if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
@@ -268,7 +268,7 @@ static void mptcp_parse_option(const struct sk_buff *skb, ptr +=8 ; }pr_debug ("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d" , - (mp_opt->addr.family ==MPTCP_ADDR_IPVERSION_6 ) ?"6" :"" , + (mp_opt->addr.family ==AF_INET6 ) ?"6" :"" , mp_opt->addr.id, mp_opt->ahmac, mp_opt->echo,ntohs (mp_opt->addr.port));break ;
@@ -992,7 +992,7 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,if (mp_opt->echo)return true; -if (mp_opt->addr.family ==MPTCP_ADDR_IPVERSION_4 ) +if (mp_opt->addr.family ==AF_INET ) hmac = add_addr_generate_hmac(msk->remote_key, msk->local_key, mp_opt->addr.id, &mp_opt->addr.addr,
net/mptcp/protocol.h +0 -2
@@ -91,8 +91,6 @@/* MPTCP ADD_ADDR flags */ #define MPTCP_ADDR_ECHO BIT(0) -#define MPTCP_ADDR_IPVERSION_4 4 -#define MPTCP_ADDR_IPVERSION_6 6/* MPTCP MP_PRIO flags */ #define MPTCP_PRIO_BKUP BIT(0)
Signature · 1 line
2.30.2
Geliang Tang
PATCH v2 5/7 mptcp: unify add_addr(6)_generate_hmac
The length of the IPv6 address is 16 octets and IPv4 is 4. That's the only difference between add_addr_generate_hmac and add_addr6_generate_hmac.
This patch dropped the duplicate code and unify them into one.
--- net/mptcp/options.c | 82 +++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 55 deletions(-)
net/mptcp/options.c +27 -55
@@ -583,39 +583,31 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,return true; } -static u64 add_addr_generate_hmac (u64 key1,u64 key2,u8 addr_id, -struct in_addr *addr,u16 port) -{ -u8 hmac[SHA256_DIGEST_SIZE ]; -u8 msg[7 ]; - - msg[0 ] = addr_id; -memcpy (&msg[1 ], &addr->s_addr,4 ); - msg[5 ] = port >>8 ; - msg[6 ] = port &0xFF ; - -mptcp_crypto_hmac_sha (key1, key2, msg,7 , hmac); - -return get_unaligned_be64 (&hmac[SHA256_DIGEST_SIZE -sizeof (u64)]); -} - -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -static u64 add_addr6_generate_hmac (u64 key1,u64 key2,u8 addr_id, -struct in6_addr *addr,u16 port) +static u64 add_addr_generate_hmac (u64 key1,u64 key2, +struct mptcp_addr_info *addr) {u8 hmac[SHA256_DIGEST_SIZE ];u8 msg[19 ]; +int i =0 ; - msg[0 ] = addr_id; -memcpy (&msg[1 ], &addr->s6_addr,16 ); - msg[17 ] = port >>8 ; - msg[18 ] = port &0xFF ; + msg[i++] = addr->id; +if (addr->family ==AF_INET ) { +memcpy (&msg[i], &addr->addr.s_addr,4 ); + i +=4 ; + } +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (addr->family == AF_INET6) { +memcpy (&msg[i], &addr->addr6.s6_addr,16 ); + i +=16 ; + } +#endif + msg[i++] = addr->port >>8 ; + msg[i++] = addr->port &0xFF ; -mptcp_crypto_hmac_sha (key1, key2, msg,19 , hmac); +mptcp_crypto_hmac_sha (key1, key2, msg, i, hmac);return get_unaligned_be64 (&hmac[SHA256_DIGEST_SIZE -sizeof (u64)]); } -#endif static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb, unsigned int *size,
@@ -652,28 +644,17 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * *size = len;if (drop_other_suboptions) *size -= opt_size; -if (opts->addr.family ==AF_INET ) { +if (opts->addr.family ==AF_INET ) opts->suboptions |=OPTION_MPTCP_ADD_ADDR ; -if (!echo) { - opts->ahmac =add_addr_generate_hmac (msk->local_key, - msk->remote_key, - opts->addr.id, - &opts->addr.addr, - opts->addr.port); - } - }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (opts->addr.family == AF_INET6) { + else if (opts->addr.family == AF_INET6) opts->suboptions |= OPTION_MPTCP_ADD_ADDR6; -if (!echo) { - opts->ahmac =add_addr6_generate_hmac (msk->local_key, - msk->remote_key, - opts->addr.id, - &opts->addr.addr6, - opts->addr.port); - } - }#endif +if (!echo) { + opts->ahmac =add_addr_generate_hmac (msk->local_key, + msk->remote_key, + &opts->addr); + }pr_debug ("addr_id=%d, ahmac=%llu, echo=%d, port=%d" , opts->addr.id, opts->ahmac, echo,ntohs (opts->addr.port));
@@ -992,18 +973,9 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,if (mp_opt->echo)return true; -if (mp_opt->addr.family ==AF_INET ) - hmac =add_addr_generate_hmac (msk->remote_key, - msk->local_key, - mp_opt->addr.id, &mp_opt->addr.addr, - mp_opt->addr.port); -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else - hmac =add_addr6_generate_hmac (msk->remote_key, - msk->local_key, - mp_opt->addr.id, &mp_opt->addr.addr6, - mp_opt->addr.port); -#endif + hmac =add_addr_generate_hmac (msk->remote_key, + msk->local_key, + &mp_opt->addr); pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n", msk, (unsigned long long)hmac,
Signature · 1 line
2.30.2
Geliang Tang
PATCH v2 6/7 mptcp: drop OPTION_MPTCP_ADD_ADDR6
Since the family field was added in struct mptcp_out_options, no need to use OPTION_MPTCP_ADD_ADDR6 to identify the IPv6 address. Drop it.
--- net/mptcp/options.c | 19 +++++-------------- net/mptcp/protocol.h | 9 ++++----- 2 files changed, 9 insertions(+), 19 deletions(-)
net/mptcp/options.c +5 -14
@@ -644,12 +644,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * *size = len;if (drop_other_suboptions) *size -= opt_size; -if (opts->addr.family ==AF_INET ) - opts->suboptions |=OPTION_MPTCP_ADD_ADDR ; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (opts->addr.family == AF_INET6) - opts->suboptions |= OPTION_MPTCP_ADD_ADDR6; -#endif + opts->suboptions |=OPTION_MPTCP_ADD_ADDR ;if (!echo) { opts->ahmac = add_addr_generate_hmac(msk->local_key, msk->remote_key,
@@ -1156,16 +1151,12 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, } mp_capable_done: - if ((OPTION_MPTCP_ADD_ADDR -#if IS_ENABLED(CONFIG_MPTCP_IPV6) - |OPTION_MPTCP_ADD_ADDR6 -#endif - ) & opts->suboptions) { +if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ;u8 echo =MPTCP_ADDR_ECHO ;#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) +if (opts->addr.family ==AF_INET6 ) len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ;#endif
@@ -1179,12 +1170,12 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , len, echo, opts->addr.id); -if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { +if (opts->addr.family ==AF_INET ) {memcpy ((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr,4 ); ptr +=1 ; }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { + else if (opts->addr.family == AF_INET6) {memcpy ((u8 *)ptr, opts->addr.addr6.s6_addr,16 ); ptr +=4 ; }
net/mptcp/protocol.h +4 -5
@@ -22,11 +22,10 @@#define OPTION_MPTCP_MPJ_SYNACK BIT(4)#define OPTION_MPTCP_MPJ_ACK BIT(5)#define OPTION_MPTCP_ADD_ADDR BIT(6) -#define OPTION_MPTCP_ADD_ADDR6 BIT(7) -#define OPTION_MPTCP_RM_ADDR BIT(8) -#define OPTION_MPTCP_FASTCLOSE BIT(9) -#define OPTION_MPTCP_PRIO BIT(10) -#define OPTION_MPTCP_RST BIT(11) +#define OPTION_MPTCP_RM_ADDR BIT(7) +#define OPTION_MPTCP_FASTCLOSE BIT(8) +#define OPTION_MPTCP_PRIO BIT(9) +#define OPTION_MPTCP_RST BIT(10)/* MPTCP option subtypes */ #define MPTCPOPT_MP_CAPABLE 0
Signature · 1 line
2.30.2
Geliang Tang
PATCH v2 7/7 mptcp: drop unnecessary CONFIG_MPTCP_IPV6
This patch dropped all the unnecessary '#if IS_ENABLED(CONFIG_MPTCP_IPV6)' and '#endif'.
--- net/mptcp/options.c | 6 ------ net/mptcp/pm_netlink.c | 8 +------- 2 files changed, 1 insertion(+), 13 deletions(-)
net/mptcp/options.c +0 -6
@@ -221,22 +221,18 @@ static void mptcp_parse_option(const struct sk_buff *skb,if (opsize ==TCPOLEN_MPTCP_ADD_ADDR || opsize ==TCPOLEN_MPTCP_ADD_ADDR_PORT ) mp_opt->addr.family =AF_INET ; -#if IS_ENABLED(CONFIG_MPTCP_IPV6)else if (opsize ==TCPOLEN_MPTCP_ADD_ADDR6 || opsize ==TCPOLEN_MPTCP_ADD_ADDR6_PORT ) mp_opt->addr.family =AF_INET6 ; -#endif else break ; }else {if (opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE || opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT ) mp_opt->addr.family =AF_INET ; -#if IS_ENABLED(CONFIG_MPTCP_IPV6)else if (opsize ==TCPOLEN_MPTCP_ADD_ADDR6_BASE || opsize ==TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT ) mp_opt->addr.family =AF_INET6 ; -#endif else break ; }
@@ -1155,10 +1151,8 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ;u8 echo =MPTCP_ADDR_ECHO ; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 )if (opts->addr.family ==AF_INET6 ) len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ; -#endif if (opts->addr.port) len +=TCPOLEN_MPTCP_PORT_LEN ;
net/mptcp/pm_netlink.c +1 -7
@@ -889,10 +889,8 @@ static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {static int mptcp_pm_family_to_addr (int family) { -#if IS_ENABLED (CONFIG_MPTCP_IPV6 )if (family ==AF_INET6 )return MPTCP_PM_ADDR_ATTR_ADDR6 ; -#endif return MPTCP_PM_ADDR_ATTR_ADDR4 ; }
@@ -925,11 +923,7 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info, } entry->addr.family =nla_get_u16 (tb[MPTCP_PM_ADDR_ATTR_FAMILY ]); - if (entry->addr.family != AF_INET -#if IS_ENABLED(CONFIG_MPTCP_IPV6) - && entry->addr.family !=AF_INET6 -#endif - ) { +if (entry->addr.family !=AF_INET && entry->addr.family !=AF_INET6 ) {NL_SET_ERR_MSG_ATTR (info->extack, attr,"unknown address family" );return -EINVAL ;
Signature · 1 line
2.30.2
Mat Martineau
[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 7/7] mptcp: drop unnecessary CONFIG_MPTCP_IPV6
Quoted 3 lines · Geliang Tang
This patch dropped all the unnecessary '#if
IS_ENABLED(CONFIG_MPTCP_IPV6)' and '#endif'.
If IPV6 is not enabled, what's the benefit of including the extra IPV6 code? I can see a possible benefit to parsing and sending echo responses to peers that might send ADD_ADDR with IPv6 (because they would not know that the other peer does not have IPv6 enabled), but I don't think that accounts for all the removals in this commit. It would help to explain the motivation in the commit message!
Thanks,
Mat
Quoted 74 lines
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
net/mptcp/options.c| 6 ------net/mptcp/pm_netlink.c| 8 +-------2 files changed, 1 insertion(+), 13 deletions(-)net/mptcp/options.c +0
-6@@ -221,22 +221,18 @@ static void mptcp_parse_option(const struct sk_buff *skb,if (opsize ==TCPOLEN_MPTCP_ADD_ADDR || opsize ==TCPOLEN_MPTCP_ADD_ADDR_PORT ) mp_opt->addr.family =AF_INET ; -#if IS_ENABLED(CONFIG_MPTCP_IPV6)else if (opsize ==TCPOLEN_MPTCP_ADD_ADDR6 || opsize ==TCPOLEN_MPTCP_ADD_ADDR6_PORT ) mp_opt->addr.family =AF_INET6 ; -#endif else break ; }else {if (opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE || opsize ==TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT ) mp_opt->addr.family =AF_INET ; -#if IS_ENABLED(CONFIG_MPTCP_IPV6)else if (opsize ==TCPOLEN_MPTCP_ADD_ADDR6_BASE || opsize ==TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT ) mp_opt->addr.family =AF_INET6 ; -#endif else break ; }@@ -1155,10 +1151,8 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ;u8 echo =MPTCP_ADDR_ECHO ; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 )if (opts->addr.family ==AF_INET6 ) len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ; -#endif if (opts->addr.port) len +=TCPOLEN_MPTCP_PORT_LEN ;net/mptcp/pm_netlink.c +1
-7@@ -889,10 +889,8 @@ static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {static int mptcp_pm_family_to_addr (int family) { -#if IS_ENABLED (CONFIG_MPTCP_IPV6 )if (family ==AF_INET6 )return MPTCP_PM_ADDR_ATTR_ADDR6 ; -#endif return MPTCP_PM_ADDR_ATTR_ADDR4 ; }@@ -925,11 +923,7 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info, } entry->addr.family =nla_get_u16 (tb[MPTCP_PM_ADDR_ATTR_FAMILY ]); - if (entry->addr.family != AF_INET -#if IS_ENABLED(CONFIG_MPTCP_IPV6) - && entry->addr.family !=AF_INET6 -#endif - ) { +if (entry->addr.family !=AF_INET && entry->addr.family !=AF_INET6 ) {NL_SET_ERR_MSG_ATTR (info->extack, attr,"unknown address family" );return -EINVAL ;Signature · 1 line
2.30.2
--
Mat Martineau
Intel
Mat Martineau
[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 1/7] mptcp: move ifindex and flags out of mptcp_addr_info
In reply to Geliang TangQuoted 216 lines · Geliang Tang
This patch moved the ifindex and flags fields from struct
mptcp_addr_infoto structmptcp_pm_addr_entry.It
__mptcp_subflow_connect, usecontainer_ofto getmptcp_pm_addr_entryfrom its parameter loc, then read out the entry's ifindex and flags values.Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
net/mptcp/pm_netlink.c | 47 ++++++++++++++++++------------------------ net/mptcp/protocol.h | 11 ++++++++-- net/mptcp/subflow.c | 6 ++++-- 3 files changed, 33 insertions(+), 31 deletions(-)net/mptcp/pm_netlink.c +5
-12@@ -22,13 +22,6 @@ static struct genl_family mptcp_genl_family;static int pm_nl_pernet_id; -struct mptcp_pm_addr_entry { -struct list_head list; -struct mptcp_addr_info addr; -struct rcu_head rcu; -struct socket *lsk; -}; -struct mptcp_pm_add_entry {struct list_head list;struct mptcp_addr_info addr;@@ -168,7 +161,7 @@ select_local_address(const struct pm_nl_pernet *pernet,rcu_read_lock ();__mptcp_flush_join_list (msk);list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) { -if (!(entry->addr.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW )) +if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ))continue ;if (entry->addr.family != sk->sk_family) {@@ -206,7 +199,7 @@ select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos)* can lead to additional addresses not being announced. */ list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) { -if (!(entry->addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) +if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ))continue ;if (i++ == pos) { ret = entry;@@ -484,8 +477,8 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) {struct sock *sk = (struct sock *)msk;unsigned int add_addr_accept_max; +struct mptcp_pm_addr_entry local;struct mptcp_addr_info remote; -struct mptcp_addr_info local;unsigned int subflows_max; add_addr_accept_max =mptcp_pm_get_add_addr_accept_max (msk);@@ -511,10 +504,10 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)if (!remote.port) remote.port = sk->sk_dport;memset (&local,0 ,sizeof (local)); - local.family = remote.family; + local.addr.family = remote.family;spin_unlock_bh (&msk->pm.lock); -__mptcp_subflow_connect (sk, &local, &remote); +__mptcp_subflow_connect (sk, &local.addr, &remote);spin_lock_bh (&msk->pm.lock);
add_addr_echo:net/mptcp/pm_netlink.c +15
-15@@ -683,7 +676,7 @@ void mptcp_pm_nl_work(struct mptcp_sock *msk)static bool address_use_port (struct mptcp_pm_addr_entry *entry) { -return (entry->addr.flags & +return (entry->flags & (MPTCP_PM_ADDR_FLAG_SIGNAL |MPTCP_PM_ADDR_FLAG_SUBFLOW )) ==MPTCP_PM_ADDR_FLAG_SIGNAL ; }@@ -735,11 +728,11 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,if (entry->addr.id > pernet->next_id) pernet->next_id = entry->addr.id; -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { addr_max = pernet->add_addr_signal_max;WRITE_ONCE (pernet->add_addr_signal_max, addr_max +1 ); } -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { addr_max = pernet->local_addr_max;WRITE_ONCE (pernet->local_addr_max, addr_max +1 ); }@@ -841,10 +834,10 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)return -ENOMEM ; entry->addr = skc_local; - entry->addr.ifindex =0 ; - entry->addr.flags =0 ; entry->addr.id =0 ; entry->addr.port =0 ; + entry->ifindex =0 ; + entry->flags =0 ; entry->lsk =NULL ; ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 )@@ -959,14 +952,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX ]) {u32 val =nla_get_s32 (tb[MPTCP_PM_ADDR_ATTR_IF_IDX ]); - entry->addr.ifindex = val; + entry->ifindex = val; }if (tb[MPTCP_PM_ADDR_ATTR_ID ]) entry->addr.id =nla_get_u8 (tb[MPTCP_PM_ADDR_ATTR_ID ]);if (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]) - entry->addr.flags =nla_get_u32 (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]); + entry->flags =nla_get_u32 (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]);if (tb[MPTCP_PM_ADDR_ATTR_PORT ]) entry->addr.port =htons (nla_get_u16 (tb[MPTCP_PM_ADDR_ATTR_PORT ]));@@ -1218,11 +1211,11 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)spin_unlock_bh (&pernet->lock);return -EINVAL ; } -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { addr_max = pernet->add_addr_signal_max;WRITE_ONCE (pernet->add_addr_signal_max, addr_max -1 ); } -if (entry->addr.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { +if (entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { addr_max = pernet->local_addr_max;WRITE_ONCE (pernet->local_addr_max, addr_max -1 ); }@@ -1338,10 +1331,10 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb, goto nla_put_failure;if (nla_put_u8 (skb,MPTCP_PM_ADDR_ATTR_ID , addr->id)) goto nla_put_failure; -if (nla_put_u32 (skb,MPTCP_PM_ADDR_ATTR_FLAGS , entry->addr.flags)) +if (nla_put_u32 (skb,MPTCP_PM_ADDR_ATTR_FLAGS , entry->flags)) goto nla_put_failure; -if (entry->addr.ifindex && -nla_put_s32 (skb,MPTCP_PM_ADDR_ATTR_IF_IDX , entry->addr.ifindex)) +if (entry->ifindex && +nla_put_s32 (skb,MPTCP_PM_ADDR_ATTR_IF_IDX , entry->ifindex)) goto nla_put_failure; if (addr->family == AF_INET &&@@ -1569,7 +1562,7 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)if (ret <0 )return ret; -if (addr.addr.flags &MPTCP_PM_ADDR_FLAG_BACKUP ) +if (addr.flags &MPTCP_PM_ADDR_FLAG_BACKUP ) bkup =1 ;list_for_each_entry (entry, &pernet->local_addr_list, list) {@@ -1579,9 +1572,9 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)return ret;if (bkup) - entry->addr.flags |=MPTCP_PM_ADDR_FLAG_BACKUP ; + entry->flags |=MPTCP_PM_ADDR_FLAG_BACKUP ;else - entry->addr.flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP ; + entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP ; } }net/mptcp/protocol.h +9
-2@@ -173,8 +173,6 @@ struct mptcp_addr_info {sa_family_t family;__be16 port;u8 id; -u8 flags; -int ifindex;union {struct in_addr addr;#if IS_ENABLED (CONFIG_MPTCP_IPV6 )@@ -183,6 +181,15 @@ struct mptcp_addr_info { }; }; +struct mptcp_pm_addr_entry { +struct list_head list; +struct mptcp_addr_info addr; +u8 flags; +int ifindex; +struct rcu_head rcu; +struct socket *lsk; +}; +enum mptcp_pm_status {MPTCP_PM_ADD_ADDR_RECEIVED ,MPTCP_PM_ADD_ADDR_SEND_ACK ,net/mptcp/subflow.c +1
-0@@ -1255,6 +1255,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, {struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_subflow_context *subflow; +struct mptcp_pm_addr_entry *entry;struct sockaddr_storage addr;int remote_id = remote->id;int local_id = loc->id;
net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1299
Quoted 5 lines
net/mptcp/subflow.c +1
-1@@ -1295,7 +1296,8 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,if (addr.ss_family ==AF_INET6 ) addrlen =sizeof (struct sockaddr_in6 );#endif - ssk->sk_bound_dev_if = loc->ifindex; + entry = container_of(loc, struct mptcp_pm_addr_entry, addr);
I prefer the v1 approach of changing the function parameter. If you'd like to avoid moving the mptcp_pm_addr_entry struct to protocol.h, maybe add parameters to this function for flags and ifindex instead?
Quoted 15 lines
net/mptcp/subflow.c +2
-1+ ssk->sk_bound_dev_if = entry->ifindex; err =kernel_bind (sf, (struct sockaddr *)&addr, addrlen);if (err) goto failed;@@ -1307,7 +1309,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, subflow->local_id = local_id; subflow->remote_id = remote_id; subflow->request_join =1 ; - subflow->request_bkup = !!(loc->flags &MPTCP_PM_ADDR_FLAG_BACKUP ); + subflow->request_bkup = !!(entry->flags &MPTCP_PM_ADDR_FLAG_BACKUP );mptcp_info2sockaddr (remote, &addr, ssk->sk_family);mptcp_add_pending_subflow (msk, subflow);Signature · 1 line
2.30.2
--
Mat Martineau
Intel