1*e11c3f44Smeem /*
2*e11c3f44Smeem * CDDL HEADER START
3*e11c3f44Smeem *
4*e11c3f44Smeem * The contents of this file are subject to the terms of the
5*e11c3f44Smeem * Common Development and Distribution License (the "License").
6*e11c3f44Smeem * You may not use this file except in compliance with the License.
7*e11c3f44Smeem *
8*e11c3f44Smeem * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*e11c3f44Smeem * or http://www.opensolaris.org/os/licensing.
10*e11c3f44Smeem * See the License for the specific language governing permissions
11*e11c3f44Smeem * and limitations under the License.
12*e11c3f44Smeem *
13*e11c3f44Smeem * When distributing Covered Code, include this CDDL HEADER in each
14*e11c3f44Smeem * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*e11c3f44Smeem * If applicable, add the following below this CDDL HEADER, with the
16*e11c3f44Smeem * fields enclosed by brackets "[]" replaced with your own identifying
17*e11c3f44Smeem * information: Portions Copyright [yyyy] [name of copyright owner]
18*e11c3f44Smeem *
19*e11c3f44Smeem * CDDL HEADER END
20*e11c3f44Smeem *
21*e11c3f44Smeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
22*e11c3f44Smeem * Use is subject to license terms.
23*e11c3f44Smeem */
24*e11c3f44Smeem
25*e11c3f44Smeem /*
26*e11c3f44Smeem * IPMP administrative interfaces (see PSARC/2007/272).
27*e11c3f44Smeem */
28*e11c3f44Smeem
29*e11c3f44Smeem #include <assert.h>
30*e11c3f44Smeem #include <errno.h>
31*e11c3f44Smeem #include <string.h>
32*e11c3f44Smeem #include <unistd.h>
33*e11c3f44Smeem #include <sys/time.h>
34*e11c3f44Smeem #include <sys/types.h>
35*e11c3f44Smeem
36*e11c3f44Smeem #include "ipmp_impl.h"
37*e11c3f44Smeem #include "ipmp_mpathd.h"
38*e11c3f44Smeem #include "ipmp_admin.h"
39*e11c3f44Smeem
40*e11c3f44Smeem static int
ipmp_command(ipmp_handle_t handle,const void * req,uint_t reqsize)41*e11c3f44Smeem ipmp_command(ipmp_handle_t handle, const void *req, uint_t reqsize)
42*e11c3f44Smeem {
43*e11c3f44Smeem ipmp_state_t *statep = (ipmp_state_t *)handle;
44*e11c3f44Smeem mi_result_t result;
45*e11c3f44Smeem struct timeval end;
46*e11c3f44Smeem int save_errno;
47*e11c3f44Smeem int retval;
48*e11c3f44Smeem
49*e11c3f44Smeem if (gettimeofday(&end, NULL) == -1)
50*e11c3f44Smeem return (IPMP_FAILURE);
51*e11c3f44Smeem end.tv_sec += IPMP_REQTIMEOUT;
52*e11c3f44Smeem
53*e11c3f44Smeem assert(statep->st_fd == -1);
54*e11c3f44Smeem retval = ipmp_connect(&statep->st_fd);
55*e11c3f44Smeem if (retval != IPMP_SUCCESS)
56*e11c3f44Smeem return (retval);
57*e11c3f44Smeem
58*e11c3f44Smeem retval = ipmp_write(statep->st_fd, req, reqsize);
59*e11c3f44Smeem if (retval != IPMP_SUCCESS)
60*e11c3f44Smeem goto out;
61*e11c3f44Smeem
62*e11c3f44Smeem retval = ipmp_read(statep->st_fd, &result, sizeof (result), &end);
63*e11c3f44Smeem if (retval != IPMP_SUCCESS)
64*e11c3f44Smeem goto out;
65*e11c3f44Smeem
66*e11c3f44Smeem errno = result.me_sys_error;
67*e11c3f44Smeem retval = result.me_mpathd_error;
68*e11c3f44Smeem out:
69*e11c3f44Smeem save_errno = errno;
70*e11c3f44Smeem (void) close(statep->st_fd);
71*e11c3f44Smeem statep->st_fd = -1;
72*e11c3f44Smeem errno = save_errno;
73*e11c3f44Smeem return (retval);
74*e11c3f44Smeem }
75*e11c3f44Smeem
76*e11c3f44Smeem int
ipmp_offline(ipmp_handle_t handle,const char * ifname,uint_t minred)77*e11c3f44Smeem ipmp_offline(ipmp_handle_t handle, const char *ifname, uint_t minred)
78*e11c3f44Smeem {
79*e11c3f44Smeem mi_offline_t mio;
80*e11c3f44Smeem
81*e11c3f44Smeem mio.mio_command = MI_OFFLINE;
82*e11c3f44Smeem mio.mio_min_redundancy = minred;
83*e11c3f44Smeem (void) strlcpy(mio.mio_ifname, ifname, LIFNAMSIZ);
84*e11c3f44Smeem return (ipmp_command(handle, &mio, sizeof (mio)));
85*e11c3f44Smeem }
86*e11c3f44Smeem
87*e11c3f44Smeem int
ipmp_undo_offline(ipmp_handle_t handle,const char * ifname)88*e11c3f44Smeem ipmp_undo_offline(ipmp_handle_t handle, const char *ifname)
89*e11c3f44Smeem {
90*e11c3f44Smeem mi_undo_offline_t miu;
91*e11c3f44Smeem
92*e11c3f44Smeem miu.miu_command = MI_UNDO_OFFLINE;
93*e11c3f44Smeem (void) strlcpy(miu.miu_ifname, ifname, LIFNAMSIZ);
94*e11c3f44Smeem return (ipmp_command(handle, &miu, sizeof (miu)));
95*e11c3f44Smeem }
96*e11c3f44Smeem
97*e11c3f44Smeem int
ipmp_ping_daemon(ipmp_handle_t handle)98*e11c3f44Smeem ipmp_ping_daemon(ipmp_handle_t handle)
99*e11c3f44Smeem {
100*e11c3f44Smeem mi_ping_t mip;
101*e11c3f44Smeem
102*e11c3f44Smeem mip.mip_command = MI_PING;
103*e11c3f44Smeem return (ipmp_command(handle, &mip, sizeof (mip)));
104*e11c3f44Smeem }
105