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

Commit bc70cd9e authored by Keith Mok's avatar Keith Mok Committed by Android (Google) Code Review
Browse files

Merge changes If51380ca,I4dae7ad3

* changes:
  libnl++: add new func to send raw data with len
  libnl++: Fix alignment problem
parents 23ffe48a 6355aa90
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ bool setBitrate(std::string ifname, uint32_t bitrate) {

    {
        auto linkinfo = req.addNested(IFLA_LINKINFO);
        req.add(IFLA_INFO_KIND, "can");
        req.addBuffer(IFLA_INFO_KIND, "can");
        {
            auto infodata = req.addNested(IFLA_INFO_DATA);
            /* For CAN FD, it would require to add IFLA_CAN_DATA_BITTIMING
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ bool add(std::string dev, std::string type) {

    {
        auto linkinfo = req.addNested(IFLA_LINKINFO);
        req.add(IFLA_INFO_KIND, type);
        req.addBuffer(IFLA_INFO_KIND, type);
    }

    nl::Socket sock(NETLINK_ROUTE);
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ bool add(const std::string& eth, const std::string& vlan, uint16_t id) {

    {
        auto linkinfo = req.addNested(IFLA_LINKINFO);
        req.add(IFLA_INFO_KIND, "vlan");
        req.addBuffer(IFLA_INFO_KIND, "vlan");

        {
            auto linkinfo = req.addNested(IFLA_INFO_DATA);
+2 −2
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ static nlattr* tail(nlmsghdr* msg) {

nlattr* MessageFactoryBase::add(nlmsghdr* msg, size_t maxLen, nlattrtype_t type, const void* data,
                                size_t dataLen) {
    const auto totalAttrLen = impl::space<nlattr>(dataLen);
    const auto newLen = impl::align(msg->nlmsg_len) + totalAttrLen;
    const auto totalAttrLen = impl::length<nlattr>(dataLen);
    const auto newLen = impl::align(msg->nlmsg_len) + impl::align(totalAttrLen);
    if (newLen > maxLen) {
        LOG(ERROR) << "Can't add attribute of size " << dataLen  //
                   << " - exceeded maxLen: " << newLen << " > " << maxLen;
+12 −5
Original line number Diff line number Diff line
@@ -106,18 +106,25 @@ class MessageFactory : private MessageFactoryBase {
     */
    template <class A>
    void add(nlattrtype_t type, const A& attr) {
        add(type, &attr, sizeof(attr));
        addInternal(type, &attr, sizeof(attr));
    }

    // It will always send the last null character, otherwise use addBuffer
    // variant instead
    template <>
    void add(nlattrtype_t type, const std::string& s) {
        add(type, s.c_str(), s.size() + 1);
        addInternal(type, s.c_str(), s.size() + 1);
    }

    void addBuffer(nlattrtype_t type, const std::string_view& s) {
        addInternal(type, s.data(), s.size());
    }

    /** Guard class to frame nested attributes. \see addNested(nlattrtype_t). */
    class [[nodiscard]] NestedGuard {
      public:
        NestedGuard(MessageFactory & req, nlattrtype_t type) : mReq(req), mAttr(req.add(type)) {}
        NestedGuard(MessageFactory& req, nlattrtype_t type)
            : mReq(req), mAttr(req.addInternal(type)) {}
        ~NestedGuard() { closeNested(&mReq.mMessage.header, mAttr); }

      private:
@@ -138,7 +145,7 @@ class MessageFactory : private MessageFactoryBase {
     *    MessageFactory<ifinfomsg> req(RTM_NEWLINK, NLM_F_REQUEST);
     *    {
     *        auto linkinfo = req.addNested(IFLA_LINKINFO);
     *        req.add(IFLA_INFO_KIND, "can");
     *        req.addBuffer(IFLA_INFO_KIND, "can");
     *        {
     *            auto infodata = req.addNested(IFLA_INFO_DATA);
     *            req.add(IFLA_CAN_BITTIMING, bitTimingStruct);
@@ -154,7 +161,7 @@ class MessageFactory : private MessageFactoryBase {
    Message mMessage = {};
    bool mIsGood = true;

    nlattr* add(nlattrtype_t type, const void* data = nullptr, size_t len = 0) {
    nlattr* addInternal(nlattrtype_t type, const void* data = nullptr, size_t len = 0) {
        if (!mIsGood) return nullptr;
        auto attr = MessageFactoryBase::add(&mMessage.header, sizeof(mMessage), type, data, len);
        if (attr == nullptr) mIsGood = false;
Loading