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