aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/csource/generated.go
diff options
context:
space:
mode:
authorMichael Tüxen <tuexen@fh-muenster.de>2019-05-01 22:45:36 +0200
committerGitHub <noreply@github.com>2019-05-01 22:45:36 +0200
commitc7c3f772cad4718f4c777362d5183ad20bce85db (patch)
treeea3e6d103ee1a57b24aab9651e04932e7096e470 /pkg/csource/generated.go
parent7516d9fa9301d2dfa5beaf49d93563f8048694aa (diff)
executor: improve setup for packet handling on *BSD (#1153)
Improve the handling of packets by: * setting the local MAC address. * configuring the local IPv4 address with prefix /24. * adding an entry in the arp cache for the remote IPv4 address. * adding an entry in the IPv6 neighbour cache for the remote IPv6 address.
Diffstat (limited to 'pkg/csource/generated.go')
-rw-r--r--pkg/csource/generated.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index a9f542d78..2a9c22002 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -443,8 +443,12 @@ static int tunfd = -1;
#define TUN_IFACE "tap%d"
#define TUN_DEVICE "/dev/tap%d"
+#define LOCAL_MAC "aa:aa:aa:aa:aa:aa"
+#define REMOTE_MAC "aa:aa:aa:aa:aa:bb"
#define LOCAL_IPV4 "172.20.%d.170"
+#define REMOTE_IPV4 "172.20.%d.187"
#define LOCAL_IPV6 "fe80::%02hxaa"
+#define REMOTE_IPV6 "fe80::%02hxbb"
static void vsnprintf_check(char* str, size_t size, const char* format, va_list args)
{
@@ -501,6 +505,7 @@ static void initialize_tun(int tun_id)
char tun_device[sizeof(TUN_DEVICE)];
snprintf_check(tun_device, sizeof(tun_device), TUN_DEVICE, tun_id);
+ execute_command(0, "ifconfig %s destroy", tun_device);
tunfd = open(tun_device, O_RDWR | O_NONBLOCK);
#if GOOS_freebsd
@@ -526,13 +531,27 @@ static void initialize_tun(int tun_id)
char tun_iface[sizeof(TUN_IFACE)];
snprintf_check(tun_iface, sizeof(tun_iface), TUN_IFACE, tun_id);
+ char local_mac[sizeof(LOCAL_MAC)];
+ snprintf_check(local_mac, sizeof(local_mac), LOCAL_MAC);
+ execute_command(1, "ifconfig %s ether %s", tun_iface, local_mac);
+
char local_ipv4[sizeof(LOCAL_IPV4)];
snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, tun_id);
- execute_command(1, "ifconfig %s inet %s", tun_iface, local_ipv4);
+ execute_command(1, "ifconfig %s inet %s netmask 255.255.255.0", tun_iface, local_ipv4);
+
+ char remote_mac[sizeof(REMOTE_MAC)];
+ char remote_ipv4[sizeof(REMOTE_IPV4)];
+ snprintf_check(remote_mac, sizeof(remote_mac), REMOTE_MAC);
+ snprintf_check(remote_ipv4, sizeof(remote_ipv4), REMOTE_IPV4, tun_id);
+ execute_command(0, "arp -s %s %s", remote_ipv4, remote_mac);
char local_ipv6[sizeof(LOCAL_IPV6)];
snprintf_check(local_ipv6, sizeof(local_ipv6), LOCAL_IPV6, tun_id);
execute_command(1, "ifconfig %s inet6 %s", tun_iface, local_ipv6);
+
+ char remote_ipv6[sizeof(REMOTE_IPV6)];
+ snprintf_check(remote_ipv6, sizeof(remote_ipv6), REMOTE_IPV6, tun_id);
+ execute_command(0, "ndp -s %s%%%s %s", remote_ipv6, tun_iface, remote_mac);
}
#endif