Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 1 | // 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 Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 5 | #include <sys/socket.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 6 | #include <unistd.h> |
| 7 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 8 | #include <memory> |
| 9 | #include <utility> |
| 10 | |
Taoyu Li | ce7caa6 | 2019-10-01 15:43:33 +0900 | [diff] [blame] | 11 | #include <base/files/scoped_file.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 12 | #include <base/logging.h> |
| 13 | #include <brillo/flag_helper.h> |
| 14 | #include <brillo/syslog_logging.h> |
| 15 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 16 | #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 Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 22 | |
| 23 | int main(int argc, char* argv[]) { |
| 24 | DEFINE_bool(log_to_stderr, false, "Log to both syslog and stderr"); |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 25 | DEFINE_int32( |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 26 | adb_proxy_fd, -1, |
| 27 | "Control socket for starting the ADB proxy subprocess. Used internally."); |
Jason Jeremy Iman | d89b5f5 | 2019-10-24 10:39:17 +0900 | [diff] [blame] | 28 | DEFINE_int32(mcast_proxy_fd, -1, |
| 29 | "Control socket for starting the multicast proxy " |
| 30 | "subprocess. Used internally."); |
Taoyu Li | f0370c9 | 2019-09-18 15:04:37 +0900 | [diff] [blame] | 31 | DEFINE_int32( |
| 32 | nd_proxy_fd, -1, |
| 33 | "Control socket for starting the ND proxy subprocess. Used internally."); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 34 | |
| 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 Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 42 | if (FLAGS_adb_proxy_fd >= 0) { |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 43 | LOG(INFO) << "Spawning adb proxy"; |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 44 | base::ScopedFD fd(FLAGS_adb_proxy_fd); |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 45 | patchpanel::AdbProxy adb_proxy(std::move(fd)); |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 46 | return adb_proxy.Run(); |
| 47 | } |
| 48 | |
Taoyu Li | f0370c9 | 2019-09-18 15:04:37 +0900 | [diff] [blame] | 49 | if (FLAGS_nd_proxy_fd >= 0) { |
| 50 | LOG(INFO) << "Spawning nd proxy"; |
| 51 | base::ScopedFD fd(FLAGS_nd_proxy_fd); |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 52 | patchpanel::NDProxyDaemon nd_proxy(std::move(fd)); |
Taoyu Li | f0370c9 | 2019-09-18 15:04:37 +0900 | [diff] [blame] | 53 | return nd_proxy.Run(); |
| 54 | } |
| 55 | |
Jason Jeremy Iman | d89b5f5 | 2019-10-24 10:39:17 +0900 | [diff] [blame] | 56 | if (FLAGS_mcast_proxy_fd >= 0) { |
| 57 | LOG(INFO) << "Spawning multicast proxy"; |
| 58 | base::ScopedFD fd(FLAGS_mcast_proxy_fd); |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 59 | patchpanel::MulticastProxy mcast_proxy(std::move(fd)); |
Jason Jeremy Iman | d89b5f5 | 2019-10-24 10:39:17 +0900 | [diff] [blame] | 60 | return mcast_proxy.Run(); |
| 61 | } |
| 62 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 63 | auto adb_proxy = std::make_unique<patchpanel::HelperProcess>(); |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 64 | adb_proxy->Start(argc, argv, "--adb_proxy_fd"); |
| 65 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 66 | auto mcast_proxy = std::make_unique<patchpanel::HelperProcess>(); |
Jason Jeremy Iman | d89b5f5 | 2019-10-24 10:39:17 +0900 | [diff] [blame] | 67 | mcast_proxy->Start(argc, argv, "--mcast_proxy_fd"); |
| 68 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 69 | auto nd_proxy = std::make_unique<patchpanel::HelperProcess>(); |
Taoyu Li | f0370c9 | 2019-09-18 15:04:37 +0900 | [diff] [blame] | 70 | nd_proxy->Start(argc, argv, "--nd_proxy_fd"); |
| 71 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 72 | LOG(INFO) << "Starting patchpanel manager"; |
| 73 | patchpanel::Manager manager(std::move(adb_proxy), std::move(mcast_proxy), |
Garrick Evans | 1f5a361 | 2019-11-08 12:59:03 +0900 | [diff] [blame] | 74 | std::move(nd_proxy)); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 75 | return manager.Run(); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 76 | } |