aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common_bsd.h
diff options
context:
space:
mode:
Diffstat (limited to 'executor/common_bsd.h')
-rw-r--r--executor/common_bsd.h28
1 files changed, 22 insertions, 6 deletions
diff --git a/executor/common_bsd.h b/executor/common_bsd.h
index d39d2aded..e483a41d1 100644
--- a/executor/common_bsd.h
+++ b/executor/common_bsd.h
@@ -37,7 +37,7 @@ static uintptr_t syz_open_pts(void)
#endif // GOOS_openbsd
-#if GOOS_freebsd || GOOS_openbsd
+#if GOOS_freebsd || GOOS_openbsd || GOOS_netbsd
#if SYZ_EXECUTOR || SYZ_TUN_ENABLE
@@ -123,7 +123,18 @@ static void initialize_tun(int tun_id)
char tun_device[sizeof(TUN_DEVICE)];
snprintf_check(tun_device, sizeof(tun_device), TUN_DEVICE, tun_id);
+
+ char tun_iface[sizeof(TUN_IFACE)];
+ snprintf_check(tun_iface, sizeof(tun_iface), TUN_IFACE, tun_id);
+
+#if GOOS_netbsd
+ // open(2) doesn't create an new tap/tun interface node
+ // so we use ifconfig to create the node. Might be casued due to regression
+ execute_command(0, "ifconfig %s destroy", tun_iface);
+ execute_command(0, "ifconfig %s create", tun_iface);
+#else
execute_command(0, "ifconfig %s destroy", tun_device);
+#endif
tunfd = open(tun_device, O_RDWR | O_NONBLOCK);
#if GOOS_freebsd
@@ -148,31 +159,36 @@ static void initialize_tun(int tun_id)
close(tunfd);
tunfd = kTunFd;
- 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);
+
+ // Set the MAC address of the interface to LOCAL_MAC
#if GOOS_openbsd
execute_command(1, "ifconfig %s lladdr %s", tun_iface, local_mac);
+#elif GOOS_netbsd
+ execute_command(1, "ifconfig %s link %s", tun_iface, local_mac);
#else
execute_command(1, "ifconfig %s ether %s", tun_iface, local_mac);
#endif
+ // Setting up a static ip for the interface
char local_ipv4[sizeof(LOCAL_IPV4)];
snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, tun_id);
execute_command(1, "ifconfig %s inet %s netmask 255.255.255.0", tun_iface, local_ipv4);
+ // Creates an ARP table entry for the remote ip and MAC address
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);
+ // Set up a static ipv6 address for the interface
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);
+ // Registers an NDP entry for the remote MAC with the remote ipv6 address
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);
@@ -332,7 +348,7 @@ static void loop();
static int do_sandbox_none(void)
{
sandbox_common();
-#if (GOOS_freebsd || GOOS_openbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE)
+#if (GOOS_freebsd || GOOS_openbsd || GOOS_netbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE)
initialize_tun(procid);
#endif
loop();
@@ -367,7 +383,7 @@ static int do_sandbox_setuid(void)
return wait_for_loop(pid);
sandbox_common();
-#if (GOOS_freebsd || GOOS_openbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE)
+#if (GOOS_freebsd || GOOS_openbsd || GOOS_netbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE)
initialize_tun(procid);
#endif