-/* $OpenBSD: bpf.c,v 1.57 2017/07/08 00:36:10 krw Exp $ */
+/* $OpenBSD: bpf.c,v 1.58 2017/07/09 19:19:58 krw Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
if (result == -1)
log_warn("send_packet");
- return (result);
+ return result ;
}
ssize_t
if (ifi->rbuf_offset >= ifi->rbuf_len) {
length = read(ifi->bfdesc, ifi->rbuf, ifi->rbuf_max);
if (length <= 0)
- return (length);
+ return length ;
ifi->rbuf_offset = 0;
ifi->rbuf_len = length;
}
memcpy(packet, ifi->rbuf + ifi->rbuf_offset, hdr.bh_caplen);
ifi->rbuf_offset = BPF_WORDALIGN(ifi->rbuf_offset +
hdr.bh_caplen);
- return (hdr.bh_caplen);
+ return hdr.bh_caplen ;
} while (!length);
- return (0);
+ return 0 ;
}
-/* $OpenBSD: conflex.c,v 1.40 2017/06/29 21:37:43 krw Exp $ */
+/* $OpenBSD: conflex.c,v 1.41 2017/07/09 19:19:58 krw Exp $ */
/* Lexical scanner for dhclient config file. */
}
} else
ugflag = 0;
- return (c);
+ return c;
}
static int
break;
}
} while (1);
- return (ttok);
+ return ttok;
}
int
if (rval)
*rval = tval;
- return (rv);
+ return rv;
}
int
if (rval)
*rval = tval;
- return (token);
+ return token;
}
static void
tokbuf[i] = '\0';
tval = tokbuf;
- return (TOK_STRING);
+ return TOK_STRING;
}
static int
if (rv == TOK_NUMBER_OR_NAME && xdigits != i)
rv = TOK_NAME;
- return (rv);
+ return rv;
}
static const struct keywords {
int
kw_cmp(const void *k, const void *e)
{
- return (strcasecmp(k, ((const struct keywords *)e)->k_name));
+ return strcasecmp(k, ((const struct keywords *)e)->k_name);
}
static int
p = bsearch(atom, keywords, sizeof(keywords)/sizeof(keywords[0]),
sizeof(keywords[0]), kw_cmp);
if (p)
- return (p->k_val);
- return (dfv);
+ return p->k_val;
+ return dfv;
}
-/* $OpenBSD: dhclient.c,v 1.462 2017/07/09 12:38:47 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.463 2017/07/09 19:19:58 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
ADVANCE(cp, sa);
}
}
- return (-1);
+ return -1;
}
struct sockaddr *
unsigned int i;
if (n == 0)
- return (NULL);
+ return NULL;
for (i = 1; i; i <<= 1)
if (i & n) {
sa = (struct sockaddr *)cp;
if (i == RTA_IFA)
- return (sa);
+ return sa;
ADVANCE(cp, sa);
}
- return (NULL);
+ return NULL;
}
void
dispatch(ifi, routefd);
/* not reached */
- return (0);
+ return 0;
}
void
if (getifaddrs(&ifap) != 0) {
log_warn("addressinuse: getifaddrs");
- return (0);
+ return 0;
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
}
freeifaddrs(ifap);
- return (used);
+ return used;
}
/*
buf = pretty_print_string(ifname, strlen(ifname), 1);
if (buf == NULL)
- return (NULL);
+ return NULL;
append_statement(string, sizeof(string), " interface ", buf);
append_statement(string, sizeof(string), " fixed-address ",
buf = pretty_print_string(lease->filename,
strlen(lease->filename), 1);
if (buf == NULL)
- return (NULL);
+ return NULL;
append_statement(string, sizeof(string), " filename ", buf);
}
if (lease->server_name) {
buf = pretty_print_string(lease->server_name,
strlen(lease->server_name), 1);
if (buf == NULL)
- return (NULL);
+ return NULL;
append_statement(string, sizeof(string), " server-name ",
buf);
}
if (lease->ssid_len != 0) {
buf = pretty_print_string(lease->ssid, lease->ssid_len, 1);
if (buf == NULL)
- return (NULL);
+ return NULL;
append_statement(string, sizeof(string), " ssid ", buf);
}
buf = pretty_print_option(i, opt, 1);
if (buf == NULL)
- return (NULL);
+ return NULL;
strlcat(string, " option ", sizeof(string));
strlcat(string, name, sizeof(string));
append_statement(string, sizeof(string), " ", buf);
rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT,
gmtime(&lease->renewal));
if (rslt == 0)
- return (NULL);
+ return NULL;
append_statement(string, sizeof(string), " renew ", timebuf);
rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT,
gmtime(&lease->rebind));
if (rslt == 0)
- return (NULL);
+ return NULL;
append_statement(string, sizeof(string), " rebind ", timebuf);
rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT,
gmtime(&lease->expiry));
if (rslt == 0)
- return (NULL);
+ return NULL;
append_statement(string, sizeof(string), " expire ", timebuf);
rslt = strlcat(string, "}\n", sizeof(string));
if (rslt >= sizeof(string))
- return (NULL);
+ return NULL;
- return (string);
+ return string ;
}
void
{
if (devnull == -1) {
errno = EBADF;
- return (-1);
+ return -1;
}
if (fcntl(devnull, F_GETFL) == -1)
- return (-1);
+ return -1;
switch (fork()) {
case -1:
- return (-1);
+ return -1;
case 0:
break;
default:
}
if (setsid() == -1)
- return (-1);
+ return -1;
(void)dup2(devnull, STDIN_FILENO);
(void)dup2(devnull, STDOUT_FILENO);
if (devnull > 2)
(void)close(devnull);
- return (0);
+ return 0;
}
int
;
} else if (pch == '.' || nch == '.' || nch == '\0') {
if (!isalnum(ch))
- return (0);
+ return 0;
} else if (!isalnum(ch) && ch != '-' && ch != '_') {
- return (0);
+ return 0;
} else if (ch == '_' && warn == 0) {
log_warnx("warning: hostname %s contains an "
"underscore which violates RFC 952", name);
}
pch = ch, ch = nch;
}
- return (1);
+ return 1;
}
/*
int count;
if (strlen(names) >= DHCP_DOMAIN_SEARCH_LEN)
- return (0);
+ return 0;
dupnames = inputstring = strdup(names);
if (inputstring == NULL)
free(dupnames);
- return (count > 0 && count < 7 && hn == NULL);
+ return count > 0 && count < 7 && hn == NULL;
}
void
newlease->options[DHO_STATIC_ROUTES].len = 0;
}
- return (newlease);
+ return newlease;
cleanup:
if (newlease) {
fatalx("Unable to apply defaults");
/* NOTREACHED */
- return (NULL);
+ return NULL;
}
struct client_lease *
newlease->options[i].len);
}
- return (newlease);
+ return newlease;
cleanup:
if (newlease) {
free_client_lease(newlease);
}
- return (NULL);
+ return NULL;
}
/*
int i;
if (active == new)
- return (0);
+ return 0;
if (!new || !active)
- return (1);
+ return 1;
if (active->address.s_addr != new->address.s_addr ||
active->is_static != new->is_static ||
BOOTP_LEASE(active) != BOOTP_LEASE(new))
- return (1);
+ return 1;
if (active->server_name != new->server_name) {
if (!active->server_name || !new->server_name)
- return (1);
+ return 1;
if (strcmp(active->server_name, new->server_name) != 0)
- return (1);
+ return 1;
}
if (active->filename != new->filename) {
if (!active->filename || !new->filename)
- return (1);
+ return 1;
if (strcmp(active->filename, new->filename) != 0)
- return (1);
+ return 1;
}
for (i = 0; i < DHO_COUNT; i++) {
if (active->options[i].len != new->options[i].len)
- return (1);
+ return 1;
if (memcmp(active->options[i].data, new->options[i].data,
active->options[i].len))
- return (1);
+ return 1;
}
- return (0);
+ return 0;
}
void
break;
}
- return (lp);
+ return lp;
}
void
-/* $OpenBSD: kroute.c,v 1.104 2017/07/09 12:38:47 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.105 2017/07/09 19:19:58 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
pid_t pid;
if (!label)
- return (ROUTE_LABEL_NONE);
+ return ROUTE_LABEL_NONE;
if (strncmp("DHCLIENT ", label->sr_label, 9) != 0)
- return (ROUTE_LABEL_NOT_DHCLIENT);
+ return ROUTE_LABEL_NOT_DHCLIENT;
pid = (pid_t)strtonum(label->sr_label + 9, 1, INT_MAX, NULL);
if (pid <= 0)
- return (ROUTE_LABEL_DHCLIENT_UNKNOWN);
+ return ROUTE_LABEL_DHCLIENT_UNKNOWN;
if (pid == getpid())
- return (ROUTE_LABEL_DHCLIENT_OURS);
+ return ROUTE_LABEL_DHCLIENT_OURS;
if (kill(pid, 0) == -1) {
if (errno == ESRCH)
- return (ROUTE_LABEL_DHCLIENT_DEAD);
+ return ROUTE_LABEL_DHCLIENT_DEAD;
else
- return (ROUTE_LABEL_DHCLIENT_UNKNOWN);
+ return ROUTE_LABEL_DHCLIENT_UNKNOWN;
}
- return (ROUTE_LABEL_DHCLIENT_LIVE);
+ return ROUTE_LABEL_DHCLIENT_LIVE;
}
/*
if (len == -1 || (unsigned int)len >= sizeof(label->sr_label)) {
log_warn("could not create route label");
- return (1);
+ return 1;
}
- return (0);
+ return 0;
}
/*
rslt = 1;
done:
- return (rslt);
+ return rslt;
}
/*
if (len == 0) {
free(dn);
- return (NULL);
+ return NULL;
}
rslt = asprintf(&courtesy, "# Generated by %s dhclient\n", name);
if (config->resolv_tail)
strlcat(contents, config->resolv_tail, len);
- return (contents);
+ return contents;
}
/*
-/* $OpenBSD: options.c,v 1.97 2017/07/08 20:38:31 krw Exp $ */
+/* $OpenBSD: options.c,v 1.98 2017/07/09 19:19:58 krw Exp $ */
/* DHCP options parsing and reassembly. */
} else {
log_warnx("option %s (%d) larger than buffer.",
name, len);
- return (0);
+ return 0;
}
} else {
log_warnx("option %s has no length field.", name);
- return (0);
+ return 0;
}
/*
s += len + 2;
}
- return (1);
+ return 1;
}
/*
length = options[code].len;
if (bufix + length + 2*((length+254)/255) >= buflen)
- return (lastopt);
+ return lastopt;
lastopt = bufix;
ix = 0;
lastopt = bufix;
}
- return (lastopt);
+ return lastopt;
}
/*
rslt = strlcat(string, "\"", sizeof(string));
if (rslt >= sizeof(string))
- return (NULL);
+ return NULL;
- return (string);
+ return string;
}
/*
bytes = (bits + 7) / 8;
if (srclen < (bytes + sizeof(gateway.s_addr)) ||
bytes > sizeof(net.s_addr))
- return (NULL);
+ return NULL;
rslt = snprintf(bitsbuf, sizeof(bitsbuf), "/%d ", bits);
if (rslt == -1 || (unsigned int)rslt >= sizeof(bitsbuf))
- return (NULL);
+ return NULL;
memset(&net, 0, sizeof(net));
memcpy(&net.s_addr, src, bytes);
strlcat(string, bitsbuf, sizeof(string));
if (strlcat(string, inet_ntoa(gateway), sizeof(string)) >=
sizeof(string))
- return (NULL);
+ return NULL;
}
- return (string);
+ return string;
}
int
* domain name.
*/
*offset = i + 1;
- return (domain_name_len);
+ return domain_name_len;
} else if (label_len & 0xC0) {
/* This is a pointer to another list of labels. */
if (i + 1 >= srclen) {
/* The pointer is truncated. */
log_warnx("Truncated pointer in DHCP Domain "
"Search option.");
- return (-1);
+ return -1;
}
pointer = ((label_len & ~(0xC0)) << 8) + src[i + 1];
*/
log_warnx("Invalid forward pointer in DHCP "
"Domain Search option compression.");
- return (-1);
+ return -1;
}
pointed_len = expand_search_domain_name(src, srclen,
domain_name_len += pointed_len;
*offset = i + 2;
- return (domain_name_len);
+ return domain_name_len;
}
if (i + label_len + 1 > srclen) {
log_warnx("Truncated label in DHCP Domain Search "
"option.");
- return (-1);
+ return -1;
}
/*
* Update the domain name length with the length of the
if (strlen(domain_search) + domain_name_len >=
DHCP_DOMAIN_SEARCH_LEN) {
log_warnx("Domain search list too long.");
- return (-1);
+ return -1;
}
/* Copy the label found. */
log_warnx("Truncated DHCP Domain Search option.");
- return (-1);
+ return -1;
}
/*
len = expand_search_domain_name(src, srclen, &offset,
domain_search);
if (len == -1)
- return (NULL);
+ return NULL;
domains++;
expanded_len += len;
if (domains > DHCP_DOMAIN_SEARCH_CNT)
- return (NULL);
+ return NULL;
}
- return (domain_search);
+ return domain_search;
}
/*
}
done:
- return (optbuf);
+ return optbuf;
toobig:
memset(optbuf, 0, sizeof(optbuf));
- return (optbuf);
+ return optbuf;
}
struct option_data *
-/* $OpenBSD: packet.c,v 1.37 2017/07/08 00:36:10 krw Exp $ */
+/* $OpenBSD: packet.c,v 1.38 2017/07/09 19:19:58 krw Exp $ */
/* Packet assembly code, originally contributed by Archie Cobbs. */
sum -= 0xFFFF;
}
- return (sum);
+ return sum;
}
uint32_t
wrapsum(uint32_t sum)
{
sum = ~sum & 0xFFFF;
- return (htons(sum));
+ return htons(sum);
}
void
struct ether_header eh;
if (buflen < sizeof(eh))
- return (-1);
+ return -1;
memcpy(&eh, buf, sizeof(eh));
memcpy(from->ether_addr_octet, eh.ether_shost, ETHER_ADDR_LEN);
- return (sizeof(eh));
+ return sizeof(eh);
}
ssize_t
/* Assure that an entire IP header is within the buffer. */
if (sizeof(*ip) > buflen)
- return (-1);
+ return -1;
ip_len = (*buf & 0xf) << 2;
if (ip_len > buflen)
- return (-1);
+ return -1;
ip = (struct ip *)(buf);
ip_packets_seen++;
ip_packets_bad_checksum, ip_packets_seen);
ip_packets_seen = ip_packets_bad_checksum = 0;
}
- return (-1);
+ return -1;
}
memcpy(&from->sin_addr, &ip->ip_src, sizeof(from->sin_addr));
/* Assure that the entire IP packet is within the buffer. */
if (ntohs(ip->ip_len) > buflen)
- return (-1);
+ return -1;
/* Assure that the UDP header is within the buffer. */
if (ip_len + sizeof(*udp) > buflen)
- return (-1);
+ return -1;
udp = (struct udphdr *)(buf + ip_len);
udp_packets_seen++;
/* Assure that the entire UDP packet is within the buffer. */
if (ip_len + ntohs(udp->uh_ulen) > buflen)
- return (-1);
+ return -1;
data = buf + ip_len + sizeof(*udp);
/*
udp_packets_length_overflow =
udp_packets_length_checked = 0;
}
- return (-1);
+ return -1;
}
#ifdef DEBUG
if (len + data != buf + buflen)
udp_packets_bad_checksum, udp_packets_seen);
udp_packets_seen = udp_packets_bad_checksum = 0;
}
- return (-1);
+ return -1;
}
memcpy(&from->sin_port, &udp->uh_sport, sizeof(udp->uh_sport));
- return (ip_len + sizeof(*udp));
+ return ip_len + sizeof(*udp);
}
-/* $OpenBSD: parse.c,v 1.56 2017/07/09 18:45:27 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.57 2017/07/09 19:19:58 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
if (token != ';') {
parse_warn("expecting semicolon.");
skip_to_semi(cfile);
- return (0);
+ return 0;
}
- return (1);
+ return 1;
}
char *
parse_warn("expecting string.");
if (token != ';')
skip_to_semi(cfile);
- return (NULL);
+ return NULL;
}
i = strnunvis(unvisbuf, val, sizeof(unvisbuf));
if (i == -1) {
parse_warn("could not unvis string");
- return (NULL);
+ return NULL;
}
s = malloc(i+1);
if (!s)
if (len != NULL)
*len = i;
- return (s);
+ return s;
}
/* cidr :== ip-address "/" bit-count
if (!len) {
parse_warn("expecting decimal value.");
skip_to_semi(cfile);
- return (0);
+ return 0;
} else if (token != '/') {
parse_warn("expecting '/'.");
skip_to_semi(cfile);
- return (0);
+ return 0;
} else if (!parse_decimal(cfile, cidr, 'B') || *cidr > 32) {
parse_warn("expecting decimal value <= 32.");
skip_to_semi(cfile);
- return (0);
+ return 0;
}
- return (1);
+ return 1;
}
int
if (len == 4) {
memcpy(addr, &buf, sizeof(*addr));
- return (1);
+ return 1;
} else if (token != '.') {
parse_warn("expecting '.'.");
skip_to_semi(cfile);
- return (0);
+ return 0;
} else {
parse_warn("expecting decimal value.");
skip_to_semi(cfile);
- return (0);
+ return 0;
}
}
if (strcasecmp(val, "true") == 0 ||
strcasecmp(val, "on") == 0) {
buf[0] = 1;
- return (1);
+ return 1;
}
if (strcasecmp(val, "false") == 0 ||
strcasecmp(val, "off") == 0) {
buf[0] = 0;
- return (1);
+ return 1;
}
}
- return (0);
+ return 0;
}
int
bytes = 1;
break;
default:
- return (0);
+ return 0;
}
numval = strtonum(val, low, high, &errstr);
if (errstr)
- return (0);
+ return 0;
numval = htobe64(numval);
memcpy(buf, (char *)&numval + (sizeof(numval) - bytes), bytes);
- return (1);
+ return 1;
}
int
if ((val[0] == '\0' || *ep != '\0') ||
(errno == ERANGE && ulval == ULONG_MAX) ||
(ulval > UINT8_MAX))
- return (0);
+ return 0;
buf[0] = ulval;
- return (1);
+ return 1;
}
/*
/* XXX Will break after year 9999! */
parse_warn("time string too long");
skip_to_semi(cfile);
- return (0);
+ return 0;
}
break;
case';':
default:
parse_warn("invalid time string");
skip_to_semi(cfile);
- return (0);
+ return 0;
}
} while (token != ';');
p = strptime(timestr, DB_TIMEFMT, &tm);
if (p == NULL || *p != '\0') {
parse_warn("unparseable time string");
- return (0);
+ return 0;
}
guess = timegm(&tm);
if (guess == -1) {
parse_warn("time could not be represented");
- return (0);
+ return 0;
}
- return (guess);
+ return guess;
}
void