ksocket.h revision 0f1702c5201310f0529cd5abb77652e5e9b241b6
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER START
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The contents of this file are subject to the terms of the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Common Development and Distribution License (the "License").
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You may not use this file except in compliance with the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * or http://www.opensolaris.org/os/licensing.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * See the License for the specific language governing permissions
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and limitations under the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * When distributing Covered Code, include this CDDL HEADER in each
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If applicable, add the following below this CDDL HEADER, with the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * fields enclosed by brackets "[]" replaced with your own identifying
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * information: Portions Copyright [yyyy] [name of copyright owner]
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER END
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Use is subject to license terms.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#ifndef _SYS_KSOCKET_H_
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define _SYS_KSOCKET_H_
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#ifdef __cplusplus
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern "C" {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#endif
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/* Opaque kernel socket type */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningtypedef struct __ksocket *ksocket_t;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningstruct nmsghdr;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/* flag bit for each Callback Event */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_CONNECTED 0x00000001
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_CONNECTFAILED 0x00000002
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_DISCONNECTED 0x00000004
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_NEWDATA 0x00000008
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_NEWCONN 0x00000010
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_CANSEND 0x00000020
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_OOBDATA 0x00000040
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_CANTSENDMORE 0x00000080
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_CANTRECVMORE 0x00000100
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_CB_ERROR 0x00000200
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Kernel Socket Callback Events
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningtypedef enum ksocket_event {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_CONNECTED,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_CONNECTFAILED,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_DISCONNECTED,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_OOBDATA,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_NEWDATA,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_NEWCONN,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_CANSEND,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_CANTSENDMORE,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_CANTRECVMORE,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_EV_ERROR
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning} ksocket_callback_event_t;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningtypedef void (*ksocket_callback_t)(ksocket_t, ksocket_callback_event_t,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning void *, uintptr_t);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningtypedef struct ksocket_callbacks {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uint32_t ksock_cb_flags;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_connected;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_connectfailed;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_disconnected;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_newdata;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_newconn;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_cansend;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_oobdata;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_cantsendmore;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_cantrecvmore;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_callback_t ksock_cb_error;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning} ksocket_callbacks_t;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_SLEEP SOCKET_SLEEP
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define KSOCKET_NOSLEEP SOCKET_NOSLEEP
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_socket(ksocket_t *, int, int, int, int, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_bind(ksocket_t, struct sockaddr *, socklen_t,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_listen(ksocket_t, int, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_accept(ksocket_t, struct sockaddr *, socklen_t *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_t *, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_connect(ksocket_t, const struct sockaddr *, socklen_t,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_send(ksocket_t, void *, size_t, int, size_t *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_sendto(ksocket_t, void *, size_t, int,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockaddr *, socklen_t, size_t *, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_sendmsg(ksocket_t, struct nmsghdr *, int, size_t *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_sendmblk(ksocket_t, struct nmsghdr *, int, mblk_t **,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_recv(ksocket_t, void *, size_t, int, size_t *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_recvfrom(ksocket_t, void *, size_t, int,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockaddr *, socklen_t *, size_t *, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_recvmsg(ksocket_t, struct nmsghdr *, int, size_t *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_shutdown(ksocket_t, int, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_setsockopt(ksocket_t, int, int, const void *, int,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_getsockopt(ksocket_t, int, int, void *, int *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_getpeername(ksocket_t, struct sockaddr *, socklen_t *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_getsockname(ksocket_t, struct sockaddr *, socklen_t *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_ioctl(ksocket_t, int, intptr_t, int *, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_setcallbacks(ksocket_t, ksocket_callbacks_t *, void *,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int ksocket_close(ksocket_t, struct cred *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern void ksocket_hold(ksocket_t);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern void ksocket_rele(ksocket_t);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#ifdef __cplusplus
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#endif
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#endif /* _SYS_KSOCKET_H_ */