Skip to content

Commit 0bc829e

Browse files
kerumetogvisor-bot
authored andcommitted
Drop unnecessary size checks and corrections for Netlink attributes.
Some Netlink attributes have a fixed size. The map attempted to make adding attributes safer and easier by having default sizes for certain attributes. However, attributes are identified via their enums, which often overlap for different types of requests, making these default sizes not hold true for all attributes that map to it. PiperOrigin-RevId: 778632075
1 parent d61832d commit 0bc829e

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

test/syscalls/linux/socket_netlink_netfilter_util.cc

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
namespace gvisor {
2828
namespace testing {
2929

30-
static const std::map<uint16_t, size_t> kNetfilterAttributeSizes = {
31-
{NFTA_TABLE_FLAGS, sizeof(uint32_t)},
32-
{NFTA_TABLE_HANDLE, sizeof(uint64_t)},
33-
{NFTA_TABLE_USE, sizeof(uint32_t)},
34-
{NFTA_TABLE_OWNER, sizeof(uint32_t)},
35-
};
36-
3730
NlReq& NlReq::MsgType(uint8_t message_type) {
3831
message_type_ = message_type;
3932
return *this;
@@ -54,22 +47,13 @@ NlReq& NlReq::Family(uint8_t family) {
5447
return *this;
5548
}
5649

57-
// Method to add an attribute to the message. If there is a default
58-
// size for the attribute type, it will be used.
59-
// Otherwise, assumes the payload is of at least size payload_size.
50+
// Method to add an attribute to the message. payload_size must be the size of
51+
// the payload in bytes.
6052
NlReq& NlReq::RawAttr(uint16_t attr_type, const void* payload,
6153
size_t payload_size) {
62-
// Check if the attribute type has a standard size. Otherwise
63-
// use the provided size.
64-
size_t attr_size;
65-
if (kNetfilterAttributeSizes.count(attr_type)) {
66-
attr_size = kNetfilterAttributeSizes.at(attr_type);
67-
} else {
68-
attr_size = payload_size;
69-
}
70-
7154
// Store a pointer to the payload and the size to construct it later.
72-
attributes_[attr_type] = {reinterpret_cast<const char*>(payload), attr_size};
55+
attributes_[attr_type] = {reinterpret_cast<const char*>(payload),
56+
payload_size};
7357
return *this;
7458
}
7559

test/syscalls/linux/socket_netlink_netfilter_util.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ class NlReq {
8686
NlReq& Seq(uint32_t seq);
8787
NlReq& Family(uint8_t family);
8888

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

9493
// Method to add a string attribute to the message.

0 commit comments

Comments
 (0)