Skip to content

Commit

Permalink
bpf: move random padding into function
Browse files Browse the repository at this point in the history
  • Loading branch information
hack3ric committed Oct 8, 2024
1 parent 713fdbe commit cb3649c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions bpf/egress.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ int egress_handler(struct __sk_buff* skb) {
if (likely(conn->state == CONN_ESTABLISHED)) {
seq = conn->seq;
ack_seq = conn->ack_seq;
padding =
conn->settings.padding == PADDING_RANDOM ? (seq + ack_seq) % 11 : conn->settings.padding;
padding = conn_padding(conn, seq, ack_seq);
conn->seq += payload_len + padding;
} else {
if (conn->state == CONN_IDLE) {
Expand Down
4 changes: 1 addition & 3 deletions bpf/ingress.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ int ingress_handler(struct xdp_md* xdp) {
}
if (will_drop) return XDP_DROP;

__u32 padding = conn->settings.padding == PADDING_RANDOM
? (ntohl(tcp->seq) + ntohl(tcp->ack_seq)) % 11
: conn->settings.padding;
__u32 padding = conn_padding(conn, ntohl(tcp->seq), ntohl(tcp->ack));
size_t reserve_len = TCP_UDP_HEADER_DIFF + padding;
if (ipv4) {
__be16 old_len = ipv4->tot_len;
Expand Down
4 changes: 4 additions & 0 deletions common/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ static __always_inline __u32 conn_cooldown_display(struct connection* conn) {
return conn->initiator ? conn_cooldown(conn) : 0;
}

static __always_inline __u32 conn_padding(struct connection* conn, __u32 seq, __u32 ack_seq) {
return conn->settings.padding == PADDING_RANDOM ? (seq + ack_seq) % 11 : conn->settings.padding;
}

static __always_inline int time_diff_sec(__u64 a, __u64 b) {
if (a <= b) return 0;
if ((a - b) % SECOND < SECOND / 2)
Expand Down

0 comments on commit cb3649c

Please sign in to comment.