Skip to content

Drop unnecessary size checks and corrections for Netlink attributes. #11888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions test/syscalls/linux/socket_netlink_netfilter_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
namespace gvisor {
namespace testing {

static const std::map<uint16_t, size_t> kNetfilterAttributeSizes = {
{NFTA_TABLE_FLAGS, sizeof(uint32_t)},
{NFTA_TABLE_HANDLE, sizeof(uint64_t)},
{NFTA_TABLE_USE, sizeof(uint32_t)},
{NFTA_TABLE_OWNER, sizeof(uint32_t)},
};

NlReq& NlReq::MsgType(uint8_t message_type) {
message_type_ = message_type;
return *this;
Expand All @@ -54,22 +47,13 @@ NlReq& NlReq::Family(uint8_t family) {
return *this;
}

// Method to add an attribute to the message. If there is a default
// size for the attribute type, it will be used.
// Otherwise, assumes the payload is of at least size payload_size.
// Method to add an attribute to the message. payload_size must be the size of
// the payload in bytes.
NlReq& NlReq::RawAttr(uint16_t attr_type, const void* payload,
size_t payload_size) {
// Check if the attribute type has a standard size. Otherwise
// use the provided size.
size_t attr_size;
if (kNetfilterAttributeSizes.count(attr_type)) {
attr_size = kNetfilterAttributeSizes.at(attr_type);
} else {
attr_size = payload_size;
}

// Store a pointer to the payload and the size to construct it later.
attributes_[attr_type] = {reinterpret_cast<const char*>(payload), attr_size};
attributes_[attr_type] = {reinterpret_cast<const char*>(payload),
payload_size};
return *this;
}

Expand Down
5 changes: 2 additions & 3 deletions test/syscalls/linux/socket_netlink_netfilter_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ class NlReq {
NlReq& Seq(uint32_t seq);
NlReq& Family(uint8_t family);

// Method to add an attribute to the message. If there is a default
// size for the attribute type, it will be used.
// Otherwise, assumes the payload is of at least size payload_size.
// Method to add an attribute to the message. payload_size must be the size of
// the payload in bytes.
NlReq& RawAttr(uint16_t attr_type, const void* payload, size_t payload_size);

// Method to add a string attribute to the message.
Expand Down
Loading