summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-network/network/network/0001-Patch-to-keep-consistent-MAC-and-IP-address-inbetwee.patch
blob: 03460302de4dff929e5d93fafb91ca4b4cd45fbf (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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
From 15f9ba436815307c1df7ace505e6f6ee04a4762b Mon Sep 17 00:00:00 2001
From: David Cobbley <david.j.cobbley@linux.intel.com>
Date: Thu, 8 Mar 2018 12:18:00 -0800
Subject: [PATCH 1/3] Patch to keep consistent MAC and IP address inbetween
 power cycles

Currently, your mac will reset upon AC cycle unless you ask systemd use
a MAC provided in your network configuration file. This will write your
randomly generate MAC to the config file upond first boot up.

Change-Id: Id47d24c62e459cde101add18be2f46c0b010e7fe
Signed-off-by: David Cobbley <david.j.cobbley@linux.intel.com>
Signed-off-by: James Feist <james.feist@linux.intel.com>
---
 ethernet_interface.cpp |   4 +-
 ethernet_interface.hpp | 360 +++++++++++++++++++++--------------------
 network_config.cpp     |  22 +--
 3 files changed, 195 insertions(+), 191 deletions(-)

diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 3fd7835..fd09b7a 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -200,8 +200,8 @@ InterfaceInfo EthernetInterface::getInterfaceInfo() const
  *  @return macaddress on success
  */
 
-std::string
-    EthernetInterface::getMACAddress(const std::string& interfaceName) const
+std::string EthernetInterface::getMACAddress(
+        const std::string& interfaceName)
 {
     ifreq ifr{};
     char macAddress[mac_address::size]{};
diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp
index bfe1d54..d62ca34 100644
--- a/ethernet_interface.hpp
+++ b/ethernet_interface.hpp
@@ -59,185 +59,187 @@ using VlanInterfaceMap =
  */
 class EthernetInterface : public Ifaces
 {
-  public:
-    EthernetInterface() = delete;
-    EthernetInterface(const EthernetInterface&) = delete;
-    EthernetInterface& operator=(const EthernetInterface&) = delete;
-    EthernetInterface(EthernetInterface&&) = delete;
-    EthernetInterface& operator=(EthernetInterface&&) = delete;
-    virtual ~EthernetInterface() = default;
-
-    /** @brief Constructor to put object onto bus at a dbus path.
-     *  @param[in] bus - Bus to attach to.
-     *  @param[in] objPath - Path to attach at.
-     *  @param[in] dhcpEnabled - is dhcp enabled(true/false).
-     *  @param[in] parent - parent object.
-     *  @param[in] emitSignal - true if the object added signal needs to be
-     *                          send.
-     */
-    EthernetInterface(sdbusplus::bus::bus& bus, const std::string& objPath,
-                      bool dhcpEnabled, Manager& parent,
-                      bool emitSignal = true);
-
-    /** @brief Function to create ipaddress dbus object.
-     *  @param[in] addressType - Type of ip address.
-     *  @param[in] ipaddress- IP address.
-     *  @param[in] prefixLength - Length of prefix.
-     *  @param[in] gateway - Gateway ip address.
-     */
-
-    void iP(IP::Protocol addressType, std::string ipaddress,
-            uint8_t prefixLength, std::string gateway) override;
-
-    /* @brief delete the dbus object of the given ipaddress.
-     * @param[in] ipaddress - IP address.
-     */
-    void deleteObject(const std::string& ipaddress);
-
-    /* @brief delete the vlan dbus object of the given interface.
-     *        Also deletes the device file and the network file.
-     * @param[in] interface - VLAN Interface.
-     */
-    void deleteVLANObject(const std::string& interface);
-
-    /* @brief creates the dbus object(IPaddres) given in the address list.
-     * @param[in] addrs - address list for which dbus objects needs
-     *                    to create.
-     */
-    void createIPAddressObjects();
-
-    /* @brief Gets all the ip addresses.
-     * @returns the list of ipaddress.
-     */
-    const AddressMap& getAddresses() const
-    {
-        return addrs;
-    }
-
-    /** Set value of DHCPEnabled */
-    bool dHCPEnabled(bool value) override;
-
-    /** @brief sets the MAC address.
-     *  @param[in] value - MAC address which needs to be set on the system.
-     *  @returns macAddress of the interface or throws an error.
-     */
-    std::string mACAddress(std::string value) override;
-
-    /** @brief sets the NTP servers.
-     *  @param[in] value - vector of NTP servers.
-     */
-    ServerList nTPServers(ServerList value) override;
-
-    /** @brief sets the DNS/nameservers.
-     *  @param[in] value - vector of DNS servers.
-     */
-    ServerList nameservers(ServerList value) override;
-
-    /** @brief create Vlan interface.
-     *  @param[in] id- VLAN identifier.
-     */
-    void createVLAN(VlanId id);
-
-    /** @brief load the vlan info from the system
-     *         and creates the ip address dbus objects.
-     *  @param[in] vlanID- VLAN identifier.
-     */
-    void loadVLAN(VlanId vlanID);
-
-    /** @brief write the network conf file with the in-memory objects.
-     */
-    void writeConfigurationFile();
-
-    /** @brief delete all dbus objects.
-     */
-    void deleteAll();
-
-    using EthernetInterfaceIntf::dHCPEnabled;
-    using EthernetInterfaceIntf::interfaceName;
-    using MacAddressIntf::mACAddress;
-
-    /** @brief Absolute path of the resolv conf file */
-    static constexpr auto resolvConfFile = "/etc/resolv.conf";
-
-  protected:
-    /** @brief get the info of the ethernet interface.
-     *  @return tuple having the link speed,autonegotiation,duplexmode .
-     */
-    InterfaceInfo getInterfaceInfo() const;
-
-    /* @brief delete the vlan interface from system.
-     * @param[in] interface - vlan Interface.
-     */
-    void deleteVLANFromSystem(const std::string& interface);
-
-    /** @brief get the mac address of the interface.
-     *  @param[in] interfaceName - Network interface name.
-     *  @return macaddress on success
-     */
-
-    std::string getMACAddress(const std::string& interfaceName) const;
-
-    /** @brief construct the ip address dbus object path.
-     *  @param[in] addressType - Type of ip address.
-     *  @param[in] ipaddress - IP address.
-     *  @param[in] prefixLength - Length of prefix.
-     *  @param[in] gateway - Gateway address.
-
-     *  @return path of the address object.
-     */
-
-    std::string generateObjectPath(IP::Protocol addressType,
-                                   const std::string& ipaddress,
-                                   uint8_t prefixLength,
-                                   const std::string& gateway) const;
-
-    /** @brief generates the id by doing hash of ipaddress,
-     *         prefixlength and the gateway.
-     *  @param[in] ipaddress - IP address.
-     *  @param[in] prefixLength - Length of prefix.
-     *  @param[in] gateway - Gateway address.
-     *  @return hash string.
-     */
-
-    static std::string generateId(const std::string& ipaddress,
-                                  uint8_t prefixLength,
-                                  const std::string& gateway);
-
-    /** @brief write the dhcp section **/
-    void writeDHCPSection(std::fstream& stream);
-
-    /** @brief get the NTP server list from the network conf
-     *
-     */
-    ServerList getNTPServersFromConf();
-
-    /** @brief write the DNS entries to resolver file.
-     *  @param[in] dnsList - DNS server list which needs to be written.
-     *  @param[in] file    - File to write the name server entries to.
-     */
-    void writeDNSEntries(const ServerList& dnsList, const std::string& file);
-
-    /** @brief get the name server details from the network conf
-     *
-     */
-    ServerList getNameServerFromConf();
-
-    /** @brief Persistent sdbusplus DBus bus connection. */
-    sdbusplus::bus::bus& bus;
-
-    /** @brief Network Manager object. */
-    Manager& manager;
-
-    /** @brief Persistent map of IPAddress dbus objects and their names */
-    AddressMap addrs;
-
-    /** @brief Persistent map of VLAN interface dbus objects and their names */
-    VlanInterfaceMap vlanInterfaces;
-
-    /** @brief Dbus object path */
-    std::string objPath;
-
-    friend class TestEthernetInterface;
+    public:
+        EthernetInterface() = delete;
+        EthernetInterface(const EthernetInterface&) = delete;
+        EthernetInterface& operator=(const EthernetInterface&) = delete;
+        EthernetInterface(EthernetInterface&&) = delete;
+        EthernetInterface& operator=(EthernetInterface&&) = delete;
+        virtual ~EthernetInterface() = default;
+
+        /** @brief Constructor to put object onto bus at a dbus path.
+         *  @param[in] bus - Bus to attach to.
+         *  @param[in] objPath - Path to attach at.
+         *  @param[in] dhcpEnabled - is dhcp enabled(true/false).
+         *  @param[in] parent - parent object.
+         *  @param[in] emitSignal - true if the object added signal needs to be
+         *                          send.
+         */
+        EthernetInterface(sdbusplus::bus::bus& bus,
+                          const std::string& objPath,
+                          bool dhcpEnabled,
+                          Manager& parent,
+                          bool emitSignal = true);
+
+        /** @brief Function to create ipaddress dbus object.
+         *  @param[in] addressType - Type of ip address.
+         *  @param[in] ipaddress- IP address.
+         *  @param[in] prefixLength - Length of prefix.
+         *  @param[in] gateway - Gateway ip address.
+         */
+
+        void iP(IP::Protocol addressType,
+                std::string ipaddress,
+                uint8_t prefixLength,
+                std::string gateway) override;
+
+        /* @brief delete the dbus object of the given ipaddress.
+         * @param[in] ipaddress - IP address.
+         */
+        void deleteObject(const std::string& ipaddress);
+
+        /* @brief delete the vlan dbus object of the given interface.
+         *        Also deletes the device file and the network file.
+         * @param[in] interface - VLAN Interface.
+         */
+        void deleteVLANObject(const std::string& interface);
+
+        /* @brief creates the dbus object(IPaddres) given in the address list.
+         * @param[in] addrs - address list for which dbus objects needs
+         *                    to create.
+         */
+        void createIPAddressObjects();
+
+        /* @brief Gets all the ip addresses.
+         * @returns the list of ipaddress.
+         */
+        const AddressMap& getAddresses() const { return addrs; }
+
+        /** Set value of DHCPEnabled */
+        bool dHCPEnabled(bool value) override;
+
+        /** @brief sets the MAC address.
+         *  @param[in] value - MAC address which needs to be set on the system.
+         *  @returns macAddress of the interface or throws an error.
+         */
+        std::string mACAddress(std::string value) override;
+
+        /** @brief sets the NTP servers.
+         *  @param[in] value - vector of NTP servers.
+         */
+        ServerList nTPServers(ServerList value) override;
+
+        /** @brief sets the DNS/nameservers.
+         *  @param[in] value - vector of DNS servers.
+         */
+        ServerList nameservers(ServerList value) override;
+
+        /** @brief create Vlan interface.
+         *  @param[in] id- VLAN identifier.
+         */
+        void createVLAN(VlanId id);
+
+        /** @brief load the vlan info from the system
+         *         and creates the ip address dbus objects.
+         *  @param[in] vlanID- VLAN identifier.
+         */
+        void loadVLAN(VlanId vlanID);
+
+        /** @brief write the network conf file with the in-memory objects.
+         */
+        void writeConfigurationFile();
+
+        /** @brief delete all dbus objects.
+         */
+        void deleteAll();
+
+        /** @brief get the mac address of the interface.
+         *  @param[in] interfaceName - Network interface name.
+         *  @return macaddress on success
+         */
+
+        static std::string getMACAddress(const std::string& interfaceName);
+
+        using EthernetInterfaceIntf::dHCPEnabled;
+        using EthernetInterfaceIntf::interfaceName;
+        using MacAddressIntf::mACAddress;
+
+        /** @brief Absolute path of the resolv conf file */
+        static constexpr auto resolvConfFile = "/etc/resolv.conf";
+
+    protected:
+        /** @brief get the info of the ethernet interface.
+         *  @return tuple having the link speed,autonegotiation,duplexmode .
+         */
+        InterfaceInfo getInterfaceInfo() const;
+
+        /* @brief delete the vlan interface from system.
+         * @param[in] interface - vlan Interface.
+         */
+        void deleteVLANFromSystem(const std::string& interface);
+
+        /** @brief construct the ip address dbus object path.
+         *  @param[in] addressType - Type of ip address.
+         *  @param[in] ipaddress - IP address.
+         *  @param[in] prefixLength - Length of prefix.
+         *  @param[in] gateway - Gateway address.
+
+         *  @return path of the address object.
+         */
+
+        std::string generateObjectPath(IP::Protocol addressType,
+                                       const std::string& ipaddress,
+                                       uint8_t prefixLength,
+                                       const std::string& gateway) const;
+
+        /** @brief generates the id by doing hash of ipaddress,
+         *         prefixlength and the gateway.
+         *  @param[in] ipaddress - IP address.
+         *  @param[in] prefixLength - Length of prefix.
+         *  @param[in] gateway - Gateway address.
+         *  @return hash string.
+         */
+
+        static std::string generateId(const std::string& ipaddress,
+                                      uint8_t prefixLength,
+                                      const std::string& gateway);
+
+        /** @brief write the dhcp section **/
+        void writeDHCPSection(std::fstream& stream);;
+
+        /** @brief get the NTP server list from the network conf
+         *
+         */
+        ServerList getNTPServersFromConf();
+
+        /** @brief write the DNS entries to resolver file.
+         *  @param[in] dnsList - DNS server list which needs to be written.
+         *  @param[in] file    - File to write the name server entries to.
+         */
+        void writeDNSEntries(const ServerList& dnsList,
+                             const std::string& file);
+
+        /** @brief get the name server details from the network conf
+         *
+         */
+        ServerList getNameServerFromConf();
+
+        /** @brief Persistent sdbusplus DBus bus connection. */
+        sdbusplus::bus::bus& bus;
+
+        /** @brief Network Manager object. */
+        Manager& manager;
+
+        /** @brief Persistent map of IPAddress dbus objects and their names */
+        AddressMap addrs;
+
+        /** @brief Persistent map of VLAN interface dbus objects and their names */
+        VlanInterfaceMap vlanInterfaces;
+
+        /** @brief Dbus object path */
+        std::string objPath;
+
+        friend class TestEthernetInterface;
 };
 
 } // namespace network
diff --git a/network_config.cpp b/network_config.cpp
index e83b16c..8ebad54 100644
--- a/network_config.cpp
+++ b/network_config.cpp
@@ -1,3 +1,5 @@
+#include "network_config.hpp"
+#include "ethernet_interface.hpp"
 #include "config.h"
 
 #include "network_config.hpp"
@@ -5,27 +7,27 @@
 #include <fstream>
 #include <string>
 
-namespace phosphor
-{
-namespace network
-{
+namespace phosphor {
+namespace network {
 
-namespace bmc
-{
-void writeDHCPDefault(const std::string& filename, const std::string& interface)
+namespace bmc {
+void writeDHCPDefault(const std::string &filename, const std::string &interface)
 {
+
     std::ofstream filestream;
 
     filestream.open(filename);
     filestream << "[Match]\nName=" << interface <<
-                "\n[Network]\nDHCP=true\n"
+            "\n[Network]\nDHCP=true\n"
 #ifdef LINK_LOCAL_AUTOCONFIGURATION
                 "LinkLocalAddressing=yes\n"
 #else
                 "LinkLocalAddressing=no\n"
 #endif
-                "IPv6AcceptRA=false\n"
-                "[DHCP]\nClientIdentifier=mac\n";
+                        "IPv6AcceptRA=false\n"
+                        "[DHCP]\nClientIdentifier=mac\n"
+                        "[Link]\nMACAddress="
+        << EthernetInterface::getMACAddress(interface) << "\n";
     filestream.close();
 }
 } // namespace bmc
-- 
2.17.1