/*
* 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
*/
/*
*/
#include <errno.h>
#include <libdladm.h>
#include <libdllink.h>
#include <libdlwlan.h>
#include <libscf.h>
#include <limits.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libnwam.h>
#include "conditions.h"
#include "events.h"
#include "objects.h"
#include "util.h"
/*
* loc.c - contains routines which handle location abstraction.
*/
static int
{
char *name;
return (0);
}
NWAM_OBJECT_TYPE_LOC, 0, name);
return (0);
}
/*
* Walk all locs, creating init events for each.
*/
void
nwamd_init_locs(void)
{
/* Unset active location */
(void) pthread_mutex_lock(&active_loc_mutex);
active_loc[0] = '\0';
(void) pthread_mutex_unlock(&active_loc_mutex);
}
/*
* Walk all locs, creating fini events for each.
*/
void
nwamd_fini_locs(void)
{
}
static boolean_t
{
&enabledval) != NWAM_SUCCESS) {
"enabled value");
return (B_FALSE);
}
!= NWAM_SUCCESS) {
"enabled value");
return (B_FALSE);
}
return (enabled);
}
static int64_t
{
&activationval) != NWAM_SUCCESS) {
"activation mode value");
return (-1);
}
if (err != NWAM_SUCCESS) {
"activation mode value");
return (-1);
}
return ((int64_t)activation);
}
/* Enables the location. */
static void
{
char *enabled;
/*
* Find currently enabled location and change its state to disabled
* if it is a manual location, or offline (if it is not).
* Only manual locations reach disabled, since conditional and
* system locations which are manually disabled simply revert to
* their conditions for activation.
*/
/* Only change state if current != new */
"find old location %s", enabled);
goto skip_disable;
}
/*
* Disable if the old location was manual, since the
* only way a manual location can deactivate is if
* it is disabled.
*/
if (do_disable) {
"disable needed for old location %s",
enabled);
} else {
"offline needed for old location %s",
enabled);
}
}
}
NET_LOC_SELECTED_PROP, object_name) == 0) {
(void) smf_restore_instance(NET_LOC_FMRI);
if (smf_refresh_instance(NET_LOC_FMRI) == 0) {
(void) pthread_mutex_lock(&active_loc_mutex);
sizeof (active_loc));
(void) pthread_mutex_unlock(&active_loc_mutex);
} else {
"%s could not be refreshed", NET_LOC_FMRI);
}
}
}
struct nwamd_loc_check_walk_arg {
};
/*
* Determine which location should be activated.
*/
static int
{
char **conditions;
if (lactivation == -1)
return (0);
switch (activation) {
if (loc_is_enabled(loch)) {
/* Manually enabled locations should always win out. */
} else {
}
}
return (0);
if (loc_is_enabled(loch)) {
/* Manually enabled locations should always win out. */
}
"condition value");
return (0);
}
"condition value");
return (0);
}
nelem);
if (satisfied) {
conditions, nelem);
}
}
return (0);
if (loc_is_enabled(loch)) {
/* Manually enabled locations should always win out. */
}
/* Either NoNet, Automatic or Legacy location, so skip. */
return (0);
default:
return (0);
}
/*NOTREACHED*/
return (0);
}
static int
{
return (0);
/* An online IP NCU found, stop walk */
return (1);
}
return (0);
}
void
{
const char *winning_loc;
/*
* Walk the NCUs to find out if at least one IP NCU is online. If so,
* check the activation-mode and conditions. If not, enable the NoNet
* location.
*/
&ncu_online);
if (!ncu_online) {
} else {
&wa);
else
}
/* If the winning location is already active, do nothing */
(void) pthread_mutex_lock(&active_loc_mutex);
(void) pthread_mutex_unlock(&active_loc_mutex);
if (is_active)
return;
}
int
{
return (1);
return (0);
}
/*
* Event handling functions.
*/
/* Handle loc initialization/refresh event */
void
{
!= NWAM_SUCCESS) {
nwam_strerror(err));
return;
}
} else {
}
/*
* If this location is ONLINE and the value of the "enabled" property
* has not changed, then this location is getting refreshed because it
* was committed with changes. Change states to re-activate itself.
* If the "enabled" property has changed, then this location is
* no need to change states here.
*/
}
}
/* Handle loc finish event */
void
{
/* Don't disable the location, as this can enable the Automatic loc */
return;
}
}
void
{
case NWAM_ACTION_ENABLE:
return;
}
"location %s already online, nothing to do",
return;
}
break;
case NWAM_ACTION_DISABLE:
return;
}
"location %s already disabled, nothing to do",
return;
}
break;
case NWAM_ACTION_ADD:
case NWAM_ACTION_REFRESH:
break;
case NWAM_ACTION_DESTROY:
break;
default:
"unexpected action");
break;
}
}
void
{
return;
}
"loc %s already in state (%s , %s)",
return;
}
/*
* State machine for location.
*/
switch (new_state) {
break;
/*
* Don't need to deactivate current location - condition check
* will activate another. If the currently active location is
* being deactivated, then it is being manually deactivated;
* so also clear active_loc so condition checking is not
* confused.
*/
(void) pthread_mutex_lock(&active_loc_mutex);
active_loc[0] = '\0';
(void) pthread_mutex_unlock(&active_loc_mutex);
break;
case NWAM_STATE_DISABLED:
case NWAM_STATE_OFFLINE:
case NWAM_STATE_UNINITIALIZED:
case NWAM_STATE_MAINTENANCE:
case NWAM_STATE_DEGRADED:
default:
/* do nothing */
break;
}
}