diff options
author | Brian Somers <brian@FreeBSD.org> | 1999-11-25 02:47:04 +0000 |
---|---|---|
committer | Brian Somers <brian@FreeBSD.org> | 1999-11-25 02:47:04 +0000 |
commit | 2cb305af778acccc5b3ee351e99990c31781efc2 (patch) | |
tree | 0f7ff229e524fe81857e437fb070e225ebbcad0d /usr.sbin/ppp/physical.c | |
parent | 869f459c00ad3844da9a6b47a69cf4c388df1fb8 (diff) | |
download | src-2cb305af778acccc5b3ee351e99990c31781efc2.tar.gz src-2cb305af778acccc5b3ee351e99990c31781efc2.zip |
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
Notes
Notes:
svn path=/head/; revision=53684
Diffstat (limited to 'usr.sbin/ppp/physical.c')
-rw-r--r-- | usr.sbin/ppp/physical.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index 97124e0dd447..f8915c9fa53e 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -634,7 +634,7 @@ physical_MaxDeviceSize() int physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov, - int *auxfd, int *nauxfd, pid_t newpid) + int *auxfd, int *nauxfd) { struct device *h; int sz; @@ -650,8 +650,7 @@ physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov, timer_Stop(&p->link.lcp.fsm.StoppedTimer); timer_Stop(&p->link.ccp.fsm.StoppedTimer); if (p->handler) { - if (p->handler->device2iov) - h = p->handler; + h = p->handler; p->handler = (struct device *)(long)p->handler->type; } @@ -661,7 +660,6 @@ physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov, else p->session_owner = (pid_t)-1; timer_Stop(&p->link.throughput.Timer); - physical_ChangedPid(p, newpid); } if (*niov + 2 >= maxiov) { @@ -672,28 +670,27 @@ physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov, return -1; } - iov[*niov].iov_base = p ? (void *)p : malloc(sizeof *p); + iov[*niov].iov_base = (void *)p; iov[*niov].iov_len = sizeof *p; (*niov)++; - iov[*niov].iov_base = p ? (void *)p->link.throughput.SampleOctets : - malloc(SAMPLE_PERIOD * sizeof(long long)); + iov[*niov].iov_base = p ? (void *)p->link.throughput.SampleOctets : NULL; iov[*niov].iov_len = SAMPLE_PERIOD * sizeof(long long); (*niov)++; sz = physical_MaxDeviceSize(); if (p) { - if (h) - (*h->device2iov)(h, iov, niov, maxiov, auxfd, nauxfd, newpid); + if (h && h->device2iov) + (*h->device2iov)(h, iov, niov, maxiov, auxfd, nauxfd); else { iov[*niov].iov_base = malloc(sz); - if (p->handler) - memcpy(iov[*niov].iov_base, p->handler, sizeof *p->handler); + if (h) + memcpy(iov[*niov].iov_base, h, sizeof *h); iov[*niov].iov_len = sz; (*niov)++; } } else { - iov[*niov].iov_base = malloc(sz); + iov[*niov].iov_base = NULL; iov[*niov].iov_len = sz; (*niov)++; } @@ -701,10 +698,19 @@ physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov, return p ? p->fd : 0; } +const char * +physical_LockedDevice(struct physical *p) +{ + if (p->fd >= 0 && *p->name.full == '/' && p->type != PHYS_DIRECT) + return p->name.base; + + return NULL; +} + void physical_ChangedPid(struct physical *p, pid_t newpid) { - if (p->fd >= 0 && *p->name.full == '/' && p->type != PHYS_DIRECT) { + if (physical_LockedDevice(p)) { int res; if ((res = ID0uu_lock_txfr(p->name.base, newpid)) != UU_LOCK_OK) |