Skip to content

Commit 438adca

Browse files
Parthasarathy Bhuvaragandavem330
authored andcommitted
tipc: create TIPC_OPEN as a new sk_state
In this commit, we create a new tipc socket state TIPC_OPEN in sk_state. We primarily replace the SS_UNCONNECTED sock->state with TIPC_OPEN. Signed-off-by: Parthasarathy Bhuvaragan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8ea642e commit 438adca

File tree

1 file changed

+43
-54
lines changed

1 file changed

+43
-54
lines changed

net/tipc/socket.c

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
enum {
5454
TIPC_LISTEN = TCP_LISTEN,
5555
TIPC_ESTABLISHED = TCP_ESTABLISHED,
56+
TIPC_OPEN = TCP_CLOSE,
5657
};
5758

5859
/**
@@ -348,16 +349,21 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
348349
static int tipc_set_sk_state(struct sock *sk, int state)
349350
{
350351
int oldstate = sk->sk_socket->state;
352+
int oldsk_state = sk->sk_state;
351353
int res = -EINVAL;
352354

353355
switch (state) {
356+
case TIPC_OPEN:
357+
res = 0;
358+
break;
354359
case TIPC_LISTEN:
355-
if (oldstate == SS_UNCONNECTED)
360+
if (oldsk_state == TIPC_OPEN)
356361
res = 0;
357362
break;
358363
case TIPC_ESTABLISHED:
359364
if (oldstate == SS_CONNECTING ||
360-
oldstate == SS_UNCONNECTED)
365+
oldstate == SS_UNCONNECTED ||
366+
oldsk_state == TIPC_OPEN)
361367
res = 0;
362368
break;
363369
}
@@ -423,8 +429,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
423429

424430
/* Finish initializing socket data structures */
425431
sock->ops = ops;
426-
sock->state = SS_UNCONNECTED;
427432
sock_init_data(sock, sk);
433+
tipc_set_sk_state(sk, TIPC_OPEN);
428434
if (tipc_sk_insert(tsk)) {
429435
pr_warn("Socket create failed; port number exhausted\n");
430436
return -EINVAL;
@@ -448,6 +454,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
448454
if (sock->type == SOCK_DGRAM)
449455
tsk_set_unreliable(tsk, true);
450456
}
457+
451458
return 0;
452459
}
453460

@@ -652,28 +659,6 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
652659
* exits. TCP and other protocols seem to rely on higher level poll routines
653660
* to handle any preventable race conditions, so TIPC will do the same ...
654661
*
655-
* TIPC sets the returned events as follows:
656-
*
657-
* socket state flags set
658-
* ------------ ---------
659-
* unconnected no read flags
660-
* POLLOUT if port is not congested
661-
*
662-
* connecting POLLIN/POLLRDNORM if ACK/NACK in rx queue
663-
* no write flags
664-
*
665-
* connected POLLIN/POLLRDNORM if data in rx queue
666-
* POLLOUT if port is not congested
667-
*
668-
* disconnecting POLLIN/POLLRDNORM/POLLHUP
669-
* no write flags
670-
*
671-
* listening POLLIN if SYN in rx queue
672-
* no write flags
673-
*
674-
* ready POLLIN/POLLRDNORM if data in rx queue
675-
* [connectionless] POLLOUT (since port cannot be congested)
676-
*
677662
* IMPORTANT: The fact that a read or write operation is indicated does NOT
678663
* imply that the operation will succeed, merely that it should be performed
679664
* and will not block.
@@ -687,27 +672,7 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
687672

688673
sock_poll_wait(file, sk_sleep(sk), wait);
689674

690-
if (tipc_sk_type_connectionless(sk)) {
691-
if (!tsk->link_cong)
692-
mask |= POLLOUT;
693-
if (!skb_queue_empty(&sk->sk_receive_queue))
694-
mask |= (POLLIN | POLLRDNORM);
695-
return mask;
696-
}
697-
698675
switch ((int)sock->state) {
699-
case SS_UNCONNECTED:
700-
switch (sk->sk_state) {
701-
case TIPC_LISTEN:
702-
if (!skb_queue_empty(&sk->sk_receive_queue))
703-
mask |= (POLLIN | POLLRDNORM);
704-
break;
705-
default:
706-
if (!tsk->link_cong)
707-
mask |= POLLOUT;
708-
break;
709-
}
710-
break;
711676
case SS_CONNECTED:
712677
if (!tsk->link_cong && !tsk_conn_cong(tsk))
713678
mask |= POLLOUT;
@@ -719,6 +684,20 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
719684
case SS_DISCONNECTING:
720685
mask = (POLLIN | POLLRDNORM | POLLHUP);
721686
break;
687+
default:
688+
switch (sk->sk_state) {
689+
case TIPC_OPEN:
690+
if (!tsk->link_cong)
691+
mask |= POLLOUT;
692+
if (tipc_sk_type_connectionless(sk) &&
693+
(!skb_queue_empty(&sk->sk_receive_queue)))
694+
mask |= (POLLIN | POLLRDNORM);
695+
break;
696+
case TIPC_LISTEN:
697+
if (!skb_queue_empty(&sk->sk_receive_queue))
698+
mask |= (POLLIN | POLLRDNORM);
699+
break;
700+
}
722701
}
723702

724703
return mask;
@@ -965,7 +944,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz)
965944
if (!is_connectionless) {
966945
if (sk->sk_state == TIPC_LISTEN)
967946
return -EPIPE;
968-
if (sock->state != SS_UNCONNECTED)
947+
if (sk->sk_state != TIPC_OPEN)
969948
return -EISCONN;
970949
if (tsk->published)
971950
return -EOPNOTSUPP;
@@ -1400,7 +1379,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, size_t buf_len,
14001379

14011380
lock_sock(sk);
14021381

1403-
if (!is_connectionless && unlikely(sock->state == SS_UNCONNECTED)) {
1382+
if (!is_connectionless && unlikely(sk->sk_state == TIPC_OPEN)) {
14041383
res = -ENOTCONN;
14051384
goto exit;
14061385
}
@@ -1497,7 +1476,7 @@ static int tipc_recv_stream(struct socket *sock, struct msghdr *m,
14971476

14981477
lock_sock(sk);
14991478

1500-
if (unlikely(sock->state == SS_UNCONNECTED)) {
1479+
if (unlikely(sk->sk_state == TIPC_OPEN)) {
15011480
res = -ENOTCONN;
15021481
goto exit;
15031482
}
@@ -1689,17 +1668,22 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
16891668
msg_set_dest_droppable(hdr, 1);
16901669
return false;
16911670

1692-
case SS_UNCONNECTED:
1671+
case SS_DISCONNECTING:
1672+
break;
1673+
}
16931674

1675+
switch (sk->sk_state) {
1676+
case TIPC_OPEN:
1677+
break;
1678+
case TIPC_LISTEN:
16941679
/* Accept only SYN message */
16951680
if (!msg_connected(hdr) && !(msg_errcode(hdr)))
16961681
return true;
16971682
break;
1698-
case SS_DISCONNECTING:
1699-
break;
17001683
default:
1701-
pr_err("Unknown socket state %u\n", sock->state);
1684+
pr_err("Unknown sk_state %u\n", sk->sk_state);
17021685
}
1686+
17031687
return false;
17041688
}
17051689

@@ -2008,8 +1992,9 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
20081992
}
20091993

20101994
previous = sock->state;
2011-
switch (sock->state) {
2012-
case SS_UNCONNECTED:
1995+
1996+
switch (sk->sk_state) {
1997+
case TIPC_OPEN:
20131998
/* Send a 'SYN-' to destination */
20141999
m.msg_name = dest;
20152000
m.msg_namelen = destlen;
@@ -2029,6 +2014,10 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
20292014
* case is EINPROGRESS, rather than EALREADY.
20302015
*/
20312016
res = -EINPROGRESS;
2017+
break;
2018+
}
2019+
2020+
switch (sock->state) {
20322021
case SS_CONNECTING:
20332022
if (previous == SS_CONNECTING)
20342023
res = -EALREADY;

0 commit comments

Comments
 (0)