summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@joyent.com>2013-09-29 14:27:52 -0700
committerRobert Mustacchi <rm@joyent.com>2013-11-06 08:09:36 -0800
commitfe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1 (patch)
treeb5723fc87b94e5c73aa9c243dc40e6dac6ef5440 /usr/src/lib
parentc6d054cbc999e5c8b9ad1aa01dbb4800b84f06bd (diff)
downloadillumos-joyent-fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1.tar.gz
4236 Internet Packet Disturber
4237 net_* and hook_* man pages are wrong Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Brendan Gregg <brendan.gregg@joyent.com> Reviewed by: Keith M Wesolowski <wesolows@foobazco.org> Reviewed by: Sebastien Roy <seb@delphix.com> Approved by: Dan McDonald <danmcd@nexenta.com>
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/Makefile2
-rw-r--r--usr/src/lib/libipd/Makefile42
-rw-r--r--usr/src/lib/libipd/Makefile.com36
-rw-r--r--usr/src/lib/libipd/amd64/Makefile19
-rw-r--r--usr/src/lib/libipd/common/libipd.c303
-rw-r--r--usr/src/lib/libipd/common/libipd.h74
-rw-r--r--usr/src/lib/libipd/common/llib-lipd20
-rw-r--r--usr/src/lib/libipd/common/mapfile-vers46
-rw-r--r--usr/src/lib/libipd/i386/Makefile18
-rw-r--r--usr/src/lib/libipd/sparc/Makefile18
-rw-r--r--usr/src/lib/libipd/sparcv9/Makefile19
11 files changed, 597 insertions, 0 deletions
diff --git a/usr/src/lib/Makefile b/usr/src/lib/Makefile
index fe1035b59b..fe579b4c9d 100644
--- a/usr/src/lib/Makefile
+++ b/usr/src/lib/Makefile
@@ -105,6 +105,7 @@ SUBDIRS += \
libcryptoutil \
libinetutil \
libipadm \
+ libipd \
libipmp \
libiscsit \
libkmf \
@@ -407,6 +408,7 @@ HDRSUBDIRS= \
libfstyp \
libgen \
libipadm \
+ libipd \
libipsecutil \
libinetsvc \
libinetutil \
diff --git a/usr/src/lib/libipd/Makefile b/usr/src/lib/libipd/Makefile
new file mode 100644
index 0000000000..feab972218
--- /dev/null
+++ b/usr/src/lib/libipd/Makefile
@@ -0,0 +1,42 @@
+#
+# 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 2012 Joyent, Inc. All rights reserved.
+#
+
+include ../Makefile.lib
+
+HDRS = libipd.h
+HDRDIR = common
+SUBDIRS = $(MACH)
+$(BUILD64)SUBDIRS += $(MACH64)
+
+all := TARGET = all
+clean := TARGET = clean
+clobber := TARGET = clobber
+install := TARGET = install
+lint := TARGET = lint
+
+.KEEP_STATE:
+
+all clean clobber install lint: $(SUBDIRS)
+
+install_h: $(ROOTHDRS)
+
+check: $(CHECKHDRS)
+
+$(SUBDIRS): FRC
+ @cd $@; pwd; $(MAKE) $(TARGET)
+
+FRC:
+
+include ../Makefile.targ
diff --git a/usr/src/lib/libipd/Makefile.com b/usr/src/lib/libipd/Makefile.com
new file mode 100644
index 0000000000..f118aa6cc3
--- /dev/null
+++ b/usr/src/lib/libipd/Makefile.com
@@ -0,0 +1,36 @@
+#
+# 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 2012 Joyent, Inc. All rights reserved.
+#
+
+include ../../Makefile.lib
+
+LIBRARY = libipd.a
+VERS = .1
+OBJECTS = libipd.o
+
+include ../../Makefile.lib
+
+LIBS = $(DYNLIB) $(LINTLIB)
+LDLIBS += -lc
+CPPFLAGS += -I../common
+
+SRCDIR = ../common
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+lint: lintcheck
+
+include ../../Makefile.targ
diff --git a/usr/src/lib/libipd/amd64/Makefile b/usr/src/lib/libipd/amd64/Makefile
new file mode 100644
index 0000000000..0ff7206916
--- /dev/null
+++ b/usr/src/lib/libipd/amd64/Makefile
@@ -0,0 +1,19 @@
+#
+# 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 2012 Joyent, Inc. All rights reserved.
+#
+
+include ../Makefile.com
+include ../../Makefile.lib.64
+
+install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64)
diff --git a/usr/src/lib/libipd/common/libipd.c b/usr/src/lib/libipd/common/libipd.c
new file mode 100644
index 0000000000..c580fdf61e
--- /dev/null
+++ b/usr/src/lib/libipd/common/libipd.c
@@ -0,0 +1,303 @@
+/*
+ * 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) 2012 Joyent, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#include <libipd.h>
+#include <sys/ipd.h>
+
+__thread ipd_errno_t ipd_errno = 0;
+__thread char ipd_errmsg[512];
+
+struct ipd_stat {
+ uint_t is_nzones;
+ zoneid_t *is_zoneids;
+ struct ipd_config *is_configs;
+};
+
+static ipd_errno_t
+xlate_errno(int e)
+{
+ switch (e) {
+ case 0:
+ return (EIPD_NOERROR);
+ case ENOMEM:
+ case EAGAIN:
+ return (EIPD_NOMEM);
+ case ERANGE:
+ return (EIPD_RANGE);
+ case EPERM:
+ return (EIPD_PERM);
+ case EFAULT:
+ return (EIPD_FAULT);
+ case ENOTTY:
+ return (EIPD_INTERNAL);
+ default:
+ return (EIPD_UNKNOWN);
+ }
+}
+
+const char *
+ipd_strerror(ipd_errno_t e)
+{
+ switch (e) {
+ case EIPD_NOERROR:
+ return ("no error");
+ case EIPD_NOMEM:
+ return ("out of memory");
+ case EIPD_ZC_NOENT:
+ return ("zone does not exist or is not using ipd");
+ case EIPD_RANGE:
+ return ("argument out of range");
+ case EIPD_PERM:
+ return ("permission denied");
+ case EIPD_FAULT:
+ return ("bad pointer");
+ case EIPD_INTERNAL:
+ return ("internal library error");
+ case EIPD_UNKNOWN:
+ default:
+ return ("unknown error");
+ }
+}
+
+static int
+ipd_set_errno(ipd_errno_t e, const char *fmt, ...)
+{
+ va_list ap;
+
+ ipd_errno = e;
+ if (fmt != NULL) {
+ va_start(ap, fmt);
+ (void) vsnprintf(ipd_errmsg, sizeof (ipd_errmsg), fmt, ap);
+ va_end(ap);
+ } else {
+ (void) strlcpy(ipd_errmsg,
+ ipd_strerror(e), sizeof (ipd_errmsg));
+ }
+
+ return (-1);
+}
+
+int
+ipd_open(const char *path)
+{
+ int fd;
+
+ if (path == NULL)
+ path = IPD_DEV_PATH;
+
+ fd = open(path, O_RDWR);
+ if (fd < 0) {
+ return (ipd_set_errno(xlate_errno(errno),
+ "unable to open %s: %s", path, strerror(errno)));
+ }
+
+ return (fd);
+}
+
+int
+ipd_close(int fd)
+{
+ (void) close(fd);
+ return (0);
+}
+
+int
+ipd_status_read(int fd, ipd_stathdl_t *ispp)
+{
+ struct ipd_stat *isp = NULL;
+ ipd_ioc_list_t ipil;
+ uint_t rzones;
+ uint_t i;
+
+ bzero(&ipil, sizeof (ipil));
+ if (ioctl(fd, IPDIOC_LIST, &ipil) != 0) {
+ return (ipd_set_errno(xlate_errno(errno),
+ "unable to retrieve ipd zone list: %s", strerror(errno)));
+ }
+
+ for (;;) {
+ if ((rzones = ipil.ipil_nzones) == 0)
+ break;
+
+ ipil.ipil_info =
+ malloc(sizeof (ipd_ioc_info_t) * ipil.ipil_nzones);
+ if (ipil.ipil_info == NULL)
+ return (ipd_set_errno(EIPD_NOMEM, NULL));
+
+ if (ioctl(fd, IPDIOC_LIST, &ipil) != 0) {
+ free(ipil.ipil_info);
+ return (ipd_set_errno(xlate_errno(errno),
+ "unable to retrieve ipd zone list: %s",
+ strerror(errno)));
+ }
+
+ if (ipil.ipil_nzones <= rzones)
+ break;
+
+ free(ipil.ipil_info);
+ }
+
+ if ((isp = malloc(sizeof (struct ipd_stat))) == NULL) {
+ free(ipil.ipil_info);
+ return (ipd_set_errno(EIPD_NOMEM, NULL));
+ }
+
+ isp->is_nzones = ipil.ipil_nzones;
+
+ if (isp->is_nzones == 0) {
+ isp->is_zoneids = NULL;
+ isp->is_configs = NULL;
+ *ispp = isp;
+ return (0);
+ }
+
+ isp->is_zoneids = malloc(sizeof (zoneid_t) * ipil.ipil_nzones);
+ if (isp->is_zoneids == NULL) {
+ free(ipil.ipil_info);
+ free(isp);
+ return (ipd_set_errno(EIPD_NOMEM, NULL));
+ }
+ isp->is_configs = malloc(sizeof (struct ipd_config) * ipil.ipil_nzones);
+ if (isp->is_configs == NULL) {
+ free(ipil.ipil_info);
+ free(isp->is_zoneids);
+ free(isp);
+ return (ipd_set_errno(EIPD_NOMEM, NULL));
+ }
+
+ for (i = 0; i < isp->is_nzones; i++) {
+ isp->is_zoneids[i] = ipil.ipil_info[i].ipii_zoneid;
+
+ isp->is_configs[i].ic_corrupt = ipil.ipil_info[i].ipii_corrupt;
+ isp->is_configs[i].ic_drop = ipil.ipil_info[i].ipii_drop;
+ isp->is_configs[i].ic_delay = ipil.ipil_info[i].ipii_delay;
+
+ isp->is_configs[i].ic_mask =
+ ((!!isp->is_configs[i].ic_corrupt) * IPDM_CORRUPT) |
+ ((!!isp->is_configs[i].ic_drop) * IPDM_DROP) |
+ ((!!isp->is_configs[i].ic_delay) * IPDM_DELAY);
+ }
+
+ *ispp = isp;
+ return (0);
+}
+
+void
+ipd_status_foreach_zone(const ipd_stathdl_t hdl, ipd_status_cb_f f, void *arg)
+{
+ const struct ipd_stat *isp = hdl;
+ uint_t i;
+
+ for (i = 0; i < isp->is_nzones; i++)
+ f(isp->is_zoneids[i], &isp->is_configs[i], arg);
+}
+
+int
+ipd_status_get_config(const ipd_stathdl_t hdl, zoneid_t z, ipd_config_t **icpp)
+{
+ const struct ipd_stat *isp = hdl;
+ uint_t i;
+
+ for (i = 0; i < isp->is_nzones; i++) {
+ if (isp->is_zoneids[i] == z) {
+ *icpp = &isp->is_configs[i];
+ return (0);
+ }
+ }
+
+ return (ipd_set_errno(EIPD_ZC_NOENT,
+ "zone %d does not exist or has no ipd configuration", z));
+}
+
+void
+ipd_status_free(ipd_stathdl_t hdl)
+{
+ struct ipd_stat *isp = hdl;
+
+ if (isp != NULL) {
+ free(isp->is_zoneids);
+ free(isp->is_configs);
+ }
+ free(isp);
+}
+
+int
+ipd_ctl(int fd, zoneid_t z, const ipd_config_t *icp)
+{
+ ipd_ioc_perturb_t ipip;
+
+ bzero(&ipip, sizeof (ipd_ioc_perturb_t));
+ ipip.ipip_zoneid = z;
+
+ if (icp->ic_mask & IPDM_CORRUPT) {
+ if (icp->ic_corrupt == 0)
+ ipip.ipip_arg |= IPD_CORRUPT;
+ }
+ if (icp->ic_mask & IPDM_DELAY) {
+ if (icp->ic_delay == 0)
+ ipip.ipip_arg |= IPD_DELAY;
+ }
+ if (icp->ic_mask & IPDM_DROP) {
+ if (icp->ic_drop == 0)
+ ipip.ipip_arg |= IPD_DROP;
+ }
+
+ if (ipip.ipip_arg != 0 && ioctl(fd, IPDIOC_REMOVE, &ipip) != 0) {
+ return (ipd_set_errno(xlate_errno(errno),
+ "unable to remove cleared ipd settings: %s",
+ strerror(errno)));
+ }
+
+ if ((icp->ic_mask & IPDM_CORRUPT) && icp->ic_corrupt != 0) {
+ ipip.ipip_zoneid = z;
+ ipip.ipip_arg = icp->ic_corrupt;
+ if (ioctl(fd, IPDIOC_CORRUPT, &ipip) != 0) {
+ return (ipd_set_errno(xlate_errno(errno),
+ "unable to set corruption rate to %d: %s",
+ ipip.ipip_arg, strerror(errno)));
+ }
+ }
+ if ((icp->ic_mask & IPDM_DELAY) && icp->ic_delay != 0) {
+ ipip.ipip_zoneid = z;
+ ipip.ipip_arg = icp->ic_delay;
+ if (ioctl(fd, IPDIOC_DELAY, &ipip) != 0) {
+ return (ipd_set_errno(xlate_errno(errno),
+ "unable to set delay time to %d: %s",
+ ipip.ipip_arg, strerror(errno)));
+ }
+ }
+ if ((icp->ic_mask & IPDM_DROP) && icp->ic_drop != 0) {
+ ipip.ipip_zoneid = z;
+ ipip.ipip_arg = icp->ic_drop;
+ if (ioctl(fd, IPDIOC_DROP, &ipip) != 0) {
+ return (ipd_set_errno(xlate_errno(errno),
+ "unable to set drop probability to %d: %s",
+ ipip.ipip_arg, strerror(errno)));
+ }
+ }
+
+ return (0);
+}
diff --git a/usr/src/lib/libipd/common/libipd.h b/usr/src/lib/libipd/common/libipd.h
new file mode 100644
index 0000000000..ebf56aea1e
--- /dev/null
+++ b/usr/src/lib/libipd/common/libipd.h
@@ -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) 2012 Joyent, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _LIBIPD_H
+#define _LIBIPD_H
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Bitmask values for ic_mask.
+ */
+#define IPDM_CORRUPT 0x1000
+#define IPDM_DELAY 0x2000
+#define IPDM_DROP 0x4000
+
+typedef enum ipd_errno {
+ EIPD_NOERROR = 0,
+ EIPD_NOMEM,
+ EIPD_ZC_NOENT,
+ EIPD_RANGE,
+ EIPD_PERM,
+ EIPD_FAULT,
+ EIPD_INTERNAL,
+ EIPD_UNKNOWN
+} ipd_errno_t;
+
+typedef struct ipd_config {
+ uint32_t ic_mask;
+ uint32_t ic_corrupt;
+ uint32_t ic_drop;
+ uint32_t ic_delay;
+} ipd_config_t;
+
+struct ipd_stat;
+typedef struct ipd_stat *ipd_stathdl_t;
+
+typedef void (*ipd_status_cb_f)(zoneid_t, const ipd_config_t *, void *);
+
+extern __thread ipd_errno_t ipd_errno;
+extern __thread char ipd_errmsg[];
+
+extern const char *ipd_strerror(ipd_errno_t);
+extern int ipd_open(const char *);
+extern int ipd_close(int);
+extern int ipd_status_read(int, ipd_stathdl_t *);
+extern void ipd_status_foreach_zone(const ipd_stathdl_t,
+ ipd_status_cb_f, void *);
+extern int ipd_status_get_config(const ipd_stathdl_t,
+ zoneid_t, ipd_config_t **);
+extern void ipd_status_free(ipd_stathdl_t);
+extern int ipd_ctl(int, zoneid_t, const ipd_config_t *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LIBIPD_H */
diff --git a/usr/src/lib/libipd/common/llib-lipd b/usr/src/lib/libipd/common/llib-lipd
new file mode 100644
index 0000000000..79a3521301
--- /dev/null
+++ b/usr/src/lib/libipd/common/llib-lipd
@@ -0,0 +1,20 @@
+/*
+ * 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) 2012 Joyent, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* LINTLIBRARY */
+/* PROTOLIB1 */
+
+#include <libipd.h>
diff --git a/usr/src/lib/libipd/common/mapfile-vers b/usr/src/lib/libipd/common/mapfile-vers
new file mode 100644
index 0000000000..91c4632dea
--- /dev/null
+++ b/usr/src/lib/libipd/common/mapfile-vers
@@ -0,0 +1,46 @@
+#
+# 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) 2012 Joyent, Inc. All rights reserved.
+#
+
+#
+# MAPFILE HEADER START
+#
+# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
+# Object versioning must comply with the rules detailed in
+#
+# usr/src/lib/README.mapfiles
+#
+# You should not be making modifications here until you've read the most current
+# copy of that file. If you need help, contact a gatekeeper for guidance.
+#
+# MAPFILE HEADER END
+#
+
+$mapfile_version 2
+
+SYMBOL_VERSION SUNWprivate_1.1 {
+ global:
+ ipd_errno;
+ ipd_errmsg;
+ ipd_strerror;
+ ipd_open;
+ ipd_close;
+ ipd_status_read;
+ ipd_status_foreach_zone;
+ ipd_status_get_config;
+ ipd_status_free;
+ ipd_ctl;
+ local:
+ *;
+};
diff --git a/usr/src/lib/libipd/i386/Makefile b/usr/src/lib/libipd/i386/Makefile
new file mode 100644
index 0000000000..6a668fb98f
--- /dev/null
+++ b/usr/src/lib/libipd/i386/Makefile
@@ -0,0 +1,18 @@
+#
+# 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 2012 Joyent, Inc. All rights reserved.
+#
+
+include ../Makefile.com
+
+install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
diff --git a/usr/src/lib/libipd/sparc/Makefile b/usr/src/lib/libipd/sparc/Makefile
new file mode 100644
index 0000000000..6a668fb98f
--- /dev/null
+++ b/usr/src/lib/libipd/sparc/Makefile
@@ -0,0 +1,18 @@
+#
+# 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 2012 Joyent, Inc. All rights reserved.
+#
+
+include ../Makefile.com
+
+install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
diff --git a/usr/src/lib/libipd/sparcv9/Makefile b/usr/src/lib/libipd/sparcv9/Makefile
new file mode 100644
index 0000000000..0ff7206916
--- /dev/null
+++ b/usr/src/lib/libipd/sparcv9/Makefile
@@ -0,0 +1,19 @@
+#
+# 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 2012 Joyent, Inc. All rights reserved.
+#
+
+include ../Makefile.com
+include ../../Makefile.lib.64
+
+install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64)