ip_anon_rcm.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* RCM module to prevent plumbed IP addresses from being removed.
*/
#include <stdlib.h>
#include <ctype.h>
#include <memory.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <thread.h>
#include <synch.h>
#include <assert.h>
#include <errno.h>
#include <libintl.h>
#include "rcm_module.h"
#include "ifaddrlist.h"
#define SUNW_IP "SUNW_ip/"
#define IP_FLAG_NEW 0x00
#define IP_FLAG_REG 0x01
#define IP_FLAG_CL 0x02
#define IP_FLAG_IGNORE 0x04
#define IP_FLAG_DELETE 0x08
static int ip_anon_register(rcm_handle_t *);
static int ip_anon_unregister(rcm_handle_t *);
char **, char **, nvlist_t *, rcm_info_t **);
char **, rcm_info_t **);
char **, rcm_info_t **);
char **, rcm_info_t **);
char **, rcm_info_t **);
typedef struct ip_status {
int flags;
char device[IP_REG_SIZE];
} ip_status_t;
static mutex_t ip_list_lock;
static struct rcm_mod_ops ip_anon_ops =
{
NULL,
NULL,
};
struct rcm_mod_ops *
{
return (&ip_anon_ops);
}
const char *
{
return ("RCM IP address module %I%");
}
int
{
/* free the registration list */
(void) mutex_lock(&ip_list_lock);
}
(void) mutex_unlock(&ip_list_lock);
(void) mutex_destroy(&ip_list_lock);
return (RCM_SUCCESS);
}
static int
{
int bootflags;
(void) mutex_lock(&ip_list_lock);
gettext("unable to check cluster status\n"));
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
"ip_anon: cladm bootflags=%d\n", bootflags);
if (bootflags == 3) {
/* build the exclusion list */
&num_exclude_addrs)) == 0) {
if (num_exclude_addrs == 0)
"ip_anon: no addresses excluded\n");
else {
malloc(sizeof (cladm_netaddr_entry_t) *
(num_exclude_addrs))) == NULL) {
gettext("out of memory\n"));
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
!= 0) {
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
}
} else {
"no _cladm() backend to get addrs\n");
} else {
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
}
"ip_anon: num exclude addrs: %d\n",
/* print the exclusion list for debugging purposes */
for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
if (exclude_addrs.cladm_netaddrs_array[i].\
cl_ipversion == IPV4_VERSION) {
}
if (exclude_addrs.cladm_netaddrs_array[i].\
cl_ipversion == IPV6_VERSION) {
}
}
}
/* obtain a list of all IPv4 and IPv6 addresses in the system */
"ip_anon: obtaining list of IPv4 addresses.\n");
gettext("cannot get IPv4 address list errno=%d (%s)\n"),
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
"ip_anon: obtaining list of IPv6 addresses.\n");
gettext("cannot get IPv6 address list errno=%d (%s)\n"),
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
/* check the state of outstanding registrations against the list */
"ip_anon: checking outstanding registrations.\n");
}
/* IPv4 */
for (i = 0; i < num_ifs; i++) {
else
gettext("out of memory\n"));
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
}
/* IPv6 */
for (i = 0; i < num_ifs6; i++) {
else
gettext("out of memory\n"));
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
_S6_u32))
}
/* examine the list of ip address registrations and their state */
"ip_anon: unregistering interest in %s\n",
gettext("failed to unregister"));
}
}
/*
* If the registration is not a clustered devices and
* not already registered, then RCM doesn't
* currently know about it.
*/
"ip_anon: registering interest in %s\n",
if (rcm_register_interest(hdl,
RCM_SUCCESS) {
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
} else {
"ip_anon: registered %s\n",
}
}
/*
* If the entry is registered and clustered, then
* the configuration has been changed and it
* should be unregistered.
*/
"ip_anon: unregistering in %s\n",
gettext("failed to unregister"));
}
}
}
}
}
(void) mutex_unlock(&ip_list_lock);
return (RCM_SUCCESS);
}
static int
{
(void) mutex_lock(&ip_list_lock);
gettext("failed to unregister"));
}
}
}
(void) mutex_unlock(&ip_list_lock);
return (RCM_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (RCM_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (RCM_FAILURE);
}
/*ARGSUSED*/
static int
{
return (RCM_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (RCM_FAILURE);
}
/*ARGSUSED*/
static int
{
return (RCM_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (RCM_FAILURE);
}
/*
* Call with ip_list_lock held.
*/
static ip_status_t *
{
int done;
done = 0;
done = 1;
else
}
return (tlist);
}
static ip_status_t *
{
return (tentry);
else {
}
return (tentry);
}
static int
{
return (-1);
} else {
return (-1);
}
return (0);
}
static int
{
int i;
/*
* If this falls in the exclusion list, the IP_FLAG_CL
* bit should be set for the adapter.
*/
for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
if (exclude_addrs.cladm_netaddrs_array[i].\
cl_ipversion == IPV4_VERSION) {
"ip_anon: matched %s:%s => %s\n",
return (1);
}
}
}
taddr);
return (0);
}
static int
{
int i, j, numequal;
/*
* If this falls in the exclusion list, the IP_FLAG_CL
* bit should be set for the adapter.
*/
for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
if (exclude_addrs.cladm_netaddrs_array[i].\
cl_ipversion == IPV6_VERSION) {
numequal = 0;
for (j = 0; j < 4; j++) {
ipv6_netaddr[j] = exclude_addrs.\
cladm_netaddrs_array[i].\
ipv6_netmask[j] = exclude_addrs.\
cladm_netaddrs_array[i].\
if (addr[j] == ipv6_netaddr[j])
numequal++;
}
if (numequal == 4)
return (1);
}
}
taddr);
return (0);
}
/*
*/
/*
* Copyright (c) 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/*
* Construct the interface list with given address family.
* If it fails, returns -1 and an error message in *errbuf;
* otherwise, returns number of interfaces, and the interface list in *ipaddrp.
*/
int
{
int fd;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
struct ifaddrlist *al;
struct ifaddrlist *ifaddrlist;
int lifc_flags = 0;
int count;
return (-1);
}
if (fd < 0) {
return (-1);
}
/* determine the number of interfaces */
return (-1);
}
/* allocate memory for the determined number of interfaces */
(size_t)sizeof (struct ifaddrlist));
if (ifaddrlist == NULL) {
return (-1);
}
return (-1);
}
/* pull out the interface list from the kernel */
return (-1);
}
/*LINTED*/
al = ifaddrlist;
count = 0;
/* let's populate the interface entries in the ifaddrlist */
/*
* Need a template to preserve address info that is
* used below to locate the next entry. (Otherwise,
* SIOCGLIFFLAGS stomps over it because the requests
* are returned in a union.)
*/
continue;
}
"SIOCGLIFFLAGS: %.*s: %s",
return (-1);
}
/* get the interface address */
return (-1);
}
} else {
}
/* get the interface index */
return (-1);
}
++al;
++count;
}
*ipaddrp = ifaddrlist;
return (count);
}