@@ -16,7 +16,15 @@ BEGIN {
$v = " ";
}
- plan tests => 14;
+ $result = system("runcon -t test_tun_tap_t $basedir/tun_tap $v -c 2>&1");
+
+ # check for TUN/TAP support - ENOENT
+ if ( $result >> 8 eq 2 ) {
+ plan skip_all => "No TUN/TAP support";
+ }
+ else {
+ plan tests => 14;
+ }
}
############ Test tun_socket TUN #############
@@ -5,7 +5,7 @@ int open_dev(int *fd, char *test_str, bool verbose)
char *tun_dev = "/dev/net/tun";
*fd = open(tun_dev, O_RDWR);
- if (fd < 0) {
+ if (*fd < 0) {
fprintf(stderr, "Failed to open device: %s\n",
strerror(errno));
return errno;
@@ -5,6 +5,7 @@ static void print_usage(char *progname)
fprintf(stderr,
"usage: %s [-p] [-s ] [-v]\n"
"Where:\n\t"
+ "-c Check if TUN/TAP features are available.\n\t"
"-p Test TAP driver, default is TUN driver.\n\t"
"-s If -v, then show TUN/TAP Features.\n\t"
"-v Print information.\n", progname);
@@ -16,14 +17,17 @@ int main(int argc, char *argv[])
char *context, *test_str;
int opt, result, fd, bit, count, test;
unsigned int features, f_switch;
- bool verbose = false, show = false;
+ bool verbose = false, show = false, check = false;
struct ifreq ifr;
test = IFF_TUN;
test_str = "TUN";
- while ((opt = getopt(argc, argv, "psv")) != -1) {
+ while ((opt = getopt(argc, argv, "cpsv")) != -1) {
switch (opt) {
+ case 'c':
+ check = true;
+ break;
case 'p':
test = IFF_TAP;
test_str = "TAP";
@@ -52,7 +56,7 @@ int main(int argc, char *argv[])
/* Start TUN/TAP */
result = open_dev(&fd, test_str, verbose);
- if (result != 0)
+ if (check || result != 0)
exit(result);
if (verbose && show) {