From dd904ef4d114f55ce57ecb8f6dab7069ea1339da Mon Sep 17 00:00:00 2001
From: Jonas Gorski <jonas.gorski@bisdn.de>
Date: Thu, 25 Apr 2024 09:23:27 +0200
Subject: [PATCH] cnetlink: only check bridge for vlan_filtering on creation

We don't need to check for vlan_filtering being enabled every time we
attach a port to the bridge, only on the first attachement of a port to
the bridge.

We don't handle vlan_filtering state changes, so even if it was disabled
later, we wouldn't be able to do anything about it. So let's only check
the state once when populating cnetlink::bridge.

Fixes: f93b9b54f161 ("cnetlink: just ignore bridges with unsupported configuration")
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
---
 src/netlink/cnetlink.cc | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/netlink/cnetlink.cc b/src/netlink/cnetlink.cc
index a9d5ab0e..f5183c59 100644
--- a/src/netlink/cnetlink.cc
+++ b/src/netlink/cnetlink.cc
@@ -1292,7 +1292,6 @@ void cnetlink::link_created(rtnl_link *link) noexcept {
   case LT_BRIDGE_SLAVE: // a new bridge slave was created
     try {
       auto master = rtnl_link_get_master(link);
-      uint8_t vlan_filtering = 0;
 
       // check for new bridge slaves
       if (master == 0) {
@@ -1321,22 +1320,23 @@ void cnetlink::link_created(rtnl_link *link) noexcept {
       auto br_link = get_link_by_ifindex(master);
       LOG(INFO) << __FUNCTION__ << ": using bridge " << br_link.get();
 
-      // we only support vlan aware bridges
-      if (rtnl_link_bridge_get_vlan_filtering(br_link.get(), &vlan_filtering) <
-              0 ||
-          vlan_filtering != 1) {
-        LOG(WARNING)
-            << __FUNCTION__
-            << ": unsupported bridge: configured with vlan_filtering 0";
-        ignored_bridges.insert(master);
-        return;
-      }
-
       bool new_bridge = false;
       // slave interface
       // use only the first bridge an interface is attached to
       // XXX TODO more bridges!
       if (bridge == nullptr) {
+        uint8_t vlan_filtering = 0;
+
+        // we only support vlan aware bridges
+        if (rtnl_link_bridge_get_vlan_filtering(br_link.get(),
+                                                &vlan_filtering) < 0 ||
+            vlan_filtering != 1) {
+          LOG(WARNING)
+              << __FUNCTION__
+              << ": unsupported bridge: configured with vlan_filtering 0";
+          ignored_bridges.insert(master);
+          return;
+        }
         bridge = new nl_bridge(this->swi, port_man, this, vlan, vxlan);
         bridge->set_bridge_interface(br_link.get());
         vxlan->register_bridge(bridge);