xref: /onnv-gate/usr/src/uts/common/inet/sctp/sctp_addr.h (revision 3510:c7025db1a5cd)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53448Sdh155122  * Common Development and Distribution License (the "License").
63448Sdh155122  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
223448Sdh155122  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SCTP_ADDR_H
270Sstevel@tonic-gate #define	_SCTP_ADDR_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/list.h>
320Sstevel@tonic-gate #include <sys/zone.h>
330Sstevel@tonic-gate #include <inet/ip.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef	__cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * SCTP IPIF structure - only relevant fields from ipif_t retained
410Sstevel@tonic-gate  *
420Sstevel@tonic-gate  * There is a global array, sctp_g_ipifs, to store all addresses of
430Sstevel@tonic-gate  * the system.  Each element of the global array is a list of
440Sstevel@tonic-gate  * sctp_ipif_t.
450Sstevel@tonic-gate  *
460Sstevel@tonic-gate  * This structure is also shared by all SCTP PCBs.  Each SCTP PCB has
470Sstevel@tonic-gate  * an array of source addresses.  Each element of that array is a list
480Sstevel@tonic-gate  * of sctp_saddr_ipif_t.  And each sctp_saddr_ipif_t has a pointer
490Sstevel@tonic-gate  * to a sctp_ipif_t.  The reason for sctp_saddr_ipif_t is that each
500Sstevel@tonic-gate  * SCTP PCB may do different things to a source address.  This info
510Sstevel@tonic-gate  * is stored locally in sctp_saddr_ipif_t.
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate typedef struct sctp_ipif_s {
550Sstevel@tonic-gate 	list_node_t		sctp_ipifs;	/* Used by the global list */
560Sstevel@tonic-gate 	struct sctp_ill_s	*sctp_ipif_ill;
570Sstevel@tonic-gate 	uint_t			sctp_ipif_mtu;
580Sstevel@tonic-gate 	uint_t			sctp_ipif_id;
590Sstevel@tonic-gate 	in6_addr_t		sctp_ipif_saddr;
600Sstevel@tonic-gate 	int			sctp_ipif_state;
610Sstevel@tonic-gate 	uint32_t		sctp_ipif_refcnt;
620Sstevel@tonic-gate 	zoneid_t		sctp_ipif_zoneid;
630Sstevel@tonic-gate 	krwlock_t		sctp_ipif_lock;
640Sstevel@tonic-gate 	boolean_t		sctp_ipif_isv6;
65432Svi117747 	uint64_t		sctp_ipif_flags;
660Sstevel@tonic-gate } sctp_ipif_t;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /* ipif_state */
690Sstevel@tonic-gate #define	SCTP_IPIFS_CONDEMNED	-1
700Sstevel@tonic-gate #define	SCTP_IPIFS_INVALID	-2
710Sstevel@tonic-gate #define	SCTP_IPIFS_DOWN		1
720Sstevel@tonic-gate #define	SCTP_IPIFS_UP		2
730Sstevel@tonic-gate 
74252Svi117747 /*
75252Svi117747  * Individual SCTP source address structure.
76252Svi117747  * saddr_ipifp is the actual pointer to the ipif/address.
77252Svi117747  * saddr_ipif_dontsrc is used to mark an address as currently unusable. This
78252Svi117747  * would be the case when we have added/deleted an address using sctp_bindx()
79252Svi117747  * and are waiting for the ASCONF ACK from the peer to confirm the addition/
80252Svi117747  * deletion. Additionally, saddr_ipif_delete_pending is used to specifically
81252Svi117747  * indicate that an address delete operation is in progress.
82252Svi117747  */
830Sstevel@tonic-gate typedef struct sctp_saddrs_ipif_s {
840Sstevel@tonic-gate 	list_node_t	saddr_ipif;
850Sstevel@tonic-gate 	sctp_ipif_t 	*saddr_ipifp;
860Sstevel@tonic-gate 	uint32_t	saddr_ipif_dontsrc : 1,
870Sstevel@tonic-gate 			saddr_ipif_delete_pending : 1,
88432Svi117747 			saddr_ipif_unconfirmed : 1,
89432Svi117747 			pad : 29;
900Sstevel@tonic-gate } sctp_saddr_ipif_t;
910Sstevel@tonic-gate 
92432Svi117747 #define	SCTP_DONT_SRC(sctp_saddr)	\
93432Svi117747 	((sctp_saddr)->saddr_ipif_dontsrc ||	\
94432Svi117747 	(sctp_saddr)->saddr_ipif_unconfirmed)
95432Svi117747 
96432Svi117747 
97252Svi117747 /*
98252Svi117747  * SCTP ILL structure - only relevant fields from ill_t retained.
99252Svi117747  * This pretty much reflects the ILL<->IPIF relation that IP maintains.
100252Svi117747  * At present the only state an ILL can be in is CONDEMNED or not.
101252Svi117747  * sctp_ill_ipifcnt gives the number of IPIFs for this ILL,
102252Svi117747  * sctp_ill_index is phyint_ifindex in the actual ILL structure (in IP)
103252Svi117747  * and sctp_ill_flags is ill_flags from the ILL structure.
1043448Sdh155122  *
1053448Sdh155122  * The comment below (and for other netstack_t references) refers
1063448Sdh155122  * to the fact that we only do netstack_hold in particular cases,
1073448Sdh155122  * such as the references from open streams (ill_t and conn_t's
1083448Sdh155122  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
1093448Sdh155122  * ire_t's when an ill goes away.
110252Svi117747  */
1110Sstevel@tonic-gate typedef struct sctp_ill_s {
1123448Sdh155122 	list_node_t	sctp_ills;
1133448Sdh155122 	int		sctp_ill_name_length;
1143448Sdh155122 	char		*sctp_ill_name;
1153448Sdh155122 	int		sctp_ill_state;
1163448Sdh155122 	uint32_t	sctp_ill_ipifcnt;
1173448Sdh155122 	uint_t		sctp_ill_index;
1183448Sdh155122 	uint64_t	sctp_ill_flags;
1193448Sdh155122 	netstack_t	*sctp_ill_netstack; /* Does not have a netstack_hold */
1200Sstevel@tonic-gate } sctp_ill_t;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate /* ill_state */
1230Sstevel@tonic-gate #define	SCTP_ILLS_CONDEMNED	-1
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate #define	SCTP_ILL_HASH	16
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate typedef struct sctp_ill_hash_s {
1280Sstevel@tonic-gate 	list_t	sctp_ill_list;
1290Sstevel@tonic-gate 	int	ill_count;
1300Sstevel@tonic-gate } sctp_ill_hash_t;
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate #define	SCTP_IPIF_REFHOLD(sctp_ipif) {				\
1340Sstevel@tonic-gate 	atomic_add_32(&(sctp_ipif)->sctp_ipif_refcnt, 1);	\
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #define	SCTP_IPIF_REFRELE(sctp_ipif) {					\
138*3510Svi117747 	rw_enter(&(sctp_ipif)->sctp_ipif_lock, RW_WRITER);		\
1390Sstevel@tonic-gate 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);			\
140*3510Svi117747 	if (--(sctp_ipif)->sctp_ipif_refcnt == 0 && 			\
141*3510Svi117747 	    (sctp_ipif)->sctp_ipif_state == SCTP_IPIFS_CONDEMNED) {	\
142*3510Svi117747 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
1430Sstevel@tonic-gate 		sctp_ipif_inactive(sctp_ipif);				\
144*3510Svi117747 	} else {							\
145*3510Svi117747 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
146*3510Svi117747 	}								\
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate /* Address set comparison results. */
1500Sstevel@tonic-gate #define	SCTP_ADDR_EQUAL		1
1510Sstevel@tonic-gate #define	SCTP_ADDR_SUBSET	2
1520Sstevel@tonic-gate #define	SCTP_ADDR_OVERLAP	3
1530Sstevel@tonic-gate #define	SCTP_ADDR_DISJOINT	4
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate extern void		sctp_update_ill(ill_t *, int);
1560Sstevel@tonic-gate extern void		sctp_update_ipif(ipif_t *, int);
1570Sstevel@tonic-gate 
158852Svi117747 extern int		sctp_valid_addr_list(sctp_t *, const void *, uint32_t,
159852Svi117747 			    uchar_t *, size_t);
1600Sstevel@tonic-gate extern int		sctp_dup_saddrs(sctp_t *, sctp_t *, int);
1610Sstevel@tonic-gate extern int		sctp_compare_saddrs(sctp_t *, sctp_t *);
162852Svi117747 extern sctp_saddr_ipif_t	*sctp_saddr_lookup(sctp_t *, in6_addr_t *,
163852Svi117747 				    uint_t);
1640Sstevel@tonic-gate extern in6_addr_t	sctp_get_valid_addr(sctp_t *, boolean_t isv6);
165432Svi117747 extern size_t		sctp_saddr_info(sctp_t *, int, uchar_t *, boolean_t);
1660Sstevel@tonic-gate extern void		sctp_del_saddr_list(sctp_t *, const void *, int,
1670Sstevel@tonic-gate 			    boolean_t);
1680Sstevel@tonic-gate extern void		sctp_del_saddr(sctp_t *, sctp_saddr_ipif_t *);
1690Sstevel@tonic-gate extern void		sctp_free_saddrs(sctp_t *);
1703448Sdh155122 extern void		sctp_saddr_init(sctp_stack_t *);
1713448Sdh155122 extern void		sctp_saddr_fini(sctp_stack_t *);
1720Sstevel@tonic-gate extern int		sctp_getmyaddrs(void *, void *, int *);
173852Svi117747 extern int		sctp_saddr_add_addr(sctp_t *, in6_addr_t *, uint_t);
174432Svi117747 extern void		sctp_check_saddr(sctp_t *, int, boolean_t);
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate #ifdef	__cplusplus
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate #endif
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate #endif	/* _SCTP_ADDR_H */
181