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