bridge: add cfm command
Subsystems (3)
cover bridge: add cfm command
The bridge has had 802.1ag CFM support since 5.11, but iproute2 never got a command for it. The only userspace for it today is Microchip's out of tree cfm tool. This series adds "bridge cfm".
Patch 1 imports cfm_bridge.h, which has the domain, direction and interval enums the CFM attributes use. Patch 2 adds the command and a man page section.
I tested it on a 7.0 kernel with two bridges joined by a veth pair and a MEP on each end. CCMs go out at every interval, each side sees the other as a peer, the TLV values and the RDI bit get through, and ccm_defect gets set when one side stops sending. I also checked show config and show status, text and JSON, with more than one MEP and peer on a bridge.
While testing I found that the kernel sends CCMs from a workqueue, so with HZ=1000 the 3.3ms interval actually comes out at about 5ms and 1s at about 1024ms. The man page says the real interval can be longer than its name.
One thing I wasn't sure about: the MAID is given as a hex string, the same bytes the kernel stores. The Microchip tool builds it from an MD name and an MA name. I can add that, but it seemed better as a separate patch.
Separately, I'm sending a net-next patch so that CFM config changes send a notification. Right now only status changes do. The two don't depend on each other.
Abdul Wasey (2):
uapi: import cfm_bridge.h
bridge: add cfm command
bridge/Makefile | 2 +- bridge/br_common.h | 1 + bridge/bridge.c | 3 +- bridge/cfm.c | 1058 +++++++++++++++++++++++++++++++ include/uapi/linux/cfm_bridge.h | 64 ++ man/man8/bridge.8 | 196 +++++- 6 files changed, 1321 insertions(+), 3 deletions(-) create mode 100644 bridge/cfm.c create mode 100644 include/uapi/linux/cfm_bridge.h
Signature · 1 line
2.53.0
PATCH 1/2 uapi: import cfm_bridge.h
The bridge CFM netlink attributes use the MEP domain, MEP direction and CCM interval enums from cfm_bridge.h, but the header was never imported. The bridge cfm command in the next patch needs it. Copied as is from net-next.
--- include/uapi/linux/cfm_bridge.h | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/uapi/linux/cfm_bridge.h
include/uapi/linux/cfm_bridge.h new file +64 -0
@@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ + +#ifndef _UAPI_LINUX_CFM_BRIDGE_H_ +#define _UAPI_LINUX_CFM_BRIDGE_H_ + +#include <linux/types.h> +#include <linux/if_ether.h> + +#define ETHER_HEADER_LENGTH (6+6+4+2) +#define CFM_MAID_LENGTH 48 +#define CFM_CCM_PDU_LENGTH 75 +#define CFM_PORT_STATUS_TLV_LENGTH 4 +#define CFM_IF_STATUS_TLV_LENGTH 4 +#define CFM_IF_STATUS_TLV_TYPE 4 +#define CFM_PORT_STATUS_TLV_TYPE 2 +#define CFM_ENDE_TLV_TYPE 0 +#define CFM_CCM_MAX_FRAME_LENGTH (ETHER_HEADER_LENGTH+\ + CFM_CCM_PDU_LENGTH+\ + CFM_PORT_STATUS_TLV_LENGTH+\ + CFM_IF_STATUS_TLV_LENGTH) +#define CFM_FRAME_PRIO 7 +#define CFM_CCM_TLV_OFFSET 70 +#define CFM_CCM_PDU_MAID_OFFSET 10 +#define CFM_CCM_PDU_MEPID_OFFSET 8 +#define CFM_CCM_PDU_SEQNR_OFFSET 4 +#define CFM_CCM_PDU_TLV_OFFSET 74 +#define CFM_CCM_ITU_RESERVED_SIZE 16 + +struct br_cfm_common_hdr { +__u8 mdlevel_version; +__u8 opcode; +__u8 flags; +__u8 tlv_offset; +}; + +enum br_cfm_opcodes { +BR_CFM_OPCODE_CCM =0x1 , +}; + +/* MEP domain */ +enum br_cfm_domain { +BR_CFM_PORT , +BR_CFM_VLAN , +}; + +/* MEP direction */ +enum br_cfm_mep_direction { +BR_CFM_MEP_DIRECTION_DOWN , +BR_CFM_MEP_DIRECTION_UP , +}; + +/* CCM interval supported. */ +enum br_cfm_ccm_interval { +BR_CFM_CCM_INTERVAL_NONE , +BR_CFM_CCM_INTERVAL_3_3_MS , +BR_CFM_CCM_INTERVAL_10_MS , +BR_CFM_CCM_INTERVAL_100_MS , +BR_CFM_CCM_INTERVAL_1_SEC , +BR_CFM_CCM_INTERVAL_10_SEC , +BR_CFM_CCM_INTERVAL_1_MIN , +BR_CFM_CCM_INTERVAL_10_MIN , +}; + +#endif
Signature · 1 line
2.53.0
PATCH 2/2 bridge: add cfm command
In reply to Abdul WaseyThe bridge has had 802.1ag CFM support since 5.11 (net/bridge/br_cfm.c), but iproute2 never got a command for it, so the only way to use it is Microchip's out of tree cfm tool.
Add "bridge cfm", which covers what the kernel supports:
bridge cfm mep { add | del | set }
bridge cfm cc config
bridge cfm cc peer { add | del }
bridge cfm cc rdi
bridge cfm cc ccm-tx
bridge cfm show { config | status }
Each command maps to one IFLA_BRIDGE_CFM_* group and is sent to the bridge device with BRIDGE_FLAGS_SELF. The MAID is taken as a hex string, the same bytes the kernel stores. There is no way yet to build it from an MD and MA name.
Example with a MEP on each end of a veth pair, one bridge each side:
$ bridge cfm mep add bridge brA instance 1 port vA
$ bridge cfm mep set bridge brA instance 1 \
address 02:00:00:00:00:0a level 3 mepid 10
$ bridge cfm cc config bridge brA instance 1 \
enable on interval 100ms maid 0104746573740002
$ bridge cfm cc peer add bridge brA instance 1 mepid 20
$ bridge cfm cc ccm-tx bridge brA instance 1 \
dmac 01:80:c2:00:00:33 period 30
(same on brB with mepid 20 and peer 10)
$ bridge cfm show status bridge brA
brA
mep 1 opcode_unexp_seen false version_unexp_seen false ...
peer mepid 20 ccm_defect false rdi false ... seen true ...--- bridge/Makefile | 2 +- bridge/br_common.h | 1 + bridge/bridge.c | 3 +- bridge/cfm.c | 1058 ++++++++++++++++++++++++++++++++++++++++++++ man/man8/bridge.8 | 196 +++++++- 5 files changed, 1257 insertions(+), 3 deletions(-) create mode 100644 bridge/cfm.c
bridge/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -BROBJ = bridge.o fdb.o monitor.o link.o mdb.o mst.o vlan.o vni.o +BROBJ = bridge.o fdb.o monitor.o link.o mdb.o mst.o vlan.o vni.o cfm.o include ../config.mk
bridge/br_common.h +1 -0
@@ -24,6 +24,7 @@ int do_mst(int argc, char **argv);int do_vlan (int argc,char **argv);int do_link (int argc,char **argv);int do_vni (int argc,char **argv); +int do_cfm (int argc,char **argv);extern int preferred_family;extern int show_stats;
bridge/bridge.c +2 -1
@@ -36,7 +36,7 @@ static void usage(void)fprintf (stderr,"Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n" " bridge [ -force ] -batch filename\n" -"where OBJECT := { link | fdb | mdb | mst | vlan | vni | monitor }\n" +"where OBJECT := { link | fdb | mdb | mst | vlan | vni | cfm | monitor }\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n" " -o[neline] | -t[imestamp] | -n[etns] name |\n" " -com[pressvlans] -c[olor] -p[retty] -j[son] }\n" );
@@ -59,6 +59,7 @@ static const struct cmd { { "mst", do_mst }, { "vlan", do_vlan }, { "vni", do_vni }, + { "cfm", do_cfm }, { "monitor", do_monitor }, { "help", do_help }, { 0 }
bridge/cfm.c new file +1058 -0
1,058 lines not on this page · raw message
man/man8/bridge.8 +195 -1
208 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 34 lines · On Sun, 4 Oct 2026 04:13:07 +0000 Abdul Wasey <[email protected]> wrote:
bridge/cfm.c new file +34
-0+static int cfm_parse_interval (const char *str) +{ +if (!strcmp (str,"none" )) +return BR_CFM_CCM_INTERVAL_NONE ; +if (!strcmp (str,"3ms3" ) || !strcmp (str,"3.3ms" )) +return BR_CFM_CCM_INTERVAL_3_3_MS ; +if (!strcmp (str,"10ms" )) +return BR_CFM_CCM_INTERVAL_10_MS ; +if (!strcmp (str,"100ms" )) +return BR_CFM_CCM_INTERVAL_100_MS ; +if (!strcmp (str,"1s" )) +return BR_CFM_CCM_INTERVAL_1_SEC ; +if (!strcmp (str,"10s" )) +return BR_CFM_CCM_INTERVAL_10_SEC ; +if (!strcmp (str,"1m" )) +return BR_CFM_CCM_INTERVAL_1_MIN ; +if (!strcmp (str,"10m" )) +return BR_CFM_CCM_INTERVAL_10_MIN ; +return -1 ; +} + +static const char *cfm_interval_str (__u32 interval) +{ +switch (interval) { +case BR_CFM_CCM_INTERVAL_NONE : +return "none" ; +case BR_CFM_CCM_INTERVAL_3_3_MS : +return "3ms3" ; +case BR_CFM_CCM_INTERVAL_10_MS : +return "10ms" ; +case BR_CFM_CCM_INTERVAL_100_MS : +return "100ms" ; +case BR_CFM_CCM_INTERVAL_1_SEC : +return "1s" ;
bridge/cfm.c line 94
Quoted 10 lines
bridge/cfm.c new file +10
-0+case BR_CFM_CCM_INTERVAL_10_SEC : +return "10s" ; +case BR_CFM_CCM_INTERVAL_1_MIN : +return "1m" ; +case BR_CFM_CCM_INTERVAL_10_MIN : +return "10m" ; +default : +return "unknown" ; + } +}
Iproute2 already has helpers get_time and print_time.
Ido Schimmel
maintainerQuoted 3 lines · Abdul Wasey
The bridge has had 802.1ag CFM support since 5.11, but iproute2 never got a command for it. The only userspace for it today is Microchip's out of tree cfm tool. This series adds "bridge cfm".
[...]
Quoted 1 line
6 files changed, 1321 insertions(+), 3 deletions(-)
Please elaborate on the motivation: What is your interest in CFM? Are you using it in production? Does anyone? Who needs this in iproute2? What is missing from Microchip's cfm tool?
Looking at the kernel log, since CFM was merged six years ago, no new features were added and the only bug fixes are for issues found by static checkers and LLMs with no reviews from the original authors. There are also no selftests.
If nobody cares about CFM or uses it, then I would prefer to start deprecating it instead of accumulating more code that needs to be maintained and that nobody is going to use.
Quoted 4 lines · Ido Schimmel
Please elaborate on the motivation: What is your interest in CFM? Are you using it in production? Does anyone? Who needs this in iproute2? What is missing from Microchip's cfm tool?
Quoted 8 lines
Looking at the kernel log, since CFM was merged six years ago, no new features were added and the only bug fixes are for issues found by static checkers and LLMs with no reviews from the original authors. There are also no selftests.
If nobody cares about CFM or uses it, then I would prefer to start deprecating it instead of accumulating more code that needs to be maintained and that nobody is going to use.
Hi Ido,
Thanks for asking directly. Short answer: I don't run CFM in production and I don't know anyone who does.
How I got here: I work on BFD (FRR's bfdd and an XDP BFD data plane) and was looking at how other liveness protocols are handled on Linux. CFM in the bridge had no iproute2 support, so I wrote it. I didn't check first whether anyone needed it, and I should have.
Testing it, I found the bridge CFM does not keep its own timing at the short intervals: with a 3.3 ms CCM interval it sends every ~5 ms and declares loss after about 8 intervals instead of 3.5, because the timers are delayed works in jiffies. The ccm-tx period also overflows a u32 above 4294 s, and interval "none" with CC enabled rearms the work with no delay. I think that fits what you describe: anyone running the short intervals would have hit the first one.
Microchip's cfm tool covers configuration and show; what it does not have is being packaged anywhere and a monitor for events. That alone is not a strong reason to carry 1300 lines in iproute2.
So I'm fine with dropping this series. Horatiu, do you know of anyone using bridge CFM? If nobody does, I'm also fine with deprecating it, and I can help with that if you want.
The same goes for my net-next series "net: bridge: cfm: notify userspace on CFM config changes", which only makes sense if CFM stays; I'll leave it until this is settled.
Thanks,
Abdul Wasey