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 | |
| 5 | #include <unistd.h> |
| 6 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <utility> |
| 9 | |
| 10 | #include <base/files/scoped_file.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
| 12 | #include <brillo/flag_helper.h> |
| 13 | #include <brillo/syslog_logging.h> |
| 14 | |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 15 | #include "arc/network/helper_process.h" |
| 16 | #include "arc/network/ip_helper.h" |
| 17 | #include "arc/network/manager.h" |
| 18 | #include "arc/network/options.h" |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 19 | |
| 20 | int main(int argc, char* argv[]) { |
| 21 | DEFINE_bool(log_to_stderr, false, "Log to both syslog and stderr"); |
Kevin Cernekee | 035d3a3 | 2017-09-12 20:46:49 -0700 | [diff] [blame] | 22 | DEFINE_string(internal_interface, "arcbr0", |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 23 | "Name of the host interface that connects to the guest"); |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 24 | DEFINE_string(mdns_ip, "100.115.92.2", |
Kevin Cernekee | 73e0920 | 2017-06-17 20:55:09 -0700 | [diff] [blame] | 25 | "Guest IP to replace with the LAN IP in mDNS responses"); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 26 | DEFINE_string(container_interface, "arc0", |
| 27 | "Name of the guest interface that connects to the host"); |
| 28 | DEFINE_int32(con_netns, 0, "Container's network namespace (PID)"); |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 29 | DEFINE_int32( |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 30 | ip_helper_fd, -1, |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 31 | "Control socket for starting an IpHelper subprocess. Used internally."); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 32 | |
| 33 | brillo::FlagHelper::Init(argc, argv, "ARC network daemon"); |
| 34 | |
| 35 | int flags = brillo::kLogToSyslog | brillo::kLogHeader; |
| 36 | if (FLAGS_log_to_stderr) |
| 37 | flags |= brillo::kLogToStderr; |
| 38 | brillo::InitLog(flags); |
| 39 | |
Kevin Cernekee | 4e62cc1 | 2016-12-03 11:50:53 -0800 | [diff] [blame] | 40 | arc_networkd::Options opt; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 41 | opt.int_ifname = FLAGS_internal_interface; |
Kevin Cernekee | 73e0920 | 2017-06-17 20:55:09 -0700 | [diff] [blame] | 42 | opt.mdns_ipaddr = FLAGS_mdns_ip; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 43 | opt.con_ifname = FLAGS_container_interface; |
| 44 | opt.con_netns = FLAGS_con_netns; |
| 45 | |
Hugo Benichi | 935eca9 | 2018-07-03 13:47:24 +0900 | [diff] [blame^] | 46 | LOG(INFO) << "Starting arc-networkd " |
| 47 | << (FLAGS_ip_helper_fd >= 0 ? "helper" : "manager") |
| 48 | << " with Option " |
| 49 | << "{ netns=" << opt.con_netns |
| 50 | << ", host ifname=" << opt.int_ifname |
| 51 | << ", guest ifname=" << opt.con_ifname |
| 52 | << ", mdns ip=" << opt.mdns_ipaddr |
| 53 | << " }"; |
| 54 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 55 | if (FLAGS_ip_helper_fd >= 0) { |
| 56 | base::ScopedFD fd(FLAGS_ip_helper_fd); |
| 57 | arc_networkd::IpHelper ip_helper{opt, std::move(fd)}; |
| 58 | return ip_helper.Run(); |
| 59 | } else { |
| 60 | std::unique_ptr<arc_networkd::HelperProcess> ip_helper( |
| 61 | new arc_networkd::HelperProcess()); |
| 62 | ip_helper->Start(argc, argv, "--ip_helper_fd"); |
| 63 | |
| 64 | arc_networkd::Manager manager{opt, std::move(ip_helper)}; |
| 65 | return manager.Run(); |
| 66 | } |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 67 | } |