Changes in 4.9.218 spi: qup: call spi_qup_pm_resume_runtime before suspending powerpc: Include .BTF section ARM: dts: dra7: Add "dma-ranges" property to PCIe RC DT nodes spi/zynqmp: remove entry that causes a cs glitch drm/exynos: dsi: propagate error value and silence meaningless warning drm/exynos: dsi: fix workaround for the legacy clock name altera-stapl: altera_get_note: prevent write beyond end of 'key' USB: Disable LPM on WD19's Realtek Hub usb: quirks: add NO_LPM quirk for RTL8153 based ethernet adapters USB: serial: option: add ME910G1 ECM composition 0x110b usb: host: xhci-plat: add a shutdown USB: serial: pl2303: add device-id for HP LD381 ALSA: line6: Fix endless MIDI read loop ALSA: seq: virmidi: Fix running status after receiving sysex ALSA: seq: oss: Fix running status after receiving sysex ALSA: pcm: oss: Avoid plugin buffer overflow ALSA: pcm: oss: Remove WARNING from snd_pcm_plug_alloc() checks iio: magnetometer: ak8974: Fix negative raw values in sysfs mmc: sdhci-of-at91: fix cd-gpios for SAMA5D2 staging: rtl8188eu: Add device id for MERCUSYS MW150US v2 staging/speakup: fix get_word non-space look-ahead intel_th: Fix user-visible error codes rtc: max8907: add missing select REGMAP_IRQ memcg: fix NULL pointer dereference in __mem_cgroup_usage_unregister_event mm: slub: be more careful about the double cmpxchg of freelist mm, slub: prevent kmalloc_node crashes and memory leaks x86/mm: split vmalloc_sync_all() USB: cdc-acm: fix close_delay and closing_wait units in TIOCSSERIAL USB: cdc-acm: fix rounding error in TIOCSSERIAL kbuild: Disable -Wpointer-to-enum-cast futex: Fix inode life-time issue futex: Unbreak futex hashing ALSA: hda/realtek: Fix pop noise on ALC225 arm64: smp: fix smp_send_stop() behaviour staging: greybus: loopback_test: fix potential path truncation staging: greybus: loopback_test: fix potential path truncations Revert "drm/dp_mst: Skip validating ports during destruction, just ref" hsr: fix general protection fault in hsr_addr_is_self() macsec: restrict to ethernet devices net: dsa: Fix duplicate frames flooded by learning net_sched: cls_route: remove the right filter from hashtable net_sched: keep alloc_hash updated after hash allocation NFC: fdp: Fix a signedness bug in fdp_nci_send_patch() slcan: not call free_netdev before rtnl_unlock in slcan_open vxlan: check return value of gro_cells_init() net: mvneta: Fix the case where the last poll did not process all rx hsr: use rcu_read_lock() in hsr_get_node_{list/status}() hsr: add restart routine into hsr_get_node_list() hsr: set .netnsok flag KVM: VMX: Do not allow reexecute_instruction() when skipping MMIO instr net: ipv4: don't let PMTU updates increase route MTU cpupower: avoid multiple definition with gcc -fno-common dt-bindings: net: FMan erratum A050385 scsi: ipr: Fix softlockup when rescanning devices in petitboot mac80211: Do not send mesh HWMP PREQ if HWMP is disabled sxgbe: Fix off by one in samsung driver strncpy size arg i2c: hix5hd2: add missed clk_disable_unprepare in remove ARM: dts: dra7: Add bus_dma_limit for L3 bus ARM: dts: omap5: Add bus_dma_limit for L3 bus perf probe: Do not depend on dwfl_module_addrsym() scripts/dtc: Remove redundant YYLOC global declaration scsi: sd: Fix optimal I/O size for devices that change reported values mac80211: mark station unauthorized before key removal genirq: Fix reference leaks on irq affinity notifiers vti[6]: fix packet tx through bpf_redirect() in XinY cases xfrm: fix uctx len check in verify_sec_ctx_len xfrm: add the missing verify_sec_ctx_len check in xfrm_add_acquire xfrm: policy: Fix doulbe free in xfrm_policy_timer netfilter: nft_fwd_netdev: validate family and chain type vti6: Fix memory leak of skb if input policy check fails Input: raydium_i2c_ts - use true and false for boolean values Input: raydium_i2c_ts - fix error codes in raydium_i2c_boot_trigger() tools: Let O= makes handle a relative path with -C option USB: serial: option: add support for ASKEY WWHC050 USB: serial: option: add BroadMobi BM806U USB: serial: option: add Wistron Neweb D19Q1 USB: cdc-acm: restore capability check order USB: serial: io_edgeport: fix slab-out-of-bounds read in edge_interrupt_callback usb: musb: fix crash with highmen PIO and usbmon media: flexcop-usb: fix endpoint sanity check media: usbtv: fix control-message timeouts staging: rtl8188eu: Add ASUS USB-N10 Nano B1 to device table staging: wlan-ng: fix ODEBUG bug in prism2sta_disconnect_usb staging: wlan-ng: fix use-after-free Read in hfa384x_usbin_callback libfs: fix infoleak in simple_attr_read() media: ov519: add missing endpoint sanity checks media: dib0700: fix rc endpoint lookup media: stv06xx: add missing descriptor sanity checks media: xirlink_cit: add missing descriptor sanity checks mac80211: Check port authorization in the ieee80211_tx_dequeue() case mac80211: fix authentication with iwlwifi/mvm vt: selection, introduce vc_is_sel vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines vt: switch vt_dont_switch to bool vt: vt_ioctl: remove unnecessary console allocation checks vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console locking/atomic, kref: Add kref_read() vt: vt_ioctl: fix use-after-free in vt_in_use() bpf: Explicitly memset the bpf_attr structure net: ks8851-ml: Fix IO operations, again arm64: alternative: fix build with clang integrated assembler perf map: Fix off by one in strncpy() size argument Linux 4.9.218 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I93ee241fe88658b93a22ab85752e8aa9883f6f98
205 lines
4.4 KiB
C
205 lines
4.4 KiB
C
/* Copyright 2011-2014 Autronica Fire and Security AS
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* Author(s):
|
|
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se
|
|
*/
|
|
|
|
#include "hsr_slave.h"
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/if_arp.h>
|
|
#include "hsr_main.h"
|
|
#include "hsr_device.h"
|
|
#include "hsr_forward.h"
|
|
#include "hsr_framereg.h"
|
|
|
|
|
|
static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
|
|
{
|
|
struct sk_buff *skb = *pskb;
|
|
struct hsr_port *port;
|
|
u16 protocol;
|
|
|
|
if (!skb_mac_header_was_set(skb)) {
|
|
WARN_ONCE(1, "%s: skb invalid", __func__);
|
|
return RX_HANDLER_PASS;
|
|
}
|
|
|
|
rcu_read_lock(); /* hsr->node_db, hsr->ports */
|
|
port = hsr_port_get_rcu(skb->dev);
|
|
if (!port)
|
|
goto finish_pass;
|
|
|
|
if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) {
|
|
/* Directly kill frames sent by ourselves */
|
|
kfree_skb(skb);
|
|
goto finish_consume;
|
|
}
|
|
|
|
protocol = eth_hdr(skb)->h_proto;
|
|
if (protocol != htons(ETH_P_PRP) && protocol != htons(ETH_P_HSR))
|
|
goto finish_pass;
|
|
|
|
skb_push(skb, ETH_HLEN);
|
|
|
|
hsr_forward_skb(skb, port);
|
|
|
|
finish_consume:
|
|
rcu_read_unlock(); /* hsr->node_db, hsr->ports */
|
|
return RX_HANDLER_CONSUMED;
|
|
|
|
finish_pass:
|
|
rcu_read_unlock(); /* hsr->node_db, hsr->ports */
|
|
return RX_HANDLER_PASS;
|
|
}
|
|
|
|
bool hsr_port_exists(const struct net_device *dev)
|
|
{
|
|
return rcu_access_pointer(dev->rx_handler) == hsr_handle_frame;
|
|
}
|
|
|
|
|
|
static int hsr_check_dev_ok(struct net_device *dev)
|
|
{
|
|
/* Don't allow HSR on non-ethernet like devices */
|
|
if ((dev->flags & IFF_LOOPBACK) || (dev->type != ARPHRD_ETHER) ||
|
|
(dev->addr_len != ETH_ALEN)) {
|
|
netdev_info(dev, "Cannot use loopback or non-ethernet device as HSR slave.\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Don't allow enslaving hsr devices */
|
|
if (is_hsr_master(dev)) {
|
|
netdev_info(dev, "Cannot create trees of HSR devices.\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (hsr_port_exists(dev)) {
|
|
netdev_info(dev, "This device is already a HSR slave.\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (dev->priv_flags & IFF_802_1Q_VLAN) {
|
|
netdev_info(dev, "HSR on top of VLAN is not yet supported in this driver.\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (dev->priv_flags & IFF_DONT_BRIDGE) {
|
|
netdev_info(dev, "This device does not support bridging.\n");
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
/* HSR over bonded devices has not been tested, but I'm not sure it
|
|
* won't work...
|
|
*/
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/* Setup device to be added to the HSR bridge. */
|
|
static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port)
|
|
{
|
|
int res;
|
|
|
|
dev_hold(dev);
|
|
res = dev_set_promiscuity(dev, 1);
|
|
if (res)
|
|
goto fail_promiscuity;
|
|
|
|
/* FIXME:
|
|
* What does net device "adjacency" mean? Should we do
|
|
* res = netdev_master_upper_dev_link(port->dev, port->hsr->dev); ?
|
|
*/
|
|
|
|
res = netdev_rx_handler_register(dev, hsr_handle_frame, port);
|
|
if (res)
|
|
goto fail_rx_handler;
|
|
dev_disable_lro(dev);
|
|
|
|
return 0;
|
|
|
|
fail_rx_handler:
|
|
dev_set_promiscuity(dev, -1);
|
|
fail_promiscuity:
|
|
dev_put(dev);
|
|
|
|
return res;
|
|
}
|
|
|
|
int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
|
|
enum hsr_port_type type)
|
|
{
|
|
struct hsr_port *port, *master;
|
|
int res;
|
|
|
|
if (type != HSR_PT_MASTER) {
|
|
res = hsr_check_dev_ok(dev);
|
|
if (res)
|
|
return res;
|
|
}
|
|
|
|
port = hsr_port_get_hsr(hsr, type);
|
|
if (port != NULL)
|
|
return -EBUSY; /* This port already exists */
|
|
|
|
port = kzalloc(sizeof(*port), GFP_KERNEL);
|
|
if (port == NULL)
|
|
return -ENOMEM;
|
|
|
|
port->hsr = hsr;
|
|
port->dev = dev;
|
|
port->type = type;
|
|
|
|
if (type != HSR_PT_MASTER) {
|
|
res = hsr_portdev_setup(dev, port);
|
|
if (res)
|
|
goto fail_dev_setup;
|
|
}
|
|
|
|
list_add_tail_rcu(&port->port_list, &hsr->ports);
|
|
synchronize_rcu();
|
|
|
|
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
|
|
netdev_update_features(master->dev);
|
|
dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
|
|
|
|
return 0;
|
|
|
|
fail_dev_setup:
|
|
kfree(port);
|
|
return res;
|
|
}
|
|
|
|
void hsr_del_port(struct hsr_port *port)
|
|
{
|
|
struct hsr_priv *hsr;
|
|
struct hsr_port *master;
|
|
|
|
hsr = port->hsr;
|
|
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
|
|
list_del_rcu(&port->port_list);
|
|
|
|
if (port != master) {
|
|
if (master != NULL) {
|
|
netdev_update_features(master->dev);
|
|
dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
|
|
}
|
|
netdev_rx_handler_unregister(port->dev);
|
|
dev_set_promiscuity(port->dev, -1);
|
|
}
|
|
|
|
/* FIXME?
|
|
* netdev_upper_dev_unlink(port->dev, port->hsr->dev);
|
|
*/
|
|
|
|
synchronize_rcu();
|
|
|
|
if (port != master)
|
|
dev_put(port->dev);
|
|
}
|