Commit 9fd4b070 authored by Parthasarathy Bhuvaragan's avatar Parthasarathy Bhuvaragan Committed by David S. Miller

tipc: create TIPC_DISCONNECTING as a new sk_state

In this commit, we create a new tipc socket state TIPC_DISCONNECTING in
sk_state. TIPC_DISCONNECTING is replacing the socket connection status
update using SS_DISCONNECTING.
TIPC_DISCONNECTING is set for connection oriented sockets at:
- tipc_shutdown()
- connection probe timeout
- when we receive an error message on the connection.

There is no functional change in this commit.
Signed-off-by: default avatarParthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 438adcaf
...@@ -54,6 +54,7 @@ enum { ...@@ -54,6 +54,7 @@ enum {
TIPC_LISTEN = TCP_LISTEN, TIPC_LISTEN = TCP_LISTEN,
TIPC_ESTABLISHED = TCP_ESTABLISHED, TIPC_ESTABLISHED = TCP_ESTABLISHED,
TIPC_OPEN = TCP_CLOSE, TIPC_OPEN = TCP_CLOSE,
TIPC_DISCONNECTING = TCP_CLOSE_WAIT,
}; };
/** /**
...@@ -362,10 +363,14 @@ static int tipc_set_sk_state(struct sock *sk, int state) ...@@ -362,10 +363,14 @@ static int tipc_set_sk_state(struct sock *sk, int state)
break; break;
case TIPC_ESTABLISHED: case TIPC_ESTABLISHED:
if (oldstate == SS_CONNECTING || if (oldstate == SS_CONNECTING ||
oldstate == SS_UNCONNECTED ||
oldsk_state == TIPC_OPEN) oldsk_state == TIPC_OPEN)
res = 0; res = 0;
break; break;
case TIPC_DISCONNECTING:
if (oldstate == SS_CONNECTING ||
oldsk_state == TIPC_ESTABLISHED)
res = 0;
break;
} }
if (!res) if (!res)
...@@ -621,13 +626,14 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -621,13 +626,14 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
int *uaddr_len, int peer) int *uaddr_len, int peer)
{ {
struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
struct tipc_sock *tsk = tipc_sk(sock->sk); struct sock *sk = sock->sk;
struct tipc_sock *tsk = tipc_sk(sk);
struct tipc_net *tn = net_generic(sock_net(sock->sk), tipc_net_id); struct tipc_net *tn = net_generic(sock_net(sock->sk), tipc_net_id);
memset(addr, 0, sizeof(*addr)); memset(addr, 0, sizeof(*addr));
if (peer) { if (peer) {
if ((sock->state != SS_CONNECTED) && if ((sock->state != SS_CONNECTED) &&
((peer != 2) || (sock->state != SS_DISCONNECTING))) ((peer != 2) || (sk->sk_state != TIPC_DISCONNECTING)))
return -ENOTCONN; return -ENOTCONN;
addr->addr.id.ref = tsk_peer_port(tsk); addr->addr.id.ref = tsk_peer_port(tsk);
addr->addr.id.node = tsk_peer_node(tsk); addr->addr.id.node = tsk_peer_node(tsk);
...@@ -693,6 +699,9 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock, ...@@ -693,6 +699,9 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
(!skb_queue_empty(&sk->sk_receive_queue))) (!skb_queue_empty(&sk->sk_receive_queue)))
mask |= (POLLIN | POLLRDNORM); mask |= (POLLIN | POLLRDNORM);
break; break;
case TIPC_DISCONNECTING:
mask = (POLLIN | POLLRDNORM | POLLHUP);
break;
case TIPC_LISTEN: case TIPC_LISTEN:
if (!skb_queue_empty(&sk->sk_receive_queue)) if (!skb_queue_empty(&sk->sk_receive_queue))
mask |= (POLLIN | POLLRDNORM); mask |= (POLLIN | POLLRDNORM);
...@@ -1028,7 +1037,7 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) ...@@ -1028,7 +1037,7 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
int err = sock_error(sk); int err = sock_error(sk);
if (err) if (err)
return err; return err;
if (sock->state == SS_DISCONNECTING) if (sk->sk_state == TIPC_DISCONNECTING)
return -EPIPE; return -EPIPE;
else if (sock->state != SS_CONNECTED) else if (sock->state != SS_CONNECTED)
return -ENOTCONN; return -ENOTCONN;
...@@ -1098,7 +1107,7 @@ static int __tipc_send_stream(struct socket *sock, struct msghdr *m, size_t dsz) ...@@ -1098,7 +1107,7 @@ static int __tipc_send_stream(struct socket *sock, struct msghdr *m, size_t dsz)
return -EMSGSIZE; return -EMSGSIZE;
if (unlikely(sock->state != SS_CONNECTED)) { if (unlikely(sock->state != SS_CONNECTED)) {
if (sock->state == SS_DISCONNECTING) if (sk->sk_state == TIPC_DISCONNECTING)
return -EPIPE; return -EPIPE;
else else
return -ENOTCONN; return -ENOTCONN;
...@@ -1626,7 +1635,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1626,7 +1635,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
return false; return false;
if (unlikely(msg_errcode(hdr))) { if (unlikely(msg_errcode(hdr))) {
sock->state = SS_DISCONNECTING; tipc_set_sk_state(sk, TIPC_DISCONNECTING);
/* Let timer expire on it's own */ /* Let timer expire on it's own */
tipc_node_remove_conn(net, tsk_peer_node(tsk), tipc_node_remove_conn(net, tsk_peer_node(tsk),
tsk->portid); tsk->portid);
...@@ -1641,13 +1650,13 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1641,13 +1650,13 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
return false; return false;
if (unlikely(msg_errcode(hdr))) { if (unlikely(msg_errcode(hdr))) {
sock->state = SS_DISCONNECTING; tipc_set_sk_state(sk, TIPC_DISCONNECTING);
sk->sk_err = ECONNREFUSED; sk->sk_err = ECONNREFUSED;
return true; return true;
} }
if (unlikely(!msg_isdata(hdr))) { if (unlikely(!msg_isdata(hdr))) {
sock->state = SS_DISCONNECTING; tipc_set_sk_state(sk, TIPC_DISCONNECTING);
sk->sk_err = EINVAL; sk->sk_err = EINVAL;
return true; return true;
} }
...@@ -1674,6 +1683,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1674,6 +1683,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
switch (sk->sk_state) { switch (sk->sk_state) {
case TIPC_OPEN: case TIPC_OPEN:
case TIPC_DISCONNECTING:
break; break;
case TIPC_LISTEN: case TIPC_LISTEN:
/* Accept only SYN message */ /* Accept only SYN message */
...@@ -2195,9 +2205,7 @@ static int tipc_shutdown(struct socket *sock, int how) ...@@ -2195,9 +2205,7 @@ static int tipc_shutdown(struct socket *sock, int how)
lock_sock(sk); lock_sock(sk);
switch (sock->state) { if (sock->state == SS_CONNECTING || sock->state == SS_CONNECTED) {
case SS_CONNECTING:
case SS_CONNECTED:
restart: restart:
dnode = tsk_peer_node(tsk); dnode = tsk_peer_node(tsk);
...@@ -2218,11 +2226,12 @@ static int tipc_shutdown(struct socket *sock, int how) ...@@ -2218,11 +2226,12 @@ static int tipc_shutdown(struct socket *sock, int how)
if (skb) if (skb)
tipc_node_xmit_skb(net, skb, dnode, tsk->portid); tipc_node_xmit_skb(net, skb, dnode, tsk->portid);
} }
sock->state = SS_DISCONNECTING; tipc_set_sk_state(sk, TIPC_DISCONNECTING);
tipc_node_remove_conn(net, dnode, tsk->portid); tipc_node_remove_conn(net, dnode, tsk->portid);
/* fall through */ }
case SS_DISCONNECTING: switch (sk->sk_state) {
case TIPC_DISCONNECTING:
/* Discard any unreceived messages */ /* Discard any unreceived messages */
__skb_queue_purge(&sk->sk_receive_queue); __skb_queue_purge(&sk->sk_receive_queue);
...@@ -2258,7 +2267,7 @@ static void tipc_sk_timeout(unsigned long data) ...@@ -2258,7 +2267,7 @@ static void tipc_sk_timeout(unsigned long data)
if (tsk->probe_unacked) { if (tsk->probe_unacked) {
if (!sock_owned_by_user(sk)) { if (!sock_owned_by_user(sk)) {
sk->sk_socket->state = SS_DISCONNECTING; tipc_set_sk_state(sk, TIPC_DISCONNECTING);
tipc_node_remove_conn(sock_net(sk), tsk_peer_node(tsk), tipc_node_remove_conn(sock_net(sk), tsk_peer_node(tsk),
tsk_peer_port(tsk)); tsk_peer_port(tsk));
sk->sk_state_change(sk); sk->sk_state_change(sk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment