summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2019-11-19 14:46:34 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2019-11-19 14:46:34 +0000
commit8bc489c72b555283119d2718cea3c78925d28537 (patch)
treed7499eb0336b614caee21f077787d8703cac12fc
parent90b5e0d082fb0fb74528924ee00ba140aac7f659 (diff)
Stop dhcp lease file parsing now that dhclient sends proposals.
Tested by deraadt as part of a larger diff.
-rw-r--r--sbin/unwind/frontend.c171
-rw-r--r--sbin/unwind/resolver.c76
-rw-r--r--sbin/unwind/unwind.c45
-rw-r--r--sbin/unwind/unwind.h5
4 files changed, 10 insertions, 287 deletions
diff --git a/sbin/unwind/frontend.c b/sbin/unwind/frontend.c
index 3bb6477898d..5e125a21fa6 100644
--- a/sbin/unwind/frontend.c
+++ b/sbin/unwind/frontend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: frontend.c,v 1.34 2019/11/11 05:51:05 florian Exp $ */
+/* $OpenBSD: frontend.c,v 1.35 2019/11/19 14:46:33 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -111,7 +111,6 @@ void get_rtaddrs(int, struct sockaddr *,
struct sockaddr **);
void rtmget_default(void);
struct pending_query *find_pending_query(uint64_t);
-void parse_dhcp_lease(int);
void parse_trust_anchor(struct trust_anchor_head *, int);
void send_trust_anchors(struct trust_anchor_head *);
void write_trust_anchors(struct trust_anchor_head *, int);
@@ -445,12 +444,6 @@ frontend_dispatch_main(int fd, short event, void *bula)
TAILQ_INIT(&ctl_conns);
control_listen();
break;
- case IMSG_LEASEFD:
- if ((fd = imsg.fd) == -1)
- fatalx("%s: expected to receive imsg dhcp "
- "lease fd but didn't receive any", __func__);
- parse_dhcp_lease(fd);
- break;
case IMSG_TAFD:
if ((ta_fd = imsg.fd) != -1)
parse_trust_anchor(&trust_anchors, ta_fd);
@@ -639,7 +632,6 @@ frontend_startup(void)
event_add(&ev_route, NULL);
frontend_imsg_compose_main(IMSG_STARTUP_DONE, 0, NULL, 0);
- rtmget_default();
}
void
@@ -1019,37 +1011,8 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info)
{
struct imsg_rdns_proposal rdns_proposal;
struct sockaddr_rtdns *rtdns;
- char buf[IF_NAMESIZE], *bufp;
switch (rtm->rtm_type) {
- case RTM_GET:
- if (rtm->rtm_errno != 0)
- break;
- if (!(rtm->rtm_flags & RTF_UP))
- break;
- if (!(rtm->rtm_addrs & RTA_DST))
- break;
- if (rti_info[RTAX_DST]->sa_family != AF_INET)
- break;
- if (((struct sockaddr_in *)rti_info[RTAX_DST])->sin_addr.
- s_addr != INADDR_ANY)
- break;
- if (!(rtm->rtm_addrs & RTA_NETMASK))
- break;
- if (rti_info[RTAX_NETMASK]->sa_family != AF_INET)
- break;
- if (((struct sockaddr_in *)rti_info[RTAX_NETMASK])->sin_addr.
- s_addr != INADDR_ANY)
- break;
-
- frontend_imsg_compose_main(IMSG_OPEN_DHCP_LEASE, 0,
- &rtm->rtm_index, sizeof(rtm->rtm_index));
-
- bufp = if_indextoname(rtm->rtm_index, buf);
- if (bufp)
- log_debug("default route is on %s", buf);
-
- break;
case RTM_IFINFO:
frontend_imsg_compose_resolver(IMSG_RECHECK_RESOLVERS, 0, NULL,
0);
@@ -1091,138 +1054,6 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info)
}
void
-rtmget_default(void)
-{
- static int rtm_seq;
- struct rt_msghdr rtm;
- struct sockaddr_in sin;
- struct iovec iov[5];
- long pad = 0;
- int iovcnt = 0, padlen;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_len = sizeof(sin);
-
- memset(&rtm, 0, sizeof(rtm));
-
- rtm.rtm_version = RTM_VERSION;
- rtm.rtm_type = RTM_GET;
- rtm.rtm_msglen = sizeof(rtm);
- rtm.rtm_tableid = 0; /* XXX imsg->rdomain; */
- rtm.rtm_seq = ++rtm_seq;
- rtm.rtm_addrs = RTA_DST | RTA_NETMASK;
-
- iov[iovcnt].iov_base = &rtm;
- iov[iovcnt++].iov_len = sizeof(rtm);
-
- /* dst */
- iov[iovcnt].iov_base = &sin;
- iov[iovcnt++].iov_len = sizeof(sin);
- rtm.rtm_msglen += sizeof(sin);
- padlen = ROUNDUP(sizeof(sin)) - sizeof(sin);
- if (padlen > 0) {
- iov[iovcnt].iov_base = &pad;
- iov[iovcnt++].iov_len = padlen;
- rtm.rtm_msglen += padlen;
- }
-
- /* mask */
- iov[iovcnt].iov_base = &sin;
- iov[iovcnt++].iov_len = sizeof(sin);
- rtm.rtm_msglen += sizeof(sin);
- padlen = ROUNDUP(sizeof(sin)) - sizeof(sin);
- if (padlen > 0) {
- iov[iovcnt].iov_base = &pad;
- iov[iovcnt++].iov_len = padlen;
- rtm.rtm_msglen += padlen;
- }
-
- if (writev(routesock, iov, iovcnt) == -1)
- log_warn("failed to send route message");
-}
-
-void
-parse_dhcp_lease(int fd)
-{
- FILE *f;
- char *line = NULL, *cur_ns = NULL, *ns = NULL;
- size_t linesize = 0;
- ssize_t linelen;
- time_t epoch = 0, lease_time = 0, now;
- char **tok, *toks[4], *p;
-
- if((f = fdopen(fd, "r")) == NULL) {
- log_warn("cannot read dhcp lease");
- close(fd);
- return;
- }
-
- now = time(NULL);
-
- while ((linelen = getline(&line, &linesize, f)) != -1) {
- for (tok = toks; tok < &toks[3] && (*tok = strsep(&line, " \t"))
- != NULL;) {
- if (**tok != '\0')
- tok++;
- }
- if (toks[0] == NULL)
- continue;
- *tok = NULL;
- if (strcmp(toks[0], "option") == 0) {
- if (toks[1] == NULL || toks[2] == NULL)
- continue;
- if (strcmp(toks[1], "domain-name-servers") == 0) {
- if((p = strchr(toks[2], ';')) != NULL) {
- *p='\0';
- free(cur_ns);
- cur_ns = strdup(toks[2]);
- }
- }
- if (strcmp(toks[1], "dhcp-lease-time") == 0) {
- if((p = strchr(toks[2], ';')) != NULL) {
- *p='\0';
- lease_time = strtonum(toks[2], 0,
- INT64_MAX, NULL);
- }
- }
- } else if (strcmp(toks[0], "epoch") == 0) {
- if (toks[1] == NULL)
- continue;
- if((p = strchr(toks[1], ';')) != NULL) {
- *p='\0';
- epoch = strtonum(toks[1], 0,
- INT64_MAX, NULL);
- }
- }
- else if (*toks[0] == '}') {
- if (epoch + lease_time > now ) {
- free(ns);
- ns = cur_ns;
- cur_ns = NULL;
- } else {
- /* expired lease */
- free(cur_ns);
- cur_ns = NULL;
- }
- }
- }
- free(line);
- free(cur_ns);
-
- if (ferror(f))
- log_warn("getline");
- fclose(f);
-
- if (ns != NULL) {
- log_debug("%s: ns: %s", __func__, ns);
- frontend_imsg_compose_resolver(IMSG_FORWARDER, 0, ns,
- strlen(ns) + 1);
- }
-}
-
-
-void
add_new_ta(struct trust_anchor_head *tah, char *val)
{
struct trust_anchor *ta, *i;
diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c
index d92c7a27665..b7b050c2599 100644
--- a/sbin/unwind/resolver.c
+++ b/sbin/unwind/resolver.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: resolver.c,v 1.66 2019/11/15 06:08:21 otto Exp $ */
+/* $OpenBSD: resolver.c,v 1.67 2019/11/19 14:46:33 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -114,7 +114,6 @@ void resolve_done(struct uw_resolver *, void *, int, void *,
void ub_resolve_done(void *, int, void *, int, int, char *,
int);
void asr_resolve_done(struct asr_result *, void *);
-void parse_dhcp_forwarders(char *);
void new_recursor(void);
void new_forwarders(int);
void new_asr_forwarders(void);
@@ -167,7 +166,6 @@ struct uw_conf *resolver_conf;
struct imsgev *iev_frontend;
struct imsgev *iev_captiveportal;
struct imsgev *iev_main;
-struct uw_forwarder_head dhcp_forwarder_list;
struct uw_forwarder_head autoconf_forwarder_list;
struct uw_resolver *resolvers[UW_RES_NONE];
struct timeval captive_portal_check_tv =
@@ -354,7 +352,6 @@ resolver(int debug, int verbose)
new_recursor();
- TAILQ_INIT(&dhcp_forwarder_list);
TAILQ_INIT(&autoconf_forwarder_list);
TAILQ_INIT(&trust_anchors);
TAILQ_INIT(&new_trust_anchors);
@@ -487,11 +484,6 @@ resolver_dispatch_frontend(int fd, short event, void *bula)
resolve(res, query_imsg->qname, query_imsg->t,
query_imsg->c, query_imsg, resolve_done);
break;
- case IMSG_FORWARDER:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- parse_dhcp_forwarders(imsg.data);
- break;
case IMSG_CTL_STATUS:
if (IMSG_DATA_SIZE(imsg) != sizeof(type))
fatalx("%s: IMSG_CTL_STATUS wrong length: %lu",
@@ -896,47 +888,6 @@ servfail:
}
void
-parse_dhcp_forwarders(char *forwarders)
-{
- struct uw_forwarder_head new_forwarder_list;
- struct uw_forwarder *uw_forwarder;
- char *ns;
-
- TAILQ_INIT(&new_forwarder_list);
-
- if (forwarders != NULL) {
- while((ns = strsep(&forwarders, ",")) != NULL) {
- log_debug("%s: %s", __func__, ns);
- if ((uw_forwarder = calloc(1, sizeof(struct
- uw_forwarder))) == NULL)
- fatal(NULL);
- if (strlcpy(uw_forwarder->name, ns,
- sizeof(uw_forwarder->name)) >=
- sizeof(uw_forwarder->name))
- fatalx("strlcpy");
- TAILQ_INSERT_TAIL(&new_forwarder_list, uw_forwarder,
- entry);
- }
- }
-
- if (check_forwarders_changed(&new_forwarder_list,
- &dhcp_forwarder_list)) {
- replace_forwarders(&new_forwarder_list, &dhcp_forwarder_list);
- new_forwarders(0);
- new_asr_forwarders();
- if (resolver_conf->captive_portal_auto)
- check_captive_portal(1);
- } else {
- while ((uw_forwarder =
- TAILQ_FIRST(&new_forwarder_list)) != NULL) {
- TAILQ_REMOVE(&new_forwarder_list, uw_forwarder, entry);
- free(uw_forwarder);
- }
- log_debug("%s: forwarders didn't change", __func__);
- }
-}
-
-void
new_recursor(void)
{
free_resolver(resolvers[UW_RES_RECURSOR]);
@@ -955,8 +906,7 @@ new_forwarders(int oppdot)
free_resolver(resolvers[UW_RES_DHCP]);
resolvers[UW_RES_DHCP] = NULL;
- if (TAILQ_EMPTY(&dhcp_forwarder_list) &&
- TAILQ_EMPTY(&autoconf_forwarder_list))
+ if (TAILQ_EMPTY(&autoconf_forwarder_list))
return;
if (TAILQ_EMPTY(&trust_anchors))
@@ -974,8 +924,7 @@ new_asr_forwarders(void)
free_resolver(resolvers[UW_RES_ASR]);
resolvers[UW_RES_ASR] = NULL;
- if (TAILQ_EMPTY(&dhcp_forwarder_list) &&
- TAILQ_EMPTY(&autoconf_forwarder_list))
+ if (TAILQ_EMPTY(&autoconf_forwarder_list))
return;
log_debug("%s: create_resolver", __func__);
@@ -1044,22 +993,10 @@ create_resolver(enum uw_resolver_type type, int oppdot)
switch (type) {
case UW_RES_ASR:
- if (TAILQ_EMPTY(&dhcp_forwarder_list) &&
- TAILQ_EMPTY(&autoconf_forwarder_list)) {
+ if (TAILQ_EMPTY(&autoconf_forwarder_list)) {
free(res);
return (NULL);
}
- TAILQ_FOREACH(uw_forwarder, &dhcp_forwarder_list, entry) {
- tmp = resolv_conf;
- if (asprintf(&resolv_conf, "%snameserver %s\n", tmp ==
- NULL ? "" : tmp, uw_forwarder->name) == -1) {
- free(tmp);
- free(res);
- log_warnx("could not create asr context");
- return (NULL);
- }
- free(tmp);
- }
TAILQ_FOREACH(uw_forwarder, &autoconf_forwarder_list, entry) {
tmp = resolv_conf;
if (asprintf(&resolv_conf, "%snameserver %s\n", tmp ==
@@ -1142,15 +1079,14 @@ create_resolver(enum uw_resolver_type type, int oppdot)
case UW_RES_DHCP:
res->oppdot = oppdot;
if (oppdot) {
- set_forwarders_oppdot(res, &dhcp_forwarder_list, 853);
set_forwarders_oppdot(res, &autoconf_forwarder_list,
853);
ub_ctx_set_option(res->ctx, "tls-cert-bundle:",
tls_default_ca_cert_file());
ub_ctx_set_tls(res->ctx, 1);
} else {
- set_forwarders_oppdot(res, &dhcp_forwarder_list, 53);
- set_forwarders_oppdot(res, &autoconf_forwarder_list, 53);
+ set_forwarders_oppdot(res, &autoconf_forwarder_list,
+ 53);
}
break;
case UW_RES_FORWARDER:
diff --git a/sbin/unwind/unwind.c b/sbin/unwind/unwind.c
index 317df549975..87e3fa87ac3 100644
--- a/sbin/unwind/unwind.c
+++ b/sbin/unwind/unwind.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unwind.c,v 1.36 2019/11/14 08:34:17 florian Exp $ */
+/* $OpenBSD: unwind.c,v 1.37 2019/11/19 14:46:33 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -49,9 +49,6 @@
#include "control.h"
#include "captiveportal.h"
-#define LEASE_DB_DIR "/var/db/"
-#define _PATH_LEASE_DB "/var/db/dhclient.leases."
-
#define TRUST_ANCHOR_FILE "/var/db/unwind.key"
__dead void usage(void);
@@ -71,7 +68,6 @@ static int main_imsg_send_config(struct uw_conf *);
int main_reload(void);
int main_sendall(enum imsg_type, void *, uint16_t);
-void open_dhcp_lease(int);
void open_ports(void);
void solicit_dns_proposals(void);
void connect_captive_portal_host(struct in_addr *);
@@ -294,8 +290,7 @@ main(int argc, char *argv[])
AF_INET)) == -1)
fatal("route socket");
- rtfilter = ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_PROPOSAL) |
- ROUTE_FILTER(RTM_GET);
+ rtfilter = ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_PROPOSAL);
if (setsockopt(frontend_routesock, AF_ROUTE, ROUTE_MSGFILTER,
&rtfilter, sizeof(rtfilter)) == -1)
fatal("setsockopt(ROUTE_MSGFILTER)");
@@ -423,7 +418,6 @@ main_dispatch_frontend(int fd, short event, void *bula)
struct imsg imsg;
ssize_t n;
int shut = 0, verbose;
- u_short rtm_index;
ibuf = &iev->ibuf;
@@ -464,13 +458,6 @@ main_dispatch_frontend(int fd, short event, void *bula)
memcpy(&verbose, imsg.data, sizeof(verbose));
log_setverbose(verbose);
break;
- case IMSG_OPEN_DHCP_LEASE:
- if (IMSG_DATA_SIZE(imsg) != sizeof(rtm_index))
- fatalx("%s: IMSG_OPEN_DHCP_LEASE wrong length: "
- "%lu", __func__, IMSG_DATA_SIZE(imsg));
- memcpy(&rtm_index, imsg.data, sizeof(rtm_index));
- open_dhcp_lease(rtm_index);
- break;
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
@@ -892,34 +879,6 @@ config_clear(struct uw_conf *conf)
}
void
-open_dhcp_lease(int if_idx)
-{
- static char lease_filename[sizeof(_PATH_LEASE_DB) + IF_NAMESIZE] =
- _PATH_LEASE_DB;
-
- int fd;
- char *bufp;
-
- bufp = lease_filename + sizeof(_PATH_LEASE_DB) - 1;
- bufp = if_indextoname(if_idx, bufp);
-
- if (bufp == NULL) {
- log_debug("cannot find interface %d", if_idx);
- return;
- }
-
- log_debug("lease file name: %s", lease_filename);
-
- if ((fd = open(lease_filename, O_RDONLY)) == -1) {
- if (errno != ENOENT)
- log_warn("cannot open lease file %s", lease_filename);
- return;
- }
-
- main_imsg_compose_frontend_fd(IMSG_LEASEFD, 0, fd);
-}
-
-void
open_ports(void)
{
struct addrinfo hints, *res0;
diff --git a/sbin/unwind/unwind.h b/sbin/unwind/unwind.h
index 2b64c071c30..37a0e0fcc0e 100644
--- a/sbin/unwind/unwind.h
+++ b/sbin/unwind/unwind.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unwind.h,v 1.28 2019/11/14 08:34:17 florian Exp $ */
+/* $OpenBSD: unwind.h,v 1.29 2019/11/19 14:46:33 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -104,9 +104,6 @@ enum imsg_type {
IMSG_QUERY,
IMSG_ANSWER_HEADER,
IMSG_ANSWER,
- IMSG_OPEN_DHCP_LEASE,
- IMSG_LEASEFD,
- IMSG_FORWARDER,
IMSG_CTL_RESOLVER_INFO,
IMSG_CTL_RESOLVER_WHY_BOGUS,
IMSG_CTL_RESOLVER_HISTOGRAM,