Skip to content

Commit d9cd27b

Browse files
Geliang Tangdavem330
authored andcommitted
mptcp: add CurrEstab MIB counter support
Add a new MIB counter named MPTCP_MIB_CURRESTAB to count current established MPTCP connections, similar to TCP_MIB_CURRESTAB. This is useful to quickly list the number of MPTCP connections without having to iterate over all of them. This patch adds a new helper function mptcp_set_state(): if the state switches from or to ESTABLISHED state, this newly added counter is incremented. This helper is going to be used in the following patch. Similar to MPTCP_INC_STATS(), a new helper called MPTCP_DEC_STATS() is also needed to decrement a MIB counter. Signed-off-by: Geliang Tang <[email protected]> Acked-by: Paolo Abeni <[email protected]> Reviewed-by: Matthieu Baerts <[email protected]> Signed-off-by: Matthieu Baerts <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 42a7889 commit d9cd27b

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

net/mptcp/mib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static const struct snmp_mib mptcp_snmp_list[] = {
6666
SNMP_MIB_ITEM("RcvWndShared", MPTCP_MIB_RCVWNDSHARED),
6767
SNMP_MIB_ITEM("RcvWndConflictUpdate", MPTCP_MIB_RCVWNDCONFLICTUPDATE),
6868
SNMP_MIB_ITEM("RcvWndConflict", MPTCP_MIB_RCVWNDCONFLICT),
69+
SNMP_MIB_ITEM("MPCurrEstab", MPTCP_MIB_CURRESTAB),
6970
SNMP_MIB_SENTINEL
7071
};
7172

net/mptcp/mib.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ enum linux_mptcp_mib_field {
6565
* conflict with another subflow while updating msk rcv wnd
6666
*/
6767
MPTCP_MIB_RCVWNDCONFLICT, /* Conflict with while updating msk rcv wnd */
68+
MPTCP_MIB_CURRESTAB, /* Current established MPTCP connections */
6869
__MPTCP_MIB_MAX
6970
};
7071

@@ -95,4 +96,11 @@ static inline void __MPTCP_INC_STATS(struct net *net,
9596
__SNMP_INC_STATS(net->mib.mptcp_statistics, field);
9697
}
9798

99+
static inline void MPTCP_DEC_STATS(struct net *net,
100+
enum linux_mptcp_mib_field field)
101+
{
102+
if (likely(net->mib.mptcp_statistics))
103+
SNMP_DEC_STATS(net->mib.mptcp_statistics, field);
104+
}
105+
98106
bool mptcp_mib_alloc(struct net *net);

net/mptcp/protocol.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,6 +2871,24 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
28712871
release_sock(ssk);
28722872
}
28732873

2874+
void mptcp_set_state(struct sock *sk, int state)
2875+
{
2876+
int oldstate = sk->sk_state;
2877+
2878+
switch (state) {
2879+
case TCP_ESTABLISHED:
2880+
if (oldstate != TCP_ESTABLISHED)
2881+
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
2882+
break;
2883+
2884+
default:
2885+
if (oldstate == TCP_ESTABLISHED)
2886+
MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
2887+
}
2888+
2889+
inet_sk_state_store(sk, state);
2890+
}
2891+
28742892
static const unsigned char new_state[16] = {
28752893
/* current state: new state: action: */
28762894
[0 /* (Invalid) */] = TCP_CLOSE,

net/mptcp/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ bool __mptcp_close(struct sock *sk, long timeout);
641641
void mptcp_cancel_work(struct sock *sk);
642642
void __mptcp_unaccepted_force_close(struct sock *sk);
643643
void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk);
644+
void mptcp_set_state(struct sock *sk, int state);
644645

645646
bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
646647
const struct mptcp_addr_info *b, bool use_port);

0 commit comments

Comments
 (0)