BpfMap/Utils - fix const-ness of key & value
When accessing maps keys are always const/read-only. Similarly for the value when it is being stored in the map. This eliminates four const_casts. Test: build, atest Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Icc57b46a8e9e81b5b06264260bfbf34a4ba9105d
This commit is contained in:
parent
b479fd6a9f
commit
79365da151
2 changed files with 8 additions and 8 deletions
|
|
@ -79,7 +79,7 @@ class BpfMap {
|
|||
|
||||
netdutils::StatusOr<Key> getNextKey(const Key& key) const {
|
||||
Key nextKey;
|
||||
if (getNextMapKey(mMapFd, const_cast<Key*>(&key), &nextKey)) {
|
||||
if (getNextMapKey(mMapFd, &key, &nextKey)) {
|
||||
return netdutils::statusFromErrno(
|
||||
errno, base::StringPrintf("Get next key of map %d failed", mMapFd.get()));
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ class BpfMap {
|
|||
}
|
||||
|
||||
netdutils::Status writeValue(const Key& key, const Value& value, uint64_t flags) {
|
||||
if (writeToMapEntry(mMapFd, const_cast<Key*>(&key), const_cast<Value*>(&value), flags)) {
|
||||
if (writeToMapEntry(mMapFd, &key, &value, flags)) {
|
||||
return netdutils::statusFromErrno(
|
||||
errno, base::StringPrintf("write to map %d failed", mMapFd.get()));
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ class BpfMap {
|
|||
|
||||
netdutils::StatusOr<Value> readValue(const Key key) const {
|
||||
Value value;
|
||||
if (findMapEntry(mMapFd, const_cast<Key*>(&key), &value)) {
|
||||
if (findMapEntry(mMapFd, &key, &value)) {
|
||||
return netdutils::statusFromErrno(
|
||||
errno, base::StringPrintf("read value of map %d failed", mMapFd.get()));
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ class BpfMap {
|
|||
}
|
||||
|
||||
netdutils::Status deleteValue(const Key& key) {
|
||||
if (deleteMapEntry(mMapFd, const_cast<Key*>(&key))) {
|
||||
if (deleteMapEntry(mMapFd, &key)) {
|
||||
return netdutils::statusFromErrno(
|
||||
errno, base::StringPrintf("delete entry from map %d failed", mMapFd.get()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ static inline int createMap(bpf_map_type map_type, uint32_t key_size, uint32_t v
|
|||
});
|
||||
}
|
||||
|
||||
static inline int writeToMapEntry(const base::unique_fd& map_fd, void* key, void* value,
|
||||
static inline int writeToMapEntry(const base::unique_fd& map_fd, const void* key, const void* value,
|
||||
uint64_t flags) {
|
||||
return bpf(BPF_MAP_UPDATE_ELEM, {
|
||||
.map_fd = static_cast<__u32>(map_fd.get()),
|
||||
|
|
@ -95,7 +95,7 @@ static inline int writeToMapEntry(const base::unique_fd& map_fd, void* key, void
|
|||
});
|
||||
}
|
||||
|
||||
static inline int findMapEntry(const base::unique_fd& map_fd, void* key, void* value) {
|
||||
static inline int findMapEntry(const base::unique_fd& map_fd, const void* key, void* value) {
|
||||
return bpf(BPF_MAP_LOOKUP_ELEM, {
|
||||
.map_fd = static_cast<__u32>(map_fd.get()),
|
||||
.key = ptr_to_u64(key),
|
||||
|
|
@ -103,14 +103,14 @@ static inline int findMapEntry(const base::unique_fd& map_fd, void* key, void* v
|
|||
});
|
||||
}
|
||||
|
||||
static inline int deleteMapEntry(const base::unique_fd& map_fd, void* key) {
|
||||
static inline int deleteMapEntry(const base::unique_fd& map_fd, const void* key) {
|
||||
return bpf(BPF_MAP_DELETE_ELEM, {
|
||||
.map_fd = static_cast<__u32>(map_fd.get()),
|
||||
.key = ptr_to_u64(key),
|
||||
});
|
||||
}
|
||||
|
||||
static inline int getNextMapKey(const base::unique_fd& map_fd, void* key, void* next_key) {
|
||||
static inline int getNextMapKey(const base::unique_fd& map_fd, const void* key, void* next_key) {
|
||||
return bpf(BPF_MAP_GET_NEXT_KEY, {
|
||||
.map_fd = static_cast<__u32>(map_fd.get()),
|
||||
.key = ptr_to_u64(key),
|
||||
|
|
|
|||
Loading…
Reference in a new issue