xref: /titanic_44/usr/src/uts/common/inet/sctp/sctp_addr.h (revision 60972f37b111e11c7b4abcfc08e54c7839fe5e63)
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 	netstack_t	*sctp_ill_netstack; /* Does not have a netstack_hold */
120 } sctp_ill_t;
121 
122 /* ill_state */
123 #define	SCTP_ILLS_CONDEMNED	-1
124 
125 #define	SCTP_ILL_HASH	16
126 
127 typedef struct sctp_ill_hash_s {
128 	list_t	sctp_ill_list;
129 	int	ill_count;
130 } sctp_ill_hash_t;
131 
132 
133 #define	SCTP_IPIF_REFHOLD(sctp_ipif) {				\
134 	atomic_add_32(&(sctp_ipif)->sctp_ipif_refcnt, 1);	\
135 }
136 
137 #define	SCTP_IPIF_REFRELE(sctp_ipif) {					\
138 	rw_enter(&(sctp_ipif)->sctp_ipif_lock, RW_WRITER);		\
139 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);			\
140 	if (--(sctp_ipif)->sctp_ipif_refcnt == 0 && 			\
141 	    (sctp_ipif)->sctp_ipif_state == SCTP_IPIFS_CONDEMNED) {	\
142 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
143 		sctp_ipif_inactive(sctp_ipif);				\
144 	} else {							\
145 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
146 	}								\
147 }
148 
149 /* Address set comparison results. */
150 #define	SCTP_ADDR_EQUAL		1
151 #define	SCTP_ADDR_SUBSET	2
152 #define	SCTP_ADDR_OVERLAP	3
153 #define	SCTP_ADDR_DISJOINT	4
154 
155 extern void		sctp_update_ill(ill_t *, int);
156 extern void		sctp_update_ipif(ipif_t *, int);
157 
158 extern int		sctp_valid_addr_list(sctp_t *, const void *, uint32_t,
159 			    uchar_t *, size_t);
160 extern int		sctp_dup_saddrs(sctp_t *, sctp_t *, int);
161 extern int		sctp_compare_saddrs(sctp_t *, sctp_t *);
162 extern sctp_saddr_ipif_t	*sctp_saddr_lookup(sctp_t *, in6_addr_t *,
163 				    uint_t);
164 extern in6_addr_t	sctp_get_valid_addr(sctp_t *, boolean_t isv6);
165 extern size_t		sctp_saddr_info(sctp_t *, int, uchar_t *, boolean_t);
166 extern void		sctp_del_saddr_list(sctp_t *, const void *, int,
167 			    boolean_t);
168 extern void		sctp_del_saddr(sctp_t *, sctp_saddr_ipif_t *);
169 extern void		sctp_free_saddrs(sctp_t *);
170 extern void		sctp_saddr_init(sctp_stack_t *);
171 extern void		sctp_saddr_fini(sctp_stack_t *);
172 extern int		sctp_getmyaddrs(void *, void *, int *);
173 extern int		sctp_saddr_add_addr(sctp_t *, in6_addr_t *, uint_t);
174 extern void		sctp_check_saddr(sctp_t *, int, boolean_t);
175 
176 #ifdef	__cplusplus
177 }
178 #endif
179 
180 #endif	/* _SCTP_ADDR_H */
181