summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0002-IPv6-Network-changes-to-configuration-file.patch
blob: b46702902b51a64cf6b7e59ae71c99457b22e877 (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
From 53dbefc9f31dcfca06d7c7705ea3dcfc5e93ae72 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 1/2] IPv6 Network changes to configuration file

Allow Additional parameters to be set for IPv6

Change-Id: If662f1ce2d265bc525073890c49231bf6f2b8a30
---
 ethernet_interface.cpp | 109 +++++++++++++++++++++++++++++++++++++++--
 ethernet_interface.hpp |  17 +++++++
 util.cpp               |   3 +-
 3 files changed, 123 insertions(+), 6 deletions(-)

diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 154efcb..aa1c895 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());
@@ -329,7 +331,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())
@@ -442,7 +453,80 @@ ObjectPath EthernetInterface::createVLAN(VlanId id)
 
     return path;
 }
+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();
@@ -524,7 +608,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)
@@ -533,8 +618,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 c65726a..55fd7d9 100644
--- a/ethernet_interface.hpp
+++ b/ethernet_interface.hpp
@@ -207,6 +207,23 @@ class EthernetInterface : public Ifaces
     /** @brief write the dhcp section **/
     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 6bc1497..6c60d54 100644
--- a/util.cpp
+++ b/util.cpp
@@ -461,8 +461,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