1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * IPMP general interfaces (PSARC/2002/615). 31 */ 32 33 #include <assert.h> 34 #include <stdlib.h> 35 #include <locale.h> 36 #include <unistd.h> 37 38 #include "ipmp_impl.h" 39 40 /* 41 * Allocate a handle and store it in `*handlep' upon success. Returns an IPMP 42 * error code. 43 */ 44 int 45 ipmp_open(ipmp_handle_t *handlep) 46 { 47 ipmp_state_t *statep; 48 49 statep = malloc(sizeof (ipmp_state_t)); 50 if (statep == NULL) 51 return (IPMP_ENOMEM); 52 53 statep->st_fd = -1; 54 statep->st_snap = NULL; 55 statep->st_magic = IPMP_MAGIC; 56 57 *handlep = statep; 58 return (IPMP_SUCCESS); 59 } 60 61 /* 62 * Destroy the IPMP handle named by `handle'. 63 */ 64 void 65 ipmp_close(ipmp_handle_t handle) 66 { 67 ipmp_state_t *statep = handle; 68 69 /* 70 * If this assertion triggers, someone called ipmp_close() twice in 71 * a row or stomped on us. 72 */ 73 assert(statep->st_magic == IPMP_MAGIC); 74 75 /* 76 * If this assertion triggers, something's gone wrong internally. 77 */ 78 assert(statep->st_fd == -1); 79 80 if (statep->st_snap != NULL) 81 ipmp_snap_free(statep->st_snap); 82 83 statep->st_magic = 0; 84 free(statep); 85 } 86 87 /* 88 * Error messages; must be in the same order as the codes in <ipmp.h> 89 */ 90 static char *errmsgs[IPMP_NERR] = { 91 "operation succeeded", /* 0 IPMP_SUCCESS */ 92 "operation failed", /* 1 IPMP_FAILURE */ 93 "minimum failover redundancy not met", /* 2 IPMP_EMINRED */ 94 "failback disabled", /* 3 IPMP_EFBDISABLED */ 95 "unable to completely fail back", /* 4 IPMP_EFBPARTIAL */ 96 "invalid argument", /* 5 IPMP_EINVAL */ 97 "out of memory", /* 6 IPMP_ENOMEM */ 98 "cannot contact in.mpathd", /* 7 IPMP_ENOMPATHD */ 99 "unknown IPMP group", /* 8 IPMP_EUNKGROUP */ 100 "interface is not using IPMP", /* 9 IPMP_EUNKIF */ 101 "unable to communicate with in.mpathd" /* 10 IPMP_EPROTO */ 102 }; 103 104 /* 105 * Return a string describing the IPMP error code named by `error'. 106 */ 107 const char * 108 ipmp_errmsg(int error) 109 { 110 if (error >= IPMP_NERR || error < 0) 111 return (dgettext(TEXT_DOMAIN, "<unknown error>")); 112 113 return (dgettext(TEXT_DOMAIN, errmsgs[error])); 114 } 115