Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mptcp: add statistics for mptcp socket in use

Do the statistics of mptcp socket in use with sock_prot_inuse_add().
Therefore, we can get the count of used mptcp socket from
/proc/net/protocols:

& cat /proc/net/protocols
protocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em
MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n
MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n

Acked-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Menglong Dong and committed by
David S. Miller
c558246e 294de909

+17 -1
+11 -1
net/mptcp/protocol.c
··· 2891 2891 return EPOLLIN | EPOLLRDNORM; 2892 2892 } 2893 2893 2894 + static void mptcp_listen_inuse_dec(struct sock *sk) 2895 + { 2896 + if (inet_sk_state_load(sk) == TCP_LISTEN) 2897 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 2898 + } 2899 + 2894 2900 bool __mptcp_close(struct sock *sk, long timeout) 2895 2901 { 2896 2902 struct mptcp_subflow_context *subflow; ··· 2906 2900 sk->sk_shutdown = SHUTDOWN_MASK; 2907 2901 2908 2902 if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) { 2903 + mptcp_listen_inuse_dec(sk); 2909 2904 inet_sk_state_store(sk, TCP_CLOSE); 2910 2905 goto cleanup; 2911 2906 } ··· 3007 3000 if (msk->fastopening) 3008 3001 return 0; 3009 3002 3003 + mptcp_listen_inuse_dec(sk); 3010 3004 inet_sk_state_store(sk, TCP_CLOSE); 3011 3005 3012 3006 mptcp_stop_timer(sk); ··· 3665 3657 3666 3658 err = ssock->ops->listen(ssock, backlog); 3667 3659 inet_sk_state_store(sk, inet_sk_state_load(ssock->sk)); 3668 - if (!err) 3660 + if (!err) { 3661 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 3669 3662 mptcp_copy_inaddrs(sk, ssock->sk); 3663 + } 3670 3664 3671 3665 mptcp_event_pm_listener(ssock->sk, MPTCP_EVENT_LISTENER_CREATED); 3672 3666
+6
net/mptcp/token.c
··· 153 153 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); 154 154 struct mptcp_sock *msk = mptcp_sk(subflow->conn); 155 155 int retries = MPTCP_TOKEN_MAX_RETRIES; 156 + struct sock *sk = subflow->conn; 156 157 struct token_bucket *bucket; 157 158 158 159 again: ··· 176 175 __sk_nulls_add_node_rcu((struct sock *)msk, &bucket->msk_chain); 177 176 bucket->chain_len++; 178 177 spin_unlock_bh(&bucket->lock); 178 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 179 179 return 0; 180 180 } 181 181 ··· 192 190 struct mptcp_sock *msk) 193 191 { 194 192 struct mptcp_subflow_request_sock *pos; 193 + struct sock *sk = (struct sock *)msk; 195 194 struct token_bucket *bucket; 196 195 196 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 197 197 bucket = token_bucket(req->token); 198 198 spin_lock_bh(&bucket->lock); 199 199 ··· 374 370 */ 375 371 void mptcp_token_destroy(struct mptcp_sock *msk) 376 372 { 373 + struct sock *sk = (struct sock *)msk; 377 374 struct token_bucket *bucket; 378 375 struct mptcp_sock *pos; 379 376 380 377 if (sk_unhashed((struct sock *)msk)) 381 378 return; 382 379 380 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 383 381 bucket = token_bucket(msk->token); 384 382 spin_lock_bh(&bucket->lock); 385 383 pos = __token_lookup_msk(bucket, msk->token);