17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5f4b3ec61Sdh  * Common Development and Distribution License (the "License").
6f4b3ec61Sdh  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22bd670b35SErik Nordmark  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SCTP_ADDR_H
277c478bd9Sstevel@tonic-gate #define	_SCTP_ADDR_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/list.h>
307c478bd9Sstevel@tonic-gate #include <sys/zone.h>
317c478bd9Sstevel@tonic-gate #include <inet/ip.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * SCTP IPIF structure - only relevant fields from ipif_t retained
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  * There is a global array, sctp_g_ipifs, to store all addresses of
417c478bd9Sstevel@tonic-gate  * the system.  Each element of the global array is a list of
427c478bd9Sstevel@tonic-gate  * sctp_ipif_t.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * This structure is also shared by all SCTP PCBs.  Each SCTP PCB has
457c478bd9Sstevel@tonic-gate  * an array of source addresses.  Each element of that array is a list
467c478bd9Sstevel@tonic-gate  * of sctp_saddr_ipif_t.  And each sctp_saddr_ipif_t has a pointer
477c478bd9Sstevel@tonic-gate  * to a sctp_ipif_t.  The reason for sctp_saddr_ipif_t is that each
487c478bd9Sstevel@tonic-gate  * SCTP PCB may do different things to a source address.  This info
497c478bd9Sstevel@tonic-gate  * is stored locally in sctp_saddr_ipif_t.
507c478bd9Sstevel@tonic-gate  *
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate typedef struct sctp_ipif_s {
537c478bd9Sstevel@tonic-gate 	list_node_t		sctp_ipifs;	/* Used by the global list */
547c478bd9Sstevel@tonic-gate 	struct sctp_ill_s	*sctp_ipif_ill;
557c478bd9Sstevel@tonic-gate 	uint_t			sctp_ipif_id;
567c478bd9Sstevel@tonic-gate 	in6_addr_t		sctp_ipif_saddr;
577c478bd9Sstevel@tonic-gate 	int			sctp_ipif_state;
587c478bd9Sstevel@tonic-gate 	uint32_t		sctp_ipif_refcnt;
597c478bd9Sstevel@tonic-gate 	zoneid_t		sctp_ipif_zoneid;
607c478bd9Sstevel@tonic-gate 	krwlock_t		sctp_ipif_lock;
617c478bd9Sstevel@tonic-gate 	boolean_t		sctp_ipif_isv6;
62f551bb10Svi 	uint64_t		sctp_ipif_flags;
637c478bd9Sstevel@tonic-gate } sctp_ipif_t;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /* ipif_state */
667c478bd9Sstevel@tonic-gate #define	SCTP_IPIFS_CONDEMNED	-1
677c478bd9Sstevel@tonic-gate #define	SCTP_IPIFS_INVALID	-2
687c478bd9Sstevel@tonic-gate #define	SCTP_IPIFS_DOWN		1
697c478bd9Sstevel@tonic-gate #define	SCTP_IPIFS_UP		2
707c478bd9Sstevel@tonic-gate 
71df19b344Svi /*
72df19b344Svi  * Individual SCTP source address structure.
73df19b344Svi  * saddr_ipifp is the actual pointer to the ipif/address.
74df19b344Svi  * saddr_ipif_dontsrc is used to mark an address as currently unusable. This
75df19b344Svi  * would be the case when we have added/deleted an address using sctp_bindx()
76df19b344Svi  * and are waiting for the ASCONF ACK from the peer to confirm the addition/
77df19b344Svi  * deletion. Additionally, saddr_ipif_delete_pending is used to specifically
78df19b344Svi  * indicate that an address delete operation is in progress.
79df19b344Svi  */
807c478bd9Sstevel@tonic-gate typedef struct sctp_saddrs_ipif_s {
817c478bd9Sstevel@tonic-gate 	list_node_t	saddr_ipif;
827c478bd9Sstevel@tonic-gate 	sctp_ipif_t 	*saddr_ipifp;
837c478bd9Sstevel@tonic-gate 	uint32_t	saddr_ipif_dontsrc : 1,
847c478bd9Sstevel@tonic-gate 			saddr_ipif_delete_pending : 1,
85f551bb10Svi 			saddr_ipif_unconfirmed : 1,
86f551bb10Svi 			pad : 29;
877c478bd9Sstevel@tonic-gate } sctp_saddr_ipif_t;
887c478bd9Sstevel@tonic-gate 
89f551bb10Svi #define	SCTP_DONT_SRC(sctp_saddr)	\
90f551bb10Svi 	((sctp_saddr)->saddr_ipif_dontsrc ||	\
91f551bb10Svi 	(sctp_saddr)->saddr_ipif_unconfirmed)
92f551bb10Svi 
93f551bb10Svi 
94df19b344Svi /*
95df19b344Svi  * SCTP ILL structure - only relevant fields from ill_t retained.
96df19b344Svi  * This pretty much reflects the ILL<->IPIF relation that IP maintains.
97df19b344Svi  * At present the only state an ILL can be in is CONDEMNED or not.
98df19b344Svi  * sctp_ill_ipifcnt gives the number of IPIFs for this ILL,
99df19b344Svi  * sctp_ill_index is phyint_ifindex in the actual ILL structure (in IP)
100df19b344Svi  * and sctp_ill_flags is ill_flags from the ILL structure.
101f4b3ec61Sdh  *
102f4b3ec61Sdh  * The comment below (and for other netstack_t references) refers
103f4b3ec61Sdh  * to the fact that we only do netstack_hold in particular cases,
104f4b3ec61Sdh  * such as the references from open streams (ill_t and conn_t's
105f4b3ec61Sdh  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
106f4b3ec61Sdh  * ire_t's when an ill goes away.
107df19b344Svi  */
1087c478bd9Sstevel@tonic-gate typedef struct sctp_ill_s {
109f4b3ec61Sdh 	list_node_t	sctp_ills;
110f4b3ec61Sdh 	int		sctp_ill_name_length;
111f4b3ec61Sdh 	char		*sctp_ill_name;
112f4b3ec61Sdh 	int		sctp_ill_state;
113f4b3ec61Sdh 	uint32_t	sctp_ill_ipifcnt;
114f4b3ec61Sdh 	uint_t		sctp_ill_index;
115f4b3ec61Sdh 	uint64_t	sctp_ill_flags;
1161d19ca10Svi 	boolean_t	sctp_ill_isv6;
117f4b3ec61Sdh 	netstack_t	*sctp_ill_netstack; /* Does not have a netstack_hold */
1187c478bd9Sstevel@tonic-gate } sctp_ill_t;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /* ill_state */
1217c478bd9Sstevel@tonic-gate #define	SCTP_ILLS_CONDEMNED	-1
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #define	SCTP_ILL_HASH	16
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate typedef struct sctp_ill_hash_s {
1267c478bd9Sstevel@tonic-gate 	list_t	sctp_ill_list;
1277c478bd9Sstevel@tonic-gate 	int	ill_count;
1287c478bd9Sstevel@tonic-gate } sctp_ill_hash_t;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #define	SCTP_IPIF_REFHOLD(sctp_ipif) {				\
132*92baa190SGeorge Shepherd 	rw_enter(&(sctp_ipif)->sctp_ipif_lock, RW_WRITER);	\
133*92baa190SGeorge Shepherd 	(sctp_ipif)->sctp_ipif_refcnt++;			\
134*92baa190SGeorge Shepherd 	rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate #define	SCTP_IPIF_REFRELE(sctp_ipif) {					\
138e35d2278Svi 	rw_enter(&(sctp_ipif)->sctp_ipif_lock, RW_WRITER);		\
1397c478bd9Sstevel@tonic-gate 	ASSERT((sctp_ipif)->sctp_ipif_refcnt != 0);			\
140e35d2278Svi 	if (--(sctp_ipif)->sctp_ipif_refcnt == 0 && 			\
141e35d2278Svi 	    (sctp_ipif)->sctp_ipif_state == SCTP_IPIFS_CONDEMNED) {	\
142e35d2278Svi 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
1437c478bd9Sstevel@tonic-gate 		sctp_ipif_inactive(sctp_ipif);				\
144e35d2278Svi 	} else {							\
145e35d2278Svi 		rw_exit(&(sctp_ipif)->sctp_ipif_lock);			\
146e35d2278Svi 	}								\
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /* Address set comparison results. */
1507c478bd9Sstevel@tonic-gate #define	SCTP_ADDR_EQUAL		1
1517c478bd9Sstevel@tonic-gate #define	SCTP_ADDR_SUBSET	2
1527c478bd9Sstevel@tonic-gate #define	SCTP_ADDR_OVERLAP	3
1537c478bd9Sstevel@tonic-gate #define	SCTP_ADDR_DISJOINT	4
1547c478bd9Sstevel@tonic-gate 
1551d8c4025Svi extern int		sctp_valid_addr_list(sctp_t *, const void *, uint32_t,
1561d8c4025Svi 			    uchar_t *, size_t);
1577c478bd9Sstevel@tonic-gate extern int		sctp_dup_saddrs(sctp_t *, sctp_t *, int);
1587c478bd9Sstevel@tonic-gate extern int		sctp_compare_saddrs(sctp_t *, sctp_t *);
1591d8c4025Svi extern sctp_saddr_ipif_t	*sctp_saddr_lookup(sctp_t *, in6_addr_t *,
1601d8c4025Svi 				    uint_t);
161c31292eeSkcpoon extern in6_addr_t	sctp_get_valid_addr(sctp_t *, boolean_t, boolean_t *);
162f551bb10Svi extern size_t		sctp_saddr_info(sctp_t *, int, uchar_t *, boolean_t);
1637c478bd9Sstevel@tonic-gate extern void		sctp_del_saddr_list(sctp_t *, const void *, int,
1647c478bd9Sstevel@tonic-gate 			    boolean_t);
1657c478bd9Sstevel@tonic-gate extern void		sctp_del_saddr(sctp_t *, sctp_saddr_ipif_t *);
1667c478bd9Sstevel@tonic-gate extern void		sctp_free_saddrs(sctp_t *);
167f4b3ec61Sdh extern void		sctp_saddr_init(sctp_stack_t *);
168f4b3ec61Sdh extern void		sctp_saddr_fini(sctp_stack_t *);
1697c478bd9Sstevel@tonic-gate extern int		sctp_getmyaddrs(void *, void *, int *);
1701d8c4025Svi extern int		sctp_saddr_add_addr(sctp_t *, in6_addr_t *, uint_t);
171c31292eeSkcpoon extern void		sctp_check_saddr(sctp_t *, int, boolean_t,
172c31292eeSkcpoon 			    in6_addr_t *);
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate #endif
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate #endif	/* _SCTP_ADDR_H */
179