net: tpmr: add Two-Port MAC Relay driver
Subsystems (3)
PATCH 1/1 net: tpmr: add Two-Port MAC Relay driver
Add a driver implementing the Two-Port MAC Relay as defined by IEEE 802.1Q-2014 §6.7.1. A TPMR is a minimal L2 relay between exactly two member ports: no FDB, no MAC learning, no STP, and -- by specification -- it forwards most of the 01:80:C2:00:00:0X reserved group address range that a regular bridge would consume. This makes it suitable as a bump-in-the-wire element that is transparent to the control plane on both sides (LACP, LLDP, EAPOL, and so on continue to reach the far end as if the relay were not present).
The driver is created with "ip link add type tpmr" and slaves are attached through ndo_add_slave, with a hard cap of two members. Forwarding is implemented as an rx_handler: a frame arriving on one slave is sent out the other via dev_queue_xmit(), with no FDB lookup. The IEEE-permitted subset of reserved multicasts is relayed; the remainder is delivered to the host stack via RX_HANDLER_PASS, preserving today's behaviour for protocols that genuinely target the local machine. Only 01:80:C2:00:00:01 (IEEE 802.3x PAUSE) is terminated, as required by the MAC layer.
The master's carrier follows the logical AND of both slaves' carriers, propagated via a netdev notifier. Both slaves enter IFF_PROMISC on enslave (and the refcount is balanced on detach) so the relay sees all unicast on the wire. rx_handler_register() provides exclusivity for free: a netdevice that is already a member of a bridge, bond, team, or macvlan is rejected with -EBUSY at enslave time.
MTU consistency is enforced at enslave: a second slave whose MTU differs from the first is rejected. Subsequent member MTU changes are blocked via NETDEV_PRECHANGEMTU; to change a member's MTU, detach it first.
Inspired by OpenBSD's tpmr(4) (David Gwynne, 2019), reimplemented against Linux's rx_handler / rtnl_link_ops infrastructure.
---
v1 (from RFC, addressing Andrew Lunn review):
- Inline reserved-address check; only PAUSE is passed up, gated on is_multicast_ether_addr() + unlikely().
- Fix MTU check that assumed ports[0] is always the
surviving slot after a detach-then-add sequence;
iterate ports[] to find the populated entry instead. - Reject member MTU changes via NETDEV_PRECHANGEMTU.
- Drop driver version string; let ethtool core fill it.
- Keep driver in drivers/net/ (precedent: veth, bonding, macvlan).
RFC: https://lore.kernel.org/netdev/[email protected]/
drivers/net/Kconfig | 14 ++ drivers/net/Makefile | 1 + drivers/net/tpmr.c | 412 +++++++++++++++++++++++++++++++++++ include/uapi/linux/if_link.h | 8 + 4 files changed, 435 insertions(+) create mode 100644 drivers/net/tpmr.c
drivers/net/Kconfig +14 -0
@@ -242,6 +242,20 @@ config VXLAN To compile this driver as a module, choose M here: the module will be called vxlan. +config TPMR + tristate "Two-Port MAC Relay (TPMR) driver" + help + This driver provides an IEEE 802.1Q-2014 §6.7.1 Two-Port MAC + Relay netdevice: a stripped-down L2 relay between exactly two + member ports, with no MAC learning, no FDB and no STP. Unlike + the bridge driver it forwards the IEEE-reserved + 01:80:c2:00:00:0x group (LACPDUs, LLDP, EAPOL/802.1X, ...), + which makes it suitable as a transparent bump-in-the-wire in + deployments using link aggregation, MACsec, or 802.1X. + + To compile this driver as a module, choose M here: the module + will be called tpmr. + config GENEVE tristate "Generic Network Virtualization Encapsulation" depends on INET
drivers/net/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_TUN) += tun.o obj-$(CONFIG_TAP) += tap.o obj-$(CONFIG_VETH) += veth.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o +obj-$(CONFIG_TPMR) += tpmr.o obj-$(CONFIG_VXLAN) += vxlan/ obj-$(CONFIG_GENEVE) += geneve.o obj-$(CONFIG_BAREUDP) += bareudp.o
drivers/net/tpmr.c new file +412 -0
412 lines not on this page · raw message
include/uapi/linux/if_link.h +8 -0
@@ -456,6 +456,14 @@ enum {#define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1) +/* TPMR section */ +enum { +IFLA_TPMR_UNSPEC , + __IFLA_TPMR_MAX, +}; + +#define IFLA_TPMR_MAX (__IFLA_TPMR_MAX - 1) +enum in6_addr_gen_mode {IN6_ADDR_GEN_MODE_EUI64 ,IN6_ADDR_GEN_MODE_NONE ,
Signature · 1 line
2.53.0
Nikolay Aleksandrov
maintainerQuoted 42 lines · David Carlier
Add a driver implementing the Two-Port MAC Relay as defined by IEEE 802.1Q-2014 §6.7.1. A TPMR is a minimal L2 relay between exactly two member ports: no FDB, no MAC learning, no STP, and -- by specification -- it forwards most of the 01:80:C2:00:00:0X reserved group address range that a regular bridge would consume. This makes it suitable as a bump-in-the-wire element that is transparent to the control plane on both sides (LACP, LLDP, EAPOL, and so on continue to reach the far end as if the relay were not present).
The driver is created with "ip link add type tpmr" and slaves are attached through
ndo_add_slave, with a hard cap of two members. Forwarding is implemented as anrx_handler: a frame arriving on one slave is sent out the other viadev_queue_xmit(), with no FDB lookup. The IEEE-permitted subset of reserved multicasts is relayed; the remainder is delivered to the host stack viaRX_HANDLER_PASS, preserving today's behaviour for protocols that genuinely target the local machine. Only 01:80:C2:00:00:01 (IEEE 802.3x PAUSE) is terminated, as required by the MAC layer.The master's carrier follows the logical AND of both slaves' carriers, propagated via a netdev notifier. Both slaves enter
IFF_PROMISCon enslave (and the refcount is balanced on detach) so the relay sees all unicast on the wire.rx_handler_register()provides exclusivity for free: a netdevice that is already a member of a bridge, bond, team, or macvlan is rejected with-EBUSYat enslave time.MTU consistency is enforced at enslave: a second slave whose MTU differs from the first is rejected. Subsequent member MTU changes are blocked via
NETDEV_PRECHANGEMTU; to change a member's MTU, detach it first.Inspired by OpenBSD's tpmr(4) (David Gwynne, 2019), reimplemented against Linux's
rx_handler/rtnl_link_opsinfrastructure.Signed-off-by David Carlier <[email protected]>---
v1 (from RFC, addressing Andrew Lunn review):
- Inline reserved-address check; only PAUSE is passed up, gated onis_multicast_ether_addr()+unlikely().
- Fix MTU check that assumed ports[0] is always the
Quoted 8 lines
surviving slot after a detach-then-add sequence; iterate ports[] to find the populated entry instead.- Reject member MTU changes via
NETDEV_PRECHANGEMTU.
- Drop driver version string; let ethtool core fill it.
- Keep driver indrivers/net/(precedent: veth, bonding, macvlan).
RFC: https://lore.kernel.org/netdev/[email protected]/
Hi David,
Please give people more time to review the proposed RFCs before sending v1. Also you specifically asked bridge maintainers to comment and did not wait for us to do so.
Now to the point - I don't think this device is needed at all, this task can be accomplished in multiple ways with what we currently have, there is no need to add another software device for something so simple.
First, I'd like to ask: could you please elaborate why bridge's group_fwd_mask isn't working out for you? How exactly are you trying to use it? It was added for this purpose, to forward link-local frames and should be able to do the same as what you're describing. If there is a problem I'd rather we fix it or extend the bridge if something's missing instead of adding so much new code that we'll have to maintain forever.
Second, what else did you try and how exactly did you try it?
Examples of a few ways to solve this:
- tc: why dismiss mirred so fast, it can do the same combined with some matching? Did you check mirred redirect?
cls_bpf/ebpf - definitely can do it as well
- nftables: should be able to solve it, too
- XDP: I wouldn't dismiss it because network managers cannot control it, all modern network managers support custom scripts in some form where you can load your custom XDP program and solve the problem
Cheers,
Nik
Hi !
Quoted 3 lines
Please give people more time to review the proposed RFCs before sending v1. Also you specifically asked bridge maintainers to comment and did not wait for us to do so.
Fair point. I jumped to v1 too quickly. I CC'd the bridge list and you specifically, then turned around v1 inside a day on the strength of one review. I should have waited; sorry for the noise.
Quoted 2 lines
First, I'd like to ask: could you please elaborate why bridge's
group_fwd_maskisn't working out for you?
Honest answer: I should have tested that configuration before posting, and I didn't. Let me actually run a 2-port bridge with group_fwd_mask set, no_learning, stp_state 0, vlan_filtering 0, and see where it falls short of a TPMR — if it falls short at all. The places I'd expect to differ are PAUSE handling, multicast outside the 01:80:c2:00:00:0x range, and carrier semantics, but I haven't proven any of that with real traffic.
If the bridge configuration covers everything materially, dropping this driver is the right call — 400 LOC duplicating existing functionality isn't worth it. If there's a concrete gap, I'd rather close it inside the bridge than maintain a parallel driver.
Quoted 1 line
Second, what else did you try and how exactly did you try it?
Same admission. tc mirred, cls_bpf, nftables, XDP_REDIRECT are all on the table and I haven't evaluated any of them seriously against the use case. Let me come back with measurements instead of arguing in the abstract.
Please consider v1 parked until then. Thanks for the pushback.
David