summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-09-09 15:08:00 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-09-09 15:08:00 +0000
commit46c258727e1a85925e4c7f4a88e2bf3ddd77c667 (patch)
tree0a97169763b2af74447b62f1a0941668eb17030e
parent152bd7a2c057d90ff643f447ea811b8a676b6ad7 (diff)
Tweak extract_classless_route() to return unsigned int
and accept NULL pointers for unwanted components of the route.
-rw-r--r--sbin/dhclient/dhcpd.h6
-rw-r--r--sbin/dhclient/kroute.c39
-rw-r--r--sbin/dhclient/options.c8
3 files changed, 29 insertions, 24 deletions
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 8543adae8c3..7a6e908dc97 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.225 2017/08/29 13:21:30 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.226 2017/09/09 15:07:59 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -233,8 +233,8 @@ void read_client_conf(char *);
void read_client_leases(char *, struct client_lease_tq *);
/* kroute.c */
-int extract_classless_route(uint8_t *, unsigned int,
- in_addr_t *, in_addr_t *, in_addr_t *);
+unsigned int extract_classless_route(uint8_t *, unsigned int,
+ in_addr_t *, in_addr_t *, in_addr_t *);
void delete_address(struct in_addr);
void set_resolv_conf(char *, uint8_t *, unsigned int,
uint8_t *, unsigned int);
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index 85160a1f571..6209abd46d0 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.145 2017/09/08 13:49:00 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.146 2017/09/09 15:07:59 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -179,28 +179,35 @@ priv_flush_routes(int index, int routefd, int rdomain,
free(buf);
}
-int
+unsigned int
extract_classless_route(uint8_t *rtstatic, unsigned int rtstatic_len,
in_addr_t *dest, in_addr_t *netmask, in_addr_t *gateway)
{
unsigned int bits, bytes, len;
if (rtstatic[0] > 32)
- return -1;
+ return 0;
bits = rtstatic[0];
bytes = (bits + 7) / 8;
len = 1 + bytes + sizeof(*gateway);
if (len > rtstatic_len)
- return -1;
+ return 0;
+
+ if (dest != NULL)
+ memcpy(dest, &rtstatic[1], bytes);
+
+ if (netmask != NULL) {
+ if (bits == 0)
+ *netmask = INADDR_ANY;
+ else
+ *netmask = htonl(0xffffffff << (32 - bits));
+ if (dest != NULL)
+ *dest &= *netmask;
+ }
- memcpy(dest, &rtstatic[1], bytes);
- if (bits == 0)
- *netmask = INADDR_ANY;
- else
- *netmask = htonl(0xffffffff << (32 - bits));
- *dest &= *netmask;
- memcpy(gateway, &rtstatic[1 + bytes], sizeof(*gateway));
+ if (gateway != NULL)
+ memcpy(gateway, &rtstatic[1 + bytes], sizeof(*gateway));
return len;
}
@@ -211,8 +218,7 @@ set_routes(struct in_addr addr, struct in_addr addrmask, uint8_t *rtstatic,
{
const struct in_addr any = { INADDR_ANY };
struct in_addr dest, gateway, netmask;
- unsigned int i;
- int len;
+ unsigned int i, len;
flush_routes(rtstatic, rtstatic_len);
@@ -221,7 +227,7 @@ set_routes(struct in_addr addr, struct in_addr addrmask, uint8_t *rtstatic,
while (i < rtstatic_len) {
len = extract_classless_route(&rtstatic[i], rtstatic_len - i,
&dest.s_addr, &netmask.s_addr, &gateway.s_addr);
- if (len <= 0)
+ if (len == 0)
return;
i += len;
@@ -793,8 +799,7 @@ route_in_rtstatic(struct rt_msghdr *rtm, uint8_t *rtstatic,
in_addr_t dstaddr, netmaskaddr, gatewayaddr;
in_addr_t rtstaticdstaddr, rtstaticnetmaskaddr;
in_addr_t rtstaticgatewayaddr;
- unsigned int i;
- int len;
+ unsigned int i, len;
get_rtaddrs(rtm->rtm_addrs,
(struct sockaddr *)((char *)(rtm) + rtm->rtm_hdrlen),
@@ -821,7 +826,7 @@ route_in_rtstatic(struct rt_msghdr *rtm, uint8_t *rtstatic,
len = extract_classless_route(&rtstatic[i], rtstatic_len - i,
&rtstaticdstaddr, &rtstaticnetmaskaddr,
&rtstaticgatewayaddr);
- if (len <= 0)
+ if (len == 0)
break;
if (dstaddr == rtstaticdstaddr &&
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index ab6a4ba1bbe..5ff7c298b73 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.104 2017/09/01 19:23:50 krw Exp $ */
+/* $OpenBSD: options.c,v 1.105 2017/09/09 15:07:59 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -589,14 +589,14 @@ pretty_print_classless_routes(unsigned char *src, size_t srclen,
{
char bitsbuf[5]; /* to hold "/nn " */
struct in_addr dest, netmask, gateway;
- unsigned int i;
- int len, rslt;
+ unsigned int i, len;
+ int rslt;
i = 0;
while (i < srclen) {
len = extract_classless_route(&src[i], srclen - i,
&dest.s_addr, &netmask.s_addr, &gateway.s_addr);
- if (len <= 0)
+ if (len == 0)
goto bad;
i += len;