From 30207d6691e04eab5071aa68a0be441913688a03 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 1 Jun 2020 22:54:15 +0200 Subject: [PATCH] Added ARP configuration for interface --- Constants.h | 6 +++++- TAP.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Constants.h b/Constants.h index cd9e3a2..fd366ee 100644 --- a/Constants.h +++ b/Constants.h @@ -8,4 +8,8 @@ #define MTU_MAX 1522 #define MTU_DEFAULT 329 -#define TXQUEUELEN 10 \ No newline at end of file +#define TXQUEUELEN 10 + +// ARP timings, in seconds +#define ARP_BASE_REACHABLE_TIME 300 +#define ARP_RETRANS_TIME 5 \ No newline at end of file diff --git a/TAP.c b/TAP.c index c2be769..45f5d00 100644 --- a/TAP.c +++ b/TAP.c @@ -80,6 +80,49 @@ int open_tap(void) { } } + // Configure ARP characteristics + char path_buf[256]; + if (device_type == IF_TAP) { + snprintf(path_buf, sizeof(path_buf), "/proc/sys/net/ipv4/neigh/%s/base_reachable_time_ms", ifr.ifr_name); + int arp_fd = open(path_buf, O_WRONLY); + if (arp_fd < 0) { + perror("Could not open proc entry for ARP parameters"); + close(inet); + cleanup(); + exit(1); + } else { + if (dprintf(arp_fd, "%d", ARP_BASE_REACHABLE_TIME*1000) <= 0) { + perror("Could not configure interface ARP parameter base_reachable_time_ms"); + close(inet); + close(arp_fd); + cleanup(); + exit(1); + } else { + close(arp_fd); + } + } + + snprintf(path_buf, sizeof(path_buf), "/proc/sys/net/ipv4/neigh/%s/retrans_time_ms", ifr.ifr_name); + arp_fd = open(path_buf, O_WRONLY); + if (arp_fd < 0) { + perror("Could not open proc entry for ARP parameters"); + close(inet); + cleanup(); + exit(1); + } else { + if (dprintf(arp_fd, "%d", ARP_RETRANS_TIME*1000) <= 0) { + perror("Could not configure interface ARP parameter retrans_time_ms"); + close(inet); + close(arp_fd); + cleanup(); + exit(1); + } else { + close(arp_fd); + } + } + } + + // Bring up if requested if (!noup) { if (ioctl(inet, SIOCGIFFLAGS, &ifr) < 0) { perror("Could not get interface flags from kernel");