Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gcc noclang take1 #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/actions-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
path : |
bin/gtp-guard
src/bpf/*.bpf
bin/*.bpf
test/
build-gtping:
name: Build gtping
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ gcc is the default compiled. Should you prefer the usage of clang, then use:
CC=clang make -j $(nproc)
```

If you are missing the `llc` llvm tool, maybe it missing from your `PATH` or it
has been renamed `llc-N`, for example `llc-18` on Ubuntu 24.04.

If you are facing such issue, you can compile using:
```
LLC=llc-18 make -j $(nproc)
```

# Basic Run

Define your own `gtp-guard.conf` settings in order to enable its vty over TCP.
Expand Down
32 changes: 16 additions & 16 deletions src/bpf/gtp_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ gtpu_ipencap(struct parse_pkt *pkt, struct gtp_iptnl_rule *iptnl_rule)
int headroom, use_vlan = 0, offset = 0;

iph = data + pkt->l3_offset;
if (iph + 1 > data_end)
if (iph + 1 > (typeof(iph))data_end)
return XDP_DROP;
payload_len = bpf_ntohs(iph->tot_len);

Expand All @@ -165,23 +165,23 @@ gtpu_ipencap(struct parse_pkt *pkt, struct gtp_iptnl_rule *iptnl_rule)
data = (void *) (long) ctx->data;
data_end = (void *) (long) ctx->data_end;
new_eth = data;
if (new_eth + 1 > data_end)
if (new_eth + 1 > (typeof(new_eth))data_end)
return XDP_DROP;

new_eth->h_proto = bpf_htons(ETH_P_IP);
if (use_vlan) {
new_eth->h_proto = bpf_htons(ETH_P_8021Q);

vlanh = data + sizeof(*new_eth);
if (vlanh + 1 > data_end)
if (vlanh + 1 > (typeof(vlanh))data_end)
return XDP_DROP;
vlanh->h_vlan_encapsulated_proto = bpf_htons(ETH_P_IP);
vlanh->hvlan_TCI = bpf_htons(iptnl_rule->encap_vlan_id);
offset = sizeof(*vlanh);
}

iph = data + sizeof(*new_eth) + offset;
if (iph + 1 > data_end)
if (iph + 1 > (typeof(iph))data_end)
return XDP_DROP;

/* Fill Encap header */
Expand Down Expand Up @@ -293,7 +293,7 @@ gtpu_ipip_decap(struct parse_pkt *pkt, struct gtp_iptnl_rule *iptnl_rule, struct
data_end = (void *) (long) ctx->data_end;

new_eth = data;
if (new_eth + 1 > data_end)
if (new_eth + 1 > (typeof(new_eth))data_end)
return XDP_DROP;

new_eth->h_proto = bpf_htons(ETH_P_8021Q);
Expand All @@ -303,15 +303,15 @@ gtpu_ipip_decap(struct parse_pkt *pkt, struct gtp_iptnl_rule *iptnl_rule, struct

if ((iptnl_rule->flags & IPTNL_FL_TAG_VLAN) && pkt->vlan_id != 0) {
vlanh = data + offset;
if (vlanh + 1 > data_end)
if (vlanh + 1 > (typeof(vlanh))data_end)
return XDP_DROP;
vlanh->h_vlan_encapsulated_proto = bpf_htons(ETH_P_IP);
vlanh->hvlan_TCI = bpf_htons(iptnl_rule->decap_vlan_id);
offset += sizeof(struct _vlan_hdr);
}

iph = data + offset;
if (iph + 1 > data_end)
if (iph + 1 > (typeof(iph))data_end)
return XDP_DROP;

/* Fragmentation handling */
Expand All @@ -327,13 +327,13 @@ gtpu_ipip_decap(struct parse_pkt *pkt, struct gtp_iptnl_rule *iptnl_rule, struct

offset += sizeof(struct iphdr);
udph = data + offset;
if (udph + 1 > data_end)
if (udph + 1 > (typeof(udph))data_end)
return XDP_DROP;

/* Perform xlat if needed */
offset += sizeof(struct udphdr);
gtph = data + offset;
if (gtph + 1 > data_end)
if (gtph + 1 > (typeof(gtph))data_end)
return XDP_DROP;

if (iptnl_rule->flags & IPTNL_FL_TRANSPARENT_EGRESS_ENCAP) {
Expand Down Expand Up @@ -366,12 +366,12 @@ gtpu_ipip_traffic_selector(struct parse_pkt *pkt)
__u16 frag_off = 0, ipfl = 0;

iph_outer = data + offset;
if (iph_outer + 1 > data_end)
if (iph_outer + 1 > (typeof(iph_outer))data_end)
return XDP_PASS;

offset += sizeof(struct iphdr);
iph_inner = data + offset;
if (iph_inner + 1 > data_end)
if (iph_inner + 1 > (typeof(iph_inner))data_end)
return XDP_PASS;

/* A bit more complicated here since we need to
Expand Down Expand Up @@ -402,7 +402,7 @@ gtpu_ipip_traffic_selector(struct parse_pkt *pkt)

offset += sizeof(struct iphdr);
udph = data + offset;
if (udph + 1 > data_end)
if (udph + 1 > (typeof(udph))data_end)
return XDP_DROP;

/* Only allow GTP-U decap !!! */
Expand All @@ -412,7 +412,7 @@ gtpu_ipip_traffic_selector(struct parse_pkt *pkt)
/* Perform xlat if needed */
offset += sizeof(struct udphdr);
gtph = data + offset;
if (gtph + 1 > data_end)
if (gtph + 1 > (typeof(gtph))data_end)
return XDP_DROP;

/* Punt into netstack GTP-U echo request */
Expand Down Expand Up @@ -577,7 +577,7 @@ gtpu_traffic_selector(struct parse_pkt *pkt)

ethh = data;
iph = data + pkt->l3_offset;
if (iph + 1 > data_end)
if (iph + 1 > (typeof(iph))data_end)
return XDP_PASS;

if (iph->protocol == IPPROTO_IPIP)
Expand All @@ -602,15 +602,15 @@ gtpu_traffic_selector(struct parse_pkt *pkt)
}

udph = data + offset + sizeof(struct iphdr);
if (udph + 1 > data_end)
if (udph + 1 > (typeof(udph))data_end)
return XDP_DROP;

if (udph->dest != bpf_htons(GTPU_PORT))
return XDP_PASS;

offset += sizeof(struct iphdr);
gtph = data + offset + sizeof(struct udphdr);
if (gtph + 1 > data_end)
if (gtph + 1 > (typeof(gtph))data_end)
return XDP_DROP;

/* That is a nice feature of XDP here:
Expand Down
4 changes: 2 additions & 2 deletions src/bpf/gtp_mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int tc_gtp_mirror(struct __sk_buff *skb)
return TC_ACT_OK;

iph = data + offset;
if (iph + 1 > data_end)
if (iph + 1 > (typeof(iph))data_end)
return TC_ACT_OK;

/* First match destination address */
Expand All @@ -77,7 +77,7 @@ int tc_gtp_mirror(struct __sk_buff *skb)

offset += sizeof(struct iphdr);
udph = data + offset;
if (udph + 1 > data_end)
if (udph + 1 > (typeof(udph))data_end)
return TC_ACT_OK;

if (!(udph->dest == rule->port || udph->source == rule->port))
Expand Down
Loading