xref: /titanic_52/usr/src/uts/common/inet/sctp/sctp_addr.h (revision b9bd317cda1afb3a01f4812de73e8cec888cbbd7)
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	_SCTP_ADDR_H
27 #define	_SCTP_ADDR_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/list.h>
32 #include <sys/zone.h>
33 #include <inet/ip.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * SCTP IPIF structure - only relevant fields from ipif_t retained
41  *
42  * There is a global array, sctp_g_ipifs, to store all addresses of
43  * the system.  Each element of the global array is a list of
44  * sctp_ipif_t.
45  *
46  * This structure is also shared by all SCTP PCBs.  Each SCTP PCB has
47  * an array of source addresses.  Each element of that array is a list
48  * of sctp_saddr_ipif_t.  And each sctp_saddr_ipif_t has a pointer
49  * to a sctp_ipif_t.  The reason for sctp_saddr_ipif_t is that each
50  * SCTP PCB may do different things to a source address.  This info
51  * is stored locally in sctp_saddr_ipif_t.
52  *
53  */
54 typedef struct sctp_ipif_s {
55 	list_node_t		sctp_ipifs;	/* Used by the global list */
56 	struct sctp_ill_s	*sctp_ipif_ill;
57 	uint_t			sctp_ipif_mtu;
58 	uint_t			sctp_ipif_id;
59 	in6_addr_t		sctp_ipif_saddr;
60 	int			sctp_ipif_state;
61 	uint32_t		sctp_ipif_refcnt;
62 	zoneid_t		sctp_ipif_zoneid;
63 	krwlock_t		sctp_ipif_lock;
64 	boolean_t		sctp_ipif_isv6;
65 	uint64_t		sctp_ipif_flags;
66 } sctp_ipif_t;
67 
68 /* ipif_state */
69 #define	SCTP_IPIFS_CONDEMNED	-1
70 #define	SCTP_IPIFS_INVALID	-2
71 #define	SCTP_IPIFS_DOWN		1
72 #define	SCTP_IPIFS_UP		2
73 
74 /*
75  * Individual SCTP source address structure.
76  * saddr_ipifp is the actual pointer to the ipif/address.
77  * saddr_ipif_dontsrc is used to mark an address as currently unusable. This
78  * would be the case when we have added/deleted an address using sctp_bindx()
79  * and are waiting for the ASCONF ACK from the peer to confirm the addition/
80  * deletion. Additionally, saddr_ipif_delete_pending is used to specifically
81  * indicate that an address delete operation is in progress.
82  */
83 typedef struct sctp_saddrs_ipif_s {
84 	list_node_t	saddr_ipif;
85 	sctp_ipif_t 	*saddr_ipifp;
86 	uint32_t	saddr_ipif_dontsrc : 1,
87 			saddr_ipif_delete_pending : 1,
88 			saddr_ipif_unconfirmed : 1,
89 			pad : 29;
90 } sctp_saddr_ipif_t;
91 
92 #define	SCTP_DONT_SRC(sctp_saddr)	\
93 	((sctp_saddr)->saddr_ipif_dontsrc ||	\
94 	(sctp_saddr)->saddr_ipif_unconfirmed)
95 
96 
97 /*
98  * SCTP ILL structure - only relevant fields from ill_t retained.
99  * This pretty much reflects the ILL<->IPIF relation that IP maintains.
100  * At present the only state an ILL can be in is CONDEMNED or not.
101  * sctp_ill_ipifcnt gives the number of IPIFs for this ILL,
102  * sctp_ill_index is phyint_ifindex in the actual ILL structure (in IP)
103  * and sctp_ill_flags is ill_flags from the ILL structure.
104  *
105  * The comment below (and for other netstack_t references) refers
106  * to the fact that we only do netstack_hold in particular cases,
107  * such as the references from open streams (ill_t and conn_t's
108  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
109  * ire_t's when an ill goes away.
110  */
111 typedef struct sctp_ill_s {
112 	list_node_t	sctp_ills;
113 	int		sctp_ill_name_length;
114 	char		*sctp_ill_name;
115 	int		sctp_ill_state;
116 	uint32_t	sctp_ill_ipifcnt;
117 	uint_t		sctp_ill_index;
118 	uint64_t	sctp_ill_flags;
119 	boolean_t	sctp_ill_isv6;
120 	netstack_t	*sctp_ill_netstack; /* Does not have a netstack_hold */
121 } sctp_ill_t;
122 
123 /* ill_state */
124 #define	SCTP_ILLS_CONDEMNED	-1
125 
126 #define	SCTP_ILL_HASH	16
127 
128 typedef struct sctp_ill_hash_s {
129 	list_t	sctp_ill_list;
130 	int	ill_count;
131 } sctp_ill_hash_t;
132 
133 
134 #define	SCTP_IPIF_REFHOLD(sctp_ipif) {				\
135 	atomic_add_32(&(sctp_ipif)->sctp_ipif_refcnt, 1);	\
136 }
137 
138 #define	SCTP_IPIF_REFRELE(sctp_ipif) {					\
139 	rw_enter(&(sctp_ipif)->sctp_ipif_lock, RW_WRITER);		\
140 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);			\
141 	if (--(sctp_ipif)->sctp_ipif_refcnt == 0 && 			\
142 	    (sctp_ipif)->sctp_ipif_state == SCTP_IPIFS_CONDEMNED) {	\
143 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
144 		sctp_ipif_inactive(sctp_ipif);				\
145 	} else {							\
146 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
147 	}								\
148 }
149 
150 /* Address set comparison results. */
151 #define	SCTP_ADDR_EQUAL		1
152 #define	SCTP_ADDR_SUBSET	2
153 #define	SCTP_ADDR_OVERLAP	3
154 #define	SCTP_ADDR_DISJOINT	4
155 
156 extern int		sctp_valid_addr_list(sctp_t *, const void *, uint32_t,
157 			    uchar_t *, size_t);
158 extern int		sctp_dup_saddrs(sctp_t *, sctp_t *, int);
159 extern int		sctp_compare_saddrs(sctp_t *, sctp_t *);
160 extern sctp_saddr_ipif_t	*sctp_saddr_lookup(sctp_t *, in6_addr_t *,
161 				    uint_t);
162 extern in6_addr_t	sctp_get_valid_addr(sctp_t *, boolean_t, boolean_t *);
163 extern size_t		sctp_saddr_info(sctp_t *, int, uchar_t *, boolean_t);
164 extern void		sctp_del_saddr_list(sctp_t *, const void *, int,
165 			    boolean_t);
166 extern void		sctp_del_saddr(sctp_t *, sctp_saddr_ipif_t *);
167 extern void		sctp_free_saddrs(sctp_t *);
168 extern void		sctp_saddr_init(sctp_stack_t *);
169 extern void		sctp_saddr_fini(sctp_stack_t *);
170 extern int		sctp_getmyaddrs(void *, void *, int *);
171 extern int		sctp_saddr_add_addr(sctp_t *, in6_addr_t *, uint_t);
172 extern void		sctp_check_saddr(sctp_t *, int, boolean_t,
173 			    in6_addr_t *);
174 
175 #ifdef	__cplusplus
176 }
177 #endif
178 
179 #endif	/* _SCTP_ADDR_H */
180