diff options
author | brian <brian@FreeBSD.org> | 2002-06-29 18:49:08 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2002-06-29 18:49:08 +0000 |
commit | 8368fc422d3830634915c3d760fe4fa0100a6c86 (patch) | |
tree | 60a441bf5be156858234fd884cc77890071f6f71 /usr.sbin/ppp | |
parent | 7d5cddbc112c867456619610ba2f918250bbf10d (diff) | |
download | FreeBSD-src-8368fc422d3830634915c3d760fe4fa0100a6c86.zip FreeBSD-src-8368fc422d3830634915c3d760fe4fa0100a6c86.tar.gz |
When a netgraph message is read, look for another before returning.
This removes a bad latency problem during initial setup where we
end up waiting for too long before reading the connected message
and time the connection out.
Problem figured out by: Andre Albsmeier <andre@albsmeier.net>
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r-- | usr.sbin/ppp/ether.c | 129 |
1 files changed, 66 insertions, 63 deletions
diff --git a/usr.sbin/ppp/ether.c b/usr.sbin/ppp/ether.c index 0621216..77ad7e5 100644 --- a/usr.sbin/ppp/ether.c +++ b/usr.sbin/ppp/ether.c @@ -230,78 +230,81 @@ ether_MessageIn(struct etherdevice *dev) log_Printf(LogERROR, "DoLoop: Cannot create fd_set\n"); return; } - zerofdset(r); - FD_SET(dev->cs, r); - t.tv_sec = t.tv_usec = 0; - ret = select(dev->cs + 1, r, NULL, NULL, &t); - free(r); - - if (ret <= 0) - return; - if (NgRecvMsg(dev->cs, rep, sizeof msgbuf, NULL) <= 0) - return; - - if (rep->header.version != NG_VERSION) { - log_Printf(LogWARN, "%ld: Unexpected netgraph version, expected %ld\n", - (long)rep->header.version, (long)NG_VERSION); - return; - } + while (1) { + zerofdset(r); + FD_SET(dev->cs, r); + t.tv_sec = t.tv_usec = 0; + ret = select(dev->cs + 1, r, NULL, NULL, &t); - if (rep->header.typecookie != NGM_PPPOE_COOKIE) { - log_Printf(LogWARN, "%ld: Unexpected netgraph cookie, expected %ld\n", - (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE); - return; - } + if (ret <= 0) + break; - asciilen = 0; - switch (rep->header.cmd) { - case NGM_PPPOE_SET_FLAG: msg = "SET_FLAG"; break; - case NGM_PPPOE_CONNECT: msg = "CONNECT"; break; - case NGM_PPPOE_LISTEN: msg = "LISTEN"; break; - case NGM_PPPOE_OFFER: msg = "OFFER"; break; - case NGM_PPPOE_SUCCESS: msg = "SUCCESS"; break; - case NGM_PPPOE_FAIL: msg = "FAIL"; break; - case NGM_PPPOE_CLOSE: msg = "CLOSE"; break; - case NGM_PPPOE_GET_STATUS: msg = "GET_STATUS"; break; - case NGM_PPPOE_ACNAME: - msg = "ACNAME"; - if (setenv("ACNAME", sts->hook, 1) != 0) - log_Printf(LogWARN, "setenv: cannot set ACNAME=%s: %m", sts->hook); - asciilen = rep->header.arglen; + if (NgRecvMsg(dev->cs, rep, sizeof msgbuf, NULL) <= 0) break; - case NGM_PPPOE_SESSIONID: - msg = "SESSIONID"; - snprintf(sessionid, sizeof sessionid, "%04x", *(u_int16_t *)sts); - if (setenv("SESSIONID", sessionid, 1) != 0) - syslog(LOG_WARNING, "setenv: cannot set SESSIONID=%s: %m", - sessionid); - /* Use this in preference to our interface index */ - slot = strtoul(sessionid, &end, 16); - if (end != sessionid && *end == '\0') - dev->slot = slot; + + if (rep->header.version != NG_VERSION) { + log_Printf(LogWARN, "%ld: Unexpected netgraph version, expected %ld\n", + (long)rep->header.version, (long)NG_VERSION); break; - default: - snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd); - msg = unknown; + } + + if (rep->header.typecookie != NGM_PPPOE_COOKIE) { + log_Printf(LogWARN, "%ld: Unexpected netgraph cookie, expected %ld\n", + (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE); break; - } + } - if (asciilen) - log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%.*s\")\n", - msg, asciilen, sts->hook); - else - log_Printf(LogPHASE, "Received NGM_PPPOE_%s\n", msg); + asciilen = 0; + switch (rep->header.cmd) { + case NGM_PPPOE_SET_FLAG: msg = "SET_FLAG"; break; + case NGM_PPPOE_CONNECT: msg = "CONNECT"; break; + case NGM_PPPOE_LISTEN: msg = "LISTEN"; break; + case NGM_PPPOE_OFFER: msg = "OFFER"; break; + case NGM_PPPOE_SUCCESS: msg = "SUCCESS"; break; + case NGM_PPPOE_FAIL: msg = "FAIL"; break; + case NGM_PPPOE_CLOSE: msg = "CLOSE"; break; + case NGM_PPPOE_GET_STATUS: msg = "GET_STATUS"; break; + case NGM_PPPOE_ACNAME: + msg = "ACNAME"; + if (setenv("ACNAME", sts->hook, 1) != 0) + log_Printf(LogWARN, "setenv: cannot set ACNAME=%s: %m", sts->hook); + asciilen = rep->header.arglen; + break; + case NGM_PPPOE_SESSIONID: + msg = "SESSIONID"; + snprintf(sessionid, sizeof sessionid, "%04x", *(u_int16_t *)sts); + if (setenv("SESSIONID", sessionid, 1) != 0) + syslog(LOG_WARNING, "setenv: cannot set SESSIONID=%s: %m", + sessionid); + /* Use this in preference to our interface index */ + slot = strtoul(sessionid, &end, 16); + if (end != sessionid && *end == '\0') + dev->slot = slot; + break; + default: + snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd); + msg = unknown; + break; + } - switch (rep->header.cmd) { - case NGM_PPPOE_SUCCESS: - dev->connected = CARRIER_OK; - break; - case NGM_PPPOE_FAIL: - case NGM_PPPOE_CLOSE: - dev->connected = CARRIER_LOST; - break; + if (asciilen) + log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%.*s\")\n", + msg, asciilen, sts->hook); + else + log_Printf(LogPHASE, "Received NGM_PPPOE_%s\n", msg); + + switch (rep->header.cmd) { + case NGM_PPPOE_SUCCESS: + dev->connected = CARRIER_OK; + break; + case NGM_PPPOE_FAIL: + case NGM_PPPOE_CLOSE: + dev->connected = CARRIER_LOST; + break; + } } + free(r); } static int |