ex_dscp.c revision 77a7fd96f77f04bbd7634db14755686062589eca
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* FMA Event Transport Module Transport Layer API implementation.
*
* Library for establishing connections and transporting FMA events between
* ETMs (event-transport modules) in separate fault domains.
*
* The transport for this library is internet socket based and uses the DSCP
* client services library (libdscp).
*/
#include "ex_dscp.h"
/*
* On the SP, there is one DSCP interface for every domain.
* Each domain has one and only one DSCP interface to the SP.
*
* The DSCP interface is created when the domain powers-on. On the SP,
* a sysevent will be generated when the DSCP interface is up. On the domain,
* the DSCP interface should be up when ETM loads.
*/
/* Protects linked list of ex_hdl_t */
/*
* * * * * * * * * * * * * *
* Module specific routines
* * * * * * * * * * * * * *
*/
/*
* Allocate and initialize a transport instance handle.
* Return hdl pointer for success, NULL for failure.
*/
static exs_hdl_t *
{
return (hp);
}
/*
* dlopen() the platform filter library and dlsym() the filter funcs.
*/
static void
{
Send_filter = NULL;
Post_filter = NULL;
return;
} else {
Send_filter = NULL;
Post_filter = NULL;
return;
}
== NULL) {
Send_filter = NULL;
}
== NULL) {
Post_filter = NULL;
}
}
}
/*
* If open, dlclose() the platform filter library.
*/
/*ARGSUSED*/
static void
{
}
/*
* Translate endpoint_id string to int.
* Return the domain ID via "dom_id".
* Return 0 for success, nonzero for failure
*/
static int
{
char *ptr;
/* Remote endpoint is the SP */
*dom_id = DSCP_IDENT_SP;
return (0);
} else {
return (1);
}
return (1);
}
}
return (0);
}
/*
* Prepare the client connection.
* Return 0 for success, nonzero for failure.
*/
static int
{
/* Find the DSCP address for the remote endpoint */
return (1);
}
return (2);
}
return (3);
}
/*
* Set SO_LINGER so TCP aborts the connection when closed.
* If the domain's client socket goes into the TIME_WAIT state,
* ETM will be unable to connect to the SP until this clears.
* This connection is over DSCP, which is a simple point-to-point
* connection and therefore has no routers or multiple forwarding.
* The risk of receiving old packets from a previously terminated
* connection is very small.
*/
sizeof (ling))) {
return (4);
}
/* Bind the socket to the local IP address of the DSCP link */
EXS_CLIENT_PORT)) != DSCP_OK) {
return (5);
}
/* Set IPsec security policy for this socket */
return (6);
}
return (0);
}
/*
* Prepare to accept a connection.
* Return 0 for success, nonzero for failure.
*/
int
{
int rv;
return (1);
}
hp->h_endpt_id);
return (2);
}
/* Bind the socket to the local IP address of the DSCP link */
EXS_SERVER_PORT)) != DSCP_OK) {
return (3);
}
/* Activate IPsec security policy for this socket */
return (4);
}
return (5);
}
return (0);
}
/*
* Notify ETM that incoming data is available on server connection.
*/
static void
{
hp->h_cb_func_arg)) {
/* Any non-zero return means to close the connection */
}
}
/*
* Accept a new incoming connection.
*/
static void
{
struct sockaddr_in new_saddr;
&new_len)) != -1) {
/* Translate saddr to domain id */
return;
}
return;
}
/* Authenticate this connection request */
return;
}
}
/* Set the socket to be non-blocking */
} else {
}
}
/*
* Accepts incoming connections and notifies ETM of incoming data.
*/
void
exs_server(void *arg)
{
continue; /* loop around and check h_quit */
break;
}
}
continue;
}
exs_accept(hp);
}
hp->h_endpt_id);
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* ETM-to-Transport API Connection Management routines
* * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
* Initialize and setup any transport infrastructure before any connections
* are opened.
* Return etm_xport_hdl_t for success, NULL for failure.
*/
void *arg), void *cb_func_arg)
{
int dom;
return (NULL);
(void) pthread_mutex_lock(&List_lock);
/* Check for a duplicate endpoint_id on the list */
"duplicate domain id : %d\n", dom);
(void) pthread_mutex_unlock(&List_lock);
return (NULL);
}
}
/* Do one-time initializations */
}
/* Add this transport instance handle to the list */
if (exs_prep_accept(hp) == 0)
/* A server thread is created for every endpoint */
(void) pthread_mutex_unlock(&List_lock);
return ((etm_xport_hdl_t)hp);
}
/*
* Teardown any transport infrastructure after all connections are closed.
* Return 0 for success, or nonzero for failure.
*/
int
{
(void) pthread_mutex_lock(&List_lock);
else
break;
}
(void) pthread_mutex_unlock(&List_lock);
(void *)hp);
}
}
/* Socket descr for h_accept and h_server are closed in exs_server */
/* Undo one-time initializations */
}
(void) pthread_mutex_unlock(&List_lock);
return (0);
}
/*
* Open a connection with the given endpoint,
* Return etm_xport_conn_t for success, NULL and set errno for failure.
*/
{
int flags;
}
if (exs_prep_accept(hp) == 0)
}
if (exs_prep_client(hp) != 0)
return (NULL);
}
/* Set the socket to be non-blocking */
if (errno != EINPROGRESS) {
hp->h_endpt_id);
return (NULL);
}
}
hp->h_endpt_id);
}
/*
* Close a connection from either endpoint.
* Return zero for success, nonzero for failure.
*/
/*ARGSUSED*/
int
{
return (0); /* Connection already closed */
return (0);
}
/*
* * * * * * * * * * * * * * * * * *
* ETM-to-Transport API I/O routines
* * * * * * * * * * * * * * * * * *
*/
/*
* Try to read byte_cnt bytes from the connection into the given buffer.
* Return how many bytes actually read for success, negative value for failure.
*/
{
return (-EBADF);
}
0)) < 0) {
}
continue;
} else if (len == 0) {
return (0);
}
} else {
break;
}
}
if (nbytes)
return (nbytes);
else
return (-1);
}
/*
* Try to write byte_cnt bytes to the connection from the given buffer.
* Return how many bytes actually written for success, negative value
* for failure.
*/
{
return (-EBADF);
}
0)) < 0) {
}
continue;
}
} else {
break;
}
}
if (nbytes)
return (nbytes);
else
return (-1);
}
/*
* * * * * * * * * * * * * * * * * * * *
* ETM-to-Transport API Filter routines
* * * * * * * * * * * * * * * * * * * *
*/
/*
* Call the platform's send_filter function.
* Otherwise return ETM_XPORT_FILTER_OK.
*/
int
{
if (Send_filter != NULL)
else
return (ETM_XPORT_FILTER_OK);
}
/*
* Call the platform's post_filter function.
* Otherwise return ETM_XPORT_FILTER_OK.
*/
int
{
if (Post_filter != NULL)
else
return (ETM_XPORT_FILTER_OK);
}