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