Skip to content

Commit

Permalink
Replace magic number with a sizeof()
Browse files Browse the repository at this point in the history
This should be more flexible if we ever need to add items to gueext.
  • Loading branch information
caboteria committed May 21, 2024
1 parent b0aa27c commit 9f2b708
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/bpf/pfc_tc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ struct tunhdr {
struct iphdr ip;
struct udphdr udp;
__u32 gue;
__u32 gue_id;
struct gueexthdr gue_id;
} __attribute__((packed));

// In order to safely parse a GUE packet we need to ensure that there
// are at least this many bytes in the packet's skb data. Not all
// packets have that at first. In some cases we need to
// bpf_skb_pull_data() this many bytes before we can parse.
#define TOTAL_GUE_HEADER_SIZE sizeof(struct ethhdr) \
+ sizeof(struct iphdr) \
+ sizeof(struct udphdr) \
+ sizeof(struct guehdr) \
+ sizeof(struct gueexthdr)
#define TOTAL_GUE_HEADER_SIZE sizeof(struct ethhdr) + sizeof(struct tunhdr)

// In order to safely call parse_ep() on a packet we need to ensure
// that there are at least this many linear bytes in the packet's skb
Expand Down Expand Up @@ -332,7 +328,7 @@ static __always_inline
int gue_encap_v4(struct __sk_buff *skb, struct tunnel *tun, struct service *svc)
{
struct iphdr iph_inner = { 0 };
struct tunhdr h_outer = {{0}, {0}, 0, 0};
struct tunhdr h_outer = {{0}, {0}, 0, {0}};
int olen = sizeof(h_outer);
__u64 flags = 0;
int ret;
Expand Down Expand Up @@ -440,7 +436,7 @@ int gue_encap_v4(struct __sk_buff *skb, struct tunnel *tun, struct service *svc)
// prepare new outer network header
// fill GUE
h_outer.gue = 0xa00405; //GUE data header: 0x0504a000
h_outer.gue_id = svc->tunnel_id;
h_outer.gue_id.tunnelid = svc->tunnel_id;

// fill IP
h_outer.ip = iph_inner;
Expand All @@ -454,7 +450,7 @@ int gue_encap_v4(struct __sk_buff *skb, struct tunnel *tun, struct service *svc)
set_ipv4_csum((void *)&h_outer.ip);

// fill UDP
int len = bpf_ntohs(iph_inner.tot_len) + sizeof(h_outer.udp) + sizeof(h_outer.gue) + 4 /*sizeof(h_outer.gueext*/;
int len = bpf_ntohs(iph_inner.tot_len) + sizeof(h_outer.udp) + sizeof(h_outer.gue) + sizeof(h_outer.gue_id);
h_outer.udp.dest = tun->port_remote;
h_outer.udp.source = tun->port_local;
h_outer.udp.len = bpf_htons(len);
Expand Down

0 comments on commit 9f2b708

Please sign in to comment.