@@ -294,7 +294,7 @@ static void tsk_rej_rx_queue(struct sock *sk)
294
294
295
295
static bool tipc_sk_connected (struct sock * sk )
296
296
{
297
- return sk -> sk_socket -> state == SS_CONNECTED ;
297
+ return sk -> sk_state == TIPC_ESTABLISHED ;
298
298
}
299
299
300
300
/* 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
639
640
640
memset (addr , 0 , sizeof (* addr ));
641
641
if (peer ) {
642
- if ((sock -> state != SS_CONNECTED ) &&
642
+ if ((! tipc_sk_connected ( sk ) ) &&
643
643
((peer != 2 ) || (sk -> sk_state != TIPC_DISCONNECTING )))
644
644
return - ENOTCONN ;
645
645
addr -> addr .id .ref = tsk_peer_port (tsk );
@@ -690,29 +690,26 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
690
690
if (sk -> sk_shutdown == SHUTDOWN_MASK )
691
691
mask |= POLLHUP ;
692
692
693
- if ((int )sock -> state == SS_CONNECTED ) {
693
+ switch (sk -> sk_state ) {
694
+ case TIPC_ESTABLISHED :
694
695
if (!tsk -> link_cong && !tsk_conn_cong (tsk ))
695
696
mask |= POLLOUT ;
697
+ /* fall thru' */
698
+ case TIPC_LISTEN :
699
+ case TIPC_CONNECTING :
696
700
if (!skb_queue_empty (& sk -> sk_receive_queue ))
697
701
mask |= (POLLIN | POLLRDNORM );
698
- } else {
699
- switch (sk -> sk_state ) {
700
- case TIPC_OPEN :
701
- if (!tsk -> link_cong )
702
- mask |= POLLOUT ;
703
- if (tipc_sk_type_connectionless (sk ) &&
704
- (!skb_queue_empty (& sk -> sk_receive_queue )))
705
- mask |= (POLLIN | POLLRDNORM );
706
- break ;
707
- case TIPC_DISCONNECTING :
708
- mask = (POLLIN | POLLRDNORM | POLLHUP );
709
- break ;
710
- case TIPC_LISTEN :
711
- case TIPC_CONNECTING :
712
- if (!skb_queue_empty (& sk -> sk_receive_queue ))
713
- mask |= (POLLIN | POLLRDNORM );
714
- break ;
715
- }
702
+ break ;
703
+ case TIPC_OPEN :
704
+ if (!tsk -> link_cong )
705
+ mask |= POLLOUT ;
706
+ if (tipc_sk_type_connectionless (sk ) &&
707
+ (!skb_queue_empty (& sk -> sk_receive_queue )))
708
+ mask |= (POLLIN | POLLRDNORM );
709
+ break ;
710
+ case TIPC_DISCONNECTING :
711
+ mask = (POLLIN | POLLRDNORM | POLLHUP );
712
+ break ;
716
713
}
717
714
718
715
return mask ;
@@ -1045,7 +1042,7 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
1045
1042
return err ;
1046
1043
if (sk -> sk_state == TIPC_DISCONNECTING )
1047
1044
return - EPIPE ;
1048
- else if (sock -> state != SS_CONNECTED )
1045
+ else if (! tipc_sk_connected ( sk ) )
1049
1046
return - ENOTCONN ;
1050
1047
if (!* timeo_p )
1051
1048
return - EAGAIN ;
@@ -1112,7 +1109,7 @@ static int __tipc_send_stream(struct socket *sock, struct msghdr *m, size_t dsz)
1112
1109
if (dsz > (uint )INT_MAX )
1113
1110
return - EMSGSIZE ;
1114
1111
1115
- if (unlikely (sock -> state != SS_CONNECTED )) {
1112
+ if (unlikely (! tipc_sk_connected ( sk ) )) {
1116
1113
if (sk -> sk_state == TIPC_DISCONNECTING )
1117
1114
return - EPIPE ;
1118
1115
else
@@ -1627,29 +1624,11 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
1627
1624
{
1628
1625
struct sock * sk = & tsk -> sk ;
1629
1626
struct net * net = sock_net (sk );
1630
- struct socket * sock = sk -> sk_socket ;
1631
1627
struct tipc_msg * hdr = buf_msg (skb );
1632
1628
1633
1629
if (unlikely (msg_mcast (hdr )))
1634
1630
return false;
1635
1631
1636
- switch ((int )sock -> state ) {
1637
- case SS_CONNECTED :
1638
-
1639
- /* Accept only connection-based messages sent by peer */
1640
- if (unlikely (!tsk_peer_msg (tsk , hdr )))
1641
- return false;
1642
-
1643
- if (unlikely (msg_errcode (hdr ))) {
1644
- tipc_set_sk_state (sk , TIPC_DISCONNECTING );
1645
- /* Let timer expire on it's own */
1646
- tipc_node_remove_conn (net , tsk_peer_node (tsk ),
1647
- tsk -> portid );
1648
- sk -> sk_state_change (sk );
1649
- }
1650
- return true;
1651
- }
1652
-
1653
1632
switch (sk -> sk_state ) {
1654
1633
case TIPC_CONNECTING :
1655
1634
/* Accept only ACK or NACK message */
@@ -1670,7 +1649,6 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
1670
1649
1671
1650
tipc_sk_finish_conn (tsk , msg_origport (hdr ), msg_orignode (hdr ));
1672
1651
msg_set_importance (& tsk -> phdr , msg_importance (hdr ));
1673
- sock -> state = SS_CONNECTED ;
1674
1652
1675
1653
/* If 'ACK+' message, add to socket receive queue */
1676
1654
if (msg_data_sz (hdr ))
@@ -1692,6 +1670,19 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
1692
1670
if (!msg_connected (hdr ) && !(msg_errcode (hdr )))
1693
1671
return true;
1694
1672
break ;
1673
+ case TIPC_ESTABLISHED :
1674
+ /* Accept only connection-based messages sent by peer */
1675
+ if (unlikely (!tsk_peer_msg (tsk , hdr )))
1676
+ return false;
1677
+
1678
+ if (unlikely (msg_errcode (hdr ))) {
1679
+ tipc_set_sk_state (sk , TIPC_DISCONNECTING );
1680
+ /* Let timer expire on it's own */
1681
+ tipc_node_remove_conn (net , tsk_peer_node (tsk ),
1682
+ tsk -> portid );
1683
+ sk -> sk_state_change (sk );
1684
+ }
1685
+ return true;
1695
1686
default :
1696
1687
pr_err ("Unknown sk_state %u\n" , sk -> sk_state );
1697
1688
}
@@ -2037,13 +2028,13 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
2037
2028
timeout = msecs_to_jiffies (timeout );
2038
2029
/* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */
2039
2030
res = tipc_wait_for_connect (sock , & timeout );
2040
- goto exit ;
2041
- }
2042
-
2043
- if (sock -> state == SS_CONNECTED )
2031
+ break ;
2032
+ case TIPC_ESTABLISHED :
2044
2033
res = - EISCONN ;
2045
- else
2034
+ break ;
2035
+ default :
2046
2036
res = - EINVAL ;
2037
+ }
2047
2038
2048
2039
exit :
2049
2040
release_sock (sk );
@@ -2152,7 +2143,6 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
2152
2143
2153
2144
/* Connect new socket to it's peer */
2154
2145
tipc_sk_finish_conn (new_tsock , msg_origport (msg ), msg_orignode (msg ));
2155
- new_sock -> state = SS_CONNECTED ;
2156
2146
2157
2147
tsk_set_importance (new_tsock , msg_importance (msg ));
2158
2148
if (msg_named (msg )) {
0 commit comments