xref: /onnv-gate/usr/src/stand/lib/sock/socket_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * Internal socket-specific definitions
27*0Sstevel@tonic-gate  */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #ifndef _SOCKET_IMPL_H
30*0Sstevel@tonic-gate #define	_SOCKET_IMPL_H
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #ifdef	__cplusplus
35*0Sstevel@tonic-gate extern "C" {
36*0Sstevel@tonic-gate #endif
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #include <sys/types.h>
39*0Sstevel@tonic-gate #include <sys/socket.h>
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate /*
42*0Sstevel@tonic-gate  * Socket support definitions
43*0Sstevel@tonic-gate  */
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #define	MAXSOCKET	(10)
46*0Sstevel@tonic-gate #define	SOCKETTYPE	(65536)
47*0Sstevel@tonic-gate #define	MEDIA_LVL	0
48*0Sstevel@tonic-gate #define	NETWORK_LVL	1
49*0Sstevel@tonic-gate #define	TRANSPORT_LVL	2
50*0Sstevel@tonic-gate #define	APP_LVL		3
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate /* Anonymous ports assigned by socket. */
53*0Sstevel@tonic-gate #define	SMALLEST_ANON_PORT	32768
54*0Sstevel@tonic-gate #define	LARGEST_ANON_PORT	((64 * 1024) - 1)
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate /* Socket state bits. */
57*0Sstevel@tonic-gate #define	SS_ISCONNECTED		0x000001 /* socket connected to a peer */
58*0Sstevel@tonic-gate #define	SS_ISCONNECTING		0x000002 /* in process of connecting to peer */
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate #define	SS_CANTRCVMORE		0x000010 /* can't receive more data from peer */
61*0Sstevel@tonic-gate #define	SS_CANTSENDMORE		0x000008 /* can't send more data to peer */
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate enum { FALSE, TRUE };
64*0Sstevel@tonic-gate enum SockType { INETBOOT_UNUSED, INETBOOT_DGRAM, INETBOOT_RAW,
65*0Sstevel@tonic-gate     INETBOOT_STREAM };
66*0Sstevel@tonic-gate enum Ports { SOURCE, DESTINATION };
67*0Sstevel@tonic-gate #define	FD_TO_SOCKET(v)	((v) - SOCKETTYPE)
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate /*
70*0Sstevel@tonic-gate  * Message block descriptor copied from usr/src/uts/common/sys/stream.h.
71*0Sstevel@tonic-gate  * We need to do that to simplify the porting of TCP code from core
72*0Sstevel@tonic-gate  * kernel to inetboot.  Note that fields which are not used by TCP
73*0Sstevel@tonic-gate  * code are removed.
74*0Sstevel@tonic-gate  */
75*0Sstevel@tonic-gate typedef struct  msgb {
76*0Sstevel@tonic-gate 	struct  msgb	*b_next;
77*0Sstevel@tonic-gate 	struct  msgb	*b_prev;
78*0Sstevel@tonic-gate 	struct  msgb	*b_cont;
79*0Sstevel@tonic-gate 	unsigned char	*b_rptr;
80*0Sstevel@tonic-gate 	unsigned char	*b_wptr;
81*0Sstevel@tonic-gate 	unsigned char	*b_datap;
82*0Sstevel@tonic-gate 	size_t		b_size;
83*0Sstevel@tonic-gate } mblk_t;
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate /* Modified stream routines to ease TCP porting. */
86*0Sstevel@tonic-gate extern mblk_t *allocb(size_t, uint_t);
87*0Sstevel@tonic-gate extern mblk_t *dupb(mblk_t *);
88*0Sstevel@tonic-gate extern void freeb(mblk_t *);
89*0Sstevel@tonic-gate extern void freemsg(mblk_t *);
90*0Sstevel@tonic-gate extern size_t msgdsize(mblk_t *);
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate /*
93*0Sstevel@tonic-gate  * "target" is needed for input prior to IP address assignment. It may
94*0Sstevel@tonic-gate  * seem redundant given the binding information contained in the socket,
95*0Sstevel@tonic-gate  * but that's only true if we have an IP address. If we don't, and we
96*0Sstevel@tonic-gate  * try DHCP, we'll try to udp checksum using INADDR_ANY as the destination
97*0Sstevel@tonic-gate  * IP address, when in fact the destination IP address was the IP address
98*0Sstevel@tonic-gate  * we were OFFERED/Assigned.
99*0Sstevel@tonic-gate  */
100*0Sstevel@tonic-gate struct inetgram {
101*0Sstevel@tonic-gate 	/* Common */
102*0Sstevel@tonic-gate 	struct sockaddr_in	igm_saddr;	/* source address info */
103*0Sstevel@tonic-gate 	int			igm_level;	/* Stack level (LVL) of data */
104*0Sstevel@tonic-gate 	mblk_t			*igm_mp;
105*0Sstevel@tonic-gate 	struct inetgram		*igm_next;	/* next inetgram in list */
106*0Sstevel@tonic-gate 	union {
107*0Sstevel@tonic-gate 		struct {
108*0Sstevel@tonic-gate 			/* Input specific */
109*0Sstevel@tonic-gate 			struct in_addr	in_t;
110*0Sstevel@tonic-gate 			uint16_t	in_i;
111*0Sstevel@tonic-gate 		} _IN_un;
112*0Sstevel@tonic-gate 		struct {
113*0Sstevel@tonic-gate 			/* Output specific */
114*0Sstevel@tonic-gate 			struct in_addr	out_r;
115*0Sstevel@tonic-gate 			int		out_f;
116*0Sstevel@tonic-gate 		} _OUT_un;
117*0Sstevel@tonic-gate 	} _i_o_inet;
118*0Sstevel@tonic-gate #define	igm_target	_i_o_inet._IN_un.in_t	/* See above comment block */
119*0Sstevel@tonic-gate #define	igm_id		_i_o_inet._IN_un.in_i	/* IP id */
120*0Sstevel@tonic-gate #define	igm_router	_i_o_inet._OUT_un.out_r	/* first router IP  ... */
121*0Sstevel@tonic-gate #define	igm_oflags	_i_o_inet._OUT_un.out_f	/* flag: 0 or MSG_DONTROUTE */
122*0Sstevel@tonic-gate };
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate struct inetboot_socket {
125*0Sstevel@tonic-gate 	enum SockType		type;		/* socket type */
126*0Sstevel@tonic-gate 	uint8_t			proto;		/* ip protocol */
127*0Sstevel@tonic-gate 	int			out_flags;	/* 0 or MSG_DONTROUTE */
128*0Sstevel@tonic-gate 	boolean_t		bound;		/* boolean */
129*0Sstevel@tonic-gate 	uint32_t		so_state;	/* Socket state */
130*0Sstevel@tonic-gate 	int			so_error;	/* Socket error */
131*0Sstevel@tonic-gate 	struct sockaddr_in	bind;		/* Binding info */
132*0Sstevel@tonic-gate 	struct sockaddr_in	remote;		/* Remote address */
133*0Sstevel@tonic-gate 	struct inetgram		*inq;		/* input queue */
134*0Sstevel@tonic-gate 	int			so_sndbuf;	/* max send buf size */
135*0Sstevel@tonic-gate 	int			so_rcvbuf;	/* max receive buf size */
136*0Sstevel@tonic-gate 	struct linger		so_linger;	/* close linger time */
137*0Sstevel@tonic-gate 	uint32_t		in_timeout;	/* Input timeout (msec) */
138*0Sstevel@tonic-gate 	uint32_t		so_opt;		/* socket level option */
139*0Sstevel@tonic-gate 	int			(*headerlen[APP_LVL])(struct inetgram *);
140*0Sstevel@tonic-gate 	int			(*input[APP_LVL])(int);
141*0Sstevel@tonic-gate 	int			(*output[APP_LVL])(int, struct inetgram *);
142*0Sstevel@tonic-gate 	int			(*close[APP_LVL])(int);
143*0Sstevel@tonic-gate 	in_port_t		(*ports)(uint16_t *, enum Ports);
144*0Sstevel@tonic-gate 	void			*pcb;		/* Protocol control block */
145*0Sstevel@tonic-gate };
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate extern struct inetboot_socket	sockets[MAXSOCKET];
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate extern void add_grams(struct inetgram **, struct inetgram *);
150*0Sstevel@tonic-gate extern void del_gram(struct inetgram **, struct inetgram *, int);
151*0Sstevel@tonic-gate extern void nuke_grams(struct inetgram **);
152*0Sstevel@tonic-gate extern struct inetgram *last_gram(struct inetgram *);
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate extern int so_check_fd(int, int *);
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate #ifdef	__cplusplus
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate #endif
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate #endif /* _SOCKET_IMPL_H */
161