Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 310c3234 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Android (Google) Code Review
Browse files

Merge changes I81e8ac62,I59af9750,I9a6226a9,I96b51cc9 into main

* changes:
  libnetdevice: define default request flags
  libnetdevice: implement ipv4 get/set/add operations
  libnetdevice: migrate API to std::string_view
  libnetdevice: support host
parents dfbec1ef 86a0ff91
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ package {
cc_library_static {
    name: "android.hardware.automotive.can@libnetdevice",
    defaults: ["android.hardware.automotive.can@defaults"],
    host_supported: true,
    vendor_available: true,
    srcs: [
        "can.cpp",
+3 −3
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ namespace android::netdevice::can {

static constexpr can_err_mask_t kErrMask = CAN_ERR_MASK;

base::unique_fd socket(const std::string& ifname) {
base::unique_fd socket(std::string_view ifname) {
    sockaddr_can addr = {};
    addr.can_family = AF_CAN;
    addr.can_ifindex = nametoindex(ifname);
@@ -66,11 +66,11 @@ base::unique_fd socket(const std::string& ifname) {
    return sock;
}

bool setBitrate(std::string ifname, uint32_t bitrate) {
bool setBitrate(std::string_view ifname, uint32_t bitrate) {
    can_bittiming bt = {};
    bt.bitrate = bitrate;

    nl::MessageFactory<ifinfomsg> req(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_ACK);
    nl::MessageFactory<ifinfomsg> req(RTM_NEWLINK);

    req->ifi_index = nametoindex(ifname);
    if (req->ifi_index == 0) {
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@

namespace android::netdevice {

unsigned int nametoindex(const std::string& ifname) {
    const auto ifidx = if_nametoindex(ifname.c_str());
unsigned int nametoindex(std::string_view ifname) {
    const auto ifidx = if_nametoindex(std::string(ifname).c_str());
    if (ifidx != 0) return ifidx;

    if (errno != ENODEV) {
+1 −1
Original line number Diff line number Diff line
@@ -32,6 +32,6 @@ namespace android::netdevice {
 * \param ifname Interface to check
 * \return Interface index, or 0 if the interface doesn't exist
 */
unsigned int nametoindex(const std::string& ifname);
unsigned int nametoindex(std::string_view ifname);

}  // namespace android::netdevice
+5 −4
Original line number Diff line number Diff line
@@ -19,27 +19,28 @@
#include "ifreqs.h"

#include <linux/ethtool.h>
#include <linux/sockios.h>

namespace android::netdevice::ethtool {

std::optional<uint32_t> getValue(const std::string& ifname, uint32_t command) {
std::optional<uint32_t> getValue(std::string_view ifname, uint32_t command) {
    struct ethtool_value valueop = {};
    valueop.cmd = command;

    auto ifr = ifreqs::fromName(ifname);
    ifr.ifr_data = &valueop;
    ifr.ifr_data = reinterpret_cast<caddr_t>(&valueop);

    if (!ifreqs::send(SIOCETHTOOL, ifr)) return std::nullopt;
    return valueop.data;
}

bool setValue(const std::string& ifname, uint32_t command, uint32_t value) {
bool setValue(std::string_view ifname, uint32_t command, uint32_t value) {
    struct ethtool_value valueop = {};
    valueop.cmd = command;
    valueop.data = value;

    auto ifr = ifreqs::fromName(ifname);
    ifr.ifr_data = &valueop;
    ifr.ifr_data = reinterpret_cast<caddr_t>(&valueop);

    return ifreqs::send(SIOCETHTOOL, ifr);
}
Loading