Skip to content

Commit

Permalink
chore: add prefix retina_ to eBPF maps so that they are easier to ide…
Browse files Browse the repository at this point in the history
…ntify (#768)

# Description

As title.

## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [x] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [x] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [x] I have correctly attributed the author(s) of the code.
- [x] I have tested the changes locally.
- [x] I have followed the project's style guidelines.
- [x] I have updated the documentation, if necessary.
- [x] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
nddq authored Oct 1, 2024
1 parent f2da04b commit 1f19ed0
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 119 deletions.
2 changes: 1 addition & 1 deletion docs/03-Metrics/plugins/Linux/dropreason.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct
__uint(max_entries, 512);
__type(key, struct metrics_map_key);
__type(value, struct metrics_map_value);
} metrics_map SEC(".maps");
} retina_dropreason_metrics SEC(".maps");

struct metrics_map_key
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const (
// MapPath is the path to pinned BPF maps
MapPath = "/sys/fs/bpf"
// FilterMapName is the name of the BPF filter map
FilterMapName = "retina_filter_map"
FilterMapName = "retina_filter"
// ConntrackMapName is the name of the BPF conntrack map
ConntrackMapName = "retina_conntrack_map"
ConntrackMapName = "retina_conntrack"
)
14 changes: 7 additions & 7 deletions pkg/plugin/conntrack/_cprog/conntrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct {
__type(value, struct ct_entry);
__uint(max_entries, CT_MAP_SIZE);
__uint(pinning, LIBBPF_PIN_BY_NAME); // needs pinning so this can be access from other processes .i.e debug cli
} retina_conntrack_map SEC(".maps");
} retina_conntrack SEC(".maps");


/**
Expand Down Expand Up @@ -120,7 +120,7 @@ static __always_inline bool _ct_create_new_tcp_connection(struct ct_v4_key key,
new_value.eviction_time = now + CT_SYN_TIMEOUT;
new_value.flags_seen_tx_dir = flags;
new_value.traffic_direction = _ct_get_traffic_direction(observation_point);
bpf_map_update_elem(&retina_conntrack_map, &key, &new_value, BPF_ANY);
bpf_map_update_elem(&retina_conntrack, &key, &new_value, BPF_ANY);
return true;
}

Expand All @@ -142,7 +142,7 @@ static __always_inline bool _ct_handle_udp_connection(struct packet *p, struct c
new_value.flags_seen_tx_dir = p->flags;
new_value.last_report_tx_dir = now;
new_value.traffic_direction = _ct_get_traffic_direction(observation_point);
bpf_map_update_elem(&retina_conntrack_map, &key, &new_value, BPF_ANY);
bpf_map_update_elem(&retina_conntrack, &key, &new_value, BPF_ANY);
// Update packet
p->is_reply = false;
p->traffic_direction = new_value.traffic_direction;
Expand Down Expand Up @@ -186,12 +186,12 @@ static __always_inline bool _ct_handle_tcp_connection(struct packet *p, struct c
p->is_reply = true;
new_value.flags_seen_rx_dir = p->flags;
new_value.last_report_rx_dir = now;
bpf_map_update_elem(&retina_conntrack_map, &reverse_key, &new_value, BPF_ANY);
bpf_map_update_elem(&retina_conntrack, &reverse_key, &new_value, BPF_ANY);
} else { // Otherwise, the packet is considered as a packet in the send direction.
p->is_reply = false;
new_value.flags_seen_tx_dir = p->flags;
new_value.last_report_tx_dir = now;
bpf_map_update_elem(&retina_conntrack_map, &key, &new_value, BPF_ANY);
bpf_map_update_elem(&retina_conntrack, &key, &new_value, BPF_ANY);
}
return true;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ static __always_inline __attribute__((unused)) bool ct_process_packet(struct pac
key.dst_port = p->dst_port;
key.proto = p->proto;
// Lookup the connection in the map.
struct ct_entry *entry = bpf_map_lookup_elem(&retina_conntrack_map, &key);
struct ct_entry *entry = bpf_map_lookup_elem(&retina_conntrack, &key);

// If the connection is found in the send direction, update the connection.
if (entry) {
Expand All @@ -316,7 +316,7 @@ static __always_inline __attribute__((unused)) bool ct_process_packet(struct pac
_ct_reverse_key(&reverse_key, &key);

// Lookup the connection in the map based on the reverse key.
entry = bpf_map_lookup_elem(&retina_conntrack_map, &reverse_key);
entry = bpf_map_lookup_elem(&retina_conntrack, &reverse_key);

// If the connection is found based on the reverse key, meaning that the packet is a reply packet to an existing connection.
if (entry) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/conntrack/conntrack_bpfel_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/plugin/conntrack/conntrack_bpfel_x86.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/plugin/conntrack/conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func New() (*Conntrack, error) {

ct.objs = objs
// Get the conntrack map from the objects
ct.ctMap = objs.RetinaConntrackMap
ct.ctMap = objs.RetinaConntrack
return ct, nil
}

Expand Down
46 changes: 23 additions & 23 deletions pkg/plugin/dropreason/_cprog/drop_reason.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct
{
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(max_entries, 16384);
} dropreason_events SEC(".maps");
} retina_dropreason_events SEC(".maps");

// Define const variables to avoid warnings.
const struct packet *unused __attribute__((unused));
Expand All @@ -65,31 +65,31 @@ struct
__uint(max_entries, 16384);
__type(key, __u32);
__type(value, struct packet);
} natdrop_pids SEC(".maps");
} retina_dropreason_natdrop_pids SEC(".maps");

struct
{
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 16384);
__type(key, __u32);
__type(value, struct packet);
} drop_pids SEC(".maps");
} retina_dropreason_drop_pids SEC(".maps");

struct
{
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 16384);
__type(key, __u32);
__type(value, __u64);
} accept_pids SEC(".maps");
} retina_dropreason_accept_pids SEC(".maps");

struct
{
__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
__uint(max_entries, 512);
__type(key, struct metrics_map_key);
__type(value, struct metrics_map_value);
} metrics_map SEC(".maps");
} retina_dropreason_metrics SEC(".maps");

#define member_address(source_struct, source_member) \
({ \
Expand All @@ -114,7 +114,7 @@ void update_metrics_map(void *ctx, drop_reason_t drop_type, int ret_val, struct
key.drop_type = drop_type;
key.return_val = ret_val;

entry = bpf_map_lookup_elem(&metrics_map, &key);
entry = bpf_map_lookup_elem(&retina_dropreason_metrics, &key);
if (entry)
{
entry->count += 1;
Expand All @@ -124,7 +124,7 @@ void update_metrics_map(void *ctx, drop_reason_t drop_type, int ret_val, struct
{
new_entry.count = 1;
new_entry.bytes = p->skb_len;
bpf_map_update_elem(&metrics_map, &key, &new_entry, 0);
bpf_map_update_elem(&retina_dropreason_metrics, &key, &new_entry, 0);
}
// parse packet if advanced metrics are enabled
#ifdef ADVANCED_METRICS
Expand All @@ -133,7 +133,7 @@ void update_metrics_map(void *ctx, drop_reason_t drop_type, int ret_val, struct
{
p->drop_type = drop_type;
p->return_val = ret_val;
bpf_perf_event_output(ctx, &dropreason_events, BPF_F_CURRENT_CPU, p, sizeof(struct packet));
bpf_perf_event_output(ctx, &retina_dropreason_events, BPF_F_CURRENT_CPU, p, sizeof(struct packet));
};
#endif
#endif
Expand Down Expand Up @@ -253,7 +253,7 @@ int BPF_KPROBE(nf_hook_slow, struct sk_buff *skb, struct nf_hook_state *state)

__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = pid_tgid >> 32;
bpf_map_update_elem(&drop_pids, &pid, &p, BPF_ANY);
bpf_map_update_elem(&retina_dropreason_drop_pids, &pid, &p, BPF_ANY);
return 0;
}

Expand All @@ -271,17 +271,17 @@ int BPF_KRETPROBE(nf_hook_slow_ret, int retVal)

if (retVal >= 0)
{
bpf_map_delete_elem(&drop_pids, &pid);
bpf_map_delete_elem(&retina_dropreason_drop_pids, &pid);
return 0;
}

struct packet *p = bpf_map_lookup_elem(&drop_pids, &pid);
struct packet *p = bpf_map_lookup_elem(&retina_dropreason_drop_pids, &pid);
if (!p)
{
return 0;
}

bpf_map_delete_elem(&drop_pids, &pid);
bpf_map_delete_elem(&retina_dropreason_drop_pids, &pid);

update_metrics_map(ctx, IPTABLE_RULE_DROP, 0, p);
return 0;
Expand Down Expand Up @@ -319,7 +319,7 @@ int BPF_KPROBE(inet_csk_accept, struct sock *sk, int flags, int *err, bool kern)
__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = pid_tgid >> 32;
__u64 err_ptr = (__u64)err;
bpf_map_update_elem(&accept_pids, &pid, &err_ptr, BPF_ANY);
bpf_map_update_elem(&retina_dropreason_accept_pids, &pid, &err_ptr, BPF_ANY);
return 0;
}

Expand All @@ -337,8 +337,8 @@ int BPF_KRETPROBE(inet_csk_accept_ret, struct sock *sk)
*/
__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = pid_tgid >> 32;
__u64 *err_ptr = bpf_map_lookup_elem(&accept_pids, &pid);
bpf_map_delete_elem(&accept_pids, &pid);
__u64 *err_ptr = bpf_map_lookup_elem(&retina_dropreason_accept_pids, &pid);
bpf_map_delete_elem(&retina_dropreason_accept_pids, &pid);

if (!err_ptr)
return 0;
Expand Down Expand Up @@ -384,7 +384,7 @@ int BPF_KPROBE(nf_nat_inet_fn, void *priv, struct sk_buff *skb, const struct nf_

__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = pid_tgid >> 32;
bpf_map_update_elem(&natdrop_pids, &pid, &p, BPF_ANY);
bpf_map_update_elem(&retina_dropreason_natdrop_pids, &pid, &p, BPF_ANY);
return 0;
}

Expand All @@ -396,17 +396,17 @@ int BPF_KRETPROBE(nf_nat_inet_fn_ret, int retVal)

if (retVal != NF_DROP)
{
bpf_map_delete_elem(&natdrop_pids, &pid);
bpf_map_delete_elem(&retina_dropreason_natdrop_pids, &pid);
return 0;
}

struct packet *p = bpf_map_lookup_elem(&natdrop_pids, &pid);
struct packet *p = bpf_map_lookup_elem(&retina_dropreason_natdrop_pids, &pid);
if (!p)
{
return 0;
}

bpf_map_delete_elem(&natdrop_pids, &pid);
bpf_map_delete_elem(&retina_dropreason_natdrop_pids, &pid);

update_metrics_map(ctx, IPTABLE_NAT_DROP, 0, p);
return 0;
Expand All @@ -430,7 +430,7 @@ int BPF_KPROBE(nf_conntrack_confirm, struct sk_buff *skb)

__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = pid_tgid >> 32;
bpf_map_update_elem(&natdrop_pids, &pid, &p, BPF_ANY);
bpf_map_update_elem(&retina_dropreason_natdrop_pids, &pid, &p, BPF_ANY);
return 0;
}

Expand All @@ -442,17 +442,17 @@ int BPF_KRETPROBE(nf_conntrack_confirm_ret, int retVal)

if (retVal != NF_DROP)
{
bpf_map_delete_elem(&natdrop_pids, &pid);
bpf_map_delete_elem(&retina_dropreason_natdrop_pids, &pid);
return 0;
}

struct packet *p = bpf_map_lookup_elem(&natdrop_pids, &pid);
struct packet *p = bpf_map_lookup_elem(&retina_dropreason_natdrop_pids, &pid);
if (!p)
{
return 0;
}

bpf_map_delete_elem(&natdrop_pids, &pid);
bpf_map_delete_elem(&retina_dropreason_natdrop_pids, &pid);

update_metrics_map(ctx, CONNTRACK_ADD_DROP, retVal, p);
return 0;
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/dropreason/dropreason_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (dr *dropReason) Init() error {
}

// read perf map
dr.reader, err = plugincommon.NewPerfReader(dr.l, objs.DropreasonEvents, perCPUBuffer, 1)
dr.reader, err = plugincommon.NewPerfReader(dr.l, objs.RetinaDropreasonEvents, perCPUBuffer, 1)
if err != nil {
dr.l.Error("Error NewReader: %w", zap.Error(err))
return err
Expand Down Expand Up @@ -225,7 +225,7 @@ func (dr *dropReason) Init() error {
}
}

dr.metricsMapData = objs.MetricsMap
dr.metricsMapData = objs.RetinaDropreasonMetrics
return nil
}

Expand Down
36 changes: 18 additions & 18 deletions pkg/plugin/dropreason/kprobe_bpfel_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1f19ed0

Please sign in to comment.