summaryrefslogtreecommitdiffstats
path: root/util.cpp
Commit message (Collapse)AuthorAgeFilesLines
* util: Don't ignore non-running interfacesHEADmasterWilliam A. Kennington III2019-04-111-2/+2
| | | | | | | | | | | | | We want to be able to configure interfaces which are not running. Just because we don't have a cable plugged into the machine doesn't mean we don't want to have the option to configure it from the host Tested: Built an image and made sure the interface was now present and configurable even if it had no link present. Change-Id: Ib93ddddc8ca015fe024209fa9cbeb5fc24421728 Signed-off-by: William A. Kennington III <wak@google.com>
* util: Add a MacAddr population functionWilliam A. Kennington III2019-02-141-0/+11
| | | | | | | | | | | | This one is pretty trivial since there is only one size of mac address, but we want to be sure we validate the buffer. Tested: Built and runs through unit tests. Works when integrated into neighbor parsing code. Change-Id: Iaf58fc398b51a3bcbbf70968cbe353beeb7b9f54 Signed-off-by: William A. Kennington III <wak@google.com>
* util: Add InAddrAny population functionWilliam A. Kennington III2019-02-141-0/+26
| | | | | | | | | | | | We commonly want to be able to turn netlink network order address data into the corresponding InAddrAny when parsing netlink data. This makes it trivial given the address family and data buffer. Tested: Ran throgh unit tests and builds fine in a BMC image. Change-Id: I4ebe1dbd284f150ea03ee091cddda5a06806c01f Signed-off-by: William A. Kennington III <wak@google.com>
* util: Add a function for converting IP bytes to stringsWilliam A. Kennington III2019-02-141-0/+30
| | | | | | | | | | We need this for future work which turns netlink data into IP addresses. Tested: Run through unit tests. Change-Id: If078b28246509ca2ebd3bf7bab652b84258df0bd Signed-off-by: William A. Kennington III <wak@google.com>
* util: Add a function for converting MAC addressesWilliam A. Kennington III2019-02-141-0/+15
| | | | | | | | | | | We need to be able to convert a mac addresses from byte form into our typical human readable string form. Tested: Unit tests pass. Change-Id: I6e68cfefd4d5962e1125c1b5229e61fce475729a Signed-off-by: William A. Kennington III <wak@google.com>
* Don't report/commit the errorRatan Gupta2018-11-301-2/+2
| | | | | | | | | If unable to fetch the networkID from the IP address string This is kind of internal failure where reporting is not needed and no service action is associated with it. Change-Id: Ia54226f2dd77a69fd23433730c424ee0e3c6ac57 Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
* Fix std::variant usageWilliam A. Kennington III2018-11-211-1/+1
| | | | | | | | This cleans up the use of mapbox only .get() variant apis in favor of the std::get() interface which both implementations provide. Change-Id: I9ba8301801d68b391fa5195de37b2b0ecec26edf Signed-off-by: William A. Kennington III <wak@google.com>
* clang-format: Update to match docs repoGunnar Mills2018-09-151-79/+65
| | | | | | | | | Update the .clang-format file and run clang-format-6.0. This .clang-format matches the example one in https://github.com/openbmc/docs/blob/master/cpp-style-and-conventions.md#clang-formatting Change-Id: Ia331c9a5b040e1a3c45a0ebf1b8d776d93b05ae5 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
* reorder headersPatrick Venture2018-08-271-7/+7
| | | | | | | | | | | | | | | | | | Reordering all the headers to the following structure: header file: local c cpp (including openbmc libraries) source file: source.hpp (if applicable) local c cpp Change-Id: Ia74a5c761a3029819366159de3cfd40c5e4c4a2c Signed-off-by: Patrick Venture <venture@google.com>
* Use s.c_str() in log messagesJoseph Reynolds2018-05-301-8/+8
| | | | | | | | | | | | | | Partly resolves openbmc/openbmc 2905 Bonus! The new static_assert found a related bug in log.cpp: log("msg", entry("fmt", data, entry("fmt", data))) which should have been: log("msg", entry("fmt", data), entry("fmt", data)) Tested: static_assert only Change-Id: Ie1c550a27f454ef92ee096d812adcc400a1a25cf Signed-off-by: Joseph Reynolds <jrey@us.ibm.com>
* Add IPv6 addresses to DbusDavid Cobbley2018-05-251-11/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Checking if the interface name is not the same as the previous is based upon the assumption that your list of interface names (ifa->ifa_name) will always come back in sorted order of the interface they belong to, i.e. eth0: 169.172.0.1 128.42.38.7 eth1: 14.243.48.103 fe80::740:61ff:fe74:3eb2 This assumption is wrong since the IP address can come in any order they please, i.e. eth0: 169.172.0.1 eth1: fe80::740:61ff:fe74:3eb2 eth0: 128.42.38.7 eth1: 14.243.48.103 The if condition I removed is looking to see if the interface name is not equal to the previous interface name, where it would assume it was rolling over to the next free interface, always leaving you with the last valid IP in the interface. In my case it was leaving me with only IPv4 addresses and not including IPv6 addresses. Tested By: Resetting my network to factory defaults, checking DBUS for all ipv6 addresses: dbus-send --system \ --print-reply \ --dest=xyz.openbmc_project.Network \ /xyz/openbmc_project/network/eth0/ipv6\ org.freedesktop.DBus.Introspectable.Introspect Adding an IPv6 Address: dbus-send --system \ --dest=xyz.openbmc_project.Network \ --type=method_call \ --print-reply \ /xyz/openbmc_project/network/eth0 \ xyz.openbmc_project.Network.IP.Create.IP \ string:"xyz.openbmc_project.Network.IP.Protocol.IPv6" \ string:"2002:1001:1001:1001:1001:1001:1001:1006" byte:10 \ string:"1001:1001:1001:1001:1001:1001:1001:1001" \ Validating the static IPv6 address appeared by the initial introspect command. Change-Id: I3b85cecded696c251028accb28448f6e53bd9a7f Signed-off-by: David Cobbley <david.j.cobbley@linux.intel.com>
* Reduce journal logsRatan Gupta2018-03-151-10/+12
| | | | | | | | | | | | | | | | | | | | Presently the code was creating the elog during reading of the values from the config parser which creates the journal log internally("Internal error Occured") Apart from creating elog,Code also logs into the journal more descriptive message saying which section and key was not found. The code which catches the exception that also logs into the journal. In the changed approach instead of throwing exception we are returning the return code as not finding a section or key in the network config file is not an error. Change-Id: Ib89a3af6541fdf93fb5fa9a8e583d6c6ed88da79 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Spelling fixesGunnar Mills2017-10-261-1/+1
| | | | | Change-Id: I953614024660287b94d835e30b117cc4023e749b Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
* IP Address use case validationNagaraju Goruganti2017-10-111-5/+32
| | | | | | | | | | | -validates IPAddress/gateway using inet_pton api. -validates prefix length for ipv4/ipv6. -if dhcp is enabled, it won't allow to set ip/gateway. Resolves openbmc/openbmc#1671 Change-Id: I76c1d9d11dfb59002eb1310d87e94ee622714a4a Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
* Implement getInterfaces in utilRatan Gupta2017-09-291-0/+32
| | | | | | | | | | | | getInterfaceAddrs returns the map of interface and associated address,if there is no address associated with the interface,then we don't get that interface. This API gets all the available interfaces on the system. Change-Id: I86f07d6e9950a15547cb74356939ca40368bddcc Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Grammar fixes for util.cppGunnar Mills2017-09-261-1/+1
| | | | | Change-Id: If9b52187610651afc9d800bf6f5f3b81b1f1df19 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
* Implement Set function for MAC addressRatan Gupta2017-09-091-1/+142
| | | | | Change-Id: I16992dda259246a66512792f06cbbb874e56a15d Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Move getDHCPValue function to utilRatan Gupta2017-08-131-1/+32
| | | | | Change-Id: Id90e60aec666e5098358f1890fbdead6744e2675 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* vlan: implement delete interfaceRatan Gupta2017-08-131-8/+53
| | | | | | | | | Delete the in-memory vlan object,Also deletes the associated device file and the network file. Change-Id: I613e31aaa4fa9172c6226765ac044481ffbd88ec Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Implement generic restart systemd unit functionRatan Gupta2017-07-191-0/+1
| | | | | Change-Id: Ibd0ec4e7c3b9c395898673839ccf4de85616b201 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Move function from network manager to utility functionRatan Gupta2017-06-211-3/+94
| | | | | | | | Function which fetches the interface address from the system. Add some types to types.hpp Change-Id: Ie2c02980a9fd7a0aaeafa22d93bc758b5c79fd04 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Fetch the network portion of the IP addressRatan Gupta2017-06-081-3/+65
| | | | | | | eg 192.168.2.24/24 ==> 192.168.2.0 Change-Id: I5e46ce7b371360c90ef74fac175c8379c6f31d4c Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Add the network utility fileRatan Gupta2017-06-081-0/+144
Moving utility functions from network manager to util.cpp. Added few more utility functions. Change-Id: I2e73c873e9a3bea543d6979463b2181e8374e12e Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
OpenPOWER on IntegriCloud