11285115cSWilliam A. Kennington III /* 21285115cSWilliam A. Kennington III * Copyright 2021 Google LLC 31285115cSWilliam A. Kennington III * 41285115cSWilliam A. Kennington III * Licensed under the Apache License, Version 2.0 (the "License"); 51285115cSWilliam A. Kennington III * you may not use this file except in compliance with the License. 61285115cSWilliam A. Kennington III * You may obtain a copy of the License at 71285115cSWilliam A. Kennington III * 81285115cSWilliam A. Kennington III * http://www.apache.org/licenses/LICENSE-2.0 91285115cSWilliam A. Kennington III * 101285115cSWilliam A. Kennington III * Unless required by applicable law or agreed to in writing, software 111285115cSWilliam A. Kennington III * distributed under the License is distributed on an "AS IS" BASIS, 121285115cSWilliam A. Kennington III * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131285115cSWilliam A. Kennington III * See the License for the specific language governing permissions and 141285115cSWilliam A. Kennington III * limitations under the License. 151285115cSWilliam A. Kennington III */ 161285115cSWilliam A. Kennington III 171285115cSWilliam A. Kennington III #pragma once 181285115cSWilliam A. Kennington III 191285115cSWilliam A. Kennington III #include "platforms/nemora/portable/net_types.h" 201285115cSWilliam A. Kennington III 211285115cSWilliam A. Kennington III #include <net_iface.h> 221285115cSWilliam A. Kennington III 231285115cSWilliam A. Kennington III #include <sdbusplus/bus.hpp> 241285115cSWilliam A. Kennington III 251285115cSWilliam A. Kennington III #include <experimental/optional> 261285115cSWilliam A. Kennington III #include <list> 271285115cSWilliam A. Kennington III #include <map> 281285115cSWilliam A. Kennington III #include <optional> 291285115cSWilliam A. Kennington III #include <string> 301285115cSWilliam A. Kennington III #include <vector> 311285115cSWilliam A. Kennington III 321285115cSWilliam A. Kennington III // The API for configuring and querying network. 331285115cSWilliam A. Kennington III 341285115cSWilliam A. Kennington III namespace net 351285115cSWilliam A. Kennington III { 361285115cSWilliam A. Kennington III 371285115cSWilliam A. Kennington III using DBusObjectPath = std::string; 381285115cSWilliam A. Kennington III using DBusService = std::string; 391285115cSWilliam A. Kennington III using DBusInterface = std::string; 401285115cSWilliam A. Kennington III using ObjectTree = 411285115cSWilliam A. Kennington III std::map<DBusObjectPath, std::map<DBusService, std::vector<DBusInterface>>>; 421285115cSWilliam A. Kennington III 431285115cSWilliam A. Kennington III class ConfigBase 441285115cSWilliam A. Kennington III { 451285115cSWilliam A. Kennington III public: 461285115cSWilliam A. Kennington III virtual ~ConfigBase() = default; 471285115cSWilliam A. Kennington III 481285115cSWilliam A. Kennington III virtual int get_mac_addr(mac_addr_t* mac) = 0; 491285115cSWilliam A. Kennington III 501285115cSWilliam A. Kennington III virtual int set_mac_addr(const mac_addr_t& mac) = 0; 511285115cSWilliam A. Kennington III 521285115cSWilliam A. Kennington III // Called each time is_nic_hostless state is sampled. 531285115cSWilliam A. Kennington III virtual int set_nic_hostless(bool is_nic_hostless) = 0; 541285115cSWilliam A. Kennington III }; 551285115cSWilliam A. Kennington III 561285115cSWilliam A. Kennington III // Calls phosphord-networkd 571285115cSWilliam A. Kennington III class PhosphorConfig : public ConfigBase 581285115cSWilliam A. Kennington III { 591285115cSWilliam A. Kennington III public: 601285115cSWilliam A. Kennington III explicit PhosphorConfig(const std::string& iface_name); 611285115cSWilliam A. Kennington III 621285115cSWilliam A. Kennington III // Reads the MAC address from phosphor-networkd interface or internal 631285115cSWilliam A. Kennington III // cache, and store in the mac pointer. 641285115cSWilliam A. Kennington III // Returns -1 if failed, 0 if succeeded. 651285115cSWilliam A. Kennington III int get_mac_addr(mac_addr_t* mac) override; 661285115cSWilliam A. Kennington III 671285115cSWilliam A. Kennington III // Sets the MAC address over phosphor-networkd, and update internal 681285115cSWilliam A. Kennington III // cache. 691285115cSWilliam A. Kennington III // Returns -1 if failed, 0 if succeeded. 701285115cSWilliam A. Kennington III int set_mac_addr(const mac_addr_t& mac) override; 711285115cSWilliam A. Kennington III 721285115cSWilliam A. Kennington III virtual int set_nic_hostless(bool is_nic_hostless) override; 731285115cSWilliam A. Kennington III 741285115cSWilliam A. Kennington III private: 75*59ac2c2dSPatrick Williams sdbusplus::message_t new_networkd_call(sdbusplus::bus_t* dbus, 761285115cSWilliam A. Kennington III bool get = false) const; 771285115cSWilliam A. Kennington III 781285115cSWilliam A. Kennington III const std::string iface_name_; 791285115cSWilliam A. Kennington III const std::string iface_path_; 801285115cSWilliam A. Kennington III 811285115cSWilliam A. Kennington III // Stores the currently configured nic state, if previously set 821285115cSWilliam A. Kennington III std::optional<bool> was_nic_hostless_; 831285115cSWilliam A. Kennington III 841285115cSWilliam A. Kennington III // The MAC address obtained from NIC. 851285115cSWilliam A. Kennington III // ncsid will commit this MAC address over DBus to phosphor-networkd 861285115cSWilliam A. Kennington III // and expect it to be persisted. If actual host MAC address changes or 871285115cSWilliam A. Kennington III // BMC MAC address is overwritten, a daemon reboot is needed to reset 881285115cSWilliam A. Kennington III // the MAC. 891285115cSWilliam A. Kennington III // Initialized to nullopt which evaluates to false. Once a value is 901285115cSWilliam A. Kennington III // set, bool() evaluates to true. 911285115cSWilliam A. Kennington III std::experimental::optional<mac_addr_t> shared_host_mac_; 921285115cSWilliam A. Kennington III 931285115cSWilliam A. Kennington III // List of outstanding pids for config jobs 941285115cSWilliam A. Kennington III std::list<pid_t> running_pids_; 951285115cSWilliam A. Kennington III 961285115cSWilliam A. Kennington III // Holds a reference to the bus for issuing commands to update network 971285115cSWilliam A. Kennington III // config 98*59ac2c2dSPatrick Williams sdbusplus::bus_t bus; 991285115cSWilliam A. Kennington III }; 1001285115cSWilliam A. Kennington III 1011285115cSWilliam A. Kennington III } // namespace net 102