Skip to content

Commit a38a211

Browse files
committed
Merge branch 'mptcp-fix-ipv6-reqsk-ops-and-some-netlink-error-codes'
Mat Martineau says: ==================== mptcp: Fix IPv6 reqsk ops and some netlink error codes Patch 1 adds some missing error status values for MPTCP path management netlink commands with invalid attributes. Patches 2-4 make IPv6 subflows use the correct request_sock_ops structure and IPv6-specific destructor. The first patch in this group is a prerequisite change that simplifies the last two patches. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 84698da + d3295fe commit a38a211

File tree

4 files changed

+68
-16
lines changed

4 files changed

+68
-16
lines changed

include/net/mptcp.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ struct mptcp_out_options {
9797
};
9898

9999
#ifdef CONFIG_MPTCP
100-
extern struct request_sock_ops mptcp_subflow_request_sock_ops;
101-
102100
void mptcp_init(void);
103101

104102
static inline bool sk_is_mptcp(const struct sock *sk)
@@ -188,6 +186,9 @@ void mptcp_seq_show(struct seq_file *seq);
188186
int mptcp_subflow_init_cookie_req(struct request_sock *req,
189187
const struct sock *sk_listener,
190188
struct sk_buff *skb);
189+
struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops,
190+
struct sock *sk_listener,
191+
bool attach_listener);
191192

192193
__be32 mptcp_get_reset_option(const struct sk_buff *skb);
193194

@@ -274,6 +275,13 @@ static inline int mptcp_subflow_init_cookie_req(struct request_sock *req,
274275
return 0; /* TCP fallback */
275276
}
276277

278+
static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops,
279+
struct sock *sk_listener,
280+
bool attach_listener)
281+
{
282+
return NULL;
283+
}
284+
277285
static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { return htonl(0u); }
278286
#endif /* CONFIG_MPTCP */
279287

net/ipv4/syncookies.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,11 @@ struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops,
288288
struct tcp_request_sock *treq;
289289
struct request_sock *req;
290290

291-
#ifdef CONFIG_MPTCP
292291
if (sk_is_mptcp(sk))
293-
ops = &mptcp_subflow_request_sock_ops;
294-
#endif
292+
req = mptcp_subflow_reqsk_alloc(ops, sk, false);
293+
else
294+
req = inet_reqsk_alloc(ops, sk, false);
295295

296-
req = inet_reqsk_alloc(ops, sk, false);
297296
if (!req)
298297
return NULL;
299298

net/mptcp/pm_userspace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
156156

157157
if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
158158
GENL_SET_ERR_MSG(info, "invalid addr id or flags");
159+
err = -EINVAL;
159160
goto announce_err;
160161
}
161162

@@ -282,6 +283,7 @@ int mptcp_nl_cmd_sf_create(struct sk_buff *skb, struct genl_info *info)
282283

283284
if (addr_l.id == 0) {
284285
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local addr id");
286+
err = -EINVAL;
285287
goto create_err;
286288
}
287289

@@ -395,11 +397,13 @@ int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info)
395397

396398
if (addr_l.family != addr_r.family) {
397399
GENL_SET_ERR_MSG(info, "address families do not match");
400+
err = -EINVAL;
398401
goto destroy_err;
399402
}
400403

401404
if (!addr_l.port || !addr_r.port) {
402405
GENL_SET_ERR_MSG(info, "missing local or remote port");
406+
err = -EINVAL;
403407
goto destroy_err;
404408
}
405409

net/mptcp/subflow.c

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static void subflow_req_destructor(struct request_sock *req)
4545
sock_put((struct sock *)subflow_req->msk);
4646

4747
mptcp_token_destroy_request(req);
48-
tcp_request_sock_ops.destructor(req);
4948
}
5049

5150
static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
@@ -529,7 +528,7 @@ static int subflow_v6_rebuild_header(struct sock *sk)
529528
}
530529
#endif
531530

532-
struct request_sock_ops mptcp_subflow_request_sock_ops;
531+
static struct request_sock_ops mptcp_subflow_v4_request_sock_ops __ro_after_init;
533532
static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops __ro_after_init;
534533

535534
static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb)
@@ -542,15 +541,22 @@ static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb)
542541
if (skb_rtable(skb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
543542
goto drop;
544543

545-
return tcp_conn_request(&mptcp_subflow_request_sock_ops,
544+
return tcp_conn_request(&mptcp_subflow_v4_request_sock_ops,
546545
&subflow_request_sock_ipv4_ops,
547546
sk, skb);
548547
drop:
549548
tcp_listendrop(sk);
550549
return 0;
551550
}
552551

552+
static void subflow_v4_req_destructor(struct request_sock *req)
553+
{
554+
subflow_req_destructor(req);
555+
tcp_request_sock_ops.destructor(req);
556+
}
557+
553558
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
559+
static struct request_sock_ops mptcp_subflow_v6_request_sock_ops __ro_after_init;
554560
static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops __ro_after_init;
555561
static struct inet_connection_sock_af_ops subflow_v6_specific __ro_after_init;
556562
static struct inet_connection_sock_af_ops subflow_v6m_specific __ro_after_init;
@@ -573,15 +579,36 @@ static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb)
573579
return 0;
574580
}
575581

576-
return tcp_conn_request(&mptcp_subflow_request_sock_ops,
582+
return tcp_conn_request(&mptcp_subflow_v6_request_sock_ops,
577583
&subflow_request_sock_ipv6_ops, sk, skb);
578584

579585
drop:
580586
tcp_listendrop(sk);
581587
return 0; /* don't send reset */
582588
}
589+
590+
static void subflow_v6_req_destructor(struct request_sock *req)
591+
{
592+
subflow_req_destructor(req);
593+
tcp6_request_sock_ops.destructor(req);
594+
}
595+
#endif
596+
597+
struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops,
598+
struct sock *sk_listener,
599+
bool attach_listener)
600+
{
601+
if (ops->family == AF_INET)
602+
ops = &mptcp_subflow_v4_request_sock_ops;
603+
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
604+
else if (ops->family == AF_INET6)
605+
ops = &mptcp_subflow_v6_request_sock_ops;
583606
#endif
584607

608+
return inet_reqsk_alloc(ops, sk_listener, attach_listener);
609+
}
610+
EXPORT_SYMBOL(mptcp_subflow_reqsk_alloc);
611+
585612
/* validate hmac received in third ACK */
586613
static bool subflow_hmac_valid(const struct request_sock *req,
587614
const struct mptcp_options_received *mp_opt)
@@ -1904,7 +1931,6 @@ static struct tcp_ulp_ops subflow_ulp_ops __read_mostly = {
19041931
static int subflow_ops_init(struct request_sock_ops *subflow_ops)
19051932
{
19061933
subflow_ops->obj_size = sizeof(struct mptcp_subflow_request_sock);
1907-
subflow_ops->slab_name = "request_sock_subflow";
19081934

19091935
subflow_ops->slab = kmem_cache_create(subflow_ops->slab_name,
19101936
subflow_ops->obj_size, 0,
@@ -1914,16 +1940,17 @@ static int subflow_ops_init(struct request_sock_ops *subflow_ops)
19141940
if (!subflow_ops->slab)
19151941
return -ENOMEM;
19161942

1917-
subflow_ops->destructor = subflow_req_destructor;
1918-
19191943
return 0;
19201944
}
19211945

19221946
void __init mptcp_subflow_init(void)
19231947
{
1924-
mptcp_subflow_request_sock_ops = tcp_request_sock_ops;
1925-
if (subflow_ops_init(&mptcp_subflow_request_sock_ops) != 0)
1926-
panic("MPTCP: failed to init subflow request sock ops\n");
1948+
mptcp_subflow_v4_request_sock_ops = tcp_request_sock_ops;
1949+
mptcp_subflow_v4_request_sock_ops.slab_name = "request_sock_subflow_v4";
1950+
mptcp_subflow_v4_request_sock_ops.destructor = subflow_v4_req_destructor;
1951+
1952+
if (subflow_ops_init(&mptcp_subflow_v4_request_sock_ops) != 0)
1953+
panic("MPTCP: failed to init subflow v4 request sock ops\n");
19271954

19281955
subflow_request_sock_ipv4_ops = tcp_request_sock_ipv4_ops;
19291956
subflow_request_sock_ipv4_ops.route_req = subflow_v4_route_req;
@@ -1938,6 +1965,20 @@ void __init mptcp_subflow_init(void)
19381965
tcp_prot_override.release_cb = tcp_release_cb_override;
19391966

19401967
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
1968+
/* In struct mptcp_subflow_request_sock, we assume the TCP request sock
1969+
* structures for v4 and v6 have the same size. It should not changed in
1970+
* the future but better to make sure to be warned if it is no longer
1971+
* the case.
1972+
*/
1973+
BUILD_BUG_ON(sizeof(struct tcp_request_sock) != sizeof(struct tcp6_request_sock));
1974+
1975+
mptcp_subflow_v6_request_sock_ops = tcp6_request_sock_ops;
1976+
mptcp_subflow_v6_request_sock_ops.slab_name = "request_sock_subflow_v6";
1977+
mptcp_subflow_v6_request_sock_ops.destructor = subflow_v6_req_destructor;
1978+
1979+
if (subflow_ops_init(&mptcp_subflow_v6_request_sock_ops) != 0)
1980+
panic("MPTCP: failed to init subflow v6 request sock ops\n");
1981+
19411982
subflow_request_sock_ipv6_ops = tcp_request_sock_ipv6_ops;
19421983
subflow_request_sock_ipv6_ops.route_req = subflow_v6_route_req;
19431984

0 commit comments

Comments
 (0)