aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
authorYing Xue <ying.xue@windriver.com>2015-01-09 02:27:05 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-12 16:24:32 -0500
commitf2f9800d4955a96d92896841d8ba9b04201deaa1 (patch)
tree3b817800cfd8fcb2de6d5a3d7eb4fff972fba681 /net/tipc/socket.c
parentc93d3baa24095887005647984cff5de8c63d3611 (diff)
tipc: make tipc node table aware of net namespace
Global variables associated with node table are below: - node table list (node_htable) - node hash table list (tipc_node_list) - node table lock (node_list_lock) - node number counter (tipc_num_nodes) - node link number counter (tipc_num_links) To make node table support namespace, above global variables must be moved to tipc_net structure in order to keep secret for different namespaces. As a consequence, these variables are allocated and initialized when namespace is created, and deallocated when namespace is destroyed. After the change, functions associated with these variables have to utilize a namespace pointer to access them. So adding namespace pointer as a parameter of these functions is the major change made in the commit. Signed-off-by: Ying Xue <ying.xue@windriver.com> Tested-by: Tero Aho <Tero.Aho@coriant.com> Reviewed-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.c72
1 files changed, 43 insertions, 29 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index c58f66be7e18..68831453bc0e 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -257,7 +257,7 @@ static void tsk_rej_rx_queue(struct sock *sk)
257 257
258 while ((skb = __skb_dequeue(&sk->sk_receive_queue))) { 258 while ((skb = __skb_dequeue(&sk->sk_receive_queue))) {
259 if (tipc_msg_reverse(skb, &dnode, TIPC_ERR_NO_PORT)) 259 if (tipc_msg_reverse(skb, &dnode, TIPC_ERR_NO_PORT))
260 tipc_link_xmit_skb(skb, dnode, 0); 260 tipc_link_xmit_skb(sock_net(sk), skb, dnode, 0);
261 } 261 }
262} 262}
263 263
@@ -473,6 +473,7 @@ static void tipc_sk_callback(struct rcu_head *head)
473static int tipc_release(struct socket *sock) 473static int tipc_release(struct socket *sock)
474{ 474{
475 struct sock *sk = sock->sk; 475 struct sock *sk = sock->sk;
476 struct net *net = sock_net(sk);
476 struct tipc_sock *tsk; 477 struct tipc_sock *tsk;
477 struct sk_buff *skb; 478 struct sk_buff *skb;
478 u32 dnode, probing_state; 479 u32 dnode, probing_state;
@@ -503,10 +504,10 @@ static int tipc_release(struct socket *sock)
503 (sock->state == SS_CONNECTED)) { 504 (sock->state == SS_CONNECTED)) {
504 sock->state = SS_DISCONNECTING; 505 sock->state = SS_DISCONNECTING;
505 tsk->connected = 0; 506 tsk->connected = 0;
506 tipc_node_remove_conn(dnode, tsk->portid); 507 tipc_node_remove_conn(net, dnode, tsk->portid);
507 } 508 }
508 if (tipc_msg_reverse(skb, &dnode, TIPC_ERR_NO_PORT)) 509 if (tipc_msg_reverse(skb, &dnode, TIPC_ERR_NO_PORT))
509 tipc_link_xmit_skb(skb, dnode, 0); 510 tipc_link_xmit_skb(net, skb, dnode, 0);
510 } 511 }
511 } 512 }
512 513
@@ -521,8 +522,8 @@ static int tipc_release(struct socket *sock)
521 tsk_peer_port(tsk), 522 tsk_peer_port(tsk),
522 tsk->portid, TIPC_ERR_NO_PORT); 523 tsk->portid, TIPC_ERR_NO_PORT);
523 if (skb) 524 if (skb)
524 tipc_link_xmit_skb(skb, dnode, tsk->portid); 525 tipc_link_xmit_skb(net, skb, dnode, tsk->portid);
525 tipc_node_remove_conn(dnode, tsk->portid); 526 tipc_node_remove_conn(net, dnode, tsk->portid);
526 } 527 }
527 528
528 /* Discard any remaining (connection-based) messages in receive queue */ 529 /* Discard any remaining (connection-based) messages in receive queue */
@@ -725,6 +726,7 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,
725 struct msghdr *msg, size_t dsz, long timeo) 726 struct msghdr *msg, size_t dsz, long timeo)
726{ 727{
727 struct sock *sk = sock->sk; 728 struct sock *sk = sock->sk;
729 struct net *net = sock_net(sk);
728 struct tipc_msg *mhdr = &tipc_sk(sk)->phdr; 730 struct tipc_msg *mhdr = &tipc_sk(sk)->phdr;
729 struct sk_buff_head head; 731 struct sk_buff_head head;
730 uint mtu; 732 uint mtu;
@@ -747,7 +749,7 @@ new_mtu:
747 return rc; 749 return rc;
748 750
749 do { 751 do {
750 rc = tipc_bclink_xmit(&head); 752 rc = tipc_bclink_xmit(net, &head);
751 if (likely(rc >= 0)) { 753 if (likely(rc >= 0)) {
752 rc = dsz; 754 rc = dsz;
753 break; 755 break;
@@ -766,7 +768,7 @@ new_mtu:
766 768
767/* tipc_sk_mcast_rcv - Deliver multicast message to all destination sockets 769/* tipc_sk_mcast_rcv - Deliver multicast message to all destination sockets
768 */ 770 */
769void tipc_sk_mcast_rcv(struct sk_buff *buf) 771void tipc_sk_mcast_rcv(struct net *net, struct sk_buff *buf)
770{ 772{
771 struct tipc_msg *msg = buf_msg(buf); 773 struct tipc_msg *msg = buf_msg(buf);
772 struct tipc_port_list dports = {0, NULL, }; 774 struct tipc_port_list dports = {0, NULL, };
@@ -798,7 +800,7 @@ void tipc_sk_mcast_rcv(struct sk_buff *buf)
798 continue; 800 continue;
799 } 801 }
800 msg_set_destport(msg, item->ports[i]); 802 msg_set_destport(msg, item->ports[i]);
801 tipc_sk_rcv(b); 803 tipc_sk_rcv(net, b);
802 } 804 }
803 } 805 }
804 tipc_port_list_free(&dports); 806 tipc_port_list_free(&dports);
@@ -886,6 +888,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
886 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 888 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
887 struct sock *sk = sock->sk; 889 struct sock *sk = sock->sk;
888 struct tipc_sock *tsk = tipc_sk(sk); 890 struct tipc_sock *tsk = tipc_sk(sk);
891 struct net *net = sock_net(sk);
889 struct tipc_msg *mhdr = &tsk->phdr; 892 struct tipc_msg *mhdr = &tsk->phdr;
890 u32 dnode, dport; 893 u32 dnode, dport;
891 struct sk_buff_head head; 894 struct sk_buff_head head;
@@ -960,7 +963,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
960 } 963 }
961 964
962new_mtu: 965new_mtu:
963 mtu = tipc_node_get_mtu(dnode, tsk->portid); 966 mtu = tipc_node_get_mtu(net, dnode, tsk->portid);
964 __skb_queue_head_init(&head); 967 __skb_queue_head_init(&head);
965 rc = tipc_msg_build(mhdr, m, 0, dsz, mtu, &head); 968 rc = tipc_msg_build(mhdr, m, 0, dsz, mtu, &head);
966 if (rc < 0) 969 if (rc < 0)
@@ -969,7 +972,7 @@ new_mtu:
969 do { 972 do {
970 skb = skb_peek(&head); 973 skb = skb_peek(&head);
971 TIPC_SKB_CB(skb)->wakeup_pending = tsk->link_cong; 974 TIPC_SKB_CB(skb)->wakeup_pending = tsk->link_cong;
972 rc = tipc_link_xmit(&head, dnode, tsk->portid); 975 rc = tipc_link_xmit(net, &head, dnode, tsk->portid);
973 if (likely(rc >= 0)) { 976 if (likely(rc >= 0)) {
974 if (sock->state != SS_READY) 977 if (sock->state != SS_READY)
975 sock->state = SS_CONNECTING; 978 sock->state = SS_CONNECTING;
@@ -1038,6 +1041,7 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock,
1038 struct msghdr *m, size_t dsz) 1041 struct msghdr *m, size_t dsz)
1039{ 1042{
1040 struct sock *sk = sock->sk; 1043 struct sock *sk = sock->sk;
1044 struct net *net = sock_net(sk);
1041 struct tipc_sock *tsk = tipc_sk(sk); 1045 struct tipc_sock *tsk = tipc_sk(sk);
1042 struct tipc_msg *mhdr = &tsk->phdr; 1046 struct tipc_msg *mhdr = &tsk->phdr;
1043 struct sk_buff_head head; 1047 struct sk_buff_head head;
@@ -1081,7 +1085,7 @@ next:
1081 goto exit; 1085 goto exit;
1082 do { 1086 do {
1083 if (likely(!tsk_conn_cong(tsk))) { 1087 if (likely(!tsk_conn_cong(tsk))) {
1084 rc = tipc_link_xmit(&head, dnode, portid); 1088 rc = tipc_link_xmit(net, &head, dnode, portid);
1085 if (likely(!rc)) { 1089 if (likely(!rc)) {
1086 tsk->sent_unacked++; 1090 tsk->sent_unacked++;
1087 sent += send; 1091 sent += send;
@@ -1090,7 +1094,8 @@ next:
1090 goto next; 1094 goto next;
1091 } 1095 }
1092 if (rc == -EMSGSIZE) { 1096 if (rc == -EMSGSIZE) {
1093 tsk->max_pkt = tipc_node_get_mtu(dnode, portid); 1097 tsk->max_pkt = tipc_node_get_mtu(net, dnode,
1098 portid);
1094 goto next; 1099 goto next;
1095 } 1100 }
1096 if (rc != -ELINKCONG) 1101 if (rc != -ELINKCONG)
@@ -1132,6 +1137,7 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,
1132static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, 1137static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,
1133 u32 peer_node) 1138 u32 peer_node)
1134{ 1139{
1140 struct net *net = sock_net(&tsk->sk);
1135 struct tipc_msg *msg = &tsk->phdr; 1141 struct tipc_msg *msg = &tsk->phdr;
1136 1142
1137 msg_set_destnode(msg, peer_node); 1143 msg_set_destnode(msg, peer_node);
@@ -1145,8 +1151,8 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,
1145 tsk->connected = 1; 1151 tsk->connected = 1;
1146 if (!mod_timer(&tsk->timer, jiffies + tsk->probing_intv)) 1152 if (!mod_timer(&tsk->timer, jiffies + tsk->probing_intv))
1147 sock_hold(&tsk->sk); 1153 sock_hold(&tsk->sk);
1148 tipc_node_add_conn(peer_node, tsk->portid, peer_port); 1154 tipc_node_add_conn(net, peer_node, tsk->portid, peer_port);
1149 tsk->max_pkt = tipc_node_get_mtu(peer_node, tsk->portid); 1155 tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid);
1150} 1156}
1151 1157
1152/** 1158/**
@@ -1245,6 +1251,7 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
1245 1251
1246static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack) 1252static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack)
1247{ 1253{
1254 struct net *net = sock_net(&tsk->sk);
1248 struct sk_buff *skb = NULL; 1255 struct sk_buff *skb = NULL;
1249 struct tipc_msg *msg; 1256 struct tipc_msg *msg;
1250 u32 peer_port = tsk_peer_port(tsk); 1257 u32 peer_port = tsk_peer_port(tsk);
@@ -1258,7 +1265,7 @@ static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack)
1258 return; 1265 return;
1259 msg = buf_msg(skb); 1266 msg = buf_msg(skb);
1260 msg_set_msgcnt(msg, ack); 1267 msg_set_msgcnt(msg, ack);
1261 tipc_link_xmit_skb(skb, dnode, msg_link_selector(msg)); 1268 tipc_link_xmit_skb(net, skb, dnode, msg_link_selector(msg));
1262} 1269}
1263 1270
1264static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop) 1271static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop)
@@ -1551,6 +1558,7 @@ static void tipc_data_ready(struct sock *sk)
1551static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) 1558static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1552{ 1559{
1553 struct sock *sk = &tsk->sk; 1560 struct sock *sk = &tsk->sk;
1561 struct net *net = sock_net(sk);
1554 struct socket *sock = sk->sk_socket; 1562 struct socket *sock = sk->sk_socket;
1555 struct tipc_msg *msg = buf_msg(*buf); 1563 struct tipc_msg *msg = buf_msg(*buf);
1556 int retval = -TIPC_ERR_NO_PORT; 1564 int retval = -TIPC_ERR_NO_PORT;
@@ -1566,7 +1574,7 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1566 sock->state = SS_DISCONNECTING; 1574 sock->state = SS_DISCONNECTING;
1567 tsk->connected = 0; 1575 tsk->connected = 0;
1568 /* let timer expire on it's own */ 1576 /* let timer expire on it's own */
1569 tipc_node_remove_conn(tsk_peer_node(tsk), 1577 tipc_node_remove_conn(net, tsk_peer_node(tsk),
1570 tsk->portid); 1578 tsk->portid);
1571 } 1579 }
1572 retval = TIPC_OK; 1580 retval = TIPC_OK;
@@ -1737,7 +1745,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
1737 if ((rc < 0) && !tipc_msg_reverse(skb, &onode, -rc)) 1745 if ((rc < 0) && !tipc_msg_reverse(skb, &onode, -rc))
1738 return 0; 1746 return 0;
1739 1747
1740 tipc_link_xmit_skb(skb, onode, 0); 1748 tipc_link_xmit_skb(sock_net(sk), skb, onode, 0);
1741 1749
1742 return 0; 1750 return 0;
1743} 1751}
@@ -1748,7 +1756,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
1748 * Consumes buffer 1756 * Consumes buffer
1749 * Returns 0 if success, or errno: -EHOSTUNREACH 1757 * Returns 0 if success, or errno: -EHOSTUNREACH
1750 */ 1758 */
1751int tipc_sk_rcv(struct sk_buff *skb) 1759int tipc_sk_rcv(struct net *net, struct sk_buff *skb)
1752{ 1760{
1753 struct tipc_sock *tsk; 1761 struct tipc_sock *tsk;
1754 struct sock *sk; 1762 struct sock *sk;
@@ -1785,7 +1793,7 @@ exit:
1785 if ((rc < 0) && !tipc_msg_reverse(skb, &dnode, -rc)) 1793 if ((rc < 0) && !tipc_msg_reverse(skb, &dnode, -rc))
1786 return -EHOSTUNREACH; 1794 return -EHOSTUNREACH;
1787 1795
1788 tipc_link_xmit_skb(skb, dnode, 0); 1796 tipc_link_xmit_skb(net, skb, dnode, 0);
1789 return (rc < 0) ? -EHOSTUNREACH : 0; 1797 return (rc < 0) ? -EHOSTUNREACH : 0;
1790} 1798}
1791 1799
@@ -2042,6 +2050,7 @@ exit:
2042static int tipc_shutdown(struct socket *sock, int how) 2050static int tipc_shutdown(struct socket *sock, int how)
2043{ 2051{
2044 struct sock *sk = sock->sk; 2052 struct sock *sk = sock->sk;
2053 struct net *net = sock_net(sk);
2045 struct tipc_sock *tsk = tipc_sk(sk); 2054 struct tipc_sock *tsk = tipc_sk(sk);
2046 struct sk_buff *skb; 2055 struct sk_buff *skb;
2047 u32 dnode; 2056 u32 dnode;
@@ -2065,8 +2074,9 @@ restart:
2065 goto restart; 2074 goto restart;
2066 } 2075 }
2067 if (tipc_msg_reverse(skb, &dnode, TIPC_CONN_SHUTDOWN)) 2076 if (tipc_msg_reverse(skb, &dnode, TIPC_CONN_SHUTDOWN))
2068 tipc_link_xmit_skb(skb, dnode, tsk->portid); 2077 tipc_link_xmit_skb(net, skb, dnode,
2069 tipc_node_remove_conn(dnode, tsk->portid); 2078 tsk->portid);
2079 tipc_node_remove_conn(net, dnode, tsk->portid);
2070 } else { 2080 } else {
2071 dnode = tsk_peer_node(tsk); 2081 dnode = tsk_peer_node(tsk);
2072 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, 2082 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE,
@@ -2074,11 +2084,11 @@ restart:
2074 0, dnode, tipc_own_addr, 2084 0, dnode, tipc_own_addr,
2075 tsk_peer_port(tsk), 2085 tsk_peer_port(tsk),
2076 tsk->portid, TIPC_CONN_SHUTDOWN); 2086 tsk->portid, TIPC_CONN_SHUTDOWN);
2077 tipc_link_xmit_skb(skb, dnode, tsk->portid); 2087 tipc_link_xmit_skb(net, skb, dnode, tsk->portid);
2078 } 2088 }
2079 tsk->connected = 0; 2089 tsk->connected = 0;
2080 sock->state = SS_DISCONNECTING; 2090 sock->state = SS_DISCONNECTING;
2081 tipc_node_remove_conn(dnode, tsk->portid); 2091 tipc_node_remove_conn(net, dnode, tsk->portid);
2082 /* fall through */ 2092 /* fall through */
2083 2093
2084 case SS_DISCONNECTING: 2094 case SS_DISCONNECTING:
@@ -2130,7 +2140,7 @@ static void tipc_sk_timeout(unsigned long data)
2130 } 2140 }
2131 bh_unlock_sock(sk); 2141 bh_unlock_sock(sk);
2132 if (skb) 2142 if (skb)
2133 tipc_link_xmit_skb(skb, peer_node, tsk->portid); 2143 tipc_link_xmit_skb(sock_net(sk), skb, peer_node, tsk->portid);
2134exit: 2144exit:
2135 sock_put(sk); 2145 sock_put(sk);
2136} 2146}
@@ -2138,6 +2148,7 @@ exit:
2138static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, 2148static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
2139 struct tipc_name_seq const *seq) 2149 struct tipc_name_seq const *seq)
2140{ 2150{
2151 struct net *net = sock_net(&tsk->sk);
2141 struct publication *publ; 2152 struct publication *publ;
2142 u32 key; 2153 u32 key;
2143 2154
@@ -2147,7 +2158,7 @@ static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
2147 if (key == tsk->portid) 2158 if (key == tsk->portid)
2148 return -EADDRINUSE; 2159 return -EADDRINUSE;
2149 2160
2150 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, 2161 publ = tipc_nametbl_publish(net, seq->type, seq->lower, seq->upper,
2151 scope, tsk->portid, key); 2162 scope, tsk->portid, key);
2152 if (unlikely(!publ)) 2163 if (unlikely(!publ))
2153 return -EINVAL; 2164 return -EINVAL;
@@ -2161,6 +2172,7 @@ static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
2161static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, 2172static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope,
2162 struct tipc_name_seq const *seq) 2173 struct tipc_name_seq const *seq)
2163{ 2174{
2175 struct net *net = sock_net(&tsk->sk);
2164 struct publication *publ; 2176 struct publication *publ;
2165 struct publication *safe; 2177 struct publication *safe;
2166 int rc = -EINVAL; 2178 int rc = -EINVAL;
@@ -2175,12 +2187,12 @@ static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope,
2175 continue; 2187 continue;
2176 if (publ->upper != seq->upper) 2188 if (publ->upper != seq->upper)
2177 break; 2189 break;
2178 tipc_nametbl_withdraw(publ->type, publ->lower, 2190 tipc_nametbl_withdraw(net, publ->type, publ->lower,
2179 publ->ref, publ->key); 2191 publ->ref, publ->key);
2180 rc = 0; 2192 rc = 0;
2181 break; 2193 break;
2182 } 2194 }
2183 tipc_nametbl_withdraw(publ->type, publ->lower, 2195 tipc_nametbl_withdraw(net, publ->type, publ->lower,
2184 publ->ref, publ->key); 2196 publ->ref, publ->key);
2185 rc = 0; 2197 rc = 0;
2186 } 2198 }
@@ -2492,8 +2504,9 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
2492 return put_user(sizeof(value), ol); 2504 return put_user(sizeof(value), ol);
2493} 2505}
2494 2506
2495static int tipc_ioctl(struct socket *sk, unsigned int cmd, unsigned long arg) 2507static int tipc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2496{ 2508{
2509 struct sock *sk = sock->sk;
2497 struct tipc_sioc_ln_req lnr; 2510 struct tipc_sioc_ln_req lnr;
2498 void __user *argp = (void __user *)arg; 2511 void __user *argp = (void __user *)arg;
2499 2512
@@ -2501,7 +2514,8 @@ static int tipc_ioctl(struct socket *sk, unsigned int cmd, unsigned long arg)
2501 case SIOCGETLINKNAME: 2514 case SIOCGETLINKNAME:
2502 if (copy_from_user(&lnr, argp, sizeof(lnr))) 2515 if (copy_from_user(&lnr, argp, sizeof(lnr)))
2503 return -EFAULT; 2516 return -EFAULT;
2504 if (!tipc_node_get_linkname(lnr.bearer_id & 0xffff, lnr.peer, 2517 if (!tipc_node_get_linkname(sock_net(sk),
2518 lnr.bearer_id & 0xffff, lnr.peer,
2505 lnr.linkname, TIPC_MAX_LINK_NAME)) { 2519 lnr.linkname, TIPC_MAX_LINK_NAME)) {
2506 if (copy_to_user(argp, &lnr, sizeof(lnr))) 2520 if (copy_to_user(argp, &lnr, sizeof(lnr)))
2507 return -EFAULT; 2521 return -EFAULT;