events.c revision b00044a2eb43864b8718585d21949611a2ee59ef
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This file contains routines to retrieve events from the system and package
* them for high level processing.
*
* struct np_event is the basic event structure. The np_event structure and
* its npe_name member are allocated using malloc(3c). free_event() frees both
* the npe_name member and the associated np_event structure.
*
* np_queue_add_event() and np_queue_get_event() provide functionality for
* adding events to a queue and blocking on that queue for an event.
*
* Functions of the form addevent_*() provide the mechanism to cook down a
* higher level event into an np_event and put it on the queue.
*
* hotplug_handler() is called for EC_DEV_ADD and EC_DEV_REMOVE hotplug events
* configuration (the interface and llp lists).
*
* routing_events() reads routing messages off of an IPv4 routing socket and
* by calling addevent_*() functions places appropriate events on the queue.
*
* start_event_collection() creates a thread to run routing_events() and one
* to run periodic_wireless_scan() in. Finally it does an initial collection
* of information from each interface currently known.
*/
#include <errno.h>
#include <libsysevent.h>
#include <libnvpair.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include "defines.h"
#include "structures.h"
#include "functions.h"
#include "variables.h"
static struct np_event *equeue_end;
static sysevent_handle_t *sysevent_handle;
union rtm_buf
{
/* Routing information. */
struct
{
} r;
/* Interface information. */
struct
{
} im;
/* Interface address information. */
struct
{
struct ifa_msghdr ifa;
} ia;
};
void
{
}
{
return (B_FALSE);
}
(void) pthread_mutex_lock(&queue_mutex);
dprintf("adding event type %s name %s to queue",
if (equeue_end != NULL) {
equeue_end = npe;
} else {
}
(void) pthread_cond_signal(&queue_cond);
(void) pthread_mutex_unlock(&queue_mutex);
return (B_TRUE);
}
/*
* Blocking getevent. This routine will block until there is an event for
* it to return.
*/
struct np_event *
np_queue_get_event(void)
{
(void) pthread_mutex_lock(&queue_mutex);
equeue_end = NULL;
(void) pthread_mutex_unlock(&queue_mutex);
return (rv);
}
const char *
{
switch (type) {
case EV_LINKDROP:
return ("LINKDROP");
case EV_LINKUP:
return ("LINKUP");
case EV_LINKFADE:
return ("LINKFADE");
case EV_LINKDISC:
return ("LINKDISC");
case EV_NEWAP:
return ("NEWAP");
case EV_USER:
return ("USER");
case EV_TIMER:
return ("TIMER");
case EV_SHUTDOWN:
return ("SHUTDOWN");
case EV_NEWADDR:
return ("NEWADDR");
case EV_RESELECT:
return ("RESELECT");
case EV_DOOR_TIME:
return ("DOOR_TIME");
case EV_ADDIF:
return ("ADDIF");
case EV_REMIF:
return ("REMIF");
case EV_TAKEDOWN:
return ("TAKEDOWN");
default:
return ("unknown");
}
}
static const char *
rtmtype_str(int type)
{
switch (type) {
case RTM_ADD:
return ("ADD");
case RTM_DELETE:
return ("DELETE");
case RTM_NEWADDR:
return ("NEWADDR");
case RTM_DELADDR:
return ("DELADDR");
case RTM_IFINFO:
return ("IFINFO");
default:
type);
return (typestr);
}
}
/*
* At present, we only handle EC_DEV_ADD/EC_DEV_REMOVE sysevents of
*
* The sysevents are converted into NWAM events so that we can process them in
* the main loop. If we didn't do this, we'd either have bad pointer
* references or need to have reference counts on everything. Serializing
* through the event mechanism is much simpler.
*/
static void
{
char *driver;
int retv;
return;
}
/*
* Retrieve driver name and instance attributes, and combine to
* get interface name.
*/
return;
}
if (retv == 0)
if (retv != 0) {
} else {
}
}
static void
{
/* Unsubscribe to sysevents */
}
static void
hotplug_events_register(void)
{
const char *subclass = ESC_NETWORK;
if (sysevent_handle == NULL) {
return;
}
/*
* Subscribe to ESC_NETWORK subclass of EC_DEV_ADD and EC_DEV_REMOVE
* events. As a result, we get sysevent notification of hotplug
*/
&subclass, 1) != 0) {
}
}
/*
* This thread reads routing socket events and sends them to the main state
* machine. We must be careful with access to interface data structures here,
* as we're not the main thread, which may delete things. Holding a pointer is
* not allowed.
*/
/* ARGSUSED */
static void *
routing_events(void *arg)
{
int rtsock;
int n;
struct ifa_msghdr *ifa;
/*
* We use v4 interfaces as proxies for links so those are the only
* routing messages we need to listen to. Look at the comments in
* structures.h for more information about the split between the
* llp and interfaces.
*/
if (rtsock == -1) {
}
for (;;) {
char *addrs;
struct sockaddr_dl *addr_dl;
struct sockaddr_in *addr_in;
continue;
} else if (n == -1) {
"%d: %m", rtsock);
/* Low likelihood. What's recovery path? */
continue;
}
if (rtm->rtm_msglen < n) {
"routing socket but message claims to be "
continue;
}
continue;
}
if (rtm->rtm_msglen != n) {
dprintf("routing message of %d size came from "
n, rtsock);
}
case RTM_DELADDR: {
/*
* Check for failure due to CR 6745448: if we get a
* report that an address has been deleted, then check
* for interface up, datalink down, and actual address
* non-zero. If that combination is seen, then this is
* a DHCP cached lease, and we need to remove it from
* the system, or it'll louse up the kernel routes
* (which aren't smart enough to avoid dead
* interfaces).
*/
dprintf("routing message DELADDR: index %d flags %x",
if (ifa->ifam_index == 0) {
/* what is this? */
dprintf("tossing index 0 routing event");
break;
}
dprintf("no RTA_IFA in RTM_DELADDR message");
break;
}
dprintf("no RTA_IFP in RTM_DELADDR message");
break;
}
AF_INET);
!(ifflags & IFF_RUNNING))
}
break;
}
case RTM_NEWADDR:
dprintf("routing message NEWADDR: index %d flags %x",
if (ifa->ifam_index == 0) {
/* what is this? */
dprintf("tossing index 0 routing event");
break;
}
dprintf("no RTA_IFA in RTM_NEWADDR message");
break;
}
dprintf("no RTA_IFP in RTM_NEWADDR message");
break;
}
/*
* We don't use the lladdr in this structure so we can
* run over it.
*/
break;
case RTM_IFINFO:
dprintf("routing message IFINFO: index %d flags %x",
dprintf("tossing index 0 routing event");
break;
}
dprintf("no RTA_IFP in RTM_IFINFO message");
break;
}
/*
* We don't use the lladdr in this structure so we can
* run over it.
*/
break;
default:
dprintf("routing message %s socket %d discarded",
break;
}
}
/* NOTREACHED */
return (NULL);
}
static char *
{
static char buffer[80];
switch (family) {
case AF_UNSPEC:
sizeof (buffer));
break;
case AF_INET:
sizeof (buffer));
break;
case AF_INET6:
sizeof (buffer));
break;
case AF_LINK:
break;
default:
/*
* We can't reliably update the size of this thing
* because we don't know what its type is. So bump
* it by a sockaddr_in and see what happens. The
* caller should really make sure this never happens.
*/
"unknown address family %d", family);
break;
}
return (buffer);
}
static void
{
if (mask == 0)
return;
if (mask & RTA_GATEWAY)
if (mask & RTA_NETMASK)
if (mask & RTA_GENMASK)
if (mask & RTA_AUTHOR)
}
static void
{
switch (family) {
case AF_UNSPEC:
case AF_INET:
break;
case AF_INET6:
break;
case AF_LINK:
break;
default:
break;
}
}
static void *
{
int i;
void *p = address;
return (NULL);
if (i & mask)
nextaddr(&p);
}
return (p);
}
start_event_collection(void)
{
int err;
/*
* have to change this.
*/
} else {
}
} else {
}
/*
* This function registers a callback which will get a dedicated thread
* for handling of hotplug sysevents when they occur.
*/
dprintf("initial interface scan");
return (B_TRUE);
}