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

tipc: remove SS_CONNECTED sock state

In this commit, we replace references to sock->state SS_CONNECTE
with sk_state TIPC_ESTABLISHED.

Finally, the sock->state is no longer explicitly used by tipc.
The FSM below is for various types of connection oriented sockets.

Stream Server Listening Socket:
+-----------+       +-------------+
| TIPC_OPEN |------>| TIPC_LISTEN |
+-----------+       +-------------+

Stream Server Data Socket:
+-----------+       +------------------+
| TIPC_OPEN |------>| TIPC_ESTABLISHED |
+-----------+       +------------------+
                          ^   |
                          |   |
                          |   v
                    +--------------------+
                    | TIPC_DISCONNECTING |
                    +--------------------+

Stream Socket Client:
+-----------+       +-----------------+
| TIPC_OPEN |------>| TIPC_CONNECTING |------+
+-----------+       +-----------------+      |
                            |                |
                            |                |
                            v                |
                    +------------------+     |
                    | TIPC_ESTABLISHED |     |
                    +------------------+     |
                          ^   |              |
                          |   |              |
                          |   v              |
                    +--------------------+   |
                    | TIPC_DISCONNECTING |<--+
                    +--------------------+
Signed-off-by: default avatarParthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 99a20889
...@@ -294,7 +294,7 @@ static void tsk_rej_rx_queue(struct sock *sk) ...@@ -294,7 +294,7 @@ static void tsk_rej_rx_queue(struct sock *sk)
static bool tipc_sk_connected(struct sock *sk) static bool tipc_sk_connected(struct sock *sk)
{ {
return sk->sk_socket->state == SS_CONNECTED; return sk->sk_state == TIPC_ESTABLISHED;
} }
/* tipc_sk_type_connectionless - check if the socket is datagram socket /* tipc_sk_type_connectionless - check if the socket is datagram socket
...@@ -639,7 +639,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -639,7 +639,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
memset(addr, 0, sizeof(*addr)); memset(addr, 0, sizeof(*addr));
if (peer) { if (peer) {
if ((sock->state != SS_CONNECTED) && if ((!tipc_sk_connected(sk)) &&
((peer != 2) || (sk->sk_state != TIPC_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);
...@@ -690,13 +690,16 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock, ...@@ -690,13 +690,16 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
if (sk->sk_shutdown == SHUTDOWN_MASK) if (sk->sk_shutdown == SHUTDOWN_MASK)
mask |= POLLHUP; mask |= POLLHUP;
if ((int)sock->state == SS_CONNECTED) { switch (sk->sk_state) {
case TIPC_ESTABLISHED:
if (!tsk->link_cong && !tsk_conn_cong(tsk)) if (!tsk->link_cong && !tsk_conn_cong(tsk))
mask |= POLLOUT; mask |= POLLOUT;
/* fall thru' */
case TIPC_LISTEN:
case TIPC_CONNECTING:
if (!skb_queue_empty(&sk->sk_receive_queue)) if (!skb_queue_empty(&sk->sk_receive_queue))
mask |= (POLLIN | POLLRDNORM); mask |= (POLLIN | POLLRDNORM);
} else { break;
switch (sk->sk_state) {
case TIPC_OPEN: case TIPC_OPEN:
if (!tsk->link_cong) if (!tsk->link_cong)
mask |= POLLOUT; mask |= POLLOUT;
...@@ -707,12 +710,6 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock, ...@@ -707,12 +710,6 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
case TIPC_DISCONNECTING: case TIPC_DISCONNECTING:
mask = (POLLIN | POLLRDNORM | POLLHUP); mask = (POLLIN | POLLRDNORM | POLLHUP);
break; break;
case TIPC_LISTEN:
case TIPC_CONNECTING:
if (!skb_queue_empty(&sk->sk_receive_queue))
mask |= (POLLIN | POLLRDNORM);
break;
}
} }
return mask; return mask;
...@@ -1045,7 +1042,7 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) ...@@ -1045,7 +1042,7 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
return err; return err;
if (sk->sk_state == TIPC_DISCONNECTING) if (sk->sk_state == TIPC_DISCONNECTING)
return -EPIPE; return -EPIPE;
else if (sock->state != SS_CONNECTED) else if (!tipc_sk_connected(sk))
return -ENOTCONN; return -ENOTCONN;
if (!*timeo_p) if (!*timeo_p)
return -EAGAIN; return -EAGAIN;
...@@ -1112,7 +1109,7 @@ static int __tipc_send_stream(struct socket *sock, struct msghdr *m, size_t dsz) ...@@ -1112,7 +1109,7 @@ static int __tipc_send_stream(struct socket *sock, struct msghdr *m, size_t dsz)
if (dsz > (uint)INT_MAX) if (dsz > (uint)INT_MAX)
return -EMSGSIZE; return -EMSGSIZE;
if (unlikely(sock->state != SS_CONNECTED)) { if (unlikely(!tipc_sk_connected(sk))) {
if (sk->sk_state == TIPC_DISCONNECTING) if (sk->sk_state == TIPC_DISCONNECTING)
return -EPIPE; return -EPIPE;
else else
...@@ -1627,29 +1624,11 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1627,29 +1624,11 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
{ {
struct sock *sk = &tsk->sk; struct sock *sk = &tsk->sk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct socket *sock = sk->sk_socket;
struct tipc_msg *hdr = buf_msg(skb); struct tipc_msg *hdr = buf_msg(skb);
if (unlikely(msg_mcast(hdr))) if (unlikely(msg_mcast(hdr)))
return false; return false;
switch ((int)sock->state) {
case SS_CONNECTED:
/* Accept only connection-based messages sent by peer */
if (unlikely(!tsk_peer_msg(tsk, hdr)))
return false;
if (unlikely(msg_errcode(hdr))) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
/* Let timer expire on it's own */
tipc_node_remove_conn(net, tsk_peer_node(tsk),
tsk->portid);
sk->sk_state_change(sk);
}
return true;
}
switch (sk->sk_state) { switch (sk->sk_state) {
case TIPC_CONNECTING: case TIPC_CONNECTING:
/* Accept only ACK or NACK message */ /* Accept only ACK or NACK message */
...@@ -1670,7 +1649,6 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1670,7 +1649,6 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
tipc_sk_finish_conn(tsk, msg_origport(hdr), msg_orignode(hdr)); tipc_sk_finish_conn(tsk, msg_origport(hdr), msg_orignode(hdr));
msg_set_importance(&tsk->phdr, msg_importance(hdr)); msg_set_importance(&tsk->phdr, msg_importance(hdr));
sock->state = SS_CONNECTED;
/* If 'ACK+' message, add to socket receive queue */ /* If 'ACK+' message, add to socket receive queue */
if (msg_data_sz(hdr)) if (msg_data_sz(hdr))
...@@ -1692,6 +1670,19 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1692,6 +1670,19 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
if (!msg_connected(hdr) && !(msg_errcode(hdr))) if (!msg_connected(hdr) && !(msg_errcode(hdr)))
return true; return true;
break; break;
case TIPC_ESTABLISHED:
/* Accept only connection-based messages sent by peer */
if (unlikely(!tsk_peer_msg(tsk, hdr)))
return false;
if (unlikely(msg_errcode(hdr))) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
/* Let timer expire on it's own */
tipc_node_remove_conn(net, tsk_peer_node(tsk),
tsk->portid);
sk->sk_state_change(sk);
}
return true;
default: default:
pr_err("Unknown sk_state %u\n", sk->sk_state); pr_err("Unknown sk_state %u\n", sk->sk_state);
} }
...@@ -2037,13 +2028,13 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest, ...@@ -2037,13 +2028,13 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
timeout = msecs_to_jiffies(timeout); timeout = msecs_to_jiffies(timeout);
/* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */
res = tipc_wait_for_connect(sock, &timeout); res = tipc_wait_for_connect(sock, &timeout);
goto exit; break;
} case TIPC_ESTABLISHED:
if (sock->state == SS_CONNECTED)
res = -EISCONN; res = -EISCONN;
else break;
default:
res = -EINVAL; res = -EINVAL;
}
exit: exit:
release_sock(sk); release_sock(sk);
...@@ -2152,7 +2143,6 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) ...@@ -2152,7 +2143,6 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
/* Connect new socket to it's peer */ /* Connect new socket to it's peer */
tipc_sk_finish_conn(new_tsock, msg_origport(msg), msg_orignode(msg)); tipc_sk_finish_conn(new_tsock, msg_origport(msg), msg_orignode(msg));
new_sock->state = SS_CONNECTED;
tsk_set_importance(new_tsock, msg_importance(msg)); tsk_set_importance(new_tsock, msg_importance(msg));
if (msg_named(msg)) { if (msg_named(msg)) {
......
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