Skip to content

Commit

Permalink
Merge pull request #289 from rubensfig/whitespace_fix
Browse files Browse the repository at this point in the history
Whitespace fix
  • Loading branch information
KanjiMonster committed Dec 16, 2020
2 parents 0641ca7 + 6ccd29f commit ef4443e
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 134 deletions.
91 changes: 46 additions & 45 deletions src/netlink/cnetlink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,12 @@ struct rtnl_link *cnetlink::get_link(int ifindex, int family) const {
rtnl_link_set_family(filter.get(), family);

// search link by filter
nl_cache_foreach_filter(caches[NL_LINK_CACHE], OBJ_CAST(filter.get()),
[](struct nl_object *obj, void *arg) {
*static_cast<nl_object **>(arg) = obj;
},
&_link);
nl_cache_foreach_filter(
caches[NL_LINK_CACHE], OBJ_CAST(filter.get()),
[](struct nl_object *obj, void *arg) {
*static_cast<nl_object **>(arg) = obj;
},
&_link);

if (_link == nullptr) {
// check the garbage
Expand All @@ -280,9 +281,8 @@ struct rtnl_link *cnetlink::get_link(int ifindex, int family) const {
return _link;
}

void cnetlink::get_bridge_ports(int br_ifindex,
std::deque<rtnl_link *> *link_list) const
noexcept {
void cnetlink::get_bridge_ports(
int br_ifindex, std::deque<rtnl_link *> *link_list) const noexcept {
assert(link_list);

if (!bridge)
Expand All @@ -295,17 +295,16 @@ void cnetlink::get_bridge_ports(int br_ifindex,
rtnl_link_set_family(filter.get(), AF_BRIDGE);
rtnl_link_set_master(filter.get(), br_ifindex);

nl_cache_foreach_filter(caches[NL_LINK_CACHE], OBJ_CAST(filter.get()),
[](struct nl_object *obj, void *arg) {
assert(arg);
auto *list =
static_cast<std::deque<rtnl_link *> *>(arg);
nl_cache_foreach_filter(
caches[NL_LINK_CACHE], OBJ_CAST(filter.get()),
[](struct nl_object *obj, void *arg) {
assert(arg);
auto *list = static_cast<std::deque<rtnl_link *> *>(arg);

VLOG(3) << __FUNCTION__ << ": found bridge port "
<< obj;
list->push_back(LINK_CAST(obj));
},
link_list);
VLOG(3) << __FUNCTION__ << ": found bridge port " << obj;
list->push_back(LINK_CAST(obj));
},
link_list);

// check the garbage
for (auto &obj : nl_objs) {
Expand Down Expand Up @@ -348,8 +347,8 @@ int cnetlink::add_l3_addr(struct rtnl_addr *a) {

int cnetlink::del_l3_addr(struct rtnl_addr *a) { return l3->del_l3_addr(a); }

void cnetlink::get_vlans(int ifindex, std::deque<uint16_t> *vlan_list) const
noexcept {
void cnetlink::get_vlans(int ifindex,
std::deque<uint16_t> *vlan_list) const noexcept {
assert(vlan_list);

std::unique_ptr<rtnl_link, decltype(&rtnl_link_put)> filter(rtnl_link_alloc(),
Expand All @@ -360,19 +359,18 @@ void cnetlink::get_vlans(int ifindex, std::deque<uint16_t> *vlan_list) const
rtnl_link_set_type(filter.get(), "vlan");
rtnl_link_set_link(filter.get(), ifindex);

nl_cache_foreach_filter(caches[NL_LINK_CACHE], OBJ_CAST(filter.get()),
[](struct nl_object *obj, void *arg) {
assert(arg);
auto *list =
static_cast<std::deque<uint16_t> *>(arg);
uint16_t vid;

VLOG(3) << __FUNCTION__ << ": found vlan interface "
<< obj;
vid = rtnl_link_vlan_get_id(LINK_CAST(obj));
list->push_back(vid);
},
vlan_list);
nl_cache_foreach_filter(
caches[NL_LINK_CACHE], OBJ_CAST(filter.get()),
[](struct nl_object *obj, void *arg) {
assert(arg);
auto *list = static_cast<std::deque<uint16_t> *>(arg);
uint16_t vid;

VLOG(3) << __FUNCTION__ << ": found vlan interface " << obj;
vid = rtnl_link_vlan_get_id(LINK_CAST(obj));
list->push_back(vid);
},
vlan_list);
}

struct rtnl_neigh *cnetlink::get_neighbour(int ifindex,
Expand Down Expand Up @@ -447,14 +445,14 @@ int cnetlink::get_port_id(int ifindex) const {

int port_id = tap_man->get_port_id(ifindex);
if (port_id > 0)
return port_id;
return port_id;

return bond->get_lag_id(ifindex);
}

int cnetlink::get_ifindex_by_port_id(uint32_t port_id) const {

return tap_man->get_ifindex(port_id);
return tap_man->get_ifindex(port_id);
}

uint16_t cnetlink::get_vrf_table_id(rtnl_link *link) {
Expand Down Expand Up @@ -1103,36 +1101,39 @@ void cnetlink::link_updated(rtnl_link *old_link, rtnl_link *new_link) noexcept {
<< OBJ_CAST(
get_link_by_ifindex(rtnl_link_get_master(new_link)).get());
// Lookup l3 addresses to delete
// We can delete the addresses on the interface because we will later receive a
// notification readding the addresses, that time with the correct VRF
// We can delete the addresses on the interface because we will later
// receive a notification readding the addresses, that time with the correct
// VRF
std::deque<rtnl_addr *> addresses;
get_l3_addrs(old_link, &addresses);
for (auto i : addresses)
l3->del_l3_addr(i);

vlan->vrf_attach(old_link, new_link);
} break;
} break;
case LT_VRF_SLAVE: {
if (lt_new == LT_VLAN) {
LOG(INFO) << __FUNCTION__ << ": freed vrf slave interface "
<< OBJ_CAST(old_link);

// Lookup l3 addresses to delete
// We can delete the addresses on the interface because we will later receive a
// notification readding the addresses, that time with the correct VRF
// We can delete the addresses on the interface because we will later
// receive a notification readding the addresses, that time with the
// correct VRF
std::deque<rtnl_addr *> addresses;
get_l3_addrs(old_link, &addresses);
// delete l3 addresses no longer associated with vrf
for (auto i: addresses)
l3->del_l3_addr(i);
// delete l3 addresses no longer associated with vrf
for (auto i : addresses)
l3->del_l3_addr(i);
vlan->vrf_detach(old_link, new_link);
} else if (lt_new == LT_VRF_SLAVE) {
LOG(INFO) << __FUNCTION__ << ": link updated " << OBJ_CAST(new_link);
vlan->vrf_attach(old_link, new_link);
}
// TODO handle LT_TAP/LT_BOND, currently unimplemented
// happens when a bond/tap interface enslaved directly to a VRF and you set nomaster
} break;
// happens when a bond/tap interface enslaved directly to a VRF and you set
// nomaster
} break;
case LT_TUN:
if (lt_new == LT_BOND_SLAVE) {
// XXX link enslaved
Expand Down
2 changes: 1 addition & 1 deletion src/netlink/nbi_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void nbi_impl::port_notification(
switch (get_port_type(ntfy.port_id)) {
case nbi::port_type_physical:
tap_man->change_port_status(ntfy.name, ntfy.status);
tap_man->set_port_speed(ntfy.name, ntfy.speed, ntfy.duplex);
tap_man->set_port_speed(ntfy.name, ntfy.speed, ntfy.duplex);
break;
default:
LOG(ERROR) << __FUNCTION__ << ": unknown port";
Expand Down
12 changes: 6 additions & 6 deletions src/netlink/nl_bond.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ std::set<uint32_t> nl_bond::get_members(rtnl_link *bond) {
std::set<uint32_t> nl_bond::get_members_by_port_id(uint32_t port_id) {
auto mem_it = lag_members.find(port_id);
if (mem_it == lag_members.end()) {
LOG(WARNING) << __FUNCTION__ << ": lag does not exist for port_id="
<< port_id;
LOG(WARNING) << __FUNCTION__
<< ": lag does not exist for port_id=" << port_id;
return {};
}

Expand Down Expand Up @@ -339,11 +339,11 @@ int nl_bond::remove_lag_member(rtnl_link *bond, rtnl_link *link) {

nl->get_vlans(rtnl_link_get_ifindex(bond), &vlans);

if (lm_rv->second.empty())
remove_l3_address(bond);
if (lm_rv->second.empty())
remove_l3_address(bond);

if (nl->is_bridge_interface(bond))
swi->ofdpa_stg_state_port_set(port_id, "forward");
if (nl->is_bridge_interface(bond))
swi->ofdpa_stg_state_port_set(port_id, "forward");

for (auto vid : vlans) {
swi->ingress_port_vlan_remove(port_id, vid, false);
Expand Down
39 changes: 20 additions & 19 deletions src/netlink/nl_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void nl_bridge::update_vlans(rtnl_link *old_link, rtnl_link *new_link) {
uint32_t b = new_br_vlan->vlan_bitmap[k];
uint32_t vlan_diff = a ^ b;

#if 0 // untagged change not yet implemented
#if 0 // untagged change not yet implemented
uint32_t c = old_br_vlan->untagged_bitmap[k];
uint32_t d = new_br_vlan->untagged_bitmap[k];
uint32_t untagged_diff = c ^ d;
Expand All @@ -391,8 +391,8 @@ void nl_bridge::update_vlans(rtnl_link *old_link, rtnl_link *new_link) {
if (new_br_vlan->untagged_bitmap[k] & 1 << (j - 1)) {
egress_untagged = true;

#if 0 // untagged change not yet implemented
// clear untagged_diff bit
#if 0 // untagged change not yet implemented
// clear untagged_diff bit
untagged_diff &= ~((uint32_t)1 << (j - 1));
#endif // 0
}
Expand Down Expand Up @@ -434,7 +434,7 @@ void nl_bridge::update_vlans(rtnl_link *old_link, rtnl_link *new_link) {
VLOG(3) << __FUNCTION__ << ": add vid=" << vid
<< " on pport_no=" << pport_no
<< " link: " << OBJ_CAST(_link);
vlan->add_bridge_vlan(_link, vid, new_br_vlan->pvid == vid,
vlan->add_bridge_vlan(_link, vid, new_br_vlan->pvid == vid,
!egress_untagged);
}
}
Expand Down Expand Up @@ -465,12 +465,13 @@ void nl_bridge::update_vlans(rtnl_link *old_link, rtnl_link *new_link) {
rtnl_neigh_set_flags(filter.get(), NTF_MASTER | NTF_EXT_LEARNED);
rtnl_neigh_set_state(filter.get(), NUD_REACHABLE);

nl_cache_foreach_filter(l2_cache.get(), OBJ_CAST(filter.get()),
[](struct nl_object *o, void *arg) {
VLOG(3) << "l2_cache remove object " << o;
nl_cache_remove(o);
},
nullptr);
nl_cache_foreach_filter(
l2_cache.get(), OBJ_CAST(filter.get()),
[](struct nl_object *o, void *arg) {
VLOG(3) << "l2_cache remove object " << o;
nl_cache_remove(o);
},
nullptr);

vlan->remove_bridge_vlan(_link, vid, new_br_vlan->pvid == vid,
!egress_untagged);
Expand Down Expand Up @@ -531,14 +532,14 @@ std::deque<rtnl_neigh *> nl_bridge::get_fdb_entries_of_port(rtnl_link *br_port,

VLOG(3) << __FUNCTION__ << ": searching for " << OBJ_CAST(filter.get());
std::deque<rtnl_neigh *> neighs;
nl_cache_foreach_filter(nl->get_cache(cnetlink::NL_NEIGH_CACHE),
OBJ_CAST(filter.get()),
[](struct nl_object *o, void *arg) {
auto *neighs = (std::deque<rtnl_neigh *> *)arg;
neighs->push_back(NEIGH_CAST(o));
VLOG(3) << "needs to be updated " << o;
},
&neighs);
nl_cache_foreach_filter(
nl->get_cache(cnetlink::NL_NEIGH_CACHE), OBJ_CAST(filter.get()),
[](struct nl_object *o, void *arg) {
auto *neighs = (std::deque<rtnl_neigh *> *)arg;
neighs->push_back(NEIGH_CAST(o));
VLOG(3) << "needs to be updated " << o;
},
&neighs);

return neighs;
}
Expand Down Expand Up @@ -645,7 +646,7 @@ void nl_bridge::update_access_ports(rtnl_link *vxlan_link, rtnl_link *br_link,
vxlan->delete_access_port(_br_port, pport_no, vid, true);

vlan->add_bridge_vlan(_br_port, vid, br_port_vlans->pvid == vid,
!untagged);
!untagged);

auto neighs = get_fdb_entries_of_port(_br_port, vid);
for (auto n : neighs) {
Expand Down
4 changes: 2 additions & 2 deletions src/netlink/nl_l3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,8 @@ int nl_l3::get_l3_interface_id(int ifindex, const struct nl_addr *s_mac,
*l3_interface_id = i->second.l3_interface_id;

VLOG(2) << __FUNCTION__ << ": l3_interface_id " << *l3_interface_id
<< " found for port " << port_id << ", src_mac " << src_mac
<< ", dst_mac " << dst_mac << ", vid " << vid;
<< " found for port " << port_id << ", src_mac " << src_mac
<< ", dst_mac " << dst_mac << ", vid " << vid;
return 0;
}
}
Expand Down
Loading

0 comments on commit ef4443e

Please sign in to comment.