25cf1a301a396c38e8adf52c15f537b80d2483f7jl * CDDL HEADER START
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * The contents of this file are subject to the terms of the
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Common Development and Distribution License (the "License").
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * You may not use this file except in compliance with the License.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * See the License for the specific language governing permissions
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * and limitations under the License.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * When distributing Covered Code, include this CDDL HEADER in each
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * If applicable, add the following below this CDDL HEADER, with the
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * fields enclosed by brackets "[]" replaced with your own identifying
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * information: Portions Copyright [yyyy] [name of copyright owner]
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * CDDL HEADER END
677fd05c3b05c78948501f6ffdced37dab9368feMary Beale * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Use is subject to license terms.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * FMA Event Transport Module Transport Layer API implementation.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Library for establishing connections and transporting FMA events between
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * ETMs (event-transport modules) in separate fault domains.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * The transport for this library is internet socket based and uses the DSCP
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * client services library (libdscp).
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * On the SP, there is one DSCP interface for every domain.
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * Each domain has one and only one DSCP interface to the SP.
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * The DSCP interface is created when the domain powers-on. On the SP,
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * a sysevent will be generated when the DSCP interface is up. On the domain,
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * the DSCP interface should be up when ETM loads.
ac92251dc182f030faf6a5f76981d551b0b16072jruttexs_conn_t Acc; /* Connection for accepting/listening */
d338766d6376ee721b7f1778e12bf79a112bd778jruttexs_hdl_t *Exh_head = NULL; /* Head of ex_hdl_t list */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Protects linked list of ex_hdl_t */
77a7fd96f77f04bbd7634db14755686062589ecajruttstatic void *Dlp = NULL; /* Handle for dlopen/dlclose/dlsym */
77a7fd96f77f04bbd7634db14755686062589ecajruttstatic int (*Send_filter)(fmd_hdl_t *hdl, nvlist_t *event, const char *dest);
77a7fd96f77f04bbd7634db14755686062589ecajruttstatic int (*Post_filter)(fmd_hdl_t *hdl, nvlist_t *event, const char *src);
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * * * * * * * * * * * * * *
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * Module specific routines
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * * * * * * * * * * * * * *
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Allocate and initialize a transport instance handle.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return hdl pointer for success, NULL for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int (*cb_func)(fmd_hdl_t *hdl, etm_xport_conn_t conn, etm_cb_flag_t flag,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl hp->h_endpt_id = fmd_hdl_strdup(hdl, endpoint_id, FMD_SLEEP);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (hp);
77a7fd96f77f04bbd7634db14755686062589ecajrutt * dlopen() the platform filter library and dlsym() the filter funcs.
77a7fd96f77f04bbd7634db14755686062589ecajrutt char *propstr = fmd_prop_get_string(hdl, "filter_path");
77a7fd96f77f04bbd7634db14755686062589ecajrutt if ((Dlp = dlopen(propstr, RTLD_LOCAL | RTLD_NOW)) == NULL) {
77a7fd96f77f04bbd7634db14755686062589ecajrutt if ((Send_filter = (int (*)())dlsym(Dlp, "send_filter"))
77a7fd96f77f04bbd7634db14755686062589ecajrutt if ((Post_filter = (int (*)())dlsym(Dlp, "post_filter"))
77a7fd96f77f04bbd7634db14755686062589ecajrutt * If open, dlclose() the platform filter library.
77a7fd96f77f04bbd7634db14755686062589ecajrutt/*ARGSUSED*/
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * Translate endpoint_id string to int.
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * Return the domain ID via "dom_id".
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * Return 0 for success, nonzero for failure
d338766d6376ee721b7f1778e12bf79a112bd778jruttexs_get_id(fmd_hdl_t *hdl, char *endpoint_id, int *dom_id)
d338766d6376ee721b7f1778e12bf79a112bd778jrutt /* Remote endpoint is the SP */
d338766d6376ee721b7f1778e12bf79a112bd778jrutt return (0);
d338766d6376ee721b7f1778e12bf79a112bd778jrutt if ((ptr = strstr(endpoint_id, EXS_DOMAIN_PREFIX)) == NULL) {
ac92251dc182f030faf6a5f76981d551b0b16072jrutt "found in %s. Check event-transport.conf\n",
d338766d6376ee721b7f1778e12bf79a112bd778jrutt return (1);
ac92251dc182f030faf6a5f76981d551b0b16072jrutt "integer found in %s. Check event-transport.conf\n",
ac92251dc182f030faf6a5f76981d551b0b16072jrutt return (2);
d338766d6376ee721b7f1778e12bf79a112bd778jrutt return (0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Prepare the client connection.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return 0 for success, nonzero for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Find the DSCP address for the remote endpoint */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_debug(hp->h_hdl, "dscpAddr on the client socket "
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (1);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((hp->h_client.c_sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hp->h_hdl, "Failed to create the client socket "
d338766d6376ee721b7f1778e12bf79a112bd778jrutt return (2);
535096c2bb10e7c765411fcb939b54c081ba4e07jrutt if (setsockopt(hp->h_client.c_sd, SOL_SOCKET, SO_REUSEADDR,
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hp->h_hdl, "Failed to set REUSEADDR on the "
535096c2bb10e7c765411fcb939b54c081ba4e07jrutt return (3);
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt * Set SO_LINGER so TCP aborts the connection when closed.
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt * If the domain's client socket goes into the TIME_WAIT state,
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt * ETM will be unable to connect to the SP until this clears.
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt * This connection is over DSCP, which is a simple point-to-point
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt * connection and therefore has no routers or multiple forwarding.
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt * The risk of receiving old packets from a previously terminated
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt * connection is very small.
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt if (setsockopt(hp->h_client.c_sd, SOL_SOCKET, SO_LINGER, &ling,
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt sizeof (ling))) {
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hp->h_hdl, "Failed to set SO_LINGER on the "
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt return (4);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Bind the socket to the local IP address of the DSCP link */
677fd05c3b05c78948501f6ffdced37dab9368feMary Beale fmd_hdl_debug(hp->h_hdl, "dscpBind on the client "
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt return (5);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Set IPsec security policy for this socket */
d338766d6376ee721b7f1778e12bf79a112bd778jrutt if ((rv = dscpSecure(hp->h_dom, hp->h_client.c_sd)) != DSCP_OK) {
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hp->h_hdl, "dscpSecure on the client socket "
c0e3f49ac0b4f11393ded2ed1fdf519a0b57c098jrutt return (6);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0);
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * Server function/thread. There is one thread per endpoint.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * Accepts incoming connections and notifies ETM of incoming data.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt continue; /* loop around and check h_quit */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_debug(hp->h_hdl, "xport - poll hangup/err for "
ac92251dc182f030faf6a5f76981d551b0b16072jrutt break; /* thread exits */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt /* Notify ETM that incoming data is available */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * For any non-zero return, close the
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * connection and exit the thread.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt break; /* thread exits */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_debug(hp->h_hdl, "xport - exiting server thread for %s",
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * Accept a new incoming connection.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt if ((new_sd = accept(Acc.c_sd, (struct sockaddr *)&new_saddr,
d338766d6376ee721b7f1778e12bf79a112bd778jrutt /* Translate saddr to domain id */
d338766d6376ee721b7f1778e12bf79a112bd778jrutt if ((rv = dscpIdent((struct sockaddr *)&new_saddr, (int)new_len,
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hdl, "dscpIdent failed : rv = %d\n", rv);
ac92251dc182f030faf6a5f76981d551b0b16072jrutt /* Find the exs_hdl_t for the domain trying to connect */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt "connection from domain %d. Check "
d338766d6376ee721b7f1778e12bf79a112bd778jrutt /* Authenticate this connection request */
d338766d6376ee721b7f1778e12bf79a112bd778jrutt if ((rv = dscpAuth(dom, (struct sockaddr *)&new_saddr,
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hdl, "dscpAuth failed for %s : rv = %d ",
d338766d6376ee721b7f1778e12bf79a112bd778jrutt /* Set the socket to be non-blocking */
45179f4335d029f1129eb7283f8087740f0395f1Karl Davis fmd_hdl_error(hdl, "Failed to accept() a new connection");
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * Listen for and accept incoming connections.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * There is only one such thread.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt continue; /* loop around and check Acc_quit */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt "accept socket");
ac92251dc182f030faf6a5f76981d551b0b16072jrutt break; /* thread exits */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_debug(hdl, "xport - exiting accept-listen thread");
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * Prepare to accept a connection.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * Return 0 for success, nonzero for failure.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt return; /* nothing to do */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt /* Check to see if the DSCP interface is configured */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt (struct sockaddr *)&Acc.c_saddr, &Acc.c_len)) != DSCP_OK) {
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_debug(hdl, "xport - dscpAddr on the accept socket "
ac92251dc182f030faf6a5f76981d551b0b16072jrutt if ((Acc.c_sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hdl, "Failed to create the accept socket");
ac92251dc182f030faf6a5f76981d551b0b16072jrutt if (setsockopt(Acc.c_sd, SOL_SOCKET, SO_REUSEADDR, &optval,
ac92251dc182f030faf6a5f76981d551b0b16072jrutt sizeof (optval))) {
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hdl, "Failed to set REUSEADDR for the accept "
ac92251dc182f030faf6a5f76981d551b0b16072jrutt /* Bind the socket to the local IP address of the DSCP link */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt if ((rv = dscpBind(dom, Acc.c_sd, EXS_SERVER_PORT)) != DSCP_OK) {
677fd05c3b05c78948501f6ffdced37dab9368feMary Beale fmd_hdl_debug(hdl, "dscpBind on the accept socket "
ac92251dc182f030faf6a5f76981d551b0b16072jrutt /* Activate IPsec security policy for this socket */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_error(hdl, "dscpSecure on the accept socket failed : "
ac92251dc182f030faf6a5f76981d551b0b16072jrutt fmd_hdl_debug(hdl, "Failed to listen() for connections");
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * * * * * * * * * * * * * * * * * * * * * * * * * * *
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * ETM-to-Transport API Connection Management routines
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * * * * * * * * * * * * * * * * * * * * * * * * * * *
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Initialize and setup any transport infrastructure before any connections
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * are opened.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return etm_xport_hdl_t for success, NULL for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int (*cb_func)(fmd_hdl_t *hdl, etm_xport_conn_t conn, etm_cb_flag_t flag,
d338766d6376ee721b7f1778e12bf79a112bd778jrutt /* Check for a duplicate endpoint_id on the list */
77a7fd96f77f04bbd7634db14755686062589ecajrutt /* Do one-time initializations */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt /* Initialize the accept/listen vars */
d338766d6376ee721b7f1778e12bf79a112bd778jrutt hp = exs_hdl_alloc(hdl, endpoint_id, cb_func, cb_func_arg, dom);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Add this transport instance handle to the list */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Teardown any transport infrastructure after all connections are closed.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return 0 for success, or nonzero for failure.
d338766d6376ee721b7f1778e12bf79a112bd778jrutt fmd_hdl_abort(hdl, "xport - fini failed, tlhdl %p not on list",
77a7fd96f77f04bbd7634db14755686062589ecajrutt /* Undo one-time initializations */
ac92251dc182f030faf6a5f76981d551b0b16072jrutt /* Destroy the accept/listen thread */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Open a connection with the given endpoint,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return etm_xport_conn_t for success, NULL and set errno for failure.
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt /* Set the socket to be non-blocking */
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt (void) fcntl(hp->h_client.c_sd, F_SETFL, flags | O_NONBLOCK);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "xport - connected client socket for %s",
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Close a connection from either endpoint.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return zero for success, nonzero for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/*ARGSUSED*/
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0); /* Connection already closed */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0);
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * * * * * * * * * * * * * * * * * *
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * ETM-to-Transport API I/O routines
d338766d6376ee721b7f1778e12bf79a112bd778jrutt * * * * * * * * * * * * * * * * * *
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Try to read byte_cnt bytes from the connection into the given buffer.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return how many bytes actually read for success, negative value for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_xport_read(fmd_hdl_t *hdl, etm_xport_conn_t conn, hrtime_t timeout,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (-EBADF);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl 0)) < 0) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl } else if (len == 0) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (-1);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Try to write byte_cnt bytes to the connection from the given buffer.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return how many bytes actually written for success, negative value
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_xport_write(fmd_hdl_t *hdl, etm_xport_conn_t conn, hrtime_t timeout,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "xport - write socket %d is closed\n",
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (-EBADF);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl 0)) < 0) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (-1);
77a7fd96f77f04bbd7634db14755686062589ecajrutt * * * * * * * * * * * * * * * * * * * *
77a7fd96f77f04bbd7634db14755686062589ecajrutt * ETM-to-Transport API Filter routines
77a7fd96f77f04bbd7634db14755686062589ecajrutt * * * * * * * * * * * * * * * * * * * *
77a7fd96f77f04bbd7634db14755686062589ecajrutt * Call the platform's send_filter function.
77a7fd96f77f04bbd7634db14755686062589ecajrutt * Otherwise return ETM_XPORT_FILTER_OK.
77a7fd96f77f04bbd7634db14755686062589ecajruttetm_xport_send_filter(fmd_hdl_t *hdl, nvlist_t *event, const char *dest)
77a7fd96f77f04bbd7634db14755686062589ecajrutt * Call the platform's post_filter function.
77a7fd96f77f04bbd7634db14755686062589ecajrutt * Otherwise return ETM_XPORT_FILTER_OK.