Commit 92a129da authored by David S. Miller's avatar David S. Miller

Merge branch 'hsr-next'

Arvid Brodin says:

====================
net/hsr: Use list_head+rcu, better frame dispatch, etc.

This patch series is meant to improve the HSR code in several ways:

* Better code readability.
* In general, make the code structure more like the net/bridge code (HSR
  operates similarly to a bridge, but uses the HSR-specific frame headers to
  break up rings, instead of the STP protocol).
* Better handling of HSR ports' net_device features.
* Use list_head and the _rcu list traversing routines instead of array of slave
  devices.
* Make it easy to support HSR Interlink devices (for future Redbox/Quadbox
  support).
* Somewhat better throughput on non-HAVE_EFFICIENT_UNALIGNED_ACCESS archs, due
  to lesser copying of skb data.

The code has been tested in a ring together with other HSR nodes running
unchanged code, on both avr32 and x86_64. There should only be one minor change
in behaviour from a user perspective:

* Anyone using the Netlink HSR_C_GET_NODE_LIST message to dump the internal
  node database will notice that the database now also contains the self node.

All patches pass 'checkpatch.pl --ignore CAMELCASE --max-line-length=83
--strict' with only CHECKs, each of which have been deliberately left in place.

The final code passes sparse checks with no output.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b8125404 a718dcc5
......@@ -4,4 +4,5 @@
obj-$(CONFIG_HSR) += hsr.o
hsr-y := hsr_main.o hsr_framereg.o hsr_device.o hsr_netlink.o
hsr-y := hsr_main.o hsr_framereg.o hsr_device.o \
hsr_netlink.o hsr_slave.o hsr_forward.o
This diff is collapsed.
/* Copyright 2011-2013 Autronica Fire and Security AS
/* 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
......@@ -6,7 +6,7 @@
* any later version.
*
* Author(s):
* 2011-2013 Arvid Brodin, arvid.brodin@xdin.com
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*/
#ifndef __HSR_DEVICE_H
......@@ -18,12 +18,8 @@
void hsr_dev_setup(struct net_device *dev);
int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
unsigned char multicast_spec);
void hsr_set_operstate(struct net_device *hsr_dev, struct net_device *slave1,
struct net_device *slave2);
void hsr_set_carrier(struct net_device *hsr_dev, struct net_device *slave1,
struct net_device *slave2);
void hsr_check_announce(struct net_device *hsr_dev, int old_operstate);
void hsr_check_carrier_and_operstate(struct hsr_priv *hsr);
bool is_hsr_master(struct net_device *dev);
int hsr_get_max_mtu(struct hsr_priv *hsr_priv);
int hsr_get_max_mtu(struct hsr_priv *hsr);
#endif /* __HSR_DEVICE_H */
This diff is collapsed.
/* 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
*/
#ifndef __HSR_FORWARD_H
#define __HSR_FORWARD_H
#include <linux/netdevice.h>
#include "hsr_main.h"
void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);
#endif /* __HSR_FORWARD_H */
This diff is collapsed.
/* Copyright 2011-2013 Autronica Fire and Security AS
/* 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
......@@ -6,42 +6,43 @@
* any later version.
*
* Author(s):
* 2011-2013 Arvid Brodin, arvid.brodin@xdin.com
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*/
#ifndef _HSR_FRAMEREG_H
#define _HSR_FRAMEREG_H
#ifndef __HSR_FRAMEREG_H
#define __HSR_FRAMEREG_H
#include "hsr_main.h"
struct node_entry;
struct hsr_node;
struct node_entry *hsr_find_node(struct list_head *node_db, struct sk_buff *skb);
struct hsr_node *hsr_add_node(struct list_head *node_db, unsigned char addr[],
u16 seq_out);
struct hsr_node *hsr_get_node(struct list_head *node_db, struct sk_buff *skb,
bool is_sup);
void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
struct hsr_port *port);
bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr);
struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv,
struct node_entry *node,
struct sk_buff *skb,
enum hsr_dev_idx dev_idx);
void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb);
void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,
struct hsr_port *port);
void hsr_addr_subst_source(struct hsr_priv *hsr_priv, struct sk_buff *skb);
void hsr_addr_subst_dest(struct hsr_priv *hsr_priv, struct ethhdr *ethhdr,
enum hsr_dev_idx dev_idx);
void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,
u16 sequence_nr);
int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node,
u16 sequence_nr);
void hsr_register_frame_in(struct node_entry *node, enum hsr_dev_idx dev_idx);
int hsr_register_frame_out(struct node_entry *node, enum hsr_dev_idx dev_idx,
struct sk_buff *skb);
void hsr_prune_nodes(struct hsr_priv *hsr_priv);
void hsr_prune_nodes(unsigned long data);
int hsr_create_self_node(struct list_head *self_node_db,
unsigned char addr_a[ETH_ALEN],
unsigned char addr_b[ETH_ALEN]);
void *hsr_get_next_node(struct hsr_priv *hsr_priv, void *_pos,
void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
unsigned char addr[ETH_ALEN]);
int hsr_get_node_data(struct hsr_priv *hsr_priv,
int hsr_get_node_data(struct hsr_priv *hsr,
const unsigned char *addr,
unsigned char addr_b[ETH_ALEN],
unsigned int *addr_b_ifindex,
......@@ -50,4 +51,4 @@ int hsr_get_node_data(struct hsr_priv *hsr_priv,
int *if2_age,
u16 *if2_seq);
#endif /* _HSR_FRAMEREG_H */
#endif /* __HSR_FRAMEREG_H */
This diff is collapsed.
/* Copyright 2011-2013 Autronica Fire and Security AS
/* 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
......@@ -6,11 +6,11 @@
* any later version.
*
* Author(s):
* 2011-2013 Arvid Brodin, arvid.brodin@xdin.com
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*/
#ifndef _HSR_PRIVATE_H
#define _HSR_PRIVATE_H
#ifndef __HSR_PRIVATE_H
#define __HSR_PRIVATE_H
#include <linux/netdevice.h>
#include <linux/list.h>
......@@ -29,6 +29,7 @@
* each node differ before we notify of communication problem?
*/
#define MAX_SLAVE_DIFF 3000 /* ms */
#define HSR_SEQNR_START (USHRT_MAX - 1024)
/* How often shall we check for broken ring and remove node entries older than
......@@ -46,16 +47,16 @@
* path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest,
* h_source, h_proto = 0x88FB }, and add { path, LSDU_size, sequence Nr,
* encapsulated protocol } instead.
*
* Field names as defined in the IEC:2010 standard for HSR.
*/
#define HSR_TAGLEN 6
/* Field names below as defined in the IEC:2010 standard for HSR. */
struct hsr_tag {
__be16 path_and_LSDU_size;
__be16 sequence_nr;
__be16 encap_proto;
} __packed;
#define HSR_HLEN 6
/* The helper functions below assumes that 'path' occupies the 4 most
* significant bits of the 16-bit field shared by 'path' and 'LSDU_size' (or
......@@ -136,31 +137,47 @@ struct hsr_ethhdr_sp {
} __packed;
enum hsr_dev_idx {
HSR_DEV_NONE = -1,
HSR_DEV_SLAVE_A = 0,
HSR_DEV_SLAVE_B,
HSR_DEV_MASTER,
enum hsr_port_type {
HSR_PT_NONE = 0, /* Must be 0, used by framereg */
HSR_PT_SLAVE_A,
HSR_PT_SLAVE_B,
HSR_PT_INTERLINK,
HSR_PT_MASTER,
HSR_PT_PORTS, /* This must be the last item in the enum */
};
struct hsr_port {
struct list_head port_list;
struct net_device *dev;
struct hsr_priv *hsr;
enum hsr_port_type type;
};
#define HSR_MAX_SLAVE (HSR_DEV_SLAVE_B + 1)
#define HSR_MAX_DEV (HSR_DEV_MASTER + 1)
struct hsr_priv {
struct list_head hsr_list; /* List of hsr devices */
struct rcu_head rcu_head;
struct net_device *dev;
struct net_device *slave[HSR_MAX_SLAVE];
struct list_head node_db; /* Other HSR nodes */
struct list_head ports;
struct list_head node_db; /* Known HSR nodes */
struct list_head self_node_db; /* MACs of slaves */
struct timer_list announce_timer; /* Supervision frame dispatch */
struct timer_list prune_timer;
int announce_count;
u16 sequence_nr;
spinlock_t seqnr_lock; /* locking for sequence_nr */
unsigned char sup_multicast_addr[ETH_ALEN];
};
void register_hsr_master(struct hsr_priv *hsr_priv);
void unregister_hsr_master(struct hsr_priv *hsr_priv);
bool is_hsr_slave(struct net_device *dev);
#define hsr_for_each_port(hsr, port) \
list_for_each_entry_rcu((port), &(hsr)->ports, port_list)
struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt);
/* Caller must ensure skb is a valid HSR frame */
static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb)
{
struct hsr_ethhdr *hsr_ethhdr;
hsr_ethhdr = (struct hsr_ethhdr *) skb_mac_header(skb);
return ntohs(hsr_ethhdr->hsr_tag.sequence_nr);
}
#endif /* _HSR_PRIVATE_H */
#endif /* __HSR_PRIVATE_H */
/* Copyright 2011-2013 Autronica Fire and Security AS
/* 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
......@@ -6,7 +6,7 @@
* any later version.
*
* Author(s):
* 2011-2013 Arvid Brodin, arvid.brodin@xdin.com
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* Routines for handling Netlink messages for HSR.
*/
......@@ -37,13 +37,17 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
struct net_device *link[2];
unsigned char multicast_spec;
if (!data) {
netdev_info(dev, "HSR: No slave devices specified\n");
return -EINVAL;
}
if (!data[IFLA_HSR_SLAVE1]) {
netdev_info(dev, "IFLA_HSR_SLAVE1 missing!\n");
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, "IFLA_HSR_SLAVE2 missing!\n");
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]));
......@@ -63,21 +67,33 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
{
struct hsr_priv *hsr_priv;
struct hsr_priv *hsr;
struct hsr_port *port;
int res;
hsr_priv = netdev_priv(dev);
hsr = netdev_priv(dev);
if (hsr_priv->slave[0])
if (nla_put_u32(skb, IFLA_HSR_SLAVE1, hsr_priv->slave[0]->ifindex))
goto nla_put_failure;
res = 0;
if (hsr_priv->slave[1])
if (nla_put_u32(skb, IFLA_HSR_SLAVE2, hsr_priv->slave[1]->ifindex))
goto nla_put_failure;
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_priv->sup_multicast_addr) ||
nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr_priv->sequence_nr))
hsr->sup_multicast_addr) ||
nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr))
goto nla_put_failure;
return 0;
......@@ -128,13 +144,13 @@ static const struct genl_multicast_group hsr_mcgrps[] = {
* 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_priv, unsigned char addr[ETH_ALEN],
enum hsr_dev_idx dev_idx)
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;
int ifindex;
skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
if (!skb)
......@@ -148,11 +164,7 @@ void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN],
if (res < 0)
goto nla_put_failure;
if (hsr_priv->slave[dev_idx])
ifindex = hsr_priv->slave[dev_idx]->ifindex;
else
ifindex = -1;
res = nla_put_u32(skb, HSR_A_IFINDEX, ifindex);
res = nla_put_u32(skb, HSR_A_IFINDEX, port->dev->ifindex);
if (res < 0)
goto nla_put_failure;
......@@ -165,16 +177,20 @@ void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN],
kfree_skb(skb);
fail:
netdev_warn(hsr_priv->dev, "Could not send HSR ring error message\n");
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_priv, unsigned char addr[ETH_ALEN])
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);
......@@ -199,7 +215,10 @@ void hsr_nl_nodedown(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN])
kfree_skb(skb);
fail:
netdev_warn(hsr_priv->dev, "Could not send HSR node down\n");
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();
}
......@@ -220,7 +239,8 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
/* For sending */
struct sk_buff *skb_out;
void *msg_head;
struct hsr_priv *hsr_priv;
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;
......@@ -267,8 +287,8 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
if (res < 0)
goto nla_put_failure;
hsr_priv = netdev_priv(hsr_dev);
res = hsr_get_node_data(hsr_priv,
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,
......@@ -301,9 +321,12 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq);
if (res < 0)
goto nla_put_failure;
if (hsr_priv->slave[0])
rcu_read_lock();
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
if (port)
res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX,
hsr_priv->slave[0]->ifindex);
port->dev->ifindex);
rcu_read_unlock();
if (res < 0)
goto nla_put_failure;
......@@ -313,9 +336,14 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq);
if (res < 0)
goto nla_put_failure;
if (hsr_priv->slave[1])
rcu_read_lock();
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
if (port)
res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX,
hsr_priv->slave[1]->ifindex);
port->dev->ifindex);
rcu_read_unlock();
if (res < 0)
goto nla_put_failure;
genlmsg_end(skb_out, msg_head);
genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
......@@ -334,7 +362,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
return res;
}
/* Get a list of MacAddressA of all nodes known to this node (other than self).
/* 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)
{
......@@ -345,7 +373,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
/* For sending */
struct sk_buff *skb_out;
void *msg_head;
struct hsr_priv *hsr_priv;
struct hsr_priv *hsr;
void *pos;
unsigned char addr[ETH_ALEN];
int res;
......@@ -385,17 +413,17 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
if (res < 0)
goto nla_put_failure;
hsr_priv = netdev_priv(hsr_dev);
hsr = netdev_priv(hsr_dev);
rcu_read_lock();
pos = hsr_get_next_node(hsr_priv, NULL, addr);
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) {
rcu_read_unlock();
goto nla_put_failure;
}
pos = hsr_get_next_node(hsr_priv, pos, addr);
pos = hsr_get_next_node(hsr, pos, addr);
}
rcu_read_unlock();
......
/* Copyright 2011-2013 Autronica Fire and Security AS
/* 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
......@@ -6,7 +6,7 @@
* any later version.
*
* Author(s):
* 2011-2013 Arvid Brodin, arvid.brodin@xdin.com
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*/
#ifndef __HSR_NETLINK_H
......@@ -17,13 +17,14 @@
#include <uapi/linux/hsr_netlink.h>
struct hsr_priv;
struct hsr_port;
int __init hsr_netlink_init(void);
void __exit hsr_netlink_exit(void);
void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN],
int dev_idx);
void hsr_nl_nodedown(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN]);
void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN],
struct hsr_port *port);
void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN]);
void hsr_nl_framedrop(int dropcount, int dev_idx);
void hsr_nl_linkdown(int dev_idx);
......
/* 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;
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 (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) {
/* Directly kill frames sent by ourselves */
kfree_skb(skb);
goto finish_consume;
}
if (eth_hdr(skb)->h_proto != htons(ETH_P_PRP))
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;
if (type != HSR_PT_MASTER) {
res = hsr_portdev_setup(dev, port);
if (res)
goto fail_dev_setup;
}
port->hsr = hsr;
port->dev = dev;
port->type = type;
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) {
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();
dev_put(port->dev);
}
/* 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
*/
#ifndef __HSR_SLAVE_H
#define __HSR_SLAVE_H
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/rtnetlink.h>
#include "hsr_main.h"
int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
enum hsr_port_type pt);
void hsr_del_port(struct hsr_port *port);
bool hsr_port_exists(const struct net_device *dev);
static inline struct hsr_port *hsr_port_get_rtnl(const struct net_device *dev)
{
ASSERT_RTNL();
return hsr_port_exists(dev) ?
rtnl_dereference(dev->rx_handler_data) : NULL;
}
static inline struct hsr_port *hsr_port_get_rcu(const struct net_device *dev)
{
return hsr_port_exists(dev) ?
rcu_dereference(dev->rx_handler_data) : NULL;
}
#endif /* __HSR_SLAVE_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment