Skip to content

Commit 99a2088

Browse files
Parthasarathy Bhuvaragandavem330
authored andcommitted
tipc: create TIPC_CONNECTING as a new sk_state
In this commit, we create a new tipc socket state TIPC_CONNECTING by primarily replacing the SS_CONNECTING with TIPC_CONNECTING. There is no functional change in this commit. Signed-off-by: Parthasarathy Bhuvaragan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6f00089 commit 99a2088

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

net/tipc/socket.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum {
5555
TIPC_ESTABLISHED = TCP_ESTABLISHED,
5656
TIPC_OPEN = TCP_CLOSE,
5757
TIPC_DISCONNECTING = TCP_CLOSE_WAIT,
58+
TIPC_CONNECTING = TCP_SYN_SENT,
5859
};
5960

6061
/**
@@ -349,7 +350,6 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
349350
*/
350351
static int tipc_set_sk_state(struct sock *sk, int state)
351352
{
352-
int oldstate = sk->sk_socket->state;
353353
int oldsk_state = sk->sk_state;
354354
int res = -EINVAL;
355355

@@ -358,16 +358,17 @@ static int tipc_set_sk_state(struct sock *sk, int state)
358358
res = 0;
359359
break;
360360
case TIPC_LISTEN:
361+
case TIPC_CONNECTING:
361362
if (oldsk_state == TIPC_OPEN)
362363
res = 0;
363364
break;
364365
case TIPC_ESTABLISHED:
365-
if (oldstate == SS_CONNECTING ||
366+
if (oldsk_state == TIPC_CONNECTING ||
366367
oldsk_state == TIPC_OPEN)
367368
res = 0;
368369
break;
369370
case TIPC_DISCONNECTING:
370-
if (oldstate == SS_CONNECTING ||
371+
if (oldsk_state == TIPC_CONNECTING ||
371372
oldsk_state == TIPC_ESTABLISHED)
372373
res = 0;
373374
break;
@@ -689,16 +690,12 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
689690
if (sk->sk_shutdown == SHUTDOWN_MASK)
690691
mask |= POLLHUP;
691692

692-
switch ((int)sock->state) {
693-
case SS_CONNECTED:
693+
if ((int)sock->state == SS_CONNECTED) {
694694
if (!tsk->link_cong && !tsk_conn_cong(tsk))
695695
mask |= POLLOUT;
696-
/* fall thru' */
697-
case SS_CONNECTING:
698696
if (!skb_queue_empty(&sk->sk_receive_queue))
699697
mask |= (POLLIN | POLLRDNORM);
700-
break;
701-
default:
698+
} else {
702699
switch (sk->sk_state) {
703700
case TIPC_OPEN:
704701
if (!tsk->link_cong)
@@ -711,6 +708,7 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
711708
mask = (POLLIN | POLLRDNORM | POLLHUP);
712709
break;
713710
case TIPC_LISTEN:
711+
case TIPC_CONNECTING:
714712
if (!skb_queue_empty(&sk->sk_receive_queue))
715713
mask |= (POLLIN | POLLRDNORM);
716714
break;
@@ -1014,7 +1012,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz)
10141012
rc = tipc_node_xmit(net, &pktchain, dnode, tsk->portid);
10151013
if (likely(!rc)) {
10161014
if (!is_connectionless)
1017-
sock->state = SS_CONNECTING;
1015+
tipc_set_sk_state(sk, TIPC_CONNECTING);
10181016
return dsz;
10191017
}
10201018
if (rc == -ELINKCONG) {
@@ -1650,9 +1648,10 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
16501648
sk->sk_state_change(sk);
16511649
}
16521650
return true;
1651+
}
16531652

1654-
case SS_CONNECTING:
1655-
1653+
switch (sk->sk_state) {
1654+
case TIPC_CONNECTING:
16561655
/* Accept only ACK or NACK message */
16571656
if (unlikely(!msg_connected(hdr)))
16581657
return false;
@@ -1684,9 +1683,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
16841683
/* 'ACK-' message is neither accepted nor rejected: */
16851684
msg_set_dest_droppable(hdr, 1);
16861685
return false;
1687-
}
16881686

1689-
switch (sk->sk_state) {
16901687
case TIPC_OPEN:
16911688
case TIPC_DISCONNECTING:
16921689
break;
@@ -1955,7 +1952,8 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
19551952
return sock_intr_errno(*timeo_p);
19561953

19571954
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
1958-
done = sk_wait_event(sk, timeo_p, sock->state != SS_CONNECTING);
1955+
done = sk_wait_event(sk, timeo_p,
1956+
sk->sk_state != TIPC_CONNECTING);
19591957
finish_wait(sk_sleep(sk), &wait);
19601958
} while (!done);
19611959
return 0;
@@ -1978,7 +1976,7 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
19781976
struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest;
19791977
struct msghdr m = {NULL,};
19801978
long timeout = (flags & O_NONBLOCK) ? 0 : tsk->conn_timeout;
1981-
socket_state previous;
1979+
int previous;
19821980
int res = 0;
19831981

19841982
lock_sock(sk);
@@ -2006,7 +2004,7 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
20062004
goto exit;
20072005
}
20082006

2009-
previous = sock->state;
2007+
previous = sk->sk_state;
20102008

20112009
switch (sk->sk_state) {
20122010
case TIPC_OPEN:
@@ -2024,31 +2022,29 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
20242022
if ((res < 0) && (res != -EWOULDBLOCK))
20252023
goto exit;
20262024

2027-
/* Just entered SS_CONNECTING state; the only
2025+
/* Just entered TIPC_CONNECTING state; the only
20282026
* difference is that return value in non-blocking
20292027
* case is EINPROGRESS, rather than EALREADY.
20302028
*/
20312029
res = -EINPROGRESS;
2032-
break;
2033-
}
2034-
2035-
switch (sock->state) {
2036-
case SS_CONNECTING:
2037-
if (previous == SS_CONNECTING)
2038-
res = -EALREADY;
2039-
if (!timeout)
2030+
/* fall thru' */
2031+
case TIPC_CONNECTING:
2032+
if (!timeout) {
2033+
if (previous == TIPC_CONNECTING)
2034+
res = -EALREADY;
20402035
goto exit;
2036+
}
20412037
timeout = msecs_to_jiffies(timeout);
20422038
/* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */
20432039
res = tipc_wait_for_connect(sock, &timeout);
2044-
break;
2045-
case SS_CONNECTED:
2040+
goto exit;
2041+
}
2042+
2043+
if (sock->state == SS_CONNECTED)
20462044
res = -EISCONN;
2047-
break;
2048-
default:
2045+
else
20492046
res = -EINVAL;
2050-
break;
2051-
}
2047+
20522048
exit:
20532049
release_sock(sk);
20542050
return res;

0 commit comments

Comments
 (0)