summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authordwmalone <dwmalone@FreeBSD.org>2001-10-04 13:11:48 +0000
committerdwmalone <dwmalone@FreeBSD.org>2001-10-04 13:11:48 +0000
commit86cf053ae0113e103de743ed432880fb2b462149 (patch)
tree6615cc44c88feefec804ce8ebb7cd6284b4483b6 /usr.sbin
parenta41aa2f6cfba0d70cf320783974b86c4bb644eda (diff)
downloadFreeBSD-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 'usr.sbin')
-rw-r--r--usr.sbin/mount_portalfs/activate.c8
-rw-r--r--usr.sbin/ppp/bundle.c10
2 files changed, 9 insertions, 9 deletions
diff --git a/usr.sbin/mount_portalfs/activate.c b/usr.sbin/mount_portalfs/activate.c
index 5646498..6143620 100644
--- a/usr.sbin/mount_portalfs/activate.c
+++ b/usr.sbin/mount_portalfs/activate.c
@@ -113,9 +113,9 @@ int error;
int n;
struct iovec iov;
struct msghdr msg;
- struct {
+ union {
struct cmsghdr cmsg;
- int fd;
+ char control[CMSG_SPACE(sizeof(int))];
} ctl;
/*
@@ -137,10 +137,10 @@ int error;
* construct a suitable rights control message.
*/
if (fd >= 0) {
- ctl.fd = fd;
- ctl.cmsg.cmsg_len = sizeof(ctl);
+ ctl.cmsg.cmsg_len = CMSG_LEN(sizeof(int));
ctl.cmsg.cmsg_level = SOL_SOCKET;
ctl.cmsg.cmsg_type = SCM_RIGHTS;
+ *((int *)CMSG_DATA(&ctl.cmsg)) = fd;
msg.msg_control = (caddr_t) &ctl;
msg.msg_controllen = ctl.cmsg.cmsg_len;
}
diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c
index 6b76231..908a9a6 100644
--- a/usr.sbin/ppp/bundle.c
+++ b/usr.sbin/ppp/bundle.c
@@ -1364,8 +1364,8 @@ bundle_ReceiveDatalink(struct bundle *bundle, int s)
return;
}
- fd = (int *)(cmsg + 1);
- nfd = (cmsg->cmsg_len - sizeof *cmsg) / sizeof(int);
+ fd = (int *)CMSG_DATA(cmsg);
+ nfd = ((caddr_t)cmsg + cmsg->cmsg_len - (caddr_t)fd) / sizeof(int);
if (nfd < 2) {
log_Printf(LogERROR, "Recvmsg: %d descriptor%s received (too few) !\n",
@@ -1457,7 +1457,7 @@ bundle_ReceiveDatalink(struct bundle *bundle, int s)
void
bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
{
- char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int) * SEND_MAXFD];
+ char cmsgbuf[CMSG_SPACE(sizeof(int) * SEND_MAXFD)];
const char *constlock;
char *lock;
struct cmsghdr *cmsg;
@@ -1507,7 +1507,7 @@ bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
msg.msg_iovlen = 1;
msg.msg_iov = iov;
msg.msg_control = cmsgbuf;
- msg.msg_controllen = sizeof *cmsg + sizeof(int) * nfd;
+ msg.msg_controllen = CMSG_SPACE(sizeof(int) * nfd);
msg.msg_flags = 0;
cmsg = (struct cmsghdr *)cmsgbuf;
@@ -1516,7 +1516,7 @@ bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
cmsg->cmsg_type = SCM_RIGHTS;
for (f = 0; f < nfd; f++)
- *((int *)(cmsg + 1) + f) = fd[f];
+ *((int *)CMSG_DATA(cmsg) + f) = fd[f];
for (f = 1, expect = 0; f < niov; f++)
expect += iov[f].iov_len;
OpenPOWER on IntegriCloud