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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * IPMP general interfaces (PSARC/2002/615).
37 #include "ipmp_impl.h"
40 * Allocate a handle and store it in `*handlep' upon success. Returns an IPMP
44 ipmp_open(ipmp_handle_t
*handlep
)
48 statep
= malloc(sizeof (ipmp_state_t
));
53 statep
->st_snap
= NULL
;
54 statep
->st_magic
= IPMP_MAGIC
;
57 return (IPMP_SUCCESS
);
61 * Destroy the IPMP handle named by `handle'.
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
);
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'.
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
]));