#include "bcast.h"
#include "netlink.h"
-#define SS_LISTENING -1 /* socket is listening */
-
#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
#define CONN_PROBING_INTERVAL msecs_to_jiffies(3600000) /* [ms] => 1 h */
#define TIPC_FWD_MSG 1
#define TIPC_MAX_PORT 0xffffffff
#define TIPC_MIN_PORT 1
+enum {
+ TIPC_LISTEN = TCP_LISTEN,
+};
+
/**
* struct tipc_sock - TIPC socket structure
* @sk: socket - interacts with 'port' and with user via the socket API
return false;
}
+/* tipc_set_sk_state - set the sk_state of the socket
+ * @sk: socket
+ *
+ * Caller must hold socket lock
+ *
+ * Returns 0 on success, errno otherwise
+ */
+static int tipc_set_sk_state(struct sock *sk, int state)
+{
+ int oldstate = sk->sk_socket->state;
+ int res = -EINVAL;
+
+ switch (state) {
+ case TIPC_LISTEN:
+ if (oldstate == SS_UNCONNECTED)
+ res = 0;
+ break;
+ }
+
+ if (!res)
+ sk->sk_state = state;
+
+ return res;
+}
+
/**
* tipc_sk_create - create a TIPC socket
* @net: network namespace (must be default network)
switch ((int)sock->state) {
case SS_UNCONNECTED:
- if (!tsk->link_cong)
- mask |= POLLOUT;
+ switch (sk->sk_state) {
+ case TIPC_LISTEN:
+ if (!skb_queue_empty(&sk->sk_receive_queue))
+ mask |= (POLLIN | POLLRDNORM);
+ break;
+ default:
+ if (!tsk->link_cong)
+ mask |= POLLOUT;
+ break;
+ }
break;
case SS_CONNECTED:
if (!tsk->link_cong && !tsk_conn_cong(tsk))
mask |= POLLOUT;
/* fall thru' */
case SS_CONNECTING:
- case SS_LISTENING:
if (!skb_queue_empty(&sk->sk_receive_queue))
mask |= (POLLIN | POLLRDNORM);
break;
return -EINVAL;
}
if (!is_connectionless) {
- if (sock->state == SS_LISTENING)
+ if (sk->sk_state == TIPC_LISTEN)
return -EPIPE;
if (sock->state != SS_UNCONNECTED)
return -EISCONN;
msg_set_dest_droppable(hdr, 1);
return false;
- case SS_LISTENING:
case SS_UNCONNECTED:
/* Accept only SYN message */
int res;
lock_sock(sk);
-
- if (sock->state != SS_UNCONNECTED)
- res = -EINVAL;
- else {
- sock->state = SS_LISTENING;
- res = 0;
- }
-
+ res = tipc_set_sk_state(sk, TIPC_LISTEN);
release_sock(sk);
+
return res;
}
err = 0;
if (!skb_queue_empty(&sk->sk_receive_queue))
break;
- err = -EINVAL;
- if (sock->state != SS_LISTENING)
- break;
err = -EAGAIN;
if (!timeo)
break;
lock_sock(sk);
- if (sock->state != SS_LISTENING) {
+ if (sk->sk_state != TIPC_LISTEN) {
res = -EINVAL;
goto exit;
}