Skip to content

Commit 591d949

Browse files
authored
chore(ct): add flag to mark ct_entry connection direction is unkown (#926)
# Description * add new member is_direction_unknown to conntrack_entry struct * set is_direction_unknown to true when the SYN packet is not captured ## Related Issue #919 ## 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.
1 parent cf0e69a commit 591d949

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

pkg/plugin/conntrack/_cprog/conntrack.c

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ struct ct_entry {
6161
*/
6262
__u8 flags_seen_tx_dir;
6363
__u8 flags_seen_rx_dir;
64+
/**
65+
* is_direction_unknown is set to true if the direction of the connection is unknown. This can happen if the connection is created
66+
* before retina deployment and the SYN packet was not captured.
67+
*/
68+
bool is_direction_unknown;
6469
};
6570

6671
struct {
@@ -117,6 +122,7 @@ static __always_inline bool _ct_create_new_tcp_connection(struct ct_v4_key key,
117122
}
118123
new_value.eviction_time = now + CT_SYN_TIMEOUT;
119124
new_value.flags_seen_tx_dir = flags;
125+
new_value.is_direction_unknown = false;
120126
new_value.traffic_direction = _ct_get_traffic_direction(observation_point);
121127
bpf_map_update_elem(&retina_conntrack, &key, &new_value, BPF_ANY);
122128
return true;
@@ -174,6 +180,8 @@ static __always_inline bool _ct_handle_tcp_connection(struct packet *p, struct c
174180
if (CT_CONNECTION_LIFETIME_TCP > UINT32_MAX - now) {
175181
return false;
176182
}
183+
// Set the connection as unknown direction since we did not capture the SYN packet.
184+
new_value.is_direction_unknown = true;
177185
new_value.eviction_time = now + CT_CONNECTION_LIFETIME_TCP;
178186
new_value.traffic_direction = _ct_get_traffic_direction(observation_point);
179187
p->traffic_direction = new_value.traffic_direction;

pkg/plugin/conntrack/conntrack_bpfel_x86.go

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/plugin/conntrack/conntrack_linux.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (ct *Conntrack) Run(ctx context.Context) error {
120120
zap.String("flags_seen_rx_dir", decodeFlags(value.FlagsSeenRxDir)),
121121
zap.Uint32("last_reported_tx_dir", value.LastReportTxDir),
122122
zap.Uint32("last_reported_rx_dir", value.LastReportRxDir),
123+
zap.Bool("is_direction_unknown", value.IsDirectionUnknown),
123124
)
124125
}
125126
if err := iter.Err(); err != nil {

pkg/plugin/packetparser/packetparser_bpfel_x86.go

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)