Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 1 | /* Copyright 2011-2014 Autronica Fire and Security AS |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify it |
| 4 | * under the terms of the GNU General Public License as published by the Free |
| 5 | * Software Foundation; either version 2 of the License, or (at your option) |
| 6 | * any later version. |
| 7 | * |
| 8 | * Author(s): |
| 9 | * 2011-2014 Arvid Brodin, arvid.brodin@alten.se |
| 10 | */ |
| 11 | |
| 12 | #include "hsr_slave.h" |
| 13 | #include <linux/etherdevice.h> |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 14 | #include <linux/if_arp.h> |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 15 | #include "hsr_main.h" |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 16 | #include "hsr_device.h" |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 17 | #include "hsr_framereg.h" |
| 18 | |
| 19 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 20 | static int hsr_check_dev_ok(struct net_device *dev) |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 21 | { |
| 22 | /* Don't allow HSR on non-ethernet like devices */ |
| 23 | if ((dev->flags & IFF_LOOPBACK) || (dev->type != ARPHRD_ETHER) || |
| 24 | (dev->addr_len != ETH_ALEN)) { |
| 25 | netdev_info(dev, "Cannot use loopback or non-ethernet device as HSR slave.\n"); |
| 26 | return -EINVAL; |
| 27 | } |
| 28 | |
| 29 | /* Don't allow enslaving hsr devices */ |
| 30 | if (is_hsr_master(dev)) { |
| 31 | netdev_info(dev, "Cannot create trees of HSR devices.\n"); |
| 32 | return -EINVAL; |
| 33 | } |
| 34 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 35 | if (hsr_port_exists(dev)) { |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 36 | netdev_info(dev, "This device is already a HSR slave.\n"); |
| 37 | return -EINVAL; |
| 38 | } |
| 39 | |
| 40 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 41 | netdev_info(dev, "HSR on top of VLAN is not yet supported in this driver.\n"); |
| 42 | return -EINVAL; |
| 43 | } |
| 44 | |
| 45 | /* HSR over bonded devices has not been tested, but I'm not sure it |
| 46 | * won't work... |
| 47 | */ |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 53 | static struct sk_buff *hsr_pull_tag(struct sk_buff *skb) |
| 54 | { |
| 55 | struct hsr_tag *hsr_tag; |
| 56 | struct sk_buff *skb2; |
| 57 | |
| 58 | skb2 = skb_share_check(skb, GFP_ATOMIC); |
| 59 | if (unlikely(!skb2)) |
| 60 | goto err_free; |
| 61 | skb = skb2; |
| 62 | |
| 63 | if (unlikely(!pskb_may_pull(skb, HSR_HLEN))) |
| 64 | goto err_free; |
| 65 | |
| 66 | hsr_tag = (struct hsr_tag *) skb->data; |
| 67 | skb->protocol = hsr_tag->encap_proto; |
| 68 | skb_pull(skb, HSR_HLEN); |
| 69 | |
| 70 | return skb; |
| 71 | |
| 72 | err_free: |
| 73 | kfree_skb(skb); |
| 74 | return NULL; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /* The uses I can see for these HSR supervision frames are: |
| 79 | * 1) Use the frames that are sent after node initialization ("HSR_TLV.Type = |
| 80 | * 22") to reset any sequence_nr counters belonging to that node. Useful if |
| 81 | * the other node's counter has been reset for some reason. |
| 82 | * -- |
| 83 | * Or not - resetting the counter and bridging the frame would create a |
| 84 | * loop, unfortunately. |
| 85 | * |
| 86 | * 2) Use the LifeCheck frames to detect ring breaks. I.e. if no LifeCheck |
| 87 | * frame is received from a particular node, we know something is wrong. |
| 88 | * We just register these (as with normal frames) and throw them away. |
| 89 | * |
| 90 | * 3) Allow different MAC addresses for the two slave interfaces, using the |
| 91 | * MacAddressA field. |
| 92 | */ |
| 93 | static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb) |
| 94 | { |
| 95 | struct hsr_sup_tag *hsr_stag; |
| 96 | |
| 97 | if (!ether_addr_equal(eth_hdr(skb)->h_dest, |
| 98 | hsr->sup_multicast_addr)) |
| 99 | return false; |
| 100 | |
| 101 | hsr_stag = (struct hsr_sup_tag *) skb->data; |
| 102 | if (get_hsr_stag_path(hsr_stag) != 0x0f) |
| 103 | return false; |
| 104 | if ((hsr_stag->HSR_TLV_Type != HSR_TLV_ANNOUNCE) && |
| 105 | (hsr_stag->HSR_TLV_Type != HSR_TLV_LIFE_CHECK)) |
| 106 | return false; |
| 107 | if (hsr_stag->HSR_TLV_Length != 12) |
| 108 | return false; |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /* Implementation somewhat according to IEC-62439-3, p. 43 |
| 115 | */ |
| 116 | rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) |
| 117 | { |
| 118 | struct sk_buff *skb = *pskb; |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 119 | struct hsr_port *port, *other_port, *master; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 120 | struct hsr_priv *hsr; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 121 | struct hsr_node *node; |
| 122 | bool deliver_to_self; |
| 123 | struct sk_buff *skb_deliver; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 124 | bool dup_out; |
| 125 | int ret; |
| 126 | |
| 127 | if (eth_hdr(skb)->h_proto != htons(ETH_P_PRP)) |
| 128 | return RX_HANDLER_PASS; |
| 129 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 130 | rcu_read_lock(); /* ports & node */ |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 131 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 132 | port = hsr_port_get_rcu(skb->dev); |
| 133 | hsr = port->hsr; |
| 134 | master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 135 | |
| 136 | node = hsr_find_node(&hsr->self_node_db, skb); |
| 137 | if (node) { |
| 138 | /* Always kill frames sent by ourselves */ |
| 139 | kfree_skb(skb); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 140 | ret = RX_HANDLER_CONSUMED; |
| 141 | goto finish; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* Is this frame a candidate for local reception? */ |
| 145 | deliver_to_self = false; |
| 146 | if ((skb->pkt_type == PACKET_HOST) || |
| 147 | (skb->pkt_type == PACKET_MULTICAST) || |
| 148 | (skb->pkt_type == PACKET_BROADCAST)) |
| 149 | deliver_to_self = true; |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 150 | else if (ether_addr_equal(eth_hdr(skb)->h_dest, |
| 151 | master->dev->dev_addr)) { |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 152 | skb->pkt_type = PACKET_HOST; |
| 153 | deliver_to_self = true; |
| 154 | } |
| 155 | |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 156 | node = hsr_find_node(&hsr->node_db, skb); |
| 157 | |
| 158 | if (is_supervision_frame(hsr, skb)) { |
| 159 | skb_pull(skb, sizeof(struct hsr_sup_tag)); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 160 | node = hsr_merge_node(node, skb, port); |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 161 | if (!node) { |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 162 | kfree_skb(skb); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 163 | master->dev->stats.rx_dropped++; |
| 164 | ret = RX_HANDLER_CONSUMED; |
| 165 | goto finish; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 166 | } |
| 167 | skb_push(skb, sizeof(struct hsr_sup_tag)); |
| 168 | deliver_to_self = false; |
| 169 | } |
| 170 | |
| 171 | if (!node) { |
| 172 | /* Source node unknown; this might be a HSR frame from |
| 173 | * another net (different multicast address). Ignore it. |
| 174 | */ |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 175 | kfree_skb(skb); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 176 | ret = RX_HANDLER_CONSUMED; |
| 177 | goto finish; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 180 | if (port->type == HSR_PT_SLAVE_A) |
| 181 | other_port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); |
| 182 | else |
| 183 | other_port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); |
| 184 | |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 185 | /* Register ALL incoming frames as outgoing through the other interface. |
| 186 | * This allows us to register frames as incoming only if they are valid |
| 187 | * for the receiving interface, without using a specific counter for |
| 188 | * incoming frames. |
| 189 | */ |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 190 | if (other_port) |
| 191 | dup_out = hsr_register_frame_out(node, other_port, skb); |
| 192 | else |
| 193 | dup_out = 0; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 194 | if (!dup_out) |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 195 | hsr_register_frame_in(node, port); |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 196 | |
| 197 | /* Forward this frame? */ |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 198 | if (dup_out || (skb->pkt_type == PACKET_HOST)) |
| 199 | other_port = NULL; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 200 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 201 | if (hsr_register_frame_out(node, master, skb)) |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 202 | deliver_to_self = false; |
| 203 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 204 | if (!deliver_to_self && !other_port) { |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 205 | kfree_skb(skb); |
| 206 | /* Circulated frame; silently remove it. */ |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 207 | ret = RX_HANDLER_CONSUMED; |
| 208 | goto finish; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | skb_deliver = skb; |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 212 | if (deliver_to_self && other_port) { |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 213 | /* skb_clone() is not enough since we will strip the hsr tag |
| 214 | * and do address substitution below |
| 215 | */ |
| 216 | skb_deliver = pskb_copy(skb, GFP_ATOMIC); |
| 217 | if (!skb_deliver) { |
| 218 | deliver_to_self = false; |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 219 | master->dev->stats.rx_dropped++; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | if (deliver_to_self) { |
| 224 | bool multicast_frame; |
| 225 | |
| 226 | skb_deliver = hsr_pull_tag(skb_deliver); |
| 227 | if (!skb_deliver) { |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 228 | master->dev->stats.rx_dropped++; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 229 | goto forward; |
| 230 | } |
| 231 | #if !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 232 | /* Move everything in the header that is after the HSR tag, |
| 233 | * to work around alignment problems caused by the 6-byte HSR |
| 234 | * tag. In practice, this removes/overwrites the HSR tag in |
| 235 | * the header and restores a "standard" packet. |
| 236 | */ |
| 237 | memmove(skb_deliver->data - HSR_HLEN, skb_deliver->data, |
| 238 | skb_headlen(skb_deliver)); |
| 239 | |
| 240 | /* Adjust skb members so they correspond with the move above. |
| 241 | * This cannot possibly underflow skb->data since hsr_pull_tag() |
| 242 | * above succeeded. |
| 243 | * At this point in the protocol stack, the transport and |
| 244 | * network headers have not been set yet, and we haven't touched |
| 245 | * the mac header nor the head. So we only need to adjust data |
| 246 | * and tail: |
| 247 | */ |
| 248 | skb_deliver->data -= HSR_HLEN; |
| 249 | skb_deliver->tail -= HSR_HLEN; |
| 250 | #endif |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 251 | skb_deliver->dev = master->dev; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 252 | hsr_addr_subst_source(hsr, skb_deliver); |
| 253 | multicast_frame = (skb_deliver->pkt_type == PACKET_MULTICAST); |
| 254 | ret = netif_rx(skb_deliver); |
| 255 | if (ret == NET_RX_DROP) { |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 256 | master->dev->stats.rx_dropped++; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 257 | } else { |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 258 | master->dev->stats.rx_packets++; |
| 259 | master->dev->stats.rx_bytes += skb->len; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 260 | if (multicast_frame) |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 261 | master->dev->stats.multicast++; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | forward: |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 266 | if (other_port) { |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 267 | skb_push(skb, ETH_HLEN); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 268 | skb->dev = other_port->dev; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 269 | dev_queue_xmit(skb); |
| 270 | } |
| 271 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 272 | ret = RX_HANDLER_CONSUMED; |
| 273 | |
| 274 | finish: |
| 275 | rcu_read_unlock(); |
| 276 | return ret; |
Arvid Brodin | 81ba6af | 2014-07-04 23:35:24 +0200 | [diff] [blame] | 277 | } |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 278 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 279 | /* Setup device to be added to the HSR bridge. */ |
| 280 | static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port) |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 281 | { |
| 282 | int res; |
| 283 | |
| 284 | dev_hold(dev); |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 285 | res = dev_set_promiscuity(dev, 1); |
| 286 | if (res) |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 287 | goto fail_promiscuity; |
| 288 | res = netdev_rx_handler_register(dev, hsr_handle_frame, port); |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 289 | if (res) |
| 290 | goto fail_rx_handler; |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 291 | dev_disable_lro(dev); |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 292 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 293 | /* FIXME: |
| 294 | * What does net device "adjacency" mean? Should we do |
| 295 | * res = netdev_master_upper_dev_link(port->dev, port->hsr->dev); ? |
| 296 | */ |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 297 | |
| 298 | return 0; |
| 299 | |
| 300 | fail_rx_handler: |
| 301 | dev_set_promiscuity(dev, -1); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 302 | fail_promiscuity: |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 303 | dev_put(dev); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 304 | |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 305 | return res; |
| 306 | } |
| 307 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 308 | int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, |
| 309 | enum hsr_port_type type) |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 310 | { |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 311 | struct hsr_port *port, *master; |
| 312 | int res; |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 313 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 314 | if (type != HSR_PT_MASTER) { |
| 315 | res = hsr_check_dev_ok(dev); |
| 316 | if (res) |
| 317 | return res; |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 320 | port = hsr_port_get_hsr(hsr, type); |
| 321 | if (port != NULL) |
| 322 | return -EBUSY; /* This port already exists */ |
| 323 | |
| 324 | port = kzalloc(sizeof(*port), GFP_KERNEL); |
| 325 | if (port == NULL) |
| 326 | return -ENOMEM; |
| 327 | |
| 328 | if (type != HSR_PT_MASTER) { |
| 329 | res = hsr_portdev_setup(dev, port); |
| 330 | if (res) |
| 331 | goto fail_dev_setup; |
| 332 | } |
| 333 | |
| 334 | port->hsr = hsr; |
| 335 | port->dev = dev; |
| 336 | port->type = type; |
| 337 | |
| 338 | list_add_tail_rcu(&port->port_list, &hsr->ports); |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 339 | synchronize_rcu(); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 340 | |
| 341 | master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); |
| 342 | |
| 343 | /* Set required header length */ |
| 344 | if (dev->hard_header_len + HSR_HLEN > master->dev->hard_header_len) |
| 345 | master->dev->hard_header_len = dev->hard_header_len + HSR_HLEN; |
| 346 | |
Arvid Brodin | 1cc1eb5 | 2014-07-04 23:38:57 +0200 | [diff] [blame^] | 347 | netdev_update_features(master->dev); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 348 | dev_set_mtu(master->dev, hsr_get_max_mtu(hsr)); |
| 349 | |
| 350 | return 0; |
| 351 | |
| 352 | fail_dev_setup: |
| 353 | kfree(port); |
| 354 | return res; |
| 355 | } |
| 356 | |
| 357 | void hsr_del_port(struct hsr_port *port) |
| 358 | { |
| 359 | struct hsr_priv *hsr; |
| 360 | struct hsr_port *master; |
| 361 | |
| 362 | hsr = port->hsr; |
| 363 | master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); |
| 364 | list_del_rcu(&port->port_list); |
| 365 | |
| 366 | if (port != master) { |
Arvid Brodin | 1cc1eb5 | 2014-07-04 23:38:57 +0200 | [diff] [blame^] | 367 | netdev_update_features(master->dev); |
Arvid Brodin | c5a7591 | 2014-07-04 23:38:05 +0200 | [diff] [blame] | 368 | dev_set_mtu(master->dev, hsr_get_max_mtu(hsr)); |
| 369 | netdev_rx_handler_unregister(port->dev); |
| 370 | dev_set_promiscuity(port->dev, -1); |
| 371 | } |
| 372 | |
| 373 | /* FIXME? |
| 374 | * netdev_upper_dev_unlink(port->dev, port->hsr->dev); |
| 375 | */ |
| 376 | |
| 377 | synchronize_rcu(); |
| 378 | dev_put(port->dev); |
Arvid Brodin | 51f3c60 | 2014-07-04 23:37:27 +0200 | [diff] [blame] | 379 | } |