diff options
author | Robert Mustacchi <rm@joyent.com> | 2017-05-03 00:43:49 +0000 |
---|---|---|
committer | Robert Mustacchi <rm@joyent.com> | 2017-05-03 20:39:01 +0000 |
commit | e14f48674b1d80f3f8d374fdd837d53e312aa7d7 (patch) | |
tree | cf0a0e96e9e7c24bcb547b0461f3f9edc201fa49 | |
parent | 3a0d591b2c17c128db3a54e83e8d0ee2742271ae (diff) | |
download | illumos-joyent-e14f48674b1d80f3f8d374fdd837d53e312aa7d7.tar.gz |
OS-6097 snoop reports "Is a directory" for non-existent VNIC
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: Jerry Jelinek <jerry.jelinek@joyent.com>
-rw-r--r-- | usr/src/lib/libdlpi/common/libdlpi.c | 12 | ||||
-rw-r--r-- | usr/src/test/os-tests/runfiles/default.run | 3 | ||||
-rw-r--r-- | usr/src/test/os-tests/tests/Makefile | 57 | ||||
-rw-r--r-- | usr/src/test/os-tests/tests/OS-6097.c | 74 |
4 files changed, 140 insertions, 6 deletions
diff --git a/usr/src/lib/libdlpi/common/libdlpi.c b/usr/src/lib/libdlpi/common/libdlpi.c index aa97afee04..d07eea70e7 100644 --- a/usr/src/lib/libdlpi/common/libdlpi.c +++ b/usr/src/lib/libdlpi/common/libdlpi.c @@ -23,7 +23,7 @@ * Use is subject to license terms. */ /* - * Copyright (c) 2014, Joyent, Inc. + * Copyright (c) 2017, Joyent, Inc. */ /* @@ -1088,10 +1088,12 @@ i_dlpi_open(const char *provider, const char *zonename, int *fd, uint_t flags, (void) snprintf(path, sizeof (path), "/dev/ipnet/%s", provider); } - if ((*fd = open(path, oflags)) != -1) + if ((*fd = open(path, oflags)) != -1) { return (DLPI_SUCCESS); - else - return (errno == ENOENT ? DLPI_ENOLINK : DL_SYSERR); + } else { + return (errno == ENOENT || errno == EISDIR ? + DLPI_ENOLINK : DL_SYSERR); + } } else if (style1 && !(flags & DLPI_DEVONLY)) { char driver[DLPI_LINKNAME_MAX]; char device[DLPI_LINKNAME_MAX]; @@ -1160,7 +1162,7 @@ fallback: if ((*fd = open(path, oflags)) != -1) return (DLPI_SUCCESS); - return (errno == ENOENT ? DLPI_ENOLINK : DL_SYSERR); + return (errno == ENOENT || errno == EISDIR ? DLPI_ENOLINK : DL_SYSERR); } /* diff --git a/usr/src/test/os-tests/runfiles/default.run b/usr/src/test/os-tests/runfiles/default.run index eca82268c0..db212b8113 100644 --- a/usr/src/test/os-tests/runfiles/default.run +++ b/usr/src/test/os-tests/runfiles/default.run @@ -58,3 +58,6 @@ tests = ['tmpfs_badmount', 'tmpfs_enospc'] [/opt/os-tests/tests/file-locking] tests = ['runtests.32', 'runtests.64'] + +[/opt/os-tests/tests/OS-6097.32] +[/opt/os-tests/tests/OS-6097.64] diff --git a/usr/src/test/os-tests/tests/Makefile b/usr/src/test/os-tests/tests/Makefile index b4330ae706..c0391d45bd 100644 --- a/usr/src/test/os-tests/tests/Makefile +++ b/usr/src/test/os-tests/tests/Makefile @@ -16,4 +16,59 @@ SUBDIRS = poll secflags sigqueue spoof-ras sdevfs timer tmpfs file-locking -include $(SRC)/test/Makefile.com +PROGS = \ + OS-6097 + +PROGS32 = $(PROGS:%=%.32) +PROGS64 = $(PROGS:%=%.64) + +OS-6097.32 := LDLIBS += -ldlpi +OS-6097.64 := LDLIBS64 += -ldlpi + +ROOTOPTDIR = $(ROOT)/opt/os-tests/tests +ROOTOPTPROGS = $(PROGS32:%=$(ROOTOPTDIR)/%) \ + $(PROGS64:%=$(ROOTOPTDIR)/%) \ + $(SCRIPTS:%=$(ROOTOPTDIR)/%) + +include $(SRC)/cmd/Makefile.cmd + +all := TARGET = all +install := TARGET = install +clean := TARGET = clean +clobber := TARGET = clobber +lint := TARGET = lint + +.KEEP_STATE: + +install: $(SUBDIRS) $(ROOTOPTPROGS) + +all: $(SUBDIRS) $(PROGS32) $(PROGS64) + +clean lint: $(SUBDIRS) + +$(ROOTOPTPROGS): $(PROGS32) $(PROGS64) $(ROOTOPTDIR) + +$(ROOTOPTDIR): + $(INS.dir) + +$(ROOTOPTDIR)/%: % + $(INS.file) + +$(ROOTOPTDIR)/%: %.ksh + $(INS.rename) + +%.64: %.c + $(LINK64.c) -o $@ $< $(LDLIBS64) + $(POST_PROCESS) + +%.32: %.c + $(LINK.c) -o $@ $< $(LDLIBS) + $(POST_PROCESS) + +clobber: $(SUBDIRS) + $(RM) $(PROGS32) $(PROGS64) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/test/os-tests/tests/OS-6097.c b/usr/src/test/os-tests/tests/OS-6097.c new file mode 100644 index 0000000000..160c01e9c7 --- /dev/null +++ b/usr/src/test/os-tests/tests/OS-6097.c @@ -0,0 +1,74 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2017, Joyent, Inc. + */ + +/* + * Regression test for OS-6097. + */ + +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <libdlpi.h> +#include <sys/debug.h> + +int +main(void) +{ + int ret; + char path[4096]; + uint_t num = 4294967294U; + dlpi_handle_t dh; + + /* + * First, we need to determine a path that doesn't exist to trigger this + * bug. We start with the highest possible number and just decrement + * until we find something. + */ + + while (num > 0) { + struct stat st; + + (void) snprintf(path, sizeof (path), "/dev/net/net%u", num); + + ret = stat(path, &st); + if (ret == -1 && errno == ENOENT) + break; + if (ret == -1) { + (void) fprintf(stderr, "test failed: unexpected error " + "running stat(2) on %s: %s\n", path, + strerror(errno)); + return (1); + } + num--; + } + + /* + * While technically this is a valid entry that we could try, at this + * point we've exhausted so many NICs, there's likely a bug. + */ + if (num == 0) { + (void) fprintf(stderr, "failed to construct a non-existent " + "NIC with a name starting with 'net'\n"); + return (1); + } + + (void) snprintf(path, sizeof (path), "net%u", num); + ret = dlpi_open(path, &dh, 0); + VERIFY3U(ret, ==, DLPI_ENOLINK); + return (0); +} |