pmlag

Poor man's link aggregation
git clone git://git.finwo.net/app/pmlag
Log | Files | Refs | README | LICENSE

commit 561808954072dde134799b285f34137edec093c3
parent 752dd6a21cc0c419dfab72231e45486dacb64cbb
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Wed,  8 Feb 2023 00:18:06 +0100

Added TODOs and thread creation for physical interfaces

Diffstat:
Msrc/config.c | 4++--
Msrc/config.h | 5+++--
Msrc/main.c | 40++++++++++++++++++++++++++++++++++++++--
3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/config.c b/src/config.c @@ -31,7 +31,7 @@ static int config_load_handler( } // Get interface being configured - struct pmlag_interface *iface = bond->interfaces; + struct pmlag_iface *iface = bond->interfaces; if (0) { // Intentionally empty @@ -60,7 +60,7 @@ static int config_load_handler( // Create iface if not found if (!iface) { - iface = calloc(1, sizeof(struct pmlag_interface)); + iface = calloc(1, sizeof(struct pmlag_iface)); iface->next = bond->interfaces; iface->name = strdup(value); iface->weight = 10; diff --git a/src/config.h b/src/config.h @@ -12,10 +12,11 @@ extern "C" { #define PMLAG_MODE_BROADCAST 2 #define PMLAG_MODE_BALANCED_RR 3 -struct pmlag_interface { +struct pmlag_iface { void *next; char *name; int weight; + pthread_t tid; struct pmlag_bond *bond; }; @@ -24,7 +25,7 @@ struct pmlag_bond { char *name; int mode; pthread_t tid; - struct pmlag_interface *interfaces; + struct pmlag_iface *interfaces; }; struct pmlag_configuration { diff --git a/src/main.c b/src/main.c @@ -11,6 +11,7 @@ #include <sys/ioctl.h> #include <sys/socket.h> #include <stdio.h> +#include <unistd.h> #include "cofyc/argparse.h" #include "config.h" @@ -23,16 +24,51 @@ static const char *const usage[] = { NULL }; +void * thread_iface(void *arg) { + struct pmlag_iface *iface = (struct pmlag_iface *)arg; + printf("Thread started for iface: %s->%s\n", iface->bond->name, iface->name); + + // TODO: open raw socket on iface + // TODO: blocking listen on iface, send to bond + // TODO: track announces in routing table + + sleep(3); + pthread_exit(NULL); + return NULL; +} void * thread_bond(void *arg) { struct pmlag_bond *bond = (struct pmlag_bond *)arg; printf("Thread started for bond: %s\n", bond->name); + + // For each bond of config->bonds + struct pmlag_iface *iface = bond->interfaces; + while(iface) { + if(pthread_create(&(iface->tid), NULL, thread_iface, iface)) { + perror("Starting iface thread"); + pthread_exit((void*)1); + return (void*)1; + } + iface = iface->next; + } + + // TODO: create bonded interface here + // TODO: blocked listen on bond, send through routing table to other ifaces + // TODO: send broadcasts to all interfaces + // TODO: timer to broadcast announce our presence to ifaces (keepalive-ish) + // hint: include sequence id, so tracking can react quickly (seq dist > 1) + + // Wait for iface threads to finish + iface = bond->interfaces; + while(iface) { + pthread_join(iface->tid, NULL); + iface = iface->next; + } + pthread_exit(NULL); return NULL; } - /* thread->tid = pthread_create(&(thread->tid), NULL, iface_thread, thread); */ - int main(int argc, const char **argv) { char *config_file="/etc/pmlag/pmlag.ini";