From acc631bf6f597b36f3f014e12e69c710da610027 Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Mon, 23 May 2011 13:47:44 -0400 Subject: tipc: Standardize exit logic for message rejection handling Modifies the routine that handles the rejection of payload messages so that it has a single exit point that frees up the rejected message, thereby eliminating some duplicated code. Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index c68dc956a42..3946b5b10c7 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -367,10 +367,8 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) imp++; /* discard rejected message if it shouldn't be returned to sender */ - if (msg_errcode(msg) || msg_dest_droppable(msg)) { - buf_discard(buf); - return data_sz; - } + if (msg_errcode(msg) || msg_dest_droppable(msg)) + goto exit; /* construct rejected message */ if (msg_mcast(msg)) @@ -378,10 +376,9 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) else hdr_sz = LONG_H_SIZE; rbuf = tipc_buf_acquire(data_sz + hdr_sz); - if (rbuf == NULL) { - buf_discard(buf); - return data_sz; - } + if (rbuf == NULL) + goto exit; + rmsg = buf_msg(rbuf); tipc_msg_init(rmsg, imp, msg_type(msg), hdr_sz, msg_orignode(msg)); msg_set_errcode(rmsg, err); @@ -411,9 +408,11 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) tipc_net_route_msg(abuf); } - /* send rejected message */ - buf_discard(buf); + /* send returned message & dispose of rejected message */ + tipc_net_route_msg(rbuf); +exit: + buf_discard(buf); return data_sz; } -- cgit v1.2.3-70-g09d2 From 76d12527f74ad1b42b068252fdd2056c8ae48a99 Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Mon, 23 May 2011 13:57:25 -0400 Subject: tipc: Add sanity check to detect rejection of non-payload messages Introduces an internal sanity check to ensure that the only undeliverable messages TIPC attempts to return to their origin are application payload messages. Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index 3946b5b10c7..756e64cbff9 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -367,6 +367,12 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) imp++; /* discard rejected message if it shouldn't be returned to sender */ + + if (WARN(!msg_isdata(msg), + "attempt to reject message with user=%u", msg_user(msg))) { + dump_stack(); + goto exit; + } if (msg_errcode(msg) || msg_dest_droppable(msg)) goto exit; -- cgit v1.2.3-70-g09d2 From 017dac31dc8a25ad45421715d88c3869e299fd35 Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Tue, 24 May 2011 13:20:09 -0400 Subject: tipc: Optimize routing of returned payload messages Reduces the work involved in transmitting a returned payload message by doing only the work necessary to route such a message directly to the specified destination port, rather than invoking the code used to route an arbitrary message to an arbitrary destination. Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index 756e64cbff9..70ecdfdf6e3 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -360,6 +360,7 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) int hdr_sz; u32 imp = msg_importance(msg); u32 data_sz = msg_data_sz(msg); + u32 src_node; if (data_sz > MAX_REJECT_SIZE) data_sz = MAX_REJECT_SIZE; @@ -416,7 +417,11 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) /* send returned message & dispose of rejected message */ - tipc_net_route_msg(rbuf); + src_node = msg_prevnode(msg); + if (src_node == tipc_own_addr) + tipc_port_recv_msg(rbuf); + else + tipc_link_send(rbuf, src_node, msg_link_selector(rmsg)); exit: buf_discard(buf); return data_sz; -- cgit v1.2.3-70-g09d2 From 7dd1bf28ccc44ef205c64aab618863faa914daa9 Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Mon, 23 May 2011 16:23:32 -0400 Subject: tipc: Optimizations & corrections to message rejection Optimizes the creation of a returned payload message by duplicating the original message and then updating the small number of fields that need to be adjusted, rather than building the new message header from scratch. In addition, certain operations that are not always required are relocated so that they are only done if needed. These optimizations also have the effect of addressing other issues that were present previously: 1) Fixes a bug that caused the socket send routines to return the size of the returned message, rather than the size of the sent message, when a returnable payload message was sent to a non-existent destination port. 2) The message header of the returned message now matches that of the original message more closely. The header is now always the same size as the original header, and some message header fields that weren't being initialized in the returned message header are now populated correctly -- namely the "d" and "s" bits, and the upper bound of a multicast name instance (where present). Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index 70ecdfdf6e3..53118171b7e 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -358,14 +358,10 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) struct sk_buff *rbuf; struct tipc_msg *rmsg; int hdr_sz; - u32 imp = msg_importance(msg); + u32 imp; u32 data_sz = msg_data_sz(msg); u32 src_node; - - if (data_sz > MAX_REJECT_SIZE) - data_sz = MAX_REJECT_SIZE; - if (msg_connected(msg) && (imp < TIPC_CRITICAL_IMPORTANCE)) - imp++; + u32 rmsg_sz; /* discard rejected message if it shouldn't be returned to sender */ @@ -377,30 +373,33 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) if (msg_errcode(msg) || msg_dest_droppable(msg)) goto exit; - /* construct rejected message */ - if (msg_mcast(msg)) - hdr_sz = MCAST_H_SIZE; - else - hdr_sz = LONG_H_SIZE; - rbuf = tipc_buf_acquire(data_sz + hdr_sz); + /* + * construct returned message by copying rejected message header and + * data (or subset), then updating header fields that need adjusting + */ + + hdr_sz = msg_hdr_sz(msg); + rmsg_sz = hdr_sz + min_t(u32, data_sz, MAX_REJECT_SIZE); + + rbuf = tipc_buf_acquire(rmsg_sz); if (rbuf == NULL) goto exit; rmsg = buf_msg(rbuf); - tipc_msg_init(rmsg, imp, msg_type(msg), hdr_sz, msg_orignode(msg)); - msg_set_errcode(rmsg, err); - msg_set_destport(rmsg, msg_origport(msg)); - msg_set_origport(rmsg, msg_destport(msg)); - if (msg_short(msg)) { - msg_set_orignode(rmsg, tipc_own_addr); - /* leave name type & instance as zeroes */ - } else { - msg_set_orignode(rmsg, msg_destnode(msg)); - msg_set_nametype(rmsg, msg_nametype(msg)); - msg_set_nameinst(rmsg, msg_nameinst(msg)); + skb_copy_to_linear_data(rbuf, msg, rmsg_sz); + + if (msg_connected(rmsg)) { + imp = msg_importance(rmsg); + if (imp < TIPC_CRITICAL_IMPORTANCE) + msg_set_importance(rmsg, ++imp); } - msg_set_size(rmsg, data_sz + hdr_sz); - skb_copy_to_linear_data_offset(rbuf, hdr_sz, msg_data(msg), data_sz); + msg_set_non_seq(rmsg, 0); + msg_set_size(rmsg, rmsg_sz); + msg_set_errcode(rmsg, err); + msg_set_prevnode(rmsg, tipc_own_addr); + msg_swap_words(rmsg, 4, 5); + if (!msg_short(rmsg)) + msg_swap_words(rmsg, 6, 7); /* send self-abort message when rejecting on a connected port */ if (msg_connected(msg)) { -- cgit v1.2.3-70-g09d2 From 741d9eb7b8f352071f56aacb77f5245b4e2a4fbe Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Tue, 31 May 2011 15:03:18 -0400 Subject: tipc: Cleanup of message header size terminology Performs cosmetic cleanup of the symbolic names used to specify TIPC payload message header sizes. The revised names now more accurately reflect the payload messages in which they can appear. In addition, several places where these payload message symbol names were being used to create non-payload messages have been updated to use the proper internal message symbolic name. No functional changes are introduced by this rework. Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/link.c | 4 ++-- net/tipc/msg.h | 10 +++++----- net/tipc/name_distr.c | 6 +++--- net/tipc/port.c | 20 ++++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/link.c b/net/tipc/link.c index 5bfe000b2a6..f89570c54f5 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c @@ -1572,7 +1572,7 @@ static struct sk_buff *link_insert_deferred_queue(struct link *l_ptr, static int link_recv_buf_validate(struct sk_buff *buf) { static u32 min_data_hdr_size[8] = { - SHORT_H_SIZE, MCAST_H_SIZE, LONG_H_SIZE, DIR_MSG_H_SIZE, + SHORT_H_SIZE, MCAST_H_SIZE, NAMED_H_SIZE, BASIC_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE }; @@ -2553,7 +2553,7 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb, u32 msg_sz = msg_size(imsg); u32 fragm_sz = msg_data_sz(fragm); u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz); - u32 max = TIPC_MAX_USER_MSG_SIZE + LONG_H_SIZE; + u32 max = TIPC_MAX_USER_MSG_SIZE + NAMED_H_SIZE; if (msg_type(imsg) == TIPC_MCAST_MSG) max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE; if (msg_size(imsg) > max) { diff --git a/net/tipc/msg.h b/net/tipc/msg.h index a58975ced22..d93178f2e85 100644 --- a/net/tipc/msg.h +++ b/net/tipc/msg.h @@ -68,10 +68,10 @@ * Message header sizes */ -#define SHORT_H_SIZE 24 /* Connected, in-cluster messages */ -#define DIR_MSG_H_SIZE 32 /* Directly addressed messages */ -#define LONG_H_SIZE 40 /* Named messages */ -#define MCAST_H_SIZE 44 /* Multicast messages */ +#define SHORT_H_SIZE 24 /* In-cluster basic payload message */ +#define BASIC_H_SIZE 32 /* Basic payload message */ +#define NAMED_H_SIZE 40 /* Named payload message */ +#define MCAST_H_SIZE 44 /* Multicast payload message */ #define INT_H_SIZE 40 /* Internal messages */ #define MIN_H_SIZE 24 /* Smallest legal TIPC header size */ #define MAX_H_SIZE 60 /* Largest possible TIPC header size */ @@ -357,7 +357,7 @@ static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p) static inline int msg_short(struct tipc_msg *m) { - return msg_hdr_sz(m) == 24; + return msg_hdr_sz(m) == SHORT_H_SIZE; } static inline u32 msg_orignode(struct tipc_msg *m) diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c index 80025a1b3bf..cd356e50433 100644 --- a/net/tipc/name_distr.c +++ b/net/tipc/name_distr.c @@ -94,13 +94,13 @@ static void publ_to_item(struct distr_item *i, struct publication *p) static struct sk_buff *named_prepare_buf(u32 type, u32 size, u32 dest) { - struct sk_buff *buf = tipc_buf_acquire(LONG_H_SIZE + size); + struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size); struct tipc_msg *msg; if (buf != NULL) { msg = buf_msg(buf); - tipc_msg_init(msg, NAME_DISTRIBUTOR, type, LONG_H_SIZE, dest); - msg_set_size(msg, LONG_H_SIZE + size); + tipc_msg_init(msg, NAME_DISTRIBUTOR, type, INT_H_SIZE, dest); + msg_set_size(msg, INT_H_SIZE + size); } return buf; } diff --git a/net/tipc/port.c b/net/tipc/port.c index 53118171b7e..70e9de57711 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -222,7 +222,7 @@ struct tipc_port *tipc_createport_raw(void *usr_handle, p_ptr->max_pkt = MAX_PKT_DEFAULT; p_ptr->ref = ref; msg = &p_ptr->phdr; - tipc_msg_init(msg, importance, TIPC_NAMED_MSG, LONG_H_SIZE, 0); + tipc_msg_init(msg, importance, TIPC_NAMED_MSG, NAMED_H_SIZE, 0); msg_set_origport(msg, ref); INIT_LIST_HEAD(&p_ptr->wait_list); INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); @@ -339,10 +339,10 @@ static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, struct sk_buff *buf; struct tipc_msg *msg; - buf = tipc_buf_acquire(LONG_H_SIZE); + buf = tipc_buf_acquire(INT_H_SIZE); if (buf) { msg = buf_msg(buf); - tipc_msg_init(msg, usr, type, LONG_H_SIZE, destnode); + tipc_msg_init(msg, usr, type, INT_H_SIZE, destnode); msg_set_errcode(msg, err); msg_set_destport(msg, destport); msg_set_origport(msg, origport); @@ -1247,7 +1247,7 @@ int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, msg_set_type(msg, TIPC_NAMED_MSG); msg_set_orignode(msg, tipc_own_addr); msg_set_origport(msg, ref); - msg_set_hdr_sz(msg, LONG_H_SIZE); + msg_set_hdr_sz(msg, NAMED_H_SIZE); msg_set_nametype(msg, name->type); msg_set_nameinst(msg, name->instance); msg_set_lookup_scope(msg, tipc_addr_scope(domain)); @@ -1300,7 +1300,7 @@ int tipc_send2port(u32 ref, struct tipc_portid const *dest, msg_set_origport(msg, ref); msg_set_destnode(msg, dest->node); msg_set_destport(msg, dest->ref); - msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); + msg_set_hdr_sz(msg, BASIC_H_SIZE); if (dest->node == tipc_own_addr) res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect, @@ -1340,13 +1340,13 @@ int tipc_send_buf2port(u32 ref, struct tipc_portid const *dest, msg_set_origport(msg, ref); msg_set_destnode(msg, dest->node); msg_set_destport(msg, dest->ref); - msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); - msg_set_size(msg, DIR_MSG_H_SIZE + dsz); - if (skb_cow(buf, DIR_MSG_H_SIZE)) + msg_set_hdr_sz(msg, BASIC_H_SIZE); + msg_set_size(msg, BASIC_H_SIZE + dsz); + if (skb_cow(buf, BASIC_H_SIZE)) return -ENOMEM; - skb_push(buf, DIR_MSG_H_SIZE); - skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE); + skb_push(buf, BASIC_H_SIZE); + skb_copy_to_linear_data(buf, msg, BASIC_H_SIZE); if (dest->node == tipc_own_addr) res = tipc_port_recv_msg(buf); -- cgit v1.2.3-70-g09d2 From e244a915ff7676b1567ba68102c9b53011f5b766 Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Tue, 31 May 2011 16:10:08 -0400 Subject: tipc: Optimize creation of FIN messages Speeds up the creation of the FIN message that terminates a TIPC connection. The typical peer termination message is now created by duplicating the terminating port's standard payload message header and adjusting the message size, importance, and error code fields, rather than building all fields of the message from scratch. A FIN message that is directed to the port itself is created the same way. but also requires swapping the origin and destination address fields. In addition to reducing the work required to create FIN messages, these changes eliminate several instances of duplicated code, Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 61 +++++++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 37 deletions(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index 70e9de57711..8be68e0bf30 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -489,39 +489,38 @@ static void port_handle_node_down(unsigned long ref) static struct sk_buff *port_build_self_abort_msg(struct tipc_port *p_ptr, u32 err) { - u32 imp = msg_importance(&p_ptr->phdr); + struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err); - if (!p_ptr->connected) - return NULL; - if (imp < TIPC_CRITICAL_IMPORTANCE) - imp++; - return port_build_proto_msg(p_ptr->ref, - tipc_own_addr, - port_peerport(p_ptr), - port_peernode(p_ptr), - imp, - TIPC_CONN_MSG, - err, - 0); + if (buf) { + struct tipc_msg *msg = buf_msg(buf); + msg_swap_words(msg, 4, 5); + msg_swap_words(msg, 6, 7); + } + return buf; } static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 err) { - u32 imp = msg_importance(&p_ptr->phdr); + struct sk_buff *buf; + struct tipc_msg *msg; + u32 imp; if (!p_ptr->connected) return NULL; - if (imp < TIPC_CRITICAL_IMPORTANCE) - imp++; - return port_build_proto_msg(port_peerport(p_ptr), - port_peernode(p_ptr), - p_ptr->ref, - tipc_own_addr, - imp, - TIPC_CONN_MSG, - err, - 0); + + buf = tipc_buf_acquire(BASIC_H_SIZE); + if (buf) { + msg = buf_msg(buf); + memcpy(msg, &p_ptr->phdr, BASIC_H_SIZE); + msg_set_hdr_sz(msg, BASIC_H_SIZE); + msg_set_size(msg, BASIC_H_SIZE); + imp = msg_importance(msg); + if (imp < TIPC_CRITICAL_IMPORTANCE) + msg_set_importance(msg, ++imp); + msg_set_errcode(msg, err); + } + return buf; } void tipc_port_recv_proto_msg(struct sk_buff *buf) @@ -1149,19 +1148,7 @@ int tipc_shutdown(u32 ref) if (!p_ptr) return -EINVAL; - if (p_ptr->connected) { - u32 imp = msg_importance(&p_ptr->phdr); - if (imp < TIPC_CRITICAL_IMPORTANCE) - imp++; - buf = port_build_proto_msg(port_peerport(p_ptr), - port_peernode(p_ptr), - ref, - tipc_own_addr, - imp, - TIPC_CONN_MSG, - TIPC_CONN_SHUTDOWN, - 0); - } + buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN); tipc_port_unlock(p_ptr); tipc_net_route_msg(buf); return tipc_disconnect(ref); -- cgit v1.2.3-70-g09d2 From 1c1a551acb8b65f842824900b283a96462f907ab Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Wed, 1 Jun 2011 15:08:10 -0400 Subject: tipc: Reject connection protocol message sent to unconnected port Restructures the logic used in tipc_port_recv_proto_msg() to ensure that incoming connection protocol messages are handled properly. The routine now uses a two-stage process that first ensures the message applies on an existing connection and then processes the request. This corrects a loophole that allowed a connection probe request to be processed if it was sent to an unconnected port that had no names bound to it. Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 79 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index 8be68e0bf30..1b20b963a2f 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -526,62 +526,63 @@ static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 er void tipc_port_recv_proto_msg(struct sk_buff *buf) { struct tipc_msg *msg = buf_msg(buf); - struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg)); - u32 err = TIPC_OK; + struct tipc_port *p_ptr; struct sk_buff *r_buf = NULL; - struct sk_buff *abort_buf = NULL; - - if (!p_ptr) { - err = TIPC_ERR_NO_PORT; - } else if (p_ptr->connected) { - if ((port_peernode(p_ptr) != msg_orignode(msg)) || - (port_peerport(p_ptr) != msg_origport(msg))) { - err = TIPC_ERR_NO_PORT; - } else if (msg_type(msg) == CONN_ACK) { - int wakeup = tipc_port_congested(p_ptr) && - p_ptr->congested && - p_ptr->wakeup; - p_ptr->acked += msg_msgcnt(msg); - if (tipc_port_congested(p_ptr)) - goto exit; - p_ptr->congested = 0; - if (!wakeup) - goto exit; - p_ptr->wakeup(p_ptr); - goto exit; - } - } else if (p_ptr->published) { - err = TIPC_ERR_NO_PORT; - } - if (err) { - r_buf = port_build_proto_msg(msg_origport(msg), - msg_orignode(msg), - msg_destport(msg), + u32 orignode = msg_orignode(msg); + u32 origport = msg_origport(msg); + u32 destport = msg_destport(msg); + int wakeable; + + /* Validate connection */ + + p_ptr = tipc_port_lock(destport); + if (!p_ptr || !p_ptr->connected || + (port_peernode(p_ptr) != orignode) || + (port_peerport(p_ptr) != origport)) { + r_buf = port_build_proto_msg(origport, + orignode, + destport, tipc_own_addr, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG, - err, + TIPC_ERR_NO_PORT, 0); + if (p_ptr) + tipc_port_unlock(p_ptr); goto exit; } - /* All is fine */ - if (msg_type(msg) == CONN_PROBE) { - r_buf = port_build_proto_msg(msg_origport(msg), - msg_orignode(msg), - msg_destport(msg), + /* Process protocol message sent by peer */ + + switch (msg_type(msg)) { + case CONN_ACK: + wakeable = tipc_port_congested(p_ptr) && p_ptr->congested && + p_ptr->wakeup; + p_ptr->acked += msg_msgcnt(msg); + if (!tipc_port_congested(p_ptr)) { + p_ptr->congested = 0; + if (wakeable) + p_ptr->wakeup(p_ptr); + } + break; + case CONN_PROBE: + r_buf = port_build_proto_msg(origport, + orignode, + destport, tipc_own_addr, CONN_MANAGER, CONN_PROBE_REPLY, TIPC_OK, 0); + break; + default: + /* CONN_PROBE_REPLY or unrecognized - no action required */ + break; } p_ptr->probing_state = CONFIRMED; + tipc_port_unlock(p_ptr); exit: - if (p_ptr) - tipc_port_unlock(p_ptr); tipc_net_route_msg(r_buf); - tipc_net_route_msg(abort_buf); buf_discard(buf); } -- cgit v1.2.3-70-g09d2 From f55b564054e35dcd171e1191a477327528271f95 Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Wed, 1 Jun 2011 15:48:42 -0400 Subject: tipc: Don't create payload message using connection protocol routine Modifies the logic that creates a connection termination payload message so that it no longer (mis)uses a routine that creates a connection protocol message. The revised code is now more easily understood, and avoids setting several fields that are either not present in payload messages or were being set more than once. Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index 1b20b963a2f..ab0a8e97e31 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -539,14 +539,15 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf) if (!p_ptr || !p_ptr->connected || (port_peernode(p_ptr) != orignode) || (port_peerport(p_ptr) != origport)) { - r_buf = port_build_proto_msg(origport, - orignode, - destport, - tipc_own_addr, - TIPC_HIGH_IMPORTANCE, - TIPC_CONN_MSG, - TIPC_ERR_NO_PORT, - 0); + r_buf = tipc_buf_acquire(BASIC_H_SIZE); + if (r_buf) { + msg = buf_msg(r_buf); + tipc_msg_init(msg, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG, + BASIC_H_SIZE, orignode); + msg_set_errcode(msg, TIPC_ERR_NO_PORT); + msg_set_origport(msg, destport); + msg_set_destport(msg, origport); + } if (p_ptr) tipc_port_unlock(p_ptr); goto exit; -- cgit v1.2.3-70-g09d2 From e4a0aee47e1823025972b8f3defde432e485b7b9 Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Wed, 1 Jun 2011 16:21:12 -0400 Subject: tipc: Optimize creation of connection protocol messages Simplifies the creation of connection protocol messages by eliminating the passing of information that is no longer required, is constant, or is contained within the port structure that is issuing the message. Signed-off-by: Allan Stephens Signed-off-by: Paul Gortmaker --- net/tipc/port.c | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) (limited to 'net/tipc/port.c') diff --git a/net/tipc/port.c b/net/tipc/port.c index ab0a8e97e31..54d812a5a4d 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -327,14 +327,12 @@ int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) } /* - * port_build_proto_msg(): build a port level protocol - * or a connection abortion message. Called with - * tipc_port lock on. + * port_build_proto_msg(): create connection protocol message for port + * + * On entry the port must be locked and connected. */ -static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, - u32 origport, u32 orignode, - u32 usr, u32 type, u32 err, - u32 ack) +static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr, + u32 type, u32 ack) { struct sk_buff *buf; struct tipc_msg *msg; @@ -342,11 +340,10 @@ static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, buf = tipc_buf_acquire(INT_H_SIZE); if (buf) { msg = buf_msg(buf); - tipc_msg_init(msg, usr, type, INT_H_SIZE, destnode); - msg_set_errcode(msg, err); - msg_set_destport(msg, destport); - msg_set_origport(msg, origport); - msg_set_orignode(msg, orignode); + tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE, + port_peernode(p_ptr)); + msg_set_destport(msg, port_peerport(p_ptr)); + msg_set_origport(msg, p_ptr->ref); msg_set_msgcnt(msg, ack); } return buf; @@ -458,14 +455,7 @@ static void port_timeout(unsigned long ref) if (p_ptr->probing_state == PROBING) { buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT); } else { - buf = port_build_proto_msg(port_peerport(p_ptr), - port_peernode(p_ptr), - p_ptr->ref, - tipc_own_addr, - CONN_MANAGER, - CONN_PROBE, - TIPC_OK, - 0); + buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0); p_ptr->probing_state = PROBING; k_start_timer(&p_ptr->timer, p_ptr->probing_interval); } @@ -567,14 +557,7 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf) } break; case CONN_PROBE: - r_buf = port_build_proto_msg(origport, - orignode, - destport, - tipc_own_addr, - CONN_MANAGER, - CONN_PROBE_REPLY, - TIPC_OK, - 0); + r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0); break; default: /* CONN_PROBE_REPLY or unrecognized - no action required */ @@ -899,14 +882,7 @@ void tipc_acknowledge(u32 ref, u32 ack) return; if (p_ptr->connected) { p_ptr->conn_unacked -= ack; - buf = port_build_proto_msg(port_peerport(p_ptr), - port_peernode(p_ptr), - ref, - tipc_own_addr, - CONN_MANAGER, - CONN_ACK, - TIPC_OK, - ack); + buf = port_build_proto_msg(p_ptr, CONN_ACK, ack); } tipc_port_unlock(p_ptr); tipc_net_route_msg(buf); -- cgit v1.2.3-70-g09d2