blob: 653c8bfa4e36379f0defceb08d28e34d1c62db5f [file] [log] [blame]
Garrick Evans066dc2c2020-12-10 10:43:55 +09001// Copyright 2021 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <sysexits.h>
6
7#include <base/files/scoped_file.h>
8#include <base/logging.h>
9#include <brillo/flag_helper.h>
10#include <brillo/syslog_logging.h>
11
12#include "dns-proxy/controller.h"
13#include "dns-proxy/proxy.h"
14
15int main(int argc, char* argv[]) {
16 DEFINE_bool(log_to_stderr, false, "Log to both syslog and stderr");
17 DEFINE_string(t, "", "The proxy type or empty to run the controller");
18 DEFINE_string(i, "", "The outbound network interface");
19 brillo::FlagHelper::Init(argc, argv, "DNS Proxy daemon");
20
21 int flags = brillo::kLogToSyslog | brillo::kLogHeader;
22 if (FLAGS_log_to_stderr)
23 flags |= brillo::kLogToStderr;
24
25 brillo::InitLog(flags);
26
27 if (FLAGS_t.empty()) {
28 dns_proxy::Controller controller(argv[0]);
29 return controller.Run();
30 }
31
32 if (auto t = dns_proxy::Proxy::StringToType(FLAGS_t)) {
33 dns_proxy::Proxy proxy({.type = t.value(), .ifname = FLAGS_i});
34 return proxy.Run();
35 }
36
37 LOG(ERROR) << "Cannot launch proxy for unknown type [" << FLAGS_t << "]";
38 return EX_USAGE;
39}