xref: /onnv-gate/usr/src/uts/common/inet/sctp/sctp_addr.h (revision 11373:cd33478fbb7b)
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 /*
2211042SErik.Nordmark@Sun.COM  * Copyright 2009 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 #include <sys/list.h>
300Sstevel@tonic-gate #include <sys/zone.h>
310Sstevel@tonic-gate #include <inet/ip.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #ifdef	__cplusplus
340Sstevel@tonic-gate extern "C" {
350Sstevel@tonic-gate #endif
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * SCTP IPIF structure - only relevant fields from ipif_t retained
390Sstevel@tonic-gate  *
400Sstevel@tonic-gate  * There is a global array, sctp_g_ipifs, to store all addresses of
410Sstevel@tonic-gate  * the system.  Each element of the global array is a list of
420Sstevel@tonic-gate  * sctp_ipif_t.
430Sstevel@tonic-gate  *
440Sstevel@tonic-gate  * This structure is also shared by all SCTP PCBs.  Each SCTP PCB has
450Sstevel@tonic-gate  * an array of source addresses.  Each element of that array is a list
460Sstevel@tonic-gate  * of sctp_saddr_ipif_t.  And each sctp_saddr_ipif_t has a pointer
470Sstevel@tonic-gate  * to a sctp_ipif_t.  The reason for sctp_saddr_ipif_t is that each
480Sstevel@tonic-gate  * SCTP PCB may do different things to a source address.  This info
490Sstevel@tonic-gate  * is stored locally in sctp_saddr_ipif_t.
500Sstevel@tonic-gate  *
510Sstevel@tonic-gate  */
520Sstevel@tonic-gate typedef struct sctp_ipif_s {
530Sstevel@tonic-gate 	list_node_t		sctp_ipifs;	/* Used by the global list */
540Sstevel@tonic-gate 	struct sctp_ill_s	*sctp_ipif_ill;
550Sstevel@tonic-gate 	uint_t			sctp_ipif_id;
560Sstevel@tonic-gate 	in6_addr_t		sctp_ipif_saddr;
570Sstevel@tonic-gate 	int			sctp_ipif_state;
580Sstevel@tonic-gate 	uint32_t		sctp_ipif_refcnt;
590Sstevel@tonic-gate 	zoneid_t		sctp_ipif_zoneid;
600Sstevel@tonic-gate 	krwlock_t		sctp_ipif_lock;
610Sstevel@tonic-gate 	boolean_t		sctp_ipif_isv6;
62432Svi117747 	uint64_t		sctp_ipif_flags;
630Sstevel@tonic-gate } sctp_ipif_t;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /* ipif_state */
660Sstevel@tonic-gate #define	SCTP_IPIFS_CONDEMNED	-1
670Sstevel@tonic-gate #define	SCTP_IPIFS_INVALID	-2
680Sstevel@tonic-gate #define	SCTP_IPIFS_DOWN		1
690Sstevel@tonic-gate #define	SCTP_IPIFS_UP		2
700Sstevel@tonic-gate 
71252Svi117747 /*
72252Svi117747  * Individual SCTP source address structure.
73252Svi117747  * saddr_ipifp is the actual pointer to the ipif/address.
74252Svi117747  * saddr_ipif_dontsrc is used to mark an address as currently unusable. This
75252Svi117747  * would be the case when we have added/deleted an address using sctp_bindx()
76252Svi117747  * and are waiting for the ASCONF ACK from the peer to confirm the addition/
77252Svi117747  * deletion. Additionally, saddr_ipif_delete_pending is used to specifically
78252Svi117747  * indicate that an address delete operation is in progress.
79252Svi117747  */
800Sstevel@tonic-gate typedef struct sctp_saddrs_ipif_s {
810Sstevel@tonic-gate 	list_node_t	saddr_ipif;
820Sstevel@tonic-gate 	sctp_ipif_t 	*saddr_ipifp;
830Sstevel@tonic-gate 	uint32_t	saddr_ipif_dontsrc : 1,
840Sstevel@tonic-gate 			saddr_ipif_delete_pending : 1,
85432Svi117747 			saddr_ipif_unconfirmed : 1,
86432Svi117747 			pad : 29;
870Sstevel@tonic-gate } sctp_saddr_ipif_t;
880Sstevel@tonic-gate 
89432Svi117747 #define	SCTP_DONT_SRC(sctp_saddr)	\
90432Svi117747 	((sctp_saddr)->saddr_ipif_dontsrc ||	\
91432Svi117747 	(sctp_saddr)->saddr_ipif_unconfirmed)
92432Svi117747 
93432Svi117747 
94252Svi117747 /*
95252Svi117747  * SCTP ILL structure - only relevant fields from ill_t retained.
96252Svi117747  * This pretty much reflects the ILL<->IPIF relation that IP maintains.
97252Svi117747  * At present the only state an ILL can be in is CONDEMNED or not.
98252Svi117747  * sctp_ill_ipifcnt gives the number of IPIFs for this ILL,
99252Svi117747  * sctp_ill_index is phyint_ifindex in the actual ILL structure (in IP)
100252Svi117747  * and sctp_ill_flags is ill_flags from the ILL structure.
1013448Sdh155122  *
1023448Sdh155122  * The comment below (and for other netstack_t references) refers
1033448Sdh155122  * to the fact that we only do netstack_hold in particular cases,
1043448Sdh155122  * such as the references from open streams (ill_t and conn_t's
1053448Sdh155122  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
1063448Sdh155122  * ire_t's when an ill goes away.
107252Svi117747  */
1080Sstevel@tonic-gate typedef struct sctp_ill_s {
1093448Sdh155122 	list_node_t	sctp_ills;
1103448Sdh155122 	int		sctp_ill_name_length;
1113448Sdh155122 	char		*sctp_ill_name;
1123448Sdh155122 	int		sctp_ill_state;
1133448Sdh155122 	uint32_t	sctp_ill_ipifcnt;
1143448Sdh155122 	uint_t		sctp_ill_index;
1153448Sdh155122 	uint64_t	sctp_ill_flags;
1164311Svi117747 	boolean_t	sctp_ill_isv6;
1173448Sdh155122 	netstack_t	*sctp_ill_netstack; /* Does not have a netstack_hold */
1180Sstevel@tonic-gate } sctp_ill_t;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate /* ill_state */
1210Sstevel@tonic-gate #define	SCTP_ILLS_CONDEMNED	-1
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate #define	SCTP_ILL_HASH	16
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate typedef struct sctp_ill_hash_s {
1260Sstevel@tonic-gate 	list_t	sctp_ill_list;
1270Sstevel@tonic-gate 	int	ill_count;
1280Sstevel@tonic-gate } sctp_ill_hash_t;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate #define	SCTP_IPIF_REFHOLD(sctp_ipif) {				\
132*11373SGeorge.Shepherd@Sun.COM 	rw_enter(&(sctp_ipif)->sctp_ipif_lock, RW_WRITER);	\
133*11373SGeorge.Shepherd@Sun.COM 	(sctp_ipif)->sctp_ipif_refcnt++;			\
134*11373SGeorge.Shepherd@Sun.COM 	rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #define	SCTP_IPIF_REFRELE(sctp_ipif) {					\
1383510Svi117747 	rw_enter(&(sctp_ipif)->sctp_ipif_lock, RW_WRITER);		\
1390Sstevel@tonic-gate 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);			\
1403510Svi117747 	if (--(sctp_ipif)->sctp_ipif_refcnt == 0 && 			\
1413510Svi117747 	    (sctp_ipif)->sctp_ipif_state == SCTP_IPIFS_CONDEMNED) {	\
1423510Svi117747 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
1430Sstevel@tonic-gate 		sctp_ipif_inactive(sctp_ipif);				\
1443510Svi117747 	} else {							\
1453510Svi117747 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
1463510Svi117747 	}								\
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 
155852Svi117747 extern int		sctp_valid_addr_list(sctp_t *, const void *, uint32_t,
156852Svi117747 			    uchar_t *, size_t);
1570Sstevel@tonic-gate extern int		sctp_dup_saddrs(sctp_t *, sctp_t *, int);
1580Sstevel@tonic-gate extern int		sctp_compare_saddrs(sctp_t *, sctp_t *);
159852Svi117747 extern sctp_saddr_ipif_t	*sctp_saddr_lookup(sctp_t *, in6_addr_t *,
160852Svi117747 				    uint_t);
1614818Skcpoon extern in6_addr_t	sctp_get_valid_addr(sctp_t *, boolean_t, boolean_t *);
162432Svi117747 extern size_t		sctp_saddr_info(sctp_t *, int, uchar_t *, boolean_t);
1630Sstevel@tonic-gate extern void		sctp_del_saddr_list(sctp_t *, const void *, int,
1640Sstevel@tonic-gate 			    boolean_t);
1650Sstevel@tonic-gate extern void		sctp_del_saddr(sctp_t *, sctp_saddr_ipif_t *);
1660Sstevel@tonic-gate extern void		sctp_free_saddrs(sctp_t *);
1673448Sdh155122 extern void		sctp_saddr_init(sctp_stack_t *);
1683448Sdh155122 extern void		sctp_saddr_fini(sctp_stack_t *);
1690Sstevel@tonic-gate extern int		sctp_getmyaddrs(void *, void *, int *);
170852Svi117747 extern int		sctp_saddr_add_addr(sctp_t *, in6_addr_t *, uint_t);
1714818Skcpoon extern void		sctp_check_saddr(sctp_t *, int, boolean_t,
1724818Skcpoon 			    in6_addr_t *);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #ifdef	__cplusplus
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate #endif
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate #endif	/* _SCTP_ADDR_H */
179