diff options
author | Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com> | 2016-11-01 09:02:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-11-01 11:53:24 -0400 |
commit | c752023aab5856559a295d045530af89cc51df06 (patch) | |
tree | 94c4f4100f8271bcecdacff99ca805849fbc0040 /net/tipc | |
parent | 360aab6b49b93937bafd45034d33e7d44148fe82 (diff) |
tipc: remove socket state SS_READY
Until now, tipc socket state SS_READY declares that the socket is a
connectionless socket.
In this commit, we remove the state SS_READY and replace it with a
condition which returns true for datagram / connectionless sockets.
Acked-by: Ying Xue <ying.xue@windriver.com>
Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/socket.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 1b1aa941cd06..a8c10764f2f6 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -45,7 +45,6 @@ | |||
45 | #include "netlink.h" | 45 | #include "netlink.h" |
46 | 46 | ||
47 | #define SS_LISTENING -1 /* socket is listening */ | 47 | #define SS_LISTENING -1 /* socket is listening */ |
48 | #define SS_READY -2 /* socket is connectionless */ | ||
49 | 48 | ||
50 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ | 49 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ |
51 | #define CONN_PROBING_INTERVAL msecs_to_jiffies(3600000) /* [ms] => 1 h */ | 50 | #define CONN_PROBING_INTERVAL msecs_to_jiffies(3600000) /* [ms] => 1 h */ |
@@ -294,6 +293,16 @@ static bool tipc_sk_connected(struct sock *sk) | |||
294 | return sk->sk_socket->state == SS_CONNECTED; | 293 | return sk->sk_socket->state == SS_CONNECTED; |
295 | } | 294 | } |
296 | 295 | ||
296 | /* tipc_sk_type_connectionless - check if the socket is datagram socket | ||
297 | * @sk: socket | ||
298 | * | ||
299 | * Returns true if connection less, false otherwise | ||
300 | */ | ||
301 | static bool tipc_sk_type_connectionless(struct sock *sk) | ||
302 | { | ||
303 | return sk->sk_type == SOCK_RDM || sk->sk_type == SOCK_DGRAM; | ||
304 | } | ||
305 | |||
297 | /* tsk_peer_msg - verify if message was sent by connected port's peer | 306 | /* tsk_peer_msg - verify if message was sent by connected port's peer |
298 | * | 307 | * |
299 | * Handles cases where the node's network address has changed from | 308 | * Handles cases where the node's network address has changed from |
@@ -345,7 +354,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
345 | { | 354 | { |
346 | struct tipc_net *tn; | 355 | struct tipc_net *tn; |
347 | const struct proto_ops *ops; | 356 | const struct proto_ops *ops; |
348 | socket_state state; | ||
349 | struct sock *sk; | 357 | struct sock *sk; |
350 | struct tipc_sock *tsk; | 358 | struct tipc_sock *tsk; |
351 | struct tipc_msg *msg; | 359 | struct tipc_msg *msg; |
@@ -357,16 +365,13 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
357 | switch (sock->type) { | 365 | switch (sock->type) { |
358 | case SOCK_STREAM: | 366 | case SOCK_STREAM: |
359 | ops = &stream_ops; | 367 | ops = &stream_ops; |
360 | state = SS_UNCONNECTED; | ||
361 | break; | 368 | break; |
362 | case SOCK_SEQPACKET: | 369 | case SOCK_SEQPACKET: |
363 | ops = &packet_ops; | 370 | ops = &packet_ops; |
364 | state = SS_UNCONNECTED; | ||
365 | break; | 371 | break; |
366 | case SOCK_DGRAM: | 372 | case SOCK_DGRAM: |
367 | case SOCK_RDM: | 373 | case SOCK_RDM: |
368 | ops = &msg_ops; | 374 | ops = &msg_ops; |
369 | state = SS_READY; | ||
370 | break; | 375 | break; |
371 | default: | 376 | default: |
372 | return -EPROTOTYPE; | 377 | return -EPROTOTYPE; |
@@ -387,7 +392,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
387 | 392 | ||
388 | /* Finish initializing socket data structures */ | 393 | /* Finish initializing socket data structures */ |
389 | sock->ops = ops; | 394 | sock->ops = ops; |
390 | sock->state = state; | 395 | sock->state = SS_UNCONNECTED; |
391 | sock_init_data(sock, sk); | 396 | sock_init_data(sock, sk); |
392 | if (tipc_sk_insert(tsk)) { | 397 | if (tipc_sk_insert(tsk)) { |
393 | pr_warn("Socket create failed; port number exhausted\n"); | 398 | pr_warn("Socket create failed; port number exhausted\n"); |
@@ -407,7 +412,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
407 | tsk->snd_win = tsk_adv_blocks(RCVBUF_MIN); | 412 | tsk->snd_win = tsk_adv_blocks(RCVBUF_MIN); |
408 | tsk->rcv_win = tsk->snd_win; | 413 | tsk->rcv_win = tsk->snd_win; |
409 | 414 | ||
410 | if (sock->state == SS_READY) { | 415 | if (tipc_sk_type_connectionless(sk)) { |
411 | tsk_set_unreturnable(tsk, true); | 416 | tsk_set_unreturnable(tsk, true); |
412 | if (sock->type == SOCK_DGRAM) | 417 | if (sock->type == SOCK_DGRAM) |
413 | tsk_set_unreliable(tsk, true); | 418 | tsk_set_unreliable(tsk, true); |
@@ -651,12 +656,19 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock, | |||
651 | 656 | ||
652 | sock_poll_wait(file, sk_sleep(sk), wait); | 657 | sock_poll_wait(file, sk_sleep(sk), wait); |
653 | 658 | ||
659 | if (tipc_sk_type_connectionless(sk)) { | ||
660 | if (!tsk->link_cong) | ||
661 | mask |= POLLOUT; | ||
662 | if (!skb_queue_empty(&sk->sk_receive_queue)) | ||
663 | mask |= (POLLIN | POLLRDNORM); | ||
664 | return mask; | ||
665 | } | ||
666 | |||
654 | switch ((int)sock->state) { | 667 | switch ((int)sock->state) { |
655 | case SS_UNCONNECTED: | 668 | case SS_UNCONNECTED: |
656 | if (!tsk->link_cong) | 669 | if (!tsk->link_cong) |
657 | mask |= POLLOUT; | 670 | mask |= POLLOUT; |
658 | break; | 671 | break; |
659 | case SS_READY: | ||
660 | case SS_CONNECTED: | 672 | case SS_CONNECTED: |
661 | if (!tsk->link_cong && !tsk_conn_cong(tsk)) | 673 | if (!tsk->link_cong && !tsk_conn_cong(tsk)) |
662 | mask |= POLLOUT; | 674 | mask |= POLLOUT; |
@@ -893,6 +905,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz) | |||
893 | struct tipc_msg *mhdr = &tsk->phdr; | 905 | struct tipc_msg *mhdr = &tsk->phdr; |
894 | u32 dnode, dport; | 906 | u32 dnode, dport; |
895 | struct sk_buff_head pktchain; | 907 | struct sk_buff_head pktchain; |
908 | bool is_connectionless = tipc_sk_type_connectionless(sk); | ||
896 | struct sk_buff *skb; | 909 | struct sk_buff *skb; |
897 | struct tipc_name_seq *seq; | 910 | struct tipc_name_seq *seq; |
898 | struct iov_iter save; | 911 | struct iov_iter save; |
@@ -903,7 +916,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz) | |||
903 | if (dsz > TIPC_MAX_USER_MSG_SIZE) | 916 | if (dsz > TIPC_MAX_USER_MSG_SIZE) |
904 | return -EMSGSIZE; | 917 | return -EMSGSIZE; |
905 | if (unlikely(!dest)) { | 918 | if (unlikely(!dest)) { |
906 | if (sock->state == SS_READY && tsk->peer.family == AF_TIPC) | 919 | if (is_connectionless && tsk->peer.family == AF_TIPC) |
907 | dest = &tsk->peer; | 920 | dest = &tsk->peer; |
908 | else | 921 | else |
909 | return -EDESTADDRREQ; | 922 | return -EDESTADDRREQ; |
@@ -911,7 +924,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz) | |||
911 | dest->family != AF_TIPC) { | 924 | dest->family != AF_TIPC) { |
912 | return -EINVAL; | 925 | return -EINVAL; |
913 | } | 926 | } |
914 | if (unlikely(sock->state != SS_READY)) { | 927 | if (!is_connectionless) { |
915 | if (sock->state == SS_LISTENING) | 928 | if (sock->state == SS_LISTENING) |
916 | return -EPIPE; | 929 | return -EPIPE; |
917 | if (sock->state != SS_UNCONNECTED) | 930 | if (sock->state != SS_UNCONNECTED) |
@@ -966,7 +979,7 @@ new_mtu: | |||
966 | TIPC_SKB_CB(skb)->wakeup_pending = tsk->link_cong; | 979 | TIPC_SKB_CB(skb)->wakeup_pending = tsk->link_cong; |
967 | rc = tipc_node_xmit(net, &pktchain, dnode, tsk->portid); | 980 | rc = tipc_node_xmit(net, &pktchain, dnode, tsk->portid); |
968 | if (likely(!rc)) { | 981 | if (likely(!rc)) { |
969 | if (sock->state != SS_READY) | 982 | if (!is_connectionless) |
970 | sock->state = SS_CONNECTING; | 983 | sock->state = SS_CONNECTING; |
971 | return dsz; | 984 | return dsz; |
972 | } | 985 | } |
@@ -1337,6 +1350,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, size_t buf_len, | |||
1337 | struct tipc_sock *tsk = tipc_sk(sk); | 1350 | struct tipc_sock *tsk = tipc_sk(sk); |
1338 | struct sk_buff *buf; | 1351 | struct sk_buff *buf; |
1339 | struct tipc_msg *msg; | 1352 | struct tipc_msg *msg; |
1353 | bool is_connectionless = tipc_sk_type_connectionless(sk); | ||
1340 | long timeo; | 1354 | long timeo; |
1341 | unsigned int sz; | 1355 | unsigned int sz; |
1342 | u32 err; | 1356 | u32 err; |
@@ -1348,7 +1362,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, size_t buf_len, | |||
1348 | 1362 | ||
1349 | lock_sock(sk); | 1363 | lock_sock(sk); |
1350 | 1364 | ||
1351 | if (unlikely(sock->state == SS_UNCONNECTED)) { | 1365 | if (!is_connectionless && unlikely(sock->state == SS_UNCONNECTED)) { |
1352 | res = -ENOTCONN; | 1366 | res = -ENOTCONN; |
1353 | goto exit; | 1367 | goto exit; |
1354 | } | 1368 | } |
@@ -1393,8 +1407,8 @@ restart: | |||
1393 | goto exit; | 1407 | goto exit; |
1394 | res = sz; | 1408 | res = sz; |
1395 | } else { | 1409 | } else { |
1396 | if ((sock->state == SS_READY) || | 1410 | if (is_connectionless || err == TIPC_CONN_SHUTDOWN || |
1397 | ((err == TIPC_CONN_SHUTDOWN) || m->msg_control)) | 1411 | m->msg_control) |
1398 | res = 0; | 1412 | res = 0; |
1399 | else | 1413 | else |
1400 | res = -ECONNRESET; | 1414 | res = -ECONNRESET; |
@@ -1403,7 +1417,7 @@ restart: | |||
1403 | if (unlikely(flags & MSG_PEEK)) | 1417 | if (unlikely(flags & MSG_PEEK)) |
1404 | goto exit; | 1418 | goto exit; |
1405 | 1419 | ||
1406 | if (likely(sock->state != SS_READY)) { | 1420 | if (likely(!is_connectionless)) { |
1407 | tsk->rcv_unacked += tsk_inc(tsk, hlen + sz); | 1421 | tsk->rcv_unacked += tsk_inc(tsk, hlen + sz); |
1408 | if (unlikely(tsk->rcv_unacked >= (tsk->rcv_win / 4))) | 1422 | if (unlikely(tsk->rcv_unacked >= (tsk->rcv_win / 4))) |
1409 | tipc_sk_send_ack(tsk); | 1423 | tipc_sk_send_ack(tsk); |
@@ -1699,7 +1713,6 @@ static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *skb) | |||
1699 | static bool filter_rcv(struct sock *sk, struct sk_buff *skb, | 1713 | static bool filter_rcv(struct sock *sk, struct sk_buff *skb, |
1700 | struct sk_buff_head *xmitq) | 1714 | struct sk_buff_head *xmitq) |
1701 | { | 1715 | { |
1702 | struct socket *sock = sk->sk_socket; | ||
1703 | struct tipc_sock *tsk = tipc_sk(sk); | 1716 | struct tipc_sock *tsk = tipc_sk(sk); |
1704 | struct tipc_msg *hdr = buf_msg(skb); | 1717 | struct tipc_msg *hdr = buf_msg(skb); |
1705 | unsigned int limit = rcvbuf_limit(sk, skb); | 1718 | unsigned int limit = rcvbuf_limit(sk, skb); |
@@ -1725,7 +1738,7 @@ static bool filter_rcv(struct sock *sk, struct sk_buff *skb, | |||
1725 | } | 1738 | } |
1726 | 1739 | ||
1727 | /* Reject if wrong message type for current socket state */ | 1740 | /* Reject if wrong message type for current socket state */ |
1728 | if (unlikely(sock->state == SS_READY)) { | 1741 | if (tipc_sk_type_connectionless(sk)) { |
1729 | if (msg_connected(hdr)) { | 1742 | if (msg_connected(hdr)) { |
1730 | err = TIPC_ERR_NO_PORT; | 1743 | err = TIPC_ERR_NO_PORT; |
1731 | goto reject; | 1744 | goto reject; |
@@ -1935,7 +1948,7 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest, | |||
1935 | lock_sock(sk); | 1948 | lock_sock(sk); |
1936 | 1949 | ||
1937 | /* DGRAM/RDM connect(), just save the destaddr */ | 1950 | /* DGRAM/RDM connect(), just save the destaddr */ |
1938 | if (sock->state == SS_READY) { | 1951 | if (tipc_sk_type_connectionless(sk)) { |
1939 | if (dst->family == AF_UNSPEC) { | 1952 | if (dst->family == AF_UNSPEC) { |
1940 | memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc)); | 1953 | memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc)); |
1941 | } else if (destlen != sizeof(struct sockaddr_tipc)) { | 1954 | } else if (destlen != sizeof(struct sockaddr_tipc)) { |