diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2019-02-03 12:02:31 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2019-02-03 12:02:31 +0000 |
commit | f9afdffacbc80ce38d0f3382a2910cbb69f5a6fe (patch) | |
tree | 0d0082630584cf5e779c025f45172bbc6245c9b8 /usr.sbin | |
parent | f5bb41ae112a156756ad002d5c89c53df6adeb6d (diff) |
Captive portal detection for unwind(8).
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/unwindctl/parser.c | 9 | ||||
-rw-r--r-- | usr.sbin/unwindctl/parser.h | 3 | ||||
-rw-r--r-- | usr.sbin/unwindctl/unwindctl.8 | 8 | ||||
-rw-r--r-- | usr.sbin/unwindctl/unwindctl.c | 28 |
4 files changed, 42 insertions, 6 deletions
diff --git a/usr.sbin/unwindctl/parser.c b/usr.sbin/unwindctl/parser.c index 57ba623b797..9c6d22480ab 100644 --- a/usr.sbin/unwindctl/parser.c +++ b/usr.sbin/unwindctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.2 2019/01/27 12:41:39 florian Exp $ */ +/* $OpenBSD: parser.c,v 1.3 2019/02/03 12:02:30 florian Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -51,11 +51,13 @@ struct token { static const struct token t_main[]; static const struct token t_log[]; static const struct token t_status[]; +static const struct token t_recheck[]; static const struct token t_main[] = { {KEYWORD, "reload", RELOAD, NULL}, {KEYWORD, "status", STATUS, t_status}, {KEYWORD, "log", NONE, t_log}, + {KEYWORD, "recheck", NONE, t_recheck}, {ENDTOKEN, "", NONE, NULL} }; @@ -75,6 +77,11 @@ static const struct token t_status[] = { {ENDTOKEN, "", STATUS, NULL} }; +static const struct token t_recheck[] = { + {KEYWORD, "portal", PORTAL, NULL}, + {ENDTOKEN, "", NONE, NULL} +}; + static const struct token *match_token(const char *, const struct token *, struct parse_result *); static void show_valid_args(const struct token *); diff --git a/usr.sbin/unwindctl/parser.h b/usr.sbin/unwindctl/parser.h index 10d8e7815e0..a2482694284 100644 --- a/usr.sbin/unwindctl/parser.h +++ b/usr.sbin/unwindctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.2 2019/01/27 12:41:39 florian Exp $ */ +/* $OpenBSD: parser.h,v 1.3 2019/02/03 12:02:30 florian Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -23,6 +23,7 @@ enum actions { LOG_VERBOSE, LOG_BRIEF, RELOAD, + PORTAL, STATUS, STATUS_RECURSOR, STATUS_DHCP, diff --git a/usr.sbin/unwindctl/unwindctl.8 b/usr.sbin/unwindctl/unwindctl.8 index f8dd5a47b2e..d04fa17aa7a 100644 --- a/usr.sbin/unwindctl/unwindctl.8 +++ b/usr.sbin/unwindctl/unwindctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: unwindctl.8,v 1.1 2019/01/23 13:12:19 florian Exp $ +.\" $OpenBSD: unwindctl.8,v 1.2 2019/02/03 12:02:30 florian Exp $ .\" .\" Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 23 2019 $ +.Dd $Mdocdate: February 3 2019 $ .Dt UNWINDCTL 8 .Os .Sh NAME @@ -53,6 +53,10 @@ Enable verbose logging. Enable very noisy debug logging. .It Cm reload Reload the configuration file. +.It Cm recheck Cm portal +Run the +.Dq Captive Portal +detection. .It Cm status Op Cm recursor Cm dhcp Cm static Show a status summary. If one of diff --git a/usr.sbin/unwindctl/unwindctl.c b/usr.sbin/unwindctl/unwindctl.c index 21146b84767..f90347314ae 100644 --- a/usr.sbin/unwindctl/unwindctl.c +++ b/usr.sbin/unwindctl/unwindctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unwindctl.c,v 1.3 2019/01/31 13:36:42 solene Exp $ */ +/* $OpenBSD: unwindctl.c,v 1.4 2019/02/03 12:02:30 florian Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -38,6 +38,7 @@ #include <unistd.h> #include "unwind.h" +#include "captiveportal.h" #include "frontend.h" #include "resolver.h" #include "parser.h" @@ -140,6 +141,12 @@ main(int argc, char *argv[]) printf("reload request sent.\n"); done = 1; break; + case PORTAL: + imsg_compose(ibuf, IMSG_CTL_RECHECK_CAPTIVEPORTAL, 0, 0, -1, + NULL, 0); + printf("recheck request sent.\n"); + done = 1; + break; case STATUS_RECURSOR: type = RECURSOR; imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, &type, @@ -210,11 +217,28 @@ show_status_msg(struct imsg *imsg) { static int header; struct ctl_resolver_info *cri; + enum captive_portal_state captive_portal_state; - if (!header++) + if (imsg->hdr.type != IMSG_CTL_CAPTIVEPORTAL_INFO && !header++) printf("%8s %16s %s\n", "selected", "type", "status"); switch (imsg->hdr.type) { + case IMSG_CTL_CAPTIVEPORTAL_INFO: + memcpy(&captive_portal_state, imsg->data, + sizeof(captive_portal_state)); + switch (captive_portal_state) { + case PORTAL_UNCHECKED: + case PORTAL_UNKNOWN: + printf("captive portal is %s\n\n", + captive_portal_state_str[captive_portal_state]); + break; + case BEHIND: + case NOT_BEHIND: + printf("%s captive portal\n\n", + captive_portal_state_str[captive_portal_state]); + break; + } + break; case IMSG_CTL_RESOLVER_INFO: cri = imsg->data; printf("%8s %16s %s\n", cri->selected ? "*" : " ", |