
This new implementation of the UDS service is built on top of the libsockevent library. It thereby inherits all the advantages that libsockevent brings. However, the fundamental restructuring required for that change also paved the way for resolution of a number of other important open issues with the old UDS code. Most importantly, the rewrite brings the behavior of the service much closer to POSIX compliance and NetBSD compatibility. These are the most important changes: - due to the use of libsockevent, UDS now supports multiple suspending calls per socket and a large number of standard socket flags and options; - socket address matching is now based on <device,inode> lookups instead of canonized path names, and socket addresses are no longer altered either due to canonization or at connect time; - the socket state machine is now well defined, most importantly resolving the erroneous reset-on-EOF semantics of the old UDS, but also allowing socket reuse; - sockets are now connected before being accepted instead of being held in connecting state, unless the LOCAL_CONNWAIT option is set on either the connecting or the listening socket; - connect(2) on datagram sockets is now supported (needed by syslog), and proper datagram socket disconnect notification is provided; - the receive queue now supports segmentation, associating ancillary data (in-flight file descriptors and credentials) with each segment instead of being kept fully separately; this is a POSIX requirement (and needed by tmux); - as part of the segmentation support, the receive queue can now hold as many packets as can fit, instead of one; - in addition to the flags supported by libsockevent, the MSG_PEEK, MSG_WAITALL, MSG_CMSG_CLOEXEC, MSG_TRUNC, and MSG_CTRUNC send and receive flags are now supported; - the SO_PASSCRED and SO_PEERCRED socket options are replaced by LOCAL_CREDS and LOCAL_PEEREID respectively, now following NetBSD semantics and allowing use of NetBSD libc's getpeereid(3); - memory usage is reduced by about 250 KB due to centralized in-flight file descriptor tracking, with a limit of OPEN_MAX total rather than of OPEN_MAX per socket; - memory usage is reduced by another ~50 KB due to removal of state redundancy, despite the fact that socket path names may now be up to 253 bytes rather than the previous 104 bytes; - compared to the old UDS, there is now very little direct indexing on the static array of sockets, thus allowing dynamic allocation of sockets more easily in the future; - the UDS service now has RMIB support for the net.local sysctl tree, implementing preliminary support for NetBSD netstat(1). Change-Id: I4a9b6fe4aaeef0edf2547eee894e6c14403fcb32
125 lines
4.4 KiB
C
125 lines
4.4 KiB
C
#define DEBUG 0
|
|
|
|
/* buffer for send/recv */
|
|
#define BUFSIZE (128)
|
|
|
|
/* macro to display information about a failed test and increment the errct */
|
|
void test_fail_fl(char *msg, char *file, int line);
|
|
#define test_fail(msg) test_fail_fl(msg, __FILE__, __LINE__)
|
|
|
|
#if DEBUG == 1
|
|
/* macros to display debugging information */
|
|
void debug_fl(char *msg, char *file, int line);
|
|
#define debug(msg) debug_fl(msg, __FILE__, __LINE__)
|
|
#else
|
|
#define debug(msg)
|
|
#endif
|
|
|
|
#define SOCKET(sd,domain,type,protocol) \
|
|
do { \
|
|
errno = 0; \
|
|
sd = socket(domain, type, protocol); \
|
|
if (sd == -1) { \
|
|
test_fail("sd = socket(domain, type, protocol) failed");\
|
|
} \
|
|
} while (0)
|
|
|
|
#define UNLINK(path) \
|
|
do { \
|
|
int rc; \
|
|
errno = 0; \
|
|
rc = unlink(path); \
|
|
if (rc == -1 && errno != ENOENT) { \
|
|
test_fail("unlink(path) failed"); \
|
|
} \
|
|
} while(0)
|
|
|
|
#define SYMLINK(oldpath,newpath) \
|
|
do { \
|
|
int rc; \
|
|
errno = 0; \
|
|
rc = symlink(oldpath,newpath); \
|
|
if (rc == -1) { \
|
|
test_fail("symlink(oldpath,newpath) failed"); \
|
|
} \
|
|
} while(0)
|
|
|
|
#define CLOSE(sd) \
|
|
do { \
|
|
int rc; \
|
|
errno = 0; \
|
|
rc = close(sd); \
|
|
if (rc == -1) { \
|
|
test_fail("close(sd) failed"); \
|
|
} \
|
|
} while (0)
|
|
|
|
extern int server_ready;
|
|
void test_xfer_sighdlr(int sig);
|
|
|
|
struct socket_test_info {
|
|
const struct sockaddr *clientaddr;
|
|
socklen_t clientaddrlen;
|
|
const struct sockaddr *clientaddr2;
|
|
socklen_t clientaddr2len;
|
|
const struct sockaddr *clientaddrsym;
|
|
socklen_t clientaddrsymlen;
|
|
int domain;
|
|
int expected_rcvbuf;
|
|
int expected_sndbuf;
|
|
const struct sockaddr *serveraddr;
|
|
socklen_t serveraddrlen;
|
|
const struct sockaddr *serveraddr2;
|
|
socklen_t serveraddr2len;
|
|
int type;
|
|
const int *types;
|
|
size_t typecount;
|
|
|
|
int buf_accept_intr; /* accept can return success when interrupted */
|
|
int bug_bind_in_use; /* bind does not return EADDRINUSE */
|
|
int bug_bind_null; /* bind segfaults with NULL pointer */
|
|
int bug_connect_after_close; /* connect succeeds after server closed */
|
|
int bug_select_nonblock; /* select unexpected results for nb sockets */
|
|
int bug_shutdown; /* shutdown not supported */
|
|
int bug_shutdown_not_conn; /* shutdown does not return ENOTCONN */
|
|
int bug_shutdown_read; /* shutdown does not support SHUT_RD */
|
|
int bug_sockopt_rcvbuf; /* get/setsockopt does not support SO_RCVBUF */
|
|
int bug_sockopt_sndbuf; /* get/setsockopt does not support SO_SNDBUF */
|
|
int ignore_accept_delay; /* success from accept after aborted connect */
|
|
int ignore_connect_delay; /* nb connect not instant */
|
|
int ignore_connect_unaccepted; /* connect succeeds without accept */
|
|
int ignore_select_delay; /* select delay reflecting other side nb op */
|
|
int ignore_send_waiting; /* can send while waiting for nb recv */
|
|
int ignore_write_conn_reset; /* write does not guarantee ECONNRESET */
|
|
|
|
void (* callback_check_sockaddr)(const struct sockaddr *sockaddr,
|
|
socklen_t sockaddrlen, const char *callname, int addridx);
|
|
void (* callback_cleanup)(void);
|
|
void (* callback_xfer_peercred)(int sd); /* can be NULL */
|
|
void (* callback_xfer_prepclient)(void); /* can be NULL */
|
|
void (* callback_set_listen_opt)(int sd); /* can be NULL */
|
|
};
|
|
|
|
void test_abort_client_server(const struct socket_test_info *info,
|
|
int abort_type);
|
|
void test_bind(const struct socket_test_info *info);
|
|
void test_close(const struct socket_test_info *info);
|
|
void test_connect_close(const struct socket_test_info *info);
|
|
void test_connect_nb(const struct socket_test_info *info);
|
|
void test_dup(const struct socket_test_info *info);
|
|
void test_dup2(const struct socket_test_info *info);
|
|
void test_getsockname(const struct socket_test_info *info);
|
|
void test_intr(const struct socket_test_info *info);
|
|
void test_listen(const struct socket_test_info *info);
|
|
void test_listen_close(const struct socket_test_info *info);
|
|
void test_listen_close_nb(const struct socket_test_info *info);
|
|
void test_msg_dgram(const struct socket_test_info *info);
|
|
void test_nonblock(const struct socket_test_info *info);
|
|
void test_read(const struct socket_test_info *info);
|
|
void test_shutdown(const struct socket_test_info *info);
|
|
void test_simple_client_server(const struct socket_test_info *info, int type);
|
|
void test_sockopts(const struct socket_test_info *info);
|
|
void test_socket(const struct socket_test_info *info);
|
|
void test_write(const struct socket_test_info *info);
|
|
void test_xfer(const struct socket_test_info *info);
|