1 #include "hyp_ethernet_interface.hpp"
2 
3 #include "hyp_network_manager.hpp"
4 
5 namespace phosphor
6 {
7 namespace network
8 {
9 
10 using namespace phosphor::logging;
11 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
12 using Argument = xyz::openbmc_project::Common::InvalidArgument;
13 
getBiosAttrsMap()14 biosTableType HypEthInterface::getBiosAttrsMap()
15 {
16     return manager.getBIOSTableAttrs();
17 }
18 
ipv6AcceptRA(bool value)19 bool HypEthInterface::ipv6AcceptRA(bool value)
20 {
21     auto currValue = ipv6AcceptRA();
22     if (currValue != value)
23     {
24         HypEthernetIntf::ipv6AcceptRA(value);
25     }
26     return value;
27 }
28 
dhcp4(bool value)29 bool HypEthInterface::dhcp4(bool value)
30 {
31     auto currValue = dhcp4();
32     if (currValue != value)
33     {
34         HypEthernetIntf::dhcp4(value);
35     }
36     return value;
37 }
38 
dhcp6(bool value)39 bool HypEthInterface::dhcp6(bool value)
40 {
41     auto currValue = dhcp6();
42     if (currValue != value)
43     {
44         HypEthernetIntf::dhcp6(value);
45     }
46     return value;
47 }
48 
dhcpIsEnabled(HypIP::Protocol family)49 bool HypEthInterface::dhcpIsEnabled(HypIP::Protocol family)
50 {
51     switch (family)
52     {
53         case HypIP::Protocol::IPv6:
54             return dhcp6();
55         case HypIP::Protocol::IPv4:
56             return dhcp4();
57     }
58     throw std::logic_error("Unreachable");
59 }
60 
dhcpEnabled(DHCPConf value)61 HypEthInterface::DHCPConf HypEthInterface::dhcpEnabled(DHCPConf value)
62 {
63     auto old4 = HypEthernetIntf::dhcp4();
64     auto new4 = HypEthernetIntf::dhcp4(
65         value == DHCPConf::v4 || value == DHCPConf::v4v6stateless ||
66         value == DHCPConf::both);
67     auto old6 = HypEthernetIntf::dhcp6();
68     auto new6 = HypEthernetIntf::dhcp6(
69         value == DHCPConf::v6 || value == DHCPConf::both);
70     auto oldra = HypEthernetIntf::ipv6AcceptRA();
71     auto newra = HypEthernetIntf::ipv6AcceptRA(
72         value == DHCPConf::v6stateless || value == DHCPConf::v4v6stateless ||
73         value == DHCPConf::v6 || value == DHCPConf::both);
74 
75     if (old4 != new4 || old6 != new6 || oldra != newra)
76     {
77         HypEthernetIntf::dhcpEnabled(value);
78     }
79     return value;
80 }
81 
dhcpEnabled() const82 HypEthInterface::DHCPConf HypEthInterface::dhcpEnabled() const
83 {
84     if (dhcp6())
85     {
86         return dhcp4() ? DHCPConf::both : DHCPConf::v6;
87     }
88     else if (dhcp4())
89     {
90         return ipv6AcceptRA() ? DHCPConf::v4v6stateless : DHCPConf::v4;
91     }
92     return ipv6AcceptRA() ? DHCPConf::v6stateless : DHCPConf::none;
93 }
94 
95 } // namespace network
96 } // namespace phosphor
97