xref: /titanic_41/usr/src/uts/common/inet/sctp/sctp_addr.h (revision fd9cb95cbb2f626355a60efb9d02c5f0a33c10e6)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SCTP_ADDR_H
28 #define	_SCTP_ADDR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/list.h>
33 #include <sys/zone.h>
34 #include <inet/ip.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * SCTP IPIF structure - only relevant fields from ipif_t retained
42  *
43  * There is a global array, sctp_g_ipifs, to store all addresses of
44  * the system.  Each element of the global array is a list of
45  * sctp_ipif_t.
46  *
47  * This structure is also shared by all SCTP PCBs.  Each SCTP PCB has
48  * an array of source addresses.  Each element of that array is a list
49  * of sctp_saddr_ipif_t.  And each sctp_saddr_ipif_t has a pointer
50  * to a sctp_ipif_t.  The reason for sctp_saddr_ipif_t is that each
51  * SCTP PCB may do different things to a source address.  This info
52  * is stored locally in sctp_saddr_ipif_t.
53  *
54  */
55 typedef struct sctp_ipif_s {
56 	list_node_t		sctp_ipifs;	/* Used by the global list */
57 	struct sctp_ill_s	*sctp_ipif_ill;
58 	uint_t			sctp_ipif_mtu;
59 	uint_t			sctp_ipif_id;
60 	in6_addr_t		sctp_ipif_saddr;
61 	int			sctp_ipif_state;
62 	uint32_t		sctp_ipif_refcnt;
63 	zoneid_t		sctp_ipif_zoneid;
64 	krwlock_t		sctp_ipif_lock;
65 	boolean_t		sctp_ipif_isv6;
66 	uint64_t		sctp_ipif_flags;
67 } sctp_ipif_t;
68 
69 /* ipif_state */
70 #define	SCTP_IPIFS_CONDEMNED	-1
71 #define	SCTP_IPIFS_INVALID	-2
72 #define	SCTP_IPIFS_DOWN		1
73 #define	SCTP_IPIFS_UP		2
74 
75 /*
76  * Individual SCTP source address structure.
77  * saddr_ipifp is the actual pointer to the ipif/address.
78  * saddr_ipif_dontsrc is used to mark an address as currently unusable. This
79  * would be the case when we have added/deleted an address using sctp_bindx()
80  * and are waiting for the ASCONF ACK from the peer to confirm the addition/
81  * deletion. Additionally, saddr_ipif_delete_pending is used to specifically
82  * indicate that an address delete operation is in progress.
83  */
84 typedef struct sctp_saddrs_ipif_s {
85 	list_node_t	saddr_ipif;
86 	sctp_ipif_t 	*saddr_ipifp;
87 	uint32_t	saddr_ipif_dontsrc : 1,
88 			saddr_ipif_delete_pending : 1,
89 			saddr_ipif_unconfirmed : 1,
90 			pad : 29;
91 } sctp_saddr_ipif_t;
92 
93 #define	SCTP_DONT_SRC(sctp_saddr)	\
94 	((sctp_saddr)->saddr_ipif_dontsrc ||	\
95 	(sctp_saddr)->saddr_ipif_unconfirmed)
96 
97 
98 /*
99  * SCTP ILL structure - only relevant fields from ill_t retained.
100  * This pretty much reflects the ILL<->IPIF relation that IP maintains.
101  * At present the only state an ILL can be in is CONDEMNED or not.
102  * sctp_ill_ipifcnt gives the number of IPIFs for this ILL,
103  * sctp_ill_index is phyint_ifindex in the actual ILL structure (in IP)
104  * and sctp_ill_flags is ill_flags from the ILL structure.
105  */
106 typedef struct sctp_ill_s {
107 	list_node_t		sctp_ills;
108 	int			sctp_ill_name_length;
109 	char			*sctp_ill_name;
110 	int			sctp_ill_state;
111 	uint32_t		sctp_ill_ipifcnt;
112 	uint_t			sctp_ill_index;
113 	uint64_t		sctp_ill_flags;
114 } sctp_ill_t;
115 
116 /* ill_state */
117 #define	SCTP_ILLS_CONDEMNED	-1
118 
119 #define	SCTP_ILL_HASH	16
120 
121 typedef struct sctp_ill_hash_s {
122 	list_t	sctp_ill_list;
123 	int	ill_count;
124 } sctp_ill_hash_t;
125 
126 /* Global list of SCTP ILLs */
127 extern sctp_ill_hash_t	sctp_g_ills[SCTP_ILL_HASH];
128 krwlock_t		sctp_g_ills_lock;
129 extern uint32_t		sctp_ills_count;
130 extern uint32_t		sctp_ills_min_mtu;
131 
132 /* Global list of SCTP ipifs */
133 extern	sctp_ipif_hash_t	sctp_g_ipifs[SCTP_IPIF_HASH];
134 extern	uint32_t		sctp_g_ipifs_count;
135 krwlock_t			sctp_g_ipifs_lock;
136 
137 
138 #define	SCTP_IPIF_REFHOLD(sctp_ipif) {				\
139 	atomic_add_32(&(sctp_ipif)->sctp_ipif_refcnt, 1);	\
140 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);		\
141 }
142 
143 #define	SCTP_IPIF_REFRELE(sctp_ipif) {					\
144 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);			\
145 	if (atomic_add_32_nv(&(sctp_ipif)->sctp_ipif_refcnt, -1) == 0)	\
146 		sctp_ipif_inactive(sctp_ipif);				\
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 extern int		sctp_dup_saddrs(sctp_t *, sctp_t *, int);
160 extern int		sctp_compare_saddrs(sctp_t *, sctp_t *);
161 extern sctp_saddr_ipif_t	*sctp_saddr_lookup(sctp_t *, in6_addr_t *);
162 extern in6_addr_t	sctp_get_valid_addr(sctp_t *, boolean_t isv6);
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();
169 extern void		sctp_saddr_fini();
170 extern sctp_saddr_ipif_t	*sctp_ipif_lookup(sctp_t *, uint_t);
171 extern int		sctp_getmyaddrs(void *, void *, int *);
172 extern int		sctp_saddr_add_addr(sctp_t *, in6_addr_t *);
173 extern void		sctp_check_saddr(sctp_t *, int, boolean_t);
174 
175 #ifdef	__cplusplus
176 }
177 #endif
178 
179 #endif	/* _SCTP_ADDR_H */
180