diff options
author | Martin Schwenke <martin@meltin.net> | 2018-08-16 15:15:55 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2018-08-30 04:48:57 +0200 |
commit | 87088af6e49e9ce973cfe77d36cfbf42f9101854 (patch) | |
tree | 88fec7d0167b9c25546e442eea2dd22c673757c5 /ctdb/tests/src | |
parent | 39cfd51143b5bddc154b1d22b3768a2f4eef2161 (diff) | |
download | samba-87088af6e49e9ce973cfe77d36cfbf42f9101854.tar.gz |
ctdb-tests: Add tests for ARP and IPv6 NA marshalling
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tests/src')
-rw-r--r-- | ctdb/tests/src/system_socket_test.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/ctdb/tests/src/system_socket_test.c b/ctdb/tests/src/system_socket_test.c index 61dfa3970c1..23a1a3b26c5 100644 --- a/ctdb/tests/src/system_socket_test.c +++ b/ctdb/tests/src/system_socket_test.c @@ -17,8 +17,21 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "replace.h" + #include <assert.h> +/* For ether_aton() */ +#ifdef _AIX +#include <arpa/inet.h> +#endif +#ifdef __FreeBSD__ +#include <net/ethernet.h> +#endif +#ifdef linux +#include <netinet/ether.h> +#endif + #include "common/system_socket.c" #include "protocol/protocol_util.h" @@ -37,11 +50,54 @@ static void test_types(void) assert(sizeof(ip4pkt) == sizeof(struct ip) + sizeof(struct tcphdr)); } +#ifdef HAVE_PACKETSOCKET + +static void test_arp(const char *addr_str, const char *hwaddr_str, bool reply) +{ + ctdb_sock_addr addr; + struct ether_addr *hw, *dhw; + uint8_t buf[512]; + size_t buflen = sizeof(buf); + size_t len; + int ret; + + ret = ctdb_sock_addr_from_string(addr_str, &addr, false); + assert(ret == 0); + + hw = ether_aton(hwaddr_str); + assert(hw != NULL); + + switch (addr.ip.sin_family) { + case AF_INET: + ret = arp_build(buf, buflen, &addr.ip, hw, reply, &dhw, &len); + break; + case AF_INET6: + ret = ip6_na_build(buf, buflen, &addr.ip6, hw, &dhw, &len); + break; + default: + abort(); + } + + assert(ret == 0); + + write(STDOUT_FILENO, buf, len); +} + +#else /* HAVE_PACKETSOCKET */ + +static void test_arp(const char *addr_str, const char *hwaddr_str, bool reply) +{ + fprintf(stderr, "PACKETSOCKET not supported\n"); +} + +#endif /* HAVE_PACKETSOCKET */ + static void usage(const char *prog) { fprintf(stderr, "usage: %s <cmd> [<arg> ...]\n", prog); fprintf(stderr, " commands:\n"); fprintf(stderr, " types\n"); + fprintf(stderr, " arp <ipaddr> <hwaddr> [reply]\n"); exit(1); } @@ -55,6 +111,15 @@ int main(int argc, char **argv) if (strcmp(argv[1], "types") == 0) { test_types(); + } else if (strcmp(argv[1], "arp") == 0) { + /* + * Extra arg indicates that a reply should be + * constructed for IPv4 - value is ignored + */ + if (argc != 4 && argc != 5) { + usage(argv[0]); + } + test_arp(argv[2], argv[3], (argc == 5)); } else { usage(argv[0]); } |