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