commit 7e7ee04f25c50417f85eaf47d6e0973b5c7c2663
parent 5cd99d6705b6384753add53134b9b5cc1c465285
Author: Robin Bron <robin@finwo.nl>
Date: Thu, 9 Mar 2023 22:32:40 +0100
Track the bcidx and multiple interfaces per remote again
Diffstat:
2 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/src/util/config.h b/src/util/config.h
@@ -19,7 +19,7 @@ extern "C" {
#define RCVBUFSIZ 65536
-typedef LLIST(struct pmlag_iface) pmlag_iface_llist;
+typedef LLIST(int l; struct pmlag_iface) pmlag_iface_llist;
struct pmlag_iface {
char *name; // name of the interface this object represents
diff --git a/src/util/routing-table.c b/src/util/routing-table.c
@@ -45,61 +45,56 @@ int rt_upsert(
// Attempt to fetch the rt entry
rt_entry = mindex_get(rt, &((struct pmlag_rt_entry){ .mac = mac }));
- /* /1* int16_t obcidx = 0; *1/ */
- /* if (rt_entry) { */
- /* /1* obcidx = rt_entry->bcidx; *1/ */
- /* printf(" Found, %d\n", rt_entry->bcidx); */
- /* } */
+#ifdef DEBUG
+ if (rt_entry) {
+ printf(" Found, %d\n", rt_entry->bcidx);
+ }
+#endif
// None given, build new one
if (!rt_entry) {
rt_entry = calloc(1, sizeof(struct pmlag_rt_entry));
rt_entry->mac = malloc(ETH_ALEN);
- /* rt_entry->bcidx = 0; */
+ rt_entry->bcidx = 0;
rt_entry->interfaces = NULL;
memcpy(rt_entry->mac, mac, ETH_ALEN);
isnew = 1;
}
- /* printf(" Old bcidx, %d\n", rt_entry->bcidx); */
- /* if ((!isnew) && (obcidx != rt_entry->bcidx)) { */
- /* printf(" BORKED\n"); */
- /* exit(1); */
- /* } */
-
- /* // Bail if */
- /* if ( */
- /* (!bcidx && rt_entry->bcidx) || // We receive a regular packet on bcidx-tracked entry */
- /* ((bcidx - rt_entry->bcidx) < 0) // Or the received bcidx is lower than known (old packet) */
- /* ) { */
- /* printf(" Bail, %d, %d\n\n", bcidx, rt_entry->bcidx); */
- /* pthread_mutex_unlock(mtx); */
- /* return 0; */
- /* } */
+ // Bail if
+ if (
+ (!bcidx && rt_entry->bcidx) || // We receive a regular packet on bcidx-tracked entry
+ ((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
+ 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 */
- /* ) { */
+ 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
+ ) {
// 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 */
- /* rt_entry->bcidx = bcidx; */
+ }
- /* printf(" How 'bout now, %d\n", rt_entry->bcidx); */
+ // Update the rt_entry's broadcast index
+ rt_entry->bcidx = bcidx;
// Add our iface to the entry's interface list
iface_entry = malloc(sizeof(pmlag_iface_llist));
iface_entry->next = rt_entry->interfaces;
iface_entry->data = iface;
+ iface_entry->l = rt_entry->interfaces ? ((pmlag_iface_llist *)iface_entry->next)->l + 1 : 1;
rt_entry->interfaces = iface_entry;
// Ensure the entry is in the rt
@@ -107,8 +102,9 @@ int rt_upsert(
mindex_set(rt, rt_entry);
}
- /* /1* printf(" or now, %d\n", rt_entry->bcidx); *1/ */
- /* printf(" RT is now %ld\n\n", mindex_length(rt)); */
+#ifdef DEBUG
+ printf(" Iface count: %d\n", rt_entry->interfaces->l);
+#endif
pthread_mutex_unlock(mtx);
return 0;