aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r--net/tipc/socket.c66
1 files changed, 26 insertions, 40 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 62655772adda..912665d409de 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/socket.c: TIPC socket API 2 * net/tipc/socket.c: TIPC socket API
3 * 3 *
4 * Copyright (c) 2001-2007, 2012 Ericsson AB 4 * Copyright (c) 2001-2007, 2012-2014, Ericsson AB
5 * Copyright (c) 2004-2008, 2010-2013, Wind River Systems 5 * Copyright (c) 2004-2008, 2010-2013, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -38,21 +38,12 @@
38#include "port.h" 38#include "port.h"
39 39
40#include <linux/export.h> 40#include <linux/export.h>
41#include <net/sock.h>
42 41
43#define SS_LISTENING -1 /* socket is listening */ 42#define SS_LISTENING -1 /* socket is listening */
44#define SS_READY -2 /* socket is connectionless */ 43#define SS_READY -2 /* socket is connectionless */
45 44
46#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ 45#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
47 46
48struct tipc_sock {
49 struct sock sk;
50 struct tipc_port *p;
51 unsigned int conn_timeout;
52};
53
54#define tipc_sk(sk) ((struct tipc_sock *)(sk))
55#define tipc_sk_port(sk) (tipc_sk(sk)->p)
56 47
57static int backlog_rcv(struct sock *sk, struct sk_buff *skb); 48static int backlog_rcv(struct sock *sk, struct sk_buff *skb);
58static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf); 49static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf);
@@ -114,6 +105,8 @@ static struct proto tipc_proto_kern;
114 * - port reference 105 * - port reference
115 */ 106 */
116 107
108#include "socket.h"
109
117/** 110/**
118 * advance_rx_queue - discard first buffer in socket receive queue 111 * advance_rx_queue - discard first buffer in socket receive queue
119 * 112 *
@@ -205,7 +198,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
205 sk->sk_rcvbuf = sysctl_tipc_rmem[1]; 198 sk->sk_rcvbuf = sysctl_tipc_rmem[1];
206 sk->sk_data_ready = tipc_data_ready; 199 sk->sk_data_ready = tipc_data_ready;
207 sk->sk_write_space = tipc_write_space; 200 sk->sk_write_space = tipc_write_space;
208 tipc_sk(sk)->p = tp_ptr;
209 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; 201 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT;
210 202
211 spin_unlock_bh(tp_ptr->lock); 203 spin_unlock_bh(tp_ptr->lock);
@@ -437,18 +429,17 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
437 int *uaddr_len, int peer) 429 int *uaddr_len, int peer)
438{ 430{
439 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 431 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
440 struct tipc_sock *tsock = tipc_sk(sock->sk); 432 struct tipc_port *port = tipc_sk_port(sock->sk);
441 433
442 memset(addr, 0, sizeof(*addr)); 434 memset(addr, 0, sizeof(*addr));
443 if (peer) { 435 if (peer) {
444 if ((sock->state != SS_CONNECTED) && 436 if ((sock->state != SS_CONNECTED) &&
445 ((peer != 2) || (sock->state != SS_DISCONNECTING))) 437 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
446 return -ENOTCONN; 438 return -ENOTCONN;
447 439 addr->addr.id.ref = tipc_port_peerport(port);
448 addr->addr.id.ref = tipc_port_peerport(tsock->p); 440 addr->addr.id.node = tipc_port_peernode(port);
449 addr->addr.id.node = tipc_port_peernode(tsock->p);
450 } else { 441 } else {
451 addr->addr.id.ref = tsock->p->ref; 442 addr->addr.id.ref = port->ref;
452 addr->addr.id.node = tipc_own_addr; 443 addr->addr.id.node = tipc_own_addr;
453 } 444 }
454 445
@@ -879,14 +870,13 @@ exit:
879 */ 870 */
880static int auto_connect(struct socket *sock, struct tipc_msg *msg) 871static int auto_connect(struct socket *sock, struct tipc_msg *msg)
881{ 872{
882 struct tipc_sock *tsock = tipc_sk(sock->sk); 873 struct tipc_port *p_ptr = tipc_sk_port(sock->sk);
883 struct tipc_port *p_ptr;
884 struct tipc_portid peer; 874 struct tipc_portid peer;
885 875
886 peer.ref = msg_origport(msg); 876 peer.ref = msg_origport(msg);
887 peer.node = msg_orignode(msg); 877 peer.node = msg_orignode(msg);
888 878
889 p_ptr = tipc_port_deref(tsock->p->ref); 879 p_ptr = tipc_port_deref(p_ptr->ref);
890 if (!p_ptr) 880 if (!p_ptr)
891 return -EINVAL; 881 return -EINVAL;
892 882
@@ -1270,17 +1260,18 @@ static void tipc_data_ready(struct sock *sk, int len)
1270 1260
1271/** 1261/**
1272 * filter_connect - Handle all incoming messages for a connection-based socket 1262 * filter_connect - Handle all incoming messages for a connection-based socket
1273 * @tsock: TIPC socket 1263 * @port: TIPC port
1274 * @msg: message 1264 * @msg: message
1275 * 1265 *
1276 * Returns TIPC error status code and socket error status code 1266 * Returns TIPC error status code and socket error status code
1277 * once it encounters some errors 1267 * once it encounters some errors
1278 */ 1268 */
1279static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) 1269static u32 filter_connect(struct tipc_port *port, struct sk_buff **buf)
1280{ 1270{
1281 struct socket *sock = tsock->sk.sk_socket; 1271 struct sock *sk = tipc_port_to_sk(port);
1272 struct socket *sock = sk->sk_socket;
1282 struct tipc_msg *msg = buf_msg(*buf); 1273 struct tipc_msg *msg = buf_msg(*buf);
1283 struct sock *sk = &tsock->sk; 1274
1284 u32 retval = TIPC_ERR_NO_PORT; 1275 u32 retval = TIPC_ERR_NO_PORT;
1285 int res; 1276 int res;
1286 1277
@@ -1290,10 +1281,10 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf)
1290 switch ((int)sock->state) { 1281 switch ((int)sock->state) {
1291 case SS_CONNECTED: 1282 case SS_CONNECTED:
1292 /* Accept only connection-based messages sent by peer */ 1283 /* Accept only connection-based messages sent by peer */
1293 if (msg_connected(msg) && tipc_port_peer_msg(tsock->p, msg)) { 1284 if (msg_connected(msg) && tipc_port_peer_msg(port, msg)) {
1294 if (unlikely(msg_errcode(msg))) { 1285 if (unlikely(msg_errcode(msg))) {
1295 sock->state = SS_DISCONNECTING; 1286 sock->state = SS_DISCONNECTING;
1296 __tipc_port_disconnect(tsock->p); 1287 __tipc_port_disconnect(port);
1297 } 1288 }
1298 retval = TIPC_OK; 1289 retval = TIPC_OK;
1299 } 1290 }
@@ -1401,7 +1392,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1401 if (msg_connected(msg)) 1392 if (msg_connected(msg))
1402 return TIPC_ERR_NO_PORT; 1393 return TIPC_ERR_NO_PORT;
1403 } else { 1394 } else {
1404 res = filter_connect(tipc_sk(sk), &buf); 1395 res = filter_connect(tipc_sk_port(sk), &buf);
1405 if (res != TIPC_OK || buf == NULL) 1396 if (res != TIPC_OK || buf == NULL)
1406 return res; 1397 return res;
1407 } 1398 }
@@ -1447,9 +1438,9 @@ static int backlog_rcv(struct sock *sk, struct sk_buff *buf)
1447 * 1438 *
1448 * Returns TIPC error status code (TIPC_OK if message is not to be rejected) 1439 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1449 */ 1440 */
1450static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) 1441static u32 dispatch(struct tipc_port *port, struct sk_buff *buf)
1451{ 1442{
1452 struct sock *sk = tport->sk; 1443 struct sock *sk = tipc_port_to_sk(port);
1453 u32 res; 1444 u32 res;
1454 1445
1455 /* 1446 /*
@@ -1478,10 +1469,9 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1478 * 1469 *
1479 * Called with port lock already taken. 1470 * Called with port lock already taken.
1480 */ 1471 */
1481static void wakeupdispatch(struct tipc_port *tport) 1472static void wakeupdispatch(struct tipc_port *port)
1482{ 1473{
1483 struct sock *sk = tport->sk; 1474 struct sock *sk = tipc_port_to_sk(port);
1484
1485 sk->sk_write_space(sk); 1475 sk->sk_write_space(sk);
1486} 1476}
1487 1477
@@ -1661,8 +1651,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1661{ 1651{
1662 struct sock *new_sk, *sk = sock->sk; 1652 struct sock *new_sk, *sk = sock->sk;
1663 struct sk_buff *buf; 1653 struct sk_buff *buf;
1664 struct tipc_sock *new_tsock; 1654 struct tipc_port *new_port;
1665 struct tipc_port *new_tport;
1666 struct tipc_msg *msg; 1655 struct tipc_msg *msg;
1667 struct tipc_portid peer; 1656 struct tipc_portid peer;
1668 u32 new_ref; 1657 u32 new_ref;
@@ -1675,7 +1664,6 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1675 res = -EINVAL; 1664 res = -EINVAL;
1676 goto exit; 1665 goto exit;
1677 } 1666 }
1678
1679 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); 1667 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
1680 res = tipc_wait_for_accept(sock, timeo); 1668 res = tipc_wait_for_accept(sock, timeo);
1681 if (res) 1669 if (res)
@@ -1688,9 +1676,8 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1688 goto exit; 1676 goto exit;
1689 1677
1690 new_sk = new_sock->sk; 1678 new_sk = new_sock->sk;
1691 new_tsock = tipc_sk(new_sk); 1679 new_port = tipc_sk_port(new_sk);
1692 new_tport = new_tsock->p; 1680 new_ref = new_port->ref;
1693 new_ref = new_tport->ref;
1694 msg = buf_msg(buf); 1681 msg = buf_msg(buf);
1695 1682
1696 /* we lock on new_sk; but lockdep sees the lock on sk */ 1683 /* we lock on new_sk; but lockdep sees the lock on sk */
@@ -1710,8 +1697,8 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1710 1697
1711 tipc_set_portimportance(new_ref, msg_importance(msg)); 1698 tipc_set_portimportance(new_ref, msg_importance(msg));
1712 if (msg_named(msg)) { 1699 if (msg_named(msg)) {
1713 new_tport->conn_type = msg_nametype(msg); 1700 new_port->conn_type = msg_nametype(msg);
1714 new_tport->conn_instance = msg_nameinst(msg); 1701 new_port->conn_instance = msg_nameinst(msg);
1715 } 1702 }
1716 1703
1717 /* 1704 /*
@@ -1729,7 +1716,6 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1729 skb_set_owner_r(buf, new_sk); 1716 skb_set_owner_r(buf, new_sk);
1730 } 1717 }
1731 release_sock(new_sk); 1718 release_sock(new_sk);
1732
1733exit: 1719exit:
1734 release_sock(sk); 1720 release_sock(sk);
1735 return res; 1721 return res;