tipc: refactor function tipc_sk_timeout()

We refactor this function as a preparation for the coming commits in
the same series.

Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jon Maloy 2018-09-28 20:23:19 +02:00 committed by David S. Miller
parent 5cbdbd1a1f
commit afe8792fec

View File

@ -2545,43 +2545,57 @@ static int tipc_shutdown(struct socket *sock, int how)
return res;
}
static void tipc_sk_check_probing_state(struct sock *sk,
struct sk_buff_head *list)
{
struct tipc_sock *tsk = tipc_sk(sk);
u32 pnode = tsk_peer_node(tsk);
u32 pport = tsk_peer_port(tsk);
u32 self = tsk_own_node(tsk);
u32 oport = tsk->portid;
struct sk_buff *skb;
if (tsk->probe_unacked) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
sk->sk_err = ECONNABORTED;
tipc_node_remove_conn(sock_net(sk), pnode, pport);
sk->sk_state_change(sk);
return;
}
/* Prepare new probe */
skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, 0,
pnode, self, pport, oport, TIPC_OK);
if (skb)
__skb_queue_tail(list, skb);
tsk->probe_unacked = true;
sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTV);
}
static void tipc_sk_timeout(struct timer_list *t)
{
struct sock *sk = from_timer(sk, t, sk_timer);
struct tipc_sock *tsk = tipc_sk(sk);
u32 peer_port = tsk_peer_port(tsk);
u32 peer_node = tsk_peer_node(tsk);
u32 own_node = tsk_own_node(tsk);
u32 own_port = tsk->portid;
struct net *net = sock_net(sk);
struct sk_buff *skb = NULL;
u32 pnode = tsk_peer_node(tsk);
struct sk_buff_head list;
skb_queue_head_init(&list);
bh_lock_sock(sk);
if (!tipc_sk_connected(sk))
goto exit;
/* Try again later if socket is busy */
if (sock_owned_by_user(sk)) {
sk_reset_timer(sk, &sk->sk_timer, jiffies + HZ / 20);
goto exit;
bh_unlock_sock(sk);
return;
}
if (tsk->probe_unacked) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
tipc_node_remove_conn(net, peer_node, peer_port);
sk->sk_state_change(sk);
goto exit;
}
/* Send new probe */
skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, 0,
peer_node, own_node, peer_port, own_port,
TIPC_OK);
tsk->probe_unacked = true;
sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTV);
exit:
if (sk->sk_state == TIPC_ESTABLISHED)
tipc_sk_check_probing_state(sk, &list);
bh_unlock_sock(sk);
if (skb)
tipc_node_xmit_skb(net, skb, peer_node, own_port);
if (!skb_queue_empty(&list))
tipc_node_xmit(sock_net(sk), &list, pnode, tsk->portid);
sock_put(sk);
}