aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-08-22 18:09:20 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-23 14:18:35 -0400
commit301bae56f21295a4ba71367818d80735687f11ac (patch)
treedd7368248aaf26d2476a54a345ede9f0db44eeb9
parent808d90f9c55943c2965d33b7156e559c59dd2db9 (diff)
tipc: merge struct tipc_port into struct tipc_sock
We complete the merging of the port and socket layer by aggregating the fields of struct tipc_port directly into struct tipc_sock, and moving the combined structure into socket.c. We also move all functions and macros that are not any longer exposed to the rest of the stack into socket.c, and rename them accordingly. Despite the size of this commit, there are no functional changes. We have only made such changes that are necessary due of the removal of struct tipc_port. 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>
-rw-r--r--net/tipc/socket.c373
-rw-r--r--net/tipc/socket.h74
2 files changed, 206 insertions, 241 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 6a699671245b..d416e83ce069 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -45,9 +45,57 @@
45#define SS_LISTENING -1 /* socket is listening */ 45#define SS_LISTENING -1 /* socket is listening */
46#define SS_READY -2 /* socket is connectionless */ 46#define SS_READY -2 /* socket is connectionless */
47 47
48#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ 48#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
49#define CONN_PROBING_INTERVAL 3600000 /* [ms] => 1 h */ 49#define CONN_PROBING_INTERVAL 3600000 /* [ms] => 1 h */
50#define TIPC_FWD_MSG 1 50#define TIPC_FWD_MSG 1
51#define TIPC_CONN_OK 0
52#define TIPC_CONN_PROBING 1
53
54/**
55 * struct tipc_sock - TIPC socket structure
56 * @sk: socket - interacts with 'port' and with user via the socket API
57 * @connected: non-zero if port is currently connected to a peer port
58 * @conn_type: TIPC type used when connection was established
59 * @conn_instance: TIPC instance used when connection was established
60 * @published: non-zero if port has one or more associated names
61 * @max_pkt: maximum packet size "hint" used when building messages sent by port
62 * @ref: unique reference to port in TIPC object registry
63 * @phdr: preformatted message header used when sending messages
64 * @port_list: adjacent ports in TIPC's global list of ports
65 * @publications: list of publications for port
66 * @pub_count: total # of publications port has made during its lifetime
67 * @probing_state:
68 * @probing_interval:
69 * @timer:
70 * @port: port - interacts with 'sk' and with the rest of the TIPC stack
71 * @peer_name: the peer of the connection, if any
72 * @conn_timeout: the time we can wait for an unresponded setup request
73 * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue
74 * @link_cong: non-zero if owner must sleep because of link congestion
75 * @sent_unacked: # messages sent by socket, and not yet acked by peer
76 * @rcv_unacked: # messages read by user, but not yet acked back to peer
77 */
78struct tipc_sock {
79 struct sock sk;
80 int connected;
81 u32 conn_type;
82 u32 conn_instance;
83 int published;
84 u32 max_pkt;
85 u32 ref;
86 struct tipc_msg phdr;
87 struct list_head sock_list;
88 struct list_head publications;
89 u32 pub_count;
90 u32 probing_state;
91 u32 probing_interval;
92 struct timer_list timer;
93 uint conn_timeout;
94 atomic_t dupl_rcvcnt;
95 bool link_cong;
96 uint sent_unacked;
97 uint rcv_unacked;
98};
51 99
52static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb); 100static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb);
53static void tipc_data_ready(struct sock *sk); 101static void tipc_data_ready(struct sock *sk);
@@ -56,9 +104,9 @@ static int tipc_release(struct socket *sock);
56static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); 104static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags);
57static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p); 105static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p);
58static void tipc_sk_timeout(unsigned long ref); 106static void tipc_sk_timeout(unsigned long ref);
59static int tipc_sk_publish(struct tipc_port *port, uint scope, 107static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
60 struct tipc_name_seq const *seq); 108 struct tipc_name_seq const *seq);
61static int tipc_sk_withdraw(struct tipc_port *port, uint scope, 109static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope,
62 struct tipc_name_seq const *seq); 110 struct tipc_name_seq const *seq);
63static u32 tipc_sk_ref_acquire(struct tipc_sock *tsk); 111static u32 tipc_sk_ref_acquire(struct tipc_sock *tsk);
64static void tipc_sk_ref_discard(u32 ref); 112static void tipc_sk_ref_discard(u32 ref);
@@ -118,49 +166,59 @@ static struct proto tipc_proto_kern;
118 * - port reference 166 * - port reference
119 */ 167 */
120 168
121static u32 tsk_peer_node(struct tipc_port *p_ptr) 169static u32 tsk_peer_node(struct tipc_sock *tsk)
122{ 170{
123 return msg_destnode(&p_ptr->phdr); 171 return msg_destnode(&tsk->phdr);
124} 172}
125 173
126static u32 tsk_peer_port(struct tipc_port *p_ptr) 174static u32 tsk_peer_port(struct tipc_sock *tsk)
127{ 175{
128 return msg_destport(&p_ptr->phdr); 176 return msg_destport(&tsk->phdr);
129} 177}
130 178
131static bool tsk_unreliable(struct tipc_port *port) 179static bool tsk_unreliable(struct tipc_sock *tsk)
132{ 180{
133 return msg_src_droppable(&port->phdr) != 0; 181 return msg_src_droppable(&tsk->phdr) != 0;
134} 182}
135 183
136static void tsk_set_unreliable(struct tipc_port *port, bool unreliable) 184static void tsk_set_unreliable(struct tipc_sock *tsk, bool unreliable)
137{ 185{
138 msg_set_src_droppable(&port->phdr, unreliable ? 1 : 0); 186 msg_set_src_droppable(&tsk->phdr, unreliable ? 1 : 0);
139} 187}
140 188
141static bool tsk_unreturnable(struct tipc_port *port) 189static bool tsk_unreturnable(struct tipc_sock *tsk)
142{ 190{
143 return msg_dest_droppable(&port->phdr) != 0; 191 return msg_dest_droppable(&tsk->phdr) != 0;
144} 192}
145 193
146static void tsk_set_unreturnable(struct tipc_port *port, bool unreturnable) 194static void tsk_set_unreturnable(struct tipc_sock *tsk, bool unreturnable)
147{ 195{
148 msg_set_dest_droppable(&port->phdr, unreturnable ? 1 : 0); 196 msg_set_dest_droppable(&tsk->phdr, unreturnable ? 1 : 0);
149} 197}
150 198
151static int tsk_importance(struct tipc_port *port) 199static int tsk_importance(struct tipc_sock *tsk)
152{ 200{
153 return msg_importance(&port->phdr); 201 return msg_importance(&tsk->phdr);
154} 202}
155 203
156static int tsk_set_importance(struct tipc_port *port, int imp) 204static int tsk_set_importance(struct tipc_sock *tsk, int imp)
157{ 205{
158 if (imp > TIPC_CRITICAL_IMPORTANCE) 206 if (imp > TIPC_CRITICAL_IMPORTANCE)
159 return -EINVAL; 207 return -EINVAL;
160 msg_set_importance(&port->phdr, (u32)imp); 208 msg_set_importance(&tsk->phdr, (u32)imp);
161 return 0; 209 return 0;
162} 210}
163 211
212static struct tipc_sock *tipc_sk(const struct sock *sk)
213{
214 return container_of(sk, struct tipc_sock, sk);
215}
216
217static int tsk_conn_cong(struct tipc_sock *tsk)
218{
219 return tsk->sent_unacked >= TIPC_FLOWCTRL_WIN;
220}
221
164/** 222/**
165 * tsk_advance_rx_queue - discard first buffer in socket receive queue 223 * tsk_advance_rx_queue - discard first buffer in socket receive queue
166 * 224 *
@@ -194,18 +252,18 @@ static void tsk_rej_rx_queue(struct sock *sk)
194 */ 252 */
195static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) 253static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
196{ 254{
197 u32 peer_port = tsk_peer_port(&tsk->port); 255 u32 peer_port = tsk_peer_port(tsk);
198 u32 orig_node; 256 u32 orig_node;
199 u32 peer_node; 257 u32 peer_node;
200 258
201 if (unlikely(!tsk->port.connected)) 259 if (unlikely(!tsk->connected))
202 return false; 260 return false;
203 261
204 if (unlikely(msg_origport(msg) != peer_port)) 262 if (unlikely(msg_origport(msg) != peer_port))
205 return false; 263 return false;
206 264
207 orig_node = msg_orignode(msg); 265 orig_node = msg_orignode(msg);
208 peer_node = tsk_peer_node(&tsk->port); 266 peer_node = tsk_peer_node(tsk);
209 267
210 if (likely(orig_node == peer_node)) 268 if (likely(orig_node == peer_node))
211 return true; 269 return true;
@@ -238,7 +296,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
238 socket_state state; 296 socket_state state;
239 struct sock *sk; 297 struct sock *sk;
240 struct tipc_sock *tsk; 298 struct tipc_sock *tsk;
241 struct tipc_port *port;
242 struct tipc_msg *msg; 299 struct tipc_msg *msg;
243 u32 ref; 300 u32 ref;
244 301
@@ -274,17 +331,15 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
274 return -ENOMEM; 331 return -ENOMEM;
275 332
276 tsk = tipc_sk(sk); 333 tsk = tipc_sk(sk);
277 port = &tsk->port;
278 ref = tipc_sk_ref_acquire(tsk); 334 ref = tipc_sk_ref_acquire(tsk);
279 if (!ref) { 335 if (!ref) {
280 pr_warn("Socket create failed; reference table exhausted\n"); 336 pr_warn("Socket create failed; reference table exhausted\n");
281 return -ENOMEM; 337 return -ENOMEM;
282 } 338 }
283 port->max_pkt = MAX_PKT_DEFAULT; 339 tsk->max_pkt = MAX_PKT_DEFAULT;
284 port->ref = ref; 340 tsk->ref = ref;
285 INIT_LIST_HEAD(&port->publications); 341 INIT_LIST_HEAD(&tsk->publications);
286 342 msg = &tsk->phdr;
287 msg = &port->phdr;
288 tipc_msg_init(msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, 343 tipc_msg_init(msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG,
289 NAMED_H_SIZE, 0); 344 NAMED_H_SIZE, 0);
290 msg_set_origport(msg, ref); 345 msg_set_origport(msg, ref);
@@ -293,7 +348,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
293 sock->ops = ops; 348 sock->ops = ops;
294 sock->state = state; 349 sock->state = state;
295 sock_init_data(sock, sk); 350 sock_init_data(sock, sk);
296 k_init_timer(&port->timer, (Handler)tipc_sk_timeout, ref); 351 k_init_timer(&tsk->timer, (Handler)tipc_sk_timeout, ref);
297 sk->sk_backlog_rcv = tipc_backlog_rcv; 352 sk->sk_backlog_rcv = tipc_backlog_rcv;
298 sk->sk_rcvbuf = sysctl_tipc_rmem[1]; 353 sk->sk_rcvbuf = sysctl_tipc_rmem[1];
299 sk->sk_data_ready = tipc_data_ready; 354 sk->sk_data_ready = tipc_data_ready;
@@ -303,9 +358,9 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
303 atomic_set(&tsk->dupl_rcvcnt, 0); 358 atomic_set(&tsk->dupl_rcvcnt, 0);
304 359
305 if (sock->state == SS_READY) { 360 if (sock->state == SS_READY) {
306 tsk_set_unreturnable(port, true); 361 tsk_set_unreturnable(tsk, true);
307 if (sock->type == SOCK_DGRAM) 362 if (sock->type == SOCK_DGRAM)
308 tsk_set_unreliable(port, true); 363 tsk_set_unreliable(tsk, true);
309 } 364 }
310 return 0; 365 return 0;
311} 366}
@@ -399,7 +454,6 @@ static int tipc_release(struct socket *sock)
399{ 454{
400 struct sock *sk = sock->sk; 455 struct sock *sk = sock->sk;
401 struct tipc_sock *tsk; 456 struct tipc_sock *tsk;
402 struct tipc_port *port;
403 struct sk_buff *buf; 457 struct sk_buff *buf;
404 u32 dnode; 458 u32 dnode;
405 459
@@ -411,14 +465,13 @@ static int tipc_release(struct socket *sock)
411 return 0; 465 return 0;
412 466
413 tsk = tipc_sk(sk); 467 tsk = tipc_sk(sk);
414 port = &tsk->port;
415 lock_sock(sk); 468 lock_sock(sk);
416 469
417 /* 470 /*
418 * Reject all unreceived messages, except on an active connection 471 * Reject all unreceived messages, except on an active connection
419 * (which disconnects locally & sends a 'FIN+' to peer) 472 * (which disconnects locally & sends a 'FIN+' to peer)
420 */ 473 */
421 dnode = tsk_peer_node(port); 474 dnode = tsk_peer_node(tsk);
422 while (sock->state != SS_DISCONNECTING) { 475 while (sock->state != SS_DISCONNECTING) {
423 buf = __skb_dequeue(&sk->sk_receive_queue); 476 buf = __skb_dequeue(&sk->sk_receive_queue);
424 if (buf == NULL) 477 if (buf == NULL)
@@ -429,27 +482,27 @@ static int tipc_release(struct socket *sock)
429 if ((sock->state == SS_CONNECTING) || 482 if ((sock->state == SS_CONNECTING) ||
430 (sock->state == SS_CONNECTED)) { 483 (sock->state == SS_CONNECTED)) {
431 sock->state = SS_DISCONNECTING; 484 sock->state = SS_DISCONNECTING;
432 port->connected = 0; 485 tsk->connected = 0;
433 tipc_node_remove_conn(dnode, port->ref); 486 tipc_node_remove_conn(dnode, tsk->ref);
434 } 487 }
435 if (tipc_msg_reverse(buf, &dnode, TIPC_ERR_NO_PORT)) 488 if (tipc_msg_reverse(buf, &dnode, TIPC_ERR_NO_PORT))
436 tipc_link_xmit(buf, dnode, 0); 489 tipc_link_xmit(buf, dnode, 0);
437 } 490 }
438 } 491 }
439 492
440 tipc_sk_withdraw(port, 0, NULL); 493 tipc_sk_withdraw(tsk, 0, NULL);
441 tipc_sk_ref_discard(port->ref); 494 tipc_sk_ref_discard(tsk->ref);
442 k_cancel_timer(&port->timer); 495 k_cancel_timer(&tsk->timer);
443 if (port->connected) { 496 if (tsk->connected) {
444 buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, 497 buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
445 SHORT_H_SIZE, 0, dnode, tipc_own_addr, 498 SHORT_H_SIZE, 0, dnode, tipc_own_addr,
446 tsk_peer_port(port), 499 tsk_peer_port(tsk),
447 port->ref, TIPC_ERR_NO_PORT); 500 tsk->ref, TIPC_ERR_NO_PORT);
448 if (buf) 501 if (buf)
449 tipc_link_xmit(buf, dnode, port->ref); 502 tipc_link_xmit(buf, dnode, tsk->ref);
450 tipc_node_remove_conn(dnode, port->ref); 503 tipc_node_remove_conn(dnode, tsk->ref);
451 } 504 }
452 k_term_timer(&port->timer); 505 k_term_timer(&tsk->timer);
453 506
454 /* Discard any remaining (connection-based) messages in receive queue */ 507 /* Discard any remaining (connection-based) messages in receive queue */
455 __skb_queue_purge(&sk->sk_receive_queue); 508 __skb_queue_purge(&sk->sk_receive_queue);
@@ -488,7 +541,7 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
488 541
489 lock_sock(sk); 542 lock_sock(sk);
490 if (unlikely(!uaddr_len)) { 543 if (unlikely(!uaddr_len)) {
491 res = tipc_sk_withdraw(&tsk->port, 0, NULL); 544 res = tipc_sk_withdraw(tsk, 0, NULL);
492 goto exit; 545 goto exit;
493 } 546 }
494 547
@@ -516,8 +569,8 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
516 } 569 }
517 570
518 res = (addr->scope > 0) ? 571 res = (addr->scope > 0) ?
519 tipc_sk_publish(&tsk->port, addr->scope, &addr->addr.nameseq) : 572 tipc_sk_publish(tsk, addr->scope, &addr->addr.nameseq) :
520 tipc_sk_withdraw(&tsk->port, -addr->scope, &addr->addr.nameseq); 573 tipc_sk_withdraw(tsk, -addr->scope, &addr->addr.nameseq);
521exit: 574exit:
522 release_sock(sk); 575 release_sock(sk);
523 return res; 576 return res;
@@ -547,10 +600,10 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
547 if ((sock->state != SS_CONNECTED) && 600 if ((sock->state != SS_CONNECTED) &&
548 ((peer != 2) || (sock->state != SS_DISCONNECTING))) 601 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
549 return -ENOTCONN; 602 return -ENOTCONN;
550 addr->addr.id.ref = tsk_peer_port(&tsk->port); 603 addr->addr.id.ref = tsk_peer_port(tsk);
551 addr->addr.id.node = tsk_peer_node(&tsk->port); 604 addr->addr.id.node = tsk_peer_node(tsk);
552 } else { 605 } else {
553 addr->addr.id.ref = tsk->port.ref; 606 addr->addr.id.ref = tsk->ref;
554 addr->addr.id.node = tipc_own_addr; 607 addr->addr.id.node = tipc_own_addr;
555 } 608 }
556 609
@@ -619,7 +672,7 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
619 break; 672 break;
620 case SS_READY: 673 case SS_READY:
621 case SS_CONNECTED: 674 case SS_CONNECTED:
622 if (!tsk->link_cong && !tipc_sk_conn_cong(tsk)) 675 if (!tsk->link_cong && !tsk_conn_cong(tsk))
623 mask |= POLLOUT; 676 mask |= POLLOUT;
624 /* fall thru' */ 677 /* fall thru' */
625 case SS_CONNECTING: 678 case SS_CONNECTING:
@@ -650,7 +703,7 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,
650 struct iovec *iov, size_t dsz, long timeo) 703 struct iovec *iov, size_t dsz, long timeo)
651{ 704{
652 struct sock *sk = sock->sk; 705 struct sock *sk = sock->sk;
653 struct tipc_msg *mhdr = &tipc_sk(sk)->port.phdr; 706 struct tipc_msg *mhdr = &tipc_sk(sk)->phdr;
654 struct sk_buff *buf; 707 struct sk_buff *buf;
655 uint mtu; 708 uint mtu;
656 int rc; 709 int rc;
@@ -740,17 +793,16 @@ static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode,
740 struct sk_buff *buf) 793 struct sk_buff *buf)
741{ 794{
742 struct tipc_msg *msg = buf_msg(buf); 795 struct tipc_msg *msg = buf_msg(buf);
743 struct tipc_port *port = &tsk->port;
744 int conn_cong; 796 int conn_cong;
745 797
746 /* Ignore if connection cannot be validated: */ 798 /* Ignore if connection cannot be validated: */
747 if (!tsk_peer_msg(tsk, msg)) 799 if (!tsk_peer_msg(tsk, msg))
748 goto exit; 800 goto exit;
749 801
750 port->probing_state = TIPC_CONN_OK; 802 tsk->probing_state = TIPC_CONN_OK;
751 803
752 if (msg_type(msg) == CONN_ACK) { 804 if (msg_type(msg) == CONN_ACK) {
753 conn_cong = tipc_sk_conn_cong(tsk); 805 conn_cong = tsk_conn_cong(tsk);
754 tsk->sent_unacked -= msg_msgcnt(msg); 806 tsk->sent_unacked -= msg_msgcnt(msg);
755 if (conn_cong) 807 if (conn_cong)
756 tsk->sk.sk_write_space(&tsk->sk); 808 tsk->sk.sk_write_space(&tsk->sk);
@@ -844,8 +896,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
844 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 896 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
845 struct sock *sk = sock->sk; 897 struct sock *sk = sock->sk;
846 struct tipc_sock *tsk = tipc_sk(sk); 898 struct tipc_sock *tsk = tipc_sk(sk);
847 struct tipc_port *port = &tsk->port; 899 struct tipc_msg *mhdr = &tsk->phdr;
848 struct tipc_msg *mhdr = &port->phdr;
849 struct iovec *iov = m->msg_iov; 900 struct iovec *iov = m->msg_iov;
850 u32 dnode, dport; 901 u32 dnode, dport;
851 struct sk_buff *buf; 902 struct sk_buff *buf;
@@ -876,13 +927,13 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
876 rc = -EISCONN; 927 rc = -EISCONN;
877 goto exit; 928 goto exit;
878 } 929 }
879 if (tsk->port.published) { 930 if (tsk->published) {
880 rc = -EOPNOTSUPP; 931 rc = -EOPNOTSUPP;
881 goto exit; 932 goto exit;
882 } 933 }
883 if (dest->addrtype == TIPC_ADDR_NAME) { 934 if (dest->addrtype == TIPC_ADDR_NAME) {
884 tsk->port.conn_type = dest->addr.name.name.type; 935 tsk->conn_type = dest->addr.name.name.type;
885 tsk->port.conn_instance = dest->addr.name.name.instance; 936 tsk->conn_instance = dest->addr.name.name.instance;
886 } 937 }
887 } 938 }
888 rc = dest_name_check(dest, m); 939 rc = dest_name_check(dest, m);
@@ -922,14 +973,14 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
922 } 973 }
923 974
924new_mtu: 975new_mtu:
925 mtu = tipc_node_get_mtu(dnode, tsk->port.ref); 976 mtu = tipc_node_get_mtu(dnode, tsk->ref);
926 rc = tipc_msg_build(mhdr, iov, 0, dsz, mtu, &buf); 977 rc = tipc_msg_build(mhdr, iov, 0, dsz, mtu, &buf);
927 if (rc < 0) 978 if (rc < 0)
928 goto exit; 979 goto exit;
929 980
930 do { 981 do {
931 TIPC_SKB_CB(buf)->wakeup_pending = tsk->link_cong; 982 TIPC_SKB_CB(buf)->wakeup_pending = tsk->link_cong;
932 rc = tipc_link_xmit(buf, dnode, tsk->port.ref); 983 rc = tipc_link_xmit(buf, dnode, tsk->ref);
933 if (likely(rc >= 0)) { 984 if (likely(rc >= 0)) {
934 if (sock->state != SS_READY) 985 if (sock->state != SS_READY)
935 sock->state = SS_CONNECTING; 986 sock->state = SS_CONNECTING;
@@ -975,8 +1026,8 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
975 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 1026 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
976 done = sk_wait_event(sk, timeo_p, 1027 done = sk_wait_event(sk, timeo_p,
977 (!tsk->link_cong && 1028 (!tsk->link_cong &&
978 !tipc_sk_conn_cong(tsk)) || 1029 !tsk_conn_cong(tsk)) ||
979 !tsk->port.connected); 1030 !tsk->connected);
980 finish_wait(sk_sleep(sk), &wait); 1031 finish_wait(sk_sleep(sk), &wait);
981 } while (!done); 1032 } while (!done);
982 return 0; 1033 return 0;
@@ -999,11 +1050,10 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock,
999{ 1050{
1000 struct sock *sk = sock->sk; 1051 struct sock *sk = sock->sk;
1001 struct tipc_sock *tsk = tipc_sk(sk); 1052 struct tipc_sock *tsk = tipc_sk(sk);
1002 struct tipc_port *port = &tsk->port; 1053 struct tipc_msg *mhdr = &tsk->phdr;
1003 struct tipc_msg *mhdr = &port->phdr;
1004 struct sk_buff *buf; 1054 struct sk_buff *buf;
1005 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 1055 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
1006 u32 ref = port->ref; 1056 u32 ref = tsk->ref;
1007 int rc = -EINVAL; 1057 int rc = -EINVAL;
1008 long timeo; 1058 long timeo;
1009 u32 dnode; 1059 u32 dnode;
@@ -1031,16 +1081,16 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock,
1031 } 1081 }
1032 1082
1033 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); 1083 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
1034 dnode = tsk_peer_node(port); 1084 dnode = tsk_peer_node(tsk);
1035 1085
1036next: 1086next:
1037 mtu = port->max_pkt; 1087 mtu = tsk->max_pkt;
1038 send = min_t(uint, dsz - sent, TIPC_MAX_USER_MSG_SIZE); 1088 send = min_t(uint, dsz - sent, TIPC_MAX_USER_MSG_SIZE);
1039 rc = tipc_msg_build(mhdr, m->msg_iov, sent, send, mtu, &buf); 1089 rc = tipc_msg_build(mhdr, m->msg_iov, sent, send, mtu, &buf);
1040 if (unlikely(rc < 0)) 1090 if (unlikely(rc < 0))
1041 goto exit; 1091 goto exit;
1042 do { 1092 do {
1043 if (likely(!tipc_sk_conn_cong(tsk))) { 1093 if (likely(!tsk_conn_cong(tsk))) {
1044 rc = tipc_link_xmit(buf, dnode, ref); 1094 rc = tipc_link_xmit(buf, dnode, ref);
1045 if (likely(!rc)) { 1095 if (likely(!rc)) {
1046 tsk->sent_unacked++; 1096 tsk->sent_unacked++;
@@ -1050,7 +1100,7 @@ next:
1050 goto next; 1100 goto next;
1051 } 1101 }
1052 if (rc == -EMSGSIZE) { 1102 if (rc == -EMSGSIZE) {
1053 port->max_pkt = tipc_node_get_mtu(dnode, ref); 1103 tsk->max_pkt = tipc_node_get_mtu(dnode, ref);
1054 goto next; 1104 goto next;
1055 } 1105 }
1056 if (rc != -ELINKCONG) 1106 if (rc != -ELINKCONG)
@@ -1089,10 +1139,10 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,
1089 1139
1090/* tipc_sk_finish_conn - complete the setup of a connection 1140/* tipc_sk_finish_conn - complete the setup of a connection
1091 */ 1141 */
1092static void tipc_sk_finish_conn(struct tipc_port *port, u32 peer_port, 1142static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,
1093 u32 peer_node) 1143 u32 peer_node)
1094{ 1144{
1095 struct tipc_msg *msg = &port->phdr; 1145 struct tipc_msg *msg = &tsk->phdr;
1096 1146
1097 msg_set_destnode(msg, peer_node); 1147 msg_set_destnode(msg, peer_node);
1098 msg_set_destport(msg, peer_port); 1148 msg_set_destport(msg, peer_port);
@@ -1100,12 +1150,12 @@ static void tipc_sk_finish_conn(struct tipc_port *port, u32 peer_port,
1100 msg_set_lookup_scope(msg, 0); 1150 msg_set_lookup_scope(msg, 0);
1101 msg_set_hdr_sz(msg, SHORT_H_SIZE); 1151 msg_set_hdr_sz(msg, SHORT_H_SIZE);
1102 1152
1103 port->probing_interval = CONN_PROBING_INTERVAL; 1153 tsk->probing_interval = CONN_PROBING_INTERVAL;
1104 port->probing_state = TIPC_CONN_OK; 1154 tsk->probing_state = TIPC_CONN_OK;
1105 port->connected = 1; 1155 tsk->connected = 1;
1106 k_start_timer(&port->timer, port->probing_interval); 1156 k_start_timer(&tsk->timer, tsk->probing_interval);
1107 tipc_node_add_conn(peer_node, port->ref, peer_port); 1157 tipc_node_add_conn(peer_node, tsk->ref, peer_port);
1108 port->max_pkt = tipc_node_get_mtu(peer_node, port->ref); 1158 tsk->max_pkt = tipc_node_get_mtu(peer_node, tsk->ref);
1109} 1159}
1110 1160
1111/** 1161/**
@@ -1132,17 +1182,17 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
1132} 1182}
1133 1183
1134/** 1184/**
1135 * anc_data_recv - optionally capture ancillary data for received message 1185 * tipc_sk_anc_data_recv - optionally capture ancillary data for received message
1136 * @m: descriptor for message info 1186 * @m: descriptor for message info
1137 * @msg: received message header 1187 * @msg: received message header
1138 * @tport: TIPC port associated with message 1188 * @tsk: TIPC port associated with message
1139 * 1189 *
1140 * Note: Ancillary data is not captured if not requested by receiver. 1190 * Note: Ancillary data is not captured if not requested by receiver.
1141 * 1191 *
1142 * Returns 0 if successful, otherwise errno 1192 * Returns 0 if successful, otherwise errno
1143 */ 1193 */
1144static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, 1194static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
1145 struct tipc_port *tport) 1195 struct tipc_sock *tsk)
1146{ 1196{
1147 u32 anc_data[3]; 1197 u32 anc_data[3];
1148 u32 err; 1198 u32 err;
@@ -1185,10 +1235,10 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
1185 anc_data[2] = msg_nameupper(msg); 1235 anc_data[2] = msg_nameupper(msg);
1186 break; 1236 break;
1187 case TIPC_CONN_MSG: 1237 case TIPC_CONN_MSG:
1188 has_name = (tport->conn_type != 0); 1238 has_name = (tsk->conn_type != 0);
1189 anc_data[0] = tport->conn_type; 1239 anc_data[0] = tsk->conn_type;
1190 anc_data[1] = tport->conn_instance; 1240 anc_data[1] = tsk->conn_instance;
1191 anc_data[2] = tport->conn_instance; 1241 anc_data[2] = tsk->conn_instance;
1192 break; 1242 break;
1193 default: 1243 default:
1194 has_name = 0; 1244 has_name = 0;
@@ -1202,17 +1252,17 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
1202 return 0; 1252 return 0;
1203} 1253}
1204 1254
1205static void tipc_sk_send_ack(struct tipc_port *port, uint ack) 1255static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack)
1206{ 1256{
1207 struct sk_buff *buf = NULL; 1257 struct sk_buff *buf = NULL;
1208 struct tipc_msg *msg; 1258 struct tipc_msg *msg;
1209 u32 peer_port = tsk_peer_port(port); 1259 u32 peer_port = tsk_peer_port(tsk);
1210 u32 dnode = tsk_peer_node(port); 1260 u32 dnode = tsk_peer_node(tsk);
1211 1261
1212 if (!port->connected) 1262 if (!tsk->connected)
1213 return; 1263 return;
1214 buf = tipc_msg_create(CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, dnode, 1264 buf = tipc_msg_create(CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, dnode,
1215 tipc_own_addr, peer_port, port->ref, TIPC_OK); 1265 tipc_own_addr, peer_port, tsk->ref, TIPC_OK);
1216 if (!buf) 1266 if (!buf)
1217 return; 1267 return;
1218 msg = buf_msg(buf); 1268 msg = buf_msg(buf);
@@ -1270,7 +1320,6 @@ static int tipc_recvmsg(struct kiocb *iocb, struct socket *sock,
1270{ 1320{
1271 struct sock *sk = sock->sk; 1321 struct sock *sk = sock->sk;
1272 struct tipc_sock *tsk = tipc_sk(sk); 1322 struct tipc_sock *tsk = tipc_sk(sk);
1273 struct tipc_port *port = &tsk->port;
1274 struct sk_buff *buf; 1323 struct sk_buff *buf;
1275 struct tipc_msg *msg; 1324 struct tipc_msg *msg;
1276 long timeo; 1325 long timeo;
@@ -1313,7 +1362,7 @@ restart:
1313 set_orig_addr(m, msg); 1362 set_orig_addr(m, msg);
1314 1363
1315 /* Capture ancillary data (optional) */ 1364 /* Capture ancillary data (optional) */
1316 res = anc_data_recv(m, msg, port); 1365 res = tipc_sk_anc_data_recv(m, msg, tsk);
1317 if (res) 1366 if (res)
1318 goto exit; 1367 goto exit;
1319 1368
@@ -1340,7 +1389,7 @@ restart:
1340 if (likely(!(flags & MSG_PEEK))) { 1389 if (likely(!(flags & MSG_PEEK))) {
1341 if ((sock->state != SS_READY) && 1390 if ((sock->state != SS_READY) &&
1342 (++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) { 1391 (++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) {
1343 tipc_sk_send_ack(port, tsk->rcv_unacked); 1392 tipc_sk_send_ack(tsk, tsk->rcv_unacked);
1344 tsk->rcv_unacked = 0; 1393 tsk->rcv_unacked = 0;
1345 } 1394 }
1346 tsk_advance_rx_queue(sk); 1395 tsk_advance_rx_queue(sk);
@@ -1367,7 +1416,6 @@ static int tipc_recv_stream(struct kiocb *iocb, struct socket *sock,
1367{ 1416{
1368 struct sock *sk = sock->sk; 1417 struct sock *sk = sock->sk;
1369 struct tipc_sock *tsk = tipc_sk(sk); 1418 struct tipc_sock *tsk = tipc_sk(sk);
1370 struct tipc_port *port = &tsk->port;
1371 struct sk_buff *buf; 1419 struct sk_buff *buf;
1372 struct tipc_msg *msg; 1420 struct tipc_msg *msg;
1373 long timeo; 1421 long timeo;
@@ -1412,7 +1460,7 @@ restart:
1412 /* Optionally capture sender's address & ancillary data of first msg */ 1460 /* Optionally capture sender's address & ancillary data of first msg */
1413 if (sz_copied == 0) { 1461 if (sz_copied == 0) {
1414 set_orig_addr(m, msg); 1462 set_orig_addr(m, msg);
1415 res = anc_data_recv(m, msg, port); 1463 res = tipc_sk_anc_data_recv(m, msg, tsk);
1416 if (res) 1464 if (res)
1417 goto exit; 1465 goto exit;
1418 } 1466 }
@@ -1451,7 +1499,7 @@ restart:
1451 /* Consume received message (optional) */ 1499 /* Consume received message (optional) */
1452 if (likely(!(flags & MSG_PEEK))) { 1500 if (likely(!(flags & MSG_PEEK))) {
1453 if (unlikely(++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) { 1501 if (unlikely(++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) {
1454 tipc_sk_send_ack(port, tsk->rcv_unacked); 1502 tipc_sk_send_ack(tsk, tsk->rcv_unacked);
1455 tsk->rcv_unacked = 0; 1503 tsk->rcv_unacked = 0;
1456 } 1504 }
1457 tsk_advance_rx_queue(sk); 1505 tsk_advance_rx_queue(sk);
@@ -1513,10 +1561,8 @@ static void tipc_data_ready(struct sock *sk)
1513static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) 1561static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1514{ 1562{
1515 struct sock *sk = &tsk->sk; 1563 struct sock *sk = &tsk->sk;
1516 struct tipc_port *port = &tsk->port;
1517 struct socket *sock = sk->sk_socket; 1564 struct socket *sock = sk->sk_socket;
1518 struct tipc_msg *msg = buf_msg(*buf); 1565 struct tipc_msg *msg = buf_msg(*buf);
1519
1520 int retval = -TIPC_ERR_NO_PORT; 1566 int retval = -TIPC_ERR_NO_PORT;
1521 1567
1522 if (msg_mcast(msg)) 1568 if (msg_mcast(msg))
@@ -1528,10 +1574,10 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1528 if (tsk_peer_msg(tsk, msg)) { 1574 if (tsk_peer_msg(tsk, msg)) {
1529 if (unlikely(msg_errcode(msg))) { 1575 if (unlikely(msg_errcode(msg))) {
1530 sock->state = SS_DISCONNECTING; 1576 sock->state = SS_DISCONNECTING;
1531 port->connected = 0; 1577 tsk->connected = 0;
1532 /* let timer expire on it's own */ 1578 /* let timer expire on it's own */
1533 tipc_node_remove_conn(tsk_peer_node(port), 1579 tipc_node_remove_conn(tsk_peer_node(tsk),
1534 port->ref); 1580 tsk->ref);
1535 } 1581 }
1536 retval = TIPC_OK; 1582 retval = TIPC_OK;
1537 } 1583 }
@@ -1556,8 +1602,8 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1556 break; 1602 break;
1557 } 1603 }
1558 1604
1559 tipc_sk_finish_conn(port, msg_origport(msg), msg_orignode(msg)); 1605 tipc_sk_finish_conn(tsk, msg_origport(msg), msg_orignode(msg));
1560 msg_set_importance(&port->phdr, msg_importance(msg)); 1606 msg_set_importance(&tsk->phdr, msg_importance(msg));
1561 sock->state = SS_CONNECTED; 1607 sock->state = SS_CONNECTED;
1562 1608
1563 /* If an incoming message is an 'ACK-', it should be 1609 /* If an incoming message is an 'ACK-', it should be
@@ -1715,7 +1761,6 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *buf)
1715int tipc_sk_rcv(struct sk_buff *buf) 1761int tipc_sk_rcv(struct sk_buff *buf)
1716{ 1762{
1717 struct tipc_sock *tsk; 1763 struct tipc_sock *tsk;
1718 struct tipc_port *port;
1719 struct sock *sk; 1764 struct sock *sk;
1720 u32 dport = msg_destport(buf_msg(buf)); 1765 u32 dport = msg_destport(buf_msg(buf));
1721 int rc = TIPC_OK; 1766 int rc = TIPC_OK;
@@ -1728,7 +1773,6 @@ int tipc_sk_rcv(struct sk_buff *buf)
1728 rc = tipc_msg_eval(buf, &dnode); 1773 rc = tipc_msg_eval(buf, &dnode);
1729 goto exit; 1774 goto exit;
1730 } 1775 }
1731 port = &tsk->port;
1732 sk = &tsk->sk; 1776 sk = &tsk->sk;
1733 1777
1734 /* Queue message */ 1778 /* Queue message */
@@ -1931,7 +1975,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1931{ 1975{
1932 struct sock *new_sk, *sk = sock->sk; 1976 struct sock *new_sk, *sk = sock->sk;
1933 struct sk_buff *buf; 1977 struct sk_buff *buf;
1934 struct tipc_port *new_port; 1978 struct tipc_sock *new_tsock;
1935 struct tipc_msg *msg; 1979 struct tipc_msg *msg;
1936 long timeo; 1980 long timeo;
1937 int res; 1981 int res;
@@ -1954,7 +1998,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1954 goto exit; 1998 goto exit;
1955 1999
1956 new_sk = new_sock->sk; 2000 new_sk = new_sock->sk;
1957 new_port = &tipc_sk(new_sk)->port; 2001 new_tsock = tipc_sk(new_sk);
1958 msg = buf_msg(buf); 2002 msg = buf_msg(buf);
1959 2003
1960 /* we lock on new_sk; but lockdep sees the lock on sk */ 2004 /* we lock on new_sk; but lockdep sees the lock on sk */
@@ -1967,13 +2011,13 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1967 tsk_rej_rx_queue(new_sk); 2011 tsk_rej_rx_queue(new_sk);
1968 2012
1969 /* Connect new socket to it's peer */ 2013 /* Connect new socket to it's peer */
1970 tipc_sk_finish_conn(new_port, msg_origport(msg), msg_orignode(msg)); 2014 tipc_sk_finish_conn(new_tsock, msg_origport(msg), msg_orignode(msg));
1971 new_sock->state = SS_CONNECTED; 2015 new_sock->state = SS_CONNECTED;
1972 2016
1973 tsk_set_importance(new_port, msg_importance(msg)); 2017 tsk_set_importance(new_tsock, msg_importance(msg));
1974 if (msg_named(msg)) { 2018 if (msg_named(msg)) {
1975 new_port->conn_type = msg_nametype(msg); 2019 new_tsock->conn_type = msg_nametype(msg);
1976 new_port->conn_instance = msg_nameinst(msg); 2020 new_tsock->conn_instance = msg_nameinst(msg);
1977 } 2021 }
1978 2022
1979 /* 2023 /*
@@ -2009,7 +2053,6 @@ static int tipc_shutdown(struct socket *sock, int how)
2009{ 2053{
2010 struct sock *sk = sock->sk; 2054 struct sock *sk = sock->sk;
2011 struct tipc_sock *tsk = tipc_sk(sk); 2055 struct tipc_sock *tsk = tipc_sk(sk);
2012 struct tipc_port *port = &tsk->port;
2013 struct sk_buff *buf; 2056 struct sk_buff *buf;
2014 u32 dnode; 2057 u32 dnode;
2015 int res; 2058 int res;
@@ -2032,20 +2075,20 @@ restart:
2032 goto restart; 2075 goto restart;
2033 } 2076 }
2034 if (tipc_msg_reverse(buf, &dnode, TIPC_CONN_SHUTDOWN)) 2077 if (tipc_msg_reverse(buf, &dnode, TIPC_CONN_SHUTDOWN))
2035 tipc_link_xmit(buf, dnode, port->ref); 2078 tipc_link_xmit(buf, dnode, tsk->ref);
2036 tipc_node_remove_conn(dnode, port->ref); 2079 tipc_node_remove_conn(dnode, tsk->ref);
2037 } else { 2080 } else {
2038 dnode = tsk_peer_node(port); 2081 dnode = tsk_peer_node(tsk);
2039 buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, 2082 buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE,
2040 TIPC_CONN_MSG, SHORT_H_SIZE, 2083 TIPC_CONN_MSG, SHORT_H_SIZE,
2041 0, dnode, tipc_own_addr, 2084 0, dnode, tipc_own_addr,
2042 tsk_peer_port(port), 2085 tsk_peer_port(tsk),
2043 port->ref, TIPC_CONN_SHUTDOWN); 2086 tsk->ref, TIPC_CONN_SHUTDOWN);
2044 tipc_link_xmit(buf, dnode, port->ref); 2087 tipc_link_xmit(buf, dnode, tsk->ref);
2045 } 2088 }
2046 port->connected = 0; 2089 tsk->connected = 0;
2047 sock->state = SS_DISCONNECTING; 2090 sock->state = SS_DISCONNECTING;
2048 tipc_node_remove_conn(dnode, port->ref); 2091 tipc_node_remove_conn(dnode, tsk->ref);
2049 /* fall through */ 2092 /* fall through */
2050 2093
2051 case SS_DISCONNECTING: 2094 case SS_DISCONNECTING:
@@ -2069,7 +2112,6 @@ restart:
2069static void tipc_sk_timeout(unsigned long ref) 2112static void tipc_sk_timeout(unsigned long ref)
2070{ 2113{
2071 struct tipc_sock *tsk; 2114 struct tipc_sock *tsk;
2072 struct tipc_port *port;
2073 struct sock *sk; 2115 struct sock *sk;
2074 struct sk_buff *buf = NULL; 2116 struct sk_buff *buf = NULL;
2075 u32 peer_port, peer_node; 2117 u32 peer_port, peer_node;
@@ -2078,17 +2120,16 @@ static void tipc_sk_timeout(unsigned long ref)
2078 if (!tsk) 2120 if (!tsk)
2079 goto exit; 2121 goto exit;
2080 sk = &tsk->sk; 2122 sk = &tsk->sk;
2081 port = &tsk->port;
2082 2123
2083 bh_lock_sock(sk); 2124 bh_lock_sock(sk);
2084 if (!port->connected) { 2125 if (!tsk->connected) {
2085 bh_unlock_sock(sk); 2126 bh_unlock_sock(sk);
2086 goto exit; 2127 goto exit;
2087 } 2128 }
2088 peer_port = tsk_peer_port(port); 2129 peer_port = tsk_peer_port(tsk);
2089 peer_node = tsk_peer_node(port); 2130 peer_node = tsk_peer_node(tsk);
2090 2131
2091 if (port->probing_state == TIPC_CONN_PROBING) { 2132 if (tsk->probing_state == TIPC_CONN_PROBING) {
2092 /* Previous probe not answered -> self abort */ 2133 /* Previous probe not answered -> self abort */
2093 buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, 2134 buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
2094 SHORT_H_SIZE, 0, tipc_own_addr, 2135 SHORT_H_SIZE, 0, tipc_own_addr,
@@ -2098,8 +2139,8 @@ static void tipc_sk_timeout(unsigned long ref)
2098 buf = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, 2139 buf = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE,
2099 0, peer_node, tipc_own_addr, 2140 0, peer_node, tipc_own_addr,
2100 peer_port, ref, TIPC_OK); 2141 peer_port, ref, TIPC_OK);
2101 port->probing_state = TIPC_CONN_PROBING; 2142 tsk->probing_state = TIPC_CONN_PROBING;
2102 k_start_timer(&port->timer, port->probing_interval); 2143 k_start_timer(&tsk->timer, tsk->probing_interval);
2103 } 2144 }
2104 bh_unlock_sock(sk); 2145 bh_unlock_sock(sk);
2105 if (buf) 2146 if (buf)
@@ -2108,37 +2149,37 @@ exit:
2108 tipc_sk_put(tsk); 2149 tipc_sk_put(tsk);
2109} 2150}
2110 2151
2111static int tipc_sk_publish(struct tipc_port *port, uint scope, 2152static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
2112 struct tipc_name_seq const *seq) 2153 struct tipc_name_seq const *seq)
2113{ 2154{
2114 struct publication *publ; 2155 struct publication *publ;
2115 u32 key; 2156 u32 key;
2116 2157
2117 if (port->connected) 2158 if (tsk->connected)
2118 return -EINVAL; 2159 return -EINVAL;
2119 key = port->ref + port->pub_count + 1; 2160 key = tsk->ref + tsk->pub_count + 1;
2120 if (key == port->ref) 2161 if (key == tsk->ref)
2121 return -EADDRINUSE; 2162 return -EADDRINUSE;
2122 2163
2123 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, 2164 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
2124 scope, port->ref, key); 2165 scope, tsk->ref, key);
2125 if (unlikely(!publ)) 2166 if (unlikely(!publ))
2126 return -EINVAL; 2167 return -EINVAL;
2127 2168
2128 list_add(&publ->pport_list, &port->publications); 2169 list_add(&publ->pport_list, &tsk->publications);
2129 port->pub_count++; 2170 tsk->pub_count++;
2130 port->published = 1; 2171 tsk->published = 1;
2131 return 0; 2172 return 0;
2132} 2173}
2133 2174
2134static int tipc_sk_withdraw(struct tipc_port *port, uint scope, 2175static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope,
2135 struct tipc_name_seq const *seq) 2176 struct tipc_name_seq const *seq)
2136{ 2177{
2137 struct publication *publ; 2178 struct publication *publ;
2138 struct publication *safe; 2179 struct publication *safe;
2139 int rc = -EINVAL; 2180 int rc = -EINVAL;
2140 2181
2141 list_for_each_entry_safe(publ, safe, &port->publications, pport_list) { 2182 list_for_each_entry_safe(publ, safe, &tsk->publications, pport_list) {
2142 if (seq) { 2183 if (seq) {
2143 if (publ->scope != scope) 2184 if (publ->scope != scope)
2144 continue; 2185 continue;
@@ -2157,12 +2198,12 @@ static int tipc_sk_withdraw(struct tipc_port *port, uint scope,
2157 publ->ref, publ->key); 2198 publ->ref, publ->key);
2158 rc = 0; 2199 rc = 0;
2159 } 2200 }
2160 if (list_empty(&port->publications)) 2201 if (list_empty(&tsk->publications))
2161 port->published = 0; 2202 tsk->published = 0;
2162 return rc; 2203 return rc;
2163} 2204}
2164 2205
2165static int tipc_sk_show(struct tipc_port *port, char *buf, 2206static int tipc_sk_show(struct tipc_sock *tsk, char *buf,
2166 int len, int full_id) 2207 int len, int full_id)
2167{ 2208{
2168 struct publication *publ; 2209 struct publication *publ;
@@ -2172,26 +2213,26 @@ static int tipc_sk_show(struct tipc_port *port, char *buf,
2172 ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:", 2213 ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:",
2173 tipc_zone(tipc_own_addr), 2214 tipc_zone(tipc_own_addr),
2174 tipc_cluster(tipc_own_addr), 2215 tipc_cluster(tipc_own_addr),
2175 tipc_node(tipc_own_addr), port->ref); 2216 tipc_node(tipc_own_addr), tsk->ref);
2176 else 2217 else
2177 ret = tipc_snprintf(buf, len, "%-10u:", port->ref); 2218 ret = tipc_snprintf(buf, len, "%-10u:", tsk->ref);
2178 2219
2179 if (port->connected) { 2220 if (tsk->connected) {
2180 u32 dport = tsk_peer_port(port); 2221 u32 dport = tsk_peer_port(tsk);
2181 u32 destnode = tsk_peer_node(port); 2222 u32 destnode = tsk_peer_node(tsk);
2182 2223
2183 ret += tipc_snprintf(buf + ret, len - ret, 2224 ret += tipc_snprintf(buf + ret, len - ret,
2184 " connected to <%u.%u.%u:%u>", 2225 " connected to <%u.%u.%u:%u>",
2185 tipc_zone(destnode), 2226 tipc_zone(destnode),
2186 tipc_cluster(destnode), 2227 tipc_cluster(destnode),
2187 tipc_node(destnode), dport); 2228 tipc_node(destnode), dport);
2188 if (port->conn_type != 0) 2229 if (tsk->conn_type != 0)
2189 ret += tipc_snprintf(buf + ret, len - ret, 2230 ret += tipc_snprintf(buf + ret, len - ret,
2190 " via {%u,%u}", port->conn_type, 2231 " via {%u,%u}", tsk->conn_type,
2191 port->conn_instance); 2232 tsk->conn_instance);
2192 } else if (port->published) { 2233 } else if (tsk->published) {
2193 ret += tipc_snprintf(buf + ret, len - ret, " bound to"); 2234 ret += tipc_snprintf(buf + ret, len - ret, " bound to");
2194 list_for_each_entry(publ, &port->publications, pport_list) { 2235 list_for_each_entry(publ, &tsk->publications, pport_list) {
2195 if (publ->lower == publ->upper) 2236 if (publ->lower == publ->upper)
2196 ret += tipc_snprintf(buf + ret, len - ret, 2237 ret += tipc_snprintf(buf + ret, len - ret,
2197 " {%u,%u}", publ->type, 2238 " {%u,%u}", publ->type,
@@ -2226,7 +2267,7 @@ struct sk_buff *tipc_sk_socks_show(void)
2226 tsk = tipc_sk_get_next(&ref); 2267 tsk = tipc_sk_get_next(&ref);
2227 for (; tsk; tsk = tipc_sk_get_next(&ref)) { 2268 for (; tsk; tsk = tipc_sk_get_next(&ref)) {
2228 lock_sock(&tsk->sk); 2269 lock_sock(&tsk->sk);
2229 str_len += tipc_sk_show(&tsk->port, pb + str_len, 2270 str_len += tipc_sk_show(tsk, pb + str_len,
2230 pb_len - str_len, 0); 2271 pb_len - str_len, 0);
2231 release_sock(&tsk->sk); 2272 release_sock(&tsk->sk);
2232 tipc_sk_put(tsk); 2273 tipc_sk_put(tsk);
@@ -2249,7 +2290,7 @@ void tipc_sk_reinit(void)
2249 2290
2250 for (; tsk; tsk = tipc_sk_get_next(&ref)) { 2291 for (; tsk; tsk = tipc_sk_get_next(&ref)) {
2251 lock_sock(&tsk->sk); 2292 lock_sock(&tsk->sk);
2252 msg = &tsk->port.phdr; 2293 msg = &tsk->phdr;
2253 msg_set_prevnode(msg, tipc_own_addr); 2294 msg_set_prevnode(msg, tipc_own_addr);
2254 msg_set_orignode(msg, tipc_own_addr); 2295 msg_set_orignode(msg, tipc_own_addr);
2255 release_sock(&tsk->sk); 2296 release_sock(&tsk->sk);
@@ -2512,7 +2553,6 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
2512{ 2553{
2513 struct sock *sk = sock->sk; 2554 struct sock *sk = sock->sk;
2514 struct tipc_sock *tsk = tipc_sk(sk); 2555 struct tipc_sock *tsk = tipc_sk(sk);
2515 struct tipc_port *port = &tsk->port;
2516 u32 value; 2556 u32 value;
2517 int res; 2557 int res;
2518 2558
@@ -2530,16 +2570,16 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
2530 2570
2531 switch (opt) { 2571 switch (opt) {
2532 case TIPC_IMPORTANCE: 2572 case TIPC_IMPORTANCE:
2533 res = tsk_set_importance(port, value); 2573 res = tsk_set_importance(tsk, value);
2534 break; 2574 break;
2535 case TIPC_SRC_DROPPABLE: 2575 case TIPC_SRC_DROPPABLE:
2536 if (sock->type != SOCK_STREAM) 2576 if (sock->type != SOCK_STREAM)
2537 tsk_set_unreliable(port, value); 2577 tsk_set_unreliable(tsk, value);
2538 else 2578 else
2539 res = -ENOPROTOOPT; 2579 res = -ENOPROTOOPT;
2540 break; 2580 break;
2541 case TIPC_DEST_DROPPABLE: 2581 case TIPC_DEST_DROPPABLE:
2542 tsk_set_unreturnable(port, value); 2582 tsk_set_unreturnable(tsk, value);
2543 break; 2583 break;
2544 case TIPC_CONN_TIMEOUT: 2584 case TIPC_CONN_TIMEOUT:
2545 tipc_sk(sk)->conn_timeout = value; 2585 tipc_sk(sk)->conn_timeout = value;
@@ -2572,7 +2612,6 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
2572{ 2612{
2573 struct sock *sk = sock->sk; 2613 struct sock *sk = sock->sk;
2574 struct tipc_sock *tsk = tipc_sk(sk); 2614 struct tipc_sock *tsk = tipc_sk(sk);
2575 struct tipc_port *port = &tsk->port;
2576 int len; 2615 int len;
2577 u32 value; 2616 u32 value;
2578 int res; 2617 int res;
@@ -2589,16 +2628,16 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
2589 2628
2590 switch (opt) { 2629 switch (opt) {
2591 case TIPC_IMPORTANCE: 2630 case TIPC_IMPORTANCE:
2592 value = tsk_importance(port); 2631 value = tsk_importance(tsk);
2593 break; 2632 break;
2594 case TIPC_SRC_DROPPABLE: 2633 case TIPC_SRC_DROPPABLE:
2595 value = tsk_unreliable(port); 2634 value = tsk_unreliable(tsk);
2596 break; 2635 break;
2597 case TIPC_DEST_DROPPABLE: 2636 case TIPC_DEST_DROPPABLE:
2598 value = tsk_unreturnable(port); 2637 value = tsk_unreturnable(tsk);
2599 break; 2638 break;
2600 case TIPC_CONN_TIMEOUT: 2639 case TIPC_CONN_TIMEOUT:
2601 value = tipc_sk(sk)->conn_timeout; 2640 value = tsk->conn_timeout;
2602 /* no need to set "res", since already 0 at this point */ 2641 /* no need to set "res", since already 0 at this point */
2603 break; 2642 break;
2604 case TIPC_NODE_RECVQ_DEPTH: 2643 case TIPC_NODE_RECVQ_DEPTH:
diff --git a/net/tipc/socket.h b/net/tipc/socket.h
index 48772169bc77..baa43d03901e 100644
--- a/net/tipc/socket.h
+++ b/net/tipc/socket.h
@@ -36,85 +36,11 @@
36#define _TIPC_SOCK_H 36#define _TIPC_SOCK_H
37 37
38#include <net/sock.h> 38#include <net/sock.h>
39#include "msg.h"
40 39
41#define TIPC_CONN_OK 0
42#define TIPC_CONN_PROBING 1
43#define TIPC_CONNACK_INTV 256 40#define TIPC_CONNACK_INTV 256
44#define TIPC_FLOWCTRL_WIN (TIPC_CONNACK_INTV * 2) 41#define TIPC_FLOWCTRL_WIN (TIPC_CONNACK_INTV * 2)
45#define TIPC_CONN_OVERLOAD_LIMIT ((TIPC_FLOWCTRL_WIN * 2 + 1) * \ 42#define TIPC_CONN_OVERLOAD_LIMIT ((TIPC_FLOWCTRL_WIN * 2 + 1) * \
46 SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE)) 43 SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE))
47
48/**
49 * struct tipc_port - TIPC port structure
50 * @lock: pointer to spinlock for controlling access to port
51 * @connected: non-zero if port is currently connected to a peer port
52 * @conn_type: TIPC type used when connection was established
53 * @conn_instance: TIPC instance used when connection was established
54 * @published: non-zero if port has one or more associated names
55 * @max_pkt: maximum packet size "hint" used when building messages sent by port
56 * @ref: unique reference to port in TIPC object registry
57 * @phdr: preformatted message header used when sending messages
58 * @port_list: adjacent ports in TIPC's global list of ports
59 * @publications: list of publications for port
60 * @pub_count: total # of publications port has made during its lifetime
61 * @probing_state:
62 * @probing_interval:
63 * @timer_ref:
64 */
65struct tipc_port {
66 int connected;
67 u32 conn_type;
68 u32 conn_instance;
69 int published;
70 u32 max_pkt;
71 u32 ref;
72 struct tipc_msg phdr;
73 struct list_head port_list;
74 struct list_head publications;
75 u32 pub_count;
76 u32 probing_state;
77 u32 probing_interval;
78 struct timer_list timer;
79};
80
81/**
82 * struct tipc_sock - TIPC socket structure
83 * @sk: socket - interacts with 'port' and with user via the socket API
84 * @port: port - interacts with 'sk' and with the rest of the TIPC stack
85 * @peer_name: the peer of the connection, if any
86 * @conn_timeout: the time we can wait for an unresponded setup request
87 * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue
88 * @link_cong: non-zero if owner must sleep because of link congestion
89 * @sent_unacked: # messages sent by socket, and not yet acked by peer
90 * @rcv_unacked: # messages read by user, but not yet acked back to peer
91 */
92
93struct tipc_sock {
94 struct sock sk;
95 struct tipc_port port;
96 unsigned int conn_timeout;
97 atomic_t dupl_rcvcnt;
98 bool link_cong;
99 uint sent_unacked;
100 uint rcv_unacked;
101};
102
103static inline struct tipc_sock *tipc_sk(const struct sock *sk)
104{
105 return container_of(sk, struct tipc_sock, sk);
106}
107
108static inline struct tipc_sock *tipc_port_to_sock(const struct tipc_port *port)
109{
110 return container_of(port, struct tipc_sock, port);
111}
112
113static inline int tipc_sk_conn_cong(struct tipc_sock *tsk)
114{
115 return tsk->sent_unacked >= TIPC_FLOWCTRL_WIN;
116}
117
118int tipc_sk_rcv(struct sk_buff *buf); 44int tipc_sk_rcv(struct sk_buff *buf);
119struct sk_buff *tipc_sk_socks_show(void); 45struct sk_buff *tipc_sk_socks_show(void);
120void tipc_sk_mcast_rcv(struct sk_buff *buf); 46void tipc_sk_mcast_rcv(struct sk_buff *buf);