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

Commit 86a0ff91 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

libnetdevice: define default request flags

Bug: 372814636
Test: verified with b/372814636 test service
Change-Id: I81e8ac625e6d075d9780b6e2e0a172aec0a04468
parent cd635b94
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ 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) {
+3 −5
Original line number Diff line number Diff line
@@ -104,8 +104,7 @@ bool setAddr4(std::string_view ifname, std::string_view addr) {
}

bool addAddr4(std::string_view ifname, std::string_view addr, uint8_t prefixlen) {
    android::nl::MessageFactory<ifaddrmsg> req(
            RTM_NEWADDR, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL | NLM_F_ACK);
    nl::MessageFactory<ifaddrmsg> req(RTM_NEWADDR, nl::kCreateFlags);
    req->ifa_family = AF_INET;
    req->ifa_prefixlen = prefixlen;
    req->ifa_flags = IFA_F_SECONDARY;
@@ -120,8 +119,7 @@ bool addAddr4(std::string_view ifname, std::string_view addr, uint8_t prefixlen)
}

bool add(std::string_view dev, std::string_view type) {
    nl::MessageFactory<ifinfomsg> req(RTM_NEWLINK,
                                      NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL | NLM_F_ACK);
    nl::MessageFactory<ifinfomsg> req(RTM_NEWLINK, nl::kCreateFlags);
    req.add(IFLA_IFNAME, dev);

    {
@@ -134,7 +132,7 @@ bool add(std::string_view dev, std::string_view type) {
}

bool del(std::string_view dev) {
    nl::MessageFactory<ifinfomsg> req(RTM_DELLINK, NLM_F_REQUEST | NLM_F_ACK);
    nl::MessageFactory<ifinfomsg> req(RTM_DELLINK);
    req.add(IFLA_IFNAME, dev);

    nl::Socket sock(NETLINK_ROUTE);
+1 −2
Original line number Diff line number Diff line
@@ -33,8 +33,7 @@ bool add(std::string_view eth, std::string_view vlan, uint16_t id) {
        return false;
    }

    nl::MessageFactory<ifinfomsg> req(RTM_NEWLINK,
                                      NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL | NLM_F_ACK);
    nl::MessageFactory<ifinfomsg> req(RTM_NEWLINK, nl::kCreateFlags);
    req.add(IFLA_IFNAME, vlan);
    req.add<uint32_t>(IFLA_LINK, ethidx);

+4 −1
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@

namespace android::nl {

static constexpr uint16_t kDefaultFlags = NLM_F_REQUEST | NLM_F_ACK;
static constexpr uint16_t kCreateFlags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL | NLM_F_ACK;

class MessageFactoryBase {
  protected:
    static nlattr* add(nlmsghdr* msg, size_t maxLen, nlattrtype_t type, const void* data,
@@ -54,7 +57,7 @@ class MessageFactory : private MessageFactoryBase {
     * \param type Message type (such as RTM_NEWLINK).
     * \param flags Message flags (such as NLM_F_REQUEST).
     */
    MessageFactory(nlmsgtype_t type, uint16_t flags)
    MessageFactory(nlmsgtype_t type, uint16_t flags = kDefaultFlags)
        : header(mMessage.header), data(mMessage.data) {
        mMessage.header.nlmsg_len = offsetof(Message, attributesBuffer);
        mMessage.header.nlmsg_type = type;