xref: /onnv-gate/usr/src/uts/common/fs/sockfs/nl7curi.h (revision 1974:465e0e36c6b1)
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
5*1974Sbrutus  * Common Development and Distribution License (the "License").
6*1974Sbrutus  * 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  */
21*1974Sbrutus 
220Sstevel@tonic-gate /*
23*1974Sbrutus  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef _SYS_SOCKFS_NL7CURI_H
280Sstevel@tonic-gate #define	_SYS_SOCKFS_NL7CURI_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/atomic.h>
380Sstevel@tonic-gate #include <sys/cmn_err.h>
390Sstevel@tonic-gate #include <sys/stropts.h>
400Sstevel@tonic-gate #include <sys/socket.h>
410Sstevel@tonic-gate #include <sys/socketvar.h>
420Sstevel@tonic-gate 
43*1974Sbrutus #undef	PROMIF_DEBUG
44*1974Sbrutus 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * Some usefull chararcter macros:
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #ifndef	tolower
500Sstevel@tonic-gate #define	tolower(c) ((c) >= 'A' && (c) <= 'Z' ? (c) | 0x20 : (c))
510Sstevel@tonic-gate #endif
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #ifndef	isdigit
540Sstevel@tonic-gate #define	isdigit(c) ((c) >= '0' && (c) <= '9')
550Sstevel@tonic-gate #endif
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #ifndef isalpha
580Sstevel@tonic-gate #define	isalpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
590Sstevel@tonic-gate #endif
600Sstevel@tonic-gate 
610Sstevel@tonic-gate #ifndef isspace
620Sstevel@tonic-gate #define	isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || \
630Sstevel@tonic-gate 		(c) == '\r' || (c) == '\f' || (c) == '\013')
640Sstevel@tonic-gate #endif
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * ref_t - reference type, ...
680Sstevel@tonic-gate  *
690Sstevel@tonic-gate  * Note, all struct's must contain a single ref_t, all must use
700Sstevel@tonic-gate  * kmem_cache, all must use the REF_* macros for free.
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate 
730Sstevel@tonic-gate typedef struct ref_s {
740Sstevel@tonic-gate 	uint32_t	cnt;		/* Reference count */
750Sstevel@tonic-gate 	void		(*last)(void *); /* Call-back for last ref */
760Sstevel@tonic-gate 	kmem_cache_t	*kmc;		/* Container allocator cache */
770Sstevel@tonic-gate } ref_t;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	REF_INIT(container, count, inactive, kmem) {			\
800Sstevel@tonic-gate 	(container)->ref.cnt = (count);					\
810Sstevel@tonic-gate 	(container)->ref.last = (void (*)(void *))((inactive));		\
820Sstevel@tonic-gate 	(container)->ref.kmc = (kmem);					\
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
850Sstevel@tonic-gate #define	REF_HOLD(container) {						\
860Sstevel@tonic-gate 	atomic_add_32(&(container)->ref.cnt, 1);			\
870Sstevel@tonic-gate 	ASSERT((container)->ref.cnt != 0);				\
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #define	REF_RELE(container) {						\
910Sstevel@tonic-gate 	if (atomic_add_32_nv(&(container)->ref.cnt, -1) == 0) {		\
920Sstevel@tonic-gate 		(container)->ref.last((container));			\
930Sstevel@tonic-gate 		kmem_cache_free((container)->ref.kmc, (container));	\
940Sstevel@tonic-gate 	}								\
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
97*1974Sbrutus #define	REF_COUNT(container) (container)->ref.cnt
98*1974Sbrutus 
990Sstevel@tonic-gate #define	REF_ASSERT(container, count)					\
1000Sstevel@tonic-gate 	ASSERT((container)->ref.cnt == (count));
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * str_t - string type, used to access a an arbitrary span of a char[].
1040Sstevel@tonic-gate  */
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate typedef struct str_s {
1070Sstevel@tonic-gate 	char	*cp;			/* Char pointer current char */
1080Sstevel@tonic-gate 	char	*ep;			/* Char pointer past end of string */
1090Sstevel@tonic-gate } str_t;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate /*
1120Sstevel@tonic-gate  * uri_*_t - URI descriptor, used to describe a cached URI object.
1130Sstevel@tonic-gate  */
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate typedef struct uri_rd_s {
1160Sstevel@tonic-gate 	size_t		sz;		/* Size of data */
1170Sstevel@tonic-gate 	offset_t	off;		/* Offset into file or -1 for kmem */
1180Sstevel@tonic-gate 	union {				/* Response data */
1190Sstevel@tonic-gate 		char	*kmem;		/* Data in kmem */
1200Sstevel@tonic-gate 		vnode_t	*vnode;		/* Data in vnode */
1210Sstevel@tonic-gate 	} data;
1220Sstevel@tonic-gate 	struct uri_rd_s *next;		/* Next response descriptor */
1230Sstevel@tonic-gate } uri_rd_t;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate typedef struct uri_desc_s {
1260Sstevel@tonic-gate 	struct uri_desc_s *hash;	/* Hash *next */
1270Sstevel@tonic-gate 	uint64_t	hit;		/* Hit counter */
1280Sstevel@tonic-gate 	clock_t		expire;		/* URI lbolt expires on (-1 = NEVER) */
129*1974Sbrutus #ifdef notyet
130*1974Sbrutus 	void		*sslctx;	/* SSL context */
131*1974Sbrutus #endif
1320Sstevel@tonic-gate 	boolean_t	nocache;	/* URI no cache */
133*1974Sbrutus 	boolean_t	conditional;	/* Conditional response */
134*1974Sbrutus 	uint32_t	hvalue;		/* Hashed value */
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	mblk_t		*reqmp;		/* Request mblk_t */
1370Sstevel@tonic-gate 	str_t		path;		/* Path name of response  */
1380Sstevel@tonic-gate 	str_t		auth;		/* Authority for response */
1390Sstevel@tonic-gate 	ssize_t		resplen;	/* Response length */
140*1974Sbrutus 	ssize_t		respclen;	/* Response chunk length */
1410Sstevel@tonic-gate 	char		*eoh;		/* End of header pointer */
1420Sstevel@tonic-gate 	void		*scheme;	/* Scheme private state */
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	ref_t		ref;		/* Reference stuff */
1450Sstevel@tonic-gate 
146*1974Sbrutus 	size_t		count;		/* rd_t chain byte count */
1470Sstevel@tonic-gate 	uri_rd_t	*tail;		/* Last response descriptor */
1480Sstevel@tonic-gate 	uri_rd_t	response;	/* First response descriptor */
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	struct sonode	*proc;		/* Socket processing this uri */
1510Sstevel@tonic-gate 	kcondvar_t	waiting;	/* Socket(s) waiting for processing */
1520Sstevel@tonic-gate 	kmutex_t	proclock;	/* Lock for proc and waiting */
1530Sstevel@tonic-gate } uri_desc_t;
1540Sstevel@tonic-gate 
155*1974Sbrutus /* Hash the (char)c to the hash accumulator (uint32_t)hv */
156*1974Sbrutus #define	CHASH(hv, c) (hv) = ((hv) << 5) + (hv) + c; (hv) &= 0x7FFFFFFF
157*1974Sbrutus 
1580Sstevel@tonic-gate #define	URI_TEMP (uri_desc_t *)-1	/* Temp (nocache) uri_t.hash pointer */
159*1974Sbrutus 
160*1974Sbrutus #define	URI_LEN_NOVALUE -1		/* Length (int) counter no value yet */
161*1974Sbrutus #define	URI_LEN_CONSUMED -2		/* Length (int) counter consumed */
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate typedef struct uri_segmap_s {
1640Sstevel@tonic-gate 	ref_t		ref;		/* Reference, one per uri_desb_t */
1650Sstevel@tonic-gate 	caddr_t		base;		/* Base addr of segmap mapping */
1660Sstevel@tonic-gate 	size_t		len;		/* Length of segmap mapping */
1670Sstevel@tonic-gate 	vnode_t		*vp;		/* Vnode mapped */
1680Sstevel@tonic-gate } uri_segmap_t;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate typedef struct uri_desb_s {
1710Sstevel@tonic-gate 	frtn_t		frtn;		/* For use by esballoc() and freinds */
1720Sstevel@tonic-gate 	uri_desc_t	*uri;		/* Containing URI of REF_HOLD() */
1730Sstevel@tonic-gate 	uri_segmap_t	*segmap;	/* If segmap mapped else NULL */
1740Sstevel@tonic-gate } uri_desb_t;
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate /*
177*1974Sbrutus  * Add (and create if need be) a new uri_rd_t to a uri.
178*1974Sbrutus  *
179*1974Sbrutus  * Note, macro can block, must be called from a blockable context.
1800Sstevel@tonic-gate  */
181*1974Sbrutus #define	URI_RD_ADD(uri, rdp, size, offset) {				\
182*1974Sbrutus 	if ((uri)->tail == NULL) {					\
183*1974Sbrutus 		(rdp) = &(uri)->response;				\
184*1974Sbrutus 	} else {							\
185*1974Sbrutus 		(rdp) = kmem_cache_alloc(nl7c_uri_rd_kmc, KM_SLEEP);	\
186*1974Sbrutus 		(uri)->tail->next = (rdp);				\
187*1974Sbrutus 	}								\
188*1974Sbrutus 	(rdp)->sz = size;						\
189*1974Sbrutus 	(rdp)->off = offset;						\
190*1974Sbrutus 	(rdp)->next = NULL;						\
191*1974Sbrutus 	(uri)->tail = rdp;						\
192*1974Sbrutus 	(uri)->count += size;						\
193*1974Sbrutus }
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #ifdef	__cplusplus
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate #endif
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #endif	/* _SYS_SOCKFS_NL7CURI_H */
200