summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0002-IPv6-Network-changes-to-configuration-file.patch
blob: 251f68319d39880dc27701eeaa6cd6c33d122054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
From ebb359773b8a5c03a25c3a48c5080bb246c07c71 Mon Sep 17 00:00:00 2001
From: David Cobbley <david.j.cobbley@linux.intel.com>
Date: Wed, 6 Jun 2018 11:11:43 -0700
Subject: [PATCH 2/3] IPv6 Network changes to configuration file

Allow Additional parameters to be set for IPv6

Change-Id: If662f1ce2d265bc525073890c49231bf6f2b8a30
---
 ethernet_interface.cpp | 109 +++++++++++++++++++++++++++++++++++++++--
 ethernet_interface.hpp |  19 ++++++-
 util.cpp               |   3 +-
 3 files changed, 124 insertions(+), 7 deletions(-)

diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index fd09b7a..63f1160 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -46,6 +46,8 @@ EthernetInterface::EthernetInterface(sdbusplus::bus::bus& bus,
     std::replace(intfName.begin(), intfName.end(), '_', '.');
     interfaceName(intfName);
     EthernetInterfaceIntf::dHCPEnabled(dhcpEnabled);
+    EthernetInterfaceIntf::iPAddressEnables(getIPAddressEnablesFromConf());
+    EthernetInterfaceIntf::iPv6AcceptRA(getIPv6AcceptRAFromConf());
     MacAddressIntf::mACAddress(getMACAddress(intfName));
     EthernetInterfaceIntf::nTPServers(getNTPServersFromConf());
     EthernetInterfaceIntf::nameservers(getNameServerFromConf());
@@ -322,7 +324,16 @@ std::string EthernetInterface::generateObjectPath(
     objectPath /= generateId(ipaddress, prefixLength, gateway);
     return objectPath.string();
 }
-
+bool EthernetInterface::iPv6AcceptRA(bool value)
+{
+    if (value == EthernetInterfaceIntf::iPv6AcceptRA())
+    {
+        return value;
+    }
+    EthernetInterfaceIntf::iPv6AcceptRA(value);
+    manager.writeToConfigurationFile();
+    return value;
+}
 bool EthernetInterface::dHCPEnabled(bool value)
 {
     if (value == EthernetInterfaceIntf::dHCPEnabled())
@@ -433,7 +444,80 @@ void EthernetInterface::createVLAN(VlanId id)
     // write the new vlan device entry to the configuration(network) file.
     manager.writeToConfigurationFile();
 }
+bool EthernetInterface::getIPv6AcceptRAFromConf()
+{
+    fs::path confPath = manager.getConfDir();
+
+    std::string fileName = systemd::config::networkFilePrefix +
+                           interfaceName() + systemd::config::networkFileSuffix;
+    confPath /= fileName;
+    config::ValueList values;
+    config::Parser parser(confPath.string());
+    auto rc = config::ReturnCode::SUCCESS;
+    std::tie(rc, values) = parser.getValues("Network", "IPv6AcceptRA");
+    if (rc != config::ReturnCode::SUCCESS)
+    {
+        log<level::DEBUG>("Unable to get the value for Network[IPv6AcceptRA]",
+                          entry("rc=%d", rc));
+        return false;
+    }
+    if (values[0] == "true")
+    {
+        return true;
+    }
+
+    return false;
+}
+EthernetInterface::IPAllowed EthernetInterface::getIPAddressEnablesFromConf()
+{
+    fs::path confPath = manager.getConfDir();
+
+    std::string fileName = systemd::config::networkFilePrefix +
+                           interfaceName() + systemd::config::networkFileSuffix;
+    confPath /= fileName;
+    config::ValueList values;
+    config::Parser parser(confPath.string());
+    auto rc = config::ReturnCode::SUCCESS;
+    std::tie(rc, values) = parser.getValues("Network", "DHCP");
+    if (rc != config::ReturnCode::SUCCESS)
+    {
+        log<level::DEBUG>("Unable to get the value for Network[DHCP]",
+                          entry("rc=%d", rc));
+        return EthernetInterface::IPAllowed::IPv4AndIPv6;
+    }
+    // true, false, ipv4, ipv6
+    if (values[0] == "ipv6")
+    {
+        return EthernetInterface::IPAllowed::IPv6Only;
+    }
+    else if (values[0] == "ipv4")
+    {
+        return EthernetInterface::IPAllowed::IPv4Only;
+    }
+    else if (values[0] == "off")
+    {
+        // This function should not get called if DHCP == off
+        log<level::DEBUG>("Function not available in static mode");
+        return EthernetInterface::IPAllowed::IPv4AndIPv6;
+    }
+    else
+    {
+        return EthernetInterface::IPAllowed::IPv4AndIPv6;
+    }
+}
+EthernetInterface::IPAllowed
+    EthernetInterface::iPAddressEnables(EthernetInterface::IPAllowed iPAllowed)
+{
+    if (iPAllowed == EthernetInterfaceIntf::iPAddressEnables())
+    {
+        return iPAllowed;
+    }
+
+    EthernetInterfaceIntf::iPAddressEnables(iPAllowed);
+    writeConfigurationFile();
 
+    return iPAllowed;
+}
 ServerList EthernetInterface::getNTPServersFromConf()
 {
     fs::path confPath = manager.getConfDir();
@@ -515,7 +599,8 @@ void EthernetInterface::writeConfigurationFile()
 #else
     stream << "LinkLocalAddressing=no\n";
 #endif
-    stream << "IPv6AcceptRA=false\n";
+    stream << std::boolalpha
+           << "IPv6AcceptRA=" << EthernetInterfaceIntf::iPv6AcceptRA() << "\n";
 
     // Add the VLAN entry
     for (const auto& intf : vlanInterfaces)
@@ -524,8 +609,24 @@ void EthernetInterface::writeConfigurationFile()
                << "\n";
     }
     // Add the DHCP entry
-    auto value = dHCPEnabled() ? "true"s : "false"s;
-    stream << "DHCP="s + value + "\n";
+    std::string dhcpValue = "false";
+    if (dHCPEnabled())
+    {
+        IPAllowed ipAllowed = EthernetInterfaceIntf::iPAddressEnables();
+        if (ipAllowed == IPAllowed::IPv4AndIPv6)
+        {
+            dhcpValue = "true";
+        }
+        else if (ipAllowed == IPAllowed::IPv4Only)
+        {
+            dhcpValue = "ipv4";
+        }
+        else if (ipAllowed == IPAllowed::IPv6Only)
+        {
+            dhcpValue = "ipv6";
+        }
+    }
+    stream << "DHCP=" << dhcpValue << "\n";
 
     // When the interface configured as dhcp, we don't need below given entries
     // in config file.
diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp
index d62ca34..7116b47 100644
--- a/ethernet_interface.hpp
+++ b/ethernet_interface.hpp
@@ -205,7 +205,24 @@ class EthernetInterface : public Ifaces
                                       const std::string& gateway);
 
         /** @brief write the dhcp section **/
-        void writeDHCPSection(std::fstream& stream);;
+        void writeDHCPSection(std::fstream& stream);
+
+        /** @brief get the IPv6AcceptRA flag from the network configuration file
+         *
+         */
+        bool getIPv6AcceptRAFromConf();
+
+        /** @brief check conf file for Router Advertisements
+         *
+         */
+        bool iPv6AcceptRA(bool value) override;
+
+        /** @brief get the allowed network modes. Similar to DHCP enabled, but
+         * more specific
+         */
+        IPAllowed getIPAddressEnablesFromConf();
+
+        IPAllowed iPAddressEnables(IPAllowed) override;
 
         /** @brief get the NTP server list from the network conf
          *
diff --git a/util.cpp b/util.cpp
index b66f908..9f06e2e 100644
--- a/util.cpp
+++ b/util.cpp
@@ -405,8 +405,7 @@ bool getDHCPValue(const std::string& confDir, const std::string& intf)
                           entry("RC=%d", rc));
         return dhcp;
     }
-    // There will be only single value for DHCP key.
-    if (values[0] == "true")
+    if (values[0] != "false")
     {
         dhcp = true;
     }
-- 
2.17.1