2013-10-04 16:29:40 +02:00
|
|
|
#ifndef __UDS_UDS_H
|
|
|
|
#define __UDS_UDS_H
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-10-04 16:29:40 +02:00
|
|
|
#include <minix/drivers.h>
|
|
|
|
#include <minix/chardriver.h>
|
|
|
|
#undef send
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
2010-08-30 15:46:44 +02:00
|
|
|
#include <sys/ucred.h>
|
2010-07-15 15:39:57 +02:00
|
|
|
#include <sys/un.h>
|
2013-10-04 16:29:40 +02:00
|
|
|
#include <sys/mman.h>
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-10-04 16:29:40 +02:00
|
|
|
/* Maximum number of UNIX domain sockets. */
|
|
|
|
#define NR_FDS 256
|
|
|
|
|
|
|
|
/* Connection backlog size for incoming connections. */
|
|
|
|
#define UDS_SOMAXCONN 64
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-10-04 16:46:18 +02:00
|
|
|
/* Maximum UDS socket buffer size. */
|
|
|
|
#define UDS_BUF PIPE_BUF
|
|
|
|
|
2013-10-04 16:29:40 +02:00
|
|
|
/* Output debugging information? */
|
|
|
|
#define DEBUG 0
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-10-04 16:46:18 +02:00
|
|
|
#if DEBUG
|
|
|
|
#define dprintf(x) printf x
|
|
|
|
#else
|
|
|
|
#define dprintf(x)
|
|
|
|
#endif
|
|
|
|
|
2010-08-30 15:46:44 +02:00
|
|
|
/* ancillary data to be sent */
|
|
|
|
struct ancillary {
|
|
|
|
int fds[OPEN_MAX];
|
|
|
|
int nfiledes;
|
2013-04-18 11:07:44 +02:00
|
|
|
struct uucred cred;
|
2010-08-30 15:46:44 +02:00
|
|
|
};
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-10-04 16:46:18 +02:00
|
|
|
#define UDS_R 0x1
|
|
|
|
#define UDS_W 0x2
|
|
|
|
|
2010-07-15 15:39:57 +02:00
|
|
|
/*
|
|
|
|
* Internal State Information for a socket descriptor.
|
|
|
|
*/
|
|
|
|
struct uds_fd {
|
|
|
|
|
|
|
|
/* Flags */
|
|
|
|
|
|
|
|
enum UDS_STATE {
|
|
|
|
/* This file descriptor is UDS_FREE and can be allocated. */
|
|
|
|
UDS_FREE = 0,
|
|
|
|
|
|
|
|
/* OR it is UDS_INUSE and can't be allocated. */
|
|
|
|
UDS_INUSE = 1
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* state is set to UDS_INUSE in uds_open(). state is Set to
|
|
|
|
* UDS_FREE in uds_init() and uds_close(). state should be
|
2010-07-15 15:39:57 +02:00
|
|
|
* checked prior to all operations.
|
|
|
|
*/
|
|
|
|
} state;
|
|
|
|
|
|
|
|
/* Owner Info */
|
|
|
|
|
|
|
|
/* Socket Owner */
|
|
|
|
endpoint_t owner;
|
|
|
|
|
|
|
|
/* Pipe Housekeeping */
|
|
|
|
|
2013-10-04 16:29:40 +02:00
|
|
|
char *buf; /* ring buffer */
|
|
|
|
size_t pos; /* tail position into ring buffer */
|
|
|
|
size_t size; /* size of used part of ring buffer */
|
2010-07-15 15:39:57 +02:00
|
|
|
|
|
|
|
/* control read/write, set by uds_open() and shutdown(2).
|
2013-10-04 16:46:18 +02:00
|
|
|
* Can be set to UDS_R|UDS_W, UDS_R, UDS_W, or 0
|
2010-07-15 15:39:57 +02:00
|
|
|
* for read and write, read only, write only, or neither.
|
2013-10-04 16:46:18 +02:00
|
|
|
* default is UDS_R|UDS_W.
|
2010-07-15 15:39:57 +02:00
|
|
|
*/
|
2013-10-04 16:29:40 +02:00
|
|
|
int mode;
|
2010-07-15 15:39:57 +02:00
|
|
|
|
|
|
|
/* Socket Info */
|
|
|
|
|
|
|
|
/* socket type - SOCK_STREAM, SOCK_DGRAM, or SOCK_SEQPACKET
|
|
|
|
* Set by uds_ioctl(NWIOSUDSTYPE). It defaults to -1 in
|
|
|
|
* uds_open(). Any action on a socket with type -1 besides
|
|
|
|
* uds_ioctl(NWIOSUDSTYPE) and uds_close() will result in
|
|
|
|
* an error.
|
|
|
|
*/
|
|
|
|
int type;
|
|
|
|
|
|
|
|
/* queue of pending connections for server sockets.
|
|
|
|
* connect(2) inserts and accept(2) removes from the queue
|
|
|
|
*/
|
|
|
|
int backlog[UDS_SOMAXCONN];
|
|
|
|
|
|
|
|
/* requested connection backlog size. Set by listen(2)
|
|
|
|
* Bounds (0 <= backlog_size <= UDS_SOMAXCONN)
|
|
|
|
* Defaults to UDS_SOMAXCONN which is defined above.
|
|
|
|
*/
|
|
|
|
unsigned char backlog_size;
|
|
|
|
|
|
|
|
/* index of peer in uds_fd_table for connected sockets.
|
2012-02-13 16:28:04 +01:00
|
|
|
* -1 is used to mean no peer. Assumptions: peer != -1 means
|
2010-07-15 15:39:57 +02:00
|
|
|
* connected.
|
|
|
|
*/
|
|
|
|
int peer;
|
|
|
|
|
|
|
|
/* index of child (client sd returned by accept(2))
|
|
|
|
* -1 is used to mean no child.
|
|
|
|
*/
|
|
|
|
int child;
|
|
|
|
|
|
|
|
/* address -- the address the socket is bound to.
|
|
|
|
* Assumptions: addr.sun_family == AF_UNIX means its bound.
|
|
|
|
*/
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
|
|
|
|
/* target -- where DGRAMs are sent to on the next uds_write(). */
|
|
|
|
struct sockaddr_un target;
|
|
|
|
|
|
|
|
/* source -- address where DGRAMs are from. used to fill in the
|
|
|
|
* from address in recvfrom(2) and recvmsg(2).
|
|
|
|
*/
|
|
|
|
struct sockaddr_un source;
|
|
|
|
|
|
|
|
/* Flag (1 or 0) - listening for incoming connections.
|
|
|
|
* Default to 0. Set to 1 by do_listen()
|
|
|
|
*/
|
|
|
|
int listening;
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* stores file pointers and credentials being sent between
|
2010-08-30 15:46:44 +02:00
|
|
|
* processes with sendmsg(2) and recvmsg(2).
|
|
|
|
*/
|
|
|
|
struct ancillary ancillary_data;
|
|
|
|
|
2010-07-15 15:39:57 +02:00
|
|
|
/* Holds an errno. This is set when a connected socket is
|
|
|
|
* closed and we need to pass ECONNRESET on to a suspended
|
|
|
|
* peer.
|
|
|
|
*/
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Suspend/Revive Housekeeping */
|
|
|
|
|
|
|
|
/* SUSPEND State Flags */
|
|
|
|
enum UDS_SUSPENDED {
|
|
|
|
|
|
|
|
/* Socket isn't blocked. */
|
|
|
|
UDS_NOT_SUSPENDED = 0,
|
|
|
|
|
|
|
|
/* Socket is blocked on read(2) waiting for data to read. */
|
|
|
|
UDS_SUSPENDED_READ = 1,
|
|
|
|
|
|
|
|
/* Socket is blocked on write(2) for space to write data. */
|
|
|
|
UDS_SUSPENDED_WRITE = 2,
|
|
|
|
|
|
|
|
/* Socket is blocked on connect(2) waiting for the server. */
|
|
|
|
UDS_SUSPENDED_CONNECT = 4,
|
|
|
|
|
|
|
|
/* Socket is blocked on accept(2) waiting for clients. */
|
|
|
|
UDS_SUSPENDED_ACCEPT = 8
|
|
|
|
} suspended;
|
|
|
|
|
2013-09-03 02:00:20 +02:00
|
|
|
/* source endpoint, saved for later use by suspended procs */
|
|
|
|
endpoint_t susp_endpt;
|
2010-07-15 15:39:57 +02:00
|
|
|
|
|
|
|
/* i/o grant, saved for later use by suspended procs */
|
2013-09-03 02:00:20 +02:00
|
|
|
cp_grant_id_t susp_grant;
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-09-03 02:00:20 +02:00
|
|
|
/* size of request, saved for later use by suspended procs */
|
|
|
|
size_t susp_size;
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-09-03 02:00:20 +02:00
|
|
|
/* request ID, saved for later use by suspended procs */
|
|
|
|
cdev_id_t susp_id;
|
2010-07-15 15:39:57 +02:00
|
|
|
|
|
|
|
/* select() */
|
|
|
|
|
2013-11-01 13:34:14 +01:00
|
|
|
/* when a select is in progress, we notify this endpoint
|
2010-07-15 15:39:57 +02:00
|
|
|
* of new data.
|
|
|
|
*/
|
2013-09-03 02:00:20 +02:00
|
|
|
endpoint_t sel_endpt;
|
2010-07-15 15:39:57 +02:00
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
/* Options (CDEV_OP_RD,WR,ERR) that are requested. */
|
2013-09-03 02:00:20 +02:00
|
|
|
unsigned int sel_ops;
|
2010-07-15 15:39:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct uds_fd uds_fd_t;
|
|
|
|
|
|
|
|
/* File Descriptor Table -- Defined in uds.c */
|
|
|
|
EXTERN uds_fd_t uds_fd_table[NR_FDS];
|
|
|
|
|
2013-10-04 16:29:40 +02:00
|
|
|
/* Function prototypes. */
|
|
|
|
|
2013-10-04 16:46:18 +02:00
|
|
|
/* ioc_uds.c */
|
2013-10-04 16:29:40 +02:00
|
|
|
int uds_clear_fds(devminor_t minor, struct ancillary *data);
|
|
|
|
int uds_do_ioctl(devminor_t minor, unsigned long request, endpoint_t endpt,
|
|
|
|
cp_grant_id_t grant);
|
|
|
|
|
2013-10-04 16:46:18 +02:00
|
|
|
/* uds.c */
|
2013-10-04 18:41:21 +02:00
|
|
|
ssize_t uds_perform_read(devminor_t minor, endpoint_t endpt,
|
|
|
|
cp_grant_id_t grant, size_t size, int pretend);
|
2013-10-04 16:46:18 +02:00
|
|
|
void uds_unsuspend(devminor_t minor);
|
|
|
|
|
2013-10-04 16:29:40 +02:00
|
|
|
#endif /* !__UDS_UDS_H */
|