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