xref: /titanic_44/usr/src/uts/common/inet/sctp/sctp_addr.h (revision bd335c6465ddbafe543900df4b03247bfa288eff)
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 2004 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 } 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 /* SCTP source address structure for individual SCTP PCB */
75 typedef struct sctp_saddrs_ipif_s {
76 	list_node_t	saddr_ipif;
77 	sctp_ipif_t 	*saddr_ipifp;
78 	uint32_t	saddr_ipif_dontsrc : 1,
79 			saddr_ipif_delete_pending : 1,
80 			pad : 30;
81 } sctp_saddr_ipif_t;
82 
83 /* SCTP ILL structure - only relevant fields from ill_t retained */
84 typedef struct sctp_ill_s {
85 	list_node_t		sctp_ills;
86 	int			sctp_ill_name_length;
87 	char			*sctp_ill_name;
88 	int			sctp_ill_state;
89 	uint32_t		sctp_ill_ipifcnt;
90 	uint_t			sctp_ill_index;
91 	uint64_t		sctp_ill_flags;
92 } sctp_ill_t;
93 
94 /* ill_state */
95 #define	SCTP_ILLS_CONDEMNED	-1
96 
97 #define	SCTP_ILL_HASH	16
98 
99 typedef struct sctp_ill_hash_s {
100 	list_t	sctp_ill_list;
101 	int	ill_count;
102 } sctp_ill_hash_t;
103 
104 /* Global list of SCTP ILLs */
105 extern sctp_ill_hash_t	sctp_g_ills[SCTP_ILL_HASH];
106 krwlock_t		sctp_g_ills_lock;
107 extern uint32_t		sctp_ills_count;
108 extern uint32_t		sctp_ills_min_mtu;
109 
110 /* Global list of SCTP ipifs */
111 extern	sctp_ipif_hash_t	sctp_g_ipifs[SCTP_IPIF_HASH];
112 extern	uint32_t		sctp_g_ipifs_count;
113 krwlock_t			sctp_g_ipifs_lock;
114 
115 
116 #define	SCTP_IPIF_REFHOLD(sctp_ipif) {				\
117 	atomic_add_32(&(sctp_ipif)->sctp_ipif_refcnt, 1);	\
118 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);		\
119 }
120 
121 #define	SCTP_IPIF_REFRELE(sctp_ipif) {					\
122 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);			\
123 	if (atomic_add_32_nv(&(sctp_ipif)->sctp_ipif_refcnt, -1) == 0)	\
124 		sctp_ipif_inactive(sctp_ipif);				\
125 }
126 
127 /* Address set comparison results. */
128 #define	SCTP_ADDR_EQUAL		1
129 #define	SCTP_ADDR_SUBSET	2
130 #define	SCTP_ADDR_OVERLAP	3
131 #define	SCTP_ADDR_DISJOINT	4
132 
133 extern void		sctp_update_ill(ill_t *, int);
134 extern void		sctp_update_ipif(ipif_t *, int);
135 
136 extern int		sctp_valid_addr_list(sctp_t *, const void *, uint32_t);
137 extern int		sctp_dup_saddrs(sctp_t *, sctp_t *, int);
138 extern int		sctp_compare_saddrs(sctp_t *, sctp_t *);
139 extern sctp_saddr_ipif_t	*sctp_saddr_lookup(sctp_t *, in6_addr_t *);
140 extern in6_addr_t	sctp_get_valid_addr(sctp_t *, boolean_t isv6);
141 extern size_t		sctp_addr_len(sctp_t *, int);
142 extern size_t		sctp_addr_val(sctp_t *, int, uchar_t *);
143 extern void		sctp_del_saddr_list(sctp_t *, const void *, int,
144 			    boolean_t);
145 extern void		sctp_del_saddr(sctp_t *, sctp_saddr_ipif_t *);
146 extern void		sctp_free_saddrs(sctp_t *);
147 extern void		sctp_saddr_init();
148 extern void		sctp_saddr_fini();
149 extern sctp_saddr_ipif_t	*sctp_ipif_lookup(sctp_t *, uint_t);
150 extern int		sctp_getmyaddrs(void *, void *, int *);
151 
152 #ifdef	__cplusplus
153 }
154 #endif
155 
156 #endif	/* _SCTP_ADDR_H */
157