diff options
author | Toomas Soome <tsoome@me.com> | 2018-08-02 16:35:20 -0700 |
---|---|---|
committer | Joshua M. Clulow <josh@sysmgr.org> | 2018-08-02 16:35:20 -0700 |
commit | e78c3bfbbe4bd8f590eca05ea278a4de7172fd2e (patch) | |
tree | 83b1f25846d1b79c390387c50488f4db581077eb | |
parent | 06307114472bd8aad5ff18ccdb8e25f128ae6652 (diff) | |
download | illumos-joyent-e78c3bfbbe4bd8f590eca05ea278a4de7172fd2e.tar.gz |
9650 libstand: Add MAXWAIT to net for establishing max total timeout
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
Reviewed by: Jason King <jason.brian.king+illumos@gmail.com>
Reviewed by: Gergő Mihály Doma <domag02@gmail.com>
Approved by: Joshua M. Clulow <josh@sysmgr.org>
-rw-r--r-- | usr/src/boot/lib/libstand/net.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/usr/src/boot/lib/libstand/net.c b/usr/src/boot/lib/libstand/net.c index d8d46c4ec4..7d775faf17 100644 --- a/usr/src/boot/lib/libstand/net.c +++ b/usr/src/boot/lib/libstand/net.c @@ -57,6 +57,20 @@ #include "net.h" /* + * Maximum wait time for sending and receiving before we give up and timeout. + * If set to 0, operations will eventually timeout completely, but send/recv + * timeouts must progress exponentially from MINTMO to MAXTMO before final + * timeout is hit. + */ +#ifndef MAXWAIT +#define MAXWAIT 0 /* seconds */ +#endif + +#if MAXWAIT < 0 +#error MAXWAIT must not be a negative number +#endif + +/* * Send a packet and wait for a reply, with exponential backoff. * * The send routine must return the actual number of bytes written, @@ -76,6 +90,7 @@ sendrecv(struct iodesc *d, { ssize_t cc; time_t t, tmo, tlast; + time_t tref; long tleft; #ifdef NET_DEBUG @@ -86,12 +101,17 @@ sendrecv(struct iodesc *d, tmo = MINTMO; tlast = 0; tleft = 0; + tref = getsecs(); t = getsecs(); for (;;) { + if (MAXWAIT > 0 && (getsecs() - tref) >= MAXWAIT) { + errno = ETIMEDOUT; + return (-1); + } if (tleft <= 0) { if (tmo >= MAXTMO) { errno = ETIMEDOUT; - return -1; + return (-1); } cc = (*sproc)(d, sbuf, ssize); if (cc != -1 && cc < ssize) @@ -134,11 +154,11 @@ sendrecv(struct iodesc *d, n_long inet_addr(char *cp) { - u_long val; + unsigned long val; int n; char c; - u_int parts[4]; - u_int *pp = parts; + unsigned int parts[4]; + unsigned int *pp = parts; for (;;) { /* @@ -204,7 +224,7 @@ inet_addr(char *cp) } return (htonl(val)); - bad: +bad: return (htonl(INADDR_NONE)); } @@ -219,12 +239,12 @@ char * intoa(n_long addr) { char *cp; - u_int byte; + unsigned int byte; int n; static char buf[17]; /* strlen(".255.255.255.255") + 1 */ addr = ntohl(addr); - cp = &buf[sizeof buf]; + cp = &buf[sizeof (buf)]; *--cp = '\0'; n = 4; @@ -250,33 +270,33 @@ number(char *s, int *n) { for (*n = 0; isdigit(*s); s++) *n = (*n * 10) + *s - '0'; - return s; + return (s); } n_long ip_convertaddr(char *p) { -#define IP_ANYADDR 0 +#define IP_ANYADDR 0 n_long addr = 0, n; - if (p == (char *)0 || *p == '\0') - return IP_ANYADDR; + if (p == NULL || *p == '\0') + return (IP_ANYADDR); p = number(p, &n); addr |= (n << 24) & 0xff000000; if (*p == '\0' || *p++ != '.') - return IP_ANYADDR; + return (IP_ANYADDR); p = number(p, &n); addr |= (n << 16) & 0xff0000; if (*p == '\0' || *p++ != '.') - return IP_ANYADDR; + return (IP_ANYADDR); p = number(p, &n); addr |= (n << 8) & 0xff00; if (*p == '\0' || *p++ != '.') - return IP_ANYADDR; + return (IP_ANYADDR); p = number(p, &n); addr |= n & 0xff; if (*p != '\0') - return IP_ANYADDR; + return (IP_ANYADDR); - return htonl(addr); + return (htonl(addr)); } |