Skip to content

Commit

Permalink
9650 libstand: Add MAXWAIT to net for establishing max total timeout
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tsoome authored and jclulow committed Aug 2, 2018
1 parent 0630711 commit e78c3bf
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions usr/src/boot/lib/libstand/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@
#include "stand.h"
#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.
*
Expand All @@ -76,6 +90,7 @@ sendrecv(struct iodesc *d,
{
ssize_t cc;
time_t t, tmo, tlast;
time_t tref;
long tleft;

#ifdef NET_DEBUG
Expand All @@ -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)
Expand Down Expand Up @@ -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 (;;) {
/*
Expand Down Expand Up @@ -204,7 +224,7 @@ inet_addr(char *cp)
}

return (htonl(val));
bad:
bad:
return (htonl(INADDR_NONE));
}

Expand All @@ -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;
Expand All @@ -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));
}

0 comments on commit e78c3bf

Please sign in to comment.