dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libipmp / common / ipmp.c
blobcf9c3c7c3c5a958a39999534feca689b0bbb80b1
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * IPMP general interfaces (PSARC/2002/615).
30 #include <assert.h>
31 #include <stdlib.h>
32 #include <locale.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <errno.h>
37 #include "ipmp_impl.h"
40 * Allocate a handle and store it in `*handlep' upon success. Returns an IPMP
41 * error code.
43 int
44 ipmp_open(ipmp_handle_t *handlep)
46 ipmp_state_t *statep;
48 statep = malloc(sizeof (ipmp_state_t));
49 if (statep == NULL)
50 return (IPMP_ENOMEM);
52 statep->st_fd = -1;
53 statep->st_snap = NULL;
54 statep->st_magic = IPMP_MAGIC;
56 *handlep = statep;
57 return (IPMP_SUCCESS);
61 * Destroy the IPMP handle named by `handle'.
63 void
64 ipmp_close(ipmp_handle_t handle)
66 ipmp_state_t *statep = handle;
69 * If this assertion triggers, someone called ipmp_close() twice in
70 * a row or stomped on us.
72 assert(statep->st_magic == IPMP_MAGIC);
75 * If this assertion triggers, something's gone wrong internally.
77 assert(statep->st_fd == -1);
79 if (statep->st_snap != NULL)
80 ipmp_snap_free(statep->st_snap);
82 statep->st_magic = 0;
83 free(statep);
87 * Error messages; must be in the same order as the codes in <ipmp.h>
89 static char *errmsgs[IPMP_NERR] = {
90 "operation succeeded", /* 0 IPMP_SUCCESS */
91 "operation failed", /* 1 IPMP_FAILURE */
92 "minimum failover redundancy not met", /* 2 IPMP_EMINRED */
93 "failback disabled", /* 3 IPMP_EFBDISABLED */
94 "unknown IPMP data address", /* 4 IPMP_EUNKADDR */
95 "invalid argument", /* 5 IPMP_EINVAL */
96 "out of memory", /* 6 IPMP_ENOMEM */
97 "cannot contact in.mpathd", /* 7 IPMP_ENOMPATHD */
98 "unknown IPMP group", /* 8 IPMP_EUNKGROUP */
99 "interface is not using IPMP", /* 9 IPMP_EUNKIF */
100 "unable to communicate with in.mpathd", /* 10 IPMP_EPROTO */
101 "interface has duplicate hardware address"
102 /* 11 IPMP_EHWADDRDUP */
106 * Return a string describing the IPMP error code named by `error'.
108 const char *
109 ipmp_errmsg(int error)
111 if (error >= IPMP_NERR || error < 0)
112 return (dgettext(TEXT_DOMAIN, "<unknown error>"));
114 if (error == IPMP_FAILURE)
115 return (strerror(errno));
117 return (dgettext(TEXT_DOMAIN, errmsgs[error]));