diff options
| author | Michael Tüxen <tuexen@fh-muenster.de> | 2019-05-01 22:45:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-01 22:45:36 +0200 |
| commit | c7c3f772cad4718f4c777362d5183ad20bce85db (patch) | |
| tree | ea3e6d103ee1a57b24aab9651e04932e7096e470 /executor/common_bsd.h | |
| parent | 7516d9fa9301d2dfa5beaf49d93563f8048694aa (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 'executor/common_bsd.h')
| -rw-r--r-- | executor/common_bsd.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/executor/common_bsd.h b/executor/common_bsd.h index be9481563..2a9f677c7 100644 --- a/executor/common_bsd.h +++ b/executor/common_bsd.h @@ -58,8 +58,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) { @@ -119,6 +123,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 @@ -146,13 +151,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 // SYZ_EXECUTOR || SYZ_TUN_ENABLE |
