commit 752dd6a21cc0c419dfab72231e45486dacb64cbb
parent dee2f5cf9ef6f300c6fdb1affcb3e7800275339a
Author: Yersa Nordman <yersa@finwo.nl>
Date: Tue, 7 Feb 2023 22:28:13 +0100
Launching pthread per configured bond
Diffstat:
3 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/src/config.c b/src/config.c
@@ -64,6 +64,7 @@ static int config_load_handler(
iface->next = bond->interfaces;
iface->name = strdup(value);
iface->weight = 10;
+ iface->bond = bond;
bond->interfaces = iface;
}
diff --git a/src/config.h b/src/config.h
@@ -1,6 +1,8 @@
#ifndef __PMLAG_CONFIG_H__
#define __PMLAG_CONFIG_H__
+#include <pthread.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -14,12 +16,14 @@ struct pmlag_interface {
void *next;
char *name;
int weight;
+ struct pmlag_bond *bond;
};
struct pmlag_bond {
void *next;
char *name;
int mode;
+ pthread_t tid;
struct pmlag_interface *interfaces;
};
diff --git a/src/main.c b/src/main.c
@@ -5,6 +5,7 @@
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/ip.h>
+#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
@@ -22,6 +23,16 @@ static const char *const usage[] = {
NULL
};
+
+void * thread_bond(void *arg) {
+ struct pmlag_bond *bond = (struct pmlag_bond *)arg;
+ printf("Thread started for bond: %s\n", bond->name);
+ 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";
@@ -49,35 +60,23 @@ int main(int argc, const char **argv) {
return 1;
}
- printf("Loaded configuration:\n");
// For each bond of config->bonds
struct pmlag_bond *bond = config->bonds;
- struct pmlag_interface *iface;
while(bond) {
- printf("\n%s:\n", bond->name);
- printf(" mode: %s\n", (
- bond->mode == PMLAG_MODE_NONE
- ? "NONE"
- : (
- bond->mode == PMLAG_MODE_BROADCAST
- ? "BROADCAST"
- : (
- bond->mode == PMLAG_MODE_BALANCED_RR
- ? "BROADCAST"
- : "ACTIVE_BACKUP"
- )
- )
- ));
- iface = bond->interfaces;
- // For each iface of config->interfaces
- while(iface) {
- printf("\n %s:\n", iface->name);
- printf(" weight: %d\n", iface->weight);
- iface = iface->next;
+ if(pthread_create(&(bond->tid), NULL, thread_bond, bond)) {
+ perror("Starting bond thread");
+ return 1;
}
bond = bond->next;
}
+ // Wait for all bonds to finish
+ bond = config->bonds;
+ while(bond) {
+ pthread_join(bond->tid, NULL);
+ bond = bond->next;
+ }
+
/* int sockfd = sockraw_open(INTERFACE); */
/* if (sockfd < 0) { */
/* return 1; */
@@ -217,5 +216,6 @@ int main(int argc, const char **argv) {
/* printf("name: %s\n", __NAME); */
/* printf("conf: %s\n", config_file); */
/* printf("sock: %d\n", sockfd); */
- return 42;
+
+ return 0;
}