Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/link.c: TIPC link code |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 4 | * Copyright (c) 1996-2007, 2012-2014, Ericsson AB |
Ying Xue | 198d73b | 2013-06-17 10:54:42 -0400 | [diff] [blame] | 5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the names of the copyright holders nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 20 | * Alternatively, this software may be distributed under the terms of the |
| 21 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 22 | * Software Foundation. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 38 | #include "link.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | #include "port.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 40 | #include "name_distr.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 41 | #include "discover.h" |
| 42 | #include "config.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 43 | |
Ying Xue | 796c75d | 2013-06-17 10:54:48 -0400 | [diff] [blame] | 44 | #include <linux/pkt_sched.h> |
| 45 | |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 46 | /* |
| 47 | * Error message prefixes |
| 48 | */ |
| 49 | static const char *link_co_err = "Link changeover error, "; |
| 50 | static const char *link_rst_msg = "Resetting link "; |
| 51 | static const char *link_unk_evt = "Unknown link event "; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 52 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 53 | /* |
Allan Stephens | a686e68 | 2008-06-04 17:29:39 -0700 | [diff] [blame] | 54 | * Out-of-range value for link session numbers |
| 55 | */ |
Allan Stephens | a686e68 | 2008-06-04 17:29:39 -0700 | [diff] [blame] | 56 | #define INVALID_SESSION 0x10000 |
| 57 | |
| 58 | /* |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 59 | * Link state events: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 60 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 61 | #define STARTING_EVT 856384768 /* link processing trigger */ |
| 62 | #define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */ |
| 63 | #define TIMEOUT_EVT 560817u /* link timer expired */ |
| 64 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 65 | /* |
| 66 | * The following two 'message types' is really just implementation |
| 67 | * data conveniently stored in the message header. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 68 | * They must not be considered part of the protocol |
| 69 | */ |
| 70 | #define OPEN_MSG 0 |
| 71 | #define CLOSED_MSG 1 |
| 72 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 73 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 74 | * State value stored in 'exp_msg_count' |
| 75 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 76 | #define START_CHANGEOVER 100000u |
| 77 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 78 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 79 | struct sk_buff *buf); |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 80 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf); |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 81 | static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, |
| 82 | struct sk_buff **buf); |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 83 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 84 | static int link_send_sections_long(struct tipc_port *sender, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 85 | struct iovec const *msg_sect, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 86 | unsigned int len, u32 destnode); |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 87 | static void link_state_event(struct tipc_link *l_ptr, u32 event); |
| 88 | static void link_reset_statistics(struct tipc_link *l_ptr); |
| 89 | static void link_print(struct tipc_link *l_ptr, const char *str); |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 90 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf); |
Jon Maloy | c64f7a6 | 2012-11-16 13:51:31 +0800 | [diff] [blame] | 91 | static void tipc_link_send_sync(struct tipc_link *l); |
| 92 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf); |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 93 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 94 | /* |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 95 | * Simple link routines |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 96 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 97 | static unsigned int align(unsigned int i) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 98 | { |
| 99 | return (i + 3) & ~3u; |
| 100 | } |
| 101 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 102 | static void link_init_max_pkt(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 103 | { |
| 104 | u32 max_pkt; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 105 | |
Allan Stephens | 2d627b9 | 2011-01-07 13:00:11 -0500 | [diff] [blame] | 106 | max_pkt = (l_ptr->b_ptr->mtu & ~3); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 107 | if (max_pkt > MAX_MSG_SIZE) |
| 108 | max_pkt = MAX_MSG_SIZE; |
| 109 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 110 | l_ptr->max_pkt_target = max_pkt; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 111 | if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT) |
| 112 | l_ptr->max_pkt = l_ptr->max_pkt_target; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 113 | else |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 114 | l_ptr->max_pkt = MAX_PKT_DEFAULT; |
| 115 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 116 | l_ptr->max_pkt_probes = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 119 | static u32 link_next_sent(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 120 | { |
| 121 | if (l_ptr->next_out) |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 122 | return buf_seqno(l_ptr->next_out); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 123 | return mod(l_ptr->next_out_no); |
| 124 | } |
| 125 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 126 | static u32 link_last_sent(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 127 | { |
| 128 | return mod(link_next_sent(l_ptr) - 1); |
| 129 | } |
| 130 | |
| 131 | /* |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 132 | * Simple non-static link routines (i.e. referenced outside this file) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 133 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 134 | int tipc_link_is_up(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 135 | { |
| 136 | if (!l_ptr) |
| 137 | return 0; |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 138 | return link_working_working(l_ptr) || link_working_unknown(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 141 | int tipc_link_is_active(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 142 | { |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 143 | return (l_ptr->owner->active_links[0] == l_ptr) || |
| 144 | (l_ptr->owner->active_links[1] == l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 148 | * link_timeout - handle expiration of link timer |
| 149 | * @l_ptr: pointer to link |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 150 | * |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 151 | * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict |
| 152 | * with tipc_link_delete(). (There is no risk that the node will be deleted by |
| 153 | * another thread because tipc_link_delete() always cancels the link timer before |
| 154 | * tipc_node_delete() is called.) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 155 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 156 | static void link_timeout(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 157 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 158 | tipc_node_lock(l_ptr->owner); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 159 | |
| 160 | /* update counters used in statistical profiling of send traffic */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 161 | l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size; |
| 162 | l_ptr->stats.queue_sz_counts++; |
| 163 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 164 | if (l_ptr->first_out) { |
| 165 | struct tipc_msg *msg = buf_msg(l_ptr->first_out); |
| 166 | u32 length = msg_size(msg); |
| 167 | |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 168 | if ((msg_user(msg) == MSG_FRAGMENTER) && |
| 169 | (msg_type(msg) == FIRST_FRAGMENT)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 170 | length = msg_size(msg_get_wrapped(msg)); |
| 171 | } |
| 172 | if (length) { |
| 173 | l_ptr->stats.msg_lengths_total += length; |
| 174 | l_ptr->stats.msg_length_counts++; |
| 175 | if (length <= 64) |
| 176 | l_ptr->stats.msg_length_profile[0]++; |
| 177 | else if (length <= 256) |
| 178 | l_ptr->stats.msg_length_profile[1]++; |
| 179 | else if (length <= 1024) |
| 180 | l_ptr->stats.msg_length_profile[2]++; |
| 181 | else if (length <= 4096) |
| 182 | l_ptr->stats.msg_length_profile[3]++; |
| 183 | else if (length <= 16384) |
| 184 | l_ptr->stats.msg_length_profile[4]++; |
| 185 | else if (length <= 32768) |
| 186 | l_ptr->stats.msg_length_profile[5]++; |
| 187 | else |
| 188 | l_ptr->stats.msg_length_profile[6]++; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /* do all other link processing performed on a periodic basis */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 193 | |
| 194 | link_state_event(l_ptr, TIMEOUT_EVT); |
| 195 | |
| 196 | if (l_ptr->next_out) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 197 | tipc_link_push_queue(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 198 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 199 | tipc_node_unlock(l_ptr->owner); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 200 | } |
| 201 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 202 | static void link_set_timer(struct tipc_link *l_ptr, u32 time) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 203 | { |
| 204 | k_start_timer(&l_ptr->timer, time); |
| 205 | } |
| 206 | |
| 207 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 208 | * tipc_link_create - create a new link |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 209 | * @n_ptr: pointer to associated node |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 210 | * @b_ptr: pointer to associated bearer |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 211 | * @media_addr: media address to use when sending messages over link |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 212 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 213 | * Returns pointer to link. |
| 214 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 215 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 216 | struct tipc_bearer *b_ptr, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 217 | const struct tipc_media_addr *media_addr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 218 | { |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 219 | struct tipc_link *l_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 220 | struct tipc_msg *msg; |
| 221 | char *if_name; |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 222 | char addr_string[16]; |
| 223 | u32 peer = n_ptr->addr; |
| 224 | |
| 225 | if (n_ptr->link_cnt >= 2) { |
| 226 | tipc_addr_string_fill(addr_string, n_ptr->addr); |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 227 | pr_err("Attempt to establish third link to %s\n", addr_string); |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
| 230 | |
| 231 | if (n_ptr->links[b_ptr->identity]) { |
| 232 | tipc_addr_string_fill(addr_string, n_ptr->addr); |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 233 | pr_err("Attempt to establish second link on <%s> to %s\n", |
| 234 | b_ptr->name, addr_string); |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 235 | return NULL; |
| 236 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 237 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 238 | l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 239 | if (!l_ptr) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 240 | pr_warn("Link creation failed, no memory\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 241 | return NULL; |
| 242 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 243 | |
| 244 | l_ptr->addr = peer; |
Allan Stephens | 2d627b9 | 2011-01-07 13:00:11 -0500 | [diff] [blame] | 245 | if_name = strchr(b_ptr->name, ':') + 1; |
Allan Stephens | 062b4c9 | 2011-04-07 09:28:47 -0400 | [diff] [blame] | 246 | sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 247 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 248 | tipc_node(tipc_own_addr), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 249 | if_name, |
| 250 | tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); |
Allan Stephens | 062b4c9 | 2011-04-07 09:28:47 -0400 | [diff] [blame] | 251 | /* note: peer i/f name is updated by reset/activate message */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 252 | memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr)); |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 253 | l_ptr->owner = n_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 254 | l_ptr->checkpoint = 1; |
Allan Stephens | f882cb76 | 2011-04-07 09:43:27 -0400 | [diff] [blame] | 255 | l_ptr->peer_session = INVALID_SESSION; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 256 | l_ptr->b_ptr = b_ptr; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 257 | link_set_supervision_props(l_ptr, b_ptr->tolerance); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 258 | l_ptr->state = RESET_UNKNOWN; |
| 259 | |
| 260 | l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg; |
| 261 | msg = l_ptr->pmsg; |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 262 | tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 263 | msg_set_size(msg, sizeof(l_ptr->proto_msg)); |
Allan Stephens | a686e68 | 2008-06-04 17:29:39 -0700 | [diff] [blame] | 264 | msg_set_session(msg, (tipc_random & 0xffff)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 265 | msg_set_bearer_id(msg, b_ptr->identity); |
| 266 | strcpy((char *)msg_data(msg), if_name); |
| 267 | |
| 268 | l_ptr->priority = b_ptr->priority; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 269 | tipc_link_set_queue_limits(l_ptr, b_ptr->window); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 270 | |
| 271 | link_init_max_pkt(l_ptr); |
| 272 | |
| 273 | l_ptr->next_out_no = 1; |
| 274 | INIT_LIST_HEAD(&l_ptr->waiting_ports); |
| 275 | |
| 276 | link_reset_statistics(l_ptr); |
| 277 | |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 278 | tipc_node_attach_link(n_ptr, l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 279 | |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 280 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, |
| 281 | (unsigned long)l_ptr); |
Florian Westphal | 94571065 | 2007-07-26 00:05:07 -0700 | [diff] [blame] | 282 | list_add_tail(&l_ptr->link_list, &b_ptr->links); |
Jon Paul Maloy | 581465f | 2014-01-07 17:02:44 -0500 | [diff] [blame] | 283 | |
| 284 | link_state_event(l_ptr, STARTING_EVT); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 285 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 286 | return l_ptr; |
| 287 | } |
| 288 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 289 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 290 | * tipc_link_delete - delete a link |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 291 | * @l_ptr: pointer to link |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 292 | * |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 293 | * Note: 'tipc_net_lock' is write_locked, bearer is locked. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 294 | * This routine must not grab the node lock until after link timer cancellation |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 295 | * to avoid a potential deadlock situation. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 296 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 297 | void tipc_link_delete(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 298 | { |
| 299 | if (!l_ptr) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 300 | pr_err("Attempt to delete non-existent link\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 301 | return; |
| 302 | } |
| 303 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 304 | k_cancel_timer(&l_ptr->timer); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 305 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 306 | tipc_node_lock(l_ptr->owner); |
| 307 | tipc_link_reset(l_ptr); |
| 308 | tipc_node_detach_link(l_ptr->owner, l_ptr); |
Jon Paul Maloy | 581465f | 2014-01-07 17:02:44 -0500 | [diff] [blame] | 309 | tipc_link_purge_queues(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 310 | list_del_init(&l_ptr->link_list); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 311 | tipc_node_unlock(l_ptr->owner); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 312 | k_term_timer(&l_ptr->timer); |
| 313 | kfree(l_ptr); |
| 314 | } |
| 315 | |
Ying Xue | 8d8439b | 2014-02-13 17:29:07 -0500 | [diff] [blame^] | 316 | void tipc_link_delete_list(struct tipc_bearer *b_ptr) |
| 317 | { |
| 318 | struct tipc_link *l_ptr; |
| 319 | struct tipc_link *temp_l_ptr; |
| 320 | |
| 321 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { |
| 322 | tipc_link_delete(l_ptr); |
| 323 | } |
| 324 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 325 | |
| 326 | /** |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 327 | * link_schedule_port - schedule port for deferred sending |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 328 | * @l_ptr: pointer to link |
| 329 | * @origport: reference to sending port |
| 330 | * @sz: amount of data to be sent |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 331 | * |
| 332 | * Schedules port for renewed sending of messages after link congestion |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 333 | * has abated. |
| 334 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 335 | static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 336 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 337 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 338 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 339 | spin_lock_bh(&tipc_port_list_lock); |
| 340 | p_ptr = tipc_port_lock(origport); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 341 | if (p_ptr) { |
| 342 | if (!p_ptr->wakeup) |
| 343 | goto exit; |
| 344 | if (!list_empty(&p_ptr->wait_list)) |
| 345 | goto exit; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 346 | p_ptr->congested = 1; |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 347 | p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 348 | list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports); |
| 349 | l_ptr->stats.link_congs++; |
| 350 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 351 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 352 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 353 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 354 | return -ELINKCONG; |
| 355 | } |
| 356 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 357 | void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 358 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 359 | struct tipc_port *p_ptr; |
| 360 | struct tipc_port *temp_p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 361 | int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size; |
| 362 | |
| 363 | if (all) |
| 364 | win = 100000; |
| 365 | if (win <= 0) |
| 366 | return; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 367 | if (!spin_trylock_bh(&tipc_port_list_lock)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 368 | return; |
| 369 | if (link_congested(l_ptr)) |
| 370 | goto exit; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 371 | list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 372 | wait_list) { |
| 373 | if (win <= 0) |
| 374 | break; |
| 375 | list_del_init(&p_ptr->wait_list); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 376 | spin_lock_bh(p_ptr->lock); |
| 377 | p_ptr->congested = 0; |
| 378 | p_ptr->wakeup(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 379 | win -= p_ptr->waiting_pkts; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 380 | spin_unlock_bh(p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 384 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 385 | } |
| 386 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 387 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 388 | * link_release_outqueue - purge link's outbound message queue |
| 389 | * @l_ptr: pointer to link |
| 390 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 391 | static void link_release_outqueue(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 392 | { |
Ying Xue | d77b383 | 2013-12-10 20:45:38 -0800 | [diff] [blame] | 393 | kfree_skb_list(l_ptr->first_out); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 394 | l_ptr->first_out = NULL; |
| 395 | l_ptr->out_queue_size = 0; |
| 396 | } |
| 397 | |
| 398 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 399 | * tipc_link_reset_fragments - purge link's inbound message fragments queue |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 400 | * @l_ptr: pointer to link |
| 401 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 402 | void tipc_link_reset_fragments(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 403 | { |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 404 | kfree_skb(l_ptr->reasm_head); |
| 405 | l_ptr->reasm_head = NULL; |
| 406 | l_ptr->reasm_tail = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 407 | } |
| 408 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 409 | /** |
Jon Paul Maloy | 581465f | 2014-01-07 17:02:44 -0500 | [diff] [blame] | 410 | * tipc_link_purge_queues - purge all pkt queues associated with link |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 411 | * @l_ptr: pointer to link |
| 412 | */ |
Jon Paul Maloy | 581465f | 2014-01-07 17:02:44 -0500 | [diff] [blame] | 413 | void tipc_link_purge_queues(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 414 | { |
Ying Xue | d77b383 | 2013-12-10 20:45:38 -0800 | [diff] [blame] | 415 | kfree_skb_list(l_ptr->oldest_deferred_in); |
| 416 | kfree_skb_list(l_ptr->first_out); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 417 | tipc_link_reset_fragments(l_ptr); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 418 | kfree_skb(l_ptr->proto_msg_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 419 | l_ptr->proto_msg_queue = NULL; |
| 420 | } |
| 421 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 422 | void tipc_link_reset(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 423 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 424 | u32 prev_state = l_ptr->state; |
| 425 | u32 checkpoint = l_ptr->next_in_no; |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 426 | int was_active_link = tipc_link_is_active(l_ptr); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 427 | |
Allan Stephens | a686e68 | 2008-06-04 17:29:39 -0700 | [diff] [blame] | 428 | msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 429 | |
Allan Stephens | a686e68 | 2008-06-04 17:29:39 -0700 | [diff] [blame] | 430 | /* Link is down, accept any session */ |
| 431 | l_ptr->peer_session = INVALID_SESSION; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 432 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 433 | /* Prepare for max packet size negotiation */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 434 | link_init_max_pkt(l_ptr); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 435 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 436 | l_ptr->state = RESET_UNKNOWN; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 437 | |
| 438 | if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET)) |
| 439 | return; |
| 440 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 441 | tipc_node_link_down(l_ptr->owner, l_ptr); |
| 442 | tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr); |
Paul Gortmaker | 7368ddf | 2010-10-12 14:25:58 +0000 | [diff] [blame] | 443 | |
Jon Paul Maloy | b9d4c33 | 2014-01-07 17:02:42 -0500 | [diff] [blame] | 444 | if (was_active_link && tipc_node_active_links(l_ptr->owner)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 445 | l_ptr->reset_checkpoint = checkpoint; |
| 446 | l_ptr->exp_msg_count = START_CHANGEOVER; |
| 447 | } |
| 448 | |
| 449 | /* Clean up all queues: */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 450 | link_release_outqueue(l_ptr); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 451 | kfree_skb(l_ptr->proto_msg_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 452 | l_ptr->proto_msg_queue = NULL; |
Ying Xue | d77b383 | 2013-12-10 20:45:38 -0800 | [diff] [blame] | 453 | kfree_skb_list(l_ptr->oldest_deferred_in); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 454 | if (!list_empty(&l_ptr->waiting_ports)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 455 | tipc_link_wakeup_ports(l_ptr, 1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 456 | |
| 457 | l_ptr->retransm_queue_head = 0; |
| 458 | l_ptr->retransm_queue_size = 0; |
| 459 | l_ptr->last_out = NULL; |
| 460 | l_ptr->first_out = NULL; |
| 461 | l_ptr->next_out = NULL; |
| 462 | l_ptr->unacked_window = 0; |
| 463 | l_ptr->checkpoint = 1; |
| 464 | l_ptr->next_out_no = 1; |
| 465 | l_ptr->deferred_inqueue_sz = 0; |
| 466 | l_ptr->oldest_deferred_in = NULL; |
| 467 | l_ptr->newest_deferred_in = NULL; |
| 468 | l_ptr->fsm_msg_cnt = 0; |
| 469 | l_ptr->stale_count = 0; |
| 470 | link_reset_statistics(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Ying Xue | e0ca2c3 | 2014-02-13 17:29:06 -0500 | [diff] [blame] | 473 | void tipc_link_reset_list(struct tipc_bearer *b_ptr) |
| 474 | { |
| 475 | struct tipc_link *l_ptr; |
| 476 | |
| 477 | list_for_each_entry(l_ptr, &b_ptr->links, link_list) { |
| 478 | struct tipc_node *n_ptr = l_ptr->owner; |
| 479 | |
| 480 | spin_lock_bh(&n_ptr->lock); |
| 481 | tipc_link_reset(l_ptr); |
| 482 | spin_unlock_bh(&n_ptr->lock); |
| 483 | } |
| 484 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 485 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 486 | static void link_activate(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 487 | { |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 488 | l_ptr->next_in_no = l_ptr->stats.recv_info = 1; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 489 | tipc_node_link_up(l_ptr->owner, l_ptr); |
| 490 | tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** |
| 494 | * link_state_event - link finite state machine |
| 495 | * @l_ptr: pointer to link |
| 496 | * @event: state machine event to process |
| 497 | */ |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 498 | static void link_state_event(struct tipc_link *l_ptr, unsigned int event) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 499 | { |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 500 | struct tipc_link *other; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 501 | u32 cont_intv = l_ptr->continuity_interval; |
| 502 | |
| 503 | if (!l_ptr->started && (event != STARTING_EVT)) |
| 504 | return; /* Not yet. */ |
| 505 | |
Ying Xue | 77a7e07 | 2013-12-10 20:45:44 -0800 | [diff] [blame] | 506 | /* Check whether changeover is going on */ |
| 507 | if (l_ptr->exp_msg_count) { |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 508 | if (event == TIMEOUT_EVT) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 509 | link_set_timer(l_ptr, cont_intv); |
Ying Xue | 77a7e07 | 2013-12-10 20:45:44 -0800 | [diff] [blame] | 510 | return; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 511 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 512 | |
| 513 | switch (l_ptr->state) { |
| 514 | case WORKING_WORKING: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 515 | switch (event) { |
| 516 | case TRAFFIC_MSG_EVT: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 517 | case ACTIVATE_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 518 | break; |
| 519 | case TIMEOUT_EVT: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 520 | if (l_ptr->next_in_no != l_ptr->checkpoint) { |
| 521 | l_ptr->checkpoint = l_ptr->next_in_no; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 522 | if (tipc_bclink_acks_missing(l_ptr->owner)) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 523 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 524 | 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 525 | l_ptr->fsm_msg_cnt++; |
| 526 | } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 527 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 528 | 1, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 529 | l_ptr->fsm_msg_cnt++; |
| 530 | } |
| 531 | link_set_timer(l_ptr, cont_intv); |
| 532 | break; |
| 533 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 534 | l_ptr->state = WORKING_UNKNOWN; |
| 535 | l_ptr->fsm_msg_cnt = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 536 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 537 | l_ptr->fsm_msg_cnt++; |
| 538 | link_set_timer(l_ptr, cont_intv / 4); |
| 539 | break; |
| 540 | case RESET_MSG: |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 541 | pr_info("%s<%s>, requested by peer\n", link_rst_msg, |
| 542 | l_ptr->name); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 543 | tipc_link_reset(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 544 | l_ptr->state = RESET_RESET; |
| 545 | l_ptr->fsm_msg_cnt = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 546 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 547 | l_ptr->fsm_msg_cnt++; |
| 548 | link_set_timer(l_ptr, cont_intv); |
| 549 | break; |
| 550 | default: |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 551 | pr_err("%s%u in WW state\n", link_unk_evt, event); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 552 | } |
| 553 | break; |
| 554 | case WORKING_UNKNOWN: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 555 | switch (event) { |
| 556 | case TRAFFIC_MSG_EVT: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 557 | case ACTIVATE_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 558 | l_ptr->state = WORKING_WORKING; |
| 559 | l_ptr->fsm_msg_cnt = 0; |
| 560 | link_set_timer(l_ptr, cont_intv); |
| 561 | break; |
| 562 | case RESET_MSG: |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 563 | pr_info("%s<%s>, requested by peer while probing\n", |
| 564 | link_rst_msg, l_ptr->name); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 565 | tipc_link_reset(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 566 | l_ptr->state = RESET_RESET; |
| 567 | l_ptr->fsm_msg_cnt = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 568 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 569 | l_ptr->fsm_msg_cnt++; |
| 570 | link_set_timer(l_ptr, cont_intv); |
| 571 | break; |
| 572 | case TIMEOUT_EVT: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 573 | if (l_ptr->next_in_no != l_ptr->checkpoint) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 574 | l_ptr->state = WORKING_WORKING; |
| 575 | l_ptr->fsm_msg_cnt = 0; |
| 576 | l_ptr->checkpoint = l_ptr->next_in_no; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 577 | if (tipc_bclink_acks_missing(l_ptr->owner)) { |
| 578 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
| 579 | 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 580 | l_ptr->fsm_msg_cnt++; |
| 581 | } |
| 582 | link_set_timer(l_ptr, cont_intv); |
| 583 | } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 584 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 585 | 1, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 586 | l_ptr->fsm_msg_cnt++; |
| 587 | link_set_timer(l_ptr, cont_intv / 4); |
| 588 | } else { /* Link has failed */ |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 589 | pr_warn("%s<%s>, peer not responding\n", |
| 590 | link_rst_msg, l_ptr->name); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 591 | tipc_link_reset(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 592 | l_ptr->state = RESET_UNKNOWN; |
| 593 | l_ptr->fsm_msg_cnt = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 594 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, |
| 595 | 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 596 | l_ptr->fsm_msg_cnt++; |
| 597 | link_set_timer(l_ptr, cont_intv); |
| 598 | } |
| 599 | break; |
| 600 | default: |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 601 | pr_err("%s%u in WU state\n", link_unk_evt, event); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 602 | } |
| 603 | break; |
| 604 | case RESET_UNKNOWN: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 605 | switch (event) { |
| 606 | case TRAFFIC_MSG_EVT: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 607 | break; |
| 608 | case ACTIVATE_MSG: |
| 609 | other = l_ptr->owner->active_links[0]; |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 610 | if (other && link_working_unknown(other)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 611 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 612 | l_ptr->state = WORKING_WORKING; |
| 613 | l_ptr->fsm_msg_cnt = 0; |
| 614 | link_activate(l_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 615 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 616 | l_ptr->fsm_msg_cnt++; |
Jon Maloy | c64f7a6 | 2012-11-16 13:51:31 +0800 | [diff] [blame] | 617 | if (l_ptr->owner->working_links == 1) |
| 618 | tipc_link_send_sync(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 619 | link_set_timer(l_ptr, cont_intv); |
| 620 | break; |
| 621 | case RESET_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 622 | l_ptr->state = RESET_RESET; |
| 623 | l_ptr->fsm_msg_cnt = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 624 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 625 | l_ptr->fsm_msg_cnt++; |
| 626 | link_set_timer(l_ptr, cont_intv); |
| 627 | break; |
| 628 | case STARTING_EVT: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 629 | l_ptr->started = 1; |
| 630 | /* fall through */ |
| 631 | case TIMEOUT_EVT: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 632 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 633 | l_ptr->fsm_msg_cnt++; |
| 634 | link_set_timer(l_ptr, cont_intv); |
| 635 | break; |
| 636 | default: |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 637 | pr_err("%s%u in RU state\n", link_unk_evt, event); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 638 | } |
| 639 | break; |
| 640 | case RESET_RESET: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 641 | switch (event) { |
| 642 | case TRAFFIC_MSG_EVT: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 643 | case ACTIVATE_MSG: |
| 644 | other = l_ptr->owner->active_links[0]; |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 645 | if (other && link_working_unknown(other)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 646 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 647 | l_ptr->state = WORKING_WORKING; |
| 648 | l_ptr->fsm_msg_cnt = 0; |
| 649 | link_activate(l_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 650 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 651 | l_ptr->fsm_msg_cnt++; |
Jon Maloy | c64f7a6 | 2012-11-16 13:51:31 +0800 | [diff] [blame] | 652 | if (l_ptr->owner->working_links == 1) |
| 653 | tipc_link_send_sync(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 654 | link_set_timer(l_ptr, cont_intv); |
| 655 | break; |
| 656 | case RESET_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 657 | break; |
| 658 | case TIMEOUT_EVT: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 659 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 660 | l_ptr->fsm_msg_cnt++; |
| 661 | link_set_timer(l_ptr, cont_intv); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 662 | break; |
| 663 | default: |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 664 | pr_err("%s%u in RR state\n", link_unk_evt, event); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 665 | } |
| 666 | break; |
| 667 | default: |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 668 | pr_err("Unknown link state %u/%u\n", l_ptr->state, event); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
| 672 | /* |
| 673 | * link_bundle_buf(): Append contents of a buffer to |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 674 | * the tail of an existing one. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 675 | */ |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 676 | static int link_bundle_buf(struct tipc_link *l_ptr, struct sk_buff *bundler, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 677 | struct sk_buff *buf) |
| 678 | { |
| 679 | struct tipc_msg *bundler_msg = buf_msg(bundler); |
| 680 | struct tipc_msg *msg = buf_msg(buf); |
| 681 | u32 size = msg_size(msg); |
Allan Stephens | e49060c | 2006-06-29 12:32:46 -0700 | [diff] [blame] | 682 | u32 bundle_size = msg_size(bundler_msg); |
| 683 | u32 to_pos = align(bundle_size); |
| 684 | u32 pad = to_pos - bundle_size; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 685 | |
| 686 | if (msg_user(bundler_msg) != MSG_BUNDLER) |
| 687 | return 0; |
| 688 | if (msg_type(bundler_msg) != OPEN_MSG) |
| 689 | return 0; |
Allan Stephens | e49060c | 2006-06-29 12:32:46 -0700 | [diff] [blame] | 690 | if (skb_tailroom(bundler) < (pad + size)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 691 | return 0; |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 692 | if (l_ptr->max_pkt < (to_pos + size)) |
Allan Stephens | 863fae6 | 2006-07-03 19:39:36 -0700 | [diff] [blame] | 693 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 694 | |
Allan Stephens | e49060c | 2006-06-29 12:32:46 -0700 | [diff] [blame] | 695 | skb_put(bundler, pad + size); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 696 | skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 697 | msg_set_size(bundler_msg, to_pos + size); |
| 698 | msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 699 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 700 | l_ptr->stats.sent_bundled++; |
| 701 | return 1; |
| 702 | } |
| 703 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 704 | static void link_add_to_outqueue(struct tipc_link *l_ptr, |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 705 | struct sk_buff *buf, |
| 706 | struct tipc_msg *msg) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 707 | { |
| 708 | u32 ack = mod(l_ptr->next_in_no - 1); |
| 709 | u32 seqno = mod(l_ptr->next_out_no++); |
| 710 | |
| 711 | msg_set_word(msg, 2, ((ack << 16) | seqno)); |
| 712 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
| 713 | buf->next = NULL; |
| 714 | if (l_ptr->first_out) { |
| 715 | l_ptr->last_out->next = buf; |
| 716 | l_ptr->last_out = buf; |
| 717 | } else |
| 718 | l_ptr->first_out = l_ptr->last_out = buf; |
Allan Stephens | 9bd80b6 | 2011-01-18 15:02:50 -0500 | [diff] [blame] | 719 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 720 | l_ptr->out_queue_size++; |
Allan Stephens | 9bd80b6 | 2011-01-18 15:02:50 -0500 | [diff] [blame] | 721 | if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz) |
| 722 | l_ptr->stats.max_queue_sz = l_ptr->out_queue_size; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 723 | } |
| 724 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 725 | static void link_add_chain_to_outqueue(struct tipc_link *l_ptr, |
Allan Stephens | dc63d91 | 2011-04-21 11:50:42 -0400 | [diff] [blame] | 726 | struct sk_buff *buf_chain, |
| 727 | u32 long_msgno) |
| 728 | { |
| 729 | struct sk_buff *buf; |
| 730 | struct tipc_msg *msg; |
| 731 | |
| 732 | if (!l_ptr->next_out) |
| 733 | l_ptr->next_out = buf_chain; |
| 734 | while (buf_chain) { |
| 735 | buf = buf_chain; |
| 736 | buf_chain = buf_chain->next; |
| 737 | |
| 738 | msg = buf_msg(buf); |
| 739 | msg_set_long_msgno(msg, long_msgno); |
| 740 | link_add_to_outqueue(l_ptr, buf, msg); |
| 741 | } |
| 742 | } |
| 743 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 744 | /* |
| 745 | * tipc_link_send_buf() is the 'full path' for messages, called from |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 746 | * inside TIPC when the 'fast path' in tipc_send_buf |
| 747 | * has failed, and from link_send() |
| 748 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 749 | int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 750 | { |
| 751 | struct tipc_msg *msg = buf_msg(buf); |
| 752 | u32 size = msg_size(msg); |
| 753 | u32 dsz = msg_data_sz(msg); |
| 754 | u32 queue_size = l_ptr->out_queue_size; |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 755 | u32 imp = tipc_msg_tot_importance(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 756 | u32 queue_limit = l_ptr->queue_limit[imp]; |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 757 | u32 max_packet = l_ptr->max_pkt; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 758 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 759 | /* Match msg importance against queue limits: */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 760 | if (unlikely(queue_size >= queue_limit)) { |
| 761 | if (imp <= TIPC_CRITICAL_IMPORTANCE) { |
Allan Stephens | bebc55a | 2011-04-19 10:17:58 -0400 | [diff] [blame] | 762 | link_schedule_port(l_ptr, msg_origport(msg), size); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 763 | kfree_skb(buf); |
Allan Stephens | bebc55a | 2011-04-19 10:17:58 -0400 | [diff] [blame] | 764 | return -ELINKCONG; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 765 | } |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 766 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 767 | if (imp > CONN_MANAGER) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 768 | pr_warn("%s<%s>, send queue full", link_rst_msg, |
| 769 | l_ptr->name); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 770 | tipc_link_reset(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 771 | } |
| 772 | return dsz; |
| 773 | } |
| 774 | |
| 775 | /* Fragmentation needed ? */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 776 | if (size > max_packet) |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 777 | return link_send_long_buf(l_ptr, buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 778 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 779 | /* Packet can be queued or sent. */ |
Erik Hugne | 512137e | 2013-12-06 10:08:00 -0500 | [diff] [blame] | 780 | if (likely(!link_congested(l_ptr))) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 781 | link_add_to_outqueue(l_ptr, buf, msg); |
| 782 | |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 783 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
| 784 | l_ptr->unacked_window = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 785 | return dsz; |
| 786 | } |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 787 | /* Congestion: can message be bundled ? */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 788 | if ((msg_user(msg) != CHANGEOVER_PROTOCOL) && |
| 789 | (msg_user(msg) != MSG_FRAGMENTER)) { |
| 790 | |
| 791 | /* Try adding message to an existing bundle */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 792 | if (l_ptr->next_out && |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 793 | link_bundle_buf(l_ptr, l_ptr->last_out, buf)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 794 | return dsz; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 795 | |
| 796 | /* Try creating a new bundle */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 797 | if (size <= max_packet * 2 / 3) { |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 798 | struct sk_buff *bundler = tipc_buf_acquire(max_packet); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 799 | struct tipc_msg bundler_hdr; |
| 800 | |
| 801 | if (bundler) { |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 802 | tipc_msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG, |
Allan Stephens | 7571521 | 2008-06-04 17:37:34 -0700 | [diff] [blame] | 803 | INT_H_SIZE, l_ptr->addr); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 804 | skb_copy_to_linear_data(bundler, &bundler_hdr, |
| 805 | INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 806 | skb_trim(bundler, INT_H_SIZE); |
| 807 | link_bundle_buf(l_ptr, bundler, buf); |
| 808 | buf = bundler; |
| 809 | msg = buf_msg(buf); |
| 810 | l_ptr->stats.sent_bundles++; |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | if (!l_ptr->next_out) |
| 815 | l_ptr->next_out = buf; |
| 816 | link_add_to_outqueue(l_ptr, buf, msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 817 | return dsz; |
| 818 | } |
| 819 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 820 | /* |
| 821 | * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 822 | * not been selected yet, and the the owner node is not locked |
| 823 | * Called by TIPC internal users, e.g. the name distributor |
| 824 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 825 | int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 826 | { |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 827 | struct tipc_link *l_ptr; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 828 | struct tipc_node *n_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 829 | int res = -ELINKCONG; |
| 830 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 831 | read_lock_bh(&tipc_net_lock); |
Allan Stephens | 51a8e4d | 2010-12-31 18:59:18 +0000 | [diff] [blame] | 832 | n_ptr = tipc_node_find(dest); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 833 | if (n_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 834 | tipc_node_lock(n_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 835 | l_ptr = n_ptr->active_links[selector & 1]; |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 836 | if (l_ptr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 837 | res = tipc_link_send_buf(l_ptr, buf); |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 838 | else |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 839 | kfree_skb(buf); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 840 | tipc_node_unlock(n_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 841 | } else { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 842 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 843 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 844 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 845 | return res; |
| 846 | } |
| 847 | |
Jon Maloy | c64f7a6 | 2012-11-16 13:51:31 +0800 | [diff] [blame] | 848 | /* |
| 849 | * tipc_link_send_sync - synchronize broadcast link endpoints. |
| 850 | * |
| 851 | * Give a newly added peer node the sequence number where it should |
| 852 | * start receiving and acking broadcast packets. |
| 853 | * |
| 854 | * Called with node locked |
| 855 | */ |
| 856 | static void tipc_link_send_sync(struct tipc_link *l) |
| 857 | { |
| 858 | struct sk_buff *buf; |
| 859 | struct tipc_msg *msg; |
| 860 | |
| 861 | buf = tipc_buf_acquire(INT_H_SIZE); |
| 862 | if (!buf) |
| 863 | return; |
| 864 | |
| 865 | msg = buf_msg(buf); |
| 866 | tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, l->addr); |
| 867 | msg_set_last_bcast(msg, l->owner->bclink.acked); |
| 868 | link_add_chain_to_outqueue(l, buf, 0); |
| 869 | tipc_link_push_queue(l); |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * tipc_link_recv_sync - synchronize broadcast link endpoints. |
| 874 | * Receive the sequence number where we should start receiving and |
| 875 | * acking broadcast packets from a newly added peer node, and open |
| 876 | * up for reception of such packets. |
| 877 | * |
| 878 | * Called with node locked |
| 879 | */ |
| 880 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf) |
| 881 | { |
| 882 | struct tipc_msg *msg = buf_msg(buf); |
| 883 | |
| 884 | n->bclink.last_sent = n->bclink.last_in = msg_last_bcast(msg); |
| 885 | n->bclink.recv_permitted = true; |
| 886 | kfree_skb(buf); |
| 887 | } |
| 888 | |
| 889 | /* |
Allan Stephens | 9aa88c2 | 2011-05-31 13:38:02 -0400 | [diff] [blame] | 890 | * tipc_link_send_names - send name table entries to new neighbor |
| 891 | * |
| 892 | * Send routine for bulk delivery of name table messages when contact |
| 893 | * with a new neighbor occurs. No link congestion checking is performed |
| 894 | * because name table messages *must* be delivered. The messages must be |
| 895 | * small enough not to require fragmentation. |
| 896 | * Called without any locks held. |
| 897 | */ |
Allan Stephens | 9aa88c2 | 2011-05-31 13:38:02 -0400 | [diff] [blame] | 898 | void tipc_link_send_names(struct list_head *message_list, u32 dest) |
| 899 | { |
| 900 | struct tipc_node *n_ptr; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 901 | struct tipc_link *l_ptr; |
Allan Stephens | 9aa88c2 | 2011-05-31 13:38:02 -0400 | [diff] [blame] | 902 | struct sk_buff *buf; |
| 903 | struct sk_buff *temp_buf; |
| 904 | |
| 905 | if (list_empty(message_list)) |
| 906 | return; |
| 907 | |
| 908 | read_lock_bh(&tipc_net_lock); |
| 909 | n_ptr = tipc_node_find(dest); |
| 910 | if (n_ptr) { |
| 911 | tipc_node_lock(n_ptr); |
| 912 | l_ptr = n_ptr->active_links[0]; |
| 913 | if (l_ptr) { |
| 914 | /* convert circular list to linear list */ |
| 915 | ((struct sk_buff *)message_list->prev)->next = NULL; |
| 916 | link_add_chain_to_outqueue(l_ptr, |
| 917 | (struct sk_buff *)message_list->next, 0); |
| 918 | tipc_link_push_queue(l_ptr); |
| 919 | INIT_LIST_HEAD(message_list); |
| 920 | } |
| 921 | tipc_node_unlock(n_ptr); |
| 922 | } |
| 923 | read_unlock_bh(&tipc_net_lock); |
| 924 | |
| 925 | /* discard the messages if they couldn't be sent */ |
Allan Stephens | 9aa88c2 | 2011-05-31 13:38:02 -0400 | [diff] [blame] | 926 | list_for_each_safe(buf, temp_buf, ((struct sk_buff *)message_list)) { |
| 927 | list_del((struct list_head *)buf); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 928 | kfree_skb(buf); |
Allan Stephens | 9aa88c2 | 2011-05-31 13:38:02 -0400 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | |
| 932 | /* |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 933 | * link_send_buf_fast: Entry for data messages where the |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 934 | * destination link is known and the header is complete, |
| 935 | * inclusive total message length. Very time critical. |
| 936 | * Link is locked. Returns user data length. |
| 937 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 938 | static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf, |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 939 | u32 *used_max_pkt) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 940 | { |
| 941 | struct tipc_msg *msg = buf_msg(buf); |
| 942 | int res = msg_data_sz(msg); |
| 943 | |
| 944 | if (likely(!link_congested(l_ptr))) { |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 945 | if (likely(msg_size(msg) <= l_ptr->max_pkt)) { |
Erik Hugne | 512137e | 2013-12-06 10:08:00 -0500 | [diff] [blame] | 946 | link_add_to_outqueue(l_ptr, buf, msg); |
| 947 | tipc_bearer_send(l_ptr->b_ptr, buf, |
| 948 | &l_ptr->media_addr); |
| 949 | l_ptr->unacked_window = 0; |
| 950 | return res; |
| 951 | } |
| 952 | else |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 953 | *used_max_pkt = l_ptr->max_pkt; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 954 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 955 | return tipc_link_send_buf(l_ptr, buf); /* All other cases */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 956 | } |
| 957 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 958 | /* |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 959 | * tipc_link_send_sections_fast: Entry for messages where the |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 960 | * destination processor is known and the header is complete, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 961 | * except for total message length. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 962 | * Returns user data length or errno. |
| 963 | */ |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 964 | int tipc_link_send_sections_fast(struct tipc_port *sender, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 965 | struct iovec const *msg_sect, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 966 | unsigned int len, u32 destaddr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 967 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 968 | struct tipc_msg *hdr = &sender->phdr; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 969 | struct tipc_link *l_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 970 | struct sk_buff *buf; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 971 | struct tipc_node *node; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 972 | int res; |
| 973 | u32 selector = msg_origport(hdr) & 1; |
| 974 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 975 | again: |
| 976 | /* |
| 977 | * Try building message using port's max_pkt hint. |
| 978 | * (Must not hold any locks while building message.) |
| 979 | */ |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 980 | res = tipc_msg_build(hdr, msg_sect, len, sender->max_pkt, &buf); |
Ying Xue | 7410f96 | 2013-06-17 10:54:49 -0400 | [diff] [blame] | 981 | /* Exit if build request was invalid */ |
| 982 | if (unlikely(res < 0)) |
| 983 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 984 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 985 | read_lock_bh(&tipc_net_lock); |
Allan Stephens | 51a8e4d | 2010-12-31 18:59:18 +0000 | [diff] [blame] | 986 | node = tipc_node_find(destaddr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 987 | if (likely(node)) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 988 | tipc_node_lock(node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 989 | l_ptr = node->active_links[selector]; |
| 990 | if (likely(l_ptr)) { |
| 991 | if (likely(buf)) { |
| 992 | res = link_send_buf_fast(l_ptr, buf, |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 993 | &sender->max_pkt); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 994 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 995 | tipc_node_unlock(node); |
| 996 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 997 | return res; |
| 998 | } |
| 999 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1000 | /* Exit if link (or bearer) is congested */ |
Erik Hugne | 512137e | 2013-12-06 10:08:00 -0500 | [diff] [blame] | 1001 | if (link_congested(l_ptr)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1002 | res = link_schedule_port(l_ptr, |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1003 | sender->ref, res); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1004 | goto exit; |
| 1005 | } |
| 1006 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1007 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1008 | * Message size exceeds max_pkt hint; update hint, |
| 1009 | * then re-try fast path or fragment the message |
| 1010 | */ |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1011 | sender->max_pkt = l_ptr->max_pkt; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1012 | tipc_node_unlock(node); |
| 1013 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1014 | |
| 1015 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1016 | if ((msg_hdr_sz(hdr) + res) <= sender->max_pkt) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1017 | goto again; |
| 1018 | |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1019 | return link_send_sections_long(sender, msg_sect, len, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1020 | destaddr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1021 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1022 | tipc_node_unlock(node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1023 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1024 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1025 | |
| 1026 | /* Couldn't find a link to the destination node */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1027 | if (buf) |
| 1028 | return tipc_reject_msg(buf, TIPC_ERR_NO_NODE); |
| 1029 | if (res >= 0) |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1030 | return tipc_port_reject_sections(sender, hdr, msg_sect, |
| 1031 | len, TIPC_ERR_NO_NODE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1032 | return res; |
| 1033 | } |
| 1034 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1035 | /* |
| 1036 | * link_send_sections_long(): Entry for long messages where the |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1037 | * destination node is known and the header is complete, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1038 | * inclusive total message length. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1039 | * Link and bearer congestion status have been checked to be ok, |
| 1040 | * and are ignored if they change. |
| 1041 | * |
| 1042 | * Note that fragments do not use the full link MTU so that they won't have |
| 1043 | * to undergo refragmentation if link changeover causes them to be sent |
| 1044 | * over another link with an additional tunnel header added as prefix. |
| 1045 | * (Refragmentation will still occur if the other link has a smaller MTU.) |
| 1046 | * |
| 1047 | * Returns user data length or errno. |
| 1048 | */ |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1049 | static int link_send_sections_long(struct tipc_port *sender, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1050 | struct iovec const *msg_sect, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1051 | unsigned int len, u32 destaddr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1052 | { |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1053 | struct tipc_link *l_ptr; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 1054 | struct tipc_node *node; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1055 | struct tipc_msg *hdr = &sender->phdr; |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1056 | u32 dsz = len; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1057 | u32 max_pkt, fragm_sz, rest; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1058 | struct tipc_msg fragm_hdr; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1059 | struct sk_buff *buf, *buf_chain, *prev; |
| 1060 | u32 fragm_crs, fragm_rest, hsz, sect_rest; |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 1061 | const unchar __user *sect_crs; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1062 | int curr_sect; |
| 1063 | u32 fragm_no; |
Ying Xue | 126c052 | 2013-06-17 10:54:50 -0400 | [diff] [blame] | 1064 | int res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1065 | |
| 1066 | again: |
| 1067 | fragm_no = 1; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1068 | max_pkt = sender->max_pkt - INT_H_SIZE; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1069 | /* leave room for tunnel header in case of link changeover */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1070 | fragm_sz = max_pkt - INT_H_SIZE; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1071 | /* leave room for fragmentation header in each fragment */ |
| 1072 | rest = dsz; |
| 1073 | fragm_crs = 0; |
| 1074 | fragm_rest = 0; |
| 1075 | sect_rest = 0; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 1076 | sect_crs = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1077 | curr_sect = -1; |
| 1078 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 1079 | /* Prepare reusable fragment header */ |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1080 | tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT, |
Allan Stephens | 7571521 | 2008-06-04 17:37:34 -0700 | [diff] [blame] | 1081 | INT_H_SIZE, msg_destnode(hdr)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1082 | msg_set_size(&fragm_hdr, max_pkt); |
| 1083 | msg_set_fragm_no(&fragm_hdr, 1); |
| 1084 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 1085 | /* Prepare header of first fragment */ |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 1086 | buf_chain = buf = tipc_buf_acquire(max_pkt); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1087 | if (!buf) |
| 1088 | return -ENOMEM; |
| 1089 | buf->next = NULL; |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1090 | skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1091 | hsz = msg_hdr_sz(hdr); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1092 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1093 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 1094 | /* Chop up message */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1095 | fragm_crs = INT_H_SIZE + hsz; |
| 1096 | fragm_rest = fragm_sz - hsz; |
| 1097 | |
| 1098 | do { /* For all sections */ |
| 1099 | u32 sz; |
| 1100 | |
| 1101 | if (!sect_rest) { |
| 1102 | sect_rest = msg_sect[++curr_sect].iov_len; |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 1103 | sect_crs = msg_sect[curr_sect].iov_base; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | if (sect_rest < fragm_rest) |
| 1107 | sz = sect_rest; |
| 1108 | else |
| 1109 | sz = fragm_rest; |
| 1110 | |
Ying Xue | f1733d7 | 2013-06-17 10:54:43 -0400 | [diff] [blame] | 1111 | if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) { |
Ying Xue | 126c052 | 2013-06-17 10:54:50 -0400 | [diff] [blame] | 1112 | res = -EFAULT; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1113 | error: |
Ying Xue | d77b383 | 2013-12-10 20:45:38 -0800 | [diff] [blame] | 1114 | kfree_skb_list(buf_chain); |
Ying Xue | 126c052 | 2013-06-17 10:54:50 -0400 | [diff] [blame] | 1115 | return res; |
Ying Xue | f1733d7 | 2013-06-17 10:54:43 -0400 | [diff] [blame] | 1116 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1117 | sect_crs += sz; |
| 1118 | sect_rest -= sz; |
| 1119 | fragm_crs += sz; |
| 1120 | fragm_rest -= sz; |
| 1121 | rest -= sz; |
| 1122 | |
| 1123 | if (!fragm_rest && rest) { |
| 1124 | |
| 1125 | /* Initiate new fragment: */ |
| 1126 | if (rest <= fragm_sz) { |
| 1127 | fragm_sz = rest; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1128 | msg_set_type(&fragm_hdr, LAST_FRAGMENT); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1129 | } else { |
| 1130 | msg_set_type(&fragm_hdr, FRAGMENT); |
| 1131 | } |
| 1132 | msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); |
| 1133 | msg_set_fragm_no(&fragm_hdr, ++fragm_no); |
| 1134 | prev = buf; |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 1135 | buf = tipc_buf_acquire(fragm_sz + INT_H_SIZE); |
Ying Xue | 126c052 | 2013-06-17 10:54:50 -0400 | [diff] [blame] | 1136 | if (!buf) { |
| 1137 | res = -ENOMEM; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1138 | goto error; |
Ying Xue | 126c052 | 2013-06-17 10:54:50 -0400 | [diff] [blame] | 1139 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1140 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1141 | buf->next = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1142 | prev->next = buf; |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1143 | skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1144 | fragm_crs = INT_H_SIZE; |
| 1145 | fragm_rest = fragm_sz; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1146 | } |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1147 | } while (rest > 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1148 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1149 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1150 | * Now we have a buffer chain. Select a link and check |
| 1151 | * that packet size is still OK |
| 1152 | */ |
Allan Stephens | 51a8e4d | 2010-12-31 18:59:18 +0000 | [diff] [blame] | 1153 | node = tipc_node_find(destaddr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1154 | if (likely(node)) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1155 | tipc_node_lock(node); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1156 | l_ptr = node->active_links[sender->ref & 1]; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1157 | if (!l_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1158 | tipc_node_unlock(node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1159 | goto reject; |
| 1160 | } |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 1161 | if (l_ptr->max_pkt < max_pkt) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1162 | sender->max_pkt = l_ptr->max_pkt; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1163 | tipc_node_unlock(node); |
Ying Xue | d77b383 | 2013-12-10 20:45:38 -0800 | [diff] [blame] | 1164 | kfree_skb_list(buf_chain); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1165 | goto again; |
| 1166 | } |
| 1167 | } else { |
| 1168 | reject: |
Ying Xue | d77b383 | 2013-12-10 20:45:38 -0800 | [diff] [blame] | 1169 | kfree_skb_list(buf_chain); |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1170 | return tipc_port_reject_sections(sender, hdr, msg_sect, |
| 1171 | len, TIPC_ERR_NO_NODE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1172 | } |
| 1173 | |
Allan Stephens | dc63d91 | 2011-04-21 11:50:42 -0400 | [diff] [blame] | 1174 | /* Append chain of fragments to send queue & send them */ |
Allan Stephens | e0f0859 | 2011-04-17 11:44:24 -0400 | [diff] [blame] | 1175 | l_ptr->long_msg_seq_no++; |
Allan Stephens | dc63d91 | 2011-04-21 11:50:42 -0400 | [diff] [blame] | 1176 | link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no); |
| 1177 | l_ptr->stats.sent_fragments += fragm_no; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1178 | l_ptr->stats.sent_fragmented++; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1179 | tipc_link_push_queue(l_ptr); |
| 1180 | tipc_node_unlock(node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1181 | return dsz; |
| 1182 | } |
| 1183 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1184 | /* |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1185 | * tipc_link_push_packet: Push one unsent packet to the media |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1186 | */ |
stephen hemminger | 9805696 | 2014-01-04 13:47:48 -0800 | [diff] [blame] | 1187 | static u32 tipc_link_push_packet(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1188 | { |
| 1189 | struct sk_buff *buf = l_ptr->first_out; |
| 1190 | u32 r_q_size = l_ptr->retransm_queue_size; |
| 1191 | u32 r_q_head = l_ptr->retransm_queue_head; |
| 1192 | |
| 1193 | /* Step to position where retransmission failed, if any, */ |
| 1194 | /* consider that buffers may have been released in meantime */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1195 | if (r_q_size && buf) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1196 | u32 last = lesser(mod(r_q_head + r_q_size), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1197 | link_last_sent(l_ptr)); |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1198 | u32 first = buf_seqno(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1199 | |
| 1200 | while (buf && less(first, r_q_head)) { |
| 1201 | first = mod(first + 1); |
| 1202 | buf = buf->next; |
| 1203 | } |
| 1204 | l_ptr->retransm_queue_head = r_q_head = first; |
| 1205 | l_ptr->retransm_queue_size = r_q_size = mod(last - first); |
| 1206 | } |
| 1207 | |
| 1208 | /* Continue retransmission now, if there is anything: */ |
Neil Horman | ca50910 | 2010-03-15 07:58:45 +0000 | [diff] [blame] | 1209 | if (r_q_size && buf) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1210 | msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1211 | msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 1212 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
| 1213 | l_ptr->retransm_queue_head = mod(++r_q_head); |
| 1214 | l_ptr->retransm_queue_size = --r_q_size; |
| 1215 | l_ptr->stats.retransmitted++; |
| 1216 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /* Send deferred protocol message, if any: */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1220 | buf = l_ptr->proto_msg_queue; |
| 1221 | if (buf) { |
| 1222 | msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1223 | msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 1224 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
| 1225 | l_ptr->unacked_window = 0; |
| 1226 | kfree_skb(buf); |
| 1227 | l_ptr->proto_msg_queue = NULL; |
| 1228 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | /* Send one deferred data message, if send window not full: */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1232 | buf = l_ptr->next_out; |
| 1233 | if (buf) { |
| 1234 | struct tipc_msg *msg = buf_msg(buf); |
| 1235 | u32 next = msg_seqno(msg); |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1236 | u32 first = buf_seqno(l_ptr->first_out); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1237 | |
| 1238 | if (mod(next - first) < l_ptr->queue_limit[0]) { |
| 1239 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1240 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 1241 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
| 1242 | if (msg_user(msg) == MSG_BUNDLER) |
| 1243 | msg_set_type(msg, CLOSED_MSG); |
| 1244 | l_ptr->next_out = buf->next; |
| 1245 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1246 | } |
| 1247 | } |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 1248 | return 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | /* |
| 1252 | * push_queue(): push out the unsent messages of a link where |
| 1253 | * congestion has abated. Node is locked |
| 1254 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1255 | void tipc_link_push_queue(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1256 | { |
| 1257 | u32 res; |
| 1258 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1259 | do { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1260 | res = tipc_link_push_packet(l_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1261 | } while (!res); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1264 | static void link_reset_all(unsigned long addr) |
| 1265 | { |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 1266 | struct tipc_node *n_ptr; |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1267 | char addr_string[16]; |
| 1268 | u32 i; |
| 1269 | |
| 1270 | read_lock_bh(&tipc_net_lock); |
| 1271 | n_ptr = tipc_node_find((u32)addr); |
| 1272 | if (!n_ptr) { |
| 1273 | read_unlock_bh(&tipc_net_lock); |
| 1274 | return; /* node no longer exists */ |
| 1275 | } |
| 1276 | |
| 1277 | tipc_node_lock(n_ptr); |
| 1278 | |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1279 | pr_warn("Resetting all links to %s\n", |
| 1280 | tipc_addr_string_fill(addr_string, n_ptr->addr)); |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1281 | |
| 1282 | for (i = 0; i < MAX_BEARERS; i++) { |
| 1283 | if (n_ptr->links[i]) { |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 1284 | link_print(n_ptr->links[i], "Resetting link\n"); |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1285 | tipc_link_reset(n_ptr->links[i]); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | tipc_node_unlock(n_ptr); |
| 1290 | read_unlock_bh(&tipc_net_lock); |
| 1291 | } |
| 1292 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1293 | static void link_retransmit_failure(struct tipc_link *l_ptr, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 1294 | struct sk_buff *buf) |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1295 | { |
| 1296 | struct tipc_msg *msg = buf_msg(buf); |
| 1297 | |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1298 | pr_warn("Retransmission failure on link <%s>\n", l_ptr->name); |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1299 | |
| 1300 | if (l_ptr->addr) { |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1301 | /* Handle failure on standard link */ |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 1302 | link_print(l_ptr, "Resetting link\n"); |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1303 | tipc_link_reset(l_ptr); |
| 1304 | |
| 1305 | } else { |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1306 | /* Handle failure on broadcast link */ |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 1307 | struct tipc_node *n_ptr; |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1308 | char addr_string[16]; |
| 1309 | |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1310 | pr_info("Msg seq number: %u, ", msg_seqno(msg)); |
| 1311 | pr_cont("Outstanding acks: %lu\n", |
| 1312 | (unsigned long) TIPC_SKB_CB(buf)->handle); |
Jeff Garzik | 617dbea | 2006-10-03 16:25:34 -0700 | [diff] [blame] | 1313 | |
Allan Stephens | 01d83ed | 2011-01-18 13:53:16 -0500 | [diff] [blame] | 1314 | n_ptr = tipc_bclink_retransmit_to(); |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1315 | tipc_node_lock(n_ptr); |
| 1316 | |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1317 | tipc_addr_string_fill(addr_string, n_ptr->addr); |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1318 | pr_info("Broadcast link info for %s\n", addr_string); |
Ying Xue | 389dd9b | 2012-11-16 13:51:30 +0800 | [diff] [blame] | 1319 | pr_info("Reception permitted: %d, Acked: %u\n", |
| 1320 | n_ptr->bclink.recv_permitted, |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1321 | n_ptr->bclink.acked); |
| 1322 | pr_info("Last in: %u, Oos state: %u, Last sent: %u\n", |
| 1323 | n_ptr->bclink.last_in, |
| 1324 | n_ptr->bclink.oos_state, |
| 1325 | n_ptr->bclink.last_sent); |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1326 | |
| 1327 | tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr); |
| 1328 | |
| 1329 | tipc_node_unlock(n_ptr); |
| 1330 | |
| 1331 | l_ptr->stale_count = 0; |
| 1332 | } |
| 1333 | } |
| 1334 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1335 | void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1336 | u32 retransmits) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1337 | { |
| 1338 | struct tipc_msg *msg; |
| 1339 | |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1340 | if (!buf) |
| 1341 | return; |
| 1342 | |
| 1343 | msg = buf_msg(buf); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1344 | |
Erik Hugne | 512137e | 2013-12-06 10:08:00 -0500 | [diff] [blame] | 1345 | /* Detect repeated retransmit failures */ |
| 1346 | if (l_ptr->last_retransmitted == msg_seqno(msg)) { |
| 1347 | if (++l_ptr->stale_count > 100) { |
| 1348 | link_retransmit_failure(l_ptr, buf); |
| 1349 | return; |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1350 | } |
| 1351 | } else { |
Erik Hugne | 512137e | 2013-12-06 10:08:00 -0500 | [diff] [blame] | 1352 | l_ptr->last_retransmitted = msg_seqno(msg); |
| 1353 | l_ptr->stale_count = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1354 | } |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1355 | |
Neil Horman | ca50910 | 2010-03-15 07:58:45 +0000 | [diff] [blame] | 1356 | while (retransmits && (buf != l_ptr->next_out) && buf) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1357 | msg = buf_msg(buf); |
| 1358 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1359 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 1360 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
| 1361 | buf = buf->next; |
| 1362 | retransmits--; |
| 1363 | l_ptr->stats.retransmitted++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1364 | } |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1365 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1366 | l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0; |
| 1367 | } |
| 1368 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1369 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1370 | * link_insert_deferred_queue - insert deferred messages back into receive chain |
| 1371 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1372 | static struct sk_buff *link_insert_deferred_queue(struct tipc_link *l_ptr, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1373 | struct sk_buff *buf) |
| 1374 | { |
| 1375 | u32 seq_no; |
| 1376 | |
| 1377 | if (l_ptr->oldest_deferred_in == NULL) |
| 1378 | return buf; |
| 1379 | |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1380 | seq_no = buf_seqno(l_ptr->oldest_deferred_in); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1381 | if (seq_no == mod(l_ptr->next_in_no)) { |
| 1382 | l_ptr->newest_deferred_in->next = buf; |
| 1383 | buf = l_ptr->oldest_deferred_in; |
| 1384 | l_ptr->oldest_deferred_in = NULL; |
| 1385 | l_ptr->deferred_inqueue_sz = 0; |
| 1386 | } |
| 1387 | return buf; |
| 1388 | } |
| 1389 | |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1390 | /** |
| 1391 | * link_recv_buf_validate - validate basic format of received message |
| 1392 | * |
| 1393 | * This routine ensures a TIPC message has an acceptable header, and at least |
| 1394 | * as much data as the header indicates it should. The routine also ensures |
| 1395 | * that the entire message header is stored in the main fragment of the message |
| 1396 | * buffer, to simplify future access to message header fields. |
| 1397 | * |
| 1398 | * Note: Having extra info present in the message header or data areas is OK. |
| 1399 | * TIPC will ignore the excess, under the assumption that it is optional info |
| 1400 | * introduced by a later release of the protocol. |
| 1401 | */ |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1402 | static int link_recv_buf_validate(struct sk_buff *buf) |
| 1403 | { |
| 1404 | static u32 min_data_hdr_size[8] = { |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 1405 | SHORT_H_SIZE, MCAST_H_SIZE, NAMED_H_SIZE, BASIC_H_SIZE, |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1406 | MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE |
| 1407 | }; |
| 1408 | |
| 1409 | struct tipc_msg *msg; |
| 1410 | u32 tipc_hdr[2]; |
| 1411 | u32 size; |
| 1412 | u32 hdr_size; |
| 1413 | u32 min_hdr_size; |
| 1414 | |
| 1415 | if (unlikely(buf->len < MIN_H_SIZE)) |
| 1416 | return 0; |
| 1417 | |
| 1418 | msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr); |
| 1419 | if (msg == NULL) |
| 1420 | return 0; |
| 1421 | |
| 1422 | if (unlikely(msg_version(msg) != TIPC_VERSION)) |
| 1423 | return 0; |
| 1424 | |
| 1425 | size = msg_size(msg); |
| 1426 | hdr_size = msg_hdr_sz(msg); |
| 1427 | min_hdr_size = msg_isdata(msg) ? |
| 1428 | min_data_hdr_size[msg_type(msg)] : INT_H_SIZE; |
| 1429 | |
| 1430 | if (unlikely((hdr_size < min_hdr_size) || |
| 1431 | (size < hdr_size) || |
| 1432 | (buf->len < size) || |
| 1433 | (size - hdr_size > TIPC_MAX_USER_MSG_SIZE))) |
| 1434 | return 0; |
| 1435 | |
| 1436 | return pskb_may_pull(buf, hdr_size); |
| 1437 | } |
| 1438 | |
Allan Stephens | b02b69c | 2010-08-17 11:00:07 +0000 | [diff] [blame] | 1439 | /** |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 1440 | * tipc_rcv - process TIPC packets/messages arriving from off-node |
Allan Stephens | b02b69c | 2010-08-17 11:00:07 +0000 | [diff] [blame] | 1441 | * @head: pointer to message buffer chain |
| 1442 | * @tb_ptr: pointer to bearer message arrived on |
| 1443 | * |
| 1444 | * Invoked with no locks held. Bearer pointer must point to a valid bearer |
| 1445 | * structure (i.e. cannot be NULL), but bearer can be inactive. |
| 1446 | */ |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 1447 | void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1448 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1449 | read_lock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1450 | while (head) { |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 1451 | struct tipc_node *n_ptr; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1452 | struct tipc_link *l_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1453 | struct sk_buff *crs; |
| 1454 | struct sk_buff *buf = head; |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1455 | struct tipc_msg *msg; |
| 1456 | u32 seq_no; |
| 1457 | u32 ackd; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1458 | u32 released = 0; |
| 1459 | int type; |
| 1460 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1461 | head = head->next; |
Erik Hugne | 732256b | 2014-01-07 15:51:36 -0500 | [diff] [blame] | 1462 | buf->next = NULL; |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1463 | |
Allan Stephens | b02b69c | 2010-08-17 11:00:07 +0000 | [diff] [blame] | 1464 | /* Ensure bearer is still enabled */ |
Allan Stephens | b02b69c | 2010-08-17 11:00:07 +0000 | [diff] [blame] | 1465 | if (unlikely(!b_ptr->active)) |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1466 | goto discard; |
Allan Stephens | b02b69c | 2010-08-17 11:00:07 +0000 | [diff] [blame] | 1467 | |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1468 | /* Ensure message is well-formed */ |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1469 | if (unlikely(!link_recv_buf_validate(buf))) |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1470 | goto discard; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1471 | |
Allan Stephens | fe13dda | 2008-04-15 19:03:23 -0700 | [diff] [blame] | 1472 | /* Ensure message data is a single contiguous unit */ |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1473 | if (unlikely(skb_linearize(buf))) |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1474 | goto discard; |
Allan Stephens | fe13dda | 2008-04-15 19:03:23 -0700 | [diff] [blame] | 1475 | |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1476 | /* Handle arrival of a non-unicast link message */ |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1477 | msg = buf_msg(buf); |
| 1478 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1479 | if (unlikely(msg_non_seq(msg))) { |
Allan Stephens | 1265a02 | 2008-06-04 17:32:35 -0700 | [diff] [blame] | 1480 | if (msg_user(msg) == LINK_CONFIG) |
| 1481 | tipc_disc_recv_msg(buf, b_ptr); |
| 1482 | else |
| 1483 | tipc_bclink_recv_pkt(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1484 | continue; |
| 1485 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1486 | |
Allan Stephens | ed33a9c | 2011-04-05 15:15:04 -0400 | [diff] [blame] | 1487 | /* Discard unicast link messages destined for another node */ |
Allan Stephens | 2600824 | 2006-06-25 23:39:31 -0700 | [diff] [blame] | 1488 | if (unlikely(!msg_short(msg) && |
| 1489 | (msg_destnode(msg) != tipc_own_addr))) |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1490 | goto discard; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1491 | |
Allan Stephens | 5a68d5e | 2010-08-17 11:00:16 +0000 | [diff] [blame] | 1492 | /* Locate neighboring node that sent message */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1493 | n_ptr = tipc_node_find(msg_prevnode(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1494 | if (unlikely(!n_ptr)) |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1495 | goto discard; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1496 | tipc_node_lock(n_ptr); |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1497 | |
Allan Stephens | 5a68d5e | 2010-08-17 11:00:16 +0000 | [diff] [blame] | 1498 | /* Locate unicast link endpoint that should handle message */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1499 | l_ptr = n_ptr->links[b_ptr->identity]; |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1500 | if (unlikely(!l_ptr)) |
| 1501 | goto unlock_discard; |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1502 | |
Allan Stephens | b4b5610 | 2011-05-27 11:00:51 -0400 | [diff] [blame] | 1503 | /* Verify that communication with node is currently allowed */ |
Allan Stephens | b4b5610 | 2011-05-27 11:00:51 -0400 | [diff] [blame] | 1504 | if ((n_ptr->block_setup & WAIT_PEER_DOWN) && |
| 1505 | msg_user(msg) == LINK_PROTOCOL && |
| 1506 | (msg_type(msg) == RESET_MSG || |
| 1507 | msg_type(msg) == ACTIVATE_MSG) && |
| 1508 | !msg_redundant_link(msg)) |
| 1509 | n_ptr->block_setup &= ~WAIT_PEER_DOWN; |
| 1510 | |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1511 | if (n_ptr->block_setup) |
| 1512 | goto unlock_discard; |
Allan Stephens | b4b5610 | 2011-05-27 11:00:51 -0400 | [diff] [blame] | 1513 | |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1514 | /* Validate message sequence number info */ |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1515 | seq_no = msg_seqno(msg); |
| 1516 | ackd = msg_ack(msg); |
| 1517 | |
| 1518 | /* Release acked messages */ |
Ying Xue | 389dd9b | 2012-11-16 13:51:30 +0800 | [diff] [blame] | 1519 | if (n_ptr->bclink.recv_permitted) |
Allan Stephens | 36559591 | 2011-10-24 15:26:24 -0400 | [diff] [blame] | 1520 | tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1521 | |
| 1522 | crs = l_ptr->first_out; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1523 | while ((crs != l_ptr->next_out) && |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1524 | less_eq(buf_seqno(crs), ackd)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1525 | struct sk_buff *next = crs->next; |
| 1526 | |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1527 | kfree_skb(crs); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1528 | crs = next; |
| 1529 | released++; |
| 1530 | } |
| 1531 | if (released) { |
| 1532 | l_ptr->first_out = crs; |
| 1533 | l_ptr->out_queue_size -= released; |
| 1534 | } |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1535 | |
| 1536 | /* Try sending any messages link endpoint has pending */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1537 | if (unlikely(l_ptr->next_out)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1538 | tipc_link_push_queue(l_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1539 | if (unlikely(!list_empty(&l_ptr->waiting_ports))) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1540 | tipc_link_wakeup_ports(l_ptr, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1541 | if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) { |
| 1542 | l_ptr->stats.sent_acks++; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1543 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
Allan Stephens | 8503556 | 2008-04-15 19:04:54 -0700 | [diff] [blame] | 1546 | /* Now (finally!) process the incoming message */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1547 | protocol_check: |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1548 | if (unlikely(!link_working_working(l_ptr))) { |
| 1549 | if (msg_user(msg) == LINK_PROTOCOL) { |
| 1550 | link_recv_proto_msg(l_ptr, buf); |
| 1551 | head = link_insert_deferred_queue(l_ptr, head); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1552 | tipc_node_unlock(n_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1553 | continue; |
| 1554 | } |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1555 | |
| 1556 | /* Traffic message. Conditionally activate link */ |
| 1557 | link_state_event(l_ptr, TRAFFIC_MSG_EVT); |
| 1558 | |
| 1559 | if (link_working_working(l_ptr)) { |
| 1560 | /* Re-insert buffer in front of queue */ |
| 1561 | buf->next = head; |
| 1562 | head = buf; |
| 1563 | tipc_node_unlock(n_ptr); |
| 1564 | continue; |
| 1565 | } |
| 1566 | goto unlock_discard; |
| 1567 | } |
| 1568 | |
| 1569 | /* Link is now in state WORKING_WORKING */ |
| 1570 | if (unlikely(seq_no != mod(l_ptr->next_in_no))) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1571 | link_handle_out_of_seq_msg(l_ptr, buf); |
| 1572 | head = link_insert_deferred_queue(l_ptr, head); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1573 | tipc_node_unlock(n_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1574 | continue; |
| 1575 | } |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1576 | l_ptr->next_in_no++; |
| 1577 | if (unlikely(l_ptr->oldest_deferred_in)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1578 | head = link_insert_deferred_queue(l_ptr, head); |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1579 | deliver: |
| 1580 | if (likely(msg_isdata(msg))) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1581 | tipc_node_unlock(n_ptr); |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1582 | tipc_port_recv_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1583 | continue; |
| 1584 | } |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1585 | switch (msg_user(msg)) { |
| 1586 | int ret; |
| 1587 | case MSG_BUNDLER: |
| 1588 | l_ptr->stats.recv_bundles++; |
| 1589 | l_ptr->stats.recv_bundled += msg_msgcnt(msg); |
| 1590 | tipc_node_unlock(n_ptr); |
| 1591 | tipc_link_recv_bundle(buf); |
| 1592 | continue; |
| 1593 | case NAME_DISTRIBUTOR: |
| 1594 | n_ptr->bclink.recv_permitted = true; |
| 1595 | tipc_node_unlock(n_ptr); |
| 1596 | tipc_named_recv(buf); |
| 1597 | continue; |
| 1598 | case BCAST_PROTOCOL: |
| 1599 | tipc_link_recv_sync(n_ptr, buf); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1600 | tipc_node_unlock(n_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1601 | continue; |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1602 | case CONN_MANAGER: |
| 1603 | tipc_node_unlock(n_ptr); |
| 1604 | tipc_port_recv_proto_msg(buf); |
| 1605 | continue; |
| 1606 | case MSG_FRAGMENTER: |
| 1607 | l_ptr->stats.recv_fragments++; |
Jon Paul Maloy | 03b9201 | 2014-02-13 17:29:05 -0500 | [diff] [blame] | 1608 | ret = tipc_link_frag_rcv(&l_ptr->reasm_head, |
| 1609 | &l_ptr->reasm_tail, |
| 1610 | &buf); |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 1611 | if (ret == LINK_REASM_COMPLETE) { |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1612 | l_ptr->stats.recv_fragmented++; |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 1613 | msg = buf_msg(buf); |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1614 | goto deliver; |
| 1615 | } |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 1616 | if (ret == LINK_REASM_ERROR) |
Erik Hugne | a715b49 | 2013-11-06 09:28:07 +0100 | [diff] [blame] | 1617 | tipc_link_reset(l_ptr); |
Erik Hugne | 528f6f4 | 2013-11-06 09:28:05 +0100 | [diff] [blame] | 1618 | tipc_node_unlock(n_ptr); |
| 1619 | continue; |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1620 | case CHANGEOVER_PROTOCOL: |
| 1621 | type = msg_type(msg); |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 1622 | if (tipc_link_tunnel_rcv(&l_ptr, &buf)) { |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1623 | msg = buf_msg(buf); |
| 1624 | seq_no = msg_seqno(msg); |
| 1625 | if (type == ORIGINAL_MSG) |
| 1626 | goto deliver; |
| 1627 | goto protocol_check; |
| 1628 | } |
| 1629 | break; |
| 1630 | default: |
| 1631 | kfree_skb(buf); |
| 1632 | buf = NULL; |
| 1633 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1634 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1635 | tipc_node_unlock(n_ptr); |
Ying Xue | 3af390e | 2013-10-30 11:26:57 +0800 | [diff] [blame] | 1636 | tipc_net_route_msg(buf); |
| 1637 | continue; |
| 1638 | unlock_discard: |
| 1639 | |
| 1640 | tipc_node_unlock(n_ptr); |
| 1641 | discard: |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1642 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1643 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1644 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1645 | } |
| 1646 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 1647 | /** |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1648 | * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue |
| 1649 | * |
| 1650 | * Returns increase in queue length (i.e. 0 or 1) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1651 | */ |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1652 | u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1653 | struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1654 | { |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1655 | struct sk_buff *queue_buf; |
| 1656 | struct sk_buff **prev; |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1657 | u32 seq_no = buf_seqno(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1658 | |
| 1659 | buf->next = NULL; |
| 1660 | |
| 1661 | /* Empty queue ? */ |
| 1662 | if (*head == NULL) { |
| 1663 | *head = *tail = buf; |
| 1664 | return 1; |
| 1665 | } |
| 1666 | |
| 1667 | /* Last ? */ |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1668 | if (less(buf_seqno(*tail), seq_no)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1669 | (*tail)->next = buf; |
| 1670 | *tail = buf; |
| 1671 | return 1; |
| 1672 | } |
| 1673 | |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1674 | /* Locate insertion point in queue, then insert; discard if duplicate */ |
| 1675 | prev = head; |
| 1676 | queue_buf = *head; |
| 1677 | for (;;) { |
| 1678 | u32 curr_seqno = buf_seqno(queue_buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1679 | |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1680 | if (seq_no == curr_seqno) { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1681 | kfree_skb(buf); |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1682 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1683 | } |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1684 | |
| 1685 | if (less(seq_no, curr_seqno)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1686 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1687 | |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1688 | prev = &queue_buf->next; |
| 1689 | queue_buf = queue_buf->next; |
| 1690 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1691 | |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1692 | buf->next = queue_buf; |
| 1693 | *prev = buf; |
| 1694 | return 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Allan Stephens | 8809b25 | 2011-10-25 10:44:35 -0400 | [diff] [blame] | 1697 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1698 | * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet |
| 1699 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1700 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1701 | struct sk_buff *buf) |
| 1702 | { |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1703 | u32 seq_no = buf_seqno(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1704 | |
| 1705 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { |
| 1706 | link_recv_proto_msg(l_ptr, buf); |
| 1707 | return; |
| 1708 | } |
| 1709 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1710 | /* Record OOS packet arrival (force mismatch on next timeout) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1711 | l_ptr->checkpoint--; |
| 1712 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1713 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1714 | * Discard packet if a duplicate; otherwise add it to deferred queue |
| 1715 | * and notify peer of gap as per protocol specification |
| 1716 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1717 | if (less(seq_no, mod(l_ptr->next_in_no))) { |
| 1718 | l_ptr->stats.duplicates++; |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1719 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1720 | return; |
| 1721 | } |
| 1722 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1723 | if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in, |
| 1724 | &l_ptr->newest_deferred_in, buf)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1725 | l_ptr->deferred_inqueue_sz++; |
| 1726 | l_ptr->stats.deferred_recv++; |
| 1727 | if ((l_ptr->deferred_inqueue_sz % 16) == 1) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1728 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1729 | } else |
| 1730 | l_ptr->stats.duplicates++; |
| 1731 | } |
| 1732 | |
| 1733 | /* |
| 1734 | * Send protocol message to the other endpoint. |
| 1735 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1736 | void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 1737 | int probe_msg, u32 gap, u32 tolerance, |
| 1738 | u32 priority, u32 ack_mtu) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1739 | { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 1740 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1741 | struct tipc_msg *msg = l_ptr->pmsg; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1742 | u32 msg_size = sizeof(l_ptr->proto_msg); |
Allan Stephens | 75f0aa4 | 2011-02-28 15:30:20 -0500 | [diff] [blame] | 1743 | int r_flag; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1744 | |
Allan Stephens | 92d2c90 | 2011-10-25 11:20:26 -0400 | [diff] [blame] | 1745 | /* Discard any previous message that was deferred due to congestion */ |
Allan Stephens | 92d2c90 | 2011-10-25 11:20:26 -0400 | [diff] [blame] | 1746 | if (l_ptr->proto_msg_queue) { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1747 | kfree_skb(l_ptr->proto_msg_queue); |
Allan Stephens | 92d2c90 | 2011-10-25 11:20:26 -0400 | [diff] [blame] | 1748 | l_ptr->proto_msg_queue = NULL; |
| 1749 | } |
| 1750 | |
Ying Xue | 77a7e07 | 2013-12-10 20:45:44 -0800 | [diff] [blame] | 1751 | /* Don't send protocol message during link changeover */ |
| 1752 | if (l_ptr->exp_msg_count) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1753 | return; |
Allan Stephens | b4b5610 | 2011-05-27 11:00:51 -0400 | [diff] [blame] | 1754 | |
| 1755 | /* Abort non-RESET send if communication with node is prohibited */ |
Allan Stephens | b4b5610 | 2011-05-27 11:00:51 -0400 | [diff] [blame] | 1756 | if ((l_ptr->owner->block_setup) && (msg_typ != RESET_MSG)) |
| 1757 | return; |
| 1758 | |
Allan Stephens | 92d2c90 | 2011-10-25 11:20:26 -0400 | [diff] [blame] | 1759 | /* Create protocol message with "out-of-sequence" sequence number */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1760 | msg_set_type(msg, msg_typ); |
| 1761 | msg_set_net_plane(msg, l_ptr->b_ptr->net_plane); |
Allan Stephens | 7a54d4a | 2011-10-27 14:17:53 -0400 | [diff] [blame] | 1762 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1763 | msg_set_last_bcast(msg, tipc_bclink_get_last_sent()); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1764 | |
| 1765 | if (msg_typ == STATE_MSG) { |
| 1766 | u32 next_sent = mod(l_ptr->next_out_no); |
| 1767 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1768 | if (!tipc_link_is_up(l_ptr)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1769 | return; |
| 1770 | if (l_ptr->next_out) |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1771 | next_sent = buf_seqno(l_ptr->next_out); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1772 | msg_set_next_sent(msg, next_sent); |
| 1773 | if (l_ptr->oldest_deferred_in) { |
Allan Stephens | f905730 | 2011-10-24 16:03:12 -0400 | [diff] [blame] | 1774 | u32 rec = buf_seqno(l_ptr->oldest_deferred_in); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1775 | gap = mod(rec - mod(l_ptr->next_in_no)); |
| 1776 | } |
| 1777 | msg_set_seq_gap(msg, gap); |
| 1778 | if (gap) |
| 1779 | l_ptr->stats.sent_nacks++; |
| 1780 | msg_set_link_tolerance(msg, tolerance); |
| 1781 | msg_set_linkprio(msg, priority); |
| 1782 | msg_set_max_pkt(msg, ack_mtu); |
| 1783 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); |
| 1784 | msg_set_probe(msg, probe_msg != 0); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1785 | if (probe_msg) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1786 | u32 mtu = l_ptr->max_pkt; |
| 1787 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1788 | if ((mtu < l_ptr->max_pkt_target) && |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1789 | link_working_working(l_ptr) && |
| 1790 | l_ptr->fsm_msg_cnt) { |
| 1791 | msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1792 | if (l_ptr->max_pkt_probes == 10) { |
| 1793 | l_ptr->max_pkt_target = (msg_size - 4); |
| 1794 | l_ptr->max_pkt_probes = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1795 | msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1796 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1797 | l_ptr->max_pkt_probes++; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1798 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1799 | |
| 1800 | l_ptr->stats.sent_probes++; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1801 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1802 | l_ptr->stats.sent_states++; |
| 1803 | } else { /* RESET_MSG or ACTIVATE_MSG */ |
| 1804 | msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1)); |
| 1805 | msg_set_seq_gap(msg, 0); |
| 1806 | msg_set_next_sent(msg, 1); |
Allan Stephens | f23d9bf | 2011-01-18 15:15:34 -0500 | [diff] [blame] | 1807 | msg_set_probe(msg, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1808 | msg_set_link_tolerance(msg, l_ptr->tolerance); |
| 1809 | msg_set_linkprio(msg, l_ptr->priority); |
| 1810 | msg_set_max_pkt(msg, l_ptr->max_pkt_target); |
| 1811 | } |
| 1812 | |
Allan Stephens | 75f0aa4 | 2011-02-28 15:30:20 -0500 | [diff] [blame] | 1813 | r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr)); |
| 1814 | msg_set_redundant_link(msg, r_flag); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1815 | msg_set_linkprio(msg, l_ptr->priority); |
Allan Stephens | 92d2c90 | 2011-10-25 11:20:26 -0400 | [diff] [blame] | 1816 | msg_set_size(msg, msg_size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1817 | |
| 1818 | msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2))); |
| 1819 | |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 1820 | buf = tipc_buf_acquire(msg_size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1821 | if (!buf) |
| 1822 | return; |
| 1823 | |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1824 | skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); |
Ying Xue | 796c75d | 2013-06-17 10:54:48 -0400 | [diff] [blame] | 1825 | buf->priority = TC_PRIO_CONTROL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1826 | |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 1827 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
Allan Stephens | 92d2c90 | 2011-10-25 11:20:26 -0400 | [diff] [blame] | 1828 | l_ptr->unacked_window = 0; |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1829 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | /* |
| 1833 | * Receive protocol message : |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1834 | * Note that network plane id propagates through the network, and may |
| 1835 | * change at any time. The node with lowest address rules |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1836 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1837 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1838 | { |
| 1839 | u32 rec_gap = 0; |
| 1840 | u32 max_pkt_info; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1841 | u32 max_pkt_ack; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1842 | u32 msg_tol; |
| 1843 | struct tipc_msg *msg = buf_msg(buf); |
| 1844 | |
Ying Xue | 77a7e07 | 2013-12-10 20:45:44 -0800 | [diff] [blame] | 1845 | /* Discard protocol message during link changeover */ |
| 1846 | if (l_ptr->exp_msg_count) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1847 | goto exit; |
| 1848 | |
| 1849 | /* record unnumbered packet arrival (force mismatch on next timeout) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1850 | l_ptr->checkpoint--; |
| 1851 | |
| 1852 | if (l_ptr->b_ptr->net_plane != msg_net_plane(msg)) |
| 1853 | if (tipc_own_addr > msg_prevnode(msg)) |
| 1854 | l_ptr->b_ptr->net_plane = msg_net_plane(msg); |
| 1855 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1856 | switch (msg_type(msg)) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1857 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1858 | case RESET_MSG: |
Allan Stephens | a686e68 | 2008-06-04 17:29:39 -0700 | [diff] [blame] | 1859 | if (!link_working_unknown(l_ptr) && |
| 1860 | (l_ptr->peer_session != INVALID_SESSION)) { |
Allan Stephens | 641c218 | 2011-04-07 09:54:43 -0400 | [diff] [blame] | 1861 | if (less_eq(msg_session(msg), l_ptr->peer_session)) |
| 1862 | break; /* duplicate or old reset: ignore */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1863 | } |
Allan Stephens | b4b5610 | 2011-05-27 11:00:51 -0400 | [diff] [blame] | 1864 | |
| 1865 | if (!msg_redundant_link(msg) && (link_working_working(l_ptr) || |
| 1866 | link_working_unknown(l_ptr))) { |
| 1867 | /* |
| 1868 | * peer has lost contact -- don't allow peer's links |
| 1869 | * to reactivate before we recognize loss & clean up |
| 1870 | */ |
| 1871 | l_ptr->owner->block_setup = WAIT_NODE_DOWN; |
| 1872 | } |
| 1873 | |
Allan Stephens | 47361c8 | 2011-10-26 10:55:16 -0400 | [diff] [blame] | 1874 | link_state_event(l_ptr, RESET_MSG); |
| 1875 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1876 | /* fall thru' */ |
| 1877 | case ACTIVATE_MSG: |
| 1878 | /* Update link settings according other endpoint's values */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1879 | strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg)); |
| 1880 | |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 1881 | msg_tol = msg_link_tolerance(msg); |
| 1882 | if (msg_tol > l_ptr->tolerance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1883 | link_set_supervision_props(l_ptr, msg_tol); |
| 1884 | |
| 1885 | if (msg_linkprio(msg) > l_ptr->priority) |
| 1886 | l_ptr->priority = msg_linkprio(msg); |
| 1887 | |
| 1888 | max_pkt_info = msg_max_pkt(msg); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1889 | if (max_pkt_info) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1890 | if (max_pkt_info < l_ptr->max_pkt_target) |
| 1891 | l_ptr->max_pkt_target = max_pkt_info; |
| 1892 | if (l_ptr->max_pkt > l_ptr->max_pkt_target) |
| 1893 | l_ptr->max_pkt = l_ptr->max_pkt_target; |
| 1894 | } else { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1895 | l_ptr->max_pkt = l_ptr->max_pkt_target; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1896 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1897 | |
Allan Stephens | 4d75313 | 2011-10-25 12:19:05 -0400 | [diff] [blame] | 1898 | /* Synchronize broadcast link info, if not done previously */ |
Allan Stephens | 7a54d4a | 2011-10-27 14:17:53 -0400 | [diff] [blame] | 1899 | if (!tipc_node_is_up(l_ptr->owner)) { |
| 1900 | l_ptr->owner->bclink.last_sent = |
| 1901 | l_ptr->owner->bclink.last_in = |
| 1902 | msg_last_bcast(msg); |
| 1903 | l_ptr->owner->bclink.oos_state = 0; |
| 1904 | } |
Allan Stephens | 4d75313 | 2011-10-25 12:19:05 -0400 | [diff] [blame] | 1905 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1906 | l_ptr->peer_session = msg_session(msg); |
| 1907 | l_ptr->peer_bearer_id = msg_bearer_id(msg); |
Allan Stephens | 47361c8 | 2011-10-26 10:55:16 -0400 | [diff] [blame] | 1908 | |
| 1909 | if (msg_type(msg) == ACTIVATE_MSG) |
| 1910 | link_state_event(l_ptr, ACTIVATE_MSG); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1911 | break; |
| 1912 | case STATE_MSG: |
| 1913 | |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 1914 | msg_tol = msg_link_tolerance(msg); |
| 1915 | if (msg_tol) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1916 | link_set_supervision_props(l_ptr, msg_tol); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1917 | |
| 1918 | if (msg_linkprio(msg) && |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1919 | (msg_linkprio(msg) != l_ptr->priority)) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1920 | pr_warn("%s<%s>, priority change %u->%u\n", |
| 1921 | link_rst_msg, l_ptr->name, l_ptr->priority, |
| 1922 | msg_linkprio(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1923 | l_ptr->priority = msg_linkprio(msg); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1924 | tipc_link_reset(l_ptr); /* Enforce change to take effect */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1925 | break; |
| 1926 | } |
| 1927 | link_state_event(l_ptr, TRAFFIC_MSG_EVT); |
| 1928 | l_ptr->stats.recv_states++; |
| 1929 | if (link_reset_unknown(l_ptr)) |
| 1930 | break; |
| 1931 | |
| 1932 | if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1933 | rec_gap = mod(msg_next_sent(msg) - |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1934 | mod(l_ptr->next_in_no)); |
| 1935 | } |
| 1936 | |
| 1937 | max_pkt_ack = msg_max_pkt(msg); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1938 | if (max_pkt_ack > l_ptr->max_pkt) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1939 | l_ptr->max_pkt = max_pkt_ack; |
| 1940 | l_ptr->max_pkt_probes = 0; |
| 1941 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1942 | |
| 1943 | max_pkt_ack = 0; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1944 | if (msg_probe(msg)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1945 | l_ptr->stats.recv_probes++; |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 1946 | if (msg_size(msg) > sizeof(l_ptr->proto_msg)) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1947 | max_pkt_ack = msg_size(msg); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1948 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1949 | |
| 1950 | /* Protocol message before retransmits, reduce loss risk */ |
Ying Xue | 389dd9b | 2012-11-16 13:51:30 +0800 | [diff] [blame] | 1951 | if (l_ptr->owner->bclink.recv_permitted) |
Allan Stephens | 7a54d4a | 2011-10-27 14:17:53 -0400 | [diff] [blame] | 1952 | tipc_bclink_update_link_state(l_ptr->owner, |
| 1953 | msg_last_bcast(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1954 | |
| 1955 | if (rec_gap || (msg_probe(msg))) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1956 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
| 1957 | 0, rec_gap, 0, 0, max_pkt_ack); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1958 | } |
| 1959 | if (msg_seq_gap(msg)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1960 | l_ptr->stats.recv_nacks++; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1961 | tipc_link_retransmit(l_ptr, l_ptr->first_out, |
| 1962 | msg_seq_gap(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1963 | } |
| 1964 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1965 | } |
| 1966 | exit: |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1967 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 1971 | /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to |
| 1972 | * a different bearer. Owner node is locked. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1973 | */ |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 1974 | static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr, |
| 1975 | struct tipc_msg *tunnel_hdr, |
| 1976 | struct tipc_msg *msg, |
| 1977 | u32 selector) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1978 | { |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 1979 | struct tipc_link *tunnel; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1980 | struct sk_buff *buf; |
| 1981 | u32 length = msg_size(msg); |
| 1982 | |
| 1983 | tunnel = l_ptr->owner->active_links[selector & 1]; |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 1984 | if (!tipc_link_is_up(tunnel)) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1985 | pr_warn("%stunnel link no longer available\n", link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1986 | return; |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 1987 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1988 | msg_set_size(tunnel_hdr, length + INT_H_SIZE); |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 1989 | buf = tipc_buf_acquire(length + INT_H_SIZE); |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 1990 | if (!buf) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1991 | pr_warn("%sunable to send tunnel msg\n", link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1992 | return; |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 1993 | } |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1994 | skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE); |
| 1995 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1996 | tipc_link_send_buf(tunnel, buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 2000 | /* tipc_link_failover_send_queue(): A link has gone down, but a second |
| 2001 | * link is still active. We can do failover. Tunnel the failing link's |
| 2002 | * whole send queue via the remaining link. This way, we don't lose |
| 2003 | * any packets, and sequence order is preserved for subsequent traffic |
| 2004 | * sent over the remaining link. Owner node is locked. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2005 | */ |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 2006 | void tipc_link_failover_send_queue(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2007 | { |
| 2008 | u32 msgcount = l_ptr->out_queue_size; |
| 2009 | struct sk_buff *crs = l_ptr->first_out; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2010 | struct tipc_link *tunnel = l_ptr->owner->active_links[0]; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2011 | struct tipc_msg tunnel_hdr; |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 2012 | int split_bundles; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2013 | |
| 2014 | if (!tunnel) |
| 2015 | return; |
| 2016 | |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 2017 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, |
Allan Stephens | 7571521 | 2008-06-04 17:37:34 -0700 | [diff] [blame] | 2018 | ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2019 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); |
| 2020 | msg_set_msgcnt(&tunnel_hdr, msgcount); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 2021 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2022 | if (!l_ptr->first_out) { |
| 2023 | struct sk_buff *buf; |
| 2024 | |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 2025 | buf = tipc_buf_acquire(INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2026 | if (buf) { |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 2027 | skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2028 | msg_set_size(&tunnel_hdr, INT_H_SIZE); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2029 | tipc_link_send_buf(tunnel, buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2030 | } else { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2031 | pr_warn("%sunable to send changeover msg\n", |
| 2032 | link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2033 | } |
| 2034 | return; |
| 2035 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 2036 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2037 | split_bundles = (l_ptr->owner->active_links[0] != |
Allan Stephens | 5392d64 | 2006-06-25 23:52:50 -0700 | [diff] [blame] | 2038 | l_ptr->owner->active_links[1]); |
| 2039 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2040 | while (crs) { |
| 2041 | struct tipc_msg *msg = buf_msg(crs); |
| 2042 | |
| 2043 | if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2044 | struct tipc_msg *m = msg_get_wrapped(msg); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2045 | unchar *pos = (unchar *)m; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2046 | |
Florian Westphal | d788d80 | 2007-08-02 19:28:06 -0700 | [diff] [blame] | 2047 | msgcount = msg_msgcnt(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2048 | while (msgcount--) { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2049 | msg_set_seqno(m, msg_seqno(msg)); |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 2050 | tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, m, |
| 2051 | msg_link_selector(m)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2052 | pos += align(msg_size(m)); |
| 2053 | m = (struct tipc_msg *)pos; |
| 2054 | } |
| 2055 | } else { |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 2056 | tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, msg, |
| 2057 | msg_link_selector(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2058 | } |
| 2059 | crs = crs->next; |
| 2060 | } |
| 2061 | } |
| 2062 | |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 2063 | /* tipc_link_dup_send_queue(): A second link has become active. Tunnel a |
| 2064 | * duplicate of the first link's send queue via the new link. This way, we |
| 2065 | * are guaranteed that currently queued packets from a socket are delivered |
| 2066 | * before future traffic from the same socket, even if this is using the |
| 2067 | * new link. The last arriving copy of each duplicate packet is dropped at |
| 2068 | * the receiving end by the regular protocol check, so packet cardinality |
| 2069 | * and sequence order is preserved per sender/receiver socket pair. |
| 2070 | * Owner node is locked. |
| 2071 | */ |
| 2072 | void tipc_link_dup_send_queue(struct tipc_link *l_ptr, |
| 2073 | struct tipc_link *tunnel) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2074 | { |
| 2075 | struct sk_buff *iter; |
| 2076 | struct tipc_msg tunnel_hdr; |
| 2077 | |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 2078 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, |
Allan Stephens | 7571521 | 2008-06-04 17:37:34 -0700 | [diff] [blame] | 2079 | DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2080 | msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size); |
| 2081 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); |
| 2082 | iter = l_ptr->first_out; |
| 2083 | while (iter) { |
| 2084 | struct sk_buff *outbuf; |
| 2085 | struct tipc_msg *msg = buf_msg(iter); |
| 2086 | u32 length = msg_size(msg); |
| 2087 | |
| 2088 | if (msg_user(msg) == MSG_BUNDLER) |
| 2089 | msg_set_type(msg, CLOSED_MSG); |
| 2090 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2091 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2092 | msg_set_size(&tunnel_hdr, length + INT_H_SIZE); |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 2093 | outbuf = tipc_buf_acquire(length + INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2094 | if (outbuf == NULL) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2095 | pr_warn("%sunable to send duplicate msg\n", |
| 2096 | link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2097 | return; |
| 2098 | } |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 2099 | skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE); |
| 2100 | skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data, |
| 2101 | length); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2102 | tipc_link_send_buf(tunnel, outbuf); |
| 2103 | if (!tipc_link_is_up(l_ptr)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2104 | return; |
| 2105 | iter = iter->next; |
| 2106 | } |
| 2107 | } |
| 2108 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2109 | /** |
| 2110 | * buf_extract - extracts embedded TIPC message from another message |
| 2111 | * @skb: encapsulating message buffer |
| 2112 | * @from_pos: offset to extract from |
| 2113 | * |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2114 | * Returns a new message buffer containing an embedded message. The |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2115 | * encapsulating message itself is left unchanged. |
| 2116 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2117 | static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos) |
| 2118 | { |
| 2119 | struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos); |
| 2120 | u32 size = msg_size(msg); |
| 2121 | struct sk_buff *eb; |
| 2122 | |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 2123 | eb = tipc_buf_acquire(size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2124 | if (eb) |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 2125 | skb_copy_to_linear_data(eb, msg, size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2126 | return eb; |
| 2127 | } |
| 2128 | |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 2129 | /* tipc_link_tunnel_rcv(): Receive a tunneled packet, sent |
| 2130 | * via other link as result of a failover (ORIGINAL_MSG) or |
| 2131 | * a new active link (DUPLICATE_MSG). Failover packets are |
| 2132 | * returned to the active link for delivery upwards. |
| 2133 | * Owner node is locked. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2134 | */ |
Jon Paul Maloy | 170b392 | 2014-01-07 17:02:41 -0500 | [diff] [blame] | 2135 | static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, |
| 2136 | struct sk_buff **buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2137 | { |
| 2138 | struct sk_buff *tunnel_buf = *buf; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2139 | struct tipc_link *dest_link; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2140 | struct tipc_msg *msg; |
| 2141 | struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf); |
| 2142 | u32 msg_typ = msg_type(tunnel_msg); |
| 2143 | u32 msg_count = msg_msgcnt(tunnel_msg); |
Dan Carpenter | cb4b102f | 2013-05-06 08:28:41 +0000 | [diff] [blame] | 2144 | u32 bearer_id = msg_bearer_id(tunnel_msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2145 | |
Dan Carpenter | cb4b102f | 2013-05-06 08:28:41 +0000 | [diff] [blame] | 2146 | if (bearer_id >= MAX_BEARERS) |
| 2147 | goto exit; |
| 2148 | dest_link = (*l_ptr)->owner->links[bearer_id]; |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 2149 | if (!dest_link) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2150 | goto exit; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 2151 | if (dest_link == *l_ptr) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2152 | pr_err("Unexpected changeover message on link <%s>\n", |
| 2153 | (*l_ptr)->name); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 2154 | goto exit; |
| 2155 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2156 | *l_ptr = dest_link; |
| 2157 | msg = msg_get_wrapped(tunnel_msg); |
| 2158 | |
| 2159 | if (msg_typ == DUPLICATE_MSG) { |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 2160 | if (less(msg_seqno(msg), mod(dest_link->next_in_no))) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2161 | goto exit; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2162 | *buf = buf_extract(tunnel_buf, INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2163 | if (*buf == NULL) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2164 | pr_warn("%sduplicate msg dropped\n", link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2165 | goto exit; |
| 2166 | } |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2167 | kfree_skb(tunnel_buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2168 | return 1; |
| 2169 | } |
| 2170 | |
| 2171 | /* First original message ?: */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2172 | if (tipc_link_is_up(dest_link)) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2173 | pr_info("%s<%s>, changeover initiated by peer\n", link_rst_msg, |
| 2174 | dest_link->name); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2175 | tipc_link_reset(dest_link); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2176 | dest_link->exp_msg_count = msg_count; |
| 2177 | if (!msg_count) |
| 2178 | goto exit; |
| 2179 | } else if (dest_link->exp_msg_count == START_CHANGEOVER) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2180 | dest_link->exp_msg_count = msg_count; |
| 2181 | if (!msg_count) |
| 2182 | goto exit; |
| 2183 | } |
| 2184 | |
| 2185 | /* Receive original message */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2186 | if (dest_link->exp_msg_count == 0) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2187 | pr_warn("%sgot too many tunnelled messages\n", link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2188 | goto exit; |
| 2189 | } |
| 2190 | dest_link->exp_msg_count--; |
| 2191 | if (less(msg_seqno(msg), dest_link->reset_checkpoint)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2192 | goto exit; |
| 2193 | } else { |
| 2194 | *buf = buf_extract(tunnel_buf, INT_H_SIZE); |
| 2195 | if (*buf != NULL) { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2196 | kfree_skb(tunnel_buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2197 | return 1; |
| 2198 | } else { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2199 | pr_warn("%soriginal msg dropped\n", link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2200 | } |
| 2201 | } |
| 2202 | exit: |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 2203 | *buf = NULL; |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2204 | kfree_skb(tunnel_buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2205 | return 0; |
| 2206 | } |
| 2207 | |
| 2208 | /* |
| 2209 | * Bundler functionality: |
| 2210 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2211 | void tipc_link_recv_bundle(struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2212 | { |
| 2213 | u32 msgcount = msg_msgcnt(buf_msg(buf)); |
| 2214 | u32 pos = INT_H_SIZE; |
| 2215 | struct sk_buff *obuf; |
| 2216 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2217 | while (msgcount--) { |
| 2218 | obuf = buf_extract(buf, pos); |
| 2219 | if (obuf == NULL) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2220 | pr_warn("Link unable to unbundle message(s)\n"); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 2221 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2222 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2223 | pos += align(msg_size(buf_msg(obuf))); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2224 | tipc_net_route_msg(obuf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2225 | } |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2226 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | /* |
| 2230 | * Fragmentation/defragmentation: |
| 2231 | */ |
| 2232 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2233 | /* |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 2234 | * link_send_long_buf: Entry for buffers needing fragmentation. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2235 | * The buffer is complete, inclusive total message length. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2236 | * Returns user data length. |
| 2237 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2238 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2239 | { |
Allan Stephens | 7756155 | 2011-04-17 13:06:23 -0400 | [diff] [blame] | 2240 | struct sk_buff *buf_chain = NULL; |
| 2241 | struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2242 | struct tipc_msg *inmsg = buf_msg(buf); |
| 2243 | struct tipc_msg fragm_hdr; |
| 2244 | u32 insize = msg_size(inmsg); |
| 2245 | u32 dsz = msg_data_sz(inmsg); |
| 2246 | unchar *crs = buf->data; |
| 2247 | u32 rest = insize; |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 2248 | u32 pack_sz = l_ptr->max_pkt; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2249 | u32 fragm_sz = pack_sz - INT_H_SIZE; |
Allan Stephens | 7756155 | 2011-04-17 13:06:23 -0400 | [diff] [blame] | 2250 | u32 fragm_no = 0; |
Allan Stephens | 9c396a7 | 2008-06-04 17:36:58 -0700 | [diff] [blame] | 2251 | u32 destaddr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2252 | |
| 2253 | if (msg_short(inmsg)) |
| 2254 | destaddr = l_ptr->addr; |
Allan Stephens | 9c396a7 | 2008-06-04 17:36:58 -0700 | [diff] [blame] | 2255 | else |
| 2256 | destaddr = msg_destnode(inmsg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2257 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2258 | /* Prepare reusable fragment header: */ |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 2259 | tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT, |
Allan Stephens | 7571521 | 2008-06-04 17:37:34 -0700 | [diff] [blame] | 2260 | INT_H_SIZE, destaddr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2261 | |
| 2262 | /* Chop up message: */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2263 | while (rest > 0) { |
| 2264 | struct sk_buff *fragm; |
| 2265 | |
| 2266 | if (rest <= fragm_sz) { |
| 2267 | fragm_sz = rest; |
| 2268 | msg_set_type(&fragm_hdr, LAST_FRAGMENT); |
| 2269 | } |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 2270 | fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2271 | if (fragm == NULL) { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2272 | kfree_skb(buf); |
Ying Xue | d77b383 | 2013-12-10 20:45:38 -0800 | [diff] [blame] | 2273 | kfree_skb_list(buf_chain); |
Allan Stephens | 7756155 | 2011-04-17 13:06:23 -0400 | [diff] [blame] | 2274 | return -ENOMEM; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2275 | } |
| 2276 | msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); |
Allan Stephens | 7756155 | 2011-04-17 13:06:23 -0400 | [diff] [blame] | 2277 | fragm_no++; |
| 2278 | msg_set_fragm_no(&fragm_hdr, fragm_no); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 2279 | skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE); |
| 2280 | skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs, |
| 2281 | fragm_sz); |
Allan Stephens | 7756155 | 2011-04-17 13:06:23 -0400 | [diff] [blame] | 2282 | buf_chain_tail->next = fragm; |
| 2283 | buf_chain_tail = fragm; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2284 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2285 | rest -= fragm_sz; |
| 2286 | crs += fragm_sz; |
| 2287 | msg_set_type(&fragm_hdr, FRAGMENT); |
| 2288 | } |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2289 | kfree_skb(buf); |
Allan Stephens | 7756155 | 2011-04-17 13:06:23 -0400 | [diff] [blame] | 2290 | |
| 2291 | /* Append chain of fragments to send queue & send them */ |
Allan Stephens | 7756155 | 2011-04-17 13:06:23 -0400 | [diff] [blame] | 2292 | l_ptr->long_msg_seq_no++; |
| 2293 | link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no); |
| 2294 | l_ptr->stats.sent_fragments += fragm_no; |
| 2295 | l_ptr->stats.sent_fragmented++; |
| 2296 | tipc_link_push_queue(l_ptr); |
| 2297 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2298 | return dsz; |
| 2299 | } |
| 2300 | |
Jon Paul Maloy | 03b9201 | 2014-02-13 17:29:05 -0500 | [diff] [blame] | 2301 | /* tipc_link_frag_rcv(): Called with node lock on. Returns |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2302 | * the reassembled buffer if message is complete. |
| 2303 | */ |
Jon Paul Maloy | 03b9201 | 2014-02-13 17:29:05 -0500 | [diff] [blame] | 2304 | int tipc_link_frag_rcv(struct sk_buff **head, struct sk_buff **tail, |
| 2305 | struct sk_buff **fbuf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2306 | { |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 2307 | struct sk_buff *frag = *fbuf; |
| 2308 | struct tipc_msg *msg = buf_msg(frag); |
| 2309 | u32 fragid = msg_type(msg); |
| 2310 | bool headstolen; |
| 2311 | int delta; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2312 | |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 2313 | skb_pull(frag, msg_hdr_sz(msg)); |
| 2314 | if (fragid == FIRST_FRAGMENT) { |
| 2315 | if (*head || skb_unclone(frag, GFP_ATOMIC)) |
| 2316 | goto out_free; |
| 2317 | *head = frag; |
| 2318 | skb_frag_list_init(*head); |
Jon Paul Maloy | 03b9201 | 2014-02-13 17:29:05 -0500 | [diff] [blame] | 2319 | *fbuf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2320 | return 0; |
Erik Hugne | 3db0a19 | 2013-11-13 09:35:11 +0100 | [diff] [blame] | 2321 | } else if (*head && |
| 2322 | skb_try_coalesce(*head, frag, &headstolen, &delta)) { |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 2323 | kfree_skb_partial(frag, headstolen); |
| 2324 | } else { |
| 2325 | if (!*head) |
| 2326 | goto out_free; |
| 2327 | if (!skb_has_frag_list(*head)) |
| 2328 | skb_shinfo(*head)->frag_list = frag; |
| 2329 | else |
| 2330 | (*tail)->next = frag; |
| 2331 | *tail = frag; |
| 2332 | (*head)->truesize += frag->truesize; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2333 | } |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 2334 | if (fragid == LAST_FRAGMENT) { |
| 2335 | *fbuf = *head; |
| 2336 | *tail = *head = NULL; |
| 2337 | return LINK_REASM_COMPLETE; |
| 2338 | } |
Jon Paul Maloy | 03b9201 | 2014-02-13 17:29:05 -0500 | [diff] [blame] | 2339 | *fbuf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2340 | return 0; |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 2341 | out_free: |
| 2342 | pr_warn_ratelimited("Link unable to reassemble fragmented message\n"); |
| 2343 | kfree_skb(*fbuf); |
Jon Paul Maloy | 03b9201 | 2014-02-13 17:29:05 -0500 | [diff] [blame] | 2344 | *fbuf = NULL; |
Erik Hugne | 40ba3cd | 2013-11-06 09:28:06 +0100 | [diff] [blame] | 2345 | return LINK_REASM_ERROR; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2346 | } |
| 2347 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2348 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2349 | { |
Allan Stephens | 5413b4c | 2011-01-18 13:24:55 -0500 | [diff] [blame] | 2350 | if ((tolerance < TIPC_MIN_LINK_TOL) || (tolerance > TIPC_MAX_LINK_TOL)) |
| 2351 | return; |
| 2352 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2353 | l_ptr->tolerance = tolerance; |
| 2354 | l_ptr->continuity_interval = |
| 2355 | ((tolerance / 4) > 500) ? 500 : tolerance / 4; |
| 2356 | l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4); |
| 2357 | } |
| 2358 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2359 | void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2360 | { |
| 2361 | /* Data messages from this node, inclusive FIRST_FRAGM */ |
Allan Stephens | 06d82c9 | 2008-03-06 15:06:55 -0800 | [diff] [blame] | 2362 | l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window; |
| 2363 | l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4; |
| 2364 | l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5; |
| 2365 | l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2366 | /* Transiting data messages,inclusive FIRST_FRAGM */ |
Allan Stephens | 06d82c9 | 2008-03-06 15:06:55 -0800 | [diff] [blame] | 2367 | l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300; |
| 2368 | l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600; |
| 2369 | l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900; |
| 2370 | l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2371 | l_ptr->queue_limit[CONN_MANAGER] = 1200; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2372 | l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500; |
| 2373 | l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000; |
| 2374 | /* FRAGMENT and LAST_FRAGMENT packets */ |
| 2375 | l_ptr->queue_limit[MSG_FRAGMENTER] = 4000; |
| 2376 | } |
| 2377 | |
| 2378 | /** |
| 2379 | * link_find_link - locate link by name |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 2380 | * @name: ptr to link name string |
| 2381 | * @node: ptr to area to be filled with ptr to associated node |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2382 | * |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2383 | * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2384 | * this also prevents link deletion. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2385 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2386 | * Returns pointer to link (or 0 if invalid link name). |
| 2387 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2388 | static struct tipc_link *link_find_link(const char *name, |
| 2389 | struct tipc_node **node) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2390 | { |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2391 | struct tipc_link *l_ptr; |
Erik Hugne | bbfbe47 | 2013-10-18 07:23:21 +0200 | [diff] [blame] | 2392 | struct tipc_node *n_ptr; |
| 2393 | int i; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2394 | |
Erik Hugne | bbfbe47 | 2013-10-18 07:23:21 +0200 | [diff] [blame] | 2395 | list_for_each_entry(n_ptr, &tipc_node_list, list) { |
| 2396 | for (i = 0; i < MAX_BEARERS; i++) { |
| 2397 | l_ptr = n_ptr->links[i]; |
| 2398 | if (l_ptr && !strcmp(l_ptr->name, name)) |
| 2399 | goto found; |
| 2400 | } |
| 2401 | } |
| 2402 | l_ptr = NULL; |
| 2403 | n_ptr = NULL; |
| 2404 | found: |
| 2405 | *node = n_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2406 | return l_ptr; |
| 2407 | } |
| 2408 | |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2409 | /** |
| 2410 | * link_value_is_valid -- validate proposed link tolerance/priority/window |
| 2411 | * |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 2412 | * @cmd: value type (TIPC_CMD_SET_LINK_*) |
| 2413 | * @new_value: the new value |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2414 | * |
| 2415 | * Returns 1 if value is within range, 0 if not. |
| 2416 | */ |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2417 | static int link_value_is_valid(u16 cmd, u32 new_value) |
| 2418 | { |
| 2419 | switch (cmd) { |
| 2420 | case TIPC_CMD_SET_LINK_TOL: |
| 2421 | return (new_value >= TIPC_MIN_LINK_TOL) && |
| 2422 | (new_value <= TIPC_MAX_LINK_TOL); |
| 2423 | case TIPC_CMD_SET_LINK_PRI: |
| 2424 | return (new_value <= TIPC_MAX_LINK_PRI); |
| 2425 | case TIPC_CMD_SET_LINK_WINDOW: |
| 2426 | return (new_value >= TIPC_MIN_LINK_WIN) && |
| 2427 | (new_value <= TIPC_MAX_LINK_WIN); |
| 2428 | } |
| 2429 | return 0; |
| 2430 | } |
| 2431 | |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2432 | /** |
| 2433 | * link_cmd_set_value - change priority/tolerance/window for link/bearer/media |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 2434 | * @name: ptr to link, bearer, or media name |
| 2435 | * @new_value: new value of link, bearer, or media setting |
| 2436 | * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*) |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2437 | * |
| 2438 | * Caller must hold 'tipc_net_lock' to ensure link/bearer/media is not deleted. |
| 2439 | * |
| 2440 | * Returns 0 if value updated and negative value on error. |
| 2441 | */ |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2442 | static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) |
| 2443 | { |
| 2444 | struct tipc_node *node; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2445 | struct tipc_link *l_ptr; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2446 | struct tipc_bearer *b_ptr; |
Paul Gortmaker | 358a0d1 | 2011-12-29 20:19:42 -0500 | [diff] [blame] | 2447 | struct tipc_media *m_ptr; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2448 | int res = 0; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2449 | |
| 2450 | l_ptr = link_find_link(name, &node); |
| 2451 | if (l_ptr) { |
| 2452 | /* |
| 2453 | * acquire node lock for tipc_link_send_proto_msg(). |
| 2454 | * see "TIPC locking policy" in net.c. |
| 2455 | */ |
| 2456 | tipc_node_lock(node); |
| 2457 | switch (cmd) { |
| 2458 | case TIPC_CMD_SET_LINK_TOL: |
| 2459 | link_set_supervision_props(l_ptr, new_value); |
| 2460 | tipc_link_send_proto_msg(l_ptr, |
| 2461 | STATE_MSG, 0, 0, new_value, 0, 0); |
| 2462 | break; |
| 2463 | case TIPC_CMD_SET_LINK_PRI: |
| 2464 | l_ptr->priority = new_value; |
| 2465 | tipc_link_send_proto_msg(l_ptr, |
| 2466 | STATE_MSG, 0, 0, 0, new_value, 0); |
| 2467 | break; |
| 2468 | case TIPC_CMD_SET_LINK_WINDOW: |
| 2469 | tipc_link_set_queue_limits(l_ptr, new_value); |
| 2470 | break; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2471 | default: |
| 2472 | res = -EINVAL; |
| 2473 | break; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2474 | } |
| 2475 | tipc_node_unlock(node); |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2476 | return res; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | b_ptr = tipc_bearer_find(name); |
| 2480 | if (b_ptr) { |
| 2481 | switch (cmd) { |
| 2482 | case TIPC_CMD_SET_LINK_TOL: |
| 2483 | b_ptr->tolerance = new_value; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2484 | break; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2485 | case TIPC_CMD_SET_LINK_PRI: |
| 2486 | b_ptr->priority = new_value; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2487 | break; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2488 | case TIPC_CMD_SET_LINK_WINDOW: |
| 2489 | b_ptr->window = new_value; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2490 | break; |
| 2491 | default: |
| 2492 | res = -EINVAL; |
| 2493 | break; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2494 | } |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2495 | return res; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | m_ptr = tipc_media_find(name); |
| 2499 | if (!m_ptr) |
| 2500 | return -ENODEV; |
| 2501 | switch (cmd) { |
| 2502 | case TIPC_CMD_SET_LINK_TOL: |
| 2503 | m_ptr->tolerance = new_value; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2504 | break; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2505 | case TIPC_CMD_SET_LINK_PRI: |
| 2506 | m_ptr->priority = new_value; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2507 | break; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2508 | case TIPC_CMD_SET_LINK_WINDOW: |
| 2509 | m_ptr->window = new_value; |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2510 | break; |
| 2511 | default: |
| 2512 | res = -EINVAL; |
| 2513 | break; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2514 | } |
Ying Xue | 636c037 | 2013-10-18 07:23:20 +0200 | [diff] [blame] | 2515 | return res; |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2516 | } |
| 2517 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2518 | struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2519 | u16 cmd) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2520 | { |
| 2521 | struct tipc_link_config *args; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2522 | u32 new_value; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2523 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2524 | |
| 2525 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2526 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2527 | |
| 2528 | args = (struct tipc_link_config *)TLV_DATA(req_tlv_area); |
| 2529 | new_value = ntohl(args->value); |
| 2530 | |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2531 | if (!link_value_is_valid(cmd, new_value)) |
| 2532 | return tipc_cfg_reply_error_string( |
| 2533 | "cannot change, value invalid"); |
| 2534 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2535 | if (!strcmp(args->name, tipc_bclink_name)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2536 | if ((cmd == TIPC_CMD_SET_LINK_WINDOW) && |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2537 | (tipc_bclink_set_queue_limits(new_value) == 0)) |
| 2538 | return tipc_cfg_reply_none(); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2539 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2540 | " (cannot change setting on broadcast link)"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2541 | } |
| 2542 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2543 | read_lock_bh(&tipc_net_lock); |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2544 | res = link_cmd_set_value(args->name, new_value, cmd); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2545 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2546 | if (res) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2547 | return tipc_cfg_reply_error_string("cannot change link setting"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2548 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2549 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | /** |
| 2553 | * link_reset_statistics - reset link statistics |
| 2554 | * @l_ptr: pointer to link |
| 2555 | */ |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2556 | static void link_reset_statistics(struct tipc_link *l_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2557 | { |
| 2558 | memset(&l_ptr->stats, 0, sizeof(l_ptr->stats)); |
| 2559 | l_ptr->stats.sent_info = l_ptr->next_out_no; |
| 2560 | l_ptr->stats.recv_info = l_ptr->next_in_no; |
| 2561 | } |
| 2562 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2563 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2564 | { |
| 2565 | char *link_name; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2566 | struct tipc_link *l_ptr; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 2567 | struct tipc_node *node; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2568 | |
| 2569 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2570 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2571 | |
| 2572 | link_name = (char *)TLV_DATA(req_tlv_area); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2573 | if (!strcmp(link_name, tipc_bclink_name)) { |
| 2574 | if (tipc_bclink_reset_stats()) |
| 2575 | return tipc_cfg_reply_error_string("link not found"); |
| 2576 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2577 | } |
| 2578 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2579 | read_lock_bh(&tipc_net_lock); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2580 | l_ptr = link_find_link(link_name, &node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2581 | if (!l_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2582 | read_unlock_bh(&tipc_net_lock); |
| 2583 | return tipc_cfg_reply_error_string("link not found"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2584 | } |
| 2585 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2586 | tipc_node_lock(node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2587 | link_reset_statistics(l_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2588 | tipc_node_unlock(node); |
| 2589 | read_unlock_bh(&tipc_net_lock); |
| 2590 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | /** |
| 2594 | * percent - convert count to a percentage of total (rounding up or down) |
| 2595 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2596 | static u32 percent(u32 count, u32 total) |
| 2597 | { |
| 2598 | return (count * 100 + (total / 2)) / total; |
| 2599 | } |
| 2600 | |
| 2601 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2602 | * tipc_link_stats - print link statistics |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2603 | * @name: link name |
| 2604 | * @buf: print buffer area |
| 2605 | * @buf_size: size of print buffer area |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2606 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2607 | * Returns length of print buffer data string (or 0 if error) |
| 2608 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2609 | static int tipc_link_stats(const char *name, char *buf, const u32 buf_size) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2610 | { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2611 | struct tipc_link *l; |
| 2612 | struct tipc_stats *s; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 2613 | struct tipc_node *node; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2614 | char *status; |
| 2615 | u32 profile_total = 0; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2616 | int ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2617 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2618 | if (!strcmp(name, tipc_bclink_name)) |
| 2619 | return tipc_bclink_stats(buf, buf_size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2620 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2621 | read_lock_bh(&tipc_net_lock); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2622 | l = link_find_link(name, &node); |
| 2623 | if (!l) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2624 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2625 | return 0; |
| 2626 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2627 | tipc_node_lock(node); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2628 | s = &l->stats; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2629 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2630 | if (tipc_link_is_active(l)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2631 | status = "ACTIVE"; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2632 | else if (tipc_link_is_up(l)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2633 | status = "STANDBY"; |
| 2634 | else |
| 2635 | status = "DEFUNCT"; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2636 | |
| 2637 | ret = tipc_snprintf(buf, buf_size, "Link <%s>\n" |
| 2638 | " %s MTU:%u Priority:%u Tolerance:%u ms" |
| 2639 | " Window:%u packets\n", |
| 2640 | l->name, status, l->max_pkt, l->priority, |
| 2641 | l->tolerance, l->queue_limit[0]); |
| 2642 | |
| 2643 | ret += tipc_snprintf(buf + ret, buf_size - ret, |
| 2644 | " RX packets:%u fragments:%u/%u bundles:%u/%u\n", |
| 2645 | l->next_in_no - s->recv_info, s->recv_fragments, |
| 2646 | s->recv_fragmented, s->recv_bundles, |
| 2647 | s->recv_bundled); |
| 2648 | |
| 2649 | ret += tipc_snprintf(buf + ret, buf_size - ret, |
| 2650 | " TX packets:%u fragments:%u/%u bundles:%u/%u\n", |
| 2651 | l->next_out_no - s->sent_info, s->sent_fragments, |
| 2652 | s->sent_fragmented, s->sent_bundles, |
| 2653 | s->sent_bundled); |
| 2654 | |
| 2655 | profile_total = s->msg_length_counts; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2656 | if (!profile_total) |
| 2657 | profile_total = 1; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2658 | |
| 2659 | ret += tipc_snprintf(buf + ret, buf_size - ret, |
| 2660 | " TX profile sample:%u packets average:%u octets\n" |
| 2661 | " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% " |
| 2662 | "-16384:%u%% -32768:%u%% -66000:%u%%\n", |
| 2663 | s->msg_length_counts, |
| 2664 | s->msg_lengths_total / profile_total, |
| 2665 | percent(s->msg_length_profile[0], profile_total), |
| 2666 | percent(s->msg_length_profile[1], profile_total), |
| 2667 | percent(s->msg_length_profile[2], profile_total), |
| 2668 | percent(s->msg_length_profile[3], profile_total), |
| 2669 | percent(s->msg_length_profile[4], profile_total), |
| 2670 | percent(s->msg_length_profile[5], profile_total), |
| 2671 | percent(s->msg_length_profile[6], profile_total)); |
| 2672 | |
| 2673 | ret += tipc_snprintf(buf + ret, buf_size - ret, |
| 2674 | " RX states:%u probes:%u naks:%u defs:%u" |
| 2675 | " dups:%u\n", s->recv_states, s->recv_probes, |
| 2676 | s->recv_nacks, s->deferred_recv, s->duplicates); |
| 2677 | |
| 2678 | ret += tipc_snprintf(buf + ret, buf_size - ret, |
| 2679 | " TX states:%u probes:%u naks:%u acks:%u" |
| 2680 | " dups:%u\n", s->sent_states, s->sent_probes, |
| 2681 | s->sent_nacks, s->sent_acks, s->retransmitted); |
| 2682 | |
| 2683 | ret += tipc_snprintf(buf + ret, buf_size - ret, |
Ying Xue | 3c294cb | 2012-11-15 11:34:45 +0800 | [diff] [blame] | 2684 | " Congestion link:%u Send queue" |
| 2685 | " max:%u avg:%u\n", s->link_congs, |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2686 | s->max_queue_sz, s->queue_sz_counts ? |
| 2687 | (s->accu_queue_sz / s->queue_sz_counts) : 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2688 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2689 | tipc_node_unlock(node); |
| 2690 | read_unlock_bh(&tipc_net_lock); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2691 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2692 | } |
| 2693 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2694 | struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2695 | { |
| 2696 | struct sk_buff *buf; |
| 2697 | struct tlv_desc *rep_tlv; |
| 2698 | int str_len; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2699 | int pb_len; |
| 2700 | char *pb; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2701 | |
| 2702 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2703 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2704 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2705 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2706 | if (!buf) |
| 2707 | return NULL; |
| 2708 | |
| 2709 | rep_tlv = (struct tlv_desc *)buf->data; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2710 | pb = TLV_DATA(rep_tlv); |
| 2711 | pb_len = ULTRA_STRING_MAX_LEN; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2712 | str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area), |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2713 | pb, pb_len); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2714 | if (!str_len) { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2715 | kfree_skb(buf); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2716 | return tipc_cfg_reply_error_string("link not found"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2717 | } |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 2718 | str_len += 1; /* for "\0" */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2719 | skb_put(buf, TLV_SPACE(str_len)); |
| 2720 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 2721 | |
| 2722 | return buf; |
| 2723 | } |
| 2724 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2725 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2726 | * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2727 | * @dest: network address of destination node |
| 2728 | * @selector: used to select from set of active links |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2729 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2730 | * If no active link can be found, uses default maximum packet size. |
| 2731 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2732 | u32 tipc_link_get_max_pkt(u32 dest, u32 selector) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2733 | { |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 2734 | struct tipc_node *n_ptr; |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2735 | struct tipc_link *l_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2736 | u32 res = MAX_PKT_DEFAULT; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2737 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2738 | if (dest == tipc_own_addr) |
| 2739 | return MAX_MSG_SIZE; |
| 2740 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2741 | read_lock_bh(&tipc_net_lock); |
Allan Stephens | 51a8e4d | 2010-12-31 18:59:18 +0000 | [diff] [blame] | 2742 | n_ptr = tipc_node_find(dest); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2743 | if (n_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2744 | tipc_node_lock(n_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2745 | l_ptr = n_ptr->active_links[selector & 1]; |
| 2746 | if (l_ptr) |
Allan Stephens | 15e979d | 2010-05-11 14:30:10 +0000 | [diff] [blame] | 2747 | res = l_ptr->max_pkt; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2748 | tipc_node_unlock(n_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2749 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2750 | read_unlock_bh(&tipc_net_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2751 | return res; |
| 2752 | } |
| 2753 | |
Paul Gortmaker | a18c4bc | 2011-12-29 20:58:42 -0500 | [diff] [blame] | 2754 | static void link_print(struct tipc_link *l_ptr, const char *str) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2755 | { |
Paul Gortmaker | 5deedde | 2012-07-11 19:27:56 -0400 | [diff] [blame] | 2756 | pr_info("%s Link %x<%s>:", str, l_ptr->addr, l_ptr->b_ptr->name); |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 2757 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2758 | if (link_working_unknown(l_ptr)) |
Paul Gortmaker | 5deedde | 2012-07-11 19:27:56 -0400 | [diff] [blame] | 2759 | pr_cont(":WU\n"); |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 2760 | else if (link_reset_reset(l_ptr)) |
Paul Gortmaker | 5deedde | 2012-07-11 19:27:56 -0400 | [diff] [blame] | 2761 | pr_cont(":RR\n"); |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 2762 | else if (link_reset_unknown(l_ptr)) |
Paul Gortmaker | 5deedde | 2012-07-11 19:27:56 -0400 | [diff] [blame] | 2763 | pr_cont(":RU\n"); |
Allan Stephens | 8d64a5b | 2010-12-31 18:59:27 +0000 | [diff] [blame] | 2764 | else if (link_working_working(l_ptr)) |
Paul Gortmaker | 5deedde | 2012-07-11 19:27:56 -0400 | [diff] [blame] | 2765 | pr_cont(":WW\n"); |
| 2766 | else |
| 2767 | pr_cont("\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2768 | } |