xref: /titanic_44/usr/src/uts/common/sys/neti.h (revision 23259b79afff8cc5e183c5be57e05120f378fa72)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_NETI_H
27 #define	_SYS_NETI_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <netinet/in.h>
32 #include <sys/int_types.h>
33 #include <sys/queue.h>
34 #include <sys/hook_impl.h>
35 #include <sys/netstack.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #define	NETINFO_VERSION 1
42 
43 /*
44  * Network hooks framework stack protocol name
45  */
46 #define	NHF_INET	"NHF_INET"
47 #define	NHF_INET6	"NHF_INET6"
48 #define	NHF_ARP		"NHF_ARP"
49 
50 /*
51  * Event identification
52  */
53 #define	NH_PHYSICAL_IN	"PHYSICAL_IN"
54 #define	NH_PHYSICAL_OUT	"PHYSICAL_OUT"
55 #define	NH_FORWARDING	"FORWARDING"
56 #define	NH_LOOPBACK_IN	"LOOPBACK_IN"
57 #define	NH_LOOPBACK_OUT	"LOOPBACK_OUT"
58 #define	NH_NIC_EVENTS	"NIC_EVENTS"
59 
60 /*
61  * Network NIC hardware checksum capability
62  */
63 #define	NET_HCK_NONE   	0x00
64 #define	NET_HCK_L3_FULL	0x01
65 #define	NET_HCK_L3_PART	0x02
66 #define	NET_HCK_L4_FULL	0x10
67 #define	NET_HCK_L4_PART	0x20
68 
69 #define	NET_IS_HCK_L3_FULL(n, x)                                             \
70 	((net_ispartialchecksum(n, x) & NET_HCK_L3_FULL) == NET_HCK_L3_FULL)
71 #define	NET_IS_HCK_L3_PART(n, x)                                             \
72 	((net_ispartialchecksum(n, x) & NET_HCK_L3_PART) == NET_HCK_L3_PART)
73 #define	NET_IS_HCK_L4_FULL(n, x)                                             \
74 	((net_ispartialchecksum(n, x) & NET_HCK_L4_FULL) == NET_HCK_L4_FULL)
75 #define	NET_IS_HCK_L4_PART(n, x)                                             \
76 	((net_ispartialchecksum(n, x) & NET_HCK_L4_PART) == NET_HCK_L4_PART)
77 #define	NET_IS_HCK_L34_FULL(n, x)                                            \
78 	((net_ispartialchecksum(n, x) & (NET_HCK_L3_FULL|NET_HCK_L4_FULL))   \
79 	    == (NET_HCK_L3_FULL | NET_HCK_L4_FULL))
80 
81 typedef uintptr_t	phy_if_t;
82 typedef intptr_t	lif_if_t;
83 typedef uintptr_t	net_ifdata_t;
84 
85 struct net_data;
86 typedef struct net_data *net_data_t;
87 
88 /*
89  * Netinfo interface specification
90  *
91  * Netinfo provides an extensible and easy to use interface for
92  * accessing data and functionality already embedded within network
93  * code that exists within the kernel.
94  */
95 typedef enum net_ifaddr {
96 	NA_ADDRESS = 1,
97 	NA_PEER,
98 	NA_BROADCAST,
99 	NA_NETMASK
100 } net_ifaddr_t;
101 
102 
103 typedef enum inject {
104 	NI_QUEUE_IN = 1,
105 	NI_QUEUE_OUT,
106 	NI_DIRECT_OUT
107 } inject_t;
108 
109 typedef struct net_inject {
110 	mblk_t			*ni_packet;
111 	struct sockaddr_storage	ni_addr;
112 	phy_if_t		ni_physical;
113 } net_inject_t;
114 
115 
116 /*
117  * net_info_t public interface
118  */
119 typedef struct net_info {
120 	int		neti_version;
121 	char		*neti_protocol;
122 	int		(*neti_getifname)(phy_if_t, char *, const size_t,
123 			    netstack_t *);
124 	int		(*neti_getmtu)(phy_if_t, lif_if_t, netstack_t *);
125 	int		(*neti_getpmtuenabled)(netstack_t *);
126 	int		(*neti_getlifaddr)(phy_if_t, lif_if_t, size_t,
127 			    net_ifaddr_t [], void *, netstack_t *);
128 	phy_if_t	(*neti_phygetnext)(phy_if_t, netstack_t *);
129 	phy_if_t	(*neti_phylookup)(const char *, netstack_t *);
130 	lif_if_t	(*neti_lifgetnext)(phy_if_t, lif_if_t, netstack_t *);
131 	int		(*neti_inject)(inject_t, net_inject_t *, netstack_t *);
132 	phy_if_t	(*neti_routeto)(struct sockaddr *, netstack_t *);
133 	int		(*neti_ispartialchecksum)(mblk_t *);
134 	int		(*neti_isvalidchecksum)(mblk_t *);
135 } net_info_t;
136 
137 
138 /*
139  * Private data structures
140  */
141 struct net_data {
142 	LIST_ENTRY(net_data)		netd_list;
143 	net_info_t			netd_info;
144 	int				netd_refcnt;
145 	hook_family_int_t		*netd_hooks;
146 	netstack_t 			*netd_netstack;
147 };
148 
149 
150 typedef struct injection_s {
151 	net_inject_t	inj_data;
152 	boolean_t	inj_isv6;
153 	void *		inj_ptr;
154 } injection_t;
155 
156 /*
157  * The ipif_id space is [0,MAX) but this interface wants to return [1,MAX] as
158  * a valid range of logical interface numbers so that it can return 0 to mean
159  * "end of list" with net_lifgetnext.  Changing ipif_id's to use the [1,MAX]
160  * space is something to be considered for the future, if it is worthwhile.
161  */
162 #define	MAP_IPIF_ID(x)		((x) + 1)
163 #define	UNMAP_IPIF_ID(x)	(((x) > 0) ? (x) - 1 : (x))
164 
165 
166 /*
167  * neti stack instances
168  */
169 struct neti_stack {
170 	krwlock_t nts_netlock;
171 
172 	/* list of net_data_t */
173 	LIST_HEAD(netd_listhead, net_data) nts_netd_head;
174 	netstack_t *nts_netstack;
175 };
176 typedef struct neti_stack neti_stack_t;
177 
178 
179 /*
180  * Data management functions
181  */
182 extern net_data_t net_register(const net_info_t *, netstackid_t);
183 extern net_data_t net_register_impl(const net_info_t *, netstack_t *);
184 extern int net_unregister(net_data_t);
185 extern net_data_t net_lookup(const char *, netstackid_t);
186 extern net_data_t net_lookup_impl(const char *, netstack_t *);
187 extern int net_release(net_data_t);
188 extern net_data_t net_walk(net_data_t, netstackid_t);
189 extern net_data_t net_walk_impl(net_data_t, netstack_t *);
190 
191 /*
192  * Accessor functions
193  */
194 extern int net_register_family(net_data_t, hook_family_t *);
195 extern int net_unregister_family(net_data_t, hook_family_t *);
196 extern hook_event_token_t net_register_event(net_data_t, hook_event_t *);
197 extern int net_unregister_event(net_data_t, hook_event_t *);
198 extern int net_register_hook(net_data_t, char *, hook_t *);
199 extern int net_unregister_hook(net_data_t, char *, hook_t *);
200 extern int net_getifname(net_data_t, phy_if_t, char *, const size_t);
201 extern int net_getmtu(net_data_t, phy_if_t, lif_if_t);
202 extern int net_getpmtuenabled(net_data_t);
203 extern int net_getlifaddr(net_data_t, phy_if_t, lif_if_t,
204     int, net_ifaddr_t [], void *);
205 extern phy_if_t net_phygetnext(net_data_t, phy_if_t);
206 extern phy_if_t net_phylookup(net_data_t, const char *);
207 extern lif_if_t net_lifgetnext(net_data_t, phy_if_t, lif_if_t);
208 extern int net_inject(net_data_t, inject_t, net_inject_t *);
209 extern phy_if_t net_routeto(net_data_t, struct sockaddr *);
210 extern int net_ispartialchecksum(net_data_t, mblk_t *);
211 extern int net_isvalidchecksum(net_data_t, mblk_t *);
212 
213 #ifdef	__cplusplus
214 }
215 #endif
216 
217 #endif /* _SYS_NETI_H */
218