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 5f4b3ec61Sdh155122 * Common Development and Distribution License (the "License"). 6f4b3ec61Sdh155122 * 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 _INET_KEYSOCK_H 277c478bd9Sstevel@tonic-gate #define _INET_KEYSOCK_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifdef __cplusplus 307c478bd9Sstevel@tonic-gate extern "C" { 317c478bd9Sstevel@tonic-gate #endif 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate extern int keysock_opt_get(queue_t *, int, int, uchar_t *); 347c478bd9Sstevel@tonic-gate extern int keysock_opt_set(queue_t *, uint_t, int, int, uint_t, 35bd670b35SErik Nordmark uchar_t *, uint_t *, uchar_t *, void *, cred_t *cr); 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * Object to represent database of options to search passed to 397c478bd9Sstevel@tonic-gate * {sock,tpi}optcom_req() interface routine to take care of option 407c478bd9Sstevel@tonic-gate * management and associated methods. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate extern optdb_obj_t keysock_opt_obj; 447c478bd9Sstevel@tonic-gate extern uint_t keysock_max_optsize; 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* 47f4b3ec61Sdh155122 * KEYSOCK stack instances 48f4b3ec61Sdh155122 */ 49f4b3ec61Sdh155122 struct keysock_stack { 50f4b3ec61Sdh155122 netstack_t *keystack_netstack; /* Common netstack */ 51f4b3ec61Sdh155122 /* 52f4b3ec61Sdh155122 * keysock_plumbed: zero if plumb not attempted, positive if it 53f4b3ec61Sdh155122 * succeeded, negative if it failed. 54f4b3ec61Sdh155122 */ 55f4b3ec61Sdh155122 int keystack_plumbed; 56f4b3ec61Sdh155122 caddr_t keystack_g_nd; 57f4b3ec61Sdh155122 struct keysockparam_s *keystack_params; 58f4b3ec61Sdh155122 59f4b3ec61Sdh155122 kmutex_t keystack_param_lock; 60f4b3ec61Sdh155122 /* Protects the NDD variables. */ 61f4b3ec61Sdh155122 62f4b3ec61Sdh155122 /* List of open PF_KEY sockets, protected by keysock_list_lock. */ 63f4b3ec61Sdh155122 kmutex_t keystack_list_lock; 64f4b3ec61Sdh155122 struct keysock_s *keystack_list; 65f4b3ec61Sdh155122 66f4b3ec61Sdh155122 /* 67f4b3ec61Sdh155122 * Consumers table. If an entry is NULL, keysock maintains 68f4b3ec61Sdh155122 * the table. 69f4b3ec61Sdh155122 */ 70f4b3ec61Sdh155122 kmutex_t keystack_consumers_lock; 71f4b3ec61Sdh155122 72f4b3ec61Sdh155122 #define KEYSOCK_MAX_CONSUMERS 256 73f4b3ec61Sdh155122 struct keysock_consumer_s *keystack_consumers[KEYSOCK_MAX_CONSUMERS]; 74f4b3ec61Sdh155122 75f4b3ec61Sdh155122 /* 76f4b3ec61Sdh155122 * State for flush/dump. This would normally be a boolean_t, but 77*8b6220d7SJosef 'Jeff' Sipek * atomic_cas_32() works best for a known 32-bit quantity. 78f4b3ec61Sdh155122 */ 79f4b3ec61Sdh155122 uint32_t keystack_flushdump; 80f4b3ec61Sdh155122 int keystack_flushdump_errno; 81f4b3ec61Sdh155122 82f4b3ec61Sdh155122 /* 83f4b3ec61Sdh155122 * This integer counts the number of extended REGISTERed sockets. This 84f4b3ec61Sdh155122 * determines if we should send extended REGISTERs. 85f4b3ec61Sdh155122 */ 86f4b3ec61Sdh155122 uint32_t keystack_num_extended; 87f4b3ec61Sdh155122 88f4b3ec61Sdh155122 /* 89f4b3ec61Sdh155122 * Global sequence space for SADB_ACQUIRE messages of any sort. 90f4b3ec61Sdh155122 */ 91f4b3ec61Sdh155122 uint32_t keystack_acquire_seq; 92f4b3ec61Sdh155122 }; 93f4b3ec61Sdh155122 typedef struct keysock_stack keysock_stack_t; 94f4b3ec61Sdh155122 95f4b3ec61Sdh155122 /* 967c478bd9Sstevel@tonic-gate * keysock session state (one per open PF_KEY socket (i.e. as a driver)) 977c478bd9Sstevel@tonic-gate * 987c478bd9Sstevel@tonic-gate * I keep these in a linked list, and assign a monotonically increasing 997c478bd9Sstevel@tonic-gate * serial ## (which is also the minor number). 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate typedef struct keysock_s { 1037c478bd9Sstevel@tonic-gate /* Protected by keysock_list_lock. */ 1047c478bd9Sstevel@tonic-gate struct keysock_s *keysock_next; /* Next in list */ 1057c478bd9Sstevel@tonic-gate struct keysock_s **keysock_ptpn; /* Pointer to previous next */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate kmutex_t keysock_lock; /* Protects the following. */ 1087c478bd9Sstevel@tonic-gate queue_t *keysock_rq; /* Read queue - putnext() to userland */ 1097c478bd9Sstevel@tonic-gate queue_t *keysock_wq; /* Write queue */ 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate uint_t keysock_state; 1127c478bd9Sstevel@tonic-gate uint_t keysock_flags; 1137c478bd9Sstevel@tonic-gate /* If SADB_SATYPE_MAX (in net/pfkeyv2.h) > 255, rewhack this. */ 1147c478bd9Sstevel@tonic-gate uint64_t keysock_registered[4]; /* Registered types for this socket. */ 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* Also protected by keysock_list_lock. */ 1177c478bd9Sstevel@tonic-gate minor_t keysock_serial; /* Serial number of this socket. */ 118f4b3ec61Sdh155122 keysock_stack_t *keysock_keystack; 1197c478bd9Sstevel@tonic-gate } keysock_t; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #define KEYSOCK_NOLOOP 0x1 /* Don't loopback messages (no replies). */ 1227c478bd9Sstevel@tonic-gate #define KEYSOCK_PROMISC 0x2 /* Give me all outbound messages. */ 1237c478bd9Sstevel@tonic-gate /* DANGER: Setting this requires EXTRA */ 1247c478bd9Sstevel@tonic-gate /* privilege on an MLS box. */ 1257c478bd9Sstevel@tonic-gate #define KEYSOCK_EXTENDED 0x4 /* Extended REGISTER received. */ 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate /* My apologies for the ugliness of this macro. And using constants. */ 1287c478bd9Sstevel@tonic-gate #define KEYSOCK_ISREG(ks, satype) (((ks)->keysock_registered[(satype) >> 3]) & \ 1297c478bd9Sstevel@tonic-gate (1 << ((satype) & 63))) 1307c478bd9Sstevel@tonic-gate #define KEYSOCK_SETREG(ks, satype) (ks)->keysock_registered[(satype) >> 3] |= \ 1317c478bd9Sstevel@tonic-gate (1 << ((satype) & 63)) 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Keysock consumers (i.e. AH, ESP), in array based on sadb_msg_satype. 1357c478bd9Sstevel@tonic-gate * For module instances. 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate typedef struct keysock_consumer_s { 1397c478bd9Sstevel@tonic-gate kmutex_t kc_lock; /* Protects instance. */ 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate queue_t *kc_rq; /* Read queue, requests from AH, ESP. */ 1427c478bd9Sstevel@tonic-gate queue_t *kc_wq; /* Write queue, putnext down */ 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* Other goodies as a need them. */ 1457c478bd9Sstevel@tonic-gate uint8_t kc_sa_type; /* What sort of SA am I? */ 1467c478bd9Sstevel@tonic-gate uint_t kc_flags; 147f4b3ec61Sdh155122 keysock_stack_t *kc_keystack; 1487c478bd9Sstevel@tonic-gate } keysock_consumer_t; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* Can only set flags when keysock_consumer_lock is held. */ 1517c478bd9Sstevel@tonic-gate #define KC_INTERNAL 0x1 /* Consumer maintained by keysock itself. */ 1527c478bd9Sstevel@tonic-gate #define KC_FLUSHING 0x2 /* SADB_FLUSH pending on this consumer. */ 1537c478bd9Sstevel@tonic-gate 154f4b3ec61Sdh155122 extern int keysock_plumb_ipsec(netstack_t *); 155f4b3ec61Sdh155122 1567c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate #endif 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #endif /* _INET_KEYSOCK_H */ 161