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
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate *
267c478bdstevel@tonic-gate * Internal socket-specific definitions
277c478bdstevel@tonic-gate */
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate#ifndef _SOCKET_IMPL_H
307c478bdstevel@tonic-gate#define	_SOCKET_IMPL_H
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate#ifdef	__cplusplus
357c478bdstevel@tonic-gateextern "C" {
367c478bdstevel@tonic-gate#endif
377c478bdstevel@tonic-gate
387c478bdstevel@tonic-gate#include <sys/types.h>
397c478bdstevel@tonic-gate#include <sys/socket.h>
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate/*
427c478bdstevel@tonic-gate * Socket support definitions
437c478bdstevel@tonic-gate */
447c478bdstevel@tonic-gate
457c478bdstevel@tonic-gate#define	MAXSOCKET	(10)
467c478bdstevel@tonic-gate#define	SOCKETTYPE	(65536)
477c478bdstevel@tonic-gate#define	MEDIA_LVL	0
487c478bdstevel@tonic-gate#define	NETWORK_LVL	1
497c478bdstevel@tonic-gate#define	TRANSPORT_LVL	2
507c478bdstevel@tonic-gate#define	APP_LVL		3
517c478bdstevel@tonic-gate
527c478bdstevel@tonic-gate/* Anonymous ports assigned by socket. */
537c478bdstevel@tonic-gate#define	SMALLEST_ANON_PORT	32768
547c478bdstevel@tonic-gate#define	LARGEST_ANON_PORT	((64 * 1024) - 1)
557c478bdstevel@tonic-gate
567c478bdstevel@tonic-gate/* Socket state bits. */
577c478bdstevel@tonic-gate#define	SS_ISCONNECTED		0x000001 /* socket connected to a peer */
587c478bdstevel@tonic-gate#define	SS_ISCONNECTING		0x000002 /* in process of connecting to peer */
597c478bdstevel@tonic-gate
607c478bdstevel@tonic-gate#define	SS_CANTRCVMORE		0x000010 /* can't receive more data from peer */
617c478bdstevel@tonic-gate#define	SS_CANTSENDMORE		0x000008 /* can't send more data to peer */
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gateenum { FALSE, TRUE };
647c478bdstevel@tonic-gateenum SockType { INETBOOT_UNUSED, INETBOOT_DGRAM, INETBOOT_RAW,
657c478bdstevel@tonic-gate    INETBOOT_STREAM };
667c478bdstevel@tonic-gateenum Ports { SOURCE, DESTINATION };
677c478bdstevel@tonic-gate#define	FD_TO_SOCKET(v)	((v) - SOCKETTYPE)
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate/*
707c478bdstevel@tonic-gate * Message block descriptor copied from usr/src/uts/common/sys/stream.h.
717c478bdstevel@tonic-gate * We need to do that to simplify the porting of TCP code from core
727c478bdstevel@tonic-gate * kernel to inetboot.  Note that fields which are not used by TCP
737c478bdstevel@tonic-gate * code are removed.
747c478bdstevel@tonic-gate */
757c478bdstevel@tonic-gatetypedef struct  msgb {
767c478bdstevel@tonic-gate	struct  msgb	*b_next;
777c478bdstevel@tonic-gate	struct  msgb	*b_prev;
787c478bdstevel@tonic-gate	struct  msgb	*b_cont;
797c478bdstevel@tonic-gate	unsigned char	*b_rptr;
807c478bdstevel@tonic-gate	unsigned char	*b_wptr;
817c478bdstevel@tonic-gate	unsigned char	*b_datap;
827c478bdstevel@tonic-gate	size_t		b_size;
837c478bdstevel@tonic-gate} mblk_t;
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gate/* Modified stream routines to ease TCP porting. */
867c478bdstevel@tonic-gateextern mblk_t *allocb(size_t, uint_t);
877c478bdstevel@tonic-gateextern mblk_t *dupb(mblk_t *);
887c478bdstevel@tonic-gateextern void freeb(mblk_t *);
897c478bdstevel@tonic-gateextern void freemsg(mblk_t *);
907c478bdstevel@tonic-gateextern size_t msgdsize(mblk_t *);
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate/*
937c478bdstevel@tonic-gate * "target" is needed for input prior to IP address assignment. It may
947c478bdstevel@tonic-gate * seem redundant given the binding information contained in the socket,
957c478bdstevel@tonic-gate * but that's only true if we have an IP address. If we don't, and we
967c478bdstevel@tonic-gate * try DHCP, we'll try to udp checksum using INADDR_ANY as the destination
977c478bdstevel@tonic-gate * IP address, when in fact the destination IP address was the IP address
987c478bdstevel@tonic-gate * we were OFFERED/Assigned.
997c478bdstevel@tonic-gate */
1007c478bdstevel@tonic-gatestruct inetgram {
1017c478bdstevel@tonic-gate	/* Common */
1027c478bdstevel@tonic-gate	struct sockaddr_in	igm_saddr;	/* source address info */
1037c478bdstevel@tonic-gate	int			igm_level;	/* Stack level (LVL) of data */
1047c478bdstevel@tonic-gate	mblk_t			*igm_mp;
1057c478bdstevel@tonic-gate	struct inetgram		*igm_next;	/* next inetgram in list */
1067c478bdstevel@tonic-gate	union {
1077c478bdstevel@tonic-gate		struct {
1087c478bdstevel@tonic-gate			/* Input specific */
1097c478bdstevel@tonic-gate			struct in_addr	in_t;
1107c478bdstevel@tonic-gate			uint16_t	in_i;
1117c478bdstevel@tonic-gate		} _IN_un;
1127c478bdstevel@tonic-gate		struct {
1137c478bdstevel@tonic-gate			/* Output specific */
1147c478bdstevel@tonic-gate			struct in_addr	out_r;
1157c478bdstevel@tonic-gate			int		out_f;
1167c478bdstevel@tonic-gate		} _OUT_un;
1177c478bdstevel@tonic-gate	} _i_o_inet;
1187c478bdstevel@tonic-gate#define	igm_target	_i_o_inet._IN_un.in_t	/* See above comment block */
1197c478bdstevel@tonic-gate#define	igm_id		_i_o_inet._IN_un.in_i	/* IP id */
1207c478bdstevel@tonic-gate#define	igm_router	_i_o_inet._OUT_un.out_r	/* first router IP  ... */
1217c478bdstevel@tonic-gate#define	igm_oflags	_i_o_inet._OUT_un.out_f	/* flag: 0 or MSG_DONTROUTE */
1227c478bdstevel@tonic-gate};
1237c478bdstevel@tonic-gate
1247c478bdstevel@tonic-gatestruct inetboot_socket {
1257c478bdstevel@tonic-gate	enum SockType		type;		/* socket type */
1267c478bdstevel@tonic-gate	uint8_t			proto;		/* ip protocol */
1277c478bdstevel@tonic-gate	int			out_flags;	/* 0 or MSG_DONTROUTE */
1287c478bdstevel@tonic-gate	boolean_t		bound;		/* boolean */
1297c478bdstevel@tonic-gate	uint32_t		so_state;	/* Socket state */
1307c478bdstevel@tonic-gate	int			so_error;	/* Socket error */
1317c478bdstevel@tonic-gate	struct sockaddr_in	bind;		/* Binding info */
1327c478bdstevel@tonic-gate	struct sockaddr_in	remote;		/* Remote address */
1337c478bdstevel@tonic-gate	struct inetgram		*inq;		/* input queue */
1347c478bdstevel@tonic-gate	int			so_sndbuf;	/* max send buf size */
1357c478bdstevel@tonic-gate	int			so_rcvbuf;	/* max receive buf size */
1367c478bdstevel@tonic-gate	struct linger		so_linger;	/* close linger time */
1377c478bdstevel@tonic-gate	uint32_t		in_timeout;	/* Input timeout (msec) */
1387c478bdstevel@tonic-gate	uint32_t		so_opt;		/* socket level option */
1397c478bdstevel@tonic-gate	int			(*headerlen[APP_LVL])(struct inetgram *);
1407c478bdstevel@tonic-gate	int			(*input[APP_LVL])(int);
1417c478bdstevel@tonic-gate	int			(*output[APP_LVL])(int, struct inetgram *);
1427c478bdstevel@tonic-gate	int			(*close[APP_LVL])(int);
1437c478bdstevel@tonic-gate	in_port_t		(*ports)(uint16_t *, enum Ports);
1447c478bdstevel@tonic-gate	void			*pcb;		/* Protocol control block */
1457c478bdstevel@tonic-gate};
1467c478bdstevel@tonic-gate
1477c478bdstevel@tonic-gateextern struct inetboot_socket	sockets[MAXSOCKET];
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gateextern void add_grams(struct inetgram **, struct inetgram *);
1507c478bdstevel@tonic-gateextern void del_gram(struct inetgram **, struct inetgram *, int);
1517c478bdstevel@tonic-gateextern void nuke_grams(struct inetgram **);
1527c478bdstevel@tonic-gateextern struct inetgram *last_gram(struct inetgram *);
1537c478bdstevel@tonic-gate
1547c478bdstevel@tonic-gateextern int so_check_fd(int, int *);
1557c478bdstevel@tonic-gate
1567c478bdstevel@tonic-gate#ifdef	__cplusplus
1577c478bdstevel@tonic-gate}
1587c478bdstevel@tonic-gate#endif
1597c478bdstevel@tonic-gate
1607c478bdstevel@tonic-gate#endif /* _SOCKET_IMPL_H */
161