net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)
Subsystems (3)
PATCH v3 1/1 net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)
High-availability Seamless Redundancy ("HSR") provides instant failover redundancy for Ethernet networks. It requires a special network topology where all nodes are connected in a ring (each node having two physical network interfaces). It is suited for applications that demand high availability and very short reaction time.
HSR acts on the Ethernet layer, using a registered Ethernet protocol type to send special HSR frames in both directions over the ring. The driver creates virtual network interfaces that can be used just like any ordinary Linux network interface, for IP/TCP/UDP traffic etc. All nodes in the network ring must be HSR capable.
This code is a "best effort" to comply with the HSR standard as described in IEC 62439-3:2010 (HSRv0).
---
This is a patch against net-next (2013-08-21).
The code has been statically analysed using sparse (no problems detected).
kmemleak has been used to detect memory leaks (no known leaks exist).
The code passes checkpatch.pl with the options --strict --max-line-length=83 except for CHECKs, which are all intentional; e.g. CamelCase is used in the IEC standard to describe field names, and these names have been used in the code.
The code has been tested extensively on rings of up to 32 avr32-based nodes. Less intense testing has included an x86_64 (SMP) system, and running HSR over a USB-to-Ethernet device.
Changes in v3:
* hsr_dev_open() no longer calls dev_open() on the HSR slave interfaces. This is to let user space decide how to treat any errors on slave open.
* is_operstate_up() is now called is_slave_up() and checks both admin state and operational state. Slaves going DOWN could otherwise be detected as still UP when HSR decided its own state.
* Files under net/ now have header comments that follow the network code standard.
Changes in v2:
* Aligned newlines with open parenthesis (Joe Perches)
* Removed unneccessary WARN_ON_ONCE from is_hsr_master() (Joe Perches)
* Removed deprecated comments about "actually signed" for HSR_A_IFn_AGE (Joe Perches)
* Broke out userspace hsr_netlink.h into include/uapi/linux/ (Joe Perches)
* Use netif_oper_up() to check for operational state UP (Stephen Hemminger)
Possibly unresolved:
* dev_base_lock vs rtnl_mutex when setting operstate? (Stephen Hemminger)
* Move more (local) header files into include/net/? (checkpatch still warns about CamelCase) (Joe Perches / with help from David Miller?)
Earlier RFC:s:
RFC v1: http://www.spinics.net/lists/netdev/msg192817.html
RFC v2: http://www.spinics.net/lists/netdev/msg203397.html
RFC v3: http://www.spinics.net/lists/netdev/msg207816.html
RFC v4: http://www.spinics.net/lists/netdev/msg213309.html
Thanks to Stephen Hemminger, Joe Perches, and others for their comments on these RFC:s.
include/uapi/linux/hsr_netlink.h | 50 ++++ include/uapi/linux/if_ether.h | 1 + include/uapi/linux/if_link.h | 13 + net/Kconfig | 1 + net/Makefile | 1 + net/hsr/Kconfig | 27 ++ net/hsr/Makefile | 7 + net/hsr/hsr_device.c | 592 +++++++++++++++++++++++++++++++++++++++ net/hsr/hsr_device.h | 29 ++ net/hsr/hsr_framereg.c | 501 +++++++++++++++++++++++++++++++++ net/hsr/hsr_framereg.h | 53 ++++ net/hsr/hsr_main.c | 458 ++++++++++++++++++++++++++++++ net/hsr/hsr_main.h | 166 +++++++++++ net/hsr/hsr_netlink.c | 457 ++++++++++++++++++++++++++++++ net/hsr/hsr_netlink.h | 30 ++ 15 files changed, 2386 insertions(+) create mode 100644 include/uapi/linux/hsr_netlink.h create mode 100644 net/hsr/Kconfig create mode 100644 net/hsr/Makefile create mode 100644 net/hsr/hsr_device.c create mode 100644 net/hsr/hsr_device.h create mode 100644 net/hsr/hsr_framereg.c create mode 100644 net/hsr/hsr_framereg.h create mode 100644 net/hsr/hsr_main.c create mode 100644 net/hsr/hsr_main.h create mode 100644 net/hsr/hsr_netlink.c create mode 100644 net/hsr/hsr_netlink.h
include/uapi/linux/hsr_netlink.h new file +50 -0
@@ -0,0 +1,50 @@ +/* +* Copyright 2011-2013 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-2013 Arvid Brodin, [email protected] +*/ + +#ifndef __UAPI_HSR_NETLINK_H +#define __UAPI_HSR_NETLINK_H + +/* Generic Netlink HSR family definition +*/ + +/* attributes */ +enum { +HSR_A_UNSPEC , +HSR_A_NODE_ADDR , +HSR_A_IFINDEX , +HSR_A_IF1_AGE , +HSR_A_IF2_AGE , +HSR_A_NODE_ADDR_B , +HSR_A_IF1_SEQ , +HSR_A_IF2_SEQ , +HSR_A_IF1_IFINDEX , +HSR_A_IF2_IFINDEX , +HSR_A_ADDR_B_IFINDEX , + __HSR_A_MAX, +}; +#define HSR_A_MAX (__HSR_A_MAX - 1) + + +/* commands */ +enum { +HSR_C_UNSPEC , +HSR_C_RING_ERROR , +HSR_C_NODE_DOWN , +HSR_C_GET_NODE_STATUS , +HSR_C_SET_NODE_STATUS , +HSR_C_GET_NODE_LIST , +HSR_C_SET_NODE_LIST , + __HSR_C_MAX, +}; +#define HSR_C_MAX (__HSR_C_MAX - 1) + +#endif /* __UAPI_HSR_NETLINK_H */
include/uapi/linux/if_ether.h +1 -0
@@ -85,6 +85,7 @@#define ETH_P_8021AH 0x88E7/* 802.1ah Backbone Service Tag */ #define ETH_P_MVRP 0x88F5/* 802.1Q MVRP */ #define ETH_P_1588 0x88F7/* IEEE 1588 Timesync */ +#define ETH_P_PRP 0x88FB/* IEC 62439-3 PRP/HSRv0 */ #define ETH_P_FCOE 0x8906/* Fibre Channel over Ethernet */ #define ETH_P_TDLS 0x890D/* TDLS */ #define ETH_P_FIP 0x8914/* FCoE Initialization Protocol */
include/uapi/linux/if_link.h +13 -0
@@ -468,4 +468,17 @@ enum {#define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1) + +/* HSR section */ + +enum { +IFLA_HSR_UNSPEC , +IFLA_HSR_SLAVE1 , +IFLA_HSR_SLAVE2 , +IFLA_HSR_MULTICAST_SPEC , + __IFLA_HSR_MAX, +}; + +#define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1) +#endif /* _UAPI_LINUX_IF_LINK_H */
net/Kconfig +1 -0
@@ -220,6 +220,7 @@ source "net/openvswitch/Kconfig" source "net/vmw_vsock/Kconfig" source "net/netlink/Kconfig" source "net/mpls/Kconfig" +source "net/hsr/Kconfig" config RPS boolean
net/Makefile +1 -0
@@ -71,3 +71,4 @@ obj-$(CONFIG_NFC) += nfc/ obj-$(CONFIG_OPENVSWITCH) += openvswitch/ obj-$(CONFIG_VSOCKETS) += vmw_vsock/ obj-$(CONFIG_NET_MPLS_GSO) += mpls/ +obj-$(CONFIG_HSR) += hsr/
net/hsr/Kconfig new file +27 -0
@@ -0,0 +1,27 @@ +# +# IEC 62439-3 High-availability Seamless Redundancy +# + +config HSR + tristate "High-availability Seamless Redundancy (HSR)" + ---help--- + If you say Y here, then your Linux box will be able to act as a + DANH ("Doubly attached node implementing HSR"). For this to work, + your Linux box needs (at least) two physical Ethernet interfaces, + and it must be connected as a node in a ring network together with + other HSR capable nodes. + + All Ethernet frames sent over the hsr device will be sent in both + directions on the ring (over both slave ports), giving a redundant, + instant fail-over network. Each HSR node in the ring acts like a + bridge for HSR frames, but filters frames that have been forwarded + earlier. + + This code is a "best effort" to comply with the HSR standard as + described in IEC 62439-3:2010 (HSRv0), but no compliancy tests have + been made. + + You need to perform any and all necessary tests yourself before + relying on this code in a safety critical system! + + If unsure, say N.
net/hsr/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for HSR +# + +obj-$(CONFIG_HSR) += hsr.o + +hsr-y := hsr_main.o hsr_framereg.o hsr_device.o hsr_netlink.o
net/hsr/hsr_device.c new file +592 -0
592 lines not on this page · raw message
net/hsr/hsr_device.h new file +29 -0
@@ -0,0 +1,29 @@ +/* Copyright 2011-2013 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-2013 Arvid Brodin, [email protected] +*/ + +#ifndef __HSR_DEVICE_H +#define __HSR_DEVICE_H + +#include <linux/netdevice.h> +#include "hsr_main.h" + +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); +bool is_hsr_master (struct net_device *dev); +int hsr_get_max_mtu (struct hsr_priv *hsr_priv); + +#endif /* __HSR_DEVICE_H */
net/hsr/hsr_framereg.c new file +501 -0
501 lines not on this page · raw message
net/hsr/hsr_framereg.h new file +53 -0
53 lines not on this page · raw message
net/hsr/hsr_main.c new file +458 -0
458 lines not on this page · raw message
net/hsr/hsr_main.h new file +166 -0
166 lines not on this page · raw message
net/hsr/hsr_netlink.c new file +457 -0
457 lines not on this page · raw message
net/hsr/hsr_netlink.h new file +30 -0
@@ -0,0 +1,30 @@ +/* Copyright 2011-2013 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-2013 Arvid Brodin, [email protected] +*/ + +#ifndef __HSR_NETLINK_H +#define __HSR_NETLINK_H + +#include <linux/if_ether.h> +#include <linux/module.h> +#include <uapi/linux/hsr_netlink.h> + +struct hsr_priv ; + +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_framedrop (int dropcount,int dev_idx); +void hsr_nl_linkdown (int dev_idx); + +#endif /* __HSR_NETLINK_H */
Signature · 6 lines
1.8.1.5 -- Arvid Brodin | Consultant (Linux) XDIN AB | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden | xdin.com
Quoted 5 lines · Arvid Brodin
High-availability Seamless Redundancy ("HSR") provides instant failover redundancy for Ethernet networks. It requires a special network topology where all nodes are connected in a ring (each node having two physical network interfaces). It is suited for applications that demand high availability and very short reaction time.
Hi Arvid.
just trivia:
net/hsr/hsr_device.c
Quoted 1 line
net/hsr/hsr_device.c +0
-0
[]
Quoted 1 line
+static int
hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
[]
net/hsr/hsr_device.c line 243
Quoted 2 lines
net/hsr/hsr_device.c +2
-0+if (likely (res1 ==NET_XMIT_SUCCESS || res1 ==NET_XMIT_CN || + res2 ==NET_XMIT_SUCCESS || res2 ==NET_XMIT_CN )) {
This might be faster using | instead of ||
[]
net/hsr/hsr_framereg.c
Quoted 1 line
net/hsr/hsr_framereg.c +0
-0
[]
Quoted 4 lines
net/hsr/hsr_framereg.c +4
-0+ +/* above(a, b) - return 1 if a > b, 0 otherwise. +*/ +static bool above (u16 a,u16 b)
net/hsr/hsr_framereg.c line 297
Quoted 10 lines
net/hsr/hsr_framereg.c +10
-0+{ +/* Remove inconsistency where above(a, b) == below(a, b) */ +if ((int ) b - a ==32768 ) +return 0 ; + +return (((s16) (b - a)) <0 ); +} +#define below (a, b) above((b), (a)) +#define above_or_eq (a, b) (!below((a), (b))) +#define below_or_eq (a, b) (!above((a), (b)))
These may be overly generic macro names given
these only take u16.
Hello.
Quoted 10 lines · Joe Perches
Quoted 5 lines
High-availability Seamless Redundancy ("HSR") provides instant failover redundancy for Ethernet networks. It requires a special network topology where all nodes are connected in a ring (each node having two physical network interfaces). It is suited for applications that demand high availability and very short reaction time.
Hi Arvid.
just trivia:
Quoted 8 lines
net/hsr/hsr_device.c
Quoted 1 line
net/hsr/hsr_device.c +0
-0[]
Quoted 1 line
+static int
hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)[]
net/hsr/hsr_device.c line 243
Quoted 2 lines
net/hsr/hsr_device.c +2
-0+if (likely (res1 ==NET_XMIT_SUCCESS || res1 ==NET_XMIT_CN || + res2 ==NET_XMIT_SUCCESS || res2 ==NET_XMIT_CN )) {This might be faster using | instead of ||
Doesn't || use shortcut evaluation in C? I.e. if the 1st == evaluates to
true, other comparisons are not even done.
WBR, Sergei
Quoted 6 lines · Sergei Shtylyov
Quoted 5 lines · Joe Perches
Quoted 5 lines
High-availability Seamless Redundancy ("HSR") provides instant failover redundancy for Ethernet networks. It requires a special network topology where all nodes are connected in a ring (each node having two physical network interfaces). It is suited for applications that demand high availability and very short reaction time.
Hi back.
Quoted 7 lines
Quoted 4 lines
net/hsr/hsr_device.c line 243
Quoted 2 lines
net/hsr/hsr_device.c new file +2
-0+if (likely (res1 ==NET_XMIT_SUCCESS || res1 ==NET_XMIT_CN || + res2 ==NET_XMIT_SUCCESS || res2 ==NET_XMIT_CN )) {This might be faster using | instead of ||
Doesn't || use shortcut evaluation in C? I.e. if the 1st == evaluates totrue, other comparisons are not even done.
Yes it does.
But if the 1st 3 comparisons are false and the last comparison is true then those 3 tests and jumps are also done which takes additional branch predictions paths. Oring is fast.
David Miller
maintainerFrom: Arvid Brodin <[email protected]>
Date: Wed, 21 Aug 2013 20:20:17 +0200
Quoted 1 line
This is a patch against net-next (2013-08-21).
First of all, your email client corrupted the patch, chopping up long lines and making whitespace changes to the content of the patch. Please fix this before resubmitting, and do so by first sending a test patch to yourself and making sure you can apply the patch you receive in that email. Do not use attachments to deal with this issue.
net/hsr/hsr_device.c line 43
Quoted 6 lines
net/hsr/hsr_device.c new file +6
-0+if (dev->operstate != transition) { +write_lock_bh (&dev_base_lock); + dev->operstate = transition; +write_unlock_bh (&dev_base_lock); +netdev_state_change (dev); + }
This is racy. And it appears that set_operstate() in net/core/rtnetlink.c has the same bug, I guess that's what you used as a guide.
Any "test and set" sequence must be guarded completely by the lock, it doesn't make any sense to only guard the change of the value.
Quoted 10 lines · David Miller
From: Arvid Brodin <[email protected]>
Date: Wed, 21 Aug 2013 20:20:17 +0200Quoted 1 line
This is a patch against net-next (2013-08-21).
First of all, your email client corrupted the patch, chopping up long lines and making whitespace changes to the content of the patch. Please fix this before resubmitting, and do so by first sending a test patch to yourself and making sure you can apply the patch you receive in that email. Do not use attachments to deal with this issue.
Sorry about that - I forgot to disable Format=Flowed... :(
Quoted 10 lines
net/hsr/hsr_device.c line 43
Quoted 6 lines
net/hsr/hsr_device.c new file +6
-0+if (dev->operstate != transition) { +write_lock_bh (&dev_base_lock); + dev->operstate = transition; +write_unlock_bh (&dev_base_lock); +netdev_state_change (dev); + }This is racy. And it appears that
set_operstate()innet/core/rtnetlink.chas the same bug, I guess that's what you used as a guide.
Quoted 2 lines
Any "test and set" sequence must be guarded completely by the lock, it doesn't make any sense to only guard the change of the value.
I never did understand the purpose of the locking done in set_operstate(). Will fix.
Also, Stephen Hemminger told me to use rtnl_mutex instead, but when I pointed to net/core/rtnetlink.c and asked if he was sure, I did not get a reply. This function - __hsr_set_operstate() - is only called from a notifier_call function, so rtnl_mutex is already held here. Do I even need additional locking?
(According to ULNI* pp 171 Stephen is right and net/core/rtnetlink.c is wrong...)
* ULNI = Understanding Linux Network Internals
Signature · 2 lines
Arvid Brodin | Consultant (Linux) XDIN AB | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden | xdin.com