net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)
Subsystems (3)
PATCH v6 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-10-29).
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. (v6 also has a WARNING about a trailing "*/" which will be fixed in v7, if it comes to that.)
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 v6:
* Use HSR_MAX_SLAVE as loop limit in all if statements where appropriate (instead of literal '2').
* Use ether_addr_equal() instead of compare_ether_addr().
* Consistently use false/true for bool types (instead of 0/1).
* Better names and comments for seq_nr_after() and family (former above() and family).
Changes in v5:
* Tried to address the issues with aligning the skb header that was brought up by David Miller in v4. Fixed comment where true/false was called 1/0.
Changes in v4:
* Fixed racy test-and-modify lock for device operstate in __hsr_set_operstate().
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) David Miller asked about this on 2013-09-03; no response.
* 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 | 596 +++++++++++++++++++++++++++++++++++++++ net/hsr/hsr_device.h | 29 ++ net/hsr/hsr_framereg.c | 503 +++++++++++++++++++++++++++++++++ net/hsr/hsr_framereg.h | 53 ++++ net/hsr/hsr_main.c | 469 ++++++++++++++++++++++++++++++ net/hsr/hsr_main.h | 166 +++++++++++ net/hsr/hsr_netlink.c | 457 ++++++++++++++++++++++++++++++ net/hsr/hsr_netlink.h | 30 ++ 15 files changed, 2403 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
@@ -481,4 +481,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 +596 -0
596 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 +503 -0
503 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 +469 -0
469 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 · 1 line
1.8.1.5
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.
Thanks Arvid. Maybe add a MAINTAINERS entry too?
Quoted 8 lines · Joe Perches
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.
Thanks Arvid. Maybe add a
MAINTAINERSentry too?
Something like this?
S: Maintained
F: drivers/net/usb/hso.c
+HSR NETWORK PROTOCOL
+M: Arvid Brodin <[email protected]> +L: [email protected] +S: Maintained +F: net/hsr/*
+
HTCPEN TOUCHSCREEN DRIVER
M: Pau Oliva Fora <[email protected]>
L: [email protected]
This would indicate that people should CC me when they send patches or find bugs, and that I should review the patch within a couple of weeks and get back to the sender and the list with my comments, right? Just making sure I understand what would be expected of me.
And where should the MAINTAINERS patch go - to netdev or to lkml?
Signature · 2 lines
Arvid Brodin | Consultant (Linux) XDIN AB | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden | xdin.com
Quoted 11 lines · Arvid Brodin
Quoted 8 lines · Joe Perches
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.
Thanks Arvid. Maybe add a
MAINTAINERSentry too?Something like this?
Yes, with a nit below:
Review
Quoted 8 lines
S: Maintained
F:drivers/net/usb/hso.c(quoted diff) +5
-0+HSR NETWORK PROTOCOL +M: Arvid Brodin <[email protected]> +L: [email protected] +S: Maintained +F: net/hsr/*
Using
F: net/hsr/
will allow any subdirectories to also be under
the same "Maintained" block.
Quoted 6 lines
This would indicate that people should CC me when they send patches or find bugs, and that I should review the patch within a couple of weeks and get back to the sender and the list with my comments, right? Just making sure I understand what would be expected of me.
And where should the
MAINTAINERSpatch go - to netdev or to lkml?
I think netdev with lkml cc'd.
From: Arvid Brodin <[email protected]>
Date: Wed, 30 Oct 2013 21:10:47 +0100
Quoted 12 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.
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.
Quoted 4 lines
This code is a "best effort" to comply with the HSR standard as described in IEC 62439-3:2010 (HSRv0).
Signed-off-by Arvid Brodin <[email protected]>
Applied, thanks.