Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/libnozzle/tests/Makefile.am b/libnozzle/tests/Makefile.am
index d677bd9b..17bfc876 100644
--- a/libnozzle/tests/Makefile.am
+++ b/libnozzle/tests/Makefile.am
@@ -1,65 +1,74 @@
#
# Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
#
# Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
#
# This software licensed under GPL-2.0+, LGPL-2.0+
#
MAINTAINERCLEANFILES = Makefile.in
include $(top_srcdir)/build-aux/check.mk
EXTRA_DIST = \
tap_updown_bad \
tap_updown_good \
api-test-coverage
noinst_HEADERS = \
test-common.h
if BUILD_LIBNOZZLE
check_PROGRAMS = \
api_nozzle_open_test \
api_nozzle_close_test \
api_nozzle_set_up_test \
api_nozzle_set_down_test \
+ api_nozzle_get_mtu_test \
+ api_nozzle_set_mtu_test \
nozzle_test
noinst_PROGRAMS = $(check_PROGRAMS)
noinst_SCRIPTS = \
api-test-coverage
TESTS = $(check_PROGRAMS)
check-local: check-api-test-coverage
check-api-test-coverage:
chmod u+x $(top_srcdir)/libnozzle/tests/api-test-coverage
$(top_srcdir)/libnozzle/tests/api-test-coverage $(top_srcdir) $(top_builddir)
AM_CPPFLAGS = -I$(top_srcdir)/libnozzle -DABSBUILDDIR=\"$(abs_builddir)\"
AM_CFLAGS += $(PTHREAD_CFLAGS) $(libnl_CFLAGS)
LIBS += $(top_builddir)/libnozzle/libnozzle.la $(PTHREAD_LIBS) $(libnl_LIBS)
api_nozzle_open_test_SOURCES = api_nozzle_open.c \
test-common.c
api_nozzle_close_test_SOURCES = api_nozzle_close.c \
test-common.c
api_nozzle_set_up_test_SOURCES = api_nozzle_set_up.c \
test-common.c \
../internals.c
api_nozzle_set_down_test_SOURCES = api_nozzle_set_down.c \
test-common.c \
../internals.c
+api_nozzle_get_mtu_test_SOURCES = api_nozzle_get_mtu.c \
+ test-common.c
+
+api_nozzle_set_mtu_test_SOURCES = api_nozzle_set_mtu.c \
+ test-common.c \
+ ../internals.c
+
nozzle_test_SOURCES = nozzle_test.c \
test-common.c \
../internals.c
endif
diff --git a/libnozzle/tests/api-test-coverage b/libnozzle/tests/api-test-coverage
index f9acb8fa..3d73b305 100755
--- a/libnozzle/tests/api-test-coverage
+++ b/libnozzle/tests/api-test-coverage
@@ -1,91 +1,92 @@
#!/bin/sh
#
# Copyright (C) 2016-2018 Red Hat, Inc. All rights reserved.
#
# Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
#
# This software licensed under GPL-2.0+, LGPL-2.0+
#
srcdir="$1"/libnozzle/tests
builddir="$2"/libnozzle/tests
headerapicalls="$(grep nozzle_ "$srcdir"/../libnozzle.h | grep -v "^ \*" | grep -v ^struct | grep -v "^[[:space:]]" | grep -v typedef | sed -e 's/(.*//g' -e 's/^const //g' -e 's/\*//g' | awk '{print $2}')"
# The PowerPC64 ELFv1 ABI defines the address of a function as that of a
# function descriptor defined in .opd, a data (D) section. Other ABIs
# use the entry address of the function itself in the text (T) section.
exportedapicalls="$(nm -B -D "$builddir"/../.libs/libnozzle.so | grep ' [DT] ' | awk '{print $3}')"
echo "Checking for exported symbols NOT available in header file"
for i in $exportedapicalls; do
found=0
for x in $headerapicalls; do
if [ "$x" = "$i" ]; then
found=1
break;
fi
done
if [ "$found" = 0 ]; then
echo "Symbol $i not found in header file"
exit 1
fi
done
echo "Checking for symbols in header file NOT exported by binary lib"
for i in $headerapicalls; do
found=0
for x in $exportedapicalls; do
if [ "$x" = "$i" ]; then
found=1
break;
fi
done
if [ "$found" = 0 ]; then
echo "Symbol $i not found in binary lib"
exit 1
fi
done
echo "Checking for tests with memcheck exceptions"
for i in $(grep -l is_memcheck "$srcdir"/*.c | grep -v test-common); do
echo "WARNING: $(basename $i) - has memcheck exception enabled"
done
echo "Checking for tests with helgrind exceptions"
for i in $(grep -l is_helgrind "$srcdir"/*.c | grep -v test-common); do
echo "WARNING: $(basename $i) has helgrind exception enabled"
done
echo "Checking for api test coverage"
numapicalls=0
found=0
missing=0
for i in $headerapicalls; do
+ [ "$i" = nozzle_reset_mtu ] && i=nozzle_set_mtu # tested together
numapicalls=$((numapicalls + 1))
if [ -f $srcdir/api_${i}.c ]; then
found=$((found + 1))
else
missing=$((missing + 1))
echo "MISSING: $i"
fi
done
echo "Summary"
echo "-------"
echo "Found : $found"
echo "Missing : $missing"
echo "Total : $numapicalls"
which bc > /dev/null 2>&1 && {
coverage=$(echo "scale=3; $found / $numapicalls * 100" | bc -l)
echo "Coverage: $coverage%"
}
exit 0
exit 0
diff --git a/libnozzle/tests/api_nozzle_get_mtu.c b/libnozzle/tests/api_nozzle_get_mtu.c
new file mode 100644
index 00000000..2c34ca39
--- /dev/null
+++ b/libnozzle/tests/api_nozzle_get_mtu.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
+ *
+ * Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
+ *
+ * This software licensed under GPL-2.0+, LGPL-2.0+
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+#include <limits.h>
+
+#include "test-common.h"
+
+static int test(void)
+{
+ char device_name[IFNAMSIZ];
+ size_t size = IFNAMSIZ;
+ int err=0;
+ nozzle_t nozzle;
+
+ int current_mtu = 0;
+ int expected_mtu = 1500;
+
+ printf("Testing get MTU\n");
+
+ memset(device_name, 0, size);
+ nozzle = nozzle_open(device_name, size, NULL);
+ if (!nozzle) {
+ printf("Unable to init %s\n", device_name);
+ return -1;
+ }
+
+ printf("Comparing default MTU\n");
+ current_mtu = nozzle_get_mtu(nozzle);
+ if (current_mtu < 0) {
+ printf("Unable to get MTU\n");
+ err = -1;
+ goto out_clean;
+ }
+ if (current_mtu != expected_mtu) {
+ printf("current mtu [%d] does not match expected default [%d]\n", current_mtu, expected_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ printf("Setting MTU to 9000\n");
+ expected_mtu = 9000;
+ if (nozzle_set_mtu(nozzle, expected_mtu) < 0) {
+ printf("Unable to set MTU to %d\n", expected_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ current_mtu = nozzle_get_mtu(nozzle);
+ if (current_mtu < 0) {
+ printf("Unable to get MTU\n");
+ err = -1;
+ goto out_clean;
+ }
+ if (current_mtu != expected_mtu) {
+ printf("current mtu [%d] does not match expected value [%d]\n", current_mtu, expected_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ printf("Testing ERROR conditions\n");
+
+ printf("Passing empty struct to get_mtu\n");
+ if (nozzle_get_mtu(NULL) > 0) {
+ printf("Something is wrong in nozzle_get_mtu sanity checks\n");
+ err = -1;
+ goto out_clean;
+ }
+
+out_clean:
+ if (nozzle) {
+ nozzle_close(nozzle);
+ }
+
+ return err;
+}
+
+int main(void)
+{
+ need_root();
+
+ if (test() < 0)
+ return FAIL;
+
+ return PASS;
+}
diff --git a/libnozzle/tests/api_nozzle_set_mtu.c b/libnozzle/tests/api_nozzle_set_mtu.c
new file mode 100644
index 00000000..510b2d46
--- /dev/null
+++ b/libnozzle/tests/api_nozzle_set_mtu.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
+ *
+ * Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
+ *
+ * This software licensed under GPL-2.0+, LGPL-2.0+
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+#include <limits.h>
+
+#include "test-common.h"
+
+char testipv4_1[IPBUFSIZE];
+char testipv4_2[IPBUFSIZE];
+char testipv6_1[IPBUFSIZE];
+char testipv6_2[IPBUFSIZE];
+
+static int test(void)
+{
+ char device_name[IFNAMSIZ];
+ size_t size = IFNAMSIZ;
+ int err=0;
+ nozzle_t nozzle;
+
+ int current_mtu = 0;
+ int expected_mtu = 1500;
+
+ printf("Testing set MTU\n");
+
+ memset(device_name, 0, size);
+ nozzle = nozzle_open(device_name, size, NULL);
+ if (!nozzle) {
+ printf("Unable to init %s\n", device_name);
+ return -1;
+ }
+
+ printf("Comparing default MTU\n");
+ current_mtu = nozzle_get_mtu(nozzle);
+ if (current_mtu < 0) {
+ printf("Unable to get MTU\n");
+ err = -1;
+ goto out_clean;
+ }
+ if (current_mtu != expected_mtu) {
+ printf("current mtu [%d] does not match expected default [%d]\n", current_mtu, expected_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ printf("Setting MTU to 9000\n");
+ expected_mtu = 9000;
+ if (nozzle_set_mtu(nozzle, expected_mtu) < 0) {
+ printf("Unable to set MTU to %d\n", expected_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ current_mtu = nozzle_get_mtu(nozzle);
+ if (current_mtu < 0) {
+ printf("Unable to get MTU\n");
+ err = -1;
+ goto out_clean;
+ }
+ if (current_mtu != expected_mtu) {
+ printf("current mtu [%d] does not match expected value [%d]\n", current_mtu, expected_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ printf("Restoring MTU to default\n");
+ expected_mtu = 1500;
+ if (nozzle_reset_mtu(nozzle) < 0) {
+ printf("Unable to reset mtu\n");
+ err = -1;
+ goto out_clean;
+ }
+ current_mtu = nozzle_get_mtu(nozzle);
+ if (current_mtu < 0) {
+ printf("Unable to get MTU\n");
+ err = -1;
+ goto out_clean;
+ }
+ if (current_mtu != expected_mtu) {
+ printf("current mtu [%d] does not match expected value [%d]\n", current_mtu, expected_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ printf("Testing ERROR conditions\n");
+
+ printf("Passing empty struct to set_mtu\n");
+ if (nozzle_set_mtu(NULL, 1500) == 0) {
+ printf("Something is wrong in nozzle_set_mtu sanity checks\n");
+ err = -1;
+ goto out_clean;
+ }
+
+ printf("Passing 0 mtu to set_mtu\n");
+ if (nozzle_set_mtu(nozzle, 0) == 0) {
+ printf("Something is wrong in nozzle_set_mtu sanity checks\n");
+ err = -1;
+ goto out_clean;
+ }
+
+out_clean:
+ if (nozzle) {
+ nozzle_close(nozzle);
+ }
+
+ return err;
+}
+
+static int test_ipv6(void)
+{
+ char device_name[IFNAMSIZ];
+ size_t size = IFNAMSIZ;
+ char verifycmd[2048];
+ int err=0;
+ nozzle_t nozzle;
+ char *error_string = NULL;
+ int current_mtu = 0;
+
+ printf("Testing get/set MTU with IPv6 address\n");
+
+ memset(device_name, 0, size);
+
+ nozzle = nozzle_open(device_name, size, NULL);
+ if (!nozzle) {
+ printf("Unable to init %s\n", device_name);
+ return -1;
+ }
+
+ printf("Adding ip: %s/64\n", testipv6_1);
+
+ err = nozzle_add_ip(nozzle, testipv6_1, "64");
+ if (err) {
+ printf("Unable to assign IP address\n");
+ err=-1;
+ goto out_clean;
+ }
+
+ memset(verifycmd, 0, sizeof(verifycmd));
+ snprintf(verifycmd, sizeof(verifycmd)-1,
+#ifdef KNET_LINUX
+ "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_1);
+#endif
+#ifdef KNET_BSD
+ "ifconfig %s | grep -q %s", nozzle->name, testipv6_1);
+#endif
+ err = execute_bin_sh_command(verifycmd, &error_string);
+ if (error_string) {
+ printf("Error string: %s\n", error_string);
+ free(error_string);
+ error_string = NULL;
+ }
+ if (err) {
+ printf("Unable to verify IP address\n");
+ err=-1;
+ goto out_clean;
+ }
+
+ printf("Setting MTU to 1200\n");
+ if (nozzle_set_mtu(nozzle, 1200) < 0) {
+ printf("Unable to set MTU to 1200\n");
+ err = -1;
+ goto out_clean;
+ }
+
+ err = execute_bin_sh_command(verifycmd, &error_string);
+ if (error_string) {
+ printf("Error string: %s\n", error_string);
+ free(error_string);
+ error_string = NULL;
+ }
+#ifdef KNET_LINUX
+ if (!err) {
+#endif
+#ifdef KNET_BSD
+ if (err) {
+#endif
+ printf("Unable to verify IP address\n");
+ err=-1;
+ goto out_clean;
+ }
+
+ printf("Adding ip: %s/64\n", testipv6_2);
+ err = nozzle_add_ip(nozzle, testipv6_2, "64");
+ if (err < 0) {
+ printf("Unable to assign IP address\n");
+ err=-1;
+ goto out_clean;
+ }
+
+ memset(verifycmd, 0, sizeof(verifycmd));
+ snprintf(verifycmd, sizeof(verifycmd)-1,
+#ifdef KNET_LINUX
+ "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_2);
+#endif
+#ifdef KNET_BSD
+ "ifconfig %s | grep -q %s", nozzle->name, testipv6_2);
+#endif
+ err = execute_bin_sh_command(verifycmd, &error_string);
+ if (error_string) {
+ printf("Error string: %s\n", error_string);
+ free(error_string);
+ error_string = NULL;
+ }
+ if (!err) {
+ printf("Unable to verify IP address\n");
+ err=-1;
+ goto out_clean;
+ }
+
+ printf("Restoring MTU to default\n");
+ if (nozzle_reset_mtu(nozzle) < 0) {
+ printf("Unable to reset mtu\n");
+ err = -1;
+ goto out_clean;
+ }
+
+ current_mtu = nozzle_get_mtu(nozzle);
+ if (current_mtu != 1500) {
+ printf("current mtu [%d] does not match expected value [1500]\n", current_mtu);
+ err = -1;
+ goto out_clean;
+ }
+
+ memset(verifycmd, 0, sizeof(verifycmd));
+ snprintf(verifycmd, sizeof(verifycmd)-1,
+#ifdef KNET_LINUX
+ "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_1);
+#endif
+#ifdef KNET_BSD
+ "ifconfig %s | grep -q %s", nozzle->name, testipv6_1);
+#endif
+ err = execute_bin_sh_command(verifycmd, &error_string);
+ if (error_string) {
+ printf("Error string: %s\n", error_string);
+ free(error_string);
+ error_string = NULL;
+ }
+ if (err) {
+ printf("Unable to verify IP address\n");
+ err=-1;
+ goto out_clean;
+ }
+
+ memset(verifycmd, 0, sizeof(verifycmd));
+ snprintf(verifycmd, sizeof(verifycmd)-1,
+#ifdef KNET_LINUX
+ "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_2);
+#endif
+#ifdef KNET_BSD
+ "ifconfig %s | grep -q %s", nozzle->name, testipv6_2);
+#endif
+ err = execute_bin_sh_command(verifycmd, &error_string);
+ if (error_string) {
+ printf("Error string: %s\n", error_string);
+ free(error_string);
+ error_string = NULL;
+ }
+ if (err) {
+ printf("Unable to verify IP address\n");
+ err=-1;
+ goto out_clean;
+ }
+
+out_clean:
+ if (nozzle) {
+ nozzle_close(nozzle);
+ }
+
+ return err;
+}
+
+int main(void)
+{
+ need_root();
+
+ make_local_ips(testipv4_1, testipv4_2, testipv6_1, testipv6_2);
+
+ if (test() < 0)
+ return FAIL;
+
+ if (test_ipv6() < 0)
+ return FAIL;
+
+ return PASS;
+}
diff --git a/libnozzle/tests/nozzle_test.c b/libnozzle/tests/nozzle_test.c
index dbf50604..9c9df994 100644
--- a/libnozzle/tests/nozzle_test.c
+++ b/libnozzle/tests/nozzle_test.c
@@ -1,931 +1,694 @@
/*
* Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
*
* Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
*
* This software licensed under GPL-2.0+, LGPL-2.0+
*/
#include "config.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <limits.h>
#include <sys/socket.h>
#include <net/ethernet.h>
#ifdef KNET_LINUX
#include <linux/if_tun.h>
#include <netinet/ether.h>
#endif
#ifdef KNET_BSD
#include <net/if_dl.h>
#endif
#include "test-common.h"
char testipv4_1[IPBUFSIZE];
char testipv4_2[IPBUFSIZE];
char testipv6_1[IPBUFSIZE];
char testipv6_2[IPBUFSIZE];
-static int check_knet_mtu(void)
-{
- char device_name[IFNAMSIZ];
- size_t size = IFNAMSIZ;
- int err=0;
- nozzle_t nozzle;
-
- int current_mtu = 0;
- int expected_mtu = 1500;
-
- printf("Testing get/set MTU\n");
-
- memset(device_name, 0, size);
- nozzle = nozzle_open(device_name, size, NULL);
- if (!nozzle) {
- printf("Unable to init %s\n", device_name);
- return -1;
- }
-
- printf("Comparing default MTU\n");
- current_mtu = nozzle_get_mtu(nozzle);
- if (current_mtu < 0) {
- printf("Unable to get MTU\n");
- err = -1;
- goto out_clean;
- }
- if (current_mtu != expected_mtu) {
- printf("current mtu [%d] does not match expected default [%d]\n", current_mtu, expected_mtu);
- err = -1;
- goto out_clean;
- }
-
- printf("Setting MTU to 9000\n");
- expected_mtu = 9000;
- if (nozzle_set_mtu(nozzle, expected_mtu) < 0) {
- printf("Unable to set MTU to %d\n", expected_mtu);
- err = -1;
- goto out_clean;
- }
-
- current_mtu = nozzle_get_mtu(nozzle);
- if (current_mtu < 0) {
- printf("Unable to get MTU\n");
- err = -1;
- goto out_clean;
- }
- if (current_mtu != expected_mtu) {
- printf("current mtu [%d] does not match expected value [%d]\n", current_mtu, expected_mtu);
- err = -1;
- goto out_clean;
- }
-
- printf("Testing ERROR conditions\n");
-
- printf("Passing empty struct to get_mtu\n");
- if (nozzle_get_mtu(NULL) > 0) {
- printf("Something is wrong in nozzle_get_mtu sanity checks\n");
- err = -1;
- goto out_clean;
- }
-
- printf("Passing empty struct to set_mtu\n");
- if (nozzle_set_mtu(NULL, 1500) == 0) {
- printf("Something is wrong in nozzle_set_mtu sanity checks\n");
- err = -1;
- goto out_clean;
- }
-
-out_clean:
- if (nozzle) {
- nozzle_close(nozzle);
- }
-
- return err;
-}
-
-static int check_knet_mtu_ipv6(void)
-{
- char device_name[IFNAMSIZ];
- size_t size = IFNAMSIZ;
- char verifycmd[2048];
- int err=0;
- nozzle_t nozzle;
- char *error_string = NULL;
-
- printf("Testing get/set MTU with IPv6 address\n");
-
- memset(device_name, 0, size);
-
- nozzle = nozzle_open(device_name, size, NULL);
- if (!nozzle) {
- printf("Unable to init %s\n", device_name);
- return -1;
- }
-
- printf("Adding ip: %s/64\n", testipv6_1);
-
- err = nozzle_add_ip(nozzle, testipv6_1, "64");
- if (err) {
- printf("Unable to assign IP address\n");
- err=-1;
- goto out_clean;
- }
-
- memset(verifycmd, 0, sizeof(verifycmd));
- snprintf(verifycmd, sizeof(verifycmd)-1,
-#ifdef KNET_LINUX
- "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_1);
-#endif
-#ifdef KNET_BSD
- "ifconfig %s | grep -q %s", nozzle->name, testipv6_1);
-#endif
- err = execute_bin_sh_command(verifycmd, &error_string);
- if (error_string) {
- printf("Error string: %s\n", error_string);
- free(error_string);
- error_string = NULL;
- }
- if (err) {
- printf("Unable to verify IP address\n");
- err=-1;
- goto out_clean;
- }
-
- printf("Setting MTU to 1200\n");
- if (nozzle_set_mtu(nozzle, 1200) < 0) {
- printf("Unable to set MTU to 1200\n");
- err = -1;
- goto out_clean;
- }
-
- err = execute_bin_sh_command(verifycmd, &error_string);
- if (error_string) {
- printf("Error string: %s\n", error_string);
- free(error_string);
- error_string = NULL;
- }
-#ifdef KNET_LINUX
- if (!err) {
-#endif
-#ifdef KNET_BSD
- if (err) {
-#endif
- printf("Unable to verify IP address\n");
- err=-1;
- goto out_clean;
- }
-
- printf("Adding ip: %s/64\n", testipv6_2);
- err = nozzle_add_ip(nozzle, testipv6_2, "64");
- if (err < 0) {
- printf("Unable to assign IP address\n");
- err=-1;
- goto out_clean;
- }
-
- memset(verifycmd, 0, sizeof(verifycmd));
- snprintf(verifycmd, sizeof(verifycmd)-1,
-#ifdef KNET_LINUX
- "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_2);
-#endif
-#ifdef KNET_BSD
- "ifconfig %s | grep -q %s", nozzle->name, testipv6_2);
-#endif
- err = execute_bin_sh_command(verifycmd, &error_string);
- if (error_string) {
- printf("Error string: %s\n", error_string);
- free(error_string);
- error_string = NULL;
- }
- if (!err) {
- printf("Unable to verify IP address\n");
- err=-1;
- goto out_clean;
- }
-
- printf("Restoring MTU to default\n");
- if (nozzle_reset_mtu(nozzle) < 0) {
- printf("Unable to reset mtu\n");
- err = -1;
- goto out_clean;
- }
-
- memset(verifycmd, 0, sizeof(verifycmd));
- snprintf(verifycmd, sizeof(verifycmd)-1,
-#ifdef KNET_LINUX
- "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_1);
-#endif
-#ifdef KNET_BSD
- "ifconfig %s | grep -q %s", nozzle->name, testipv6_1);
-#endif
- err = execute_bin_sh_command(verifycmd, &error_string);
- if (error_string) {
- printf("Error string: %s\n", error_string);
- free(error_string);
- error_string = NULL;
- }
- if (err) {
- printf("Unable to verify IP address\n");
- err=-1;
- goto out_clean;
- }
-
- memset(verifycmd, 0, sizeof(verifycmd));
- snprintf(verifycmd, sizeof(verifycmd)-1,
-#ifdef KNET_LINUX
- "ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_2);
-#endif
-#ifdef KNET_BSD
- "ifconfig %s | grep -q %s", nozzle->name, testipv6_2);
-#endif
- err = execute_bin_sh_command(verifycmd, &error_string);
- if (error_string) {
- printf("Error string: %s\n", error_string);
- free(error_string);
- error_string = NULL;
- }
- if (err) {
- printf("Unable to verify IP address\n");
- err=-1;
- goto out_clean;
- }
-
-out_clean:
- if (nozzle) {
- nozzle_close(nozzle);
- }
-
- return err;
-}
-
static int check_knet_mac(void)
{
char device_name[IFNAMSIZ];
size_t size = IFNAMSIZ;
int err=0;
nozzle_t nozzle;
char *current_mac = NULL, *temp_mac = NULL, *err_mac = NULL;
struct ether_addr *cur_mac, *tmp_mac;
printf("Testing get/set MAC\n");
memset(device_name, 0, size);
nozzle = nozzle_open(device_name, size, NULL);
if (!nozzle) {
printf("Unable to init %s\n", device_name);
return -1;
}
printf("Get current MAC\n");
if (nozzle_get_mac(nozzle, &current_mac) < 0) {
printf("Unable to get current MAC address.\n");
err = -1;
goto out_clean;
}
printf("Current MAC: %s\n", current_mac);
printf("Setting MAC: 00:01:01:01:01:01\n");
if (nozzle_set_mac(nozzle, "00:01:01:01:01:01") < 0) {
printf("Unable to set current MAC address.\n");
err = -1;
goto out_clean;
}
if (nozzle_get_mac(nozzle, &temp_mac) < 0) {
printf("Unable to get current MAC address.\n");
err = -1;
goto out_clean;
}
printf("Current MAC: %s\n", temp_mac);
cur_mac = ether_aton(current_mac);
tmp_mac = ether_aton(temp_mac);
printf("Comparing MAC addresses\n");
if (memcmp(cur_mac, tmp_mac, sizeof(struct ether_addr))) {
printf("Mac addresses are not the same?!\n");
err = -1;
goto out_clean;
}
printf("Testing ERROR conditions\n");
printf("Pass NULL to get_mac (pass1)\n");
errno = 0;
if ((nozzle_get_mac(NULL, &err_mac) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_get_mac sanity checks\n");
err = -1;
goto out_clean;
}
printf("Pass NULL to get_mac (pass2)\n");
errno = 0;
if ((nozzle_get_mac(nozzle, NULL) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_get_mac sanity checks\n");
err = -1;
goto out_clean;
}
printf("Pass NULL to set_mac (pass1)\n");
errno = 0;
if ((nozzle_set_mac(nozzle, NULL) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_mac sanity checks\n");
err = -1;
goto out_clean;
}
printf("Pass NULL to set_mac (pass2)\n");
errno = 0;
if ((nozzle_set_mac(NULL, err_mac) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_mac sanity checks\n");
err = -1;
goto out_clean;
}
out_clean:
if (err_mac) {
printf("Something managed to set err_mac!\n");
err = -1;
free(err_mac);
}
if (current_mac)
free(current_mac);
if (temp_mac)
free(temp_mac);
if (nozzle) {
nozzle_close(nozzle);
}
return err;
}
static int check_nozzle_execute_bin_sh_command(void)
{
int err = 0;
char command[4096];
char *error_string = NULL;
memset(command, 0, sizeof(command));
printf("Testing execute_bin_sh_command\n");
printf("command true\n");
err = execute_bin_sh_command("true", &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (err) {
printf("Unable to execute true ?!?!\n");
goto out_clean;
}
printf("Testing ERROR conditions\n");
printf("command false\n");
err = execute_bin_sh_command("false", &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (!err) {
printf("Can we really execute false successfully?!?!\n");
err = -1;
goto out_clean;
}
printf("command that outputs to stdout (enforcing redirect)\n");
err = execute_bin_sh_command("grep -h 2>&1", &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (!err) {
printf("Can we really execute grep -h successfully?!?\n");
err = -1;
goto out_clean;
}
printf("command that outputs to stderr\n");
err = execute_bin_sh_command("grep -h", &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (!err) {
printf("Can we really execute grep -h successfully?!?\n");
err = -1;
goto out_clean;
}
printf("empty command\n");
err = execute_bin_sh_command(NULL, &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (!err) {
printf("Can we really execute (nil) successfully?!?!\n");
err = -1;
goto out_clean;
}
printf("empty error\n");
err = execute_bin_sh_command("true", NULL);
if (!err) {
printf("Check EINVAL filter for no error_string!\n");
err = -1;
goto out_clean;
}
err = 0;
out_clean:
return err;
}
static int check_knet_up_down(void)
{
char verifycmd[1024];
char device_name[IFNAMSIZ];
size_t size = IFNAMSIZ;
int err=0;
nozzle_t nozzle;
char *error_string = NULL;
printf("Testing interface up/down\n");
memset(device_name, 0, size);
nozzle = nozzle_open(device_name, size, NULL);
if (!nozzle) {
printf("Unable to init %s\n", device_name);
return -1;
}
printf("Put the interface up\n");
err = nozzle_set_up(nozzle);
if (err < 0) {
printf("Unable to set interface up\n");
err = -1;
goto out_clean;
}
memset(verifycmd, 0, sizeof(verifycmd));
snprintf(verifycmd, sizeof(verifycmd)-1,
#ifdef KNET_LINUX
"ip addr show dev %s | grep -q UP", nozzle->name);
#endif
#ifdef KNET_BSD
"ifconfig %s | grep -q UP", nozzle->name);
#endif
err = execute_bin_sh_command(verifycmd, &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (err < 0) {
printf("Unable to verify inteface UP\n");
err = -1;
goto out_clean;
}
printf("Put the interface down\n");
err = nozzle_set_down(nozzle);
if (err < 0) {
printf("Unable to put the interface down\n");
err = -1;
goto out_clean;
}
memset(verifycmd, 0, sizeof(verifycmd));
snprintf(verifycmd, sizeof(verifycmd)-1,
#ifdef KNET_LINUX
"ip addr show dev %s | grep -q UP", nozzle->name);
#endif
#ifdef KNET_BSD
"ifconfig %s | grep -q UP", nozzle->name);
#endif
err = execute_bin_sh_command(verifycmd, &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (!err) {
printf("Unable to verify inteface DOWN\n");
err = -1;
goto out_clean;
}
nozzle_close(nozzle);
printf("Testing interface pre-up/up/down/post-down (exec errors)\n");
memset(device_name, 0, size);
nozzle = nozzle_open(device_name, size, ABSBUILDDIR "/nozzle_updown_bad");
if (!nozzle) {
printf("Unable to init %s\n", device_name);
return -1;
}
printf("Put the interface up\n");
err = nozzle_run_updown(nozzle, NOZZLE_PREUP, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_PREUP error: %s\n", strerror(errno));
}
if (error_string) {
printf("preup output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
err = nozzle_set_up(nozzle);
if (err < 0) {
printf("Unable to put the interface up\n");
err = -1;
goto out_clean;
}
err = nozzle_run_updown(nozzle, NOZZLE_UP, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_UP error: %s\n", strerror(errno));
}
if (error_string) {
printf("up output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
printf("Put the interface down\n");
err = nozzle_run_updown(nozzle, NOZZLE_DOWN, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_DOWN error: %s\n", strerror(errno));
}
if (error_string) {
printf("down output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
err = nozzle_set_down(nozzle);
if (err < 0) {
printf("Unable to put the interface down\n");
err = -1;
goto out_clean;
}
err = nozzle_run_updown(nozzle, NOZZLE_POSTDOWN, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_POSTDOWN error: %s\n", strerror(errno));
}
if (error_string) {
printf("postdown output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
nozzle_close(nozzle);
printf("Testing interface pre-up/up/down/post-down\n");
memset(device_name, 0, size);
nozzle = nozzle_open(device_name, size, ABSBUILDDIR "/nozzle_updown_good");
if (!nozzle) {
printf("Unable to init %s\n", device_name);
return -1;
}
printf("Put the interface up\n");
err = nozzle_run_updown(nozzle, NOZZLE_PREUP, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_PREUP error: %s\n", strerror(errno));
}
if (error_string) {
printf("preup output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
err = nozzle_set_up(nozzle);
if (err < 0) {
printf("Unable to put the interface up\n");
err = -1;
goto out_clean;
}
err = nozzle_run_updown(nozzle, NOZZLE_UP, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_UP error: %s\n", strerror(errno));
}
if (error_string) {
printf("up output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
printf("Put the interface down\n");
err = nozzle_run_updown(nozzle, NOZZLE_DOWN, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_DOWN error: %s\n", strerror(errno));
}
if (error_string) {
printf("down output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
err = nozzle_set_down(nozzle);
if (err < 0) {
printf("Unable to put the interface down\n");
err = -1;
goto out_clean;
}
err = nozzle_run_updown(nozzle, NOZZLE_POSTDOWN, &error_string);
if (err) {
printf("nozzle_run_updown NOZZLE_POSTDOWN error: %s\n", strerror(errno));
}
if (error_string) {
printf("postdown output: %s\n", error_string);
free(error_string);
error_string = NULL;
}
nozzle_close(nozzle);
printf("Test ERROR conditions\n");
printf("Pass NULL to nozzle set_up\n");
err = 0;
errno = 0;
if ((nozzle_set_up(NULL) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_up sanity checks\n");
err = -1;
goto out_clean;
}
printf("Pass NULL to nozzle set_down\n");
errno = 0;
if ((nozzle_set_down(NULL) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_down sanity checks\n");
err = -1;
goto out_clean;
}
out_clean:
nozzle_close(nozzle);
return err;
}
static int check_knet_set_del_ip(void)
{
char device_name[IFNAMSIZ];
size_t size = IFNAMSIZ;
char verifycmd[2048];
int err = 0;
nozzle_t nozzle;
struct nozzle_ip *ip_list = NULL, *ip_list_tmp = NULL;
int ip_list_entries = 0;
char *error_string = NULL;
printf("Testing interface add/remove ip\n");
memset(device_name, 0, size);
nozzle = nozzle_open(device_name, size, NULL);
if (!nozzle) {
printf("Unable to init %s\n", device_name);
return -1;
}
printf("Adding ip: %s/24\n", testipv4_1);
err = nozzle_add_ip(nozzle, testipv4_1, "24");
if (err < 0) {
printf("Unable to assign IP address\n");
err=-1;
goto out_clean;
}
printf("Adding ip: %s/24\n", testipv4_2);
err = nozzle_add_ip(nozzle, testipv4_2, "24");
if (err < 0) {
printf("Unable to assign IP address\n");
err=-1;
goto out_clean;
}
printf("Adding duplicate ip: %s/24\n", testipv4_1);
err = nozzle_add_ip(nozzle, testipv4_1, "24");
if (err < 0) {
printf("Unable to find IP address in libnozzle db\n");
err=-1;
goto out_clean;
}
printf("Checking ip: %s/24\n", testipv4_1);
memset(verifycmd, 0, sizeof(verifycmd));
snprintf(verifycmd, sizeof(verifycmd)-1,
#ifdef KNET_LINUX
"ip addr show dev %s | grep -q %s/24", nozzle->name, testipv4_1);
#endif
#ifdef KNET_BSD
"ifconfig %s | grep -q %s", nozzle->name, testipv4_1);
#endif
err = execute_bin_sh_command(verifycmd, &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (err) {
printf("Unable to verify IP address\n");
err=-1;
goto out_clean;
}
printf("Get ip list from libnozzle:\n");
if (nozzle_get_ips(nozzle, &ip_list) < 0) {
printf("Not enough mem?\n");
err=-1;
goto out_clean;
}
ip_list_tmp = ip_list;
ip_list_entries = 0;
while(ip_list_tmp) {
ip_list_entries++;
printf("Found IP %s %s in libnozzle db\n", ip_list_tmp->ipaddr, ip_list_tmp->prefix);
ip_list_tmp = ip_list_tmp->next;
}
if (ip_list_entries != 2) {
printf("Didn't get enough ip back from libnozzle?\n");
err=-1;
goto out_clean;
}
printf("Deleting ip: %s/24\n", testipv4_1);
err = nozzle_del_ip(nozzle, testipv4_1, "24");
if (err < 0) {
printf("Unable to delete IP address\n");
err=-1;
goto out_clean;
}
printf("Deleting ip: %s/24\n", testipv4_2);
err = nozzle_del_ip(nozzle, testipv4_2, "24");
if (err < 0) {
printf("Unable to delete IP address\n");
err=-1;
goto out_clean;
}
printf("Deleting again ip: %s/24\n", testipv4_1);
err = nozzle_del_ip(nozzle, testipv4_1, "24");
if (err < 0) {
printf("Unable to delete IP address\n");
err=-1;
goto out_clean;
}
memset(verifycmd, 0, sizeof(verifycmd));
snprintf(verifycmd, sizeof(verifycmd)-1,
#ifdef KNET_LINUX
"ip addr show dev %s | grep -q %s/24", nozzle->name, testipv4_1);
#endif
#ifdef KNET_BSD
"ifconfig %s | grep -q %s", nozzle->name, testipv4_1);
#endif
err = execute_bin_sh_command(verifycmd, &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (!err) {
printf("Unable to verify IP address\n");
err=-1;
goto out_clean;
}
printf("Adding ip: %s/64\n", testipv6_1);
err = nozzle_add_ip(nozzle, testipv6_1, "64");
if (err < 0) {
printf("Unable to assign IP address\n");
err=-1;
goto out_clean;
}
memset(verifycmd, 0, sizeof(verifycmd));
snprintf(verifycmd, sizeof(verifycmd)-1,
#ifdef KNET_LINUX
"ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_1);
#endif
#ifdef KNET_BSD
"ifconfig %s | grep -q %s", nozzle->name, testipv6_1);
#endif
err = execute_bin_sh_command(verifycmd, &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (err) {
printf("Unable to verify IP address\n");
err=-1;
goto out_clean;
}
printf("Deleting ip: %s/64\n", testipv6_1);
err = nozzle_del_ip(nozzle, testipv6_1, "64");
if (err) {
printf("Unable to delete IP address\n");
err=-1;
goto out_clean;
}
memset(verifycmd, 0, sizeof(verifycmd));
snprintf(verifycmd, sizeof(verifycmd)-1,
#ifdef KNET_LINUX
"ip addr show dev %s | grep -q %s/64", nozzle->name, testipv6_1);
#endif
#ifdef KNET_BSD
"ifconfig %s | grep -q %s", nozzle->name, testipv6_1);
#endif
err = execute_bin_sh_command(verifycmd, &error_string);
if (error_string) {
printf("Error string: %s\n", error_string);
free(error_string);
error_string = NULL;
}
if (!err) {
printf("Unable to verify IP address\n");
err=-1;
goto out_clean;
}
out_clean:
nozzle_close(nozzle);
return err;
}
int main(void)
{
need_root();
make_local_ips(testipv4_1, testipv4_2, testipv6_1, testipv6_2);
- if (check_knet_mtu() < 0)
- return -1;
-
- if (check_knet_mtu_ipv6() < 0)
- return -1;
-
if (check_knet_mac() < 0)
return -1;
if (check_nozzle_execute_bin_sh_command() < 0)
return -1;
if (check_knet_up_down() < 0)
return -1;
if (check_knet_set_del_ip() < 0)
return -1;
return 0;
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 11:34 AM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1018684
Default Alt Text
(34 KB)

Event Timeline