summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/libipadm/common/ipadm_if.c96
-rw-r--r--usr/src/lib/libipadm/common/libipadm.h22
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.c106
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.h6
4 files changed, 141 insertions, 89 deletions
diff --git a/usr/src/lib/libipadm/common/ipadm_if.c b/usr/src/lib/libipadm/common/ipadm_if.c
index 41f22e4eeb..c140f4ca40 100644
--- a/usr/src/lib/libipadm/common/ipadm_if.c
+++ b/usr/src/lib/libipadm/common/ipadm_if.c
@@ -20,6 +20,7 @@
*/
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2021, Tintry by DDN. All rights reserved.
*/
#include <errno.h>
@@ -82,12 +83,12 @@ i_ipadm_is_if_down(char *ifname, struct ifaddrs *ifa)
*/
static ipadm_status_t
i_ipadm_active_if_info(ipadm_handle_t iph, const char *ifname,
- ipadm_if_info_t **if_info, int64_t lifc_flags)
+ ipadm_if_info_list_t **if_info, int64_t lifc_flags)
{
struct lifreq *buf;
struct lifreq *lifrp;
struct lifreq lifrl;
- ipadm_if_info_t *last = NULL;
+ ipadm_if_info_list_t *ifl, *last = NULL;
ipadm_if_info_t *ifp;
int s;
int n;
@@ -117,24 +118,26 @@ i_ipadm_active_if_info(ipadm_handle_t iph, const char *ifname,
* Check if the interface already exists in our list.
* If it already exists, we need to update its flags.
*/
- for (ifp = *if_info; ifp != NULL; ifp = ifp->ifi_next) {
+ for (ifl = *if_info; ifl != NULL; ifl = ifl->ifil_next) {
+ ifp = &ifl->ifil_ifi;
if (strcmp(lifrp->lifr_name, ifp->ifi_name) == 0)
break;
}
- if (ifp == NULL) {
- ifp = calloc(1, sizeof (ipadm_if_info_t));
- if (ifp == NULL) {
+ if (ifl == NULL) {
+ ifl = calloc(1, sizeof (ipadm_if_info_list_t));
+ if (ifl == NULL) {
status = ipadm_errno2status(errno);
goto fail;
}
+ ifp = &ifl->ifil_ifi;
(void) strlcpy(ifp->ifi_name, lifrp->lifr_name,
sizeof (ifp->ifi_name));
- /* Update the `ifi_next' pointer for this new node */
+ /* Update the `ifil_next' pointer for this new node */
if (*if_info == NULL)
- *if_info = ifp;
+ *if_info = ifl;
else
- last->ifi_next = ifp;
- last = ifp;
+ last->ifil_next = ifl;
+ last = ifl;
}
/*
@@ -188,12 +191,13 @@ fail:
*/
static ipadm_status_t
i_ipadm_persist_if_info(ipadm_handle_t iph, const char *ifname,
- ipadm_if_info_t **if_info)
+ ipadm_if_info_list_t **if_info)
{
ipadm_status_t status = IPADM_SUCCESS;
ipmgmt_getif_arg_t getif;
ipmgmt_getif_rval_t *rvalp;
- ipadm_if_info_t *ifp, *curr, *prev = NULL;
+ ipadm_if_info_t *ifp;
+ ipadm_if_info_list_t *curr, *prev = NULL;
int i = 0, err = 0;
bzero(&getif, sizeof (getif));
@@ -225,8 +229,8 @@ i_ipadm_persist_if_info(ipadm_handle_t iph, const char *ifname,
ipadm_free_if_info(prev);
break;
}
- (void) bcopy(ifp, curr, sizeof (*curr));
- curr->ifi_next = prev;
+ (void) bcopy(ifp, &curr->ifil_ifi, sizeof (*ifp));
+ curr->ifil_next = prev;
prev = curr;
}
*if_info = curr;
@@ -242,14 +246,16 @@ i_ipadm_persist_if_info(ipadm_handle_t iph, const char *ifname,
*/
ipadm_status_t
i_ipadm_get_all_if_info(ipadm_handle_t iph, const char *ifname,
- ipadm_if_info_t **if_info, int64_t lifc_flags)
+ ipadm_if_info_list_t **if_info, int64_t lifc_flags)
{
ipadm_status_t status;
- ipadm_if_info_t *aifinfo = NULL;
- ipadm_if_info_t *pifinfo = NULL;
+ ipadm_if_info_list_t *aifinfo = NULL;
+ ipadm_if_info_list_t *pifinfo = NULL;
+ ipadm_if_info_list_t *last = NULL;
+ ipadm_if_info_list_t *aifl;
+ ipadm_if_info_list_t *pifl;
ipadm_if_info_t *aifp;
ipadm_if_info_t *pifp;
- ipadm_if_info_t *last = NULL;
struct ifaddrs *ifa;
struct ifaddrs *ifap;
@@ -269,7 +275,9 @@ retry:
status = ipadm_errno2status(errno);
goto fail;
}
- for (aifp = aifinfo; aifp != NULL; aifp = aifp->ifi_next) {
+ for (aifl = aifinfo; aifl != NULL; aifl = aifl->ifil_next) {
+ aifp = &aifl->ifil_ifi;
+
/*
* Find the `ifaddrs' structure from `ifa'
* for this interface. We need the IFF_* flags
@@ -299,8 +307,8 @@ retry:
aifp->ifi_state = IFIS_DOWN;
else
aifp->ifi_state = IFIS_OK;
- if (aifp->ifi_next == NULL)
- last = aifp;
+ if (aifl->ifil_next == NULL)
+ last = aifl;
}
freeifaddrs(ifa);
}
@@ -321,27 +329,29 @@ retry:
* `aifinfo', it means that this interface was disabled. We should
* add this interface to `aifinfo' and set it state to IFIF_DISABLED.
*/
- for (pifp = pifinfo; pifp != NULL; pifp = pifp->ifi_next) {
- for (aifp = aifinfo; aifp != NULL; aifp = aifp->ifi_next) {
+ for (pifl = pifinfo; pifl != NULL; pifl = pifl->ifil_next) {
+ pifp = &pifl->ifil_ifi;
+ for (aifl = aifinfo; aifl != NULL; aifl = aifl->ifil_next) {
+ aifp = &aifl->ifil_ifi;
if (strcmp(aifp->ifi_name, pifp->ifi_name) == 0) {
aifp->ifi_pflags = pifp->ifi_pflags;
break;
}
}
- if (aifp == NULL) {
- aifp = malloc(sizeof (ipadm_if_info_t));
- if (aifp == NULL) {
+ if (aifl == NULL) {
+ aifl = malloc(sizeof (ipadm_if_info_list_t));
+ if (aifl == NULL) {
status = ipadm_errno2status(errno);
goto fail;
}
- *aifp = *pifp;
- aifp->ifi_next = NULL;
- aifp->ifi_state = IFIS_DISABLED;
+ *aifl = *pifl;
+ aifl->ifil_next = NULL;
+ aifl->ifil_ifi.ifi_state = IFIS_DISABLED;
if (last != NULL)
- last->ifi_next = aifp;
+ last->ifil_next = aifl;
else
- aifinfo = aifp;
- last = aifp;
+ aifinfo = aifl;
+ last = aifl;
}
}
*if_info = aifinfo;
@@ -375,7 +385,7 @@ ipadm_status_t
i_ipadm_if_pexists(ipadm_handle_t iph, const char *ifname, sa_family_t af,
boolean_t *exists)
{
- ipadm_if_info_t *ifinfo;
+ ipadm_if_info_list_t *ifinfo;
ipadm_status_t status;
/*
@@ -390,9 +400,9 @@ i_ipadm_if_pexists(ipadm_handle_t iph, const char *ifname, sa_family_t af,
status = i_ipadm_persist_if_info(iph, ifname, &ifinfo);
if (status == IPADM_SUCCESS) {
*exists = ((af == AF_INET &&
- (ifinfo->ifi_pflags & IFIF_IPV4)) ||
+ (ifinfo->ifil_ifi.ifi_pflags & IFIF_IPV4)) ||
(af == AF_INET6 &&
- (ifinfo->ifi_pflags & IFIF_IPV6)));
+ (ifinfo->ifil_ifi.ifi_pflags & IFIF_IPV6)));
free(ifinfo);
} else if (status == IPADM_NOTFOUND) {
status = IPADM_SUCCESS;
@@ -495,7 +505,7 @@ i_ipadm_create_ipmp_peer(ipadm_handle_t iph, char *ifname, sa_family_t af)
lifgroupinfo_t lifgr;
ipadm_status_t status = IPADM_SUCCESS;
struct lifreq lifr;
- int other_af_sock;
+ int other_af_sock;
assert(af == AF_INET || af == AF_INET6);
@@ -1387,7 +1397,7 @@ ipadm_delete_if(ipadm_handle_t iph, const char *ifname, sa_family_t af,
* If af is AF_UNSPEC, then we return the following:
* status1, if status1 == status2
* IPADM_SUCCESS, if either of status1 or status2 is SUCCESS
- * and the other status is ENXIO
+ * and the other status is ENXIO
* IPADM_ENXIO, if both status1 and status2 are ENXIO
* IPADM_FAILURE otherwise.
*/
@@ -1411,12 +1421,12 @@ ipadm_delete_if(ipadm_handle_t iph, const char *ifname, sa_family_t af,
* identified by `ifname'.
*
* Return values:
- * On success: IPADM_SUCCESS.
- * On error : IPADM_INVALID_ARG, IPADM_ENXIO or IPADM_FAILURE.
+ * On success: IPADM_SUCCESS.
+ * On error : IPADM_INVALID_ARG, IPADM_ENXIO or IPADM_FAILURE.
*/
ipadm_status_t
ipadm_if_info(ipadm_handle_t iph, const char *ifname,
- ipadm_if_info_t **if_info, uint32_t flags, int64_t lifc_flags)
+ ipadm_if_info_list_t **if_info, uint32_t flags, int64_t lifc_flags)
{
ipadm_status_t status;
ifspec_t ifsp;
@@ -1442,12 +1452,12 @@ ipadm_if_info(ipadm_handle_t iph, const char *ifname,
* Frees the linked list allocated by ipadm_if_info().
*/
void
-ipadm_free_if_info(ipadm_if_info_t *ifinfo)
+ipadm_free_if_info(ipadm_if_info_list_t *ifinfo)
{
- ipadm_if_info_t *ifinfo_next;
+ ipadm_if_info_list_t *ifinfo_next;
for (; ifinfo != NULL; ifinfo = ifinfo_next) {
- ifinfo_next = ifinfo->ifi_next;
+ ifinfo_next = ifinfo->ifil_next;
free(ifinfo);
}
}
diff --git a/usr/src/lib/libipadm/common/libipadm.h b/usr/src/lib/libipadm/common/libipadm.h
index 0d8e3fdd7b..0ae9d89e4b 100644
--- a/usr/src/lib/libipadm/common/libipadm.h
+++ b/usr/src/lib/libipadm/common/libipadm.h
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
+ * Copyright 2021, Tintri by DDN. All rights reserved.
*/
#ifndef _LIBIPADM_H
#define _LIBIPADM_H
@@ -205,14 +206,27 @@ typedef enum {
IFIS_DISABLED /* Interface has been disabled. */
} ipadm_if_state_t;
+/*
+ * Declare ipadm_if_info_list_t as a container for ipadm_if_info_t.
+ *
+ * ipadm_if_info_t used to have a list pointer ifi_next for linking a number
+ * of ipadm_if_info_t's together. Even though this linking wasn't used in the
+ * data exchange between ipmgmtd and libipadm, this meant the structure wasn't
+ * safe for passing through the door between 32bit and 64bit processes.
+ */
typedef struct ipadm_if_info_s {
- struct ipadm_if_info_s *ifi_next;
char ifi_name[LIFNAMSIZ]; /* interface name */
ipadm_if_state_t ifi_state; /* see above */
uint_t ifi_cflags; /* current flags */
uint_t ifi_pflags; /* persistent flags */
} ipadm_if_info_t;
+typedef struct ipadm_if_info_list_s {
+ struct ipadm_if_info_list_s *ifil_next;
+ ipadm_if_info_t ifil_ifi;
+} ipadm_if_info_list_t;
+
+
/* ipadm_if_info_t flags */
#define IFIF_BROADCAST 0x00000001
#define IFIF_MULTICAST 0x00000002
@@ -279,8 +293,8 @@ extern ipadm_status_t ipadm_disable_if(ipadm_handle_t, const char *,
uint32_t);
extern ipadm_status_t ipadm_enable_if(ipadm_handle_t, const char *, uint32_t);
extern ipadm_status_t ipadm_if_info(ipadm_handle_t, const char *,
- ipadm_if_info_t **, uint32_t, int64_t);
-extern void ipadm_free_if_info(ipadm_if_info_t *);
+ ipadm_if_info_list_t **, uint32_t, int64_t);
+extern void ipadm_free_if_info(ipadm_if_info_list_t *);
extern ipadm_status_t ipadm_delete_if(ipadm_handle_t, const char *,
sa_family_t, uint32_t);
extern void ipadm_if_move(ipadm_handle_t, const char *);
@@ -362,7 +376,7 @@ extern ipadm_status_t ipadm_get_prop(ipadm_handle_t, const char *, char *,
/*
* miscellaneous helper functions.
*/
-extern const char *ipadm_status2str(ipadm_status_t);
+extern const char *ipadm_status2str(ipadm_status_t);
extern int ipadm_str2nvlist(const char *, nvlist_t **, uint_t);
extern size_t ipadm_nvlist2str(nvlist_t *, char *, size_t);
extern char *ipadm_proto2str(uint_t);
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.c b/usr/src/lib/libvmmapi/common/vmmapi.c
index ba3fb7f8dd..ec27949a43 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.c
+++ b/usr/src/lib/libvmmapi/common/vmmapi.c
@@ -39,7 +39,7 @@
*
* Copyright 2015 Pluribus Networks Inc.
* Copyright 2019 Joyent, Inc.
- * Copyright 2020 Oxide Computer Company
+ * Copyright 2021 Oxide Computer Company
*/
#include <sys/cdefs.h>
@@ -109,12 +109,31 @@ struct vmctx {
#ifdef __FreeBSD__
#define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x)))
#define DESTROY(x) sysctlbyname("hw.vmm.destroy", NULL, NULL, (x), strlen((x)))
-#else
-#define CREATE(x) vm_do_ctl(VMM_CREATE_VM, (x))
-#define DESTROY(x) vm_do_ctl(VMM_DESTROY_VM, (x))
+int
+vm_create(const char *name)
+{
+ /* Try to load vmm(4) module before creating a guest. */
+ if (modfind("vmm") < 0)
+ kldload("vmm");
+ return (CREATE((char *)name));
+}
+
+void
+vm_destroy(struct vmctx *vm)
+{
+ assert(vm != NULL);
+
+ if (vm->fd >= 0)
+ close(vm->fd);
+ DESTROY(vm->name);
+
+ free(vm);
+}
+
+#else
static int
-vm_do_ctl(int cmd, const char *name)
+vm_do_ctl(int cmd, void *req)
{
int ctl_fd;
@@ -123,7 +142,7 @@ vm_do_ctl(int cmd, const char *name)
return (-1);
}
- if (ioctl(ctl_fd, cmd, name) == -1) {
+ if (ioctl(ctl_fd, cmd, req) == -1) {
int err = errno;
/* Do not lose ioctl errno through the close(2) */
@@ -135,6 +154,46 @@ vm_do_ctl(int cmd, const char *name)
return (0);
}
+
+int
+vm_create(const char *name, uint64_t flags)
+{
+ struct vm_create_req req;
+
+ (void) strncpy(req.name, name, VM_MAX_NAMELEN);
+ req.flags = flags;
+
+ return (vm_do_ctl(VMM_CREATE_VM, &req));
+}
+
+void
+vm_close(struct vmctx *vm)
+{
+ assert(vm != NULL);
+ assert(vm->fd >= 0);
+
+ (void) close(vm->fd);
+
+ free(vm);
+}
+
+void
+vm_destroy(struct vmctx *vm)
+{
+ struct vm_destroy_req req;
+
+ assert(vm != NULL);
+
+ if (vm->fd >= 0) {
+ (void) close(vm->fd);
+ vm->fd = -1;
+ }
+
+ (void) strncpy(req.name, vm->name, VM_MAX_NAMELEN);
+ (void) vm_do_ctl(VMM_DESTROY_VM, &req);
+
+ free(vm);
+}
#endif
static int
@@ -155,17 +214,6 @@ vm_device_open(const char *name)
return (fd);
}
-int
-vm_create(const char *name)
-{
-#ifdef __FreeBSD__
- /* Try to load vmm(4) module before creating a guest. */
- if (modfind("vmm") < 0)
- kldload("vmm");
-#endif
- return (CREATE((char *)name));
-}
-
struct vmctx *
vm_open(const char *name)
{
@@ -189,30 +237,6 @@ err:
return (NULL);
}
-#ifndef __FreeBSD__
-void
-vm_close(struct vmctx *vm)
-{
- assert(vm != NULL);
- assert(vm->fd >= 0);
-
- (void) close(vm->fd);
-
- free(vm);
-}
-#endif
-
-void
-vm_destroy(struct vmctx *vm)
-{
- assert(vm != NULL);
-
- if (vm->fd >= 0)
- close(vm->fd);
- DESTROY(vm->name);
-
- free(vm);
-}
int
vm_parse_memsize(const char *optarg, size_t *ret_memsize)
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.h b/usr/src/lib/libvmmapi/common/vmmapi.h
index 79c7dc02ee..e239b70a56 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.h
+++ b/usr/src/lib/libvmmapi/common/vmmapi.h
@@ -39,7 +39,7 @@
*
* Copyright 2015 Pluribus Networks Inc.
* Copyright 2019 Joyent, Inc.
- * Copyright 2020 Oxide Computer Company
+ * Copyright 2021 Oxide Computer Company
*/
#ifndef _VMMAPI_H_
@@ -134,7 +134,11 @@ int vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, int segid,
int vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len);
+#ifndef __FreeBSD__
+int vm_create(const char *name, uint64_t flags);
+#else
int vm_create(const char *name);
+#endif /* __FreeBSD__ */
int vm_get_device_fd(struct vmctx *ctx);
struct vmctx *vm_open(const char *name);
#ifndef __FreeBSD__