Skip to content
Merged
8 changes: 3 additions & 5 deletions scripts/baseboxd-knet-reset.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python3
#
# SPDX-FileCopyrightText: © 2017 BISDN GmbH
# SPDX-License-Identifier: MPL-2.0-no-copyleft-exception
#
# Helper script for resetting KNET to its initial state by removing all
# added interfaces and filters, intended to be called after stopping
# baseboxd.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. */


from ctypes import *
import fcntl
Expand Down
5 changes: 2 additions & 3 deletions src/basebox_api.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2017 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include "basebox_api.h"
#include "basebox_grpc_statistics.h"
Expand Down
5 changes: 2 additions & 3 deletions src/basebox_api.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2017 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/basebox_grpc_statistics.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2017 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <glog/logging.h>
#include <utility>
Expand Down
5 changes: 2 additions & 3 deletions src/basebox_grpc_statistics.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2017 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/baseboxd.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2013 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <gflags/gflags.h>
#include <glog/logging.h>
Expand Down
27 changes: 20 additions & 7 deletions src/netlink/cnetlink.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2014 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <cassert>
#include <cstring>
Expand Down Expand Up @@ -1652,11 +1651,25 @@ void cnetlink::link_updated(rtnl_link *old_link, rtnl_link *new_link) noexcept {
bond->update_lag(old_link, new_link);
break;
case LT_VRF: // No need to care about the vrf interface itself
case LT_BRIDGE:
VLOG(2) << __FUNCTION__
<< ": ignoring update (not supported) of old_lt=" << lt_old
<< " old link: " << old_link << ", new link: " << new_link;
break;
case LT_BRIDGE: {
uint32_t old_ageing_time, new_ageing_time;

if (rtnl_link_bridge_get_ageing_time(old_link, &old_ageing_time))
old_ageing_time = 0;
if (rtnl_link_bridge_get_ageing_time(new_link, &new_ageing_time))
new_ageing_time = 0;

if (!bridge || !bridge->is_bridge_interface(new_link)) {
VLOG(1) << __FUNCTION__ << ": ignoring update on untracked bridge "
<< new_link;
break;
}

if (old_ageing_time != new_ageing_time)
bridge->set_ageing_time(new_ageing_time);

} break;
default:
if (port_id > 0) {
if (lt_new == LT_BOND_SLAVE) {
Expand Down
5 changes: 2 additions & 3 deletions src/netlink/cnetlink.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2013 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/ctapdev.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2013 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <fcntl.h>
#include <net/if.h>
Expand Down
5 changes: 2 additions & 3 deletions src/netlink/ctapdev.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2013 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/knet_manager.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2022 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <glog/logging.h>
#include <linux/sockios.h>
Expand Down
5 changes: 2 additions & 3 deletions src/netlink/knet_manager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2022 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nbi_impl.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2016 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <glog/logging.h>

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nbi_impl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2016 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/netlink-utils.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2018 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <cassert>
#include <map>
Expand Down
5 changes: 2 additions & 3 deletions src/netlink/netlink-utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2018 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_bond.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2018 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include "nl_bond.h"

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_bond.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2018 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
68 changes: 65 additions & 3 deletions src/netlink/nl_bridge.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2015 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <cassert>
#include <cstring>
Expand All @@ -17,6 +16,7 @@
#ifdef HAVE_NETLINK_ROUTE_MDB_H
#include <netlink/route/mdb.h>
#endif
#include <netlink/route/link/bridge_info.h>
#include <netlink/route/link/vlan.h>
#include <netlink/route/link/vxlan.h>
#include <netlink/route/neighbour.h>
Expand Down Expand Up @@ -67,6 +67,8 @@ static rofl::caddress_in4 libnl_in4addr_2_rofl(struct nl_addr *addr, int *rv) {
}

void nl_bridge::set_bridge_interface(rtnl_link *bridge) {
uint32_t ageing_time;

assert(bridge);
assert((rtnl_link_get_type(bridge) != nullptr &&
std::string("bridge").compare(rtnl_link_get_type(bridge)) == 0) ||
Expand All @@ -79,6 +81,9 @@ void nl_bridge::set_bridge_interface(rtnl_link *bridge) {
if (!get_vlan_filtering())
LOG(FATAL) << __FUNCTION__
<< " unsupported: bridge configured with vlan_filtering 0";

if (rtnl_link_bridge_get_ageing_time(bridge, &ageing_time) == 0)
set_ageing_time(ageing_time);
}

bool nl_bridge::is_bridge_interface(int ifindex) {
Expand Down Expand Up @@ -815,6 +820,63 @@ void nl_bridge::update_access_ports(rtnl_link *vxlan_link, rtnl_link *br_link,
}
}
}
void nl_bridge::set_ageing_time(uint32_t ageing_time) {
assert(sw);
std::deque<rtnl_neigh *> neighs;

// ageing time is in centiseconds, so convert it to seconds, rounded
uint32_t new_ageing_time = (ageing_time + 50) / 100;

if (new_ageing_time > UINT16_MAX) {
LOG(WARNING) << __FUNCTION__ << ": ageing time " << (ageing_time * 10)
<< "ms larger than maximum supported, limiting to "
<< (UINT16_MAX * 1000) << " ms";
new_ageing_time = UINT16_MAX;
}

if (ageing_time > 0 && new_ageing_time == 0) {
LOG(WARNING) << __FUNCTION__ << ": ageing time " << (ageing_time * 10)
<< " ms less than minimum supported, raising to 1000 ms";
new_ageing_time = 1;
}

VLOG(1) << __FUNCTION__ << ": updating ageing time to " << new_ageing_time;

sw->l2_set_idle_timeout(new_ageing_time);

// get all tracked neighs
nl_cache_foreach(
l2_cache.get(),
[](struct nl_object *obj, void *arg) {
assert(arg);
auto *list = static_cast<std::deque<rtnl_neigh *> *>(arg);
auto neigh = NEIGH_CAST(obj);

// skip permanent neighs
if (!!(rtnl_neigh_get_flags(neigh) & (NUD_NOARP | NUD_PERMANENT)))
return;

nl_object_get(obj);
list->push_back(neigh);
},
&neighs);

for (auto neigh : neighs) {
int ifindex = rtnl_neigh_get_ifindex(neigh);
uint32_t port = nl->get_port_id(ifindex);
nl_addr *mac = rtnl_neigh_get_lladdr(neigh);
int vid = rtnl_neigh_get_vlan(neigh);
rofl::caddress_ll _mac((uint8_t *)nl_addr_get_binary_addr(mac),
nl_addr_get_len(mac));

VLOG(2) << __FUNCTION__ << ": updating l2 neigh " << neigh;

// update entry to update its ageing time
sw->l2_addr_add(port, vid, _mac, true, false, true);

rtnl_neigh_put(neigh);
}
}

void nl_bridge::add_neigh_to_fdb(rtnl_neigh *neigh, bool update) {
assert(sw);
Expand Down
6 changes: 3 additions & 3 deletions src/netlink/nl_bridge.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2015 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down Expand Up @@ -162,6 +161,7 @@ class nl_bridge {
void update_interface(rtnl_link *old_link, rtnl_link *new_link);
void delete_interface(rtnl_link *);

void set_ageing_time(uint32_t ageing_time);
void add_neigh_to_fdb(rtnl_neigh *, bool update = false);
void remove_neigh_from_fdb(rtnl_neigh *);

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_fdb_flush.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2024 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_hashing.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2018 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_interface.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2019 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <netlink/route/link.h>

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_interface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2019 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_l3.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2016 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include <net/if.h>
#include <memory>
Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_l3.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2016 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_l3_interfaces.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2019 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_obj.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2016 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#include "nl_obj.h"
#include <glog/logging.h>
Expand Down
5 changes: 2 additions & 3 deletions src/netlink/nl_obj.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// SPDX-FileCopyrightText: © 2016 BISDN GmbH
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception

#pragma once

Expand Down
Loading