aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-08-22 18:09:09 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-23 11:18:33 -0700
commit5728901581139e68e6cf53b36590f64829c37453 (patch)
tree3c0aa4250f7b4528d8997a18d757bd36d45034ee /net/tipc/socket.c
parenttipc: use message to abort connections when losing contact to node (diff)
downloadlinux-dev-5728901581139e68e6cf53b36590f64829c37453.tar.xz
linux-dev-5728901581139e68e6cf53b36590f64829c37453.zip
tipc: clean up socket timer function
The last remaining BH upcall to the socket, apart for the message reception function tipc_sk_rcv(), is the timer function. We prefer to let this function continue executing in BH, since it only does read-acces to semi-permanent data, but we make three changes to it: 1) We introduce a bh_lock_sock()/bh_unlock_sock() inside the scope of port_lock. This is a preparation for replacing port_lock with bh_lock_sock() at the locations where it is still used. 2) We move the function from port.c to socket.c, as a further step of eliminating the port code level altogether. 3) We let it make use of the newly introduced tipc_msg_create() function. This enables us to get rid of three context specific functions (port_create_self_abort_msg() etc.) in port.c Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to '')
-rw-r--r--net/tipc/socket.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index a8be4d2001f7..5f8376e8da2a 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -53,6 +53,7 @@ static void tipc_write_space(struct sock *sk);
static int tipc_release(struct socket *sock);
static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags);
static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p);
+static void tipc_sk_timeout(unsigned long ref);
static const struct proto_ops packet_ops;
static const struct proto_ops stream_ops;
@@ -202,6 +203,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
sock->state = state;
sock_init_data(sock, sk);
+ k_init_timer(&port->timer, (Handler)tipc_sk_timeout, ref);
sk->sk_backlog_rcv = tipc_backlog_rcv;
sk->sk_rcvbuf = sysctl_tipc_rmem[1];
sk->sk_data_ready = tipc_data_ready;
@@ -1946,6 +1948,50 @@ restart:
return res;
}
+static void tipc_sk_timeout(unsigned long ref)
+{
+ struct tipc_port *port = tipc_port_lock(ref);
+ struct tipc_sock *tsk;
+ struct sock *sk;
+ struct sk_buff *buf = NULL;
+ struct tipc_msg *msg = NULL;
+ u32 peer_port, peer_node;
+
+ if (!port)
+ return;
+
+ if (!port->connected) {
+ tipc_port_unlock(port);
+ return;
+ }
+ tsk = tipc_port_to_sock(port);
+ sk = &tsk->sk;
+ bh_lock_sock(sk);
+ peer_port = tipc_port_peerport(port);
+ peer_node = tipc_port_peernode(port);
+
+ if (port->probing_state == TIPC_CONN_PROBING) {
+ /* Previous probe not answered -> self abort */
+ buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
+ SHORT_H_SIZE, 0, tipc_own_addr,
+ peer_node, ref, peer_port,
+ TIPC_ERR_NO_PORT);
+ } else {
+ buf = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE,
+ 0, peer_node, tipc_own_addr,
+ peer_port, ref, TIPC_OK);
+ port->probing_state = TIPC_CONN_PROBING;
+ k_start_timer(&port->timer, port->probing_interval);
+ }
+ bh_unlock_sock(sk);
+ tipc_port_unlock(port);
+ if (!buf)
+ return;
+
+ msg = buf_msg(buf);
+ tipc_link_xmit(buf, msg_destnode(msg), msg_link_selector(msg));
+}
+
/**
* tipc_setsockopt - set socket option
* @sock: socket structure