xref: /titanic_51/usr/src/uts/common/sys/neti.h (revision f4b3ec61df05330d25f55a36b975b4d7519fdeb1)
1381a2a9aSdr146992 /*
2381a2a9aSdr146992  * CDDL HEADER START
3381a2a9aSdr146992  *
4381a2a9aSdr146992  * The contents of this file are subject to the terms of the
5381a2a9aSdr146992  * Common Development and Distribution License (the "License").
6381a2a9aSdr146992  * You may not use this file except in compliance with the License.
7381a2a9aSdr146992  *
8381a2a9aSdr146992  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9381a2a9aSdr146992  * or http://www.opensolaris.org/os/licensing.
10381a2a9aSdr146992  * See the License for the specific language governing permissions
11381a2a9aSdr146992  * and limitations under the License.
12381a2a9aSdr146992  *
13381a2a9aSdr146992  * When distributing Covered Code, include this CDDL HEADER in each
14381a2a9aSdr146992  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15381a2a9aSdr146992  * If applicable, add the following below this CDDL HEADER, with the
16381a2a9aSdr146992  * fields enclosed by brackets "[]" replaced with your own identifying
17381a2a9aSdr146992  * information: Portions Copyright [yyyy] [name of copyright owner]
18381a2a9aSdr146992  *
19381a2a9aSdr146992  * CDDL HEADER END
20381a2a9aSdr146992  */
21381a2a9aSdr146992 /*
22*f4b3ec61Sdh155122  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23381a2a9aSdr146992  * Use is subject to license terms.
24381a2a9aSdr146992  */
25381a2a9aSdr146992 
26381a2a9aSdr146992 #ifndef _SYS_NETI_H
27381a2a9aSdr146992 #define	_SYS_NETI_H
28381a2a9aSdr146992 
29381a2a9aSdr146992 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30381a2a9aSdr146992 
31381a2a9aSdr146992 #include <netinet/in.h>
32381a2a9aSdr146992 #include <sys/int_types.h>
33381a2a9aSdr146992 #include <sys/queue.h>
34381a2a9aSdr146992 #include <sys/hook_impl.h>
35*f4b3ec61Sdh155122 #include <sys/netstack.h>
36381a2a9aSdr146992 
37381a2a9aSdr146992 #ifdef	__cplusplus
38381a2a9aSdr146992 extern "C" {
39381a2a9aSdr146992 #endif
40381a2a9aSdr146992 
41381a2a9aSdr146992 #define	NETINFO_VERSION 1
42381a2a9aSdr146992 
43381a2a9aSdr146992 /*
44381a2a9aSdr146992  * Network hooks framework stack protocol name
45381a2a9aSdr146992  */
46381a2a9aSdr146992 #define	NHF_INET	"NHF_INET"
47381a2a9aSdr146992 #define	NHF_INET6	"NHF_INET6"
48381a2a9aSdr146992 #define	NHF_ARP		"NHF_ARP"
49381a2a9aSdr146992 
50381a2a9aSdr146992 /*
51381a2a9aSdr146992  * Event identification
52381a2a9aSdr146992  */
53381a2a9aSdr146992 #define	NH_PHYSICAL_IN	"PHYSICAL_IN"
54381a2a9aSdr146992 #define	NH_PHYSICAL_OUT	"PHYSICAL_OUT"
55381a2a9aSdr146992 #define	NH_FORWARDING	"FORWARDING"
56381a2a9aSdr146992 #define	NH_LOOPBACK_IN	"LOOPBACK_IN"
57381a2a9aSdr146992 #define	NH_LOOPBACK_OUT	"LOOPBACK_OUT"
58381a2a9aSdr146992 #define	NH_NIC_EVENTS	"NIC_EVENTS"
59381a2a9aSdr146992 
60381a2a9aSdr146992 /*
61381a2a9aSdr146992  * Network NIC hardware checksum capability
62381a2a9aSdr146992  */
63381a2a9aSdr146992 #define	NET_HCK_NONE   	0x00
64381a2a9aSdr146992 #define	NET_HCK_L3_FULL	0x01
65381a2a9aSdr146992 #define	NET_HCK_L3_PART	0x02
66381a2a9aSdr146992 #define	NET_HCK_L4_FULL	0x10
67381a2a9aSdr146992 #define	NET_HCK_L4_PART	0x20
68381a2a9aSdr146992 
69381a2a9aSdr146992 #define	NET_IS_HCK_L3_FULL(n, x)                                             \
70381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L3_FULL) == NET_HCK_L3_FULL)
71381a2a9aSdr146992 #define	NET_IS_HCK_L3_PART(n, x)                                             \
72381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L3_PART) == NET_HCK_L3_PART)
73381a2a9aSdr146992 #define	NET_IS_HCK_L4_FULL(n, x)                                             \
74381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L4_FULL) == NET_HCK_L4_FULL)
75381a2a9aSdr146992 #define	NET_IS_HCK_L4_PART(n, x)                                             \
76381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L4_PART) == NET_HCK_L4_PART)
77381a2a9aSdr146992 #define	NET_IS_HCK_L34_FULL(n, x)                                            \
78381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & (NET_HCK_L3_FULL|NET_HCK_L4_FULL))   \
79381a2a9aSdr146992 	    == (NET_HCK_L3_FULL | NET_HCK_L4_FULL))
80381a2a9aSdr146992 
81381a2a9aSdr146992 typedef uintptr_t	phy_if_t;
82381a2a9aSdr146992 typedef intptr_t	lif_if_t;
83381a2a9aSdr146992 typedef uintptr_t	net_ifdata_t;
84381a2a9aSdr146992 
85381a2a9aSdr146992 struct net_data;
86381a2a9aSdr146992 typedef struct net_data *net_data_t;
87381a2a9aSdr146992 
88381a2a9aSdr146992 /*
89381a2a9aSdr146992  * Netinfo interface specification
90381a2a9aSdr146992  *
91381a2a9aSdr146992  * Netinfo provides an extensible and easy to use interface for
92381a2a9aSdr146992  * accessing data and functionality already embedded within network
93381a2a9aSdr146992  * code that exists within the kernel.
94381a2a9aSdr146992  */
95381a2a9aSdr146992 typedef enum net_ifaddr {
96381a2a9aSdr146992 	NA_ADDRESS = 1,
97381a2a9aSdr146992 	NA_PEER,
98381a2a9aSdr146992 	NA_BROADCAST,
99381a2a9aSdr146992 	NA_NETMASK
100381a2a9aSdr146992 } net_ifaddr_t;
101381a2a9aSdr146992 
102381a2a9aSdr146992 
103381a2a9aSdr146992 typedef enum inject {
104381a2a9aSdr146992 	NI_QUEUE_IN = 1,
105381a2a9aSdr146992 	NI_QUEUE_OUT,
106381a2a9aSdr146992 	NI_DIRECT_OUT
107381a2a9aSdr146992 } inject_t;
108381a2a9aSdr146992 
109381a2a9aSdr146992 typedef struct net_inject {
110381a2a9aSdr146992 	mblk_t			*ni_packet;
111381a2a9aSdr146992 	struct sockaddr_storage	ni_addr;
112381a2a9aSdr146992 	phy_if_t		ni_physical;
113381a2a9aSdr146992 } net_inject_t;
114381a2a9aSdr146992 
115381a2a9aSdr146992 
116381a2a9aSdr146992 /*
117381a2a9aSdr146992  * net_info_t public interface
118381a2a9aSdr146992  */
119381a2a9aSdr146992 typedef struct net_info {
120381a2a9aSdr146992 	int		neti_version;
121381a2a9aSdr146992 	char		*neti_protocol;
122*f4b3ec61Sdh155122 	int		(*neti_getifname)(phy_if_t, char *, const size_t,
123*f4b3ec61Sdh155122 			    netstack_t *);
124*f4b3ec61Sdh155122 	int		(*neti_getmtu)(phy_if_t, lif_if_t, netstack_t *);
125*f4b3ec61Sdh155122 	int		(*neti_getpmtuenabled)(netstack_t *);
126381a2a9aSdr146992 	int		(*neti_getlifaddr)(phy_if_t, lif_if_t, size_t,
127*f4b3ec61Sdh155122 			    net_ifaddr_t [], void *, netstack_t *);
128*f4b3ec61Sdh155122 	phy_if_t	(*neti_phygetnext)(phy_if_t, netstack_t *);
129*f4b3ec61Sdh155122 	phy_if_t	(*neti_phylookup)(const char *, netstack_t *);
130*f4b3ec61Sdh155122 	lif_if_t	(*neti_lifgetnext)(phy_if_t, lif_if_t, netstack_t *);
131*f4b3ec61Sdh155122 	int		(*neti_inject)(inject_t, net_inject_t *, netstack_t *);
132*f4b3ec61Sdh155122 	phy_if_t	(*neti_routeto)(struct sockaddr *, netstack_t *);
133381a2a9aSdr146992 	int		(*neti_ispartialchecksum)(mblk_t *);
134381a2a9aSdr146992 	int		(*neti_isvalidchecksum)(mblk_t *);
135381a2a9aSdr146992 } net_info_t;
136381a2a9aSdr146992 
137381a2a9aSdr146992 
138381a2a9aSdr146992 /*
139381a2a9aSdr146992  * Private data structures
140381a2a9aSdr146992  */
141381a2a9aSdr146992 struct net_data {
142381a2a9aSdr146992 	LIST_ENTRY(net_data)		netd_list;
143381a2a9aSdr146992 	net_info_t			netd_info;
144381a2a9aSdr146992 	int				netd_refcnt;
145381a2a9aSdr146992 	hook_family_int_t		*netd_hooks;
146*f4b3ec61Sdh155122 	netstack_t 			*netd_netstack;
147381a2a9aSdr146992 };
148381a2a9aSdr146992 
149381a2a9aSdr146992 
150381a2a9aSdr146992 typedef struct injection_s {
151381a2a9aSdr146992 	net_inject_t	inj_data;
152381a2a9aSdr146992 	boolean_t	inj_isv6;
153*f4b3ec61Sdh155122 	void *		inj_ptr;
154381a2a9aSdr146992 } injection_t;
155381a2a9aSdr146992 
156381a2a9aSdr146992 /*
157381a2a9aSdr146992  * The ipif_id space is [0,MAX) but this interface wants to return [1,MAX] as
158381a2a9aSdr146992  * a valid range of logical interface numbers so that it can return 0 to mean
159381a2a9aSdr146992  * "end of list" with net_lifgetnext.  Changing ipif_id's to use the [1,MAX]
160381a2a9aSdr146992  * space is something to be considered for the future, if it is worthwhile.
161381a2a9aSdr146992  */
162381a2a9aSdr146992 #define	MAP_IPIF_ID(x)		((x) + 1)
163381a2a9aSdr146992 #define	UNMAP_IPIF_ID(x)	(((x) > 0) ? (x) - 1 : (x))
164381a2a9aSdr146992 
165381a2a9aSdr146992 
166381a2a9aSdr146992 /*
167*f4b3ec61Sdh155122  * neti stack instances
168*f4b3ec61Sdh155122  */
169*f4b3ec61Sdh155122 struct neti_stack {
170*f4b3ec61Sdh155122 	krwlock_t nts_netlock;
171*f4b3ec61Sdh155122 
172*f4b3ec61Sdh155122 	/* list of net_data_t */
173*f4b3ec61Sdh155122 	LIST_HEAD(netd_listhead, net_data) nts_netd_head;
174*f4b3ec61Sdh155122 	netstack_t *nts_netstack;
175*f4b3ec61Sdh155122 };
176*f4b3ec61Sdh155122 typedef struct neti_stack neti_stack_t;
177*f4b3ec61Sdh155122 
178*f4b3ec61Sdh155122 
179*f4b3ec61Sdh155122 /*
180381a2a9aSdr146992  * Data management functions
181381a2a9aSdr146992  */
182*f4b3ec61Sdh155122 extern net_data_t net_register(const net_info_t *, netstackid_t);
183*f4b3ec61Sdh155122 extern net_data_t net_register_impl(const net_info_t *, netstack_t *);
184381a2a9aSdr146992 extern int net_unregister(net_data_t);
185*f4b3ec61Sdh155122 extern net_data_t net_lookup(const char *, netstackid_t);
186*f4b3ec61Sdh155122 extern net_data_t net_lookup_impl(const char *, netstack_t *);
187381a2a9aSdr146992 extern int net_release(net_data_t);
188*f4b3ec61Sdh155122 extern net_data_t net_walk(net_data_t, netstackid_t);
189*f4b3ec61Sdh155122 extern net_data_t net_walk_impl(net_data_t, netstack_t *);
190381a2a9aSdr146992 
191381a2a9aSdr146992 /*
192381a2a9aSdr146992  * Accessor functions
193381a2a9aSdr146992  */
194381a2a9aSdr146992 extern int net_register_family(net_data_t, hook_family_t *);
195381a2a9aSdr146992 extern int net_unregister_family(net_data_t, hook_family_t *);
196381a2a9aSdr146992 extern hook_event_token_t net_register_event(net_data_t, hook_event_t *);
197381a2a9aSdr146992 extern int net_unregister_event(net_data_t, hook_event_t *);
198381a2a9aSdr146992 extern int net_register_hook(net_data_t, char *, hook_t *);
199381a2a9aSdr146992 extern int net_unregister_hook(net_data_t, char *, hook_t *);
200381a2a9aSdr146992 extern int net_getifname(net_data_t, phy_if_t, char *, const size_t);
201381a2a9aSdr146992 extern int net_getmtu(net_data_t, phy_if_t, lif_if_t);
202381a2a9aSdr146992 extern int net_getpmtuenabled(net_data_t);
203381a2a9aSdr146992 extern int net_getlifaddr(net_data_t, phy_if_t, lif_if_t,
204381a2a9aSdr146992     int, net_ifaddr_t [], void *);
205381a2a9aSdr146992 extern phy_if_t net_phygetnext(net_data_t, phy_if_t);
206381a2a9aSdr146992 extern phy_if_t net_phylookup(net_data_t, const char *);
207381a2a9aSdr146992 extern lif_if_t net_lifgetnext(net_data_t, phy_if_t, lif_if_t);
208381a2a9aSdr146992 extern int net_inject(net_data_t, inject_t, net_inject_t *);
209381a2a9aSdr146992 extern phy_if_t net_routeto(net_data_t, struct sockaddr *);
210381a2a9aSdr146992 extern int net_ispartialchecksum(net_data_t, mblk_t *);
211381a2a9aSdr146992 extern int net_isvalidchecksum(net_data_t, mblk_t *);
212381a2a9aSdr146992 
213381a2a9aSdr146992 #ifdef	__cplusplus
214381a2a9aSdr146992 }
215381a2a9aSdr146992 #endif
216381a2a9aSdr146992 
217381a2a9aSdr146992 #endif /* _SYS_NETI_H */
218