53
53
enum {
54
54
TIPC_LISTEN = TCP_LISTEN ,
55
55
TIPC_ESTABLISHED = TCP_ESTABLISHED ,
56
+ TIPC_OPEN = TCP_CLOSE ,
56
57
};
57
58
58
59
/**
@@ -348,16 +349,21 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
348
349
static int tipc_set_sk_state (struct sock * sk , int state )
349
350
{
350
351
int oldstate = sk -> sk_socket -> state ;
352
+ int oldsk_state = sk -> sk_state ;
351
353
int res = - EINVAL ;
352
354
353
355
switch (state ) {
356
+ case TIPC_OPEN :
357
+ res = 0 ;
358
+ break ;
354
359
case TIPC_LISTEN :
355
- if (oldstate == SS_UNCONNECTED )
360
+ if (oldsk_state == TIPC_OPEN )
356
361
res = 0 ;
357
362
break ;
358
363
case TIPC_ESTABLISHED :
359
364
if (oldstate == SS_CONNECTING ||
360
- oldstate == SS_UNCONNECTED )
365
+ oldstate == SS_UNCONNECTED ||
366
+ oldsk_state == TIPC_OPEN )
361
367
res = 0 ;
362
368
break ;
363
369
}
@@ -423,8 +429,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
423
429
424
430
/* Finish initializing socket data structures */
425
431
sock -> ops = ops ;
426
- sock -> state = SS_UNCONNECTED ;
427
432
sock_init_data (sock , sk );
433
+ tipc_set_sk_state (sk , TIPC_OPEN );
428
434
if (tipc_sk_insert (tsk )) {
429
435
pr_warn ("Socket create failed; port number exhausted\n" );
430
436
return - EINVAL ;
@@ -448,6 +454,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
448
454
if (sock -> type == SOCK_DGRAM )
449
455
tsk_set_unreliable (tsk , true);
450
456
}
457
+
451
458
return 0 ;
452
459
}
453
460
@@ -652,28 +659,6 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
652
659
* exits. TCP and other protocols seem to rely on higher level poll routines
653
660
* to handle any preventable race conditions, so TIPC will do the same ...
654
661
*
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
- *
677
662
* IMPORTANT: The fact that a read or write operation is indicated does NOT
678
663
* imply that the operation will succeed, merely that it should be performed
679
664
* and will not block.
@@ -687,27 +672,7 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
687
672
688
673
sock_poll_wait (file , sk_sleep (sk ), wait );
689
674
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
-
698
675
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 ;
711
676
case SS_CONNECTED :
712
677
if (!tsk -> link_cong && !tsk_conn_cong (tsk ))
713
678
mask |= POLLOUT ;
@@ -719,6 +684,20 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
719
684
case SS_DISCONNECTING :
720
685
mask = (POLLIN | POLLRDNORM | POLLHUP );
721
686
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
+ }
722
701
}
723
702
724
703
return mask ;
@@ -965,7 +944,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz)
965
944
if (!is_connectionless ) {
966
945
if (sk -> sk_state == TIPC_LISTEN )
967
946
return - EPIPE ;
968
- if (sock -> state != SS_UNCONNECTED )
947
+ if (sk -> sk_state != TIPC_OPEN )
969
948
return - EISCONN ;
970
949
if (tsk -> published )
971
950
return - EOPNOTSUPP ;
@@ -1400,7 +1379,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, size_t buf_len,
1400
1379
1401
1380
lock_sock (sk );
1402
1381
1403
- if (!is_connectionless && unlikely (sock -> state == SS_UNCONNECTED )) {
1382
+ if (!is_connectionless && unlikely (sk -> sk_state == TIPC_OPEN )) {
1404
1383
res = - ENOTCONN ;
1405
1384
goto exit ;
1406
1385
}
@@ -1497,7 +1476,7 @@ static int tipc_recv_stream(struct socket *sock, struct msghdr *m,
1497
1476
1498
1477
lock_sock (sk );
1499
1478
1500
- if (unlikely (sock -> state == SS_UNCONNECTED )) {
1479
+ if (unlikely (sk -> sk_state == TIPC_OPEN )) {
1501
1480
res = - ENOTCONN ;
1502
1481
goto exit ;
1503
1482
}
@@ -1689,17 +1668,22 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
1689
1668
msg_set_dest_droppable (hdr , 1 );
1690
1669
return false;
1691
1670
1692
- case SS_UNCONNECTED :
1671
+ case SS_DISCONNECTING :
1672
+ break ;
1673
+ }
1693
1674
1675
+ switch (sk -> sk_state ) {
1676
+ case TIPC_OPEN :
1677
+ break ;
1678
+ case TIPC_LISTEN :
1694
1679
/* Accept only SYN message */
1695
1680
if (!msg_connected (hdr ) && !(msg_errcode (hdr )))
1696
1681
return true;
1697
1682
break ;
1698
- case SS_DISCONNECTING :
1699
- break ;
1700
1683
default :
1701
- pr_err ("Unknown socket state %u\n" , sock -> state );
1684
+ pr_err ("Unknown sk_state %u\n" , sk -> sk_state );
1702
1685
}
1686
+
1703
1687
return false;
1704
1688
}
1705
1689
@@ -2008,8 +1992,9 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
2008
1992
}
2009
1993
2010
1994
previous = sock -> state ;
2011
- switch (sock -> state ) {
2012
- case SS_UNCONNECTED :
1995
+
1996
+ switch (sk -> sk_state ) {
1997
+ case TIPC_OPEN :
2013
1998
/* Send a 'SYN-' to destination */
2014
1999
m .msg_name = dest ;
2015
2000
m .msg_namelen = destlen ;
@@ -2029,6 +2014,10 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
2029
2014
* case is EINPROGRESS, rather than EALREADY.
2030
2015
*/
2031
2016
res = - EINPROGRESS ;
2017
+ break ;
2018
+ }
2019
+
2020
+ switch (sock -> state ) {
2032
2021
case SS_CONNECTING :
2033
2022
if (previous == SS_CONNECTING )
2034
2023
res = - EALREADY ;
0 commit comments