xref: /titanic_51/usr/src/uts/common/sys/neti.h (revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4)
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*0a0e9771SDarren Reed  * Copyright 2009 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 #include <netinet/in.h>
30381a2a9aSdr146992 #include <sys/int_types.h>
31381a2a9aSdr146992 #include <sys/queue.h>
32381a2a9aSdr146992 #include <sys/hook_impl.h>
33f4b3ec61Sdh155122 #include <sys/netstack.h>
34381a2a9aSdr146992 
35381a2a9aSdr146992 #ifdef	__cplusplus
36381a2a9aSdr146992 extern "C" {
37381a2a9aSdr146992 #endif
38381a2a9aSdr146992 
39381a2a9aSdr146992 #define	NETINFO_VERSION 1
40381a2a9aSdr146992 
41381a2a9aSdr146992 /*
42381a2a9aSdr146992  * Network hooks framework stack protocol name
43381a2a9aSdr146992  */
44381a2a9aSdr146992 #define	NHF_INET	"NHF_INET"
45381a2a9aSdr146992 #define	NHF_INET6	"NHF_INET6"
46381a2a9aSdr146992 #define	NHF_ARP		"NHF_ARP"
47381a2a9aSdr146992 
48381a2a9aSdr146992 /*
49381a2a9aSdr146992  * Event identification
50381a2a9aSdr146992  */
51381a2a9aSdr146992 #define	NH_PHYSICAL_IN	"PHYSICAL_IN"
52381a2a9aSdr146992 #define	NH_PHYSICAL_OUT	"PHYSICAL_OUT"
53381a2a9aSdr146992 #define	NH_FORWARDING	"FORWARDING"
54381a2a9aSdr146992 #define	NH_LOOPBACK_IN	"LOOPBACK_IN"
55381a2a9aSdr146992 #define	NH_LOOPBACK_OUT	"LOOPBACK_OUT"
56381a2a9aSdr146992 #define	NH_NIC_EVENTS	"NIC_EVENTS"
57*0a0e9771SDarren Reed #define	NH_OBSERVE	"OBSERVING"
58381a2a9aSdr146992 
59381a2a9aSdr146992 /*
60381a2a9aSdr146992  * Network NIC hardware checksum capability
61381a2a9aSdr146992  */
62381a2a9aSdr146992 #define	NET_HCK_NONE   	0x00
63381a2a9aSdr146992 #define	NET_HCK_L3_FULL	0x01
64381a2a9aSdr146992 #define	NET_HCK_L3_PART	0x02
65381a2a9aSdr146992 #define	NET_HCK_L4_FULL	0x10
66381a2a9aSdr146992 #define	NET_HCK_L4_PART	0x20
67381a2a9aSdr146992 
68381a2a9aSdr146992 #define	NET_IS_HCK_L3_FULL(n, x)                                             \
69381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L3_FULL) == NET_HCK_L3_FULL)
70381a2a9aSdr146992 #define	NET_IS_HCK_L3_PART(n, x)                                             \
71381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L3_PART) == NET_HCK_L3_PART)
72381a2a9aSdr146992 #define	NET_IS_HCK_L4_FULL(n, x)                                             \
73381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L4_FULL) == NET_HCK_L4_FULL)
74381a2a9aSdr146992 #define	NET_IS_HCK_L4_PART(n, x)                                             \
75381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & NET_HCK_L4_PART) == NET_HCK_L4_PART)
76381a2a9aSdr146992 #define	NET_IS_HCK_L34_FULL(n, x)                                            \
77381a2a9aSdr146992 	((net_ispartialchecksum(n, x) & (NET_HCK_L3_FULL|NET_HCK_L4_FULL))   \
78381a2a9aSdr146992 	    == (NET_HCK_L3_FULL | NET_HCK_L4_FULL))
79381a2a9aSdr146992 
80381a2a9aSdr146992 typedef uintptr_t	phy_if_t;
81381a2a9aSdr146992 typedef intptr_t	lif_if_t;
82381a2a9aSdr146992 typedef uintptr_t	net_ifdata_t;
837ddc9b1aSDarren Reed typedef id_t		netid_t;
84381a2a9aSdr146992 
85381a2a9aSdr146992 /*
86381a2a9aSdr146992  * Netinfo interface specification
87381a2a9aSdr146992  *
88381a2a9aSdr146992  * Netinfo provides an extensible and easy to use interface for
89381a2a9aSdr146992  * accessing data and functionality already embedded within network
90381a2a9aSdr146992  * code that exists within the kernel.
91381a2a9aSdr146992  */
92381a2a9aSdr146992 typedef enum net_ifaddr {
93381a2a9aSdr146992 	NA_ADDRESS = 1,
94381a2a9aSdr146992 	NA_PEER,
95381a2a9aSdr146992 	NA_BROADCAST,
96381a2a9aSdr146992 	NA_NETMASK
97381a2a9aSdr146992 } net_ifaddr_t;
98381a2a9aSdr146992 
99381a2a9aSdr146992 
100381a2a9aSdr146992 typedef enum inject {
101381a2a9aSdr146992 	NI_QUEUE_IN = 1,
102381a2a9aSdr146992 	NI_QUEUE_OUT,
103381a2a9aSdr146992 	NI_DIRECT_OUT
104381a2a9aSdr146992 } inject_t;
105381a2a9aSdr146992 
1067ddc9b1aSDarren Reed /*
1077ddc9b1aSDarren Reed  * net_inject - public interface
1087ddc9b1aSDarren Reed  */
109381a2a9aSdr146992 typedef struct net_inject {
1107ddc9b1aSDarren Reed 	int			ni_version;
1117ddc9b1aSDarren Reed 	netid_t			ni_netid;
112381a2a9aSdr146992 	mblk_t			*ni_packet;
113381a2a9aSdr146992 	struct sockaddr_storage	ni_addr;
114381a2a9aSdr146992 	phy_if_t		ni_physical;
115381a2a9aSdr146992 } net_inject_t;
116381a2a9aSdr146992 
1177ddc9b1aSDarren Reed typedef struct net_data *net_handle_t;
118381a2a9aSdr146992 
119381a2a9aSdr146992 /*
1207ddc9b1aSDarren Reed  * net_protocol_t private interface
121381a2a9aSdr146992  */
1227ddc9b1aSDarren Reed struct net_protocol_s {
1237ddc9b1aSDarren Reed 	int		netp_version;
1247ddc9b1aSDarren Reed 	char		*netp_name;
1257ddc9b1aSDarren Reed 	int		(*netp_getifname)(net_handle_t, phy_if_t, char *,
1267ddc9b1aSDarren Reed 			    const size_t);
1277ddc9b1aSDarren Reed 	int		(*netp_getmtu)(net_handle_t, phy_if_t, lif_if_t);
1287ddc9b1aSDarren Reed 	int		(*netp_getpmtuenabled)(net_handle_t);
1297ddc9b1aSDarren Reed 	int		(*netp_getlifaddr)(net_handle_t, phy_if_t, lif_if_t,
1307ddc9b1aSDarren Reed 			    size_t, net_ifaddr_t [], void *);
131b127ac41SPhilip Kirk 	int		(*neti_getlifzone)(net_handle_t, phy_if_t, lif_if_t,
132b127ac41SPhilip Kirk 			    zoneid_t *);
133b127ac41SPhilip Kirk 	int		(*neti_getlifflags)(net_handle_t, phy_if_t, lif_if_t,
134b127ac41SPhilip Kirk 			    uint64_t *);
1357ddc9b1aSDarren Reed 	phy_if_t	(*netp_phygetnext)(net_handle_t, phy_if_t);
1367ddc9b1aSDarren Reed 	phy_if_t	(*netp_phylookup)(net_handle_t, const char *);
1377ddc9b1aSDarren Reed 	lif_if_t	(*netp_lifgetnext)(net_handle_t, phy_if_t, lif_if_t);
1387ddc9b1aSDarren Reed 	int		(*netp_inject)(net_handle_t, inject_t, net_inject_t *);
1397ddc9b1aSDarren Reed 	phy_if_t	(*netp_routeto)(net_handle_t, struct sockaddr *,
1407ddc9b1aSDarren Reed 			    struct sockaddr *);
1417ddc9b1aSDarren Reed 	int		(*netp_ispartialchecksum)(net_handle_t, mblk_t *);
1427ddc9b1aSDarren Reed 	int		(*netp_isvalidchecksum)(net_handle_t, mblk_t *);
1437ddc9b1aSDarren Reed };
1447ddc9b1aSDarren Reed typedef struct net_protocol_s net_protocol_t;
145381a2a9aSdr146992 
146381a2a9aSdr146992 
147381a2a9aSdr146992 /*
148381a2a9aSdr146992  * Private data structures
149381a2a9aSdr146992  */
150381a2a9aSdr146992 struct net_data {
151381a2a9aSdr146992 	LIST_ENTRY(net_data)		netd_list;
1527ddc9b1aSDarren Reed 	net_protocol_t			netd_info;
153381a2a9aSdr146992 	int				netd_refcnt;
154381a2a9aSdr146992 	hook_family_int_t		*netd_hooks;
1557ddc9b1aSDarren Reed 	struct neti_stack_s		*netd_stack;
1567ddc9b1aSDarren Reed 	int				netd_condemned;
157381a2a9aSdr146992 };
158381a2a9aSdr146992 
159381a2a9aSdr146992 
160381a2a9aSdr146992 typedef struct injection_s {
161381a2a9aSdr146992 	net_inject_t	inj_data;
162381a2a9aSdr146992 	boolean_t	inj_isv6;
163f4b3ec61Sdh155122 	void *		inj_ptr;
164381a2a9aSdr146992 } injection_t;
165381a2a9aSdr146992 
166381a2a9aSdr146992 /*
167381a2a9aSdr146992  * The ipif_id space is [0,MAX) but this interface wants to return [1,MAX] as
168381a2a9aSdr146992  * a valid range of logical interface numbers so that it can return 0 to mean
169381a2a9aSdr146992  * "end of list" with net_lifgetnext.  Changing ipif_id's to use the [1,MAX]
170381a2a9aSdr146992  * space is something to be considered for the future, if it is worthwhile.
171381a2a9aSdr146992  */
172381a2a9aSdr146992 #define	MAP_IPIF_ID(x)		((x) + 1)
173381a2a9aSdr146992 #define	UNMAP_IPIF_ID(x)	(((x) > 0) ? (x) - 1 : (x))
174381a2a9aSdr146992 
1757ddc9b1aSDarren Reed struct net_instance_s {
1767ddc9b1aSDarren Reed 	int				nin_version;
1777ddc9b1aSDarren Reed 	char				*nin_name;
1787ddc9b1aSDarren Reed 	void				*(*nin_create)(const netid_t);
1797ddc9b1aSDarren Reed 	void				(*nin_destroy)(const netid_t, void *);
1807ddc9b1aSDarren Reed 	void				(*nin_shutdown)(const netid_t, void *);
181f4b3ec61Sdh155122 };
1827ddc9b1aSDarren Reed typedef struct net_instance_s net_instance_t;
183f4b3ec61Sdh155122 
1847ddc9b1aSDarren Reed struct net_instance_int_s {
1857ddc9b1aSDarren Reed 	LIST_ENTRY(net_instance_int_s)	nini_next;
1868ad74188SDarren Reed 	uint_t				nini_ref;
1877ddc9b1aSDarren Reed 	void				*nini_created;
1887ddc9b1aSDarren Reed 	struct net_instance_int_s	*nini_parent;
1897ddc9b1aSDarren Reed 	net_instance_t			*nini_instance;
1907ddc9b1aSDarren Reed 	hook_notify_t			nini_notify;
1917ddc9b1aSDarren Reed 	uint32_t			nini_flags;
1927ddc9b1aSDarren Reed 	kcondvar_t			nini_cv;
1938ad74188SDarren Reed 	boolean_t			nini_condemned;
1947ddc9b1aSDarren Reed };
1957ddc9b1aSDarren Reed typedef struct net_instance_int_s net_instance_int_t;
1967ddc9b1aSDarren Reed LIST_HEAD(nini_head_s, net_instance_int_s);
1977ddc9b1aSDarren Reed typedef struct nini_head_s nini_head_t;
1987ddc9b1aSDarren Reed 
1997ddc9b1aSDarren Reed #define	nini_version	nini_instance->nin_version
2007ddc9b1aSDarren Reed #define	nini_name	nini_instance->nin_name
2017ddc9b1aSDarren Reed #define	nini_create	nini_instance->nin_create
2027ddc9b1aSDarren Reed #define	nini_destroy	nini_instance->nin_destroy
2037ddc9b1aSDarren Reed #define	nini_shutdown	nini_instance->nin_shutdown
204f4b3ec61Sdh155122 
205f4b3ec61Sdh155122 /*
2067ddc9b1aSDarren Reed  * netinfo stack instances
207381a2a9aSdr146992  */
2087ddc9b1aSDarren Reed struct neti_stack_s {
2097ddc9b1aSDarren Reed 	kmutex_t			nts_lock;
2107ddc9b1aSDarren Reed 	LIST_ENTRY(neti_stack_s)	nts_next;
2117ddc9b1aSDarren Reed 	netid_t				nts_id;
2127ddc9b1aSDarren Reed 	zoneid_t			nts_zoneid;
2137ddc9b1aSDarren Reed 	netstackid_t			nts_stackid;
2147ddc9b1aSDarren Reed 	netstack_t			*nts_netstack;
2157ddc9b1aSDarren Reed 	nini_head_t			nts_instances;
2167ddc9b1aSDarren Reed 	uint32_t			nts_flags;
2177ddc9b1aSDarren Reed 	kcondvar_t			nts_cv;
2187ddc9b1aSDarren Reed 	/* list of net_handle_t */
2197ddc9b1aSDarren Reed 	LIST_HEAD(netd_listhead, net_data) nts_netd_head;
2207ddc9b1aSDarren Reed };
2217ddc9b1aSDarren Reed typedef struct neti_stack_s neti_stack_t;
2227ddc9b1aSDarren Reed LIST_HEAD(neti_stack_head_s, neti_stack_s);
2237ddc9b1aSDarren Reed typedef struct neti_stack_head_s neti_stack_head_t;
224381a2a9aSdr146992 
225381a2a9aSdr146992 /*
2267ddc9b1aSDarren Reed  * Internal functions that need to be exported within the module.
227381a2a9aSdr146992  */
2287ddc9b1aSDarren Reed extern void neti_init(void);
2297ddc9b1aSDarren Reed extern void neti_fini(void);
2307ddc9b1aSDarren Reed extern neti_stack_t *net_getnetistackbyid(netid_t);
2317ddc9b1aSDarren Reed extern netstackid_t net_getnetstackidbynetid(netid_t);
2327ddc9b1aSDarren Reed extern netid_t net_getnetidbynetstackid(netstackid_t);
2337ddc9b1aSDarren Reed extern netid_t net_zoneidtonetid(zoneid_t);
2347ddc9b1aSDarren Reed extern zoneid_t net_getzoneidbynetid(netid_t);
2357ddc9b1aSDarren Reed 
2367ddc9b1aSDarren Reed /*
2377ddc9b1aSDarren Reed  * Functions available for public use.
2387ddc9b1aSDarren Reed  */
2397ddc9b1aSDarren Reed extern hook_event_token_t net_event_register(net_handle_t, hook_event_t *);
2408ad74188SDarren Reed extern int net_event_shutdown(net_handle_t, hook_event_t *);
2417ddc9b1aSDarren Reed extern int net_event_unregister(net_handle_t, hook_event_t *);
2427ddc9b1aSDarren Reed extern int net_event_notify_register(net_handle_t, char *,
2437ddc9b1aSDarren Reed     hook_notify_fn_t, void *);
2447ddc9b1aSDarren Reed extern int net_event_notify_unregister(net_handle_t, char *, hook_notify_fn_t);
2457ddc9b1aSDarren Reed 
2467ddc9b1aSDarren Reed extern int net_family_register(net_handle_t, hook_family_t *);
2478ad74188SDarren Reed extern int net_family_shutdown(net_handle_t, hook_family_t *);
2487ddc9b1aSDarren Reed extern int net_family_unregister(net_handle_t, hook_family_t *);
2497ddc9b1aSDarren Reed 
2507ddc9b1aSDarren Reed extern int net_hook_register(net_handle_t, char *, hook_t *);
2517ddc9b1aSDarren Reed extern int net_hook_unregister(net_handle_t, char *, hook_t *);
2527ddc9b1aSDarren Reed 
2537ddc9b1aSDarren Reed extern int net_inject(net_handle_t, inject_t, net_inject_t *);
2547ddc9b1aSDarren Reed extern net_inject_t *net_inject_alloc(const int);
2557ddc9b1aSDarren Reed extern void net_inject_free(net_inject_t *);
2567ddc9b1aSDarren Reed 
2577ddc9b1aSDarren Reed extern net_instance_t *net_instance_alloc(const int version);
2587ddc9b1aSDarren Reed extern void net_instance_free(net_instance_t *);
2597ddc9b1aSDarren Reed extern int net_instance_register(net_instance_t *);
2607ddc9b1aSDarren Reed extern int net_instance_unregister(net_instance_t *);
2617ddc9b1aSDarren Reed extern int net_instance_notify_register(netid_t, hook_notify_fn_t, void *);
2627ddc9b1aSDarren Reed extern int net_instance_notify_unregister(netid_t netid, hook_notify_fn_t);
2637ddc9b1aSDarren Reed 
2647ddc9b1aSDarren Reed extern kstat_t *net_kstat_create(netid_t, char *, int, char *, char *,
2657ddc9b1aSDarren Reed     uchar_t, ulong_t, uchar_t);
2667ddc9b1aSDarren Reed extern void net_kstat_delete(netid_t, kstat_t *);
2677ddc9b1aSDarren Reed 
2687ddc9b1aSDarren Reed extern net_handle_t net_protocol_lookup(netid_t, const char *);
2697ddc9b1aSDarren Reed extern net_handle_t net_protocol_register(netid_t, const net_protocol_t *);
2707ddc9b1aSDarren Reed extern int net_protocol_release(net_handle_t);
2717ddc9b1aSDarren Reed extern int net_protocol_unregister(net_handle_t);
2727ddc9b1aSDarren Reed extern net_handle_t net_protocol_walk(netid_t, net_handle_t);
2737ddc9b1aSDarren Reed extern int net_protocol_notify_register(net_handle_t, hook_notify_fn_t, void *);
2747ddc9b1aSDarren Reed extern int net_protocol_notify_unregister(net_handle_t, hook_notify_fn_t);
2757ddc9b1aSDarren Reed 
2767ddc9b1aSDarren Reed 
2777ddc9b1aSDarren Reed extern int net_getifname(net_handle_t, phy_if_t, char *, const size_t);
2787ddc9b1aSDarren Reed extern int net_getmtu(net_handle_t, phy_if_t, lif_if_t);
2797ddc9b1aSDarren Reed extern int net_getpmtuenabled(net_handle_t);
2807ddc9b1aSDarren Reed extern int net_getlifaddr(net_handle_t, phy_if_t, lif_if_t,
281381a2a9aSdr146992     int, net_ifaddr_t [], void *);
282b127ac41SPhilip Kirk extern zoneid_t net_getlifzone(net_handle_t, phy_if_t, lif_if_t, zoneid_t *);
283b127ac41SPhilip Kirk extern int net_getlifflags(net_handle_t, phy_if_t, lif_if_t, uint64_t *);
2847ddc9b1aSDarren Reed extern phy_if_t net_phygetnext(net_handle_t, phy_if_t);
2857ddc9b1aSDarren Reed extern phy_if_t net_phylookup(net_handle_t, const char *);
2867ddc9b1aSDarren Reed extern lif_if_t net_lifgetnext(net_handle_t, phy_if_t, lif_if_t);
2877ddc9b1aSDarren Reed extern phy_if_t net_routeto(net_handle_t, struct sockaddr *,
2887ddc9b1aSDarren Reed     struct sockaddr *);
2897ddc9b1aSDarren Reed extern int net_ispartialchecksum(net_handle_t, mblk_t *);
2907ddc9b1aSDarren Reed extern int net_isvalidchecksum(net_handle_t, mblk_t *);
291381a2a9aSdr146992 
292381a2a9aSdr146992 #ifdef	__cplusplus
293381a2a9aSdr146992 }
294381a2a9aSdr146992 #endif
295381a2a9aSdr146992 
296381a2a9aSdr146992 #endif /* _SYS_NETI_H */
297