diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2019-02-17 14:49:16 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2019-02-17 14:49:16 +0000 |
commit | d4a3083bed7c0ba45250ef37bd4762ed787f4b70 (patch) | |
tree | 997b53ba990cf95f51b7817146ad7e966289d6ac /sbin/unwind | |
parent | 4d5eaf8d4d803fb7396ffb216d89dde357140cea (diff) |
s/unwind_/uw_/ to save screen real estate; fix style(9) issues while here
Diffstat (limited to 'sbin/unwind')
-rw-r--r-- | sbin/unwind/captiveportal.c | 140 | ||||
-rw-r--r-- | sbin/unwind/control.c | 11 | ||||
-rw-r--r-- | sbin/unwind/frontend.c | 136 | ||||
-rw-r--r-- | sbin/unwind/printconf.c | 27 | ||||
-rw-r--r-- | sbin/unwind/resolver.c | 376 | ||||
-rw-r--r-- | sbin/unwind/resolver.h | 16 | ||||
-rw-r--r-- | sbin/unwind/unwind.c | 158 | ||||
-rw-r--r-- | sbin/unwind/unwind.h | 37 | ||||
-rw-r--r-- | sbin/unwind/uw_parse.y | 102 |
9 files changed, 496 insertions, 507 deletions
diff --git a/sbin/unwind/captiveportal.c b/sbin/unwind/captiveportal.c index 902c9c957ec..10df16b704c 100644 --- a/sbin/unwind/captiveportal.c +++ b/sbin/unwind/captiveportal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: captiveportal.c,v 1.3 2019/02/08 08:21:05 florian Exp $ */ +/* $OpenBSD: captiveportal.c,v 1.4 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -62,28 +62,28 @@ enum http_state { struct http_ctx { TAILQ_ENTRY(http_ctx) entry; - struct event ev; - int fd; - enum http_state state; - char *buf; - size_t bufsz; - int status; - int content_length; + struct event ev; + int fd; + enum http_state state; + char *buf; + size_t bufsz; + int status; + int content_length; }; -__dead void captiveportal_shutdown(void); -void captiveportal_sig_handler(int, short, void *); -void captiveportal_startup(void); -void http_callback(int, short, void *); -int parse_http_header(struct http_ctx *); -void check_http_body(struct http_ctx *ctx); -void free_http_ctx(struct http_ctx *); -void close_other_http_contexts(struct http_ctx *); +__dead void captiveportal_shutdown(void); +void captiveportal_sig_handler(int, short, void *); +void captiveportal_startup(void); +void http_callback(int, short, void *); +int parse_http_header(struct http_ctx *); +void check_http_body(struct http_ctx *ctx); +void free_http_ctx(struct http_ctx *); +void close_other_http_contexts(struct http_ctx *); -struct unwind_conf *captiveportal_conf; -struct imsgev *iev_main; -struct imsgev *iev_resolver; -struct imsgev *iev_frontend; +struct uw_conf *captiveportal_conf; +struct imsgev *iev_main; +struct imsgev *iev_resolver; +struct imsgev *iev_frontend; #define MAX_SERVERS_DNS 8 enum http_global_state http_global_state = IDLE; @@ -112,8 +112,8 @@ captiveportal_sig_handler(int sig, short event, void *bula) void captiveportal(int debug, int verbose) { - struct event ev_sigint, ev_sigterm; - struct passwd *pw; + struct event ev_sigint, ev_sigterm; + struct passwd *pw; captiveportal_conf = config_new_empty(); @@ -128,9 +128,9 @@ captiveportal(int debug, int verbose) if (chdir("/") == -1) fatal("chdir(\"/\")"); - unwind_process = PROC_CAPTIVEPORTAL; - setproctitle("%s", log_procnames[unwind_process]); - log_procinit(log_procnames[unwind_process]); + uw_process = PROC_CAPTIVEPORTAL; + setproctitle("%s", log_procnames[uw_process]); + log_procinit(log_procnames[uw_process]); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || @@ -192,14 +192,15 @@ captiveportal_shutdown(void) } int -captiveportal_imsg_compose_main(int type, pid_t pid, void *data, uint16_t datalen) +captiveportal_imsg_compose_main(int type, pid_t pid, void *data, + uint16_t datalen) { - return (imsg_compose_event(iev_main, type, 0, pid, -1, data, - datalen)); + return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen)); } int -captiveportal_imsg_compose_resolver(int type, pid_t pid, void *data, uint16_t datalen) +captiveportal_imsg_compose_resolver(int type, pid_t pid, void *data, + uint16_t datalen) { return (imsg_compose_event(iev_resolver, type, 0, pid, -1, data, datalen)); @@ -216,13 +217,13 @@ captiveportal_imsg_compose_frontend(int type, pid_t pid, void *data, void captiveportal_dispatch_main(int fd, short event, void *bula) { - static struct unwind_conf *nconf; - struct unwind_forwarder *unwind_forwarder; - struct imsg imsg; - struct imsgev *iev = bula; - struct imsgbuf *ibuf = &iev->ibuf; - struct http_ctx *ctx; - int n, shut = 0; + static struct uw_conf *nconf; + struct uw_forwarder *uw_forwarder; + struct imsg imsg; + struct imsgev *iev = bula; + struct imsgbuf *ibuf = &iev->ibuf; + struct http_ctx *ctx; + int n, shut = 0; if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) @@ -270,7 +271,8 @@ captiveportal_dispatch_main(int fd, short event, void *bula) iev_resolver->events = EV_READ; event_set(&iev_resolver->ev, iev_resolver->ibuf.fd, - iev_resolver->events, iev_resolver->handler, iev_resolver); + iev_resolver->events, iev_resolver->handler, + iev_resolver); event_add(&iev_resolver->ev, NULL); break; case IMSG_SOCKET_IPC_FRONTEND: @@ -299,23 +301,23 @@ captiveportal_dispatch_main(int fd, short event, void *bula) iev_frontend->events = EV_READ; event_set(&iev_frontend->ev, iev_frontend->ibuf.fd, - iev_frontend->events, iev_frontend->handler, iev_frontend); + iev_frontend->events, iev_frontend->handler, + iev_frontend); event_add(&iev_frontend->ev, NULL); break; case IMSG_RECONF_CONF: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_conf)) + sizeof(struct uw_conf)) fatalx("%s: IMSG_RECONF_CONF wrong length: %d", __func__, imsg.hdr.len); - if ((nconf = malloc(sizeof(struct unwind_conf))) == - NULL) + if ((nconf = malloc(sizeof(struct uw_conf))) == NULL) fatal(NULL); - memcpy(nconf, imsg.data, sizeof(struct unwind_conf)); + memcpy(nconf, imsg.data, sizeof(struct uw_conf)); nconf->captive_portal_host = NULL; nconf->captive_portal_path = NULL; nconf->captive_portal_expected_response = NULL; - SIMPLEQ_INIT(&nconf->unwind_forwarder_list); - SIMPLEQ_INIT(&nconf->unwind_dot_forwarder_list); + SIMPLEQ_INIT(&nconf->uw_forwarder_list); + SIMPLEQ_INIT(&nconf->uw_dot_forwarder_list); break; case IMSG_RECONF_CAPTIVE_PORTAL_HOST: /* make sure this is a string */ @@ -343,29 +345,29 @@ captiveportal_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_FORWARDER: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_forwarder)) + sizeof(struct uw_forwarder)) fatalx("%s: IMSG_RECONF_FORWARDER wrong length:" " %d", __func__, imsg.hdr.len); - if ((unwind_forwarder = malloc(sizeof(struct - unwind_forwarder))) == NULL) + if ((uw_forwarder = malloc(sizeof(struct + uw_forwarder))) == NULL) fatal(NULL); - memcpy(unwind_forwarder, imsg.data, sizeof(struct - unwind_forwarder)); - SIMPLEQ_INSERT_TAIL(&nconf->unwind_forwarder_list, - unwind_forwarder, entry); + memcpy(uw_forwarder, imsg.data, sizeof(struct + uw_forwarder)); + SIMPLEQ_INSERT_TAIL(&nconf->uw_forwarder_list, + uw_forwarder, entry); break; case IMSG_RECONF_DOT_FORWARDER: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_forwarder)) + sizeof(struct uw_forwarder)) fatalx("%s: IMSG_RECONF_DOT_FORWARDER wrong " "length: %d", __func__, imsg.hdr.len); - if ((unwind_forwarder = malloc(sizeof(struct - unwind_forwarder))) == NULL) + if ((uw_forwarder = malloc(sizeof(struct + uw_forwarder))) == NULL) fatal(NULL); - memcpy(unwind_forwarder, imsg.data, sizeof(struct - unwind_forwarder)); - SIMPLEQ_INSERT_TAIL(&nconf->unwind_dot_forwarder_list, - unwind_forwarder, entry); + memcpy(uw_forwarder, imsg.data, sizeof(struct + uw_forwarder)); + SIMPLEQ_INSERT_TAIL(&nconf->uw_dot_forwarder_list, + uw_forwarder, entry); break; case IMSG_RECONF_END: merge_config(captiveportal_conf, nconf); @@ -426,10 +428,10 @@ captiveportal_dispatch_main(int fd, short event, void *bula) void captiveportal_dispatch_resolver(int fd, short event, void *bula) { - struct imsgev *iev = bula; - struct imsgbuf *ibuf = &iev->ibuf; - struct imsg imsg; - int n, shut = 0; + struct imsgev *iev = bula; + struct imsgbuf *ibuf = &iev->ibuf; + struct imsg imsg; + int n, shut = 0; if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) @@ -470,10 +472,10 @@ captiveportal_dispatch_resolver(int fd, short event, void *bula) void captiveportal_dispatch_frontend(int fd, short event, void *bula) { - struct imsgev *iev = bula; - struct imsgbuf *ibuf = &iev->ibuf; - struct imsg imsg; - int n, shut = 0; + struct imsgev *iev = bula; + struct imsgbuf *ibuf = &iev->ibuf; + struct imsg imsg; + int n, shut = 0; if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) @@ -514,9 +516,9 @@ captiveportal_dispatch_frontend(int fd, short event, void *bula) void http_callback(int fd, short events, void *arg) { - struct http_ctx *ctx; - ssize_t n; - char *query, buf[512], *vis_str, *p, *ep; + struct http_ctx *ctx; + ssize_t n; + char *query, buf[512], *vis_str, *p, *ep; ctx = (struct http_ctx *)arg; diff --git a/sbin/unwind/control.c b/sbin/unwind/control.c index 0c4b8fc412b..0589904ff2d 100644 --- a/sbin/unwind/control.c +++ b/sbin/unwind/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.6 2019/02/03 12:02:30 florian Exp $ */ +/* $OpenBSD: control.c,v 1.7 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -74,7 +74,8 @@ control_init(char *path) } umask(old_umask); - if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) == -1) { + if (chmod(path, + S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) == -1) { log_warn("%s: chmod", __func__); close(fd); (void)unlink(path); @@ -139,8 +140,8 @@ control_accept(int listenfd, short event, void *bula) imsg_init(&c->iev.ibuf, connfd); c->iev.handler = control_dispatch_imsg; c->iev.events = EV_READ; - event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events, - c->iev.handler, &c->iev); + event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events, c->iev.handler, + &c->iev); event_add(&c->iev.ev, NULL); TAILQ_INSERT_TAIL(&ctl_conns, c, entry); @@ -277,7 +278,7 @@ control_dispatch_imsg(int fd, short event, void *bula) break; case IMSG_CTL_STATUS: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(enum - unwind_resolver_type)) + uw_resolver_type)) break; frontend_imsg_compose_resolver(imsg.hdr.type, 0, imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE); diff --git a/sbin/unwind/frontend.c b/sbin/unwind/frontend.c index c070dfa0cda..fcad36774d7 100644 --- a/sbin/unwind/frontend.c +++ b/sbin/unwind/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.12 2019/02/10 14:10:22 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.13 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -93,7 +93,7 @@ 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); -struct unwind_conf *frontend_conf; +struct uw_conf *frontend_conf; struct imsgev *iev_main; struct imsgev *iev_resolver; struct imsgev *iev_captiveportal; @@ -124,11 +124,11 @@ frontend_sig_handler(int sig, short event, void *bula) void frontend(int debug, int verbose) { - struct event ev_sigint, ev_sigterm; - struct passwd *pw; - size_t rcvcmsglen, sndcmsgbuflen; - uint8_t *rcvcmsgbuf; - uint8_t *sndcmsgbuf = NULL; + struct event ev_sigint, ev_sigterm; + struct passwd *pw; + size_t rcvcmsglen, sndcmsgbuflen; + uint8_t *rcvcmsgbuf; + uint8_t *sndcmsgbuf = NULL; frontend_conf = config_new_empty(); control_state.fd = -1; @@ -144,9 +144,9 @@ frontend(int debug, int verbose) if (chdir("/") == -1) fatal("chdir(\"/\")"); - unwind_process = PROC_FRONTEND; - setproctitle("%s", log_procnames[unwind_process]); - log_procinit(log_procnames[unwind_process]); + uw_process = PROC_FRONTEND; + setproctitle("%s", log_procnames[uw_process]); + log_procinit(log_procnames[uw_process]); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || @@ -240,19 +240,20 @@ frontend_shutdown(void) int frontend_imsg_compose_main(int type, pid_t pid, void *data, uint16_t datalen) { - return (imsg_compose_event(iev_main, type, 0, pid, -1, data, - datalen)); + return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen)); } int -frontend_imsg_compose_resolver(int type, pid_t pid, void *data, uint16_t datalen) +frontend_imsg_compose_resolver(int type, pid_t pid, void *data, + uint16_t datalen) { return (imsg_compose_event(iev_resolver, type, 0, pid, -1, data, datalen)); } int -frontend_imsg_compose_captiveportal(int type, pid_t pid, void *data, uint16_t datalen) +frontend_imsg_compose_captiveportal(int type, pid_t pid, void *data, + uint16_t datalen) { return (imsg_compose_event(iev_captiveportal, type, 0, pid, -1, data, datalen)); @@ -261,12 +262,12 @@ frontend_imsg_compose_captiveportal(int type, pid_t pid, void *data, uint16_t da void frontend_dispatch_main(int fd, short event, void *bula) { - static struct unwind_conf *nconf; - struct unwind_forwarder *unwind_forwarder; - struct imsg imsg; - struct imsgev *iev = bula; - struct imsgbuf *ibuf = &iev->ibuf; - int n, shut = 0; + static struct uw_conf *nconf; + struct uw_forwarder *uw_forwarder; + struct imsg imsg; + struct imsgev *iev = bula; + struct imsgbuf *ibuf = &iev->ibuf; + int n, shut = 0; if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) @@ -314,7 +315,8 @@ frontend_dispatch_main(int fd, short event, void *bula) iev_resolver->events = EV_READ; event_set(&iev_resolver->ev, iev_resolver->ibuf.fd, - iev_resolver->events, iev_resolver->handler, iev_resolver); + iev_resolver->events, iev_resolver->handler, + iev_resolver); event_add(&iev_resolver->ev, NULL); break; case IMSG_SOCKET_IPC_CAPTIVEPORTAL: @@ -339,27 +341,29 @@ frontend_dispatch_main(int fd, short event, void *bula) fatal(NULL); imsg_init(&iev_captiveportal->ibuf, fd); - iev_captiveportal->handler = frontend_dispatch_captiveportal; + iev_captiveportal->handler = + frontend_dispatch_captiveportal; iev_captiveportal->events = EV_READ; - event_set(&iev_captiveportal->ev, iev_captiveportal->ibuf.fd, - iev_captiveportal->events, iev_captiveportal->handler, iev_captiveportal); + event_set(&iev_captiveportal->ev, + iev_captiveportal->ibuf.fd, + iev_captiveportal->events, + iev_captiveportal->handler, iev_captiveportal); event_add(&iev_captiveportal->ev, NULL); break; case IMSG_RECONF_CONF: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_conf)) + sizeof(struct uw_conf)) fatalx("%s: IMSG_RECONF_CONF wrong length: %d", __func__, imsg.hdr.len); - if ((nconf = malloc(sizeof(struct unwind_conf))) == - NULL) + if ((nconf = malloc(sizeof(struct uw_conf))) == NULL) fatal(NULL); - memcpy(nconf, imsg.data, sizeof(struct unwind_conf)); + memcpy(nconf, imsg.data, sizeof(struct uw_conf)); nconf->captive_portal_host = NULL; nconf->captive_portal_path = NULL; nconf->captive_portal_expected_response = NULL; - SIMPLEQ_INIT(&nconf->unwind_forwarder_list); - SIMPLEQ_INIT(&nconf->unwind_dot_forwarder_list); + SIMPLEQ_INIT(&nconf->uw_forwarder_list); + SIMPLEQ_INIT(&nconf->uw_dot_forwarder_list); break; case IMSG_RECONF_CAPTIVE_PORTAL_HOST: /* make sure this is a string */ @@ -387,29 +391,29 @@ frontend_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_FORWARDER: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_forwarder)) + sizeof(struct uw_forwarder)) fatalx("%s: IMSG_RECONF_FORWARDER wrong length:" " %d", __func__, imsg.hdr.len); - if ((unwind_forwarder = malloc(sizeof(struct - unwind_forwarder))) == NULL) + if ((uw_forwarder = malloc(sizeof(struct + uw_forwarder))) == NULL) fatal(NULL); - memcpy(unwind_forwarder, imsg.data, sizeof(struct - unwind_forwarder)); - SIMPLEQ_INSERT_TAIL(&nconf->unwind_forwarder_list, - unwind_forwarder, entry); + memcpy(uw_forwarder, imsg.data, sizeof(struct + uw_forwarder)); + SIMPLEQ_INSERT_TAIL(&nconf->uw_forwarder_list, + uw_forwarder, entry); break; case IMSG_RECONF_DOT_FORWARDER: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_forwarder)) + sizeof(struct uw_forwarder)) fatalx("%s: IMSG_RECONF_DOT_FORWARDER wrong " "length: %d", __func__, imsg.hdr.len); - if ((unwind_forwarder = malloc(sizeof(struct - unwind_forwarder))) == NULL) + if ((uw_forwarder = malloc(sizeof(struct + uw_forwarder))) == NULL) fatal(NULL); - memcpy(unwind_forwarder, imsg.data, sizeof(struct - unwind_forwarder)); - SIMPLEQ_INSERT_TAIL(&nconf->unwind_dot_forwarder_list, - unwind_forwarder, entry); + memcpy(uw_forwarder, imsg.data, sizeof(struct + uw_forwarder)); + SIMPLEQ_INSERT_TAIL(&nconf->uw_dot_forwarder_list, + uw_forwarder, entry); break; case IMSG_RECONF_END: merge_config(frontend_conf, nconf); @@ -421,8 +425,7 @@ frontend_dispatch_main(int fd, short event, void *bula) __func__); if ((udp6sock = imsg.fd) == -1) fatalx("%s: expected to receive imsg " - "UDP6 fd but didn't receive any", - __func__); + "UDP6 fd but didn't receive any", __func__); event_set(&udp6ev.ev, udp6sock, EV_READ | EV_PERSIST, udp_receive, &udp6ev); event_add(&udp6ev.ev, NULL); @@ -433,8 +436,7 @@ frontend_dispatch_main(int fd, short event, void *bula) __func__); if ((udp4sock = imsg.fd) == -1) fatalx("%s: expected to receive imsg " - "UDP4 fd but didn't receive any", - __func__); + "UDP4 fd but didn't receive any", __func__); event_set(&udp4ev.ev, udp4sock, EV_READ | EV_PERSIST, udp_receive, &udp4ev); event_add(&udp4ev.ev, NULL); @@ -459,9 +461,8 @@ frontend_dispatch_main(int fd, short event, void *bula) fatalx("%s: received unexpected controlsock", __func__); if ((fd = imsg.fd) == -1) - fatalx("%s: expected to receive imsg " - "control fd but didn't receive any", - __func__); + fatalx("%s: expected to receive imsg control " + "fd but didn't receive any", __func__); control_state.fd = fd; /* Listen on control socket. */ TAILQ_INIT(&ctl_conns); @@ -469,9 +470,8 @@ frontend_dispatch_main(int fd, short event, void *bula) break; case IMSG_LEASEFD: if ((fd = imsg.fd) == -1) - fatalx("%s: expected to receive imsg " - "dhcp lease fd but didn't receive any", - __func__); + fatalx("%s: expected to receive imsg dhcp " + "lease fd but didn't receive any", __func__); parse_dhcp_lease(fd); break; case IMSG_TAFD: @@ -622,10 +622,10 @@ frontend_dispatch_resolver(int fd, short event, void *bula) void frontend_dispatch_captiveportal(int fd, short event, void *bula) { - struct imsgev *iev = bula; - struct imsgbuf *ibuf = &iev->ibuf; - struct imsg imsg; - int n, shut = 0; + struct imsgev *iev = bula; + struct imsgbuf *ibuf = &iev->ibuf; + struct imsg imsg; + int n, shut = 0; if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) @@ -786,14 +786,12 @@ udp_receive(int fd, short events, void *arg) free(pq->query); free(pq); } - } void send_answer(struct pending_query *pq, uint8_t *answer, ssize_t len) { - log_debug("result for %s", - ip_port((struct sockaddr*)&pq->from)); + log_debug("result for %s", ip_port((struct sockaddr*)&pq->from)); if (answer == NULL) { answer = pq->query; @@ -820,8 +818,8 @@ send_answer(struct pending_query *pq, uint8_t *answer, ssize_t len) } } - if(sendto(pq->fd, answer, len, 0, (struct sockaddr *) - &pq->from, pq->from.ss_len) == -1) + if(sendto(pq->fd, answer, len, 0, (struct sockaddr *)&pq->from, + pq->from.ss_len) == -1) log_warn("sendto"); TAILQ_REMOVE(&pending_queries, pq, entry); @@ -864,11 +862,11 @@ find_pending_query(uint64_t id) void route_receive(int fd, short events, void *arg) { - static uint8_t *buf; + static uint8_t *buf; - struct rt_msghdr *rtm; - struct sockaddr *sa, *rti_info[RTAX_MAX]; - ssize_t n; + struct rt_msghdr *rtm; + struct sockaddr *sa, *rti_info[RTAX_MAX]; + ssize_t n; if (buf == NULL) { buf = malloc(ROUTE_SOCKET_BUF_SIZE); @@ -955,7 +953,6 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info) default: break; } - } void @@ -1081,7 +1078,6 @@ parse_dhcp_lease(int fd) void add_new_ta(struct trust_anchor_head *tah, char *val) { - struct trust_anchor *ta, *i; int cmp; @@ -1133,7 +1129,7 @@ merge_tas(struct trust_anchor_head *newh, struct trust_anchor_head *oldh) } j = TAILQ_NEXT(j, entry); } - if (j!= NULL) + if (j != NULL) chg = 1; if (chg) { diff --git a/sbin/unwind/printconf.c b/sbin/unwind/printconf.c index 5f544fd8e4f..1e2747e29a0 100644 --- a/sbin/unwind/printconf.c +++ b/sbin/unwind/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.5 2019/02/03 12:02:30 florian Exp $ */ +/* $OpenBSD: printconf.c,v 1.6 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -52,27 +52,26 @@ print_forwarder(char *name) } void -print_config(struct unwind_conf *conf) +print_config(struct uw_conf *conf) { - struct unwind_forwarder *unwind_forwarder; + struct uw_forwarder *uw_forwarder; #if notyet - printf("strict %s\n", yesno(conf->unwind_options)); + printf("strict %s\n", yesno(conf->uw_options)); #endif - if (!SIMPLEQ_EMPTY(&conf->unwind_forwarder_list) || - !SIMPLEQ_EMPTY(&conf->unwind_dot_forwarder_list)) { + if (!SIMPLEQ_EMPTY(&conf->uw_forwarder_list) || + !SIMPLEQ_EMPTY(&conf->uw_dot_forwarder_list)) { printf("forwarder {\n"); - SIMPLEQ_FOREACH(unwind_forwarder, &conf->unwind_forwarder_list, - entry) { + SIMPLEQ_FOREACH(uw_forwarder, &conf->uw_forwarder_list, entry) { printf("\t"); - print_forwarder(unwind_forwarder->name); + print_forwarder(uw_forwarder->name); printf("\n"); } - SIMPLEQ_FOREACH(unwind_forwarder, - &conf->unwind_dot_forwarder_list, entry) { + SIMPLEQ_FOREACH(uw_forwarder, &conf->uw_dot_forwarder_list, + entry) { printf("\t"); - print_forwarder(unwind_forwarder->name); + print_forwarder(uw_forwarder->name); printf(" DoT\n"); } printf("}\n"); @@ -80,8 +79,8 @@ print_config(struct unwind_conf *conf) if (conf->captive_portal_host != NULL) { printf("captive portal {\n"); - printf("\turl \"http://%s%s\"\n", - conf->captive_portal_host, conf->captive_portal_path); + printf("\turl \"http://%s%s\"\n", conf->captive_portal_host, + conf->captive_portal_path); printf("\texpected status %d\n", conf->captive_portal_expected_status); if (conf->captive_portal_expected_response != NULL) diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c index c12f43561d0..44e738a51d7 100644 --- a/sbin/unwind/resolver.c +++ b/sbin/unwind/resolver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolver.c,v 1.16 2019/02/07 17:20:35 florian Exp $ */ +/* $OpenBSD: resolver.c,v 1.17 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -56,33 +56,33 @@ #include "unwind.h" #include "resolver.h" -#define UB_LOG_VERBOSE 4 -#define UB_LOG_BRIEF 0 +#define UB_LOG_VERBOSE 4 +#define UB_LOG_BRIEF 0 /* don't cause churn when trust anchor comes from a cache */ -#define ROOT_DNSKEY_TTL 172800 +#define ROOT_DNSKEY_TTL 172800 -#define PORTAL_CHECK_SEC 15 -#define PORTAL_CHECK_MAXSEC 600 +#define PORTAL_CHECK_SEC 15 +#define PORTAL_CHECK_MAXSEC 600 -#define TRUST_ANCHOR_RETRY_INTERVAL 8640 +#define TRUST_ANCHOR_RETRY_INTERVAL 8640 #define TRUST_ANCHOR_QUERY_INTERVAL 43200 -struct unwind_resolver { - struct event check_ev; - struct event free_ev; - struct ub_ctx *ctx; - int ref_cnt; - int stop; - enum unwind_resolver_state state; - enum unwind_resolver_type type; - char *why_bogus; - int64_t histogram[nitems(histogram_limits)]; +struct uw_resolver { + struct event check_ev; + struct event free_ev; + struct ub_ctx *ctx; + int ref_cnt; + int stop; + enum uw_resolver_state state; + enum uw_resolver_type type; + char *why_bogus; + int64_t histogram[nitems(histogram_limits)]; }; struct check_resolver_data { - struct unwind_resolver *res; - struct unwind_resolver *check_res; + struct uw_resolver *res; + struct uw_resolver *check_res; }; __dead void resolver_shutdown(void); @@ -90,46 +90,44 @@ void resolver_sig_handler(int sig, short, void *); void resolver_dispatch_frontend(int, short, void *); void resolver_dispatch_captiveportal(int, short, void *); void resolver_dispatch_main(int, short, void *); -void resolve_done(void *, int, void *, int, int, - char *, int); +void resolve_done(void *, int, void *, int, int, char *, + int); void parse_dhcp_forwarders(char *); void new_recursor(void); void new_forwarders(void); void new_static_forwarders(void); void new_static_dot_forwarders(void); -struct unwind_resolver *create_resolver(enum unwind_resolver_type); -void free_resolver(struct unwind_resolver *); -void set_forwarders(struct unwind_resolver *, - struct unwind_forwarder_head *); +struct uw_resolver *create_resolver(enum uw_resolver_type); +void free_resolver(struct uw_resolver *); +void set_forwarders(struct uw_resolver *, + struct uw_forwarder_head *); void resolver_check_timo(int, short, void *); void resolver_free_timo(int, short, void *); -void check_resolver(struct unwind_resolver *); +void check_resolver(struct uw_resolver *); void check_resolver_done(void *, int, void *, int, int, char *, int); -int check_forwarders_changed(struct - unwind_forwarder_head *, - struct unwind_forwarder_head *); -void replace_forwarders(struct unwind_forwarder_head *, - struct unwind_forwarder_head *); -void resolver_ref(struct unwind_resolver *); -void resolver_unref(struct unwind_resolver *); -struct unwind_resolver *best_resolver(void); -int resolver_cmp(struct unwind_resolver *, - struct unwind_resolver *); +int check_forwarders_changed(struct uw_forwarder_head *, + struct uw_forwarder_head *); +void replace_forwarders(struct uw_forwarder_head *, + struct uw_forwarder_head *); +void resolver_ref(struct uw_resolver *); +void resolver_unref(struct uw_resolver *); +struct uw_resolver *best_resolver(void); +int resolver_cmp(struct uw_resolver *, + struct uw_resolver *); void restart_resolvers(void); -void show_status(enum unwind_resolver_type, pid_t); -void send_resolver_info(struct unwind_resolver *, int, +void show_status(enum uw_resolver_type, pid_t); +void send_resolver_info(struct uw_resolver *, int, pid_t); +void send_detailed_resolver_info(struct uw_resolver *, pid_t); -void send_detailed_resolver_info(struct unwind_resolver *, +void send_resolver_histogram_info(struct uw_resolver *, pid_t); -void send_resolver_histogram_info(struct unwind_resolver *, - pid_t pid); void check_captive_portal(int); void check_captive_portal_timo(int, short, void *); void check_captive_portal_resolve_done(void *, int, void *, int, int, char *, int); -int check_captive_portal_changed(struct unwind_conf *, - struct unwind_conf *); +int check_captive_portal_changed(struct uw_conf *, + struct uw_conf *); void trust_anchor_resolve(void); void trust_anchor_timo(int, short, void *); void trust_anchor_resolve_done(void *, int, void *, int, @@ -140,28 +138,29 @@ void init_locks(void); unsigned long id_callback(void); void lock_callback(int, int, const char *, int); -struct unwind_conf *resolver_conf; -struct imsgev *iev_frontend; -struct imsgev *iev_captiveportal; -struct imsgev *iev_main; -struct unwind_forwarder_head dhcp_forwarder_list; -struct unwind_resolver *recursor, *forwarder, *static_forwarder; -struct unwind_resolver *static_dot_forwarder; -struct timeval resolver_check_pause = { 30, 0}; +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_resolver *recursor, *forwarder, *static_forwarder; +struct uw_resolver *static_dot_forwarder; +struct timeval resolver_check_pause = { 30, 0}; -struct timeval captive_portal_check_tv = {PORTAL_CHECK_SEC, 0}; -struct event captive_portal_check_ev; +struct timeval captive_portal_check_tv = + {PORTAL_CHECK_SEC, 0}; +struct event captive_portal_check_ev; -struct event trust_anchor_timer; +struct event trust_anchor_timer; static struct trust_anchor_head trust_anchors, new_trust_anchors; -struct event_base *ev_base; +struct event_base *ev_base; /* for openssl */ -pthread_mutex_t *locks; +pthread_mutex_t *locks; -enum unwind_resolver_state global_state = DEAD; +enum uw_resolver_state global_state = DEAD; enum captive_portal_state captive_portal_state = PORTAL_UNCHECKED; void @@ -200,9 +199,9 @@ resolver(int debug, int verbose) if (chdir("/") == -1) fatal("chdir(\"/\")"); - unwind_process = PROC_RESOLVER; - setproctitle("%s", log_procnames[unwind_process]); - log_procinit(log_procnames[unwind_process]); + uw_process = PROC_RESOLVER; + setproctitle("%s", log_procnames[uw_process]); + log_procinit(log_procnames[uw_process]); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || @@ -279,12 +278,12 @@ resolver_shutdown(void) int resolver_imsg_compose_main(int type, pid_t pid, void *data, uint16_t datalen) { - return (imsg_compose_event(iev_main, type, 0, pid, -1, data, - datalen)); + return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen)); } int -resolver_imsg_compose_frontend(int type, pid_t pid, void *data, uint16_t datalen) +resolver_imsg_compose_frontend(int type, pid_t pid, void *data, + uint16_t datalen) { return (imsg_compose_event(iev_frontend, type, 0, pid, -1, data, datalen)); @@ -301,16 +300,16 @@ resolver_imsg_compose_captiveportal(int type, pid_t pid, void *data, void resolver_dispatch_frontend(int fd, short event, void *bula) { - struct imsgev *iev = bula; - struct imsgbuf *ibuf; - struct imsg imsg; - struct query_imsg *query_imsg; - struct unwind_resolver *res; - enum unwind_resolver_type type; - ssize_t n; - int shut = 0, verbose, err; - int update_resolvers; - char *ta; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; + struct imsg imsg; + struct query_imsg *query_imsg; + struct uw_resolver *res; + enum uw_resolver_type type; + ssize_t n; + int shut = 0, verbose, err; + int update_resolvers; + char *ta; ibuf = &iev->ibuf; @@ -366,7 +365,7 @@ resolver_dispatch_frontend(int fd, short event, void *bula) } log_debug("%s: choosing %s", __func__, - unwind_resolver_type_str[res->type]); + uw_resolver_type_str[res->type]); query_imsg->resolver = res; resolver_ref(res); @@ -437,11 +436,11 @@ resolver_dispatch_frontend(int fd, short event, void *bula) void resolver_dispatch_captiveportal(int fd, short event, void *bula) { - struct imsgev *iev = bula; - struct imsgbuf *ibuf; - struct imsg imsg; - ssize_t n; - int shut = 0; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; + struct imsg imsg; + ssize_t n; + int shut = 0; ibuf = &iev->ibuf; @@ -499,15 +498,15 @@ resolver_dispatch_captiveportal(int fd, short event, void *bula) void resolver_dispatch_main(int fd, short event, void *bula) { - static struct unwind_conf *nconf; - struct unwind_forwarder *unwind_forwarder; - struct imsg imsg; - struct imsgev *iev = bula; - struct imsgbuf *ibuf; - ssize_t n; - int shut = 0, forwarders_changed; - int dot_forwarders_changed; - int captive_portal_changed; + static struct uw_conf *nconf; + struct uw_forwarder *uw_forwarder; + struct imsg imsg; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; + ssize_t n; + int shut = 0, forwarders_changed; + int dot_forwarders_changed; + int captive_portal_changed; ibuf = &iev->ibuf; @@ -591,17 +590,17 @@ resolver_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_CONF: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_conf)) + sizeof(struct uw_conf)) fatalx("%s: IMSG_RECONF_CONF wrong length: %d", __func__, imsg.hdr.len); - if ((nconf = malloc(sizeof(struct unwind_conf))) == NULL) + if ((nconf = malloc(sizeof(struct uw_conf))) == NULL) fatal(NULL); - memcpy(nconf, imsg.data, sizeof(struct unwind_conf)); + memcpy(nconf, imsg.data, sizeof(struct uw_conf)); nconf->captive_portal_host = NULL; nconf->captive_portal_path = NULL; nconf->captive_portal_expected_response = NULL; - SIMPLEQ_INIT(&nconf->unwind_forwarder_list); - SIMPLEQ_INIT(&nconf->unwind_dot_forwarder_list); + SIMPLEQ_INIT(&nconf->uw_forwarder_list); + SIMPLEQ_INIT(&nconf->uw_dot_forwarder_list); break; case IMSG_RECONF_CAPTIVE_PORTAL_HOST: /* make sure this is a string */ @@ -629,37 +628,37 @@ resolver_dispatch_main(int fd, short event, void *bula) break; case IMSG_RECONF_FORWARDER: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_forwarder)) + sizeof(struct uw_forwarder)) fatalx("%s: IMSG_RECONF_FORWARDER wrong length:" " %d", __func__, imsg.hdr.len); - if ((unwind_forwarder = malloc(sizeof(struct - unwind_forwarder))) == NULL) + if ((uw_forwarder = malloc(sizeof(struct + uw_forwarder))) == NULL) fatal(NULL); - memcpy(unwind_forwarder, imsg.data, sizeof(struct - unwind_forwarder)); - SIMPLEQ_INSERT_TAIL(&nconf->unwind_forwarder_list, - unwind_forwarder, entry); + memcpy(uw_forwarder, imsg.data, sizeof(struct + uw_forwarder)); + SIMPLEQ_INSERT_TAIL(&nconf->uw_forwarder_list, + uw_forwarder, entry); break; case IMSG_RECONF_DOT_FORWARDER: if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct unwind_forwarder)) + sizeof(struct uw_forwarder)) fatalx("%s: IMSG_RECONF_DOT_FORWARDER wrong " "length: %d", __func__, imsg.hdr.len); - if ((unwind_forwarder = malloc(sizeof(struct - unwind_forwarder))) == NULL) + if ((uw_forwarder = malloc(sizeof(struct + uw_forwarder))) == NULL) fatal(NULL); - memcpy(unwind_forwarder, imsg.data, sizeof(struct - unwind_forwarder)); - SIMPLEQ_INSERT_TAIL(&nconf->unwind_dot_forwarder_list, - unwind_forwarder, entry); + memcpy(uw_forwarder, imsg.data, sizeof(struct + uw_forwarder)); + SIMPLEQ_INSERT_TAIL(&nconf->uw_dot_forwarder_list, + uw_forwarder, entry); break; case IMSG_RECONF_END: forwarders_changed = check_forwarders_changed( - &resolver_conf->unwind_forwarder_list, - &nconf->unwind_forwarder_list); + &resolver_conf->uw_forwarder_list, + &nconf->uw_forwarder_list); dot_forwarders_changed = check_forwarders_changed( - &resolver_conf->unwind_dot_forwarder_list, - &nconf->unwind_dot_forwarder_list); + &resolver_conf->uw_dot_forwarder_list, + &nconf->uw_dot_forwarder_list); captive_portal_changed = check_captive_portal_changed( resolver_conf, nconf); merge_config(resolver_conf, nconf); @@ -701,7 +700,7 @@ resolve_done(void *arg, int rcode, void *answer_packet, int answer_len, int sec, char *why_bogus, int was_ratelimited) { struct query_imsg *query_imsg; - struct unwind_resolver *res; + struct uw_resolver *res; struct timespec tp, elapsed; int64_t ms; size_t i; @@ -710,7 +709,7 @@ resolve_done(void *arg, int rcode, void *answer_packet, int answer_len, clock_gettime(CLOCK_MONOTONIC, &tp); query_imsg = (struct query_imsg *)arg; - res = (struct unwind_resolver *)query_imsg->resolver; + res = (struct uw_resolver *)query_imsg->resolver; timespecsub(&tp, &query_imsg->tp, &elapsed); @@ -766,8 +765,8 @@ resolve_done(void *arg, int rcode, void *answer_packet, int answer_len, servfail: query_imsg->err = -4; /* UB_SERVFAIL */ - resolver_imsg_compose_frontend(IMSG_ANSWER_HEADER, 0, - query_imsg, sizeof(*query_imsg)); + resolver_imsg_compose_frontend(IMSG_ANSWER_HEADER, 0, query_imsg, + sizeof(*query_imsg)); free(query_imsg); resolver_unref(res); } @@ -775,8 +774,8 @@ servfail: void parse_dhcp_forwarders(char *resolvers) { - struct unwind_forwarder_head new_forwarder_list; - struct unwind_forwarder *unwind_forwarder; + struct uw_forwarder_head new_forwarder_list; + struct uw_forwarder *uw_forwarder; char *ns; SIMPLEQ_INIT(&new_forwarder_list); @@ -784,15 +783,15 @@ parse_dhcp_forwarders(char *resolvers) if (resolvers != NULL) { while((ns = strsep(&resolvers, ",")) != NULL) { log_debug("%s: %s", __func__, ns); - if ((unwind_forwarder = malloc(sizeof(struct - unwind_forwarder))) == NULL) + if ((uw_forwarder = malloc(sizeof(struct + uw_forwarder))) == NULL) fatal(NULL); - if (strlcpy(unwind_forwarder->name, ns, - sizeof(unwind_forwarder->name)) >= - sizeof(unwind_forwarder->name)) + if (strlcpy(uw_forwarder->name, ns, + sizeof(uw_forwarder->name)) >= + sizeof(uw_forwarder->name)) fatalx("strlcpy"); - SIMPLEQ_INSERT_TAIL(&new_forwarder_list, - unwind_forwarder, entry); + SIMPLEQ_INSERT_TAIL(&new_forwarder_list, uw_forwarder, + entry); } } @@ -844,7 +843,7 @@ new_static_forwarders(void) free_resolver(static_forwarder); static_forwarder = NULL; - if (SIMPLEQ_EMPTY(&resolver_conf->unwind_forwarder_list)) + if (SIMPLEQ_EMPTY(&resolver_conf->uw_forwarder_list)) return; if (TAILQ_EMPTY(&trust_anchors)) @@ -852,7 +851,7 @@ new_static_forwarders(void) log_debug("%s: create_resolver", __func__); static_forwarder = create_resolver(STATIC_FORWARDER); - set_forwarders(static_forwarder, &resolver_conf->unwind_forwarder_list); + set_forwarders(static_forwarder, &resolver_conf->uw_forwarder_list); check_resolver(static_forwarder); } @@ -863,7 +862,7 @@ new_static_dot_forwarders(void) free_resolver(static_dot_forwarder); static_dot_forwarder = NULL; - if (SIMPLEQ_EMPTY(&resolver_conf->unwind_dot_forwarder_list)) + if (SIMPLEQ_EMPTY(&resolver_conf->uw_dot_forwarder_list)) return; if (TAILQ_EMPTY(&trust_anchors)) @@ -872,18 +871,18 @@ new_static_dot_forwarders(void) log_debug("%s: create_resolver", __func__); static_dot_forwarder = create_resolver(STATIC_DOT_FORWARDER); set_forwarders(static_dot_forwarder, - &resolver_conf->unwind_dot_forwarder_list); + &resolver_conf->uw_dot_forwarder_list); ub_ctx_set_tls(static_dot_forwarder->ctx, 1); check_resolver(static_dot_forwarder); } -struct unwind_resolver * -create_resolver(enum unwind_resolver_type type) +struct uw_resolver * +create_resolver(enum uw_resolver_type type) { - struct unwind_resolver *res; + struct uw_resolver *res; struct trust_anchor *ta; - int err; + int err; if ((res = calloc(1, sizeof(*res))) == NULL) { log_warn("%s", __func__); @@ -941,7 +940,7 @@ create_resolver(enum unwind_resolver_type type) } void -free_resolver(struct unwind_resolver *res) +free_resolver(struct uw_resolver *res) { if (res == NULL) return; @@ -959,31 +958,31 @@ free_resolver(struct unwind_resolver *res) } void -set_forwarders(struct unwind_resolver *res, struct unwind_forwarder_head - *unwind_forwarder_list) +set_forwarders(struct uw_resolver *res, struct uw_forwarder_head + *uw_forwarder_list) { - struct unwind_forwarder *unwind_forwarder; + struct uw_forwarder *uw_forwarder; - SIMPLEQ_FOREACH(unwind_forwarder, unwind_forwarder_list, entry) - ub_ctx_set_fwd(res->ctx, unwind_forwarder->name); + SIMPLEQ_FOREACH(uw_forwarder, uw_forwarder_list, entry) + ub_ctx_set_fwd(res->ctx, uw_forwarder->name); } void resolver_check_timo(int fd, short events, void *arg) { - check_resolver((struct unwind_resolver *)arg); + check_resolver((struct uw_resolver *)arg); } void resolver_free_timo(int fd, short events, void *arg) { - free_resolver((struct unwind_resolver *)arg); + free_resolver((struct uw_resolver *)arg); } void -check_resolver(struct unwind_resolver *res) +check_resolver(struct uw_resolver *res) { - struct unwind_resolver *check_res; + struct uw_resolver *check_res; struct check_resolver_data *data; int err; @@ -1000,12 +999,11 @@ check_resolver(struct unwind_resolver *res) set_forwarders(check_res, &dhcp_forwarder_list); break; case STATIC_FORWARDER: - set_forwarders(check_res, - &resolver_conf->unwind_forwarder_list); + set_forwarders(check_res, &resolver_conf->uw_forwarder_list); break; case STATIC_DOT_FORWARDER: set_forwarders(check_res, - &resolver_conf->unwind_dot_forwarder_list); + &resolver_conf->uw_dot_forwarder_list); ub_ctx_set_tls(check_res->ctx, 1); break; case RESOLVER_NONE: @@ -1021,8 +1019,8 @@ check_resolver(struct unwind_resolver *res) if ((err = ub_resolve_event(check_res->ctx, ".", LDNS_RR_TYPE_NS, LDNS_RR_CLASS_IN, data, check_resolver_done, NULL)) != 0) { - log_warn("%s: ub_resolve_event: err: %d, %s", - __func__, err, ub_strerror(err)); + log_warn("%s: ub_resolve_event: err: %d, %s", __func__, err, + ub_strerror(err)); resolver_unref(check_res); resolver_unref(res); evtimer_add(&res->check_ev, &resolver_check_pause); @@ -1034,7 +1032,7 @@ check_resolver_done(void *arg, int rcode, void *answer_packet, int answer_len, int sec, char *why_bogus, int was_ratelimited) { struct check_resolver_data *data; - struct unwind_resolver *best; + struct uw_resolver *best; struct timeval tv = {0, 1}; char *str; @@ -1076,8 +1074,8 @@ out: evtimer_add(&data->res->check_ev, &resolver_check_pause); log_debug("%s: %s: %s", __func__, - unwind_resolver_type_str[data->res->type], - unwind_resolver_state_str[data->res->state]); + uw_resolver_type_str[data->res->type], + uw_resolver_state_str[data->res->state]); log_debug("%s: %p - %p", __func__, data->res, data->res->ctx); @@ -1130,10 +1128,10 @@ lock_callback(int mode, int type, const char *file, int line) } int -check_forwarders_changed(struct unwind_forwarder_head *list_a, - struct unwind_forwarder_head *list_b) +check_forwarders_changed(struct uw_forwarder_head *list_a, + struct uw_forwarder_head *list_b) { - struct unwind_forwarder *a, *b; + struct uw_forwarder *a, *b; a = SIMPLEQ_FIRST(list_a); b = SIMPLEQ_FIRST(list_b); @@ -1152,7 +1150,7 @@ check_forwarders_changed(struct unwind_forwarder_head *list_a, } void -resolver_ref(struct unwind_resolver *res) +resolver_ref(struct uw_resolver *res) { if (res->ref_cnt == INT_MAX) fatalx("%s: INT_MAX references", __func__); @@ -1160,7 +1158,7 @@ resolver_ref(struct unwind_resolver *res) } void -resolver_unref(struct unwind_resolver *res) +resolver_unref(struct uw_resolver *res) { struct timeval tv = { 0, 1}; @@ -1182,47 +1180,47 @@ resolver_unref(struct unwind_resolver *res) } void -replace_forwarders(struct unwind_forwarder_head *new_list, struct - unwind_forwarder_head *old_list) +replace_forwarders(struct uw_forwarder_head *new_list, struct + uw_forwarder_head *old_list) { - struct unwind_forwarder *unwind_forwarder; + struct uw_forwarder *uw_forwarder; - while ((unwind_forwarder = + while ((uw_forwarder = SIMPLEQ_FIRST(old_list)) != NULL) { SIMPLEQ_REMOVE_HEAD(old_list, entry); - free(unwind_forwarder); + free(uw_forwarder); } - while ((unwind_forwarder = SIMPLEQ_FIRST(new_list)) != NULL) { + while ((uw_forwarder = SIMPLEQ_FIRST(new_list)) != NULL) { SIMPLEQ_REMOVE_HEAD(new_list, entry); - SIMPLEQ_INSERT_TAIL(old_list, unwind_forwarder, entry); + SIMPLEQ_INSERT_TAIL(old_list, uw_forwarder, entry); } } -struct unwind_resolver* +struct uw_resolver* best_resolver(void) { - struct unwind_resolver *res = NULL; + struct uw_resolver *res = NULL; if (recursor != NULL) log_debug("%s: %s state: %s", __func__, - unwind_resolver_type_str[recursor->type], - unwind_resolver_state_str[recursor->state]); + uw_resolver_type_str[recursor->type], + uw_resolver_state_str[recursor->state]); if (static_forwarder != NULL) log_debug("%s: %s state: %s", __func__, - unwind_resolver_type_str[static_forwarder->type], - unwind_resolver_state_str[static_forwarder->state]); + uw_resolver_type_str[static_forwarder->type], + uw_resolver_state_str[static_forwarder->state]); if (static_dot_forwarder != NULL) log_debug("%s: %s state: %s", __func__, - unwind_resolver_type_str[static_dot_forwarder->type], - unwind_resolver_state_str[static_dot_forwarder->state]); + uw_resolver_type_str[static_dot_forwarder->type], + uw_resolver_state_str[static_dot_forwarder->state]); if (forwarder != NULL) log_debug("%s: %s state: %s", __func__, - unwind_resolver_type_str[forwarder->type], - unwind_resolver_state_str[forwarder->state]); + uw_resolver_type_str[forwarder->type], + uw_resolver_state_str[forwarder->state]); log_debug("%s: %s captive portal", __func__, captive_portal_state_str[ captive_portal_state]); @@ -1247,9 +1245,8 @@ best_resolver(void) } int -resolver_cmp(struct unwind_resolver *a, struct unwind_resolver *b) +resolver_cmp(struct uw_resolver *a, struct uw_resolver *b) { - if (a == NULL && b == NULL) return 0; @@ -1277,9 +1274,9 @@ restart_resolvers(void) } void -show_status(enum unwind_resolver_type type, pid_t pid) +show_status(enum uw_resolver_type type, pid_t pid) { - struct unwind_resolver *best; + struct uw_resolver *best; best = best_resolver(); @@ -1317,9 +1314,10 @@ show_status(enum unwind_resolver_type type, pid_t pid) } void -send_resolver_info(struct unwind_resolver *res, int selected, pid_t pid) +send_resolver_info(struct uw_resolver *res, int selected, pid_t pid) { struct ctl_resolver_info cri; + if (res == NULL) return; @@ -1331,7 +1329,7 @@ send_resolver_info(struct unwind_resolver *res, int selected, pid_t pid) } void -send_detailed_resolver_info(struct unwind_resolver *res, pid_t pid) +send_detailed_resolver_info(struct uw_resolver *res, pid_t pid) { char buf[1024]; @@ -1347,7 +1345,7 @@ send_detailed_resolver_info(struct unwind_resolver *res, pid_t pid) } void -send_resolver_histogram_info(struct unwind_resolver *res, pid_t pid) +send_resolver_histogram_info(struct uw_resolver *res, pid_t pid) { int64_t histogram[nitems(histogram_limits)]; @@ -1369,7 +1367,7 @@ check_captive_portal_timo(int fd, short events, void *arg) void check_captive_portal(int timer_reset) { - struct unwind_resolver *res; + struct uw_resolver *res; int err; log_debug("%s", __func__); @@ -1399,18 +1397,17 @@ check_captive_portal(int timer_reset) resolver_conf->captive_portal_host, LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, res, check_captive_portal_resolve_done, NULL)) != 0) { - log_warn("%s: ub_resolve_async: err: %d, %s", - __func__, err, ub_strerror(err)); + log_warn("%s: ub_resolve_async: err: %d, %s", __func__, err, + ub_strerror(err)); resolver_unref(res); } - } void check_captive_portal_resolve_done(void *arg, int rcode, void *answer_packet, int answer_len, int sec, char *why_bogus, int was_ratelimited) { - struct unwind_resolver *res; + struct uw_resolver *res; struct ub_result *result; sldns_buffer *buf; struct regional *region; @@ -1418,7 +1415,7 @@ check_captive_portal_resolve_done(void *arg, int rcode, void *answer_packet, int i; char *str, rdata_buf[sizeof("XXX.XXX.XXX.XXX")]; - res = (struct unwind_resolver *)arg; + res = (struct uw_resolver *)arg; if ((result = calloc(1, sizeof(*result))) == NULL) goto out; @@ -1472,7 +1469,7 @@ out: } int -check_captive_portal_changed(struct unwind_conf *a, struct unwind_conf *b) +check_captive_portal_changed(struct uw_conf *a, struct uw_conf *b) { if (a->captive_portal_expected_status != @@ -1508,13 +1505,12 @@ check_captive_portal_changed(struct unwind_conf *a, struct unwind_conf *b) return (1); return (0); - } void trust_anchor_resolve(void) { - struct unwind_resolver *res; + struct uw_resolver *res; struct timeval tv = {TRUST_ANCHOR_RETRY_INTERVAL, 0}; int err; @@ -1549,7 +1545,7 @@ void trust_anchor_resolve_done(void *arg, int rcode, void *answer_packet, int answer_len, int sec, char *why_bogus, int was_ratelimited) { - struct unwind_resolver *res; + struct uw_resolver *res; struct ub_result *result; sldns_buffer *buf; struct regional *region; @@ -1558,7 +1554,7 @@ trust_anchor_resolve_done(void *arg, int rcode, void *answer_packet, uint16_t dnskey_flags; char *str, rdata_buf[1024], *ta; - res = (struct unwind_resolver *)arg; + res = (struct uw_resolver *)arg; if ((result = calloc(1, sizeof(*result))) == NULL) goto out; diff --git a/sbin/unwind/resolver.h b/sbin/unwind/resolver.h index 2265e3c7ec1..cf1c590dd6e 100644 --- a/sbin/unwind/resolver.h +++ b/sbin/unwind/resolver.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolver.h,v 1.3 2019/02/03 12:02:30 florian Exp $ */ +/* $OpenBSD: resolver.h,v 1.4 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -17,21 +17,21 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -enum unwind_resolver_state { +enum uw_resolver_state { DEAD, UNKNOWN, RESOLVING, VALIDATING }; -static const char * const unwind_resolver_state_str[] = { +static const char * const uw_resolver_state_str[] = { "dead", "unknown", "resolving", "validating" }; -enum unwind_resolver_type { +enum uw_resolver_type { RECURSOR, FORWARDER, STATIC_FORWARDER, @@ -39,7 +39,7 @@ enum unwind_resolver_type { RESOLVER_NONE = -1 }; -static const char * const unwind_resolver_type_str[] = { +static const char * const uw_resolver_type_str[] = { "recursor", "dhcp forwarder", "static forwarder", @@ -63,9 +63,9 @@ static const int64_t histogram_limits[] = { }; struct ctl_resolver_info { - enum unwind_resolver_state state; - enum unwind_resolver_type type; - int selected; + enum uw_resolver_state state; + enum uw_resolver_type type; + int selected; }; void resolver(int, int); diff --git a/sbin/unwind/unwind.c b/sbin/unwind/unwind.c index 433a27a1e5f..f54fa8958a3 100644 --- a/sbin/unwind/unwind.c +++ b/sbin/unwind/unwind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unwind.c,v 1.14 2019/02/11 13:38:53 florian Exp $ */ +/* $OpenBSD: unwind.c,v 1.15 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -48,42 +48,42 @@ #include "control.h" #include "captiveportal.h" -#define LEASE_DB_DIR "/var/db/" -#define _PATH_LEASE_DB "/var/db/dhclient.leases." +#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); __dead void main_shutdown(void); -void main_sig_handler(int, short, void *); +void main_sig_handler(int, short, void *); static pid_t start_child(int, char *, int, int, int); -void main_dispatch_frontend(int, short, void *); -void main_dispatch_resolver(int, short, void *); -void main_dispatch_captiveportal(int, short, void *); +void main_dispatch_frontend(int, short, void *); +void main_dispatch_resolver(int, short, void *); +void main_dispatch_captiveportal(int, short, void *); static int main_imsg_send_ipc_sockets(struct imsgbuf *, struct imsgbuf *, struct imsgbuf *); -static int main_imsg_send_config(struct unwind_conf *); +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); +int main_reload(void); +int main_sendall(enum imsg_type, void *, uint16_t); +void open_dhcp_lease(int); +void open_ports(void); -struct unwind_conf *main_conf; -struct imsgev *iev_frontend; -struct imsgev *iev_resolver; -struct imsgev *iev_captiveportal; -char *conffile; +struct uw_conf *main_conf; +struct imsgev *iev_frontend; +struct imsgev *iev_resolver; +struct imsgev *iev_captiveportal; +char *conffile; -pid_t frontend_pid; -pid_t resolver_pid; -pid_t captiveportal_pid; +pid_t frontend_pid; +pid_t resolver_pid; +pid_t captiveportal_pid; -uint32_t cmd_opts; +uint32_t cmd_opts; void main_sig_handler(int sig, short event, void *arg) @@ -122,17 +122,13 @@ usage(void) int main(int argc, char *argv[]) { - struct event ev_sigint, ev_sigterm, ev_sighup; - int ch; - int debug = 0, resolver_flag = 0; - int frontend_flag = 0, captiveportal_flag = 0; - char *saved_argv0; - int pipe_main2frontend[2]; - int pipe_main2resolver[2]; - int pipe_main2captiveportal[2]; - int frontend_routesock, rtfilter; - int control_fd, ta_fd; - char *csock; + struct event ev_sigint, ev_sigterm, ev_sighup; + int ch, debug = 0, resolver_flag = 0, frontend_flag = 0; + int captiveportal_flag = 0, frontend_routesock, rtfilter; + int pipe_main2frontend[2], pipe_main2resolver[2]; + int pipe_main2captiveportal[2]; + int control_fd, ta_fd; + char *csock, *saved_argv0; conffile = CONF_FILE; csock = UNWIND_SOCKET; @@ -237,8 +233,8 @@ main(int argc, char *argv[]) pipe_main2captiveportal[1], debug, cmd_opts & (OPT_VERBOSE | OPT_VERBOSE2)); - unwind_process = PROC_MAIN; - log_procinit(log_procnames[unwind_process]); + uw_process = PROC_MAIN; + log_procinit(log_procnames[uw_process]); event_init(); @@ -271,8 +267,8 @@ main(int argc, char *argv[]) event_add(&iev_frontend->ev, NULL); iev_resolver->events = EV_READ; - event_set(&iev_resolver->ev, iev_resolver->ibuf.fd, iev_resolver->events, - iev_resolver->handler, iev_resolver); + event_set(&iev_resolver->ev, iev_resolver->ibuf.fd, + iev_resolver->events, iev_resolver->handler, iev_resolver); event_add(&iev_resolver->ev, NULL); iev_captiveportal->events = EV_READ; @@ -408,12 +404,12 @@ start_child(int p, char *argv0, int fd, int debug, int verbose) void main_dispatch_frontend(int fd, short event, void *bula) { - struct imsgev *iev = bula; - struct imsgbuf *ibuf; - struct imsg imsg; - ssize_t n; - int shut = 0, verbose; - u_short rtm_index; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; + struct imsg imsg; + ssize_t n; + int shut = 0, verbose; + u_short rtm_index; ibuf = &iev->ibuf; @@ -710,7 +706,7 @@ main_imsg_send_ipc_sockets(struct imsgbuf *frontend_buf, int main_reload(void) { - struct unwind_conf *xconf; + struct uw_conf *xconf; if ((xconf = parse_config(conffile)) == NULL) return (-1); @@ -724,9 +720,9 @@ main_reload(void) } int -main_imsg_send_config(struct unwind_conf *xconf) +main_imsg_send_config(struct uw_conf *xconf) { - struct unwind_forwarder *unwind_forwarder; + struct uw_forwarder *uw_forwarder; /* Send fixed part of config to children. */ if (main_sendall(IMSG_RECONF_CONF, xconf, sizeof(*xconf)) == -1) @@ -754,17 +750,17 @@ main_imsg_send_config(struct unwind_conf *xconf) } /* send static forwarders to children */ - SIMPLEQ_FOREACH(unwind_forwarder, &xconf->unwind_forwarder_list, entry) { - if (main_sendall(IMSG_RECONF_FORWARDER, unwind_forwarder, - sizeof(*unwind_forwarder)) == -1) + SIMPLEQ_FOREACH(uw_forwarder, &xconf->uw_forwarder_list, entry) { + if (main_sendall(IMSG_RECONF_FORWARDER, uw_forwarder, + sizeof(*uw_forwarder)) == -1) return (-1); } /* send static DoT forwarders to children */ - SIMPLEQ_FOREACH(unwind_forwarder, &xconf->unwind_dot_forwarder_list, + SIMPLEQ_FOREACH(uw_forwarder, &xconf->uw_dot_forwarder_list, entry) { - if (main_sendall(IMSG_RECONF_DOT_FORWARDER, unwind_forwarder, - sizeof(*unwind_forwarder)) == -1) + if (main_sendall(IMSG_RECONF_DOT_FORWARDER, uw_forwarder, + sizeof(*uw_forwarder)) == -1) return (-1); } @@ -789,23 +785,23 @@ main_sendall(enum imsg_type type, void *buf, uint16_t len) } void -merge_config(struct unwind_conf *conf, struct unwind_conf *xconf) +merge_config(struct uw_conf *conf, struct uw_conf *xconf) { - struct unwind_forwarder *unwind_forwarder; + struct uw_forwarder *uw_forwarder; /* Remove & discard existing forwarders. */ - while ((unwind_forwarder = - SIMPLEQ_FIRST(&conf->unwind_forwarder_list)) != NULL) { - SIMPLEQ_REMOVE_HEAD(&conf->unwind_forwarder_list, entry); - free(unwind_forwarder); + while ((uw_forwarder = SIMPLEQ_FIRST(&conf->uw_forwarder_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&conf->uw_forwarder_list, entry); + free(uw_forwarder); } - while ((unwind_forwarder = - SIMPLEQ_FIRST(&conf->unwind_dot_forwarder_list)) != NULL) { - SIMPLEQ_REMOVE_HEAD(&conf->unwind_dot_forwarder_list, entry); - free(unwind_forwarder); + while ((uw_forwarder = SIMPLEQ_FIRST(&conf->uw_dot_forwarder_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&conf->uw_dot_forwarder_list, entry); + free(uw_forwarder); } - conf->unwind_options = xconf->unwind_options; + conf->uw_options = xconf->uw_options; free(conf->captive_portal_host); conf->captive_portal_host = xconf->captive_portal_host; @@ -823,36 +819,37 @@ merge_config(struct unwind_conf *conf, struct unwind_conf *xconf) conf->captive_portal_auto = xconf->captive_portal_auto; /* Add new forwarders. */ - while ((unwind_forwarder = - SIMPLEQ_FIRST(&xconf->unwind_forwarder_list)) != NULL) { - SIMPLEQ_REMOVE_HEAD(&xconf->unwind_forwarder_list, entry); - SIMPLEQ_INSERT_TAIL(&conf->unwind_forwarder_list, - unwind_forwarder, entry); + while ((uw_forwarder = SIMPLEQ_FIRST(&xconf->uw_forwarder_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&xconf->uw_forwarder_list, entry); + SIMPLEQ_INSERT_TAIL(&conf->uw_forwarder_list, + uw_forwarder, entry); } - while ((unwind_forwarder = - SIMPLEQ_FIRST(&xconf->unwind_dot_forwarder_list)) != NULL) { - SIMPLEQ_REMOVE_HEAD(&xconf->unwind_dot_forwarder_list, entry); - SIMPLEQ_INSERT_TAIL(&conf->unwind_dot_forwarder_list, - unwind_forwarder, entry); + while ((uw_forwarder = SIMPLEQ_FIRST(&xconf->uw_dot_forwarder_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&xconf->uw_dot_forwarder_list, entry); + SIMPLEQ_INSERT_TAIL(&conf->uw_dot_forwarder_list, + uw_forwarder, entry); } free(xconf); } -struct unwind_conf * +struct uw_conf * config_new_empty(void) { - struct unwind_conf *xconf; + struct uw_conf *xconf; xconf = calloc(1, sizeof(*xconf)); if (xconf == NULL) fatal(NULL); - SIMPLEQ_INIT(&xconf->unwind_forwarder_list); - SIMPLEQ_INIT(&xconf->unwind_dot_forwarder_list); + SIMPLEQ_INIT(&xconf->uw_forwarder_list); + SIMPLEQ_INIT(&xconf->uw_dot_forwarder_list); if ((xconf->captive_portal_expected_response = strdup("")) == NULL) fatal(NULL); + xconf->captive_portal_expected_status = 200; xconf->captive_portal_auto = 1; @@ -860,9 +857,9 @@ config_new_empty(void) } void -config_clear(struct unwind_conf *conf) +config_clear(struct uw_conf *conf) { - struct unwind_conf *xconf; + struct uw_conf *xconf; /* Merge current config with an empty config. */ xconf = config_new_empty(); @@ -895,15 +892,14 @@ open_dhcp_lease(int if_idx) return; } - main_imsg_compose_frontend_fd(IMSG_LEASEFD, 0, fd); } void open_ports(void) { - struct addrinfo hints, *res0; - int udp4sock = -1, udp6sock = -1, error; + struct addrinfo hints, *res0; + int udp4sock = -1, udp6sock = -1, error; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; diff --git a/sbin/unwind/unwind.h b/sbin/unwind/unwind.h index 47baff9e162..4aabeda22d7 100644 --- a/sbin/unwind/unwind.h +++ b/sbin/unwind/unwind.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unwind.h,v 1.8 2019/02/10 14:10:22 florian Exp $ */ +/* $OpenBSD: unwind.h,v 1.9 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -27,22 +27,22 @@ #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif -#define CONF_FILE "/etc/unwind.conf" -#define UNWIND_SOCKET "/var/run/unwind.sock" -#define UNWIND_USER "_unwind" +#define CONF_FILE "/etc/unwind.conf" +#define UNWIND_SOCKET "/var/run/unwind.sock" +#define UNWIND_USER "_unwind" #define OPT_VERBOSE 0x00000001 #define OPT_VERBOSE2 0x00000002 #define OPT_NOACTION 0x00000004 -#define KSK2017 ". 172800 IN DNSKEY 257 3 8 AwEAAaz/tAm8yTn4Mfeh5eyI96WSVexTBAvkMgJzkKTOiW1vkIbzxeF3+/4RgWOq7HrxRixHlFlExOLAJr5emLvN7SWXgnLh4+B5xQlNVz8Og8kvArMtNROxVQuCaSnIDdD5LKyWbRd2n9WGe2R8PzgCmr3EgVLrjyBxWezF0jLHwVN8efS3rCj/EWgvIWgb9tarpVUDK/b58Da+sqqls3eNbuv7pr+eoZG+SrDK6nWeL3c6H5Apxz7LjVc1uTIdsIXxuOLYA4/ilBmSVIzuDWfdRUfhHdY6+cn8HFRm+2hM8AnXGXws9555KrUB5qihylGa8subX2Nn6UwNR1AkUTV74bU=" +#define KSK2017 ". 172800 IN DNSKEY 257 3 8 AwEAAaz/tAm8yTn4Mfeh5eyI96WSVexTBAvkMgJzkKTOiW1vkIbzxeF3+/4RgWOq7HrxRixHlFlExOLAJr5emLvN7SWXgnLh4+B5xQlNVz8Og8kvArMtNROxVQuCaSnIDdD5LKyWbRd2n9WGe2R8PzgCmr3EgVLrjyBxWezF0jLHwVN8efS3rCj/EWgvIWgb9tarpVUDK/b58Da+sqqls3eNbuv7pr+eoZG+SrDK6nWeL3c6H5Apxz7LjVc1uTIdsIXxuOLYA4/ilBmSVIzuDWfdRUfhHdY6+cn8HFRm+2hM8AnXGXws9555KrUB5qihylGa8subX2Nn6UwNR1AkUTV74bU=" enum { PROC_MAIN, PROC_RESOLVER, PROC_FRONTEND, PROC_CAPTIVEPORTAL, -} unwind_process; +} uw_process; static const char * const log_procnames[] = { "main", @@ -103,15 +103,16 @@ enum imsg_type { IMSG_NEW_TAS_DONE, }; -struct unwind_forwarder { - SIMPLEQ_ENTRY(unwind_forwarder) entry; +struct uw_forwarder { + SIMPLEQ_ENTRY(uw_forwarder) entry; char name[1024]; /* XXX */ }; -struct unwind_conf { - SIMPLEQ_HEAD(unwind_forwarder_head, unwind_forwarder) unwind_forwarder_list; - struct unwind_forwarder_head unwind_dot_forwarder_list; - int unwind_options; +SIMPLEQ_HEAD(uw_forwarder_head, uw_forwarder); +struct uw_conf { + struct uw_forwarder_head uw_forwarder_list; + struct uw_forwarder_head uw_dot_forwarder_list; + int uw_options; char *captive_portal_host; char *captive_portal_path; char *captive_portal_expected_response; @@ -139,17 +140,17 @@ void main_imsg_compose_frontend_fd(int, pid_t, int); void main_imsg_compose_resolver(int, pid_t, void *, uint16_t); void main_imsg_compose_captiveportal(int, pid_t, void *, uint16_t); void main_imsg_compose_captiveportal_fd(int, pid_t, int); -void merge_config(struct unwind_conf *, struct unwind_conf *); +void merge_config(struct uw_conf *, struct uw_conf *); void imsg_event_add(struct imsgev *); int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, int, void *, uint16_t); -struct unwind_conf *config_new_empty(void); -void config_clear(struct unwind_conf *); +struct uw_conf *config_new_empty(void); +void config_clear(struct uw_conf *); /* printconf.c */ -void print_config(struct unwind_conf *); +void print_config(struct uw_conf *); /* parse.y */ -struct unwind_conf *parse_config(char *); -int cmdline_symset(char *); +struct uw_conf *parse_config(char *); +int cmdline_symset(char *); diff --git a/sbin/unwind/uw_parse.y b/sbin/unwind/uw_parse.y index ce9de6f25ee..b312671d289 100644 --- a/sbin/unwind/uw_parse.y +++ b/sbin/unwind/uw_parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: uw_parse.y,v 1.10 2019/02/13 22:57:07 deraadt Exp $ */ +/* $OpenBSD: uw_parse.y,v 1.11 2019/02/17 14:49:15 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -81,11 +81,11 @@ struct sym { int symset(const char *, const char *, int); char *symget(const char *); -static struct unwind_conf *conf; +static struct uw_conf *conf; static int errors; -static struct unwind_forwarder *unwind_forwarder; +static struct uw_forwarder *uw_forwarder; -void clear_config(struct unwind_conf *xconf); +void clear_config(struct uw_conf *xconf); struct sockaddr_storage *host_ip(const char *); typedef struct { @@ -114,7 +114,7 @@ grammar : /* empty */ | grammar '\n' | grammar conf_main '\n' | grammar varset '\n' - | grammar unwind_forwarder '\n' + | grammar uw_forwarder '\n' | grammar captive_portal '\n' | grammar error '\n' { file->errors++; } ; @@ -170,7 +170,7 @@ varset : STRING '=' string { ; conf_main : STRICT yesno { - conf->unwind_options = $2; + conf->uw_options = $2; } ; @@ -228,7 +228,7 @@ captive_portal_optsl : URL STRING { } ; -unwind_forwarder : FORWARDER forwarder_block +uw_forwarder : FORWARDER forwarder_block ; forwarder_block : '{' optnl forwarderopts_l '}' @@ -248,22 +248,21 @@ forwarderoptsl : STRING { } free(ss); - if ((unwind_forwarder = calloc(1, - sizeof(*unwind_forwarder))) == NULL) + if ((uw_forwarder = calloc(1, + sizeof(*uw_forwarder))) == NULL) err(1, NULL); - if(strlcpy(unwind_forwarder->name, $1, - sizeof(unwind_forwarder->name)) >= - sizeof(unwind_forwarder->name)) { - free(unwind_forwarder); + if(strlcpy(uw_forwarder->name, $1, + sizeof(uw_forwarder->name)) >= + sizeof(uw_forwarder->name)) { + free(uw_forwarder); yyerror("forwarder %s too long", $1); free($1); YYERROR; } - SIMPLEQ_INSERT_TAIL( - &conf->unwind_forwarder_list, - unwind_forwarder, entry); + SIMPLEQ_INSERT_TAIL(&conf->uw_forwarder_list, + uw_forwarder, entry); } | STRING PORT NUMBER { int ret; @@ -281,24 +280,23 @@ forwarderoptsl : STRING { YYERROR; } - if ((unwind_forwarder = calloc(1, - sizeof(*unwind_forwarder))) == NULL) + if ((uw_forwarder = calloc(1, + sizeof(*uw_forwarder))) == NULL) err(1, NULL); - ret = snprintf(unwind_forwarder->name, - sizeof(unwind_forwarder->name), "%s@%d", $1, + ret = snprintf(uw_forwarder->name, + sizeof(uw_forwarder->name), "%s@%d", $1, (int)$3); if (ret == -1 || (size_t)ret >= - sizeof(unwind_forwarder->name)) { - free(unwind_forwarder); + sizeof(uw_forwarder->name)) { + free(uw_forwarder); yyerror("forwarder %s too long", $1); free($1); YYERROR; } - SIMPLEQ_INSERT_TAIL( - &conf->unwind_forwarder_list, - unwind_forwarder, entry); + SIMPLEQ_INSERT_TAIL(&conf->uw_forwarder_list, + uw_forwarder, entry); } | STRING DOT { struct sockaddr_storage *ss; @@ -309,22 +307,22 @@ forwarderoptsl : STRING { } free(ss); - if ((unwind_forwarder = calloc(1, - sizeof(*unwind_forwarder))) == NULL) + if ((uw_forwarder = calloc(1, + sizeof(*uw_forwarder))) == NULL) err(1, NULL); - if(strlcpy(unwind_forwarder->name, $1, - sizeof(unwind_forwarder->name)) >= - sizeof(unwind_forwarder->name)) { - free(unwind_forwarder); + if(strlcpy(uw_forwarder->name, $1, + sizeof(uw_forwarder->name)) >= + sizeof(uw_forwarder->name)) { + free(uw_forwarder); yyerror("forwarder %s too long", $1); free($1); YYERROR; } SIMPLEQ_INSERT_TAIL( - &conf->unwind_dot_forwarder_list, - unwind_forwarder, entry); + &conf->uw_dot_forwarder_list, uw_forwarder, + entry); } | STRING PORT NUMBER DOT { int ret; @@ -342,24 +340,24 @@ forwarderoptsl : STRING { YYERROR; } - if ((unwind_forwarder = calloc(1, - sizeof(*unwind_forwarder))) == NULL) + if ((uw_forwarder = calloc(1, + sizeof(*uw_forwarder))) == NULL) err(1, NULL); - ret = snprintf(unwind_forwarder->name, - sizeof(unwind_forwarder->name), "%s@%d", $1, + ret = snprintf(uw_forwarder->name, + sizeof(uw_forwarder->name), "%s@%d", $1, (int)$3); if (ret == -1 || (size_t)ret >= - sizeof(unwind_forwarder->name)) { - free(unwind_forwarder); + sizeof(uw_forwarder->name)) { + free(uw_forwarder); yyerror("forwarder %s too long", $1); free($1); YYERROR; } SIMPLEQ_INSERT_TAIL( - &conf->unwind_dot_forwarder_list, - unwind_forwarder, entry); + &conf->uw_dot_forwarder_list, uw_forwarder, + entry); } ; %% @@ -760,10 +758,10 @@ popfile(void) return (file ? 0 : EOF); } -struct unwind_conf * +struct uw_conf * parse_config(char *filename) { - struct sym *sym, *next; + struct sym *sym, *next; conf = config_new_empty(); @@ -874,17 +872,17 @@ symget(const char *nam) } void -clear_config(struct unwind_conf *xconf) +clear_config(struct uw_conf *xconf) { - while((unwind_forwarder = - SIMPLEQ_FIRST(&xconf->unwind_forwarder_list)) != NULL) { - SIMPLEQ_REMOVE_HEAD(&xconf->unwind_forwarder_list, entry); - free(unwind_forwarder); + while((uw_forwarder = SIMPLEQ_FIRST(&xconf->uw_forwarder_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&xconf->uw_forwarder_list, entry); + free(uw_forwarder); } - while((unwind_forwarder = - SIMPLEQ_FIRST(&xconf->unwind_dot_forwarder_list)) != NULL) { - SIMPLEQ_REMOVE_HEAD(&xconf->unwind_dot_forwarder_list, entry); - free(unwind_forwarder); + while((uw_forwarder = SIMPLEQ_FIRST(&xconf->uw_dot_forwarder_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&xconf->uw_dot_forwarder_list, entry); + free(uw_forwarder); } free(xconf); |