Skip to content

Commit

Permalink
refactor: batch update bpf elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Oct 17, 2024
1 parent 438c05c commit b152b52
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions control/kern/tproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,23 +649,21 @@ route(const __u32 flag[8], const void *l4hdr, const __be32 saddr[4],

int ret;
struct lpm_key *lpm_key;
__u32 key = MatchType_L4Proto;
__u16 h_dport;
__u16 h_sport;
struct lpm_key lpm_key_instance = {
.trie_key = { IPV6_BYTE_LENGTH * 8, {} },
};

/// TODO: BPF_MAP_UPDATE_BATCH ?
ret = bpf_map_update_elem(&l4proto_ipversion_map, &key, &_l4proto_type,
BPF_ANY);
if (unlikely(ret))
return ret;
key = MatchType_IpVersion;
ret = bpf_map_update_elem(&l4proto_ipversion_map, &key,
&_ipversion_type, BPF_ANY);
if (unlikely(ret))
return ret;
const enum MatchType keys[] = { MatchType_L4Proto,
MatchType_IpVersion };

for (__u32 i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
ret = bpf_map_update_elem(&l4proto_ipversion_map, &keys[i],
&flag[i], BPF_ANY);
if (unlikely(ret))
return ret;
}

// Variables for further use.
if (_l4proto_type == L4ProtoType_TCP) {
Expand All @@ -676,7 +674,7 @@ route(const __u32 flag[8], const void *l4hdr, const __be32 saddr[4],
h_sport = bpf_ntohs(((struct udphdr *)l4hdr)->source);
}

key = MatchType_SourcePort;
__u32 key = MatchType_SourcePort;
if (unlikely((ret = bpf_map_update_elem(&h_port_map, &key, &h_sport,
BPF_ANY))))
return ret;
Expand Down

0 comments on commit b152b52

Please sign in to comment.