xref: /titanic_50/usr/src/uts/common/fs/sockfs/nl7curi.h (revision 1a5e258f5471356ca102c7176637cdce45bac147)
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
52c9e429eSbrutus  * Common Development and Distribution License (the "License").
62c9e429eSbrutus  * 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  */
212c9e429eSbrutus 
227c478bd9Sstevel@tonic-gate /*
232c9e429eSbrutus  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_SOCKFS_NL7CURI_H
287c478bd9Sstevel@tonic-gate #define	_SYS_SOCKFS_NL7CURI_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
367c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
377c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
387c478bd9Sstevel@tonic-gate #include <sys/socket.h>
397c478bd9Sstevel@tonic-gate #include <sys/socketvar.h>
407c478bd9Sstevel@tonic-gate 
412c9e429eSbrutus #undef	PROMIF_DEBUG
422c9e429eSbrutus 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * Some usefull chararcter macros:
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #ifndef	tolower
487c478bd9Sstevel@tonic-gate #define	tolower(c) ((c) >= 'A' && (c) <= 'Z' ? (c) | 0x20 : (c))
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #ifndef	isdigit
527c478bd9Sstevel@tonic-gate #define	isdigit(c) ((c) >= '0' && (c) <= '9')
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #ifndef isalpha
567c478bd9Sstevel@tonic-gate #define	isalpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #ifndef isspace
607c478bd9Sstevel@tonic-gate #define	isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || \
617c478bd9Sstevel@tonic-gate 		(c) == '\r' || (c) == '\f' || (c) == '\013')
627c478bd9Sstevel@tonic-gate #endif
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * ref_t - reference type, ...
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * Note, all struct's must contain a single ref_t, all must use
687c478bd9Sstevel@tonic-gate  * kmem_cache, all must use the REF_* macros for free.
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate typedef struct ref_s {
727c478bd9Sstevel@tonic-gate 	uint32_t	cnt;		/* Reference count */
737c478bd9Sstevel@tonic-gate 	void		(*last)(void *); /* Call-back for last ref */
747c478bd9Sstevel@tonic-gate 	kmem_cache_t	*kmc;		/* Container allocator cache */
757c478bd9Sstevel@tonic-gate } ref_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #define	REF_INIT(container, count, inactive, kmem) {			\
787c478bd9Sstevel@tonic-gate 	(container)->ref.cnt = (count);					\
797c478bd9Sstevel@tonic-gate 	(container)->ref.last = (void (*)(void *))((inactive));		\
807c478bd9Sstevel@tonic-gate 	(container)->ref.kmc = (kmem);					\
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #define	REF_HOLD(container) {						\
84*1a5e258fSJosef 'Jeff' Sipek 	atomic_inc_32(&(container)->ref.cnt);			\
857c478bd9Sstevel@tonic-gate 	ASSERT((container)->ref.cnt != 0);				\
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	REF_RELE(container) {						\
89*1a5e258fSJosef 'Jeff' Sipek 	if (atomic_dec_32_nv(&(container)->ref.cnt) == 0) {		\
907c478bd9Sstevel@tonic-gate 		(container)->ref.last((container));			\
917c478bd9Sstevel@tonic-gate 		kmem_cache_free((container)->ref.kmc, (container));	\
927c478bd9Sstevel@tonic-gate 	}								\
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
952c9e429eSbrutus #define	REF_COUNT(container) (container)->ref.cnt
962c9e429eSbrutus 
977c478bd9Sstevel@tonic-gate #define	REF_ASSERT(container, count)					\
987c478bd9Sstevel@tonic-gate 	ASSERT((container)->ref.cnt == (count));
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * str_t - string type, used to access a an arbitrary span of a char[].
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate typedef struct str_s {
1057c478bd9Sstevel@tonic-gate 	char	*cp;			/* Char pointer current char */
1067c478bd9Sstevel@tonic-gate 	char	*ep;			/* Char pointer past end of string */
1077c478bd9Sstevel@tonic-gate } str_t;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * uri_*_t - URI descriptor, used to describe a cached URI object.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate typedef struct uri_rd_s {
1147c478bd9Sstevel@tonic-gate 	size_t		sz;		/* Size of data */
1157c478bd9Sstevel@tonic-gate 	offset_t	off;		/* Offset into file or -1 for kmem */
1167c478bd9Sstevel@tonic-gate 	union {				/* Response data */
1177c478bd9Sstevel@tonic-gate 		char	*kmem;		/* Data in kmem */
1187c478bd9Sstevel@tonic-gate 		vnode_t	*vnode;		/* Data in vnode */
1197c478bd9Sstevel@tonic-gate 	} data;
1207c478bd9Sstevel@tonic-gate 	struct uri_rd_s *next;		/* Next response descriptor */
1217c478bd9Sstevel@tonic-gate } uri_rd_t;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate typedef struct uri_desc_s {
1247c478bd9Sstevel@tonic-gate 	struct uri_desc_s *hash;	/* Hash *next */
1257c478bd9Sstevel@tonic-gate 	uint64_t	hit;		/* Hit counter */
1267c478bd9Sstevel@tonic-gate 	clock_t		expire;		/* URI lbolt expires on (-1 = NEVER) */
1272c9e429eSbrutus #ifdef notyet
1282c9e429eSbrutus 	void		*sslctx;	/* SSL context */
1292c9e429eSbrutus #endif
1307c478bd9Sstevel@tonic-gate 	boolean_t	nocache;	/* URI no cache */
1312c9e429eSbrutus 	boolean_t	conditional;	/* Conditional response */
1322c9e429eSbrutus 	uint32_t	hvalue;		/* Hashed value */
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	mblk_t		*reqmp;		/* Request mblk_t */
1357c478bd9Sstevel@tonic-gate 	str_t		path;		/* Path name of response  */
1367c478bd9Sstevel@tonic-gate 	str_t		auth;		/* Authority for response */
1377c478bd9Sstevel@tonic-gate 	ssize_t		resplen;	/* Response length */
1382c9e429eSbrutus 	ssize_t		respclen;	/* Response chunk length */
1397c478bd9Sstevel@tonic-gate 	char		*eoh;		/* End of header pointer */
1407c478bd9Sstevel@tonic-gate 	void		*scheme;	/* Scheme private state */
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	ref_t		ref;		/* Reference stuff */
1437c478bd9Sstevel@tonic-gate 
1442c9e429eSbrutus 	size_t		count;		/* rd_t chain byte count */
1457c478bd9Sstevel@tonic-gate 	uri_rd_t	*tail;		/* Last response descriptor */
1467c478bd9Sstevel@tonic-gate 	uri_rd_t	response;	/* First response descriptor */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	struct sonode	*proc;		/* Socket processing this uri */
1497c478bd9Sstevel@tonic-gate 	kcondvar_t	waiting;	/* Socket(s) waiting for processing */
1507c478bd9Sstevel@tonic-gate 	kmutex_t	proclock;	/* Lock for proc and waiting */
1517c478bd9Sstevel@tonic-gate } uri_desc_t;
1527c478bd9Sstevel@tonic-gate 
1532c9e429eSbrutus /* Hash the (char)c to the hash accumulator (uint32_t)hv */
1542c9e429eSbrutus #define	CHASH(hv, c) (hv) = ((hv) << 5) + (hv) + c; (hv) &= 0x7FFFFFFF
1552c9e429eSbrutus 
1567c478bd9Sstevel@tonic-gate #define	URI_TEMP (uri_desc_t *)-1	/* Temp (nocache) uri_t.hash pointer */
1572c9e429eSbrutus 
1582c9e429eSbrutus #define	URI_LEN_NOVALUE -1		/* Length (int) counter no value yet */
1592c9e429eSbrutus #define	URI_LEN_CONSUMED -2		/* Length (int) counter consumed */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate typedef struct uri_segmap_s {
1627c478bd9Sstevel@tonic-gate 	ref_t		ref;		/* Reference, one per uri_desb_t */
1637c478bd9Sstevel@tonic-gate 	caddr_t		base;		/* Base addr of segmap mapping */
1647c478bd9Sstevel@tonic-gate 	size_t		len;		/* Length of segmap mapping */
1657c478bd9Sstevel@tonic-gate 	vnode_t		*vp;		/* Vnode mapped */
1667c478bd9Sstevel@tonic-gate } uri_segmap_t;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate typedef struct uri_desb_s {
1697c478bd9Sstevel@tonic-gate 	frtn_t		frtn;		/* For use by esballoc() and freinds */
1707c478bd9Sstevel@tonic-gate 	uri_desc_t	*uri;		/* Containing URI of REF_HOLD() */
1717c478bd9Sstevel@tonic-gate 	uri_segmap_t	*segmap;	/* If segmap mapped else NULL */
1727c478bd9Sstevel@tonic-gate } uri_desb_t;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*
1752c9e429eSbrutus  * Add (and create if need be) a new uri_rd_t to a uri.
1762c9e429eSbrutus  *
1772c9e429eSbrutus  * Note, macro can block, must be called from a blockable context.
1787c478bd9Sstevel@tonic-gate  */
1792c9e429eSbrutus #define	URI_RD_ADD(uri, rdp, size, offset) {				\
1802c9e429eSbrutus 	if ((uri)->tail == NULL) {					\
1812c9e429eSbrutus 		(rdp) = &(uri)->response;				\
1822c9e429eSbrutus 	} else {							\
1832c9e429eSbrutus 		(rdp) = kmem_cache_alloc(nl7c_uri_rd_kmc, KM_SLEEP);	\
1842c9e429eSbrutus 		(uri)->tail->next = (rdp);				\
1852c9e429eSbrutus 	}								\
1862c9e429eSbrutus 	(rdp)->sz = size;						\
1872c9e429eSbrutus 	(rdp)->off = offset;						\
1882c9e429eSbrutus 	(rdp)->next = NULL;						\
1892c9e429eSbrutus 	(uri)->tail = rdp;						\
1902c9e429eSbrutus 	(uri)->count += size;						\
1912c9e429eSbrutus }
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate #endif
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #endif	/* _SYS_SOCKFS_NL7CURI_H */
198