aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2015-02-05 08:36:39 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-05 19:00:02 -0500
commite3a77561e7d326e18881ef3cb84807892b353459 (patch)
treeb3d958bcfa747d87a979936e5814b7a5aeba97f3 /net/tipc/socket.c
parentd570d86497eeb11410b1c096d82ade11bcdd966c (diff)
tipc: split up function tipc_msg_eval()
The function tipc_msg_eval() is in reality doing two related, but different tasks. First it tries to find a new destination for named messages, in case there was no first lookup, or if the first lookup failed. Second, it does what its name suggests, evaluating the validity of the message and its destination, and returning an appropriate error code depending on the result. This is confusing, and in this commit we choose to break it up into two functions. A new function, tipc_msg_lookup_dest(), first attempts to find a new destination, if the message is of the right type. If this lookup fails, or if the message should not be subject to a second lookup, the already existing tipc_msg_reverse() is called. This function performs prepares the message for rejection, if applicable. Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r--net/tipc/socket.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 1d98bfcda6f6..e14b2aedb212 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1739,7 +1739,7 @@ static int filter_rcv(struct sock *sk, struct sk_buff **skb)
1739 * @sk: socket 1739 * @sk: socket
1740 * @skb: message 1740 * @skb: message
1741 * 1741 *
1742 * Caller must hold socket lock, but not port lock. 1742 * Caller must hold socket lock
1743 * 1743 *
1744 * Returns 0 1744 * Returns 0
1745 */ 1745 */
@@ -1805,27 +1805,31 @@ int tipc_sk_rcv(struct net *net, struct sk_buff *skb)
1805 struct tipc_net *tn; 1805 struct tipc_net *tn;
1806 struct sock *sk; 1806 struct sock *sk;
1807 u32 dport = msg_destport(buf_msg(skb)); 1807 u32 dport = msg_destport(buf_msg(skb));
1808 int err; 1808 int err = -TIPC_ERR_NO_PORT;
1809 u32 dnode; 1809 u32 dnode;
1810 1810
1811 /* Validate destination and message */ 1811 /* Find destination */
1812 tsk = tipc_sk_lookup(net, dport); 1812 tsk = tipc_sk_lookup(net, dport);
1813 if (unlikely(!tsk)) { 1813 if (likely(tsk)) {
1814 err = tipc_msg_eval(net, skb, &dnode); 1814 sk = &tsk->sk;
1815 goto exit; 1815 spin_lock_bh(&sk->sk_lock.slock);
1816 } 1816 err = tipc_sk_enqueue_skb(sk, &skb);
1817 sk = &tsk->sk; 1817 spin_unlock_bh(&sk->sk_lock.slock);
1818 1818 sock_put(sk);
1819 spin_lock_bh(&sk->sk_lock.slock);
1820 err = tipc_sk_enqueue_skb(sk, &skb);
1821 spin_unlock_bh(&sk->sk_lock.slock);
1822 sock_put(sk);
1823exit:
1824 if (unlikely(skb)) {
1825 tn = net_generic(net, tipc_net_id);
1826 if (!err || tipc_msg_reverse(tn->own_addr, skb, &dnode, -err))
1827 tipc_link_xmit_skb(net, skb, dnode, 0);
1828 } 1819 }
1820 if (likely(!skb))
1821 return 0;
1822 if (tipc_msg_lookup_dest(net, skb, &dnode, &err))
1823 goto xmit;
1824 if (!err) {
1825 dnode = msg_destnode(buf_msg(skb));
1826 goto xmit;
1827 }
1828 tn = net_generic(net, tipc_net_id);
1829 if (!tipc_msg_reverse(tn->own_addr, skb, &dnode, -err))
1830 return -EHOSTUNREACH;
1831xmit:
1832 tipc_link_xmit_skb(net, skb, dnode, dport);
1829 return err ? -EHOSTUNREACH : 0; 1833 return err ? -EHOSTUNREACH : 0;
1830} 1834}
1831 1835