/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This RCM module adds support to the RCM framework for Bridge links
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <synch.h>
#include <assert.h>
#include <strings.h>
#include "rcm_module.h"
#include <libintl.h>
#include <libdllink.h>
#include <libdlbridge.h>
#include <libdlpi.h>
/*
* Definitions
*/
#ifndef lint
#define _(x) gettext(x)
#else
#define _(x) x
#endif
/* Some generic well-knowns and defaults used in this module */
/* Bridge Cache state flags */
typedef enum {
/* Network Cache lookup options */
/* Cache element */
typedef struct link_cache {
} link_cache_t;
/*
* Global cache for network Bridges
*/
/*
* RCM module interface prototypes
*/
static int bridge_register(rcm_handle_t *);
static int bridge_unregister(rcm_handle_t *);
char **, char **, nvlist_t *, rcm_info_t **);
char **, rcm_info_t **);
char **, rcm_info_t **);
uint_t, char **, rcm_info_t **);
char **, rcm_info_t **);
/* Module private routines */
static void cache_free(void);
static int cache_update(rcm_handle_t *);
static void cache_remove(link_cache_t *);
static void node_free(link_cache_t *);
static void cache_insert(link_cache_t *);
static char *bridge_usage(link_cache_t *);
static void bridge_log_err(datalink_id_t, char **, char *);
/* Module-Private data */
{
NULL,
NULL,
};
/*
* rcm_mod_init() - Update registrations, and return the ops structure.
*/
struct rcm_mod_ops *
rcm_mod_init(void)
{
"Bridge: cannot open datalink handle: %s\n",
return (NULL);
}
/* Return the ops vectors */
return (&bridge_ops);
}
/*
* rcm_mod_info() - Return a string describing this module.
*/
const char *
rcm_mod_info(void)
{
return ("Bridge module version 1.0");
}
/*
* rcm_mod_fini() - Destroy the network Bridge cache.
*/
int
rcm_mod_fini(void)
{
/*
* Note that bridge_unregister() does not seem to be called anywhere,
* therefore we free the cache nodes here. In theory we should call
* rcm_register_interest() for each node before we free it, but the
* framework does not provide the rcm_handle to allow us to do so.
*/
cache_free();
(void) mutex_destroy(&cache_lock);
return (RCM_SUCCESS);
}
/*
* bridge_register() - Make sure the cache is properly sync'ed, and its
* registrations are in order.
*/
static int
{
int retv;
return (retv);
/*
* Need to register interest in all new resources
* getting attached, so we get attach event notifications
*/
if (!events_registered) {
if (retv != RCM_SUCCESS) {
_("Bridge: failed to register %s\n"),
} else {
}
}
return (retv);
}
/*
* bridge_unregister() - Walk the cache, unregistering all the links.
*/
static int
{
/* Walk the cache, unregistering everything */
(void) mutex_lock(&cache_lock);
while (node != &cache_tail) {
if (retv != RCM_SUCCESS)
break;
}
(void) mutex_unlock(&cache_lock);
if (retv != RCM_SUCCESS) {
return (retv);
}
/*
* Unregister interest in all new resources
*/
if (events_registered) {
if (retv != RCM_SUCCESS) {
_("Bridge: failed to unregister %s\n"),
} else {
}
}
return (retv);
}
/*
* bridge_offline() - Offline the bridge on a specific link.
*/
static int
{
/* Lock the cache and lookup the resource */
(void) mutex_lock(&cache_lock);
/* should not happen because the resource is registered. */
"unrecognized resource");
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/* Check if it's a query */
"Bridge: offline query succeeded(%s)\n", rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
if (status != DLADM_STATUS_OK) {
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/*
* bridge_undo_offline() - Undo offline of a previously offlined node.
*/
/*ARGSUSED*/
static int
{
(void) mutex_lock(&cache_lock);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
/* Check if no attempt should be made to online the link here */
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/*
* Try to bring on an offlined bridge link.
*/
if (status != DLADM_STATUS_OK) {
/*
* Print a warning message.
*/
_("Bridge: Bridge online failed %u %s: %s\n"),
}
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/*
* bridge_get_info() - Gather usage information for this resource.
*/
/*ARGSUSED*/
int
{
(void) mutex_lock(&cache_lock);
_("Bridge: get_info(%s) unrecognized resource\n"), rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
(void) mutex_unlock(&cache_lock);
/* most likely malloc failure */
_("Bridge: get_info(%s) malloc failure\n"), rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
return (RCM_SUCCESS);
}
/*
* bridge_suspend() - Nothing to do, always okay
*/
/*ARGSUSED*/
static int
{
return (RCM_SUCCESS);
}
/*
* bridge_resume() - Nothing to do, always okay
*/
/*ARGSUSED*/
static int
{
return (RCM_SUCCESS);
}
/*
* bridge_remove() - remove a resource from cache
*/
/*ARGSUSED*/
static int
{
(void) mutex_lock(&cache_lock);
_("Bridge: remove(%s) unrecognized resource\n"), rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
/* remove the cached entry for the resource */
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/*
* bridge_notify_event - Project private implementation to receive new resource
* events. It intercepts all new resource events. If the
* new resource is a network resource, pass up a notify
* for it too. The new resource need not be cached, since
* it is done at register again.
*/
/*ARGSUSED*/
static int
{
"unrecognized event");
return (RCM_FAILURE);
}
/* Update cache to reflect latest Bridges */
"private Cache update failed");
return (lastrv);
}
/*
* Try best to recover all configuration.
*/
continue;
"cannot get linkid");
continue;
}
}
}
"Bridge: notify_event: link configuration complete\n");
return (lastrv);
}
/*
* bridge_usage - Determine the usage of a link.
* The returned buffer is owned by caller, and the caller
* must free it up when done.
*/
static char *
{
char *buf;
const char *fmt;
if (status != DLADM_STATUS_OK) {
_("Bridge: usage(%s) get link name failure(%s)\n"),
return (NULL);
}
sizeof (bridge));
fmt = _("%1$s offlined");
else if (bridge[0] == '\0')
fmt = _("%1$s not bridged");
else
fmt = _("%1$s bridge: %2$s");
return (buf);
}
/*
* Cache management routines, all cache management functions should be
* be called with cache_lock held.
*/
/*
* cache_lookup() - Get a cache node for a resource.
* Call with cache lock held.
*
* This ensures that the cache is consistent with the system state and
* returns a pointer to the cache element corresponding to the resource.
*/
static link_cache_t *
{
if (options & CACHE_REFRESH) {
/* drop lock since update locks cache again */
(void) mutex_unlock(&cache_lock);
(void) cache_update(hd);
(void) mutex_lock(&cache_lock);
}
"Bridge: cache lookup succeeded(%s, %s)\n", rsrc,
return (node);
}
}
return (NULL);
}
/*
* node_free - Free a node from the cache
*/
static void
{
}
}
/*
* cache_insert - Insert a resource node in cache
*/
static void
{
/* insert at the head for best performance */
}
/*
* cache_remove() - Remove a resource node from cache.
*/
static void
{
}
typedef struct bridge_update_arg_s {
int retval;
/*
* bridge_update() - Update physical interface properties
*/
static int
{
char *rsrc;
sizeof (bridge));
if (status != DLADM_STATUS_OK) {
"Bridge: no bridge information for %u (%s)\n",
return (DLADM_WALK_CONTINUE);
}
_("Bridge: allocation failure: %s %u: %s\n"),
goto done;
}
rsrc);
} else {
"Bridge: %s is a new resource (bridge %s)\n",
goto done;
}
}
ret = RCM_SUCCESS;
done:
}
/*
* cache_update() - Update cache with latest interface info
*/
static int
{
(void) mutex_lock(&cache_lock);
/* first we walk the entire cache, marking each entry stale */
/* now walk the links and update all of the entries */
/*
* Continue to delete all stale nodes from the cache even if the walk
* above failed. Unregister links that are not offlined and still in
* the cache.
*/
0);
"Bridge: unregistered %s %s\n",
continue;
}
continue;
if (rv != RCM_SUCCESS) {
_("Bridge: failed to register %s\n"),
node->vc_resource);
} else {
node->vc_resource);
}
}
(void) mutex_unlock(&cache_lock);
return (lastrv);
}
/*
* cache_free() - Empty the cache
*/
static void
cache_free(void)
{
(void) mutex_lock(&cache_lock);
while (node != &cache_tail) {
}
(void) mutex_unlock(&cache_lock);
}
/*
* bridge_log_err() - RCM error log wrapper
*/
static void
{
char *error;
link[0] = '\0';
if (linkid != DATALINK_INVALID_LINKID) {
_("Bridge: cannot get link name for (%s) %s\n"),
}
} else {
}
if (link[0] != '\0')
else
}
/*
* bridge_configure() - Configure bridge on a physical link after it attaches
*/
static int
{
/* Check for the bridge links in the cache */
/* Check if the link is new or was previously offlined */
(void) mutex_lock(&cache_lock);
"Bridge: Skipping configured interface(%s)\n", rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
(void) mutex_unlock(&cache_lock);
/* clear out previous bridge, if any */
if (bridge[0] != '\0')
}
/* now set up the new one */
return (RCM_FAILURE);
else
return (RCM_SUCCESS);
}