Skip to content

Commit

Permalink
Use kprobe to change checksum offset
Browse files Browse the repository at this point in the history
  • Loading branch information
hack3ric committed Aug 8, 2024
1 parent c0d99b3 commit 1ecbc12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bpf/egress.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int egress_handler(struct __sk_buff* skb) {
csum_diff = bpf_csum_diff((__be32*)&old_ph, sizeof(old_ph), (__be32*)&new_ph, sizeof(new_ph), 0);
bpf_l4_csum_replace(skb, csum_off, 0, csum_diff, BPF_F_PSEUDO_HDR);

// bpf_skb_change_proto(skb, IPPROTO_TCP, MAGIC_FLAG);
bpf_skb_change_proto(skb, IPPROTO_TCP, MAGIC_FLAG);
// log_info("%llu", retval);
// mimic_change_csum_offset(skb, IPPROTO_TCP);

Expand Down
2 changes: 2 additions & 0 deletions kmod/kprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static int ret_handler(struct kretprobe_instance* ri, struct pt_regs* regs) {
struct bpf_skb_change_proto_params* params = (typeof(params))ri->data;
if (!params->skb || params->flags != MAGIC_FLAG) return 0;

printk("checksum: %d\n", params->skb->ip_summed);

if (params->skb->ip_summed != CHECKSUM_PARTIAL) {
regs_set_return_value(regs, -1);
return 0;
Expand Down

0 comments on commit 1ecbc12

Please sign in to comment.