pmlag

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

commit dc4da3a03f15f550dc4a12d0dcc81fe71923d18f
parent 83fdd063d4b75eff3e2af2a5094057f850eae435
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Tue, 31 Jan 2023 23:01:07 +0100

Project restart

Diffstat:
M.editorconfig | 3---
M.gitignore | 6++----
D.gitmodules | 6------
DMakefile | 47-----------------------------------------------
DREADME.md | 112-------------------------------------------------------------------------------
DTODO | 21---------------------
Dempty.conf | 0
Dexample.conf | 12------------
Dlib/argparse | 1-
Dlib/inih | 1-
Dmanpage.1.md | 112-------------------------------------------------------------------------------
Dsrc/config.c | 101-------------------------------------------------------------------------------
Dsrc/config.h | 37-------------------------------------
Dsrc/main.c | 246-------------------------------------------------------------------------------
Dsrc/main.h | 20--------------------
Dsrc/socket.c | 57---------------------------------------------------------
Dsrc/socket.h | 14--------------
17 files changed, 2 insertions(+), 794 deletions(-)

diff --git a/.editorconfig b/.editorconfig @@ -8,8 +8,5 @@ charset = utf-8 indent_size = 2 indent_style = space -[*.{php,html}] -indent_size = 4 - [Makefile*] indent_style = tab diff --git a/.gitignore b/.gitignore @@ -1,4 +1,2 @@ -pmlag -*.[ao] -pmlag.1 -pmlag.html +/bak/ +/lib/ diff --git a/.gitmodules b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "lib/argparse"] - path = lib/argparse - url = git://git.finwo.net/argparse -[submodule "lib/inih"] - path = lib/inih - url = git://git.finwo.net/inih diff --git a/Makefile b/Makefile @@ -1,47 +0,0 @@ -# Setup core -SRC:=$(wildcard src/*.c) -LIBS= -CFLAGS?= -BIN=pmlag - -# We're using threads in our program -CFLAGS+=-lpthread - -# Include lib/argparse -SRC+=lib/argparse/argparse.c -CFLAGS+=-Ilib/argparse -LIBS+=lib/argparse - -# Include lib/ini -SRC+=lib/inih/ini.c -CFLAGS+=-Ilib/inih -LIBS+=lib/inih - -# Translate and default rule -OBJ:=$(SRC:.c=.o) -default: $(BIN) $(BIN).1 README.md - -# How to fetch libraries -$(LIBS): - git submodule update --init $@ - -# How to generate object files -$(OBJ): $(LIBS) - $(CC) $(CFLAGS) $(@:.o=.c) -c -o $@ - -# Build main binary -$(BIN): $(OBJ) - $(CC) $(CFLAGS) $(OBJ) -o $(BIN) - -# Build manpage -$(BIN).1: manpage.1.md - env NAME=$(BIN) envsubst < manpage.1.md | pandoc --standalone --from markdown --to man -o $(BIN).1 - env NAME=$(BIN) envsubst < manpage.1.md | pandoc --standalone --from markdown --to html -o $(BIN).html - -README.md: manpage.1.md - env NAME=$(BIN) envsubst < manpage.1.md > README.md - -# Cleanup -.PHONY: clean -clean: - rm -rf $(OBJ) diff --git a/README.md b/README.md @@ -1,112 +0,0 @@ -% pmlag(1) | General Commands Manual - -NAME -==== - -pmlag - Poor man's link aggregator - -SYNOPSIS -======== - -`pmlag [options]` - -DESCRIPTION -=========== - -pmlag is a tool for bonding network interfaces together when the hardware on -the other side of the cable(s) doesn't necessarily support it. - -OPTIONS -======= - -#### `-h, --help` - -Show the help message and exit - -#### `-c, --config <PATH>` - -Load a custom configuration instead of the default (/etc/pmlag.conf) - -CONFIGURATION -============= - -The configuration is an ini-like format, where the sections are the name of the -device being configured. - -The configuration can be reloaded by sending the USR1 signal to the process. - -#### broadcast - -Select the broadcast method for the bonded interface - -- flood: send out broadcast packages out over all interfaces -- balanced: send out broadcast packages according to balancing strategy - -#### mode - -Select the balancing mode for non-broadcast packages - -- active-backup: define a primary and backup interface -- broadcast: always sent packets to all interfaces -- balance-rr: weighted round-robin balancing - -#### mac - -Define the mac address of the bonded interface - -#### master - -Define which bonded interface the current described interface belongs to - -#### weight - -Behaves differently depending on the mode the bonded interface is in: - -- active-backup: priority of the interface (higher = more preferred) -- broadcast: no effect -- balance-rr: share of traffic the interface transmits - -Try to keep this number as low as possible, as it's used directly to define -the number of packets to send before moving to the next interface in the -round-robin strategy. - -### Example: - -```ini -[bond0] -broadcast=flood -mode=balance-rr -mac=01:23:45:67:89:AB - -[eth0] -master=bond0 -weight=1 - -[eth1] -master=bond0 -weight=10 -``` - -LICENSE -======= - -The MIT License (MIT) - -Copyright © 2022 finwo - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the “Software”), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/TODO b/TODO @@ -1,21 +0,0 @@ -mvp: -- start thread for every interface -- let thread create bond -- let thread create socket -- mutex all the things -- incoming on socket = send to master -- incoming on master = flood to slaves -balanced rr (a.k.a. spine-leaf-ish optimistic): -- set remainder to weight if remainder = 0 (and move to back of line) -- send packet and decrement remainder by 1 -config reloading: -- listen to USR1 signal in parent thread -- update config -- create iface threads for new ifaces -- make thread close socket if not found in config -- make thread close bond if not found in config -spine-leaf-pessimistic: -- track seen mac addresses -- send only to interfaces where it was seen -- optionally send broadcast to all interfaces -- remove known mac address from interface if not seen for weight * 2 on interface diff --git a/empty.conf b/empty.conf diff --git a/example.conf b/example.conf @@ -1,12 +0,0 @@ -[bond0] -broadcast=flood -mode=balance-rr -mac=01:23:45:67:89:AB - -[eth0] -master=bond0 -weight=1 - -[eth1] -master=bond0 -weight=10 diff --git a/lib/argparse b/lib/argparse @@ -1 +0,0 @@ -Subproject commit ffd9c23427d0cb105e27f27f0cf97b463b6a8bf8 diff --git a/lib/inih b/lib/inih @@ -1 +0,0 @@ -Subproject commit 4bd3261ea422a99aa764e63820e16d19cdad33dd diff --git a/manpage.1.md b/manpage.1.md @@ -1,112 +0,0 @@ -% ${NAME}(1) | General Commands Manual - -NAME -==== - -${NAME} - Poor man's link aggregator - -SYNOPSIS -======== - -`${NAME} [options]` - -DESCRIPTION -=========== - -${NAME} is a tool for bonding network interfaces together when the hardware on -the other side of the cable(s) doesn't necessarily support it. - -OPTIONS -======= - -#### `-h, --help` - -Show the help message and exit - -#### `-c, --config <PATH>` - -Load a custom configuration instead of the default (/etc/${NAME}.conf) - -CONFIGURATION -============= - -The configuration is an ini-like format, where the sections are the name of the -device being configured. - -The configuration can be reloaded by sending the USR1 signal to the process. - -#### broadcast - -Select the broadcast method for the bonded interface - -- flood: send out broadcast packages out over all interfaces -- balanced: send out broadcast packages according to balancing strategy - -#### mode - -Select the balancing mode for non-broadcast packages - -- active-backup: define a primary and backup interface -- broadcast: always sent packets to all interfaces -- balance-rr: weighted round-robin balancing - -#### mac - -Define the mac address of the bonded interface - -#### master - -Define which bonded interface the current described interface belongs to - -#### weight - -Behaves differently depending on the mode the bonded interface is in: - -- active-backup: priority of the interface (higher = more preferred) -- broadcast: no effect -- balance-rr: share of traffic the interface transmits - -Try to keep this number as low as possible, as it's used directly to define -the number of packets to send before moving to the next interface in the -round-robin strategy. - -### Example: - -```ini -[bond0] -broadcast=flood -mode=balance-rr -mac=01:23:45:67:89:AB - -[eth0] -master=bond0 -weight=1 - -[eth1] -master=bond0 -weight=10 -``` - -LICENSE -======= - -The MIT License (MIT) - -Copyright © 2022 finwo - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the “Software”), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/config.c b/src/config.c @@ -1,101 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "config.h" -#include "ini.h" -#include "main.h" - -static int config_load_handler( - void *user, - const char *section, - const char *name, - const char *value -) { - pmlag_configuration* config = (pmlag_configuration *) user; - - // Get interface being configured - pmlag_interface *iface = config->interfaces; - while(iface) { - if (!strcmp(iface->name, section)) { - break; - } - iface = iface->next; - } - - // Create interface if not found - if (!iface) { - iface = calloc(1, sizeof(pmlag_interface)); - iface->next = config->interfaces; - iface->name = strdup(section); - config->interfaces = iface; - } - - - // Set found value - if (!strcmp("master", name)) { - iface->master = strdup(value); - } else if (!strcmp("weight", name)) { - iface->weight = atoi(value); - } else if (!strcmp("broadcast", name)) { - if (!strcmp("flood", value)) { - iface->broadcast = BROADCAST_FLOOD; - } else if (!strcmp("balanced", value)) { - iface->broadcast = BROADCAST_BALANCED; - } else { - fprintf(stderr, "Unknown broadcast: %s\n", value); - return 0; - } - } else if (!strcmp("mode", name)) { - if (!strcmp("slave", value)) { - iface->mode = MODE_SLAVE; - } else if (!strcmp("active-backup", value)) { - iface->mode = MODE_ACTIVE_BACKUP; - } else if (!strcmp("broadcast", value)) { - iface->mode = MODE_BROADCAST; - } else if (!strcmp("balance-rr", value)) { - iface->mode = MODE_BALANCE_RR; - } else { - fprintf(stderr, "Unknown mode: %s\n", value); - return 0; - } - } else if (!strcmp("mac", name)) { - // TODO: parse mac address - iface->mac = strdup(value); - } else { - return 0; - } - - return 1; -} - -void config_free(pmlag_configuration *config) { - if (!config) return; - pmlag_interface *iface_next; - pmlag_interface *iface = config->interfaces; - while(iface) { - iface_next = iface->next; - if (iface_next == config->interfaces) break; - if (iface->mac ) free(iface->mac); - if (iface->master) free(iface->master); - if (iface->name ) free(iface->name); - free(iface); - iface = iface_next; - } - free(config); -} - -pmlag_configuration * config_load(const char * filename) { - // Load config, entry-by-entry - pmlag_configuration *config = calloc(1, sizeof(pmlag_configuration)); - if (ini_parse(filename, config_load_handler, config) < 0) { - fprintf(stderr, "Can not load %s\n", filename); - return NULL; - } - // Loop interface list - pmlag_interface *iface = config->interfaces; - while (iface && iface->next) iface = iface->next; - if (iface) iface->next = config->interfaces; - // Return produce - return config; -} diff --git a/src/config.h b/src/config.h @@ -1,37 +0,0 @@ -#ifndef __PMLAG_CONFIG_H__ -#define __PMLAG_CONFIG_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <semaphore.h> - -typedef struct { - // Linked list - void *next; // Ref to the next interface - // Config - char *name; // Name of the interface - char *master; // Name of the controlling interface - char *mac; // Mac address to set on the interface - int broadcast; // Broadcast mode - int mode; // Balancing mode - int weight; // Weight of the interface - // Activity - int socket; // Socket file descriptor - int remainder; // Round robin remainder - sem_t sem_queue; // Egress queue -} pmlag_interface; - -typedef struct { - pmlag_interface *interfaces; -} pmlag_configuration; - -void config_free(pmlag_configuration *config); -pmlag_configuration * config_load(const char * filename); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // __PMLAG_CONFIG_H__ diff --git a/src/main.c b/src/main.c @@ -1,246 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <arpa/inet.h> -#include <netinet/in.h> -#include <netinet/ip.h> -#include <linux/if_ether.h> -#include <sys/socket.h> - -#include <pthread.h> -#include <semaphore.h> -#include <signal.h> - -#include "argparse.h" -#include "config.h" -#include "main.h" -#include "socket.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef NAME -#define NAME "pmlag" -#endif - -static const char *const usage[] = { - NAME " [options]", - NULL -}; - -typedef struct { - void *next; - pthread_t tid; - pmlag_interface *iface; - sem_t *sem_int; - int sig; -} pmlag_thread_ll; - -pmlag_configuration *config = NULL; -pmlag_configuration *config_pending = NULL; -pmlag_thread_ll *threads = NULL; - -int counter = 0; -pthread_mutex_t counter_lock; -void * iface_thread(void *arg) { - pmlag_thread_ll *thread = (pmlag_thread_ll *)arg; - - - printf("Thread started for %s\n", thread->iface->name); - - while(1) { - usleep(100000); // 100ms - - // Handle sigint - if (thread->sig & SIGINT) { - printf("Thread for %s received SIGINT\n", thread->iface->name); - sem_post(thread->sem_int); - return NULL; - } - - } - /* unsigned long i = 0; */ - /* int local_id; */ - - /* pthread_mutex_lock(&counter_lock); */ - /* counter+=1; */ - /* local_id = counter; */ - /* pthread_mutex_unlock(&counter_lock); */ - - /* printf("Job started: %d\n", local_id); */ - /* for(i=0; i<(0xFFFFFFF);i++); */ - /* printf(" Job %d finished\n", local_id); */ - - return NULL; -} - - -void update_workers() { - - // Only act on config updates - if (!config_pending) return; - - // First shutdown all active threads - pmlag_thread_ll *thread = threads; - pmlag_thread_ll *oldthread = NULL; - while(thread) { - thread->sig = SIGINT; // Signal the thread to interrupt - sem_wait(thread->sem_int); // Wait for the thread to shut down - sem_destroy(thread->sem_int); // Desroy the semaphore - free(thread->sem_int); - oldthread = thread; // Free thread & move on the the next - thread = thread->next; - free(oldthread); - } - threads = NULL; - - // For each interface, start a new thread - pmlag_interface *iface = config_pending->interfaces; - while(iface) { - thread = calloc(1, sizeof(pmlag_thread_ll)); - thread->next = threads; - thread->iface = iface; - thread->sem_int = calloc(1, sizeof(sem_t)); - threads = thread; - sem_init(thread->sem_int, 0, 0); - thread->tid = pthread_create(&(thread->tid), NULL, iface_thread, thread); - iface = iface->next; - if (iface == config_pending->interfaces) break; - } - - // Mark the updated config as current - if (config) config_free(config); - config = config_pending; - config_pending = NULL; -} - -int main(int argc, const char **argv) { - const char *config_file = "/etc/" NAME ".conf"; - - // Define which options we support - struct argparse_option options[] = { - OPT_HELP(), - OPT_STRING('c', "config", &config_file, "Config file to use", NULL, 0, 0), - OPT_END(), - }; - - // Parse command line arguments - struct argparse argparse; - argparse_init(&argparse, options, usage, 0); - argparse_describe(&argparse, NULL, - // TODO: format to terminal width - "\n" NAME " is a tool for bonding network interfaces together when the " - "hardware\non the other side of the cable(s) doesn't support it." - "\n" - ); - argc = argparse_parse(&argparse, argc, argv); - - // Load configuration - pmlag_configuration *loaded = config_load(config_file); - - // Basic config validation - if (!loaded->interfaces) { - fprintf(stderr, "No interfaces defined in config\n"); - return 1; - } - - // Trigger update - config_pending = loaded; - update_workers(); - - // TODO: monitor threads here - // TODO: capture USR1 for config reload - sleep(10); - - // Trigger graceful shutdown - config_pending = calloc(1, sizeof(pmlag_configuration)); - update_workers(); - return 0; - - /* // DEBUG: Show loaded configuration */ - /* fprintf(stderr, "Loaded configuration:\n"); */ - /* pmlag_interface *iface = loaded->interfaces; */ - /* while(iface) { */ - /* fprintf(stderr, " Interface: %s\n", iface->name); */ - /* fprintf(stderr, " master : %s\n", iface->master ? iface->master : ""); */ - /* fprintf(stderr, " mac : %s\n", iface->mac ? iface->mac : ""); */ - /* fprintf(stderr, " broadcast: %s%s\n", */ - /* iface->broadcast == BROADCAST_FLOOD ? "flood" : "", */ - /* iface->broadcast == BROADCAST_BALANCED ? "balanced" : "" */ - /* ); */ - /* fprintf(stderr, " mode : %s%s%s%s\n", */ - /* iface->mode == MODE_SLAVE ? "slave" : "", */ - /* iface->mode == MODE_ACTIVE_BACKUP ? "active-backup" : "", */ - /* iface->mode == MODE_BROADCAST ? "broadcast" : "", */ - /* iface->mode == MODE_BALANCE_RR ? "balance-rr" : "" */ - /* ); */ - /* fprintf(stderr, " weight : %d\n", iface->weight); */ - /* iface = iface->next; */ - /* if (iface == loaded->interfaces) break; */ - /* } */ - - - - - /* int sockfd = sockraw_open(INTERFACE); */ - - /* // Prepare ingress buffer */ - /* int buflen; */ - /* unsigned char *buffer = (unsigned char *) malloc(65536); */ - /* memset(buffer, 0, 65536); */ - /* struct sockaddr saddr; */ - /* int saddr_len = sizeof(saddr); */ - - /* // Fetch a packet */ - /* buflen = recvfrom(sockfd, buffer, 65536, 0, &saddr, (socklen_t *)&saddr_len); */ - /* if (buflen < 0) { */ - /* perror("recvfrom"); */ - /* exit(EXIT_FAILURE); */ - /* } */ - - /* printf("\n"); */ - /* printf("Got packet: %d bytes\n", buflen); */ - /* printf("\n"); */ - - /* struct ethhdr *eth = (struct ethhdr *)(buffer); */ - /* printf("Ethernet header\n"); */ - /* printf("\t|- DST %.2X-%.2X-%.2X-%.2X-%.2X-%.2X\n",eth->h_dest[0],eth->h_dest[1],eth->h_dest[2],eth->h_dest[3],eth->h_dest[4],eth->h_dest[5]); */ - /* printf("\t|- SRC %.2X-%.2X-%.2X-%.2X-%.2X-%.2X\n",eth->h_source[0],eth->h_source[1],eth->h_source[2],eth->h_source[3],eth->h_source[4],eth->h_source[5]); */ - /* printf("\t|- PROTO %d\n",eth->h_proto); */ - - /* printf("\n"); */ - - /* struct sockaddr_in source; */ - /* struct sockaddr_in dest; */ - /* if (eth->h_proto == 8) { */ - /* unsigned short iphdrlen; */ - /* struct iphdr *ip = (struct iphdr*)(buffer + sizeof(struct ethhdr)); */ - /* memset(&source, 0, sizeof(source)); */ - /* source.sin_addr.s_addr = ip->saddr; */ - /* memset(&dest, 0, sizeof(dest)); */ - /* dest.sin_addr.s_addr = ip->daddr; */ - - /* printf("IP header\n"); */ - /* printf("\t|- Version %d\n",(unsigned int)ip->version); */ - /* printf("\t|- Internet hlen %d DWORDS or %d Bytes\n",(unsigned int)ip->ihl,((unsigned int)(ip->ihl))*4); */ - /* printf("\t|- Type Of Service %d\n",(unsigned int)ip->tos); */ - /* printf("\t|- Total Length %d Bytes\n",ntohs(ip->tot_len)); */ - /* printf("\t|- Identification %d\n",ntohs(ip->id)); */ - /* printf("\t|- Time To Live %d\n",(unsigned int)ip->ttl); */ - /* printf("\t|- Protocol %d\n",(unsigned int)ip->protocol); */ - /* printf("\t|- Header Checksum %d\n",ntohs(ip->check)); */ - /* printf("\t|- Source IP %s\n", inet_ntoa(source.sin_addr)); */ - /* printf("\t|- Destination IP %s\n",inet_ntoa(dest.sin_addr)); */ - - /* printf("\n"); */ - /* } */ - - /* return 0; */ -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/src/main.h b/src/main.h @@ -1,20 +0,0 @@ -#ifndef __PMLAG_MAIN_H__ -#define __PMLAG_MAIN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define BROADCAST_FLOOD 1 -#define BROADCAST_BALANCED 2 - -#define MODE_SLAVE 0 -#define MODE_ACTIVE_BACKUP 1 -#define MODE_BROADCAST 2 -#define MODE_BALANCE_RR 3 - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // __PMLAG_MAIN_H__ diff --git a/src/socket.c b/src/socket.c @@ -1,57 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -#include <arpa/inet.h> -#include <net/ethernet.h> -#include <net/if.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <unistd.h> - -#include <linux/if_packet.h> - -int sockraw_open(char * ifname) { - - // Open socket - int sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); - if (sockfd < 0) { - perror("Error opening socket"); - close(sockfd); - return -1; - } - - struct sockaddr_ll sll; - struct ifreq ifr; - bzero(&sll, sizeof(sll)); - bzero(&ifr, sizeof(ifr)); - - // Get interface index - strncpy((char *)ifr.ifr_name, ifname, IFNAMSIZ); - if ((ioctl(sockfd, SIOCGIFINDEX, &ifr)) == -1) { - perror("Error getting interface index"); - close(sockfd); - return -1; - } - - // Bind socket to interface - sll.sll_family = AF_PACKET; - sll.sll_ifindex = ifr.ifr_ifindex; - sll.sll_protocol = htons(ETH_P_ALL); - if((bind(sockfd, (struct sockaddr *)&sll, sizeof(sll))) == -1) { - perror("Error binding raw socket to interface"); - close(sockfd); - return -1; - } - - // Return the prepared socket - return sockfd; -} - - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/src/socket.h b/src/socket.h @@ -1,14 +0,0 @@ -#ifndef __PMLAG_SOCKET_H__ -#define __PMLAG_SOCKET_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int sockraw_open(char * ifname); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // __PMLAG_SOCKET_H__