diff options
author | dwmalone <dwmalone@FreeBSD.org> | 2001-10-04 13:11:48 +0000 |
---|---|---|
committer | dwmalone <dwmalone@FreeBSD.org> | 2001-10-04 13:11:48 +0000 |
commit | 86cf053ae0113e103de743ed432880fb2b462149 (patch) | |
tree | 6615cc44c88feefec804ce8ebb7cd6284b4483b6 /lib | |
parent | a41aa2f6cfba0d70cf320783974b86c4bb644eda (diff) | |
download | FreeBSD-src-86cf053ae0113e103de743ed432880fb2b462149.zip FreeBSD-src-86cf053ae0113e103de743ed432880fb2b462149.tar.gz |
Hopefully improve control message passing over Unix domain sockets.
1) Allow the sending of more than one control message at a time
over a unix domain socket. This should cover the PR 29499.
2) This requires that unp_{ex,in}ternalize and unp_scan understand
mbufs with more than one control message at a time.
3) Internalize and externalize used to work on the mbuf in-place.
This made life quite complicated and the code for sizeof(int) <
sizeof(file *) could end up doing the wrong thing. The patch always
create a new mbuf/cluster now. This resulted in the change of the
prototype for the domain externalise function.
4) You can now send SCM_TIMESTAMP messages.
5) Always use CMSG_DATA(cm) to determine the start where the data
in unp_{ex,in}ternalize. It was using ((struct cmsghdr *)cm + 1)
in some places, which gives the wrong alignment on the alpha.
(NetBSD made this fix some time ago).
This results in an ABI change for discriptor passing and creds
passing on the alpha. (Probably on the IA64 and Spare ports too).
6) Fix userland programs to use CMSG_* macros too.
7) Be more careful about freeing mbufs containing (file *)s.
This is made possible by the prototype change of externalise.
PR: 29499
MFC after: 6 weeks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/rpc/clnt_vc.c | 16 | ||||
-rw-r--r-- | lib/libc/rpc/svc_vc.c | 23 |
2 files changed, 25 insertions, 14 deletions
diff --git a/lib/libc/rpc/clnt_vc.c b/lib/libc/rpc/clnt_vc.c index 6cdaad1..d2d0178 100644 --- a/lib/libc/rpc/clnt_vc.c +++ b/lib/libc/rpc/clnt_vc.c @@ -793,7 +793,10 @@ __msgread(sock, buf, cnt) { struct iovec iov[1]; struct msghdr msg; - struct cmessage cm; + union { + struct cmsghdr cmsg; + char control[CMSG_SPACE(sizeof(struct cmsgcred))]; + } cm; bzero((char *)&cm, sizeof(cm)); iov[0].iov_base = buf; @@ -804,7 +807,7 @@ __msgread(sock, buf, cnt) msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_control = (caddr_t)&cm; - msg.msg_controllen = sizeof(struct cmessage); + msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); msg.msg_flags = 0; return(_recvmsg(sock, &msg, 0)); @@ -818,7 +821,10 @@ __msgwrite(sock, buf, cnt) { struct iovec iov[1]; struct msghdr msg; - struct cmessage cm; + union { + struct cmsghdr cmsg; + char control[CMSG_SPACE(sizeof(struct cmsgcred))]; + } cm; bzero((char *)&cm, sizeof(cm)); iov[0].iov_base = buf; @@ -826,14 +832,14 @@ __msgwrite(sock, buf, cnt) cm.cmsg.cmsg_type = SCM_CREDS; cm.cmsg.cmsg_level = SOL_SOCKET; - cm.cmsg.cmsg_len = sizeof(struct cmessage); + cm.cmsg.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred)); msg.msg_iov = iov; msg.msg_iovlen = 1; msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_control = (caddr_t)&cm; - msg.msg_controllen = sizeof(struct cmessage); + msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); msg.msg_flags = 0; return(_sendmsg(sock, &msg, 0)); diff --git a/lib/libc/rpc/svc_vc.c b/lib/libc/rpc/svc_vc.c index 052678b..95b907a 100644 --- a/lib/libc/rpc/svc_vc.c +++ b/lib/libc/rpc/svc_vc.c @@ -400,8 +400,6 @@ read_vc(xprtp, buf, len) struct pollfd pollfd; struct sockaddr *sa; struct cmessage *cm; - struct cmsghdr *cmp; - struct sockcred *sc; xprt = (SVCXPRT *)(void *)xprtp; assert(xprt != NULL); @@ -429,9 +427,7 @@ read_vc(xprtp, buf, len) if (sa->sa_family == AF_LOCAL) { cm = (struct cmessage *)xprt->xp_verf.oa_base; if ((len = __msgread_withcred(sock, buf, len, cm)) > 0) { - cmp = &cm->cmsg; - sc = (struct sockcred *)(void *)CMSG_DATA(cmp); - xprt->xp_p2 = sc; + xprt->xp_p2 = &cm->cmcred; return (len); } } else { @@ -638,8 +634,14 @@ __msgread_withcred(sock, buf, cnt, cmp) { struct iovec iov[1]; struct msghdr msg; + union { + struct cmsghdr cmsg; + char control[CMSG_SPACE(sizeof(struct cmsgcred))]; + } cm; + int ret; + - bzero(cmp, sizeof(*cmp)); + bzero(&cm, sizeof(cm)); iov[0].iov_base = buf; iov[0].iov_len = cnt; @@ -647,11 +649,14 @@ __msgread_withcred(sock, buf, cnt, cmp) msg.msg_iovlen = 1; msg.msg_name = NULL; msg.msg_namelen = 0; - msg.msg_control = cmp; - msg.msg_controllen = sizeof(struct cmessage); + msg.msg_control = &cm; + msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); msg.msg_flags = 0; - return(_recvmsg(sock, &msg, 0)); + ret = _recvmsg(sock, &msg, 0); + bcopy(&cm.cmsg, &cmp->cmsg, sizeof(cmp->cmsg)); + bcopy(CMSG_DATA(&cm), &cmp->cmcred, sizeof(cmp->cmcred)); + return ret; } static int |