xref: /illumos-gate/usr/src/uts/common/sys/hook_event.h (revision 336970851eecf9c4348b3de7bbea0687059dd216)
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  * This file include definition of message passed from hook provider
28  * to hook consumer.  If necessary, each hook provider can add its
29  * own message definition here.
30  */
31 
32 #ifndef _SYS_HOOK_EVENT_H
33 #define	_SYS_HOOK_EVENT_H
34 
35 #include <sys/neti.h>
36 #include <sys/hook.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 struct msgb;	/* avoiding sys/stream.h here */
43 
44 /*
45  * The hook_pkt_event_t structure is supplied with packet events on
46  * associated network interfaces.
47  *
48  * The members of this structure are defined as follows:
49  * hpe_protocol - protocol identifier that indicates which protocol the
50  *                header data is associated with.
51  * hpe_ifp - "in" interface for packets coming into the system or forwarded
52  * hpe_ofp - "out" interface for packets being transmitted or forwarded
53  * hpe_hdr - pointer to protocol header within the packet
54  * hpe_mp  - pointer to the mblk pointer starting the chain for this packet
55  * hpe_mb  - pointer to the mblk that contains hpe_hdr
56  */
57 typedef struct hook_pkt_event {
58 	net_handle_t		hpe_protocol;
59 	phy_if_t		hpe_ifp;
60 	phy_if_t		hpe_ofp;
61 	void			*hpe_hdr;
62 	struct msgb		**hpe_mp;
63 	struct msgb		*hpe_mb;
64 	int			hpe_flags;
65 	void			*hpe_reserved[2];
66 } hook_pkt_event_t;
67 
68 #define	HPE_MULTICAST	0x01
69 #define	HPE_BROADCAST	0x02
70 
71 /*
72  * NIC events hook provider
73  */
74 typedef enum nic_event {
75 	NE_PLUMB = 1,
76 	NE_UNPLUMB,
77 	NE_UP,
78 	NE_DOWN,
79 	NE_ADDRESS_CHANGE,
80 	NE_LIF_UP,
81 	NE_LIF_DOWN,
82 	NE_IFINDEX_CHANGE
83 } nic_event_t;
84 
85 typedef void *nic_event_data_t;
86 
87 /*
88  * The hook_nic_event data structure is provided with all network interface
89  * events.
90  *
91  * hne_protocol- network protocol for events, returned from net_lookup
92  * hne_nic     - physical interface associated with event
93  * hne_lif     - logical interface (if any) associated with event
94  * hne_event   - type of event occuring
95  * hne_data    - pointer to extra data about event or NULL if none
96  * hne_datalen - size of data pointed to by hne_data (can be 0)
97  */
98 typedef struct hook_nic_event {
99 	net_handle_t		hne_protocol;
100 	phy_if_t		hne_nic;
101 	lif_if_t		hne_lif;
102 	nic_event_t		hne_event;
103 	nic_event_data_t	hne_data;
104 	size_t			hne_datalen;
105 } hook_nic_event_t;
106 
107 /*
108  * This structure is used internally by ip to queue events.
109  */
110 struct hook_nic_event_int {
111 	netstackid_t		hnei_stackid;
112 	hook_nic_event_t	hnei_event;
113 };
114 typedef struct hook_nic_event_int hook_nic_event_int_t;
115 
116 /*
117  * This structure holds the data passed back from the ip module to
118  * observability consumers.
119  *
120  * Externally exposed fields, that must match the order and size of
121  * dl_ipnetinfo_t in <sys/dlpi.h> are:
122  * hpo_version    Version number for this header
123  * hpo_family     Address family of the attached packet
124  * hpo_htype      IPobs hook type
125  * hpo_pktlen     Length of the attached packet
126  * hpo_ifindex    Interface index that the packet was received/sent over.
127  *                For local packets, this is the index of the interface
128  *                associated with the local destination address.
129  * hpo_grifindex  IPMP group interface index (zero unless ihd_ifindex
130  *                is an IPMP underlying interface).
131  * hpo_zsrc       Source zoneid; set to ALL_ZONES when unknown.
132  * hpo_zdst       Destination zoneid; set to ALL_ZONES when unknown.
133  *
134  * Fields used internally are:
135  * hpo_pkt        Pointer to the mblk_t containig this structure with
136  *                the real packet found at b_cont
137  */
138 typedef struct hook_pkt_observe_s {
139 	uint8_t		hpo_version;
140 	uint8_t		hpo_family;
141 	uint16_t	hpo_htype;
142 	uint32_t	hpo_pktlen;
143 	uint32_t	hpo_ifindex;
144 	uint32_t	hpo_grifindex;
145 	uint32_t	hpo_zsrc;
146 	uint32_t	hpo_zdst;
147 	/*
148 	 * Fields used internally are below.
149 	 */
150 	struct msgb	*hpo_pkt;
151 	void		*hpo_ctx;
152 } hook_pkt_observe_t;
153 
154 /*
155  * ipobs_hooktype_t describes the hook types supported
156  * by the ip module. IPOBS_HOOK_LOCAL refers to packets
157  * which are looped back internally within the ip module.
158  */
159 
160 typedef enum ipobs_hook_type {
161 	IPOBS_HOOK_INBOUND = 0,
162 	IPOBS_HOOK_OUTBOUND = 1,
163 	IPOBS_HOOK_LOCAL = 2
164 } ipobs_hook_type_t;
165 
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif /* _SYS_HOOK_EVENT_H */
172