blob: 91f1cd24ffbb44d12b2aff0549a5c4e88785113d [file] [log] [blame]
Kevin Cernekee95d4ae92016-06-19 10:26:29 -07001// Copyright 2016 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
Garrick Evans3cbac7c2019-04-18 15:31:31 +09005#include <sys/socket.h>
Kevin Cernekee95d4ae92016-06-19 10:26:29 -07006#include <unistd.h>
7
Kevin Cernekee27bcaa62016-12-03 11:16:26 -08008#include <memory>
9#include <utility>
10
Taoyu Lice7caa62019-10-01 15:43:33 +090011#include <base/files/scoped_file.h>
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070012#include <base/logging.h>
13#include <brillo/flag_helper.h>
14#include <brillo/syslog_logging.h>
15
Garrick Evans3388a032020-03-24 11:25:55 +090016#include "patchpanel/adb_proxy.h"
17#include "patchpanel/helper_process.h"
18#include "patchpanel/manager.h"
19#include "patchpanel/multicast_proxy.h"
20#include "patchpanel/ndproxy.h"
21#include "patchpanel/socket.h"
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070022
23int main(int argc, char* argv[]) {
24 DEFINE_bool(log_to_stderr, false, "Log to both syslog and stderr");
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080025 DEFINE_int32(
Garrick Evans96e03042019-05-28 14:30:52 +090026 adb_proxy_fd, -1,
27 "Control socket for starting the ADB proxy subprocess. Used internally.");
Jason Jeremy Imand89b5f52019-10-24 10:39:17 +090028 DEFINE_int32(mcast_proxy_fd, -1,
29 "Control socket for starting the multicast proxy "
30 "subprocess. Used internally.");
Taoyu Lif0370c92019-09-18 15:04:37 +090031 DEFINE_int32(
32 nd_proxy_fd, -1,
33 "Control socket for starting the ND proxy subprocess. Used internally.");
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070034
35 brillo::FlagHelper::Init(argc, argv, "ARC network daemon");
36
37 int flags = brillo::kLogToSyslog | brillo::kLogHeader;
38 if (FLAGS_log_to_stderr)
39 flags |= brillo::kLogToStderr;
40 brillo::InitLog(flags);
41
Garrick Evans96e03042019-05-28 14:30:52 +090042 if (FLAGS_adb_proxy_fd >= 0) {
Garrick Evans3cbac7c2019-04-18 15:31:31 +090043 LOG(INFO) << "Spawning adb proxy";
Garrick Evans96e03042019-05-28 14:30:52 +090044 base::ScopedFD fd(FLAGS_adb_proxy_fd);
Garrick Evans3388a032020-03-24 11:25:55 +090045 patchpanel::AdbProxy adb_proxy(std::move(fd));
Garrick Evans3cbac7c2019-04-18 15:31:31 +090046 return adb_proxy.Run();
47 }
48
Taoyu Lif0370c92019-09-18 15:04:37 +090049 if (FLAGS_nd_proxy_fd >= 0) {
50 LOG(INFO) << "Spawning nd proxy";
51 base::ScopedFD fd(FLAGS_nd_proxy_fd);
Garrick Evans3388a032020-03-24 11:25:55 +090052 patchpanel::NDProxyDaemon nd_proxy(std::move(fd));
Taoyu Lif0370c92019-09-18 15:04:37 +090053 return nd_proxy.Run();
54 }
55
Jason Jeremy Imand89b5f52019-10-24 10:39:17 +090056 if (FLAGS_mcast_proxy_fd >= 0) {
57 LOG(INFO) << "Spawning multicast proxy";
58 base::ScopedFD fd(FLAGS_mcast_proxy_fd);
Garrick Evans3388a032020-03-24 11:25:55 +090059 patchpanel::MulticastProxy mcast_proxy(std::move(fd));
Jason Jeremy Imand89b5f52019-10-24 10:39:17 +090060 return mcast_proxy.Run();
61 }
62
Garrick Evans3388a032020-03-24 11:25:55 +090063 auto adb_proxy = std::make_unique<patchpanel::HelperProcess>();
Garrick Evans96e03042019-05-28 14:30:52 +090064 adb_proxy->Start(argc, argv, "--adb_proxy_fd");
65
Garrick Evans3388a032020-03-24 11:25:55 +090066 auto mcast_proxy = std::make_unique<patchpanel::HelperProcess>();
Jason Jeremy Imand89b5f52019-10-24 10:39:17 +090067 mcast_proxy->Start(argc, argv, "--mcast_proxy_fd");
68
Garrick Evans3388a032020-03-24 11:25:55 +090069 auto nd_proxy = std::make_unique<patchpanel::HelperProcess>();
Taoyu Lif0370c92019-09-18 15:04:37 +090070 nd_proxy->Start(argc, argv, "--nd_proxy_fd");
71
Garrick Evans3388a032020-03-24 11:25:55 +090072 LOG(INFO) << "Starting patchpanel manager";
73 patchpanel::Manager manager(std::move(adb_proxy), std::move(mcast_proxy),
Garrick Evans1f5a3612019-11-08 12:59:03 +090074 std::move(nd_proxy));
Garrick Evans49879532018-12-03 13:15:36 +090075 return manager.Run();
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070076}