diff --git a/gtests/net/packetdrill/Makefile.Darwin b/gtests/net/packetdrill/Makefile.Darwin new file mode 100644 index 0000000000000000000000000000000000000000..3f5395881dad905e6a6019556d6a27add3b2b019 --- /dev/null +++ b/gtests/net/packetdrill/Makefile.Darwin @@ -0,0 +1,8 @@ +packetdrill-ext-libs := -pthread -lpcap +CFLAGS = -D__APPLE_USE_RFC_3542 +LDFLAGS = +ifeq ("$(wildcard $(/usr/lib/libsctp.dylib))","") + packetdrill-ext-libs += -lsctp + CFLAGS += -DHAVE_SCTP +endif +include Makefile.common diff --git a/gtests/net/packetdrill/Makefile.common b/gtests/net/packetdrill/Makefile.common index 06a865dbbd8a082002323ad88b67c0fa2b69e05b..d7ce394eadcbb72239ff2f09a179f52582c8ad51 100644 --- a/gtests/net/packetdrill/Makefile.common +++ b/gtests/net/packetdrill/Makefile.common @@ -1,6 +1,7 @@ all: binaries -CFLAGS = -g -Wall -Werror -Wno-unknown-warning-option -Wno-address-of-packed-member +CFLAGS += -g -Wall -Werror -Wno-unknown-warning-option -Wno-address-of-packed-member +LDFLAGS ?= -static parser.o: parser.y bison --output=parser.c --defines=parser.h --report=state parser.y @@ -19,6 +20,7 @@ packetdrill-lib := \ symbols_freebsd.o \ symbols_openbsd.o \ symbols_netbsd.o \ + symbols_darwin.o \ gre_packet.o icmp_packet.o ip_packet.o \ sctp_packet.o tcp_packet.o udp_packet.o udplite_packet.o \ mpls_packet.o \ @@ -35,7 +37,7 @@ packetdrill-lib := \ packetdrill-objs := packetdrill.o $(packetdrill-lib) packetdrill: $(packetdrill-objs) - $(CC) -o packetdrill -g -static $(packetdrill-objs) $(packetdrill-ext-libs) + $(CC) -o packetdrill -g $(LDFLAGS) $(packetdrill-objs) $(packetdrill-ext-libs) test-bins := checksum_test packet_parser_test packet_to_string_test tests: $(test-bins) diff --git a/gtests/net/packetdrill/code.c b/gtests/net/packetdrill/code.c index 5a062b24770a68164d7769ef1d1f02ecbaa1a6de..e2c3755412c003a7b105b5eab84d62be2f2166cd 100644 --- a/gtests/net/packetdrill/code.c +++ b/gtests/net/packetdrill/code.c @@ -104,7 +104,7 @@ static void emit_var_end(struct code_state *code) static void write_symbols(struct code_state *code) { /* tcpi_state */ -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) emit_var(code, "TCPI_CLOSED", TCPS_CLOSED); emit_var(code, "TCPI_LISTEN", TCPS_LISTEN); emit_var(code, "TCPI_SYN_SENT", TCPS_SYN_SENT); @@ -152,6 +152,18 @@ static void write_symbols(struct code_state *code) emit_var(code, "TCPI_OPT_WSCALE", TCPI_OPT_WSCALE); emit_var(code, "TCPI_OPT_ECN", TCPI_OPT_ECN); #endif +#ifdef __APPLE__ + emit_var(code, "TCPI_OPT_TIMESTAMPS", TCPCI_OPT_TIMESTAMPS); + emit_var(code, "TCPI_OPT_SACK", TCPCI_OPT_SACK); + emit_var(code, "TCPI_OPT_WSCALE", TCPCI_OPT_WSCALE); + emit_var(code, "TCPI_OPT_ECN", TCPCI_OPT_ECN); +#endif + + /* tcpi_flags flags */ +#ifdef __APPLE__ + emit_var(code, "TCPI_FLAG_LOSSRECOVERY", TCPCI_FLAG_LOSSRECOVERY); + emit_var(code, "TCPI_FLAG_REORDERING_DETECTED", TCPCI_FLAG_REORDERING_DETECTED); +#endif } #endif /* HAVE_TCP_INFO */ @@ -248,6 +260,61 @@ static void write_tcp_info(struct code_state *code, #endif /* __FreeBSD__ */ +#if defined(__APPLE__) + +/* Write out a formatted representation of the given tcp_info buffer. */ +static void write_tcp_info(struct code_state *code, + const struct _tcp_info *info, + int len) +{ + assert(len >= sizeof(struct _tcp_info)); + + write_symbols(code); + + /* Emit the recorded values of tcpi_foo values. */ + emit_var(code, "tcpi_state", info->tcpi_state); + emit_var(code, "tcpi_snd_wscale", info->tcpi_snd_wscale); + emit_var(code, "tcpi_rcv_wscale", info->tcpi_rcv_wscale); + emit_var(code, "tcpi_options", info->tcpi_options); + emit_var(code, "tcpi_flags", info->tcpi_flags); + emit_var(code, "tcpi_rto", info->tcpi_rto); + emit_var(code, "tcpi_maxseg", info->tcpi_maxseg); + emit_var(code, "tcpi_snd_ssthresh", info->tcpi_snd_ssthresh); + emit_var(code, "tcpi_snd_cwnd", info->tcpi_snd_cwnd); + emit_var(code, "tcpi_snd_wnd", info->tcpi_snd_wnd); + emit_var(code, "tcpi_snd_sbbytes", info->tcpi_snd_sbbytes); + emit_var(code, "tcpi_rcv_wnd", info->tcpi_rcv_wnd); + emit_var(code, "tcpi_rttcur", info->tcpi_rttcur); + emit_var(code, "tcpi_srtt", info->tcpi_srtt); + emit_var(code, "tcpi_rttvar", info->tcpi_rttvar); + emit_var(code, "tcpi_tfo_cookie_req", info->tcpi_tfo_cookie_req); + emit_var(code, "tcpi_tfo_cookie_rcv", info->tcpi_tfo_cookie_rcv); + emit_var(code, "tcpi_tfo_syn_loss", info->tcpi_tfo_syn_loss); + emit_var(code, "tcpi_tfo_syn_data_sent", info->tcpi_tfo_syn_data_sent); + emit_var(code, "tcpi_tfo_syn_data_acked", info->tcpi_tfo_syn_data_acked); + emit_var(code, "tcpi_tfo_syn_data_rcv", info->tcpi_tfo_syn_data_rcv); + emit_var(code, "tcpi_tfo_cookie_req_rcv", info->tcpi_tfo_cookie_req_rcv); + emit_var(code, "tcpi_tfo_cookie_sent", info->tcpi_tfo_cookie_sent); + emit_var(code, "tcpi_tfo_cookie_invalid", info->tcpi_tfo_cookie_invalid); + emit_var(code, "tcpi_tfo_cookie_wrong", info->tcpi_tfo_cookie_wrong); + emit_var(code, "tcpi_tfo_no_cookie_rcv", info->tcpi_tfo_no_cookie_rcv); + emit_var(code, "tcpi_tfo_heuristics_disable", info->tcpi_tfo_heuristics_disable); + emit_var(code, "tcpi_tfo_send_blackhole", info->tcpi_tfo_send_blackhole); + emit_var(code, "tcpi_tfo_recv_blackhole", info->tcpi_tfo_recv_blackhole); + emit_var(code, "tcpi_tfo_onebyte_proxy", info->tcpi_tfo_onebyte_proxy); + emit_var(code, "tcpi_txpackets", info->tcpi_txpackets); + emit_var(code, "tcpi_txbytes", info->tcpi_txbytes); + emit_var(code, "tcpi_txretransmitbytes", info->tcpi_txretransmitbytes); + emit_var(code, "tcpi_rxpackets", info->tcpi_rxpackets); + emit_var(code, "tcpi_rxbytes", info->tcpi_rxbytes); + emit_var(code, "tcpi_rxoutoforderbytes", info->tcpi_rxoutoforderbytes); + emit_var(code, "tcpi_txretransmitpackets", info->tcpi_txretransmitpackets); + + emit_var_end(code); +} + +#endif /* __APPLE__ */ + /* Allocate a new empty struct code_text struct. */ static struct code_text *text_new(void) { @@ -580,7 +647,11 @@ static void *get_data(int fd, enum code_data_t data_type, int *len) break; #if HAVE_TCP_INFO case DATA_TCP_INFO: +#if defined(__APPLE__) + opt_name = TCP_CONNECTION_INFO; +#else opt_name = TCP_INFO; +#endif data_len = sizeof(struct _tcp_info); min_data_len = data_len; break; diff --git a/gtests/net/packetdrill/lexer.l b/gtests/net/packetdrill/lexer.l index ea3c647d1e2993ff2bd6dd609307448917b70694..a91ab1402f53f2d94f30fddfd91764e642662cb0 100644 --- a/gtests/net/packetdrill/lexer.l +++ b/gtests/net/packetdrill/lexer.l @@ -104,7 +104,7 @@ static s64 hextol(const char *s) } enum ifdef_os { - Linux_IFDEF = 1, FreeBSD_IFDEF, NetBSD_IFDEF, OpenBSD_IFDEF, Omnet_IFDEF + Linux_IFDEF = 1, FreeBSD_IFDEF, NetBSD_IFDEF, OpenBSD_IFDEF, Omnet_IFDEF, Apple_IFDEF }; #define MAX_IFDEF_DEPTH 1 @@ -123,34 +123,35 @@ static inline int get_os_name_length(enum ifdef_os os) { return strlen("OpenBSD"); case Omnet_IFDEF: return strlen("Omnet"); + case Apple_IFDEF: + return strlen("Apple"); default: return -1; } } static inline bool ignore_ifdef(enum ifdef_os os) { + switch (os) { #ifdef linux - if (os == Linux_IFDEF) { - return false; - } + case Linux_IFDEF: #endif #ifdef __FreeBSD__ - if (os == FreeBSD_IFDEF) { - return false; - } + case FreeBSD_IFDEF: #endif #ifdef __OpenBSD__ - if (os == OpenBSD_IFDEF) { - return false; - } + case OpenBSD_IFDEF: #endif #ifdef __NetBSD__ - if (os == NetBSD_IFDEF) { - return false; - } + case NetBSD_IFDEF: +#endif +#ifdef __APPLE__ + case Apple_IFDEF: #endif /* no need to handle Omnet here */ - return true; + return false; + default: + return true; + } } static inline char* remove_ifdef_start_and_endtag(char *code, int os_name_length) { @@ -187,11 +188,11 @@ static void handle_ifdef(enum ifdef_os os, const char *s) { } code = strdup(s); - - // keep track of the current value of yylineno, because we need to restore it later (see EOF-Condition), - // otherwise all ifdefs that were interpreted will count twice in yylineno, - // which will mess up the value in yylineno. - old_yylineno = yylineno; + + // keep track of the current value of yylineno, because we need to restore it later (see EOF-Condition), + // otherwise all ifdefs that were interpreted will count twice in yylineno, + // which will mess up the value in yylineno. + old_yylineno = yylineno; code_without_ifdef = remove_ifdef_start_and_endtag(code, os_name_length); ifdef_stack[ifdef_stack_ptr++] = YY_CURRENT_BUFFER; @@ -288,10 +289,10 @@ msg_name return MSG_NAME; msg_iov return MSG_IOV; msg_control return MSG_CONTROL; msg_flags return MSG_FLAGS; -cmsg_len return CMSG_LEN; +cmsg_len return _CMSG_LEN_; cmsg_level return CMSG_LEVEL; cmsg_type return CMSG_TYPE; -cmsg_data return CMSG_DATA; +cmsg_data return _CMSG_DATA_; fd return FD; events return EVENTS; revents return REVENTS; diff --git a/gtests/net/packetdrill/link_layer.c b/gtests/net/packetdrill/link_layer.c index 45f5b666f4f44bbec2def6febf96912a3657fa1b..d283bb8564ceac66aaeca1e45f717d322c858058 100644 --- a/gtests/net/packetdrill/link_layer.c +++ b/gtests/net/packetdrill/link_layer.c @@ -66,13 +66,11 @@ void get_hw_address(const char *name, struct ether_addr *hw_address) #else -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include <net/if_types.h> #include <net/if_dl.h> #include <sys/types.h> #include <sys/socket.h> #include <ifaddrs.h> -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ void get_hw_address(const char *name, struct ether_addr *hw_address) { diff --git a/gtests/net/packetdrill/net_utils.c b/gtests/net/packetdrill/net_utils.c index 1b59d6452a4f9f86ae6b8a4d4971c41dc55d377a..ca2dd3872d27ba25d3b93a42aa379acc030a553f 100644 --- a/gtests/net/packetdrill/net_utils.c +++ b/gtests/net/packetdrill/net_utils.c @@ -43,47 +43,50 @@ static void verbose_system(const char *command) /* Configure a local IPv4 address and netmask for the device */ static void net_add_ipv4_address(const char *dev_name, - const struct ip_address *ip, - int prefix_len) + const struct ip_address *local_ip, + int prefix_len, + const struct ip_address *gateway_ip) { char *command = NULL; - char ip_string[ADDR_STR_LEN]; + char local_ip_string[ADDR_STR_LEN]; + char gateway_ip_string[ADDR_STR_LEN]; - ip_to_string(ip, ip_string); + ip_to_string(local_ip, local_ip_string); + ip_to_string(gateway_ip, gateway_ip_string); #ifdef linux asprintf(&command, "ip addr add %s/%d dev %s > /dev/null 2>&1", - ip_string, prefix_len, dev_name); + local_ip_string, prefix_len, dev_name); #endif #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) asprintf(&command, "/sbin/ifconfig %s %s/%d alias", - dev_name, ip_string, prefix_len); + dev_name, local_ip_string, prefix_len); #endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ - +#if defined(__APPLE__) + asprintf(&command, "/sbin/ifconfig %s %s/%d %s alias", + dev_name, local_ip_string, prefix_len, gateway_ip_string); +#endif /* defined(__APPLE__) */ verbose_system(command); free(command); } /* Configure a local IPv6 address and prefix length for the device */ static void net_add_ipv6_address(const char *dev_name, - const struct ip_address *ip, + const struct ip_address *local_ip, int prefix_len) { char *command = NULL; - char ip_string[ADDR_STR_LEN]; + char local_ip_string[ADDR_STR_LEN]; - ip_to_string(ip, ip_string); + ip_to_string(local_ip, local_ip_string); #ifdef linux - asprintf(&command, "ip addr add %s/%d dev %s > /dev/null 2>&1", - ip_string, prefix_len, dev_name); -#endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) - + local_ip_string, prefix_len, dev_name); +#else asprintf(&command, "/sbin/ifconfig %s inet6 %s/%d", - dev_name, ip_string, prefix_len); -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ + dev_name, local_ip_string, prefix_len); +#endif /* defined(linux) */ verbose_system(command); free(command); @@ -96,22 +99,22 @@ static void net_add_ipv6_address(const char *dev_name, #ifdef linux if (!strstr(dev_name, "tun")) sleep(2); -#endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#else sleep(3); #endif } -void net_add_dev_address(const char *dev_name, - const struct ip_address *ip, - int prefix_len) +static void net_add_dev_address(const char *dev_name, + const struct ip_address *local_ip, + int prefix_len, + const struct ip_address *gateway_ip) { - switch (ip->address_family) { + switch (local_ip->address_family) { case AF_INET: - net_add_ipv4_address(dev_name, ip, prefix_len); + net_add_ipv4_address(dev_name, local_ip, prefix_len, gateway_ip); break; case AF_INET6: - net_add_ipv6_address(dev_name, ip, prefix_len); + net_add_ipv6_address(dev_name, local_ip, prefix_len); break; default: assert(!"bad family"); @@ -127,18 +130,15 @@ void net_del_dev_address(const char *dev_name, char ip_string[ADDR_STR_LEN]; ip_to_string(ip, ip_string); - -#ifdef linux +#if defined(linux) asprintf(&command, "ip addr del %s/%d dev %s > /dev/null 2>&1", ip_string, prefix_len, dev_name); -#endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#else asprintf(&command, "/sbin/ifconfig %s %s %s/%d -alias", dev_name, ip->address_family == AF_INET6 ? "inet6" : "", ip_string, prefix_len); -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ - +#endif /* defined(linux) */ verbose_system(command); free(command); } @@ -152,12 +152,13 @@ void net_del_dev_address(const char *dev_name, * and add it on the newly-requested device. */ void net_setup_dev_address(const char *dev_name, - const struct ip_address *ip, - int prefix_len) + const struct ip_address *local_ip, + int prefix_len, + const struct ip_address *gateway_ip) { char cur_dev_name[IFNAMSIZ]; - bool found = get_ip_device(ip, cur_dev_name); + bool found = get_ip_device(local_ip, cur_dev_name); DEBUGP("net_setup_dev_address: found: %d\n", found); @@ -167,6 +168,6 @@ void net_setup_dev_address(const char *dev_name, } if (found) - net_del_dev_address(cur_dev_name, ip, prefix_len); - net_add_dev_address(dev_name, ip, prefix_len); + net_del_dev_address(cur_dev_name, local_ip, prefix_len); + net_add_dev_address(dev_name, local_ip, prefix_len, gateway_ip); } diff --git a/gtests/net/packetdrill/net_utils.h b/gtests/net/packetdrill/net_utils.h index bdc100965b51293d7e5b6a795a83a23d66e455b4..5bb00588c5b58b31987a10b3e60f72b5626a875a 100644 --- a/gtests/net/packetdrill/net_utils.h +++ b/gtests/net/packetdrill/net_utils.h @@ -30,13 +30,6 @@ #include "ip_address.h" -/* Add the given IP address, with the given subnet/prefix length, - * to the given device. - */ -extern void net_add_dev_address(const char *dev_name, - const struct ip_address *ip, - int prefix_len); - /* Delete the given IP address, with the given subnet/prefix length, * from the given device. */ @@ -48,9 +41,12 @@ extern void net_del_dev_address(const char *dev_name, * is already on the given device. If so, return without doing * anything. If not, delete it from any device it's currently on, and * add it to the given network device. + * On some platforms P2P devices are used, so also provide the gateway + * address. */ extern void net_setup_dev_address(const char *dev_name, - const struct ip_address *ip, - int prefix_len); + const struct ip_address *local_ip, + int prefix_len, + const struct ip_address *gateway_ip); #endif /* __NET_UTILS_H__ */ diff --git a/gtests/net/packetdrill/netdev.c b/gtests/net/packetdrill/netdev.c index 6dc334d87c726d0db7dadb226ec424bdad0b8ce3..14996281bf2b758e194a81b5148cab5f4377e1e2 100644 --- a/gtests/net/packetdrill/netdev.c +++ b/gtests/net/packetdrill/netdev.c @@ -44,7 +44,14 @@ #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include <net/if_tun.h> #endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ - +#if defined(__APPLE__) +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <net/if.h> +#include <net/if_utun.h> +#include <sys/kern_control.h> +#include <sys/kern_event.h> +#endif #include "ip.h" #include "ipv6.h" #include "logging.h" @@ -119,6 +126,52 @@ static void check_remote_address(struct config *config, } /* Create a tun device for the lifetime of this test. */ +#if defined(__APPLE__) +static void create_device(struct config *config, struct local_netdev *netdev) +{ + struct sockaddr_ctl addr; + struct ctl_info info; + char name[IFNAMSIZ]; + char *command; + socklen_t len; + int tun_fd; + + tun_fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL); + if (tun_fd < 0) { + die_perror("open utun device"); + } + memset(&info, 0, sizeof(struct ctl_info)); + strncpy(info.ctl_name, UTUN_CONTROL_NAME, MAX_KCTL_NAME); + if (ioctl(tun_fd, CTLIOCGINFO, &info) < 0) { + die_perror("open utun device"); + } + addr.sc_len = sizeof(struct sockaddr_ctl); + addr.sc_family = AF_SYSTEM; + addr.ss_sysaddr = AF_SYS_CONTROL; + addr.sc_id = info.ctl_id; + addr.sc_unit = 0; + if (connect(tun_fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_ctl)) < 0) { + die_perror("open utun device"); + } + netdev->tun_fd = tun_fd; + len = IFNAMSIZ; + if (getsockopt(tun_fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, name, &len) < 0) { + die_perror("open utun device"); + } + netdev->name = strdup(name); + DEBUGP("utun name: '%s'\n", netdev->name); + netdev->index = if_nametoindex(netdev->name); + if (netdev->index == 0) + die_perror("if_nametoindex"); + DEBUGP("utun index: '%d'\n", netdev->index); + if (config->mtu != TUN_DRIVER_DEFAULT_MTU) { + asprintf(&command, "ifconfig %s mtu %d", netdev->name, config->mtu); + if (system(command) < 0) + die("Error executing %s\n", command); + free(command); + } +} +#else static void create_device(struct config *config, struct local_netdev *netdev) { /* Open the tun device, which "clones" it for our purposes. */ @@ -252,6 +305,7 @@ static void create_device(struct config *config, struct local_netdev *netdev) if (netdev->ipv4_control_fd < 0) die_perror("opening AF_INET, SOCK_DGRAM, IPPROTO_IP socket"); } +#endif /* Set the offload flags to be like a typical ethernet device */ static void set_device_offload_flags(struct local_netdev *netdev) @@ -267,6 +321,7 @@ static void set_device_offload_flags(struct local_netdev *netdev) #endif } +#if !defined(__APPLE__) /* Bring up the device */ static void bring_up_device(struct local_netdev *netdev) { @@ -284,13 +339,14 @@ static void bring_up_device(struct local_netdev *netdev) if (ioctl(netdev->ipv4_control_fd, SIOCSIFFLAGS, &ifr) < 0) die_perror("SIOCSIFFLAGS"); } +#endif /* Route traffic destined for our remote IP through this device */ static void route_traffic_to_device(struct config *config, struct local_netdev *netdev) { char *route_command = NULL; -#ifdef linux +#if defined(linux) asprintf(&route_command, "ip route del %s > /dev/null 2>&1 ; " "ip route add %s dev %s via %s > /dev/null 2>&1", @@ -298,8 +354,7 @@ static void route_traffic_to_device(struct config *config, config->live_remote_prefix_string, netdev->name, config->live_gateway_ip_string); -#endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#else if (config->wire_protocol == AF_INET) { asprintf(&route_command, "route delete %s > /dev/null 2>&1 ; " @@ -317,7 +372,7 @@ static void route_traffic_to_device(struct config *config, } else { assert(!"bad wire protocol"); } -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ +#endif /* defined(linux) */ int result = system(route_command); if ((result == -1) || (WEXITSTATUS(result) != 0)) { die("error executing route command '%s'\n", @@ -337,14 +392,21 @@ struct netdev *local_netdev_new(struct config *config) check_remote_address(config, netdev); create_device(config, netdev); set_device_offload_flags(netdev); +#if !defined(__APPLE__) bring_up_device(netdev); +#endif net_setup_dev_address(netdev->name, &config->live_local_ip, - config->live_prefix_len); + config->live_prefix_len, + &config->live_gateway_ip); route_traffic_to_device(config, netdev); netdev->psock = packet_socket_new(netdev->name); + /* Make sure we only see packets from the machine under test. */ + packet_socket_set_filter(netdev->psock, + NULL, + &config->live_local_ip); /* client IP */ return (struct netdev *)netdev; } @@ -379,7 +441,7 @@ static void local_netdev_free(struct netdev *a_netdev) free(netdev); } -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) /* According to `man 4 tun` on OpenBSD: "Each packet read or written * is prefixed with a tunnel header consisting of a 4-byte network * byte order integer containing the address family in the case of @@ -400,7 +462,7 @@ static void bsd_tun_write(struct local_netdev *netdev, if (writev(netdev->tun_fd, vector, ARRAY_SIZE(vector)) < 0) die_perror("BSD tun write()"); } -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ +#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) */ #ifdef linux static void linux_tun_write(struct local_netdev *netdev, @@ -425,9 +487,9 @@ static int local_netdev_send(struct netdev *a_netdev, DEBUGP("local_netdev_send\n"); -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) bsd_tun_write(netdev, packet); -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ +#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) */ #ifdef linux linux_tun_write(netdev, packet); diff --git a/gtests/net/packetdrill/packet_socket_pcap.c b/gtests/net/packetdrill/packet_socket_pcap.c index 1e2bd210e5147272450d6486107e4e869f5ac4fe..568aef97147d9842e0cb877100995c6839c39c11 100644 --- a/gtests/net/packetdrill/packet_socket_pcap.c +++ b/gtests/net/packetdrill/packet_socket_pcap.c @@ -35,7 +35,7 @@ #ifdef USE_LIBPCAP -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__APPLE__) #include <pcap/pcap.h> #elif defined(__OpenBSD__) || defined(__NetBSD__) #include <pcap.h> @@ -47,9 +47,8 @@ struct packet_socket { char *name; /* malloc-allocated copy of interface name */ - pcap_t *pcap_in; /* handle for sniffing incoming packets */ - pcap_t *pcap_out; /* handle for sniffing outgoing packets */ - /* also used for sending packets */ + pcap_t *pcap; /* handle for sniffing packets sent by the SUT */ + /* also used for sending packets */ char pcap_error[PCAP_ERRBUF_SIZE]; /* for libpcap errors */ int pcap_offset; /* offset of packet data in pcap buffer */ int data_link; @@ -64,75 +63,40 @@ static inline s64 bpf_timeval_to_usecs(const struct bpf_timeval *tv) } #endif /* defined(__OpenBSD__) */ -/* Call pcap_perror() and then exit with a failure status code. */ -extern void die_pcap_perror(pcap_t *pcap, char *message) -{ - pcap_perror(pcap, message); - - exit(EXIT_FAILURE); -} - static void packet_socket_setup(struct packet_socket *psock) { - int bpf_fd = -1, val = -1; + char *devname; + int result; DEBUGP("calling pcap_create() with %s\n", psock->name); - psock->pcap_in = pcap_create(psock->name, psock->pcap_error); - if (psock->pcap_in == NULL) - die_pcap_perror(psock->pcap_in, "pcap_create"); - psock->pcap_out = pcap_create(psock->name, psock->pcap_error); - if (psock->pcap_out == NULL) - die_pcap_perror(psock->pcap_out, "pcap_create"); - - if (pcap_set_snaplen(psock->pcap_in, PACKET_READ_BYTES) != 0) - die_pcap_perror(psock->pcap_in, "pcap_set_snaplen"); - if (pcap_set_snaplen(psock->pcap_out, PACKET_READ_BYTES) != 0) - die_pcap_perror(psock->pcap_out, "pcap_set_snaplen"); - - if (pcap_activate(psock->pcap_in) != 0) - die_pcap_perror(psock->pcap_in, - "pcap_activate " - "(OpenBSD: another process (tcpdump?) " - "using bpf0?)"); - if (pcap_activate(psock->pcap_out) != 0) - die_pcap_perror(psock->pcap_out, - "pcap_activate " - "(OpenBSD: another process (tcpdump?) " - "using bpf0?)"); - - if (pcap_setdirection(psock->pcap_in, PCAP_D_IN) != 0) - die_pcap_perror(psock->pcap_in, "pcap_setdirection"); - if (pcap_setdirection(psock->pcap_out, PCAP_D_OUT) != 0) - die_pcap_perror(psock->pcap_out, "pcap_setdirection"); - - bpf_fd = pcap_get_selectable_fd(psock->pcap_in); - if (bpf_fd < 0) - die_pcap_perror(psock->pcap_in, "pcap_get_selectable_fd"); - - /* By default libpcap with BPF waits until a read buffer fills - * up before returning any packets. We use BIOCIMMEDIATE to - * force the BPF device to return the first packet - * immediately. - */ - val = 1; - if (ioctl(bpf_fd, BIOCIMMEDIATE, &val) < 0) - die_perror("ioctl BIOCIMMEDIATE on bpf fd"); - bpf_fd = pcap_get_selectable_fd(psock->pcap_out); - if (bpf_fd < 0) - die_pcap_perror(psock->pcap_out, "pcap_get_selectable_fd"); - - /* By default libpcap with BPF waits until a read buffer fills - * up before returning any packets. We use BIOCIMMEDIATE to - * force the BPF device to return the first packet - * immediately. - */ - val = 1; - if (ioctl(bpf_fd, BIOCIMMEDIATE, &val) < 0) - die_perror("ioctl BIOCIMMEDIATE on bpf fd"); - - /* Find data link type. */ - psock->data_link = pcap_datalink(psock->pcap_in); - DEBUGP("data_link: %d\n", psock->data_link); +#if defined(__APPLE__) + asprintf(&devname, "pktap,%s", psock->name); +#else + asprintf(&devname, "%s", psock->name); +#endif + psock->pcap = pcap_create(devname, psock->pcap_error); + free(devname); + if (psock->pcap == NULL) + die("%s: %s\n", "pcap_create", psock->pcap_error); + /* The following two calls MUST be called before activating + * the handle. Then they are not failing. */ + result = pcap_set_snaplen(psock->pcap, PACKET_READ_BYTES); + if (result != 0) + die("%s: %s\n", "pcap_set_snaplen", pcap_statustostr(result)); + result = pcap_set_immediate_mode(psock->pcap, 1); + if (result != 0) + die("%s: %s\n", "pcap_set_immediate_mode", pcap_statustostr(result)); + result = pcap_activate(psock->pcap); + if (result != 0) { + if (result == PCAP_WARNING || result == PCAP_ERROR) + die("%s: %s\n", "pcap_activate", pcap_geterr(psock->pcap)); + else + die("%s: %s\n", "pcap_activate", pcap_statustostr(result)); + } + psock->data_link = pcap_datalink(psock->pcap); + DEBUGP("data_link: %d (DLT_%s)\n", + psock->data_link, + pcap_datalink_val_to_name(psock->data_link)); /* Based on the data_link type, calculate the offset of the * packet data in the buffer. @@ -145,8 +109,14 @@ static void packet_socket_setup(struct packet_socket *psock) case DLT_NULL: psock->pcap_offset = sizeof(u32); break; + case DLT_RAW: + /* Used on MacOS when using pktap. */ + psock->pcap_offset = 0; + break; default: - die("Unknown data_link type %d\n", psock->data_link); + die("Unknown data_link type %d (DLT_%s)\n", + psock->data_link, + pcap_datalink_val_to_name(psock->data_link)); break; } } @@ -163,28 +133,28 @@ void packet_socket_set_filter(struct packet_socket *psock, ip_to_string(client_live_ip, client_live_ip_string); - asprintf(&filter_str, - "ether src %02x:%02x:%02x:%02x:%02x:%02x and %s src %s", - client_ether[0], - client_ether[1], - client_ether[2], - client_ether[3], - client_ether[4], - client_ether[5], - client_live_ip->address_family == AF_INET6 ? "ip6" : "ip", - client_live_ip_string); - + if (client_ether_addr != NULL) + asprintf(&filter_str, + "ether src %02x:%02x:%02x:%02x:%02x:%02x and %s src %s", + client_ether[0], + client_ether[1], + client_ether[2], + client_ether[3], + client_ether[4], + client_ether[5], + client_live_ip->address_family == AF_INET6 ? "ip6" : "ip", + client_live_ip_string); + else + asprintf(&filter_str, + "%s src %s", + client_live_ip->address_family == AF_INET6 ? "ip6" : "ip", + client_live_ip_string); DEBUGP("setting BPF filter: %s\n", filter_str); - if (pcap_compile(psock->pcap_in, &bpf_code, filter_str, 1, 0) != 0) - die_pcap_perror(psock->pcap_in, "pcap_compile"); - if (pcap_setfilter(psock->pcap_in, &bpf_code) != 0) - die_pcap_perror(psock->pcap_in, "pcap_setfilter"); - pcap_freecode(&bpf_code); - if (pcap_compile(psock->pcap_out, &bpf_code, filter_str, 1, 0) != 0) - die_pcap_perror(psock->pcap_out, "pcap_compile"); - if (pcap_setfilter(psock->pcap_out, &bpf_code) != 0) - die_pcap_perror(psock->pcap_out, "pcap_setfilter"); + if (pcap_compile(psock->pcap, &bpf_code, filter_str, 1, 0) != 0) + die("%s: %s\n", "pcap_compile", pcap_geterr(psock->pcap)); + if (pcap_setfilter(psock->pcap, &bpf_code) != 0) + die("%s: %s\n", "pcap_setfilter", pcap_geterr(psock->pcap)); pcap_freecode(&bpf_code); free(filter_str); } @@ -205,8 +175,7 @@ void packet_socket_free(struct packet_socket *psock) if (psock->name != NULL) free(psock->name); - pcap_close(psock->pcap_in); - pcap_close(psock->pcap_out); + pcap_close(psock->pcap); memset(psock, 0, sizeof(*psock)); /* paranoia to catch bugs*/ free(psock); @@ -220,7 +189,7 @@ int packet_socket_writev(struct packet_socket *psock, */ u8 *buf = NULL, *p = NULL; - int len = 0, i = 0; + int len = 0, i = 0, result; /* Calculate how much space we need. */ for (i = 0; i < iovcnt; ++i) @@ -237,8 +206,11 @@ int packet_socket_writev(struct packet_socket *psock, DEBUGP("calling pcap_inject with %d bytes\n", len); - if (pcap_inject(psock->pcap_out, buf, len) != len) - die_pcap_perror(psock->pcap_out, "pcap_inject"); + result = pcap_inject(psock->pcap, buf, len); + if (result == -1) + die("%s: %s\n", "pcap_inject", pcap_geterr(psock->pcap)); + if (result !=len) + die("%s: wrote %d bytes instead of %d\n", "pcap_inject", result, len); free(buf); return STATUS_OK; @@ -251,18 +223,13 @@ int packet_socket_receive(struct packet_socket *psock, int status = 0; struct pcap_pkthdr *pkt_header = NULL; const u8 *pkt_data = NULL; - pcap_t *pcap; struct ether_header *ether; + u8 version; u32 address_family; DEBUGP("calling pcap_next_ex() for direction %s\n", direction == DIRECTION_INBOUND ? "inbound" : "outbound"); - if (direction == DIRECTION_INBOUND) - pcap = psock->pcap_in; - else - pcap = psock->pcap_out; - /* Something about the way we're doing BIOCIMMEDIATE * causes libpcap to return 0 if there's no packet * yet, which forces us to spin in this loop until @@ -273,13 +240,13 @@ int packet_socket_receive(struct packet_socket *psock, * here. TODO(ncardwell): fix this. */ while (1) { - status = pcap_next_ex(pcap, &pkt_header, &pkt_data); + status = pcap_next_ex(psock->pcap, &pkt_header, &pkt_data); if (status == 1) break; /* got a packet */ else if (status == 0) return STATUS_ERR; /* no packet yet */ else if (status == -1) - die_pcap_perror(pcap, "pcap_next_ex"); + die("%s: %s\n", "pcap_inject", pcap_geterr(psock->pcap)); else if (status == -2) die("pcap_next_ex: EOF in save file?!\n"); else @@ -290,7 +257,7 @@ int packet_socket_receive(struct packet_socket *psock, (u32)pkt_header->ts.tv_sec, (u32)pkt_header->ts.tv_usec); -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) packet->time_usecs = timeval_to_usecs(&pkt_header->ts); #elif defined(__OpenBSD__) packet->time_usecs = bpf_timeval_to_usecs(&pkt_header->ts); @@ -343,6 +310,26 @@ int packet_socket_receive(struct packet_socket *psock, return STATUS_ERR; } break; + case DLT_RAW: +#if __BYTE_ORDER == __LITTLE_ENDIAN + version = (*pkt_data & 0xf0) >> 4; +#elif __BYTE_ORDER == __BIG_ENDIAN + version = *pkt_data & 0x0f; +#else +#error "Please fix endianness defines" +#endif + switch (version) { + case 4: + *ether_type = ETHERTYPE_IP; + break; + case 6: + *ether_type = ETHERTYPE_IPV6; + break; + default: + DEBUGP("Unknown IP version %u (first byte %u).\n", version, *pkt_data); + return STATUS_ERR; + } + break; default: assert(!"not reached"); break; diff --git a/gtests/net/packetdrill/parser.y b/gtests/net/packetdrill/parser.y index db2b43f40de51fc7ce499d78f297eb7aada64cea..d7bd9c1ccb9df55983306ed6f5c5013123e89497 100644 --- a/gtests/net/packetdrill/parser.y +++ b/gtests/net/packetdrill/parser.y @@ -559,7 +559,7 @@ static struct tcp_option *new_tcp_exp_fast_open_option(const char *cookie_string */ %token ELLIPSIS %token <reserved> SA_FAMILY SIN_PORT SIN_ADDR _HTONS_ _HTONL_ INET_ADDR -%token <reserved> MSG_NAME MSG_IOV MSG_FLAGS MSG_CONTROL CMSG_LEN CMSG_LEVEL CMSG_TYPE CMSG_DATA +%token <reserved> MSG_NAME MSG_IOV MSG_FLAGS MSG_CONTROL _CMSG_LEN_ CMSG_LEVEL CMSG_TYPE _CMSG_DATA_ %token <reserved> SF_HDTR_HEADERS SF_HDTR_TRAILERS %token <reserved> FD EVENTS REVENTS ONOFF LINGER %token <reserved> ACK ECR EOL MSS NOP SACK NR_SACK SACKOK TIMESTAMP VAL WIN WSCALE PRO @@ -3093,7 +3093,7 @@ sockaddr struct sockaddr_in *ipv4 = malloc(sizeof(struct sockaddr_in)); memset(ipv4, 0, sizeof(*ipv4)); ipv4->sin_family = AF_INET; -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) ipv4->sin_len = sizeof(*ipv4); #endif ipv4->sin_port = htons($10); @@ -3108,7 +3108,7 @@ sockaddr struct sockaddr_in6 *ipv6 = malloc(sizeof(struct sockaddr_in6)); memset(ipv6, 0, sizeof(*ipv6)); ipv6->sin6_family = AF_INET6; -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) ipv6->sin6_len = sizeof(*ipv6); #endif ipv6->sin6_port = htons($10); @@ -3188,19 +3188,19 @@ cmsg_type ; cmsg_data -: CMSG_DATA '=' sctp_initmsg { $$ = $3; } -| CMSG_DATA '=' sctp_sndrcvinfo { $$ = $3; } -| CMSG_DATA '=' sctp_extrcvinfo { $$ = $3; } -| CMSG_DATA '=' sctp_sndinfo { $$ = $3; } -| CMSG_DATA '=' sctp_rcvinfo { $$ = $3; } -| CMSG_DATA '=' sctp_nxtinfo { $$ = $3; } -| CMSG_DATA '=' sctp_prinfo { $$ = $3; } -| CMSG_DATA '=' sctp_authinfo { $$ = $3; } -| CMSG_DATA '=' sockaddr { $$ = $3; } +: _CMSG_DATA_ '=' sctp_initmsg { $$ = $3; } +| _CMSG_DATA_ '=' sctp_sndrcvinfo { $$ = $3; } +| _CMSG_DATA_ '=' sctp_extrcvinfo { $$ = $3; } +| _CMSG_DATA_ '=' sctp_sndinfo { $$ = $3; } +| _CMSG_DATA_ '=' sctp_rcvinfo { $$ = $3; } +| _CMSG_DATA_ '=' sctp_nxtinfo { $$ = $3; } +| _CMSG_DATA_ '=' sctp_prinfo { $$ = $3; } +| _CMSG_DATA_ '=' sctp_authinfo { $$ = $3; } +| _CMSG_DATA_ '=' sockaddr { $$ = $3; } ; cmsghdr -: '{' CMSG_LEN '=' INTEGER ',' cmsg_level ',' cmsg_type ',' cmsg_data '}' { +: '{' _CMSG_LEN_ '=' INTEGER ',' cmsg_level ',' cmsg_type ',' cmsg_data '}' { $$ = new_expression(EXPR_CMSGHDR); $$->value.cmsghdr = calloc(1, sizeof(struct cmsghdr_expr)); if (!is_valid_s32($4)) { diff --git a/gtests/net/packetdrill/platforms.h b/gtests/net/packetdrill/platforms.h index 27705d35fb8516cf6f58d594385bf53b27b9d74e..e277272b1d87deed9569448634451f3a916b9d52 100644 --- a/gtests/net/packetdrill/platforms.h +++ b/gtests/net/packetdrill/platforms.h @@ -102,5 +102,20 @@ #endif /* __NetBSD__ */ +/* ------------------------- Darwin --------------------- */ + +#if defined(__APPLE__) + +#if defined(HAVE_SCTP) +#include <sys/types.h> +#include <netinet/sctp.h> +#endif +#define USE_LIBPCAP 1 +#define HAVE_TCP_INFO 1 +#define HAVE_FMEMOPEN 1 +#define HAVE_OPEN_MEMSTREAM 1 + +#endif /* __APPLE__ */ + #endif /* __PLATFORMS_H__ */ diff --git a/gtests/net/packetdrill/run.c b/gtests/net/packetdrill/run.c index f5170a9725cbe7f5c81db5bd73af6731add98d90..f079e185a624c57d07dc0e80d8bf9356449e105c 100644 --- a/gtests/net/packetdrill/run.c +++ b/gtests/net/packetdrill/run.c @@ -332,7 +332,7 @@ void wait_for_event(struct state *state) * that we know has a fine-grained usleep(), then * usleep() instead of spinning on the CPU. */ -#if defined(linux) +#if defined(linux) || defined(__APPLE__) /* Since the scheduler may not wake us up precisely * when we tell it to, sleep until just before the * event we're waiting for and then spin. @@ -439,7 +439,7 @@ void set_scheduling_priority(void) if (num_cpus <= 1) return; -#if !defined(__OpenBSD__) +#if !defined(__OpenBSD__) && !defined(__APPLE__) /* Chose a real-time policy, but use SCHED_RR instead of * SCHED_FIFO, so that we round-robin among real-time threads * of the same priority. In practice this shouldn't matter, @@ -458,7 +458,7 @@ void set_scheduling_priority(void) param.sched_priority = priority; if (sched_setscheduler(0, policy, ¶m)) die_perror("sched_setscheduler"); -#endif /* !defined(__OpenBSD__) */ +#endif /* !defined(__OpenBSD__) && !defined(__APPLE__) */ } /* To ensure timing that's as consistent as possible, pull all our @@ -466,8 +466,10 @@ void set_scheduling_priority(void) */ void lock_memory(void) { +#if !defined(__APPLE__) if (mlockall(MCL_CURRENT | MCL_FUTURE)) die_perror("lockall(MCL_CURRENT | MCL_FUTURE)"); +#endif } /* Wait for and return the wall time at which we should start the diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c index 8a48a8fd6a0853e076508951f5b050256e1eedff..68cc766c0ce079bec10a2ae1406dc4ebf8dd4926 100644 --- a/gtests/net/packetdrill/run_system_call.c +++ b/gtests/net/packetdrill/run_system_call.c @@ -57,6 +57,10 @@ #if defined(linux) #include <sys/sendfile.h> #endif +#if defined(__APPLE__) +#include <pthread.h> +#include <mach/mach.h> +#endif #include <time.h> #include <unistd.h> #include "logging.h" @@ -72,7 +76,7 @@ struct sctp_tlv { u32 sn_length; }; #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_notification(struct socket *socket, struct iovec *iov, struct expression *iovec_expr, char **error); static int parse_expression_to_sctp_initmsg(struct expression *expr, struct sctp_initmsg *init, @@ -80,7 +84,7 @@ static int parse_expression_to_sctp_initmsg(struct expression *expr, struct sctp static int parse_expression_to_sctp_sndrcvinfo(struct expression *expr, struct sctp_sndrcvinfo *info, bool send, char **error); #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int parse_expression_to_sctp_sndinfo(struct expression *expr, struct sctp_sndinfo *info, char **error); static int parse_expression_to_sctp_prinfo(struct expression *expr, struct sctp_prinfo *info, @@ -96,19 +100,19 @@ static int check_sctp_sndinfo(struct sctp_sndinfo_expr *expr, struct sctp_sndinf static int check_sctp_initmsg(struct sctp_initmsg_expr *expr, struct sctp_initmsg *sctp_initmsg, char **error); #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_extrcvinfo(struct sctp_extrcvinfo_expr *expr, struct sctp_extrcvinfo *sctp_info, char **error); #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_rcvinfo(struct sctp_rcvinfo_expr *expr, struct sctp_rcvinfo *sctp_rcvinfo, char** error); #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_nxtinfo(struct sctp_nxtinfo_expr *expr, struct sctp_nxtinfo *sctp_nxtinfo, char **error); #endif -#if defined(linux) || defined(__FreeBSD__) +#if defined(linux) || defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_sndrcvinfo(struct sctp_sndrcvinfo_expr *expr, struct sctp_sndrcvinfo *sctp_sndrcvinfo, char** error); @@ -203,6 +207,49 @@ static bool is_thread_sleeping(pid_t process_id, int thread_id) procstat_close(procstat); return is_sleeping; } +#elif defined(__APPLE__) +static bool is_thread_sleeping(pid_t process_id, mach_port_t port) +{ + thread_info_data_t thinfo; + thread_basic_info_t basic_info_th; + mach_msg_type_number_t thread_info_count; + kern_return_t kr; + bool is_sleeping; + + thread_info_count = THREAD_INFO_MAX; + kr = thread_info(port, THREAD_BASIC_INFO, (thread_info_t)thinfo, &thread_info_count); + if (kr != KERN_SUCCESS) { + die("task_threads(): %s\n", mach_error_string(kr)); + } + basic_info_th = (thread_basic_info_t)thinfo; + switch (basic_info_th->run_state) { + case TH_STATE_RUNNING: + DEBUGP("run_state = TH_STATE_RUNNING\n"); + is_sleeping = false; + break; + case TH_STATE_STOPPED: + DEBUGP("run_state = TH_STATE_STOPPED\n"); + is_sleeping = false; + break; + case TH_STATE_WAITING: + DEBUGP("run_state = TH_STATE_WAITING\n"); + is_sleeping = true; + break; + case TH_STATE_UNINTERRUPTIBLE: + DEBUGP("run_state = TH_STATE_UNINTERRUPTIBLE\n"); + is_sleeping = true; + break; + case TH_STATE_HALTED: + DEBUGP("run_state = TH_STATE_HALTED\n"); + is_sleeping = false; + break; + default: + die("Unknown thread state: %d\n", basic_info_th->run_state); + is_sleeping = false; + break; + } + return is_sleeping; +} #else static bool is_thread_sleeping(pid_t process_id, int thread_id) { @@ -304,7 +351,7 @@ static int get_socklen_t(struct expression *expression, return STATUS_OK; } -#if defined(linux) || defined(__FreeBSD__) +#if defined(linux) || defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) /* Sets the value from the expression argument, checking that it is a * valid size_t, and matches the expected type. Returns STATUS_OK on * success; on failure returns STATUS_ERR and sets error message. @@ -346,7 +393,7 @@ static int get_off_t(struct expression *expression, } #endif -#if defined(linux) || defined(__FreeBSD__) +#if defined(linux) || defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) /* Sets the value from the expression argument, checking that it is a * valid sctp_assoc_t, and matches the expected type. Returns STATUS_OK on * success; on failure returns STATUS_ERR and sets error message. @@ -537,7 +584,7 @@ static int s32_bracketed_arg(struct expression_list *args, /* Return the value of the argument with the given index, and verify * that it has the expected type: a list with a single integer. */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int u32_bracketed_arg(struct expression_list *args, int index, u32 *value, char **error) { @@ -557,7 +604,9 @@ static int u32_bracketed_arg(struct expression_list *args, } return get_u32(list->expression, value, error); } +#endif +#if defined(__FreeBSD__) static int off_t_bracketed_arg(struct expression_list *args, int index, off_t *value, char **error) { @@ -636,7 +685,7 @@ static int get_sockstorage_arg(struct expression *arg, struct sockaddr_storage * } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sockaddr(struct expression *sockaddr_expr, struct sockaddr *live_addr, char **error) { if (sockaddr_expr->type != EXPR_ELLIPSIS) { @@ -701,7 +750,7 @@ static int check_sockaddr(struct expression *sockaddr_expr, struct sockaddr *liv } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int check_u8_expr(struct expression *expr, u8 value, char *val_name, char **error) { if (expr->type != EXPR_ELLIPSIS) { u8 script_val; @@ -718,7 +767,7 @@ int check_u8_expr(struct expression *expr, u8 value, char *val_name, char **erro } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) #ifdef SCTP_REMOTE_UDP_ENCAPS_PORT int check_u16_htons_expr(struct expression *expr, u16 value, char *val_name, char **error) { if (expr->type != EXPR_ELLIPSIS) { @@ -799,7 +848,7 @@ int check_u32_expr(struct expression *expr, u32 value, char *val_name, char **er return STATUS_OK; } -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int check_sctp_assoc_t_expr(struct expression *expr, sctp_assoc_t value, char *val_name, char **error) { if (expr->type != EXPR_ELLIPSIS) { sctp_assoc_t script_val; @@ -848,7 +897,7 @@ int check_size_t_expr(struct expression *expr, size_t value, char *val_name, cha } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_u8array_expr(struct expression *expr_list, u8 *data, size_t data_len, char *val_name, char **error) { if ( expr_list->type != EXPR_ELLIPSIS) { struct expression *expr = NULL; @@ -890,7 +939,7 @@ static int check_u8array_expr(struct expression *expr_list, u8 *data, size_t dat } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_u16array_expr(struct expression *expr_list, u16 *data, int data_len, char *val_name, char **error) { if ( expr_list->type != EXPR_ELLIPSIS) { struct expression *expr = NULL; @@ -2004,7 +2053,7 @@ static int run_syscall_connect(struct state *state, return STATUS_OK; } -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int run_syscall_sctp_peeloff(struct state *state, int script_copy_fd, int script_new_fd, @@ -2398,7 +2447,7 @@ static int syscall_recvmsg(struct state *state, struct syscall_spec *syscall, expected_msg_flags, msg->msg_flags); goto error_out; } -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) if (msg->msg_flags & MSG_NOTIFICATION) { struct socket *socket = find_socket_by_script_fd(state, script_fd); if (check_sctp_notification(socket, msg->msg_iov, msg_expression->value.msghdr->msg_iov, error)) @@ -4428,7 +4477,7 @@ static int syscall_setsockopt(struct state *state, struct syscall_spec *syscall, &paddrparams.spp_flags, error)) { return STATUS_ERR; } -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) if (get_u32(val_expression->value.sctp_paddrparams->spp_ipv6_flowlabel, &paddrparams.spp_ipv6_flowlabel, error)) { return STATUS_ERR; @@ -4885,7 +4934,7 @@ error_out: static int syscall_sctp_sendmsg(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int result, script_fd, live_fd; void *msg = NULL; struct sockaddr_storage to; @@ -4968,7 +5017,7 @@ static int syscall_sctp_sendmsg(struct state *state, struct syscall_spec *syscal #endif } -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_sndrcvinfo(struct sctp_sndrcvinfo_expr *expr, struct sctp_sndrcvinfo *sctp_sndrcvinfo, char** error) { @@ -5004,7 +5053,7 @@ static int check_sctp_sndrcvinfo(struct sctp_sndrcvinfo_expr *expr, } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_extrcvinfo(struct sctp_extrcvinfo_expr *expr, struct sctp_extrcvinfo *sctp_extrcvinfo, char** error) { @@ -5083,7 +5132,7 @@ static int syscall_sctp_recvmsg(struct state *state, struct syscall_spec *syscal struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int script_fd, live_fd, live_msg_flags = 0, result; void *msg; u32 len; @@ -5146,7 +5195,7 @@ static int syscall_sctp_recvmsg(struct state *state, struct syscall_spec *syscal #endif } -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int parse_expression_to_sctp_initmsg(struct expression *expr, struct sctp_initmsg *init, char **error) { if (expr->type == EXPR_SCTP_INITMSG) { struct sctp_initmsg_expr *init_expr = expr->value.sctp_initmsg; @@ -5275,7 +5324,7 @@ static int parse_expression_to_sctp_sndrcvinfo(struct expression *expr, } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int parse_expression_to_sctp_sndinfo(struct expression *expr, struct sctp_sndinfo *info, char **error) { if (expr->type == EXPR_SCTP_SNDINFO) { struct sctp_sndinfo_expr *sndinfo_expr = expr->value.sctp_sndinfo; @@ -5355,7 +5404,7 @@ static int parse_expression_to_sctp_sendv_spa(struct expression *expr, struct sc } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int get_sockaddr_from_list(struct expression *expr, size_t *addr_size, struct sockaddr **addrs, char **error) { if (expr->type == EXPR_LIST) { struct expression_list *addrs_expr_list = (struct expression_list *)expr->value.list; @@ -5408,7 +5457,7 @@ static int syscall_sctp_send(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int script_fd, live_fd, flags, result; size_t len; void *msg; @@ -5463,7 +5512,7 @@ static int syscall_sctp_sendx(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) { -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) int script_fd, live_fd, flags, addrcnt, result; size_t len; void *msg = NULL; @@ -5546,7 +5595,7 @@ static int syscall_sctp_sendv(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) { -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) int script_fd, live_fd, iovcnt, addrcnt, result, flags; u32 infotype; size_t script_iovec_list_len = 0; @@ -5666,7 +5715,7 @@ error_out: #endif } -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_rcvinfo(struct sctp_rcvinfo_expr *expr, struct sctp_rcvinfo *sctp_rcvinfo, char **error) @@ -5696,7 +5745,7 @@ static int check_sctp_rcvinfo(struct sctp_rcvinfo_expr *expr, } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_nxtinfo(struct sctp_nxtinfo_expr *expr, struct sctp_nxtinfo *sctp_nxtinfo, char **error) @@ -5721,7 +5770,7 @@ static int check_sctp_nxtinfo(struct sctp_nxtinfo_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_assoc_change(struct sctp_assoc_change_expr *expr, struct sctp_assoc_change *sctp_event, char **error) { @@ -5757,7 +5806,7 @@ static int check_sctp_assoc_change(struct sctp_assoc_change_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_paddr_change(struct sctp_paddr_change_expr *expr, struct sctp_paddr_change *sctp_event, char **error) { @@ -5787,7 +5836,7 @@ static int check_sctp_paddr_change(struct sctp_paddr_change_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_remote_error(struct sctp_remote_error_expr *expr, struct sctp_remote_error *sctp_event, char **error) { @@ -5814,7 +5863,7 @@ static int check_sctp_remote_error(struct sctp_remote_error_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_send_failed(struct sctp_send_failed_expr *expr, struct sctp_send_failed *sctp_event, char **error) { @@ -5847,7 +5896,7 @@ static int check_sctp_send_failed(struct sctp_send_failed_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_shutdown_event(struct sctp_shutdown_event_expr *expr, struct sctp_shutdown_event *sctp_event, char **error) { @@ -5869,7 +5918,7 @@ static int check_sctp_shutdown_event(struct sctp_shutdown_event_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_adaptation_event(struct sctp_adaptation_event_expr *expr, struct sctp_adaptation_event *sctp_event, char **error) { @@ -5894,7 +5943,7 @@ static int check_sctp_adaptation_event(struct sctp_adaptation_event_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_pdapi_event(struct sctp_pdapi_event_expr *expr, struct sctp_pdapi_event *sctp_event, char **error) { @@ -5939,7 +5988,7 @@ static int check_sctp_pdapi_event(struct sctp_pdapi_event_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_authkey_event(struct sctp_authkey_event_expr *expr, struct sctp_authkey_event *sctp_event, char **error) { @@ -5967,7 +6016,7 @@ static int check_sctp_authkey_event(struct sctp_authkey_event_expr *expr, } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_sender_dry_event(struct sctp_sender_dry_event_expr *expr, struct sctp_sender_dry_event *sctp_event, char **error) { @@ -5989,7 +6038,7 @@ static int check_sctp_sender_dry_event(struct sctp_sender_dry_event_expr *expr, } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_send_failed_event(struct sctp_send_failed_event_expr *expr, struct sctp_send_failed_event *sctp_event, char **error) { @@ -6021,7 +6070,7 @@ static int check_sctp_send_failed_event(struct sctp_send_failed_event_expr *expr } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_tlv(struct sctp_tlv_expr *expr, struct sctp_tlv *sctp_tlv, char **error) { if (check_u16_expr(expr->sn_type, sctp_tlv->sn_type, "sctp_tlv.sn_type", error)) @@ -6036,7 +6085,7 @@ static int check_sctp_tlv(struct sctp_tlv_expr *expr, struct sctp_tlv *sctp_tlv, } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_stream_reset_event(struct sctp_stream_reset_event_expr *expr, struct sctp_stream_reset_event *sctp_stream_reset_event, char **error) { @@ -6061,7 +6110,7 @@ static int check_sctp_stream_reset_event(struct sctp_stream_reset_event_expr *ex } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_assoc_reset_event(struct socket *socket, struct sctp_assoc_reset_event_expr *expr, struct sctp_assoc_reset_event *sctp_assoc_reset_event, char **error) { @@ -6095,7 +6144,7 @@ static int check_sctp_assoc_reset_event(struct socket *socket, struct sctp_assoc } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_stream_change_event(struct sctp_stream_change_event_expr *expr, struct sctp_stream_change_event *sctp_stream_change_event, char **error) { @@ -6122,7 +6171,7 @@ static int check_sctp_stream_change_event(struct sctp_stream_change_event_expr * } #endif -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_notification(struct socket *socket, struct iovec *iov, struct expression *iovec_expr, @@ -6195,7 +6244,7 @@ static int check_sctp_notification(struct socket *socket, error)) return STATUS_ERR; break; -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) case EXPR_SCTP_SEND_FAILED_EVENT: if (check_sctp_send_failed_event(script_iov_base->value.sctp_send_failed_event, (struct sctp_send_failed_event *) iov[i].iov_base, @@ -6209,7 +6258,7 @@ static int check_sctp_notification(struct socket *socket, error)) return STATUS_ERR; break; -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) case EXPR_SCTP_STREAM_RESET_EVENT: if (check_sctp_stream_reset_event(script_iov_base->value.sctp_stream_reset_event, (struct sctp_stream_reset_event *) iov[i].iov_base, @@ -6217,7 +6266,7 @@ static int check_sctp_notification(struct socket *socket, return STATUS_ERR; break; #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) case EXPR_SCTP_ASSOC_RESET_EVENT: if (check_sctp_assoc_reset_event(socket, script_iov_base->value.sctp_assoc_reset_event, (struct sctp_assoc_reset_event *) iov[i].iov_base, @@ -6225,7 +6274,7 @@ static int check_sctp_notification(struct socket *socket, return STATUS_ERR; break; #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) case EXPR_SCTP_STREAM_CHANGE_EVENT: if (check_sctp_stream_change_event(script_iov_base->value.sctp_stream_change_event, (struct sctp_stream_change_event *) iov[i].iov_base, @@ -6248,7 +6297,7 @@ static int check_sctp_notification(struct socket *socket, } #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) static int check_sctp_recvv_rn(struct sctp_recvv_rn_expr *expr, struct sctp_recvv_rn *sctp_recvv_rn, char **error) @@ -6275,7 +6324,7 @@ static int syscall_sctp_recvv(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) { -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(HAVE_SCTP)) int flags, iovlen, script_fd, live_fd, result; size_t script_iovec_list_len = 0; unsigned int infotype = 0; @@ -6442,7 +6491,7 @@ static int syscall_sctp_bindx(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int live_fd, script_fd, addrcnt, flags, result; struct sockaddr_storage addrs; struct expression *addr_list; @@ -6487,7 +6536,7 @@ static int syscall_sctp_bindx(struct state *state, struct syscall_spec *syscall, static int syscall_sctp_connectx(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int live_fd, script_fd, addrcnt, result; struct sockaddr_storage live_addr; struct expression *addrs_expr, *assoc_expr; @@ -6541,7 +6590,7 @@ static int syscall_sctp_peeloff(struct state *state, struct syscall_spec *syscal struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int live_fd, script_fd, result, script_new_fd; sctp_assoc_t assoc_id; struct expression *expr_assoc; @@ -6581,7 +6630,7 @@ static int syscall_sctp_getpaddrs(struct state *state, struct syscall_spec *sysc struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int live_fd, script_fd, result; sctp_assoc_t assoc_id; struct expression *assoc_expr, *addrs_list_expr; @@ -6645,7 +6694,7 @@ static int syscall_sctp_freepaddrs(struct state *state, struct syscall_spec *sys struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) struct expression *addrs_expr; if (check_arg_count(args, 1, error)) return STATUS_ERR; @@ -6666,7 +6715,7 @@ static int syscall_sctp_getladdrs(struct state *state, struct syscall_spec *sysc struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) int live_fd, script_fd, result; sctp_assoc_t assoc_id; struct expression *assoc_expr, *addrs_list_expr; @@ -6730,7 +6779,7 @@ static int syscall_sctp_freeladdrs(struct state *state, struct syscall_spec *sys struct expression_list *args, char **error) { -#if defined(__FreeBSD__) || defined(linux) +#if defined(__FreeBSD__) || defined(linux) || (defined(__APPLE__) && defined(HAVE_SCTP)) struct expression *addrs_expr; if (check_arg_count(args, 1, error)) return STATUS_ERR; @@ -6885,7 +6934,10 @@ static int yield(void) return 0; #elif defined(__NetBSD__) return sched_yield(); -#endif /* defined(__NetBSD__) */ +#elif defined(__APPLE__) + pthread_yield_np(); + return 0; +#endif /* defined(__APPLE__) */ } /* Enqueue the system call for the syscall thread and wake up the thread. */ @@ -6924,6 +6976,8 @@ static void enqueue_system_call( pid_t thread_id; #elif defined(__FreeBSD__) int thread_id; +#elif defined(__APPLE__) + mach_port_t thread_id; #else int thread_id; /* FIXME */ #endif @@ -6984,6 +7038,8 @@ static void *system_call_thread(void *arg) #if defined(__FreeBSD__) pthread_set_name_np(pthread_self(), "syscall thread"); +#elif defined(__APPLE__) + pthread_setname_np("syscall thread"); #endif DEBUGP("syscall thread: starting and locking\n"); run_lock(state); @@ -6994,6 +7050,8 @@ static void *system_call_thread(void *arg) die_perror("gettid"); #elif defined(__FreeBSD__) state->syscalls->thread_id = pthread_getthreadid_np(); +#elif defined(__APPLE__) + state->syscalls->thread_id = pthread_mach_thread_np(pthread_self()); #else state->syscalls->thread_id = 0; /* FIXME */ #endif diff --git a/gtests/net/packetdrill/run_system_call.h b/gtests/net/packetdrill/run_system_call.h index ca30c5bed77ad794e0be11bc9da85e81031199af..340cffaa8e0a22bf846bad4fe8ced1eeec62eade 100644 --- a/gtests/net/packetdrill/run_system_call.h +++ b/gtests/net/packetdrill/run_system_call.h @@ -55,6 +55,8 @@ struct syscalls { pid_t thread_id; /* kernel thread ID */ #elif defined(__FreeBSD__) int thread_id; +#elif defined(__APPLE__) + mach_port_t thread_id; #else int thread_id; /* FIXME */ #endif diff --git a/gtests/net/packetdrill/sctp_packet.c b/gtests/net/packetdrill/sctp_packet.c index b948e3a846ee9672fbc03c2d063fa6df4c16be6e..d74d0dbb70ec7347a2d509f8e3822f3e5697e8cd 100644 --- a/gtests/net/packetdrill/sctp_packet.c +++ b/gtests/net/packetdrill/sctp_packet.c @@ -2628,6 +2628,7 @@ sctp_missing_mandatory_parameter_cause_new(struct sctp_parameter_type_list *list assert((i == list->nr_entries) && (item == NULL)); } else { cause->nr_parameters = htonl(0); + i = 0; /* Just to make the compiler on NetBSD happy. */ } if (padding_length == 2) { cause->parameter_type[i] = htons(0); diff --git a/gtests/net/packetdrill/symbols_darwin.c b/gtests/net/packetdrill/symbols_darwin.c new file mode 100644 index 0000000000000000000000000000000000000000..05cee229e7a5f8e86c899f607cbb6dec01e2599a --- /dev/null +++ b/gtests/net/packetdrill/symbols_darwin.c @@ -0,0 +1,632 @@ +/* + * Copyright 2013 Google Inc. + * Copyright 2018 Michael Tuexen + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ +/* + * Author: tuexen@fh-muenster.de (Michael Tuexen) + * + * Definitions of strace-style symbols for FreeBSD. + * Allows us to map from symbolic strings to integers for system call inputs. + */ + +#if defined(__APPLE__) + +#include "symbols.h" + +#include <errno.h> +#include <fcntl.h> +#include <netinet/in.h> +#include <netinet/udp.h> +#include <poll.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/unistd.h> + +#include "tcp.h" + +/* A table of platform-specific string->int mappings. */ +struct int_symbol platform_symbols_table[] = { + + /* /usr/include/sys/socket.h */ + { SO_DEBUG, "SO_DEBUG" }, + { SO_ACCEPTCONN, "SO_ACCEPTCONN" }, + { SO_REUSEADDR, "SO_REUSEADDR" }, + { SO_KEEPALIVE, "SO_KEEPALIVE" }, + { SO_DONTROUTE, "SO_DONTROUTE" }, + { SO_BROADCAST, "SO_BROADCAST" }, + { SO_USELOOPBACK, "SO_USELOOPBACK" }, + { SO_LINGER, "SO_LINGER" }, + { SO_OOBINLINE, "SO_OOBINLINE" }, + { SO_REUSEPORT, "SO_REUSEPORT" }, + { SO_TIMESTAMP, "SO_TIMESTAMP" }, + { SO_TIMESTAMP_MONOTONIC, "SO_TIMESTAMP_MONOTONIC" }, + { SO_DONTTRUNC, "SO_DONTTRUNC" }, + { SO_WANTMORE, "SO_WANTMORE" }, + { SO_WANTOOBFLAG, "SO_WANTOOBFLAG" }, + { SO_SNDBUF, "SO_SNDBUF" }, + { SO_RCVBUF, "SO_RCVBUF" }, + { SO_SNDLOWAT, "SO_SNDLOWAT" }, + { SO_RCVLOWAT, "SO_RCVLOWAT" }, + { SO_SNDTIMEO, "SO_SNDTIMEO" }, + { SO_RCVTIMEO, "SO_RCVTIMEO" }, + { SO_ERROR, "SO_ERROR" }, + { SO_TYPE, "SO_TYPE" }, + { SO_LABEL, "SO_LABEL" }, + { SO_PEERLABEL, "SO_PEERLABEL" }, + { SO_NREAD, "SO_NREAD" }, + { SO_NKE, "SO_NKE" }, + { SO_NOSIGPIPE, "SO_NOSIGPIPE" }, + { SO_NOADDRERR, "SO_NOADDRERR" }, + { SO_NWRITE, "SO_NWRITE" }, + { SO_REUSESHAREUID, "SO_REUSESHAREUID" }, + { SO_LINGER_SEC, "SO_LINGER_SEC" }, + { SO_RANDOMPORT, "SO_RANDOMPORT" }, + { SO_NP_EXTENSIONS, "SO_NP_EXTENSIONS" }, + { SO_NUMRCVPKT, "SO_NUMRCVPKT" }, + + /* /usr/include/netinet/in.h */ + { IP_OPTIONS, "IP_OPTIONS" }, + { IP_HDRINCL, "IP_HDRINCL" }, + { IP_TOS, "IP_TOS" }, + { IP_TTL, "IP_TTL" }, + { IP_RECVOPTS, "IP_RECVOPTS" }, + { IP_RECVRETOPTS, "IP_RECVRETOPTS" }, + { IP_RECVDSTADDR, "IP_RECVDSTADDR" }, + { IP_RETOPTS, "IP_RETOPTS" }, + { IP_PORTRANGE, "IP_PORTRANGE" }, + { IP_RECVIF, "IP_RECVIF" }, + { IP_RECVTTL, "IP_RECVTTL" }, + { IP_PKTINFO, "IP_PKTINFO," }, + { IP_RECVPKTINFO, "IP_RECVPKTINFO" }, + { IP_RECVTOS, "IP_RECVTOS" }, + + /* /usr/include/netinet6/in6.h */ + { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" }, + { IPV6_PORTRANGE, "IPV6_PORTRANGE" }, + { ICMP6_FILTER, "ICMP6_FILTER" }, + { IPV6_2292PKTINFO, "IPV6_2292PKTINFO" }, + { IPV6_2292HOPLIMIT, "IPV6_2292HOPLIMIT" }, + { IPV6_2292NEXTHOP, "IPV6_2292NEXTHOP" }, + { IPV6_2292HOPOPTS, "IPV6_2292HOPOPTS" }, + { IPV6_2292DSTOPTS, "IPV6_2292DSTOPTS" }, + { IPV6_2292RTHDR, "IPV6_2292RTHDR" }, + { IPV6_2292PKTOPTIONS, "IPV6_2292PKTOPTIONS" }, + { IPV6_CHECKSUM, "IPV6_CHECKSUM" }, + { IPV6_V6ONLY, "IPV6_V6ONLY" }, + { IPV6_BINDV6ONLY, "IPV6_BINDV6ONLY" }, + { IPV6_RECVTCLASS, "IPV6_RECVTCLASS" }, + { IPV6_TCLASS, "IPV6_TCLASS" }, + { IPV6_RTHDRDSTOPTS, "IPV6_RTHDRDSTOPTS" }, + { IPV6_RECVPKTINFO, "IPV6_RECVPKTINFO" }, + { IPV6_RECVHOPLIMIT, "IPV6_RECVHOPLIMIT" }, + { IPV6_RECVRTHDR, "IPV6_RECVRTHDR" }, + { IPV6_RECVHOPOPTS, "IPV6_RECVHOPOPTS" }, + { IPV6_RECVDSTOPTS, "IPV6_RECVDSTOPTS" }, + { IPV6_USE_MIN_MTU, "IPV6_USE_MIN_MTU" }, + { IPV6_RECVPATHMTU, "IPV6_RECVPATHMTU" }, + { IPV6_PATHMTU, "IPV6_PATHMTU" }, + { IPV6_3542PKTINFO, "IPV6_3542PKTINFO" }, + { IPV6_3542HOPLIMIT, "IPV6_3542HOPLIMIT" }, + { IPV6_3542NEXTHOP, "IPV6_3542NEXTHOP" }, + { IPV6_3542HOPOPTS, "IPV6_3542HOPOPTS" }, + { IPV6_3542DSTOPTS, "IPV6_3542DSTOPTS" }, + { IPV6_3542RTHDR, "IPV6_3542RTHDR" }, + { IPV6_PKTINFO, "IPV6_PKTINFO" }, + { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" }, + { IPV6_NEXTHOP, "IPV6_NEXTHOP" }, + { IPV6_HOPOPTS, "IPV6_HOPOPTS" }, + { IPV6_DSTOPTS, "IPV6_DSTOPTS" }, + { IPV6_RTHDR, "IPV6_RTHDR" }, + { IPV6_AUTOFLOWLABEL, "IPV6_AUTOFLOWLABEL" }, + { IPV6_DONTFRAG, "IPV6_DONTFRAG" }, + { IPV6_PREFER_TEMPADDR, "IPV6_PREFER_TEMPADDR" }, + { IPV6_BOUND_IF, "IPV6_BOUND_IF" }, + +#if defined(HAVE_SCTP) + /* /usr/include/netinet/sctp.h and /usr/include/netinet/sctp_uio.h */ + { SCTP_RTOINFO, "SCTP_RTOINFO" }, + { SCTP_ASSOCINFO, "SCTP_ASSOCINFO" }, + { SCTP_INITMSG, "SCTP_INITMSG" }, + { SCTP_INIT, "SCTP_INIT" }, + { SCTP_NODELAY, "SCTP_NODELAY" }, + { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE" }, + { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" }, + { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" }, + { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS" }, + { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM" }, + { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR" }, + { SCTP_MAXSEG, "SCTP_MAXSEG" }, + { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" }, + { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" }, + { SCTP_DELAYED_SACK, "SCTP_DELAYED_SACK" }, + { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT" }, + { SCTP_AUTO_ASCONF, "SCTP_AUTO_ASCONF" }, + { SCTP_MAX_BURST, "SCTP_MAX_BURST" }, + { SCTP_CONTEXT, "SCTP_CONTEXT" }, + { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" }, + { SCTP_EVENT, "SCTP_EVENT" }, + { SCTP_EXPLICIT_EOR, "SCTP_EXPLICIT_EOR" }, + { SCTP_REUSE_PORT, "SCTP_REUSE_PORT" }, + { SCTP_EVENTS, "SCTP_EVENTS" }, + { SCTP_DEFAULT_SNDINFO, "SCTP_DEFAULT_SNDINFO" }, + { SCTP_DEFAULT_PRINFO, "SCTP_DEFAULT_PRINFO" }, + { SCTP_STATUS, "SCTP_STATUS" }, + { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO" }, + { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" }, + { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS" }, + { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" }, + { SCTP_GET_ASSOC_ID_LIST, "SCTP_GET_ASSOC_ID_LIST" }, + { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR" }, + { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" }, + { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" }, + { SCTP_AUTH_DEACTIVATE_KEY, "SCTP_AUTH_DEACTIVATE_KEY" }, + { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" }, + { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE" }, + { SCTP_EXPLICIT_EOR, "SCTP_EXPLICIT_EOR" }, +#if defined(SCTP_INTERLEAVING_SUPPORTED) + { SCTP_INTERLEAVING_SUPPORTED, "SCTP_INTERLEAVING_SUPPORTED" }, +#endif + { SCTP_REMOTE_UDP_ENCAPS_PORT, "SCTP_REMOTE_UDP_ENCAPS_PORT" }, + { SCTP_CLOSED, "SCTP_CLOSED" }, + { SCTP_BOUND, "SCTP_BOUND" }, + { SCTP_LISTEN, "SCTP_LISTEN" }, + { SCTP_COOKIE_WAIT, "SCTP_COOKIE_WAIT" }, + { SCTP_COOKIE_ECHOED, "SCTP_COOKIE_ECHOED" }, + { SCTP_ESTABLISHED, "SCTP_ESTABLISHED" }, + { SCTP_SHUTDOWN_SENT, "SCTP_SHUTDOWN_SENT" }, + { SCTP_SHUTDOWN_RECEIVED, "SCTP_SHUTDOWN_RECEIVED" }, + { SCTP_SHUTDOWN_ACK_SENT, "SCTP_SHUTDOWN_ACK_SENT" }, + { SCTP_SHUTDOWN_PENDING, "SCTP_SHUTDOWN_PENDING" }, + /* The following constants are from + * https://tools.ietf.org/html/draft-ietf-tsvwg-sctp-ndata-04 + * The old symbols currently being deployed are also provided. + */ + { SCTP_PLUGGABLE_SS, "SCTP_PLUGGABLE_SS" }, + { SCTP_SS_VALUE, "SCTP_SS_VALUE" }, + { SCTP_SS_DEFAULT, "SCTP_SS_DEFAULT" }, + { SCTP_SS_ROUND_ROBIN, "SCTP_SS_ROUND_ROBIN" }, + { SCTP_SS_ROUND_ROBIN_PACKET, "SCTP_SS_ROUND_ROBIN_PACKET" }, + { SCTP_SS_PRIORITY, "SCTP_SS_PRIORITY" }, + /* The following is a typo in FreeBSD's sctp.h */ + { SCTP_SS_FAIR_BANDWITH, "SCTP_SS_FAIR_BANDWITH" }, + { SCTP_SS_FIRST_COME, "SCTP_SS_FIRST_COME" }, +#if defined(SCTP_SS_FCFS) + { SCTP_SS_FCFS, "SCTP_SS_FCFS" }, +#endif +#if defined(SCTP_SS_RR) + { SCTP_SS_RR, "SCTP_SS_RR" }, +#endif +#if defined(SCTP_SS_RR_PKT) + { SCTP_SS_RR_PKT, "SCTP_SS_RR_PKT" }, +#endif +#if defined(SCTP_SS_PRIO) + { SCTP_SS_PRIO, "SCTP_SS_PRIO" }, +#endif +#if defined(SCTP_SS_FB) + { SCTP_SS_FB, "SCTP_SS_FB" }, +#endif +#if defined(SCTP_SS_WFQ) + { SCTP_SS_WFQ, "SCTP_SS_WFQ" }, +#endif +#if defined(SCTP_SS_RR_INTER) + { SCTP_SS_RR_INTER, "SCTP_SS_RR_INTER" }, +#endif +#if defined(SCTP_SS_RR_PKT_INTER) + { SCTP_SS_RR_PKT_INTER, "SCTP_SS_RR_PKT_INTER" }, +#endif +#if defined(SCTP_SS_PRIO_INTER) + { SCTP_SS_PRIO_INTER, "SCTP_SS_PRIO_INTER" }, +#endif +#if defined(SCTP_SS_FB_INTER) + { SCTP_SS_FB_INTER, "SCTP_SS_FB_INTER" }, +#endif +#if defined(SCTP_SS_WFQ_INTER) + { SCTP_SS_WFQ_INTER, "SCTP_SS_WFQ_INTER" }, +#endif + { SCTP_UNCONFIRMED, "SCTP_UNCONFIRMED" }, + { SCTP_ACTIVE, "SCTP_ACTIVE" }, + { SCTP_INACTIVE, "SCTP_INACTIVE" }, + { SPP_HB_ENABLE, "SPP_HB_ENABLE" }, + { SPP_HB_DISABLE, "SPP_HB_DISABLE" }, + { SPP_HB_DEMAND, "SPP_HB_DEMAND" }, + { SPP_HB_TIME_IS_ZERO, "SPP_HB_TIME_IS_ZERO" }, + { SPP_PMTUD_ENABLE, "SPP_PMTUD_ENABLE" }, + { SPP_PMTUD_DISABLE, "SPP_PMTUD_DISABLE" }, + { SPP_IPV6_FLOWLABEL, "SPP_IPV6_FLOWLABEL" }, + { SPP_DSCP, "SPP_DSCP" }, + { SCTP_ASSOC_CHANGE, "SCTP_ASSOC_CHANGE" }, + { SCTP_PEER_ADDR_CHANGE, "SCTP_PEER_ADDR_CHANGE" }, + { SCTP_REMOTE_ERROR, "SCTP_REMOTE_ERROR" }, + { SCTP_SEND_FAILED, "SCTP_SEND_FAILED" }, + { SCTP_SHUTDOWN_EVENT, "SCTP_SHUTDOWN_EVENT" }, + { SCTP_SENDER_DRY_EVENT, "SCTP_SENDER_DRY_EVENT" }, + { SCTP_SEND_FAILED_EVENT, "SCTP_SEND_FAILED_EVENT" }, + { SCTP_ADAPTATION_INDICATION, "SCTP_ADAPTATION_INDICATION" }, + { SCTP_ADAPTION_INDICATION, "SCTP_ADAPTION_INDICATION" }, + { SCTP_PARTIAL_DELIVERY_EVENT, "SCTP_PARTIAL_DELIVERY_EVENT" }, + { SCTP_AUTHENTICATION_EVENT, "SCTP_AUTHENTICATION_EVENT" }, + { SCTP_NOTIFICATIONS_STOPPED_EVENT, "SCTP_NOTIFICATIONS_STOPPED_EVENT"}, + { SCTP_SEND_FAILED_EVENT, "SCTP_SEND_FAILED_EVENT" }, + { SCTP_UNORDERED, "SCTP_UNORDERED" }, + { SCTP_COMPLETE, "SCTP_COMPLETE" }, + { SCTP_ADDR_OVER, "SCTP_ADDR_OVER" }, + { SCTP_ABORT, "SCTP_ABORT" }, + { SCTP_EOF, "SCTP_EOF" }, + { SCTP_SENDALL, "SCTP_SENDALL" }, + { SCTP_EOR, "SCTP_EOR" }, + { SCTP_NEXT_MSG_AVAIL, "SCTP_NEXT_MSG_AVAIL" }, + { SCTP_NEXT_MSG_ISCOMPLETE, "SCTP_NEXT_MSG_ISCOMPLETE" }, + { SCTP_NEXT_MSG_IS_UNORDERED, "SCTP_NEXT_MSG_IS_UNORDERED" }, + { SCTP_NEXT_MSG_IS_NOTIFICATION, "SCTP_NEXT_MSG_IS_NOTIFICATION" }, + { SCTP_SACK_IMMEDIATELY, "SCTP_SACK_IMMEDIATELY" }, + { SCTP_PR_SCTP_NONE, "SCTP_PR_SCTP_NONE" }, + { SCTP_PR_SCTP_TTL, "SCTP_PR_SCTP_TTL" }, + { SCTP_PR_SCTP_RTX, "SCTP_PR_SCTP_RTX" }, + { SCTP_PR_SCTP_PRIO, "SCTP_PR_SCTP_PRIO" }, + { SCTP_BINDX_ADD_ADDR, "SCTP_BINDX_ADD_ADDR" }, + { SCTP_BINDX_REM_ADDR, "SCTP_BINDX_REM_ADDR" }, + { SCTP_SENDV_NOINFO, "SCTP_SENDV_NOINFO" }, + { SCTP_SENDV_SNDINFO, "SCTP_SENDV_SNDINFO" }, + { SCTP_SENDV_PRINFO, "SCTP_SENDV_PRINFO" }, + { SCTP_SENDV_AUTHINFO, "SCTP_SENDV_AUTHINFO" }, + { SCTP_SENDV_SPA, "SCTP_SENDV_SPA" }, + { SCTP_SEND_SNDINFO_VALID, "SCTP_SEND_SNDINFO_VALID" }, + { SCTP_SEND_PRINFO_VALID, "SCTP_SEND_PRINFO_VALID" }, + { SCTP_SEND_AUTHINFO_VALID, "SCTP_SEND_AUTHINFO_VALID" }, + { SCTP_RECVV_NOINFO, "SCTP_RECVV_NOINFO" }, + { SCTP_RECVV_RCVINFO, "SCTP_RECVV_RCVINFO" }, + { SCTP_RECVV_NXTINFO, "SCTP_RECVV_NXTINFO" }, + { SCTP_RECVV_RN, "SCTP_RECVV_RN" }, + { SCTP_RECVRCVINFO, "SCTP_RECVRCVINFO" }, + { SCTP_RECVNXTINFO, "SCTP_RECVNXTINFO" }, + { SCTP_DATA_SENT, "SCTP_DATA_SENT" }, + { SCTP_DATA_UNSENT, "SCTP_DATA_UNSENT" }, + { SCTP_COMM_UP, "SCTP_COMM_UP" }, + { SCTP_COMM_LOST, "SCTP_COMM_LOST" }, + { SCTP_RESTART, "SCTP_RESTART" }, + { SCTP_SHUTDOWN_COMP, "SCTP_SHUTDOWN_COMP" }, + { SCTP_AUTH_NEW_KEY, "SCTP_AUTH_NEW_KEY" }, + { SCTP_AUTH_NO_AUTH, "SCTP_AUTH_NO_AUTH" }, + { SCTP_AUTH_FREE_KEY, "SCTP_AUTH_FREE_KEY" }, + { SCTP_ASSOC_SUPPORTS_PR, "SCTP_ASSOC_SUPPORTS_PR" }, + { SCTP_ASSOC_SUPPORTS_AUTH, "SCTP_ASSOC_SUPPORTS_AUTH" }, + { SCTP_ASSOC_SUPPORTS_ASCONF, "SCTP_ASSOC_SUPPORTS_ASCONF" }, + { SCTP_ASSOC_SUPPORTS_MULTIBUF, "SCTP_ASSOC_SUPPORTS_MULTIBUF" }, + { SCTP_PARTIAL_DELIVERY_ABORTED, "SCTP_PARTIAL_DELIVERY_ABORTED" }, + { SCTP_ADDR_AVAILABLE, "SCTP_ADDR_AVAILABLE" }, + { SCTP_ADDR_UNREACHABLE, "SCTP_ADDR_UNREACHABLE" }, + { SCTP_ADDR_REMOVED, "SCTP_ADDR_REMOVED" }, + { SCTP_ADDR_MADE_PRIM, "SCTP_ADDR_MADE_PRIM" }, + { SCTP_SNDRCV, "SCTP_SNDRCV" }, + { SCTP_SNDINFO, "SCTP_SNDINFO" }, + { SCTP_RCVINFO, "SCTP_RCVINFO" }, + { SCTP_NXTINFO, "SCTP_NXTINFO" }, + { SCTP_PRINFO, "SCTP_PRINFO" }, + { SCTP_AUTHINFO, "SCTP_AUTHINFO" }, + { SCTP_DSTADDRV4, "SCTP_DSTADDRV4" }, + { SCTP_DSTADDRV6, "SCTP_DSTADDRV6" }, + { SCTP_EXTRCV, "SCTP_EXTRCV" }, + { SCTP_USE_EXT_RCVINFO, "SCTP_USE_EXT_RCVINFO" }, + { SCTP_AUTH_HMAC_ID_SHA1, "SCTP_AUTH_HMAC_ID_SHA1" }, + { SCTP_AUTH_HMAC_ID_SHA256, "SCTP_AUTH_HMAC_ID_SHA256" }, + + /* sctp stream reconfiguration */ + { SCTP_ENABLE_STREAM_RESET, "SCTP_ENABLE_STREAM_RESET" }, + { SCTP_ENABLE_RESET_STREAM_REQ, "SCTP_ENABLE_RESET_STREAM_REQ" }, + { SCTP_ENABLE_RESET_ASSOC_REQ, "SCTP_ENABLE_RESET_ASSOC_REQ" }, + { SCTP_ENABLE_CHANGE_ASSOC_REQ, "SCTP_ENABLE_CHANGE_ASSOC_REQ" }, + { SCTP_RESET_STREAMS, "SCTP_RESET_STREAMS" }, + { SCTP_STREAM_RESET_INCOMING, "SCTP_STREAM_RESET_INCOMING" }, + { SCTP_STREAM_RESET_OUTGOING, "SCTP_STREAM_RESET_OUTGOING" }, + { SCTP_RESET_ASSOC, "SCTP_RESET_ASSOC" }, + { SCTP_ADD_STREAMS, "SCTP_ADD_STREAMS" }, + { SCTP_STREAM_RESET_EVENT, "SCTP_STREAM_RESET_EVENT" }, + { SCTP_STREAM_RESET_INCOMING_SSN, "SCTP_STREAM_RESET_INCOMING_SSN" }, + { SCTP_STREAM_RESET_OUTGOING_SSN, "SCTP_STREAM_RESET_OUTGOING_SSN" }, + { SCTP_STREAM_RESET_DENIED, "SCTP_STREAM_RESET_DENIED" }, + { SCTP_STREAM_RESET_FAILED, "SCTP_STREAM_RESET_FAILED" }, + { SCTP_ASSOC_RESET_EVENT, "SCTP_ASSOC_RESET_EVENT" }, + { SCTP_ASSOC_RESET_DENIED, "SCTP_ASSOC_RESET_DENIED" }, + { SCTP_ASSOC_RESET_FAILED, "SCTP_ASSOC_RESET_FAILED" }, + { SCTP_STREAM_CHANGE_EVENT, "SCTP_STREAM_CHANGE_EVENT" }, + { SCTP_STREAM_CHANGE_DENIED, "SCTP_STREAM_CHANGE_DENIED" }, + { SCTP_STREAM_CHANGE_FAILED, "SCTP_STREAM_CHANGE_FAILED" }, +#endif + + /* /usr/include/netinet/tcp.h */ + { TCP_NODELAY, "TCP_NODELAY" }, + { TCP_MAXSEG, "TCP_MAXSEG" }, + { TCP_NOPUSH, "TCP_NOPUSH" }, + { TCP_NOOPT, "TCP_NOOPT" }, + { TCP_KEEPALIVE, "TCP_KEEPALIVE" }, + { TCP_CONNECTIONTIMEOUT, "TCP_CONNECTIONTIMEOUT" }, + { PERSIST_TIMEOUT, "PERSIST_TIMEOUT" }, + { TCP_RXT_CONNDROPTIME, "TCP_RXT_CONNDROPTIME" }, + { TCP_RXT_FINDROP, "TCP_RXT_FINDROP" }, + { TCP_KEEPINTVL, "TCP_KEEPINTVL" }, + { TCP_KEEPCNT, "TCP_KEEPCNT" }, + { TCP_SENDMOREACKS, "TCP_SENDMOREACKS" }, + { TCP_ENABLE_ECN, "TCP_ENABLE_ECN" }, + { TCP_FASTOPEN, "TCP_FASTOPEN" }, + { TCP_CONNECTION_INFO, "TCP_CONNECTION_INFO" }, + { TCP_NOTSENT_LOWAT, "TCP_NOTSENT_LOWAT" }, + + /* /usr/include/sys/fcntl.h */ + { O_RDONLY, "O_RDONLY" }, + { O_WRONLY, "O_WRONLY" }, + { O_RDWR, "O_RDWR" }, + { O_ACCMODE, "O_ACCMODE" }, + { FREAD, "FREAD" }, + { FWRITE, "FWRITE" }, + { O_NONBLOCK, "O_NONBLOCK" }, + { O_APPEND, "O_APPEND" }, + { O_SHLOCK, "O_SHLOCK" }, + { O_EXLOCK, "O_EXLOCK" }, + { O_ASYNC, "O_ASYNC" }, + { O_FSYNC, "O_FSYNC" }, + { O_NOFOLLOW, "O_NOFOLLOW" }, + { O_CREAT, "O_CREAT" }, + { O_TRUNC, "O_TRUNC" }, + { O_EXCL, "O_EXCL" }, + { AT_FDCWD, "AT_FDCWD" }, + { AT_EACCESS, "AT_EACCESS" }, + { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" }, + { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" }, + { AT_REMOVEDIR, "AT_REMOVEDIR" }, + { O_EVTONLY, "O_EVTONLY" }, + { O_NOCTTY, "O_NOCTTY" }, + { O_DIRECTORY, "O_DIRECTORY" }, + { O_SYMLINK, "O_SYMLINK" }, + { O_CLOEXEC, "O_CLOEXEC" }, + { O_DP_GETRAWENCRYPTED, "O_DP_GETRAWENCRYPTED" }, + { O_DP_GETRAWUNENCRYPTED, "O_DP_GETRAWUNENCRYPTED" }, + { FAPPEND, "FAPPEND" }, + { FASYNC, "FASYNC" }, + { FFSYNC, "FFSYNC" }, + { FFDSYNC, "FFDSYNC" }, + { FNONBLOCK, "FNONBLOCK" }, + { FNDELAY, "FNDELAY" }, + { O_NDELAY, "O_NDELAY" }, + { CPF_OVERWRITE, "CPF_OVERWRITE" }, + { CPF_IGNORE_MODE, "CPF_IGNORE_MODE" }, + { F_DUPFD, "F_DUPFD" }, + { F_GETFD, "F_GETFD" }, + { F_SETFD, "F_SETFD" }, + { F_GETFL, "F_GETFL" }, + { F_SETFL, "F_SETFL" }, + { F_GETOWN, "F_GETOWN" }, + { F_SETOWN, "F_SETOWN" }, + { F_GETLK, "F_GETLK" }, + { F_SETLK, "F_SETLK" }, + { F_SETLKW, "F_SETLKW" }, + { F_SETLKWTIMEOUT, "F_SETLKWTIMEOUT" }, + { F_FLUSH_DATA, "F_FLUSH_DATA" }, + { F_CHKCLEAN, "F_CHKCLEAN" }, + { F_PREALLOCATE, "F_PREALLOCATE" }, + { F_SETSIZE, "F_SETSIZE" }, + { F_RDADVISE, "F_RDADVISE" }, + { F_RDAHEAD, "F_RDAHEAD" }, + { F_NOCACHE, "F_NOCACHE" }, + { F_LOG2PHYS, "F_LOG2PHYS" }, + { F_GETPATH, "F_GETPATH" }, + { F_FULLFSYNC, "F_FULLFSYNC" }, + { F_PATHPKG_CHECK, "F_PATHPKG_CHECK" }, + { F_FREEZE_FS, "F_FREEZE_FS" }, + { F_THAW_FS, "F_THAW_FS" }, + { F_GLOBAL_NOCACHE, "F_GLOBAL_NOCACHE" }, + { F_ADDSIGS, "F_ADDSIGS" }, + { F_ADDFILESIGS, "F_ADDFILESIGS" }, + { F_NODIRECT, "F_NODIRECT" }, + { F_GETPROTECTIONCLASS, "F_GETPROTECTIONCLASS" }, + { F_SETPROTECTIONCLASS, "F_SETPROTECTIONCLASS" }, + { F_LOG2PHYS_EXT, "F_LOG2PHYS_EXT" }, + { F_GETLKPID, "F_GETLKPID" }, + { F_SETBACKINGSTORE, "F_SETBACKINGSTORE" }, + { F_GETPATH_MTMINFO, "F_GETPATH_MTMINFO" }, + { F_GETCODEDIR, "F_GETCODEDIR" }, + { F_SETNOSIGPIPE, "F_SETNOSIGPIPE" }, + { F_GETNOSIGPIPE, "F_GETNOSIGPIPE" }, + { F_TRANSCODEKEY, "F_TRANSCODEKEY" }, + { F_SINGLE_WRITER, "F_SINGLE_WRITER" }, + { F_GETPROTECTIONLEVEL, "F_GETPROTECTIONLEVEL" }, + { F_FINDSIGS, "F_FINDSIGS" }, + { F_ADDFILESIGS_FOR_DYLD_SIM, "F_ADDFILESIGS_FOR_DYLD_SIM" }, + { F_BARRIERFSYNC, "F_BARRIERFSYNC" }, + { F_ADDFILESIGS_RETURN, "F_ADDFILESIGS_RETURN" }, + { F_CHECK_LV, "F_CHECK_LV" }, + { F_PUNCHHOLE, "F_PUNCHHOLE" }, + { F_TRIM_ACTIVE_FILE, "F_TRIM_ACTIVE_FILE" }, + { FCNTL_FS_SPECIFIC_BASE, "F_UFCNTL_FS_SPECIFIC_BASENLCK" }, + { F_DUPFD_CLOEXEC, "F_DUPFD_CLOEXEC" }, + { FD_CLOEXEC, "FD_CLOEXEC" }, + { F_RDLCK, "F_RDLCK" }, + { F_UNLCK, "F_UNLCK" }, + { F_WRLCK, "F_WRLCK" }, + { F_ALLOCATECONTIG, "F_ALLOCATECONTIG" }, + { F_ALLOCATEALL, "F_ALLOCATEALL" }, + { F_PEOFPOSMODE, "F_PEOFPOSMODE" }, + { F_VOLPOSMODE, "F_VOLPOSMODE" }, + + /* /usr/include/sys/unistd.h */ + { SEEK_SET, "SEEK_SET" }, + { SEEK_CUR, "SEEK_CUR" }, + { SEEK_END, "SEEK_END" }, + + /* /usr/include/sys/socket.h */ + { MSG_OOB, "MSG_OOB" }, + { MSG_PEEK, "MSG_PEEK" }, + { MSG_DONTROUTE, "MSG_DONTROUTE" }, + { MSG_EOR, "MSG_EOR" }, + { MSG_TRUNC, "MSG_TRUNC" }, + { MSG_CTRUNC, "MSG_CTRUNC" }, + { MSG_WAITALL, "MSG_WAITALL" }, + { MSG_DONTWAIT, "MSG_DONTWAIT" }, + { MSG_EOF, "MSG_EOF" }, + { MSG_FLUSH, "MSG_FLUSH" }, + { MSG_HOLD, "MSG_HOLD" }, + { MSG_SEND, "MSG_SEND" }, + { MSG_HAVEMORE, "MSG_HAVEMORE" }, + { MSG_RCVMORE, "MSG_RCVMORE" }, + { MSG_NEEDSA, "MSG_NEEDSA" }, + + /* /usr/include/sys/filio.h */ + { FIOCLEX, "FIOCLEX" }, + { FIONCLEX, "FIONCLEX" }, + { FIONREAD, "FIONREAD" }, + { FIONBIO, "FIONBIO" }, + { FIOASYNC, "FIOASYNC" }, + { FIOSETOWN, "FIOSETOWN" }, + { FIOGETOWN, "FIOGETOWN" }, + { FIODTYPE, "FIODTYPE" }, + + /* /usr/include/sys/poll.h */ + { POLLIN, "POLLIN" }, + { POLLPRI, "POLLPRI" }, + { POLLOUT, "POLLOUT" }, + { POLLRDNORM, "POLLRDNORM" }, + { POLLWRNORM, "POLLWRNORM" }, + { POLLRDBAND, "POLLRDBAND" }, + { POLLWRBAND, "POLLWRBAND" }, + { POLLERR, "POLLERR" }, + { POLLHUP, "POLLHUP" }, + { POLLNVAL, "POLLNVAL" }, + + /* /usr/include/sys/errno.h */ + { EPERM, "EPERM" }, + { ENOENT, "ENOENT" }, + { ESRCH, "ESRCH" }, + { EINTR, "EINTR" }, + { EIO, "EIO" }, + { ENXIO, "ENXIO" }, + { E2BIG, "E2BIG" }, + { ENOEXEC, "ENOEXEC" }, + { EBADF, "EBADF" }, + { ECHILD, "ECHILD" }, + { EDEADLK, "EDEADLK" }, + { ENOMEM, "ENOMEM" }, + { EACCES, "EACCES" }, + { EFAULT, "EFAULT" }, + { ENOTBLK, "ENOTBLK" }, + { EBUSY, "EBUSY" }, + { EEXIST, "EEXIST" }, + { EXDEV, "EXDEV" }, + { ENODEV, "ENODEV" }, + { ENOTDIR, "ENOTDIR" }, + { EISDIR, "EISDIR" }, + { EINVAL, "EINVAL" }, + { ENFILE, "ENFILE" }, + { EMFILE, "EMFILE" }, + { ENOTTY, "ENOTTY" }, + { ETXTBSY, "ETXTBSY" }, + { EFBIG, "EFBIG" }, + { ENOSPC, "ENOSPC" }, + { ESPIPE, "ESPIPE" }, + { EROFS, "EROFS" }, + { EMLINK, "EMLINK" }, + { EPIPE, "EPIPE" }, + { EDOM, "EDOM" }, + { ERANGE, "ERANGE" }, + { EAGAIN, "EAGAIN" }, + { EWOULDBLOCK, "EWOULDBLOCK" }, + { EINPROGRESS, "EINPROGRESS" }, + { EALREADY, "EALREADY" }, + { ENOTSOCK, "ENOTSOCK" }, + { EDESTADDRREQ, "EDESTADDRREQ" }, + { EMSGSIZE, "EMSGSIZE" }, + { EPROTOTYPE, "EPROTOTYPE" }, + { ENOPROTOOPT, "ENOPROTOOPT" }, + { EPROTONOSUPPORT, "EPROTONOSUPPORT" }, + { ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT" }, + { EOPNOTSUPP, "EOPNOTSUPP" }, + { ENOTSUP, "ENOTSUP" }, + { EPFNOSUPPORT, "EPFNOSUPPORT" }, + { EAFNOSUPPORT, "EAFNOSUPPORT" }, + { EADDRINUSE, "EADDRINUSE" }, + { EADDRNOTAVAIL, "EADDRNOTAVAIL" }, + { ENETDOWN, "ENETDOWN" }, + { ENETUNREACH, "ENETUNREACH" }, + { ENETRESET, "ENETRESET" }, + { ECONNABORTED, "ECONNABORTED" }, + { ECONNRESET, "ECONNRESET" }, + { ENOBUFS, "ENOBUFS" }, + { EISCONN, "EISCONN" }, + { ENOTCONN, "ENOTCONN" }, + { ESHUTDOWN, "ESHUTDOWN" }, + { ETOOMANYREFS, "ETOOMANYREFS" }, + { ETIMEDOUT, "ETIMEDOUT" }, + { ECONNREFUSED, "ECONNREFUSED" }, + { ELOOP, "ELOOP" }, + { ENAMETOOLONG, "ENAMETOOLONG" }, + { EHOSTDOWN, "EHOSTDOWN" }, + { EHOSTUNREACH, "EHOSTUNREACH" }, + { ENOTEMPTY, "ENOTEMPTY" }, + { EPROCLIM, "EPROCLIM" }, + { EUSERS, "EUSERS" }, + { EDQUOT, "EDQUOT" }, + { ESTALE, "ESTALE" }, + { EREMOTE, "EREMOTE" }, + { EBADRPC, "EBADRPC" }, + { ERPCMISMATCH, "ERPCMISMATCH" }, + { EPROGUNAVAIL, "EPROGUNAVAIL" }, + { EPROGMISMATCH, "EPROGMISMATCH" }, + { EPROCUNAVAIL, "EPROCUNAVAIL" }, + { ENOLCK, "ENOLCK" }, + { ENOSYS, "ENOSYS" }, + { EFTYPE, "EFTYPE" }, + { EAUTH, "EAUTH" }, + { ENEEDAUTH, "ENEEDAUTH" }, + { EPWROFF, "EPWROFF" }, + { EDEVERR, "EDEVERR" }, + { EOVERFLOW, "EOVERFLOW" }, + { EBADEXEC, "EBADEXEC" }, + { EBADARCH, "EBADARCH" }, + { ESHLIBVERS, "ESHLIBVERS" }, + { EBADMACHO, "EBADMACHO" }, + { ECANCELED, "ECANCELED" }, + { EIDRM, "EIDRM" }, + { ENOMSG, "ENOMSG" }, + { EILSEQ, "EILSEQ" }, + { ENOATTR, "ENOATTR" }, + { EBADMSG, "EBADMSG" }, + { EMULTIHOP, "EMULTIHOP" }, + { ENODATA, "ENODATA" }, + { ENOLINK, "ENOLINK" }, + { ENOSR, "ENOSR" }, + { ENOSTR, "ENOSTR" }, + { EPROTO, "EPROTO" }, + { ETIME, "ETIME" }, + { EOPNOTSUPP, "EOPNOTSUPP" }, + { ENOPOLICY, "ENOPOLICY" }, + { ENOTRECOVERABLE, "ENOTRECOVERABLE" }, + { EOWNERDEAD, "EOWNERDEAD" }, + { EQFULL, "EQFULL" }, + + /* Sentinel marking the end of the table. */ + { 0, NULL }, +}; + +struct int_symbol *platform_symbols(void) +{ + return platform_symbols_table; +} + +#endif /* __APPLE__ */ diff --git a/gtests/net/packetdrill/tcp.h b/gtests/net/packetdrill/tcp.h index fbc8edbd2d652dfb8cddcde7b8a816c0dcdfa4ba..da9cbe6735daf5fb19fe7188c05170e61b98bd0d 100644 --- a/gtests/net/packetdrill/tcp.h +++ b/gtests/net/packetdrill/tcp.h @@ -34,13 +34,13 @@ #include "types.h" #include <netinet/tcp.h> -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) #include <netinet/tcp_fsm.h> #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) #define SOL_TCP IPPROTO_TCP -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ +#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) */ #ifdef linux @@ -230,5 +230,53 @@ struct _tcp_info { #endif /* __FreeBSD__ */ +#if defined(__APPLE__) + +/* Data returned by the TCP_INFO socket option on MacOS. */ +struct _tcp_info { + u_int8_t tcpi_state; + u_int8_t tcpi_snd_wscale; + u_int8_t tcpi_rcv_wscale; + u_int8_t __pad1; + u_int32_t tcpi_options; + u_int32_t tcpi_flags; + u_int32_t tcpi_rto; + u_int32_t tcpi_maxseg; + u_int32_t tcpi_snd_ssthresh; + u_int32_t tcpi_snd_cwnd; + u_int32_t tcpi_snd_wnd; + u_int32_t tcpi_snd_sbbytes; + u_int32_t tcpi_rcv_wnd; + u_int32_t tcpi_rttcur; + u_int32_t tcpi_srtt; + u_int32_t tcpi_rttvar; + u_int32_t + tcpi_tfo_cookie_req:1, + tcpi_tfo_cookie_rcv:1, + tcpi_tfo_syn_loss:1, + tcpi_tfo_syn_data_sent:1, + tcpi_tfo_syn_data_acked:1, + tcpi_tfo_syn_data_rcv:1, + tcpi_tfo_cookie_req_rcv:1, + tcpi_tfo_cookie_sent:1, + tcpi_tfo_cookie_invalid:1, + tcpi_tfo_cookie_wrong:1, + tcpi_tfo_no_cookie_rcv:1, + tcpi_tfo_heuristics_disable:1, + tcpi_tfo_send_blackhole:1, + tcpi_tfo_recv_blackhole:1, + tcpi_tfo_onebyte_proxy:1, + __pad2:17; + u_int64_t tcpi_txpackets __attribute__((aligned(8))); + u_int64_t tcpi_txbytes __attribute__((aligned(8))); + u_int64_t tcpi_txretransmitbytes __attribute__((aligned(8))); + u_int64_t tcpi_rxpackets __attribute__((aligned(8))); + u_int64_t tcpi_rxbytes __attribute__((aligned(8))); + u_int64_t tcpi_rxoutoforderbytes __attribute__((aligned(8))); + u_int64_t tcpi_txretransmitpackets __attribute__((aligned(8))); +}; + +#endif /* __APPLE__ */ + #endif /* __TCP_HEADERS_H__ */ diff --git a/gtests/net/packetdrill/wire_client_netdev.c b/gtests/net/packetdrill/wire_client_netdev.c index 049f982117fa0d91af739bbfee57d584eec4697c..f7f47b9ba17ae79082489b3a6f67fe6ac90f5cce 100644 --- a/gtests/net/packetdrill/wire_client_netdev.c +++ b/gtests/net/packetdrill/wire_client_netdev.c @@ -65,7 +65,7 @@ static void route_traffic_to_wire_server(struct config *config, struct wire_client_netdev *netdev) { char *route_command = NULL; -#ifdef linux +#if defined(linux) asprintf(&route_command, "ip %s route del %s > /dev/null 2>&1 ; " "ip %s route add %s dev %s via %s > /dev/null 2>&1", @@ -75,8 +75,7 @@ static void route_traffic_to_wire_server(struct config *config, config->live_remote_prefix_string, netdev->name, config->live_gateway_ip_string); -#endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#else if (config->wire_protocol == AF_INET) { asprintf(&route_command, "route delete %s > /dev/null 2>&1 ; " @@ -94,7 +93,7 @@ static void route_traffic_to_wire_server(struct config *config, } else { assert(!"bad wire protocol"); } -#endif /* defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) */ +#endif /* defined(linux) */ /* We intentionally ignore failures and output to stderr, * since they can happen if there is no previously existing @@ -121,7 +120,8 @@ struct netdev *wire_client_netdev_new(struct config *config) /* Add the client live local IP to our NIC, so we can send/receive */ net_setup_dev_address(netdev->name, &config->live_local_ip, - config->live_prefix_len); + config->live_prefix_len, + &config->live_gateway_ip); route_traffic_to_wire_server(config, netdev); diff --git a/gtests/net/packetdrill/wire_server_netdev.c b/gtests/net/packetdrill/wire_server_netdev.c index 02905614f03b20a1a19946acba25a2bf301abef2..bf17f2046452605cca2048e0d4e4fa1ae066e9bc 100644 --- a/gtests/net/packetdrill/wire_server_netdev.c +++ b/gtests/net/packetdrill/wire_server_netdev.c @@ -126,7 +126,8 @@ struct netdev *wire_server_netdev_new( */ net_setup_dev_address(netdev->name, &config->live_gateway_ip, - config->live_prefix_len); + config->live_prefix_len, + &config->live_gateway_ip); netdev->psock = packet_socket_new(netdev->name);