Changes in 4.9.220 bus: sunxi-rsb: Return correct data when mixing 16-bit and 8-bit reads net: vxge: fix wrong __VA_ARGS__ usage qlcnic: Fix bad kzalloc null test i2c: st: fix missing struct parameter description irqchip/versatile-fpga: Handle chained IRQs properly sched: Avoid scale real weight down to zero selftests/x86/ptrace_syscall_32: Fix no-vDSO segfault libata: Remove extra scsi_host_put() in ata_scsi_add_hosts() gfs2: Don't demote a glock until its revokes are written x86/boot: Use unsigned comparison for addresses locking/lockdep: Avoid recursion in lockdep_count_{for,back}ward_deps() btrfs: remove a BUG_ON() from merge_reloc_roots() btrfs: track reloc roots based on their commit root bytenr misc: rtsx: set correct pcr_ops for rts522A ASoC: fix regwmask ASoC: dapm: connect virtual mux with default value ASoC: dpcm: allow start or stop during pause for backend ASoC: topology: use name_prefix for new kcontrol usb: gadget: f_fs: Fix use after free issue as part of queue failure usb: gadget: composite: Inform controller driver of self-powered ALSA: usb-audio: Add mixer workaround for TRX40 and co ALSA: hda: Add driver blacklist ALSA: hda: Fix potential access overflow in beep helper ALSA: ice1724: Fix invalid access for enumerated ctl items ALSA: pcm: oss: Fix regression by buffer overflow fix media: ti-vpe: cal: fix disable_irqs to only the intended target acpi/x86: ignore unspecified bit positions in the ACPI global lock field thermal: devfreq_cooling: inline all stubs for CONFIG_DEVFREQ_THERMAL=n KEYS: reaching the keys quotas correctly irqchip/versatile-fpga: Apply clear-mask earlier MIPS: OCTEON: irq: Fix potential NULL pointer dereference ath9k: Handle txpower changes even when TPC is disabled signal: Extend exec_id to 64bits x86/entry/32: Add missing ASM_CLAC to general_protection entry KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks KVM: s390: vsie: Fix delivery of addressing exceptions KVM: x86: Allocate new rmap and large page tracking when moving memslot KVM: VMX: Always VMCLEAR in-use VMCSes during crash with kexec support KVM: VMX: fix crash cleanup when KVM wasn't used btrfs: drop block from cache on error in relocation crypto: mxs-dcp - fix scatterlist linearization for hash ALSA: hda: Initialize power_state field properly x86/speculation: Remove redundant arch_smt_update() invocation tools: gpio: Fix out-of-tree build regression mm: Use fixed constant in page_frag_alloc instead of size + 1 dm verity fec: fix memory leak in verity_fec_dtr scsi: zfcp: fix missing erp_lock in port recovery trigger for point-to-point arm64: armv8_deprecated: Fix undef_hook mask for thumb setend rtc: omap: Use define directive for PIN_CONFIG_ACTIVE_HIGH ext4: fix a data race at inode->i_blocks ocfs2: no need try to truncate file beyond i_size s390/diag: fix display of diagnose call statistics Input: i8042 - add Acer Aspire 5738z to nomux list kmod: make request_module() return an error when autoloading is disabled cpufreq: powernv: Fix use-after-free hfsplus: fix crash and filesystem corruption when deleting files libata: Return correct status in sata_pmp_eh_recover_pm() when ATA_DFLAG_DETACH is set powerpc/64/tm: Don't let userspace set regs->trap via sigreturn Btrfs: fix crash during unmount due to race with delayed inode workers drm/dp_mst: Fix clearing payload state on topology disable drm: Remove PageReserved manipulation from drm_pci_alloc ipmi: fix hung processes in __get_guid() powerpc/fsl_booke: Avoid creating duplicate tlb1 entry misc: echo: Remove unnecessary parentheses and simplify check for zero mfd: dln2: Fix sanity checking for endpoints hsr: check protocol version in hsr_newlink() net: ipv4: devinet: Fix crash when add/del multicast IP with autojoin net: qrtr: send msgs from local of same id as broadcast net: ipv6: do not consider routes via gateways for anycast address check scsi: ufs: Fix ufshcd_hold() caused scheduling while atomic jbd2: improve comments about freeing data buffers whose page mapping is NULL ext4: fix incorrect group count in ext4_fill_super error message ext4: fix incorrect inodes per group in error message ASoC: Intel: mrfld: fix incorrect check on p->sink ASoC: Intel: mrfld: return error codes when an error occurs ALSA: usb-audio: Don't override ignore_ctl_error value from the map btrfs: check commit root generation in should_ignore_root mac80211_hwsim: Use kstrndup() in place of kasprintf() ext4: do not zeroout extents beyond i_disksize dm flakey: check for null arg_name in parse_features() kvm: x86: Host feature SSBD doesn't imply guest feature SPEC_CTRL_SSBD scsi: target: remove boilerplate code scsi: target: fix hang when multiple threads try to destroy the same iscsi session tracing: Fix the race between registering 'snapshot' event trigger and triggering 'snapshot' operation objtool: Fix switch table detection in .text.unlikely scsi: sg: add sg_remove_request in sg_common_write ALSA: hda: Don't release card at firmware loading error video: fbdev: sis: Remove unnecessary parentheses and commented code drm: NULL pointer dereference [null-pointer-deref] (CWE 476) problem Revert "gpio: set up initial state from .get_direction()" wil6210: increase firmware ready timeout wil6210: fix temperature debugfs scsi: ufs: make sure all interrupts are processed scsi: ufs: ufs-qcom: remove broken hci version quirk wil6210: rate limit wil_rx_refill error rtc: pm8xxx: Fix issue in RTC write path wil6210: fix length check in __wmi_send soc: qcom: smem: Use le32_to_cpu for comparison of: fix missing kobject init for !SYSFS && OF_DYNAMIC config arm64: cpu_errata: include required headers of: unittest: kmemleak in of_unittest_platform_populate() clk: at91: usb: continue if clk_hw_round_rate() return zero power: supply: bq27xxx_battery: Silence deferred-probe error clk: tegra: Fix Tegra PMC clock out parents NFS: direct.c: Fix memory leak of dreq when nfs_get_lock_context fails s390/cpuinfo: fix wrong output when CPU0 is offline powerpc/maple: Fix declaration made after definition ext4: do not commit super on read-only bdev percpu_counter: fix a data race at vm_committed_as compiler.h: fix error in BUILD_BUG_ON() reporting KVM: s390: vsie: Fix possible race when shadowing region 3 tables NFS: Fix memory leaks in nfs_pageio_stop_mirroring() ext2: fix empty body warnings when -Wextra is used ext2: fix debug reference to ext2_xattr_cache libnvdimm: Out of bounds read in __nd_ioctl() iommu/amd: Fix the configuration of GCR3 table root pointer fbdev: potential information leak in do_fb_ioctl() tty: evh_bytechan: Fix out of bounds accesses locktorture: Print ratio of acquisitions, not failures mtd: lpddr: Fix a double free in probe() mtd: phram: fix a double free issue in error path x86/CPU: Add native CPUID variants returning a single datum x86/microcode/intel: replace sync_core() with native_cpuid_reg(eax) x86/vdso: Fix lsl operand order Linux 4.9.220 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I130bead53d151b84c03bac575c0f3760e14538a6
514 lines
12 KiB
C
514 lines
12 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
|
|
*
|
|
* Routines for handling Netlink messages for HSR.
|
|
*/
|
|
|
|
#include "hsr_netlink.h"
|
|
#include <linux/kernel.h>
|
|
#include <net/rtnetlink.h>
|
|
#include <net/genetlink.h>
|
|
#include "hsr_main.h"
|
|
#include "hsr_device.h"
|
|
#include "hsr_framereg.h"
|
|
|
|
static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = {
|
|
[IFLA_HSR_SLAVE1] = { .type = NLA_U32 },
|
|
[IFLA_HSR_SLAVE2] = { .type = NLA_U32 },
|
|
[IFLA_HSR_MULTICAST_SPEC] = { .type = NLA_U8 },
|
|
[IFLA_HSR_VERSION] = { .type = NLA_U8 },
|
|
[IFLA_HSR_SUPERVISION_ADDR] = { .len = ETH_ALEN },
|
|
[IFLA_HSR_SEQ_NR] = { .type = NLA_U16 },
|
|
};
|
|
|
|
|
|
/* Here, it seems a netdevice has already been allocated for us, and the
|
|
* hsr_dev_setup routine has been executed. Nice!
|
|
*/
|
|
static int hsr_newlink(struct net *src_net, struct net_device *dev,
|
|
struct nlattr *tb[], struct nlattr *data[])
|
|
{
|
|
struct net_device *link[2];
|
|
unsigned char multicast_spec, hsr_version;
|
|
|
|
if (!data) {
|
|
netdev_info(dev, "HSR: No slave devices specified\n");
|
|
return -EINVAL;
|
|
}
|
|
if (!data[IFLA_HSR_SLAVE1]) {
|
|
netdev_info(dev, "HSR: Slave1 device not specified\n");
|
|
return -EINVAL;
|
|
}
|
|
link[0] = __dev_get_by_index(src_net, nla_get_u32(data[IFLA_HSR_SLAVE1]));
|
|
if (!data[IFLA_HSR_SLAVE2]) {
|
|
netdev_info(dev, "HSR: Slave2 device not specified\n");
|
|
return -EINVAL;
|
|
}
|
|
link[1] = __dev_get_by_index(src_net, nla_get_u32(data[IFLA_HSR_SLAVE2]));
|
|
|
|
if (!link[0] || !link[1])
|
|
return -ENODEV;
|
|
if (link[0] == link[1])
|
|
return -EINVAL;
|
|
|
|
if (!data[IFLA_HSR_MULTICAST_SPEC])
|
|
multicast_spec = 0;
|
|
else
|
|
multicast_spec = nla_get_u8(data[IFLA_HSR_MULTICAST_SPEC]);
|
|
|
|
if (!data[IFLA_HSR_VERSION]) {
|
|
hsr_version = 0;
|
|
} else {
|
|
hsr_version = nla_get_u8(data[IFLA_HSR_VERSION]);
|
|
if (hsr_version > 1) {
|
|
netdev_info(dev, "Only versions 0..1 are supported");
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
return hsr_dev_finalize(dev, link, multicast_spec, hsr_version);
|
|
}
|
|
|
|
static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
|
|
{
|
|
struct hsr_priv *hsr;
|
|
struct hsr_port *port;
|
|
int res;
|
|
|
|
hsr = netdev_priv(dev);
|
|
|
|
res = 0;
|
|
|
|
rcu_read_lock();
|
|
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
|
|
if (port)
|
|
res = nla_put_u32(skb, IFLA_HSR_SLAVE1, port->dev->ifindex);
|
|
rcu_read_unlock();
|
|
if (res)
|
|
goto nla_put_failure;
|
|
|
|
rcu_read_lock();
|
|
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
|
|
if (port)
|
|
res = nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex);
|
|
rcu_read_unlock();
|
|
if (res)
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN,
|
|
hsr->sup_multicast_addr) ||
|
|
nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr))
|
|
goto nla_put_failure;
|
|
|
|
return 0;
|
|
|
|
nla_put_failure:
|
|
return -EMSGSIZE;
|
|
}
|
|
|
|
static struct rtnl_link_ops hsr_link_ops __read_mostly = {
|
|
.kind = "hsr",
|
|
.maxtype = IFLA_HSR_MAX,
|
|
.policy = hsr_policy,
|
|
.priv_size = sizeof(struct hsr_priv),
|
|
.setup = hsr_dev_setup,
|
|
.newlink = hsr_newlink,
|
|
.fill_info = hsr_fill_info,
|
|
};
|
|
|
|
|
|
|
|
/* attribute policy */
|
|
static const struct nla_policy hsr_genl_policy[HSR_A_MAX + 1] = {
|
|
[HSR_A_NODE_ADDR] = { .len = ETH_ALEN },
|
|
[HSR_A_NODE_ADDR_B] = { .len = ETH_ALEN },
|
|
[HSR_A_IFINDEX] = { .type = NLA_U32 },
|
|
[HSR_A_IF1_AGE] = { .type = NLA_U32 },
|
|
[HSR_A_IF2_AGE] = { .type = NLA_U32 },
|
|
[HSR_A_IF1_SEQ] = { .type = NLA_U16 },
|
|
[HSR_A_IF2_SEQ] = { .type = NLA_U16 },
|
|
};
|
|
|
|
static struct genl_family hsr_genl_family = {
|
|
.id = GENL_ID_GENERATE,
|
|
.hdrsize = 0,
|
|
.name = "HSR",
|
|
.version = 1,
|
|
.maxattr = HSR_A_MAX,
|
|
.netnsok = true,
|
|
};
|
|
|
|
static const struct genl_multicast_group hsr_mcgrps[] = {
|
|
{ .name = "hsr-network", },
|
|
};
|
|
|
|
|
|
|
|
/* This is called if for some node with MAC address addr, we only get frames
|
|
* over one of the slave interfaces. This would indicate an open network ring
|
|
* (i.e. a link has failed somewhere).
|
|
*/
|
|
void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN],
|
|
struct hsr_port *port)
|
|
{
|
|
struct sk_buff *skb;
|
|
void *msg_head;
|
|
struct hsr_port *master;
|
|
int res;
|
|
|
|
skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
|
|
if (!skb)
|
|
goto fail;
|
|
|
|
msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, HSR_C_RING_ERROR);
|
|
if (!msg_head)
|
|
goto nla_put_failure;
|
|
|
|
res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
res = nla_put_u32(skb, HSR_A_IFINDEX, port->dev->ifindex);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
genlmsg_end(skb, msg_head);
|
|
genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
|
|
|
|
return;
|
|
|
|
nla_put_failure:
|
|
kfree_skb(skb);
|
|
|
|
fail:
|
|
rcu_read_lock();
|
|
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
|
|
netdev_warn(master->dev, "Could not send HSR ring error message\n");
|
|
rcu_read_unlock();
|
|
}
|
|
|
|
/* This is called when we haven't heard from the node with MAC address addr for
|
|
* some time (just before the node is removed from the node table/list).
|
|
*/
|
|
void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN])
|
|
{
|
|
struct sk_buff *skb;
|
|
void *msg_head;
|
|
struct hsr_port *master;
|
|
int res;
|
|
|
|
skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
|
|
if (!skb)
|
|
goto fail;
|
|
|
|
msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, HSR_C_NODE_DOWN);
|
|
if (!msg_head)
|
|
goto nla_put_failure;
|
|
|
|
|
|
res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
genlmsg_end(skb, msg_head);
|
|
genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
|
|
|
|
return;
|
|
|
|
nla_put_failure:
|
|
kfree_skb(skb);
|
|
|
|
fail:
|
|
rcu_read_lock();
|
|
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
|
|
netdev_warn(master->dev, "Could not send HSR node down\n");
|
|
rcu_read_unlock();
|
|
}
|
|
|
|
|
|
/* HSR_C_GET_NODE_STATUS lets userspace query the internal HSR node table
|
|
* about the status of a specific node in the network, defined by its MAC
|
|
* address.
|
|
*
|
|
* Input: hsr ifindex, node mac address
|
|
* Output: hsr ifindex, node mac address (copied from request),
|
|
* age of latest frame from node over slave 1, slave 2 [ms]
|
|
*/
|
|
static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
|
|
{
|
|
/* For receiving */
|
|
struct nlattr *na;
|
|
struct net_device *hsr_dev;
|
|
|
|
/* For sending */
|
|
struct sk_buff *skb_out;
|
|
void *msg_head;
|
|
struct hsr_priv *hsr;
|
|
struct hsr_port *port;
|
|
unsigned char hsr_node_addr_b[ETH_ALEN];
|
|
int hsr_node_if1_age;
|
|
u16 hsr_node_if1_seq;
|
|
int hsr_node_if2_age;
|
|
u16 hsr_node_if2_seq;
|
|
int addr_b_ifindex;
|
|
int res;
|
|
|
|
if (!info)
|
|
goto invalid;
|
|
|
|
na = info->attrs[HSR_A_IFINDEX];
|
|
if (!na)
|
|
goto invalid;
|
|
na = info->attrs[HSR_A_NODE_ADDR];
|
|
if (!na)
|
|
goto invalid;
|
|
|
|
rcu_read_lock();
|
|
hsr_dev = dev_get_by_index_rcu(genl_info_net(info),
|
|
nla_get_u32(info->attrs[HSR_A_IFINDEX]));
|
|
if (!hsr_dev)
|
|
goto rcu_unlock;
|
|
if (!is_hsr_master(hsr_dev))
|
|
goto rcu_unlock;
|
|
|
|
/* Send reply */
|
|
skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
|
|
if (!skb_out) {
|
|
res = -ENOMEM;
|
|
goto fail;
|
|
}
|
|
|
|
msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
|
|
info->snd_seq, &hsr_genl_family, 0,
|
|
HSR_C_SET_NODE_STATUS);
|
|
if (!msg_head) {
|
|
res = -ENOMEM;
|
|
goto nla_put_failure;
|
|
}
|
|
|
|
res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
hsr = netdev_priv(hsr_dev);
|
|
res = hsr_get_node_data(hsr,
|
|
(unsigned char *) nla_data(info->attrs[HSR_A_NODE_ADDR]),
|
|
hsr_node_addr_b,
|
|
&addr_b_ifindex,
|
|
&hsr_node_if1_age,
|
|
&hsr_node_if1_seq,
|
|
&hsr_node_if2_age,
|
|
&hsr_node_if2_seq);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN,
|
|
nla_data(info->attrs[HSR_A_NODE_ADDR]));
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
if (addr_b_ifindex > -1) {
|
|
res = nla_put(skb_out, HSR_A_NODE_ADDR_B, ETH_ALEN,
|
|
hsr_node_addr_b);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
res = nla_put_u32(skb_out, HSR_A_ADDR_B_IFINDEX, addr_b_ifindex);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
}
|
|
|
|
res = nla_put_u32(skb_out, HSR_A_IF1_AGE, hsr_node_if1_age);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
|
|
if (port)
|
|
res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX,
|
|
port->dev->ifindex);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
res = nla_put_u32(skb_out, HSR_A_IF2_AGE, hsr_node_if2_age);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
|
|
if (port)
|
|
res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX,
|
|
port->dev->ifindex);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
|
|
rcu_read_unlock();
|
|
|
|
genlmsg_end(skb_out, msg_head);
|
|
genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
|
|
|
|
return 0;
|
|
|
|
rcu_unlock:
|
|
rcu_read_unlock();
|
|
invalid:
|
|
netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL);
|
|
return 0;
|
|
|
|
nla_put_failure:
|
|
kfree_skb(skb_out);
|
|
/* Fall through */
|
|
|
|
fail:
|
|
rcu_read_unlock();
|
|
return res;
|
|
}
|
|
|
|
/* Get a list of MacAddressA of all nodes known to this node (including self).
|
|
*/
|
|
static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
|
|
{
|
|
unsigned char addr[ETH_ALEN];
|
|
struct net_device *hsr_dev;
|
|
struct sk_buff *skb_out;
|
|
struct hsr_priv *hsr;
|
|
bool restart = false;
|
|
struct nlattr *na;
|
|
void *pos = NULL;
|
|
void *msg_head;
|
|
int res;
|
|
|
|
if (!info)
|
|
goto invalid;
|
|
|
|
na = info->attrs[HSR_A_IFINDEX];
|
|
if (!na)
|
|
goto invalid;
|
|
|
|
rcu_read_lock();
|
|
hsr_dev = dev_get_by_index_rcu(genl_info_net(info),
|
|
nla_get_u32(info->attrs[HSR_A_IFINDEX]));
|
|
if (!hsr_dev)
|
|
goto rcu_unlock;
|
|
if (!is_hsr_master(hsr_dev))
|
|
goto rcu_unlock;
|
|
|
|
restart:
|
|
/* Send reply */
|
|
skb_out = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
|
|
if (!skb_out) {
|
|
res = -ENOMEM;
|
|
goto fail;
|
|
}
|
|
|
|
msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
|
|
info->snd_seq, &hsr_genl_family, 0,
|
|
HSR_C_SET_NODE_LIST);
|
|
if (!msg_head) {
|
|
res = -ENOMEM;
|
|
goto nla_put_failure;
|
|
}
|
|
|
|
if (!restart) {
|
|
res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex);
|
|
if (res < 0)
|
|
goto nla_put_failure;
|
|
}
|
|
|
|
hsr = netdev_priv(hsr_dev);
|
|
|
|
if (!pos)
|
|
pos = hsr_get_next_node(hsr, NULL, addr);
|
|
while (pos) {
|
|
res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr);
|
|
if (res < 0) {
|
|
if (res == -EMSGSIZE) {
|
|
genlmsg_end(skb_out, msg_head);
|
|
genlmsg_unicast(genl_info_net(info), skb_out,
|
|
info->snd_portid);
|
|
restart = true;
|
|
goto restart;
|
|
}
|
|
goto nla_put_failure;
|
|
}
|
|
pos = hsr_get_next_node(hsr, pos, addr);
|
|
}
|
|
rcu_read_unlock();
|
|
|
|
genlmsg_end(skb_out, msg_head);
|
|
genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
|
|
|
|
return 0;
|
|
|
|
rcu_unlock:
|
|
rcu_read_unlock();
|
|
invalid:
|
|
netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL);
|
|
return 0;
|
|
|
|
nla_put_failure:
|
|
nlmsg_free(skb_out);
|
|
/* Fall through */
|
|
|
|
fail:
|
|
rcu_read_unlock();
|
|
return res;
|
|
}
|
|
|
|
|
|
static const struct genl_ops hsr_ops[] = {
|
|
{
|
|
.cmd = HSR_C_GET_NODE_STATUS,
|
|
.flags = 0,
|
|
.policy = hsr_genl_policy,
|
|
.doit = hsr_get_node_status,
|
|
.dumpit = NULL,
|
|
},
|
|
{
|
|
.cmd = HSR_C_GET_NODE_LIST,
|
|
.flags = 0,
|
|
.policy = hsr_genl_policy,
|
|
.doit = hsr_get_node_list,
|
|
.dumpit = NULL,
|
|
},
|
|
};
|
|
|
|
int __init hsr_netlink_init(void)
|
|
{
|
|
int rc;
|
|
|
|
rc = rtnl_link_register(&hsr_link_ops);
|
|
if (rc)
|
|
goto fail_rtnl_link_register;
|
|
|
|
rc = genl_register_family_with_ops_groups(&hsr_genl_family, hsr_ops,
|
|
hsr_mcgrps);
|
|
if (rc)
|
|
goto fail_genl_register_family;
|
|
|
|
return 0;
|
|
|
|
fail_genl_register_family:
|
|
rtnl_link_unregister(&hsr_link_ops);
|
|
fail_rtnl_link_register:
|
|
|
|
return rc;
|
|
}
|
|
|
|
void __exit hsr_netlink_exit(void)
|
|
{
|
|
genl_unregister_family(&hsr_genl_family);
|
|
rtnl_link_unregister(&hsr_link_ops);
|
|
}
|
|
|
|
MODULE_ALIAS_RTNL_LINK("hsr");
|