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