xref: /illumos-gate/usr/src/cmd/syseventd/modules/datalink_mod/datalink_mod.c (revision 5093e10312724e92dd76c008a15bdb59d414708a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * datalink syseventd module.
28  *
29  * The purpose of this module is to identify all datalink related events,
30  * and react accordingly.
31  */
32 
33 #include <errno.h>
34 #include <sys/sysevent/eventdefs.h>
35 #include <string.h>
36 #include <libnvpair.h>
37 #include <librcm.h>
38 #include <libsysevent.h>
39 
40 static rcm_handle_t *rcm_hdl = NULL;
41 
42 /*ARGSUSED*/
43 static int
44 datalink_deliver_event(sysevent_t *ev, int unused)
45 {
46 	const char *class = sysevent_get_class_name(ev);
47 	const char *subclass = sysevent_get_subclass_name(ev);
48 	nvlist_t *nvl;
49 	int err = 0;
50 
51 	if (strcmp(class, EC_DATALINK) != 0 ||
52 	    strcmp(subclass, ESC_DATALINK_PHYS_ADD) != 0) {
53 		return (0);
54 	}
55 
56 	if (sysevent_get_attr_list(ev, &nvl) != 0)
57 		return (EINVAL);
58 
59 	/*
60 	 * Send the PHYSLINK_NEW event to network_rcm to update the network
61 	 * devices cache accordingly.
62 	 */
63 	if ((rcm_notify_event(rcm_hdl, RCM_RESOURCE_PHYSLINK_NEW, 0,
64 	    nvl, NULL) != RCM_SUCCESS)) {
65 		err = EINVAL;
66 	}
67 
68 	nvlist_free(nvl);
69 	return (err);
70 }
71 
72 static struct slm_mod_ops datalink_mod_ops = {
73 	SE_MAJOR_VERSION,
74 	SE_MINOR_VERSION,
75 	SE_MAX_RETRY_LIMIT,
76 	datalink_deliver_event
77 };
78 
79 struct slm_mod_ops *
80 slm_init()
81 {
82 	if (rcm_alloc_handle(NULL, 0, NULL, &rcm_hdl) != RCM_SUCCESS)
83 		return (NULL);
84 
85 	return (&datalink_mod_ops);
86 }
87 
88 void
89 slm_fini()
90 {
91 	(void) rcm_free_handle(rcm_hdl);
92 	rcm_hdl = NULL;
93 }
94