Ratan Gupta | a54d8f8 | 2017-09-08 17:05:46 +0530 | [diff] [blame] | 1 | #include "config.h" |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 2 | |
William A. Kennington III | 0b111d4 | 2022-10-04 18:06:11 -0700 | [diff] [blame] | 3 | #ifdef SYNC_MAC_FROM_INVENTORY |
| 4 | #include "inventory_mac.hpp" |
| 5 | #endif |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 6 | #include "network_manager.hpp" |
| 7 | #include "rtnetlink_server.hpp" |
William A. Kennington III | 3a70fa2 | 2018-09-20 18:48:20 -0700 | [diff] [blame] | 8 | #include "types.hpp" |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 9 | |
William A. Kennington III | 4fd52ae | 2022-09-30 13:49:39 -0700 | [diff] [blame] | 10 | #include <fmt/format.h> |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 11 | |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 12 | #include <chrono> |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 13 | #include <phosphor-logging/log.hpp> |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 14 | #include <sdbusplus/bus.hpp> |
| 15 | #include <sdbusplus/server/manager.hpp> |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 16 | #include <sdeventplus/clock.hpp> |
William A. Kennington III | 3a70fa2 | 2018-09-20 18:48:20 -0700 | [diff] [blame] | 17 | #include <sdeventplus/event.hpp> |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 18 | #include <sdeventplus/source/signal.hpp> |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 19 | #include <sdeventplus/utility/timer.hpp> |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 20 | #include <stdplus/signal.hpp> |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 21 | |
William A. Kennington III | 09095f8 | 2018-09-27 12:05:12 -0700 | [diff] [blame] | 22 | using phosphor::logging::level; |
| 23 | using phosphor::logging::log; |
William A. Kennington III | 09095f8 | 2018-09-27 12:05:12 -0700 | [diff] [blame] | 24 | |
William A. Kennington III | 5f1eb46 | 2019-02-12 19:47:51 -0800 | [diff] [blame] | 25 | constexpr char DEFAULT_OBJPATH[] = "/xyz/openbmc_project/network"; |
| 26 | |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 27 | namespace phosphor::network |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 28 | { |
| 29 | |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 30 | class TimerExecutor : public DelayedExecutor |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 31 | { |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 32 | private: |
| 33 | using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>; |
| 34 | |
| 35 | public: |
| 36 | TimerExecutor(sdeventplus::Event& event, std::chrono::seconds delay) : |
| 37 | delay(delay), timer(event, nullptr) |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 38 | { |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 39 | } |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 40 | |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 41 | void schedule() override |
| 42 | { |
| 43 | timer.restartOnce(delay); |
| 44 | } |
| 45 | |
| 46 | void setCallback(fu2::unique_function<void()>&& cb) override |
| 47 | { |
| 48 | timer.set_callback([cb = std::move(cb)](Timer&) mutable { cb(); }); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | std::chrono::seconds delay; |
| 53 | Timer timer; |
| 54 | }; |
Ratan Gupta | 16f1288 | 2017-09-22 18:26:11 +0530 | [diff] [blame] | 55 | |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 56 | void termCb(sdeventplus::source::Signal& signal, const struct signalfd_siginfo*) |
| 57 | { |
| 58 | log<level::NOTICE>("Got TERM, exiting"); |
| 59 | signal.get_event().exit(0); |
| 60 | } |
| 61 | |
William A. Kennington III | 4fd52ae | 2022-09-30 13:49:39 -0700 | [diff] [blame] | 62 | int main() |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 63 | { |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 64 | auto event = sdeventplus::Event::get_default(); |
| 65 | stdplus::signal::block(SIGTERM); |
| 66 | sdeventplus::source::Signal(event, SIGTERM, termCb).set_floating(true); |
| 67 | |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 68 | auto bus = sdbusplus::bus::new_default(); |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 69 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 70 | sdbusplus::server::manager_t objManager(bus, DEFAULT_OBJPATH); |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 71 | |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 72 | TimerExecutor reload(event, std::chrono::seconds(3)); |
| 73 | Manager manager(bus, reload, DEFAULT_OBJPATH, "/etc/systemd/network"); |
| 74 | netlink::Server svr(event, manager); |
Vishwanatha Subbanna | 18891c6 | 2017-10-17 15:22:46 +0530 | [diff] [blame] | 75 | |
William A. Kennington III | 6f39c5e | 2021-05-13 18:39:23 -0700 | [diff] [blame] | 76 | #ifdef SYNC_MAC_FROM_INVENTORY |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 77 | auto runtime = inventory::watch(bus, manager); |
Manojkiran Eda | cc099a8 | 2020-05-11 14:25:16 +0530 | [diff] [blame] | 78 | #endif |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 79 | |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 80 | bus.request_name(DEFAULT_BUSNAME); |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 81 | return event.loop(); |
William A. Kennington III | 4fd52ae | 2022-09-30 13:49:39 -0700 | [diff] [blame] | 82 | } |
| 83 | |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 84 | } // namespace phosphor::network |
William A. Kennington III | 4fd52ae | 2022-09-30 13:49:39 -0700 | [diff] [blame] | 85 | |
| 86 | int main(int /*argc*/, char** /*argv*/) |
| 87 | { |
| 88 | try |
| 89 | { |
| 90 | return phosphor::network::main(); |
| 91 | } |
| 92 | catch (const std::exception& e) |
| 93 | { |
William A. Kennington III | be1af44 | 2022-11-12 01:49:21 -0800 | [diff] [blame] | 94 | fmt::print(stderr, "FAILED: {}", e.what()); |
| 95 | fflush(stderr); |
William A. Kennington III | 4fd52ae | 2022-09-30 13:49:39 -0700 | [diff] [blame] | 96 | return 1; |
| 97 | } |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 98 | } |