From 2297e266601237abaa1d9d064280de74eee3dea6 Mon Sep 17 00:00:00 2001 From: Thomas Veerman Date: Mon, 30 Aug 2010 13:41:22 +0000 Subject: [PATCH] Prepare headers to support file descriptor passing over UNIX Domain Sockets. Contributed by Thomas Cort. --- include/errno.h | 1 + include/minix/vfsif.h | 14 ++++++++++++++ include/net/ioctl.h | 37 ++++++++++++++++++++++++++----------- include/sys/socket.h | 9 +++++++++ lib/libc/ansi/errlist.c | 1 + man/man2/intro.2 | 4 +++- 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/include/errno.h b/include/errno.h index 1aef7acab..55f920eee 100644 --- a/include/errno.h +++ b/include/errno.h @@ -111,6 +111,7 @@ extern int errno; /* place where the error numbers go */ #define ENOTSUP EOPNOTSUPP /* Not supported */ #define ENETDOWN (_SIGN 77) /* network is down */ #define EPFNOSUPPORT (_SIGN 78) /* Protocol family not supported */ +#define EDESTADDRREQ (_SIGN 79) /* Destination address required */ /* The following are not POSIX errors, but they can still happen. * All of these are generated by the kernel and relate to message passing. diff --git a/include/minix/vfsif.h b/include/minix/vfsif.h index 01f3d434d..f373a9a27 100644 --- a/include/minix/vfsif.h +++ b/include/minix/vfsif.h @@ -119,5 +119,19 @@ typedef struct { #define IS_VFS_RQ(type) (((type) & ~0xff) == VFS_BASE) +#define PFS_BASE (VFS_BASE + 100) + +#define PFS_REQ_CHECK_PERMS (PFS_BASE + 1) +#define PFS_REQ_VERIFY_FD (PFS_BASE + 2) +#define PFS_REQ_SET_FILP (PFS_BASE + 3) +#define PFS_REQ_COPY_FILP (PFS_BASE + 4) +#define PFS_REQ_PUT_FILP (PFS_BASE + 5) +#define PFS_REQ_CANCEL_FD (PFS_BASE + 6) + +#define PFS_NREQS 7 + +#define IS_PFS_VFS_RQ(type) (type >= PFS_BASE && \ + type < (PFS_BASE + PFS_NREQS)) + #endif diff --git a/include/net/ioctl.h b/include/net/ioctl.h index 5c2b4980f..feba25012 100644 --- a/include/net/ioctl.h +++ b/include/net/ioctl.h @@ -9,6 +9,19 @@ #include #include +#ifndef _SOCKLEN_T +#define _SOCKLEN_T +typedef int32_t socklen_t; +#endif /* _SOCKLEN_T */ + +#define MSG_CONTROL_MAX (1024 - sizeof(socklen_t)) +struct msg_control +{ + char msg_control[MSG_CONTROL_MAX]; + socklen_t msg_controllen; +}; + + /* Network ioctls. */ #define NWIOSETHOPT _IOW('n', 16, struct nwio_ethopt) #define NWIOGETHOPT _IOR('n', 17, struct nwio_ethopt) @@ -51,17 +64,19 @@ #define NWIOGUDPOPT _IOR('n', 65, struct nwio_udpopt) #define NWIOUDPPEEK _IOR('n', 66, struct udp_io_hdr) -#define NWIOGUDSFADDR _IOR('n', 67, struct sockaddr_un) /* recvfrom() */ -#define NWIOSUDSTADDR _IOW('n', 68, struct sockaddr_un) /* sendto() */ -#define NWIOSUDSADDR _IOW('n', 69, struct sockaddr_un) /* bind() */ -#define NWIOGUDSADDR _IOR('n', 70, struct sockaddr_un) /* getsockname() */ -#define NWIOGUDSPADDR _IOR('n', 71, struct sockaddr_un) /* getpeername() */ -#define NWIOSUDSTYPE _IOW('n', 72, int) /* socket() */ -#define NWIOSUDSBLOG _IOW('n', 73, int) /* listen() */ -#define NWIOSUDSCONN _IOW('n', 74, struct sockaddr_un) /* connect() */ -#define NWIOSUDSSHUT _IOW('n', 75, int) /* shutdown() */ -#define NWIOSUDSPAIR _IOW('n', 76, dev_t) /* socketpair() */ -#define NWIOSUDSACCEPT _IOW('n', 77, struct sockaddr_un) /* accept() */ +#define NWIOGUDSFADDR _IOR ('n', 67, struct sockaddr_un) /* recvfrom() */ +#define NWIOSUDSTADDR _IOW ('n', 68, struct sockaddr_un) /* sendto() */ +#define NWIOSUDSADDR _IOW ('n', 69, struct sockaddr_un) /* bind() */ +#define NWIOGUDSADDR _IOR ('n', 70, struct sockaddr_un) /* getsockname() */ +#define NWIOGUDSPADDR _IOR ('n', 71, struct sockaddr_un) /* getpeername() */ +#define NWIOSUDSTYPE _IOW ('n', 72, int) /* socket() */ +#define NWIOSUDSBLOG _IOW ('n', 73, int) /* listen() */ +#define NWIOSUDSCONN _IOW ('n', 74, struct sockaddr_un) /* connect() */ +#define NWIOSUDSSHUT _IOW ('n', 75, int) /* shutdown() */ +#define NWIOSUDSPAIR _IOW ('n', 76, dev_t) /* socketpair() */ +#define NWIOSUDSACCEPT _IOW ('n', 77, struct sockaddr_un) /* accept() */ +#define NWIOSUDSCTRL _IOW ('n', 78, struct msg_control) /* sendmsg() */ +#define NWIOGUDSCTRL _IORW('n', 79, struct msg_control) /* recvmsg() */ #define NWIOSPSIPOPT _IOW('n', 80, struct nwio_psipopt) #define NWIOGPSIPOPT _IOR('n', 81, struct nwio_psipopt) diff --git a/include/sys/socket.h b/include/sys/socket.h index 0e2ae8f3e..e603b3aa3 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -45,7 +45,10 @@ sys/socket.h typedef uint8_t sa_family_t; #endif /* _SA_FAMILY_T */ +#ifndef _SOCKLEN_T +#define _SOCKLEN_T typedef int32_t socklen_t; +#endif /* _SOCKLEN_T */ struct sockaddr { @@ -94,6 +97,12 @@ struct cmsghdr #define CMSG_DATA(cmsg) \ ( (unsigned char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)) ) +#define CMSG_SPACE(len) \ + ( CMSG_ALIGN(len) + CMSG_ALIGN(sizeof(struct cmsghdr)) ) + +#define CMSG_LEN(len) \ + ( len + CMSG_ALIGN(sizeof(struct cmsghdr)) ) + #define SCM_RIGHTS 0x01 #define SCM_CREDENTIALS 0x02 #define SCM_SECURITY 0x04 diff --git a/lib/libc/ansi/errlist.c b/lib/libc/ansi/errlist.c index eade94954..67746eeae 100644 --- a/lib/libc/ansi/errlist.c +++ b/lib/libc/ansi/errlist.c @@ -86,6 +86,7 @@ const char *_sys_errlist[] = { "Operation not supported", /* EOPNOTSUPP */ "Network is down", /* ENETDOWN */ "Protocol family not supported", /* EPFNOSUPPORT */ + "Destination address required", /* EDESTADDRREQ */ }; const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]); diff --git a/man/man2/intro.2 b/man/man2/intro.2 index cfca39419..74556599b 100644 --- a/man/man2/intro.2 +++ b/man/man2/intro.2 @@ -365,8 +365,10 @@ for example, trying to a connection on a datagram socket. .It Er 77 ENETDOWN Em "Network is down" . A socket operation encountered a dead network. -.It Er 77 EPFNOSUPPORT Em "Protocol family not supported" . +.It Er 78 EPFNOSUPPORT Em "Protocol family not supported" . A socket operation specified an unsupported protocol family. +.It Er 79 EDESTADDRREQ Em "Destination address required" . +A required address was omitted from an operation on a socket. .El .Sh DEFINITIONS .Bl -tag -width Ds