aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/port.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-06-25 21:41:41 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-27 15:50:56 -0400
commitac0074ee70ddb32f62d918b31cb20e3c947c75a1 (patch)
tree27c0e82b319ecbcbd23c1c3039b4b0e0d5a9ec1c /net/tipc/port.c
parentec8a2e5621db2da24badb3969eda7fd359e1869f (diff)
tipc: clean up connection protocol reception function
We simplify the code for receiving connection probes, leveraging the recently introduced tipc_msg_reverse() function. We also stick to the principle of sending a possible response message directly from the calling (tipc_sk_rcv or backlog_rcv) functions, hence making the call chain shallower and easier to follow. We make one small protocol change here, allowed according to the spec. If a protocol message arrives from a remote socket that is not the one we are connected to, we are currently generating a connection abort message and send it to the source. This behavior is unnecessary, and might even be a security risk, so instead we now choose to only ignore the message. The consequnce for the sender is that he will need longer time to discover his mistake (until the next timeout), but this is an extreme corner case, and may happen anyway under other circumstances, so we deem this change acceptable. 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>
Diffstat (limited to 'net/tipc/port.c')
-rw-r--r--net/tipc/port.c53
1 files changed, 3 insertions, 50 deletions
diff --git a/net/tipc/port.c b/net/tipc/port.c
index dcc630948e04..9f53d5ac35e1 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -42,8 +42,6 @@
42 42
43/* Connection management: */ 43/* Connection management: */
44#define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ 44#define PROBING_INTERVAL 3600000 /* [ms] => 1 h */
45#define CONFIRMED 0
46#define PROBING 1
47 45
48#define MAX_REJECT_SIZE 1024 46#define MAX_REJECT_SIZE 1024
49 47
@@ -299,11 +297,11 @@ static void port_timeout(unsigned long ref)
299 } 297 }
300 298
301 /* Last probe answered ? */ 299 /* Last probe answered ? */
302 if (p_ptr->probing_state == PROBING) { 300 if (p_ptr->probing_state == TIPC_CONN_PROBING) {
303 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT); 301 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
304 } else { 302 } else {
305 buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0); 303 buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0);
306 p_ptr->probing_state = PROBING; 304 p_ptr->probing_state = TIPC_CONN_PROBING;
307 k_start_timer(&p_ptr->timer, p_ptr->probing_interval); 305 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
308 } 306 }
309 tipc_port_unlock(p_ptr); 307 tipc_port_unlock(p_ptr);
@@ -365,51 +363,6 @@ static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 er
365 return buf; 363 return buf;
366} 364}
367 365
368void tipc_port_proto_rcv(struct tipc_port *p_ptr, struct sk_buff *buf)
369{
370 struct tipc_msg *msg = buf_msg(buf);
371 struct sk_buff *r_buf = NULL;
372 u32 destport = msg_destport(msg);
373 int wakeable;
374
375 /* Validate connection */
376 if (!p_ptr || !p_ptr->connected || !tipc_port_peer_msg(p_ptr, msg)) {
377 r_buf = tipc_buf_acquire(BASIC_H_SIZE);
378 if (r_buf) {
379 msg = buf_msg(r_buf);
380 tipc_msg_init(msg, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG,
381 BASIC_H_SIZE, msg_orignode(msg));
382 msg_set_errcode(msg, TIPC_ERR_NO_PORT);
383 msg_set_origport(msg, destport);
384 msg_set_destport(msg, msg_origport(msg));
385 }
386 goto exit;
387 }
388
389 /* Process protocol message sent by peer */
390 switch (msg_type(msg)) {
391 case CONN_ACK:
392 wakeable = tipc_port_congested(p_ptr) && p_ptr->congested;
393 p_ptr->acked += msg_msgcnt(msg);
394 if (!tipc_port_congested(p_ptr)) {
395 p_ptr->congested = 0;
396 if (wakeable)
397 tipc_port_wakeup(p_ptr);
398 }
399 break;
400 case CONN_PROBE:
401 r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0);
402 break;
403 default:
404 /* CONN_PROBE_REPLY or unrecognized - no action required */
405 break;
406 }
407 p_ptr->probing_state = CONFIRMED;
408exit:
409 tipc_link_xmit2(r_buf, msg_destnode(msg), msg_link_selector(msg));
410 kfree_skb(buf);
411}
412
413static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id) 366static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id)
414{ 367{
415 struct publication *publ; 368 struct publication *publ;
@@ -613,7 +566,7 @@ int __tipc_port_connect(u32 ref, struct tipc_port *p_ptr,
613 msg_set_hdr_sz(msg, SHORT_H_SIZE); 566 msg_set_hdr_sz(msg, SHORT_H_SIZE);
614 567
615 p_ptr->probing_interval = PROBING_INTERVAL; 568 p_ptr->probing_interval = PROBING_INTERVAL;
616 p_ptr->probing_state = CONFIRMED; 569 p_ptr->probing_state = TIPC_CONN_OK;
617 p_ptr->connected = 1; 570 p_ptr->connected = 1;
618 k_start_timer(&p_ptr->timer, p_ptr->probing_interval); 571 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
619 572