xref: /titanic_51/usr/src/uts/common/inet/rawip_impl.h (revision 5d460eafffba936e81c4dd5ebe0f59b238f09121)
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 /* Copyright (c) 1990 Mentat Inc. */
26 
27 #ifndef	_RAWIP_IMPL_H
28 #define	_RAWIP_IMPL_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #ifdef _KERNEL
35 
36 #include <sys/types.h>
37 #include <sys/netstack.h>
38 
39 #include <netinet/in.h>
40 #include <netinet/icmp6.h>
41 #include <netinet/ip6.h>
42 
43 #include <inet/common.h>
44 #include <inet/ip.h>
45 #include <inet/optcom.h>
46 
47 /* Named Dispatch Parameter Management Structure */
48 typedef struct icmpparam_s {
49 	uint_t	icmp_param_min;
50 	uint_t	icmp_param_max;
51 	uint_t	icmp_param_value;
52 	char	*icmp_param_name;
53 } icmpparam_t;
54 
55 /*
56  * ICMP stack instances
57  */
58 struct icmp_stack {
59 	netstack_t	*is_netstack;	/* Common netstack */
60 	void		*is_head;	/* Head for list of open icmps */
61 	IDP		is_nd;	/* Points to table of ICMP ND variables. */
62 	icmpparam_t	*is_param_arr; 	/* ndd variable table */
63 	kstat_t		*is_ksp;	/* kstats */
64 	mib2_rawip_t	is_rawip_mib;	/* SNMP fixed size info */
65 	ldi_ident_t	is_ldi_ident;
66 };
67 
68 typedef struct icmp_stack icmp_stack_t;
69 
70 /* Internal icmp control structure, one per open stream */
71 typedef	struct icmp_s {
72 	krwlock_t	icmp_rwlock;	/* Protects most of icmp_t */
73 	t_scalar_t	icmp_pending_op;	/* The current TPI operation */
74 	/*
75 	 * Following fields up to icmp_ipversion protected by conn_lock.
76 	 */
77 	uint_t		icmp_state;	/* TPI state */
78 	in6_addr_t	icmp_v6src;	/* Source address of this stream */
79 	in6_addr_t	icmp_bound_v6src; /* Explicitely bound to address */
80 	sin6_t		icmp_v6dst;	/* Connected destination */
81 	/*
82 	 * IP format that packets transmitted from this struct should use.
83 	 * Value can be IP4_VERSION or IPV6_VERSION.
84 	 */
85 	uchar_t		icmp_ipversion;
86 
87 	/* Written to only once at the time of opening the endpoint */
88 	sa_family_t	icmp_family;	/* Family from socket() call */
89 
90 	/* Following protected by icmp_rwlock */
91 	uint32_t 	icmp_max_hdr_len; /* For write offset in stream head */
92 	uint_t		icmp_proto;
93 	uint_t		icmp_ip_snd_options_len; /* Len of IPv4 options */
94 	uint8_t		*icmp_ip_snd_options;	/* Ptr to IPv4 options */
95 	uint8_t		icmp_multicast_ttl;	/* IP*_MULTICAST_TTL/HOPS */
96 	ipaddr_t	icmp_multicast_if_addr; /* IP_MULTICAST_IF option */
97 	uint_t		icmp_multicast_if_index; /* IPV6_MULTICAST_IF option */
98 	int		icmp_bound_if;		/* IP*_BOUND_IF option */
99 
100 	/* Written to only once at the time of opening the endpoint */
101 	conn_t		*icmp_connp;
102 
103 	/* Following protected by icmp_rwlock */
104 	uint_t
105 	    icmp_debug : 1,		/* SO_DEBUG "socket" option. */
106 	    icmp_dontroute : 1,		/* SO_DONTROUTE "socket" option. */
107 	    icmp_broadcast : 1,		/* SO_BROADCAST "socket" option. */
108 	    icmp_reuseaddr : 1,		/* SO_REUSEADDR "socket" option. */
109 
110 	    icmp_useloopback : 1,	/* SO_USELOOPBACK "socket" option. */
111 	    icmp_hdrincl : 1,		/* IP_HDRINCL option + RAW and IGMP */
112 	    icmp_dgram_errind : 1,	/* SO_DGRAM_ERRIND option */
113 	    icmp_unspec_source : 1,	/* IP*_UNSPEC_SRC option */
114 
115 	    icmp_raw_checksum : 1,	/* raw checksum per IPV6_CHECKSUM */
116 	    icmp_no_tp_cksum : 1,	/* icmp_proto is UDP or TCP */
117 	    icmp_ip_recvpktinfo : 1,	/* IPV[4,6]_RECVPKTINFO option  */
118 	    icmp_ipv6_recvhoplimit : 1,	/* IPV6_RECVHOPLIMIT option */
119 
120 	    icmp_ipv6_recvhopopts : 1,	/* IPV6_RECVHOPOPTS option */
121 	    icmp_ipv6_recvdstopts : 1,	/* IPV6_RECVDSTOPTS option */
122 	    icmp_ipv6_recvrthdr : 1,	/* IPV6_RECVRTHDR option */
123 	    icmp_ipv6_recvpathmtu : 1,	/* IPV6_RECVPATHMTU option */
124 
125 	    icmp_recvif:1,		/* IP_RECVIF for raw sockets option */
126 	    icmp_ipv6_recvtclass : 1,	/* IPV6_RECVTCLASS option */
127 	    icmp_ipv6_recvrtdstopts : 1, /* Obsolete IPV6_RECVRTHDRDSTOPTS */
128 	    icmp_old_ipv6_recvdstopts : 1, /* Old ver of IPV6_RECVDSTOPTS */
129 
130 	    icmp_timestamp : 1,  	/* SO_TIMESTAMP "socket" option */
131 
132 	    icmp_pad_to_bit_31: 11;
133 
134 	uint8_t		icmp_type_of_service;
135 	uint8_t		icmp_ttl;		/* TTL or hoplimit */
136 	uint32_t	icmp_checksum_off; /* user supplied checksum offset */
137 	icmp6_filter_t	*icmp_filter;		/* ICMP6_FILTER option */
138 
139 	ip6_pkt_t	icmp_sticky_ipp;	/* Sticky options */
140 	uint8_t		*icmp_sticky_hdrs;	/* Prebuilt IPv6 hdrs */
141 	uint_t		icmp_sticky_hdrs_len;	/* Incl. ip6h and any ip6i */
142 	zoneid_t	icmp_zoneid;		/* ID of owning zone */
143 	uint_t		icmp_label_len;		/* length of security label */
144 	uint_t		icmp_label_len_v6;	/* sec. part of sticky opt */
145 	in6_addr_t 	icmp_v6lastdst;		/* most recent destination */
146 	icmp_stack_t	*icmp_is;		/* Stack instance */
147 	size_t		icmp_xmit_hiwat;
148 	size_t		icmp_xmit_lowat;
149 	size_t		icmp_recv_hiwat;
150 	size_t		icmp_recv_lowat;
151 	int		icmp_delayed_error;
152 	kmutex_t	icmp_recv_lock;
153 	mblk_t		*icmp_fallback_queue_head;
154 	mblk_t		*icmp_fallback_queue_tail;
155 	struct sockaddr_storage	icmp_delayed_addr;
156 } icmp_t;
157 
158 /*
159  * Object to represent database of options to search passed to
160  * {sock,tpi}optcom_req() interface routine to take care of option
161  * management and associated methods.
162  */
163 extern optdb_obj_t	icmp_opt_obj;
164 extern uint_t		icmp_max_optsize;
165 
166 extern mblk_t	*icmp_snmp_get(queue_t *q, mblk_t *mpctl);
167 
168 extern void	icmp_ddi_g_init(void);
169 extern void	icmp_ddi_g_destroy(void);
170 
171 extern sock_lower_handle_t rawip_create(int, int, int, sock_downcalls_t **,
172     uint_t *, int *, int, cred_t *);
173 extern int rawip_fallback(sock_lower_handle_t, queue_t *, boolean_t,
174     so_proto_quiesced_cb_t);
175 
176 extern sock_downcalls_t sock_rawip_downcalls;
177 
178 #endif	/* _KERNEL */
179 
180 #ifdef	__cplusplus
181 }
182 #endif
183 
184 #endif	/* _RAWIP_IMPL_H */
185