xref: /titanic_44/usr/src/uts/common/inet/keysock.h (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
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 1998,2001-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_INET_KEYSOCK_H
28 #define	_INET_KEYSOCK_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 extern int keysock_opt_get(queue_t *, int, int, uchar_t *);
37 extern int keysock_opt_set(queue_t *, uint_t, int, int, uint_t,
38     uchar_t *, uint_t *, uchar_t *, void *, cred_t *cr, mblk_t *mblk);
39 
40 /*
41  * Object to represent database of options to search passed to
42  * {sock,tpi}optcom_req() interface routine to take care of option
43  * management and associated methods.
44  */
45 
46 extern optdb_obj_t	keysock_opt_obj;
47 extern uint_t		keysock_max_optsize;
48 
49 /*
50  * keysock session state (one per open PF_KEY socket (i.e. as a driver))
51  *
52  * I keep these in a linked list, and assign a monotonically increasing
53  * serial ## (which is also the minor number).
54  */
55 
56 typedef struct keysock_s {
57 	/* Protected by keysock_list_lock. */
58 	struct keysock_s *keysock_next; /* Next in list */
59 	struct keysock_s **keysock_ptpn; /* Pointer to previous next */
60 
61 	kmutex_t keysock_lock; /* Protects the following. */
62 	queue_t *keysock_rq;   /* Read queue - putnext() to userland */
63 	queue_t *keysock_wq;   /* Write queue */
64 
65 	uint_t keysock_state;
66 	uint_t keysock_flags;
67 	/* If SADB_SATYPE_MAX (in net/pfkeyv2.h) > 255, rewhack this. */
68 	uint64_t keysock_registered[4]; /* Registered types for this socket. */
69 
70 	/* Also protected by keysock_list_lock. */
71 	minor_t keysock_serial; /* Serial number of this socket. */
72 } keysock_t;
73 
74 #define	KEYSOCK_NOLOOP	0x1	/* Don't loopback messages (no replies). */
75 #define	KEYSOCK_PROMISC	0x2	/* Give me all outbound messages. */
76 				/* DANGER:	Setting this requires EXTRA */
77 				/* 		privilege on an MLS box. */
78 #define	KEYSOCK_EXTENDED 0x4	/* Extended REGISTER received. */
79 
80 /* My apologies for the ugliness of this macro.  And using constants. */
81 #define	KEYSOCK_ISREG(ks, satype) (((ks)->keysock_registered[(satype) >> 3]) & \
82 	(1 << ((satype) & 63)))
83 #define	KEYSOCK_SETREG(ks, satype) (ks)->keysock_registered[(satype) >> 3] |= \
84 	(1 << ((satype) & 63))
85 
86 /*
87  * Keysock consumers (i.e. AH, ESP), in array based on sadb_msg_satype.
88  * For module instances.
89  */
90 
91 typedef struct keysock_consumer_s {
92 	kmutex_t kc_lock;	/* Protects instance. */
93 
94 	queue_t *kc_rq;		/* Read queue, requests from AH, ESP. */
95 	queue_t *kc_wq;		/* Write queue, putnext down */
96 
97 	/* Other goodies as a need them. */
98 	uint8_t kc_sa_type;	/* What sort of SA am I? */
99 	uint_t kc_flags;
100 } keysock_consumer_t;
101 
102 /* Can only set flags when keysock_consumer_lock is held. */
103 #define	KC_INTERNAL 0x1		/* Consumer maintained by keysock itself. */
104 #define	KC_FLUSHING 0x2		/* SADB_FLUSH pending on this consumer. */
105 
106 #ifdef	__cplusplus
107 }
108 #endif
109 
110 #endif /* _INET_KEYSOCK_H */
111