aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-05-14 05:39:15 -0400
committerDavid S. Miller <davem@davemloft.net>2014-05-14 15:19:48 -0400
commit9816f0615d549b948a76e6d2385159b4366e4658 (patch)
tree6384a917346902a5916789cdea9d3a18e47f53a6 /net/tipc
parentc82910e2a8d6fc9dd321a1f30dd4e89fb779cfe1 (diff)
tipc: merge port message reception into socket reception function
In order to reduce complexity and save a call level during message reception at port/socket level, we remove the function tipc_port_rcv() and merge its functionality into tipc_sk_rcv(). Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/link.c3
-rw-r--r--net/tipc/net.c3
-rw-r--r--net/tipc/port.c39
-rw-r--r--net/tipc/port.h1
-rw-r--r--net/tipc/socket.c57
-rw-r--r--net/tipc/socket.h2
6 files changed, 46 insertions, 59 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 24d058796cd9..ad2c57f5868d 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -37,6 +37,7 @@
37#include "core.h" 37#include "core.h"
38#include "link.h" 38#include "link.h"
39#include "port.h" 39#include "port.h"
40#include "socket.h"
40#include "name_distr.h" 41#include "name_distr.h"
41#include "discover.h" 42#include "discover.h"
42#include "config.h" 43#include "config.h"
@@ -1590,7 +1591,7 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
1590 case TIPC_HIGH_IMPORTANCE: 1591 case TIPC_HIGH_IMPORTANCE:
1591 case TIPC_CRITICAL_IMPORTANCE: 1592 case TIPC_CRITICAL_IMPORTANCE:
1592 tipc_node_unlock(n_ptr); 1593 tipc_node_unlock(n_ptr);
1593 tipc_port_rcv(buf); 1594 tipc_sk_rcv(buf);
1594 continue; 1595 continue;
1595 case MSG_BUNDLER: 1596 case MSG_BUNDLER:
1596 l_ptr->stats.recv_bundles++; 1597 l_ptr->stats.recv_bundles++;
diff --git a/net/tipc/net.c b/net/tipc/net.c
index f8fc95d58c0d..f64375e7f99f 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -39,6 +39,7 @@
39#include "name_distr.h" 39#include "name_distr.h"
40#include "subscr.h" 40#include "subscr.h"
41#include "port.h" 41#include "port.h"
42#include "socket.h"
42#include "node.h" 43#include "node.h"
43#include "config.h" 44#include "config.h"
44 45
@@ -141,7 +142,7 @@ void tipc_net_route_msg(struct sk_buff *buf)
141 if (msg_mcast(msg)) 142 if (msg_mcast(msg))
142 tipc_port_mcast_rcv(buf, NULL); 143 tipc_port_mcast_rcv(buf, NULL);
143 else if (msg_destport(msg)) 144 else if (msg_destport(msg))
144 tipc_port_rcv(buf); 145 tipc_sk_rcv(buf);
145 else 146 else
146 net_route_named_msg(buf); 147 net_route_named_msg(buf);
147 return; 148 return;
diff --git a/net/tipc/port.c b/net/tipc/port.c
index 5c14c7801ee6..5fd7acce01ea 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -165,7 +165,7 @@ void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp)
165 msg_set_destnode(msg, tipc_own_addr); 165 msg_set_destnode(msg, tipc_own_addr);
166 if (dp->count == 1) { 166 if (dp->count == 1) {
167 msg_set_destport(msg, dp->ports[0]); 167 msg_set_destport(msg, dp->ports[0]);
168 tipc_port_rcv(buf); 168 tipc_sk_rcv(buf);
169 tipc_port_list_free(dp); 169 tipc_port_list_free(dp);
170 return; 170 return;
171 } 171 }
@@ -180,7 +180,7 @@ void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp)
180 if ((index == 0) && (cnt != 0)) 180 if ((index == 0) && (cnt != 0))
181 item = item->next; 181 item = item->next;
182 msg_set_destport(buf_msg(b), item->ports[index]); 182 msg_set_destport(buf_msg(b), item->ports[index]);
183 tipc_port_rcv(b); 183 tipc_sk_rcv(b);
184 } 184 }
185 } 185 }
186exit: 186exit:
@@ -343,7 +343,7 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err)
343 /* send returned message & dispose of rejected message */ 343 /* send returned message & dispose of rejected message */
344 src_node = msg_prevnode(msg); 344 src_node = msg_prevnode(msg);
345 if (in_own_node(src_node)) 345 if (in_own_node(src_node))
346 tipc_port_rcv(rbuf); 346 tipc_sk_rcv(rbuf);
347 else 347 else
348 tipc_link_xmit(rbuf, src_node, msg_link_selector(rmsg)); 348 tipc_link_xmit(rbuf, src_node, msg_link_selector(rmsg));
349exit: 349exit:
@@ -754,37 +754,6 @@ int tipc_port_shutdown(u32 ref)
754 return tipc_port_disconnect(ref); 754 return tipc_port_disconnect(ref);
755} 755}
756 756
757/**
758 * tipc_port_rcv - receive message from lower layer and deliver to port user
759 */
760int tipc_port_rcv(struct sk_buff *buf)
761{
762 struct tipc_port *p_ptr;
763 struct tipc_msg *msg = buf_msg(buf);
764 u32 destport = msg_destport(msg);
765 u32 dsz = msg_data_sz(msg);
766 u32 err;
767
768 /* forward unresolved named message */
769 if (unlikely(!destport)) {
770 tipc_net_route_msg(buf);
771 return dsz;
772 }
773
774 /* validate destination & pass to port, otherwise reject message */
775 p_ptr = tipc_port_lock(destport);
776 if (likely(p_ptr)) {
777 err = tipc_sk_rcv(&tipc_port_to_sock(p_ptr)->sk, buf);
778 tipc_port_unlock(p_ptr);
779 if (likely(!err))
780 return dsz;
781 } else {
782 err = TIPC_ERR_NO_PORT;
783 }
784
785 return tipc_reject_msg(buf, err);
786}
787
788/* 757/*
789 * tipc_port_iovec_rcv: Concatenate and deliver sectioned 758 * tipc_port_iovec_rcv: Concatenate and deliver sectioned
790 * message for this node. 759 * message for this node.
@@ -798,7 +767,7 @@ static int tipc_port_iovec_rcv(struct tipc_port *sender,
798 767
799 res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf); 768 res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf);
800 if (likely(buf)) 769 if (likely(buf))
801 tipc_port_rcv(buf); 770 tipc_sk_rcv(buf);
802 return res; 771 return res;
803} 772}
804 773
diff --git a/net/tipc/port.h b/net/tipc/port.h
index 5dfd165df1d7..cf4ca5b1d9a4 100644
--- a/net/tipc/port.h
+++ b/net/tipc/port.h
@@ -135,7 +135,6 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg);
135/* 135/*
136 * TIPC messaging routines 136 * TIPC messaging routines
137 */ 137 */
138int tipc_port_rcv(struct sk_buff *buf);
139 138
140int tipc_send(struct tipc_port *port, 139int tipc_send(struct tipc_port *port,
141 struct iovec const *msg_sect, 140 struct iovec const *msg_sect,
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 249500614568..ac08966f2858 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1442,39 +1442,56 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *buf)
1442 1442
1443/** 1443/**
1444 * tipc_sk_rcv - handle incoming message 1444 * tipc_sk_rcv - handle incoming message
1445 * @sk: socket receiving message 1445 * @buf: buffer containing arriving message
1446 * @buf: message 1446 * Consumes buffer
1447 * 1447 * Returns 0 if success, or errno: -EHOSTUNREACH
1448 * Called with port lock already taken.
1449 *
1450 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1451 */ 1448 */
1452u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf) 1449int tipc_sk_rcv(struct sk_buff *buf)
1453{ 1450{
1454 struct tipc_sock *tsk = tipc_sk(sk); 1451 struct tipc_sock *tsk;
1455 u32 res; 1452 struct tipc_port *port;
1453 struct sock *sk;
1454 u32 dport = msg_destport(buf_msg(buf));
1455 int err = TIPC_OK;
1456 uint limit; 1456 uint limit;
1457 /* 1457
1458 * Process message if socket is unlocked; otherwise add to backlog queue 1458 /* Forward unresolved named message */
1459 * 1459 if (unlikely(!dport)) {
1460 * This code is based on sk_receive_skb(), but must be distinct from it 1460 tipc_net_route_msg(buf);
1461 * since a TIPC-specific filter/reject mechanism is utilized 1461 return 0;
1462 */ 1462 }
1463
1464 /* Validate destination */
1465 port = tipc_port_lock(dport);
1466 if (unlikely(!port)) {
1467 err = TIPC_ERR_NO_PORT;
1468 goto exit;
1469 }
1470
1471 tsk = tipc_port_to_sock(port);
1472 sk = &tsk->sk;
1473
1474 /* Queue message */
1463 bh_lock_sock(sk); 1475 bh_lock_sock(sk);
1476
1464 if (!sock_owned_by_user(sk)) { 1477 if (!sock_owned_by_user(sk)) {
1465 res = filter_rcv(sk, buf); 1478 err = filter_rcv(sk, buf);
1466 } else { 1479 } else {
1467 if (sk->sk_backlog.len == 0) 1480 if (sk->sk_backlog.len == 0)
1468 atomic_set(&tsk->dupl_rcvcnt, 0); 1481 atomic_set(&tsk->dupl_rcvcnt, 0);
1469 limit = rcvbuf_limit(sk, buf) + atomic_read(&tsk->dupl_rcvcnt); 1482 limit = rcvbuf_limit(sk, buf) + atomic_read(&tsk->dupl_rcvcnt);
1470 if (sk_add_backlog(sk, buf, limit)) 1483 if (sk_add_backlog(sk, buf, limit))
1471 res = TIPC_ERR_OVERLOAD; 1484 err = TIPC_ERR_OVERLOAD;
1472 else
1473 res = TIPC_OK;
1474 } 1485 }
1486
1475 bh_unlock_sock(sk); 1487 bh_unlock_sock(sk);
1488 tipc_port_unlock(port);
1476 1489
1477 return res; 1490 if (likely(!err))
1491 return 0;
1492exit:
1493 tipc_reject_msg(buf, err);
1494 return -EHOSTUNREACH;
1478} 1495}
1479 1496
1480static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) 1497static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
diff --git a/net/tipc/socket.h b/net/tipc/socket.h
index 86c27cc51e33..3afcd2a70b31 100644
--- a/net/tipc/socket.h
+++ b/net/tipc/socket.h
@@ -69,6 +69,6 @@ static inline void tipc_sock_wakeup(struct tipc_sock *tsk)
69 tsk->sk.sk_write_space(&tsk->sk); 69 tsk->sk.sk_write_space(&tsk->sk);
70} 70}
71 71
72u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf); 72int tipc_sk_rcv(struct sk_buff *buf);
73 73
74#endif 74#endif