commit 49c1ddb8e9302a5f2ffb40a6fc4241cfd545fd15
parent 206c4de7f03146dac1a716a92d571612c79484b8
Author: Yersa Nordman <yersa@finwo.nl>
Date: Mon, 20 Mar 2023 23:16:18 +0100
Clean up some unused code comments
Diffstat:
1 file changed, 9 insertions(+), 73 deletions(-)
diff --git a/src/util/routing-table.c b/src/util/routing-table.c
@@ -19,29 +19,7 @@ static int rt_compare(const void *a, const void *b, void *udata) {
static void rt_purge(const void *item, void *udata) {
struct pmlag_rt_entry *rt_entry = (struct pmlag_rt_entry *)item;
- /* pmlag_iface_llist *iface_entry; */
-
-/* #ifdef DEBUG */
-/* printf("PURGE %.2x:%.2x:%.2x:%.2x:%.2x:%.2x -- %p\n", */
-/* rt_entry->mac[0], */
-/* rt_entry->mac[1], */
-/* rt_entry->mac[2], */
-/* rt_entry->mac[3], */
-/* rt_entry->mac[4], */
-/* rt_entry->mac[5], */
-/* item */
-/* ); */
-/* #endif */
-
- // Free all iface entries in the rt_entry
free(rt_entry->interfaces);
- /* while(rt_entry->interfaces) { */
- /* iface_entry = rt_entry->interfaces; */
- /* rt_entry->interfaces = iface_entry->next; */
- /* free(iface_entry); */
- /* } */
-
- // Free remainder
free(rt_entry->mac);
free(rt_entry);
}
@@ -60,23 +38,12 @@ int rt_upsert(
int isnew = 0;
struct pmlag_rt_entry *rt_entry;
-/* #ifdef DEBUG */
-/* printf("rt_upsert\n"); */
-/* #endif */
-
// Lock the routing table
pthread_mutex_lock(mtx);
-/* #ifdef DEBUG */
-/* printf(" acquired lock\n"); */
-/* #endif */
// Attempt to fetch the rt entry
rt_entry = mindex_get(rt, &((struct pmlag_rt_entry){ .mac = mac }));
-/* #ifdef DEBUG */
-/* printf(" Found %p -- %d\n", rt_entry, rt_entry ? rt_entry->bcidx : 0); */
-/* #endif */
-
// None given, build new one
if (!rt_entry) {
rt_entry = calloc(1, sizeof(struct pmlag_rt_entry));
@@ -92,27 +59,19 @@ int rt_upsert(
(!bcidx && rt_entry->bcidx) || // We receive a regular packet on bcidx-tracked entry
(rt_entry->bcidx && ((bcidx - rt_entry->bcidx) < 0)) // Or the received bcidx is lower than known (old packet)
) {
-/* #ifdef DEBUG */
-/* printf(" Bail, %d, %d\n\n", bcidx, rt_entry->bcidx); */
-/* #endif */
- // Caution: possible memory leak
+ if (isnew) {
+ rt_purge(rt_entry, NULL);
+ }
pthread_mutex_unlock(mtx);
return 0;
}
// Clear list of known interfaces if
- /* pmlag_iface_llist *iface_entry; */
if (
(bcidx && (rt_entry->bcidx != bcidx)) || // We got a NEW broadcast index
(!bcidx && (rt_entry->bcidx == 0)) // Or we're updating a non-pmlag remote
) {
rt_entry->iface_cnt = 0;
- /* // Free list 1-by-1 */
- /* while(rt_entry->interfaces) { */
- /* iface_entry = rt_entry->interfaces; */
- /* rt_entry->interfaces = iface_entry->next; */
- /* free(iface_entry); */
- /* } */
}
// Update the rt_entry's broadcast index
@@ -120,7 +79,9 @@ int rt_upsert(
// Bail if rt_entry->iface_cnt+1 lg bond->iface_cnt
if ((rt_entry->iface_cnt + 1) > iface->bond->iface_cnt) {
- // Caution: possible memory leak
+ if (isnew) {
+ rt_purge(rt_entry, NULL);
+ }
pthread_mutex_unlock(mtx);
return 0;
}
@@ -128,20 +89,12 @@ int rt_upsert(
// Add our iface to the entry's interface list
rt_entry->interfaces[rt_entry->iface_cnt] = iface;
rt_entry->iface_cnt++;
- /* iface_entry = malloc(sizeof(pmlag_iface_llist)); */
- /* iface_entry->next = rt_entry->interfaces; */
- /* iface_entry->data = iface; */
- /* rt_entry->interfaces = iface_entry; */
// Ensure the entry is in the rt
if (isnew) {
mindex_set(rt, rt_entry);
}
-/* #ifdef DEBUG */
-/* printf(" Iface count: %d\n", rt_entry->interfaces->l); */
-/* printf(" Routing table is now %ld entries\n", mindex_length(rt)); */
-/* #endif */
if (mindex_length(rt) > RT_MAX_ENTRIES) {
rt_entry = mindex_rand(rt);
if (rt_entry) {
@@ -158,35 +111,18 @@ struct pmlag_iface * rt_find(
pthread_mutex_t *mtx,
unsigned char *mac
) {
- // Lock the routing table
- pthread_mutex_lock(mtx);
struct pmlag_rt_entry *rt_entry;
- /* int llist_len = 0; */
// Attempt to fetch the rt entry
+ pthread_mutex_lock(mtx);
rt_entry = mindex_get(rt, &((struct pmlag_rt_entry){ .mac = mac }));
if (!rt_entry) {
pthread_mutex_unlock(mtx);
return NULL;
}
- /* // Get the list length */
- /* pmlag_iface_llist *iface_entry = rt_entry->interfaces; */
- /* while(iface_entry) { */
- /* llist_len++; */
- /* iface_entry = iface_entry->next; */
- /* } */
-
- // Select an interface at random
- int sel = rand() % rt_entry->iface_cnt;
-
- /* iface_entry = rt_entry->interfaces; */
- /* while(sel--) { */
- /* iface_entry = iface_entry->next; */
- /* } */
-
// Unlock the routing table again
+ struct pmlag_iface *iface = rt_entry->interfaces[rand() % rt_entry->iface_cnt];
pthread_mutex_unlock(mtx);
- /* return iface_entry->data; */
- return rt_entry->interfaces[sel];
+ return iface;
}