-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue-1444: move netlink helpers to core/libs/netlink (#2471)
- Loading branch information
1 parent
98d2c20
commit f82fa2c
Showing
8 changed files
with
238 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "message.h" | ||
|
||
namespace NCloud::NNetlink { | ||
|
||
TNestedAttribute::TNestedAttribute(nl_msg* message, int attribute) | ||
: Message(message) | ||
{ | ||
Attribute = nla_nest_start(message, attribute); | ||
if (!Attribute) { | ||
throw TServiceError(E_FAIL) << "unable to nest attribute"; | ||
} | ||
} | ||
|
||
TNestedAttribute::~TNestedAttribute() | ||
{ | ||
nla_nest_end(Message, Attribute); | ||
} | ||
|
||
TMessage::TMessage(int family, int command) | ||
{ | ||
Message = nlmsg_alloc(); | ||
if (Message == nullptr) { | ||
throw TServiceError(E_FAIL) << "unable to allocate message"; | ||
} | ||
genlmsg_put( | ||
Message, | ||
NL_AUTO_PORT, | ||
NL_AUTO_SEQ, | ||
family, | ||
0, // hdrlen | ||
0, // flags | ||
command, | ||
1); // version | ||
} | ||
|
||
TMessage::~TMessage() | ||
{ | ||
nlmsg_free(Message); | ||
} | ||
|
||
TNestedAttribute TMessage::Nest(int attribute) | ||
{ | ||
return TNestedAttribute(Message, attribute); | ||
} | ||
|
||
void TMessage::Put(int attribute, void* data, size_t size) | ||
{ | ||
if (int err = nla_put(Message, attribute, size, data)) { | ||
throw TServiceError(E_FAIL) | ||
<< "unable to put attribute " << attribute << ": " | ||
<< nl_geterror(err); | ||
} | ||
} | ||
|
||
} // namespace NCloud::NNetlink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <cloud/storage/core/libs/common/error.h> | ||
|
||
#include <netlink/genl/ctrl.h> | ||
#include <netlink/genl/genl.h> | ||
|
||
namespace NCloud::NNetlink { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
class TNestedAttribute | ||
{ | ||
private: | ||
nl_msg* Message; | ||
nlattr* Attribute; | ||
|
||
public: | ||
TNestedAttribute(nl_msg* message, int attribute); | ||
~TNestedAttribute(); | ||
}; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
class TMessage | ||
{ | ||
private: | ||
nl_msg* Message; | ||
|
||
public: | ||
TMessage(int family, int command); | ||
~TMessage(); | ||
|
||
operator nl_msg*() const | ||
{ | ||
return Message; | ||
} | ||
|
||
TNestedAttribute Nest(int attribute); | ||
|
||
void Put(int attribute, void* data, size_t size); | ||
|
||
template <typename T> | ||
void Put(int attribute, T data) | ||
{ | ||
Put(attribute, &data, sizeof(T)); | ||
} | ||
}; | ||
|
||
} // namespace NCloud::NNetlink |
Oops, something went wrong.