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 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 15 | #include "arc-networkd/helper_process.h" |
| 16 | #include "arc-networkd/ip_helper.h" |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 17 | #include "arc-networkd/manager.h" |
Kevin Cernekee | 4e62cc1 | 2016-12-03 11:50:53 -0800 | [diff] [blame] | 18 | #include "arc-networkd/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"); |
| 22 | DEFINE_string(internal_interface, "br0", |
| 23 | "Name of the host interface that connects to the guest"); |
| 24 | DEFINE_string(container_interface, "arc0", |
| 25 | "Name of the guest interface that connects to the host"); |
| 26 | DEFINE_int32(con_netns, 0, "Container's network namespace (PID)"); |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 27 | DEFINE_int32( |
| 28 | ip_helper_fd, |
| 29 | -1, |
| 30 | "Control socket for starting an IpHelper subprocess. Used internally."); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 31 | |
| 32 | brillo::FlagHelper::Init(argc, argv, "ARC network daemon"); |
| 33 | |
| 34 | int flags = brillo::kLogToSyslog | brillo::kLogHeader; |
| 35 | if (FLAGS_log_to_stderr) |
| 36 | flags |= brillo::kLogToStderr; |
| 37 | brillo::InitLog(flags); |
| 38 | |
Kevin Cernekee | 4e62cc1 | 2016-12-03 11:50:53 -0800 | [diff] [blame] | 39 | arc_networkd::Options opt; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 40 | opt.int_ifname = FLAGS_internal_interface; |
| 41 | opt.con_ifname = FLAGS_container_interface; |
| 42 | opt.con_netns = FLAGS_con_netns; |
| 43 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 44 | if (FLAGS_ip_helper_fd >= 0) { |
| 45 | base::ScopedFD fd(FLAGS_ip_helper_fd); |
| 46 | arc_networkd::IpHelper ip_helper{opt, std::move(fd)}; |
| 47 | return ip_helper.Run(); |
| 48 | } else { |
| 49 | std::unique_ptr<arc_networkd::HelperProcess> ip_helper( |
| 50 | new arc_networkd::HelperProcess()); |
| 51 | ip_helper->Start(argc, argv, "--ip_helper_fd"); |
| 52 | |
| 53 | arc_networkd::Manager manager{opt, std::move(ip_helper)}; |
| 54 | return manager.Run(); |
| 55 | } |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 56 | } |