Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/bpf/cgn.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
SEC("xdp")
int cgn_entry(struct xdp_md *ctx)
{
struct if_rule_data d = { .ctx = ctx };
struct if_rule_data d = { };
int action, ret;

/* phase 1: parse interface encap */
action = if_rule_parse_pkt(&d, NULL);
action = if_rule_parse_pkt(ctx, &d, NULL);

/* phase 2: execute action */
if (action == XDP_IFR_DEFAULT_ROUTE) {
ret = cgn_pkt_handle(&d, 2);
ret = cgn_pkt_handle(ctx, &d, 2);
if (hit_bug || ret < 0) {
hit_bug = 0;
return XDP_ABORTED;
Expand All @@ -33,7 +33,7 @@ int cgn_entry(struct xdp_md *ctx)

/* phase 3: rewrite interface encap */
if (action == XDP_IFR_FORWARD)
return if_rule_rewrite_pkt(&d);
return if_rule_rewrite_pkt(ctx, &d);

return action;
}
Expand Down
12 changes: 6 additions & 6 deletions src/bpf/gtp_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@
SEC("xdp")
int gtp_fwd_main(struct xdp_md *ctx)
{
struct if_rule_data d = { .ctx = ctx };
struct if_rule_data d = { };
int action, ret;

action = if_rule_parse_pkt(&d, gtp_fwd_rule_selection);
action = if_rule_parse_pkt(ctx, &d, gtp_fwd_rule_selection);

switch (action) {
case XDP_ABORTED ... XDP_REDIRECT:
return action;

case XDP_IFR_DEFAULT_ROUTE:
action = gtp_fwd_traffic_selector(&d);
action = gtp_fwd_traffic_selector(ctx, &d);
break;

case XDP_GTPFWD_GTPU_XLAT:
case XDP_GTPFWD_GTPU_NOXLAT:
action = gtp_fwd_handle_gtpu(&d);
action = gtp_fwd_handle_gtpu(ctx, &d);
break;

case XDP_GTPFWD_TUN_XLAT:
case XDP_GTPFWD_TUN_NOXLAT:
action = gtp_fwd_handle_ipip(&d);
action = gtp_fwd_handle_ipip(ctx, &d);
break;

default:
return XDP_PASS;
}

if (action == XDP_IFR_FORWARD)
return if_rule_rewrite_pkt(&d);
return if_rule_rewrite_pkt(ctx, &d);

return action;
}
Expand Down
12 changes: 6 additions & 6 deletions src/bpf/gtp_fwd_mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@
SEC("xdp")
int gtp_fwd_main(struct xdp_md *ctx)
{
struct if_rule_data d = { .ctx = ctx };
struct if_rule_data d = { };
int action, ret;

action = if_rule_parse_pkt(&d, gtp_fwd_rule_selection);
action = if_rule_parse_pkt(ctx, &d, gtp_fwd_rule_selection);

switch (action) {
case XDP_ABORTED ... XDP_REDIRECT:
return action;

case XDP_IFR_DEFAULT_ROUTE:
action = gtp_fwd_traffic_selector(&d);
action = gtp_fwd_traffic_selector(ctx, &d);
break;

case XDP_GTPFWD_GTPU_XLAT:
case XDP_GTPFWD_GTPU_NOXLAT:
action = gtp_fwd_handle_gtpu(&d);
action = gtp_fwd_handle_gtpu(ctx, &d);
break;

case XDP_GTPFWD_TUN_XLAT:
case XDP_GTPFWD_TUN_NOXLAT:
action = gtp_fwd_handle_ipip(&d);
action = gtp_fwd_handle_ipip(ctx, &d);
break;

default:
return XDP_PASS;
}

if (action == XDP_IFR_FORWARD)
return if_rule_rewrite_pkt(&d);
return if_rule_rewrite_pkt(ctx, &d);

return action;
}
Expand Down
28 changes: 15 additions & 13 deletions src/bpf/lib/cgn.h
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,8 @@ struct {


static __always_inline int
cgn_pkt_rewrite_src(struct xdp_md *ctx, struct cgn_packet *cp, struct iphdr *ip4h, void *payload,
__u32 addr, __u16 port)
cgn_pkt_rewrite_src(struct xdp_md *ctx, struct cgn_packet *cp, struct iphdr *ip4h,
void *payload, __u32 addr, __u16 port)
{
void *data_end = (void *)(long)ctx->data_end;
__u32 sum;
Expand Down Expand Up @@ -1158,8 +1158,9 @@ static __always_inline int
_handle_pkt_icmp_error(struct cgn_packet *cp, struct iphdr *outer_ip4h,
struct icmphdr *outer_icmp, struct iphdr *ip4h)
{
void *data = (void *)(long)cp->ctx->data;
void *data_end = (void *)(long)cp->ctx->data_end;
struct xdp_md *ctx = cp->ctx;
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
__u32 sum, addr;
int ret;

Expand Down Expand Up @@ -1208,7 +1209,7 @@ _handle_pkt_icmp_error(struct cgn_packet *cp, struct iphdr *outer_ip4h,
if (cp->from_priv == 0 || cp->from_priv == 2) {
ret = cgn_flow_handle_pub(cp);
if (!ret) {
ret = cgn_pkt_rewrite_src(cp->ctx, cp, ip4h, udp,
ret = cgn_pkt_rewrite_src(ctx, cp, ip4h, udp,
cp->dst_addr, cp->dst_port);
if (ret)
return ret;
Expand All @@ -1225,7 +1226,7 @@ _handle_pkt_icmp_error(struct cgn_packet *cp, struct iphdr *outer_ip4h,
ret = cgn_flow_handle_priv(cp);
if (ret)
return ret;
ret = cgn_pkt_rewrite_dst(cp->ctx, cp, ip4h, udp, cp->src_addr, cp->src_port);
ret = cgn_pkt_rewrite_dst(ctx, cp, ip4h, udp, cp->src_addr, cp->src_port);
if (ret)
return ret;

Expand Down Expand Up @@ -1256,24 +1257,25 @@ _handle_pkt_icmp_error(struct cgn_packet *cp, struct iphdr *outer_ip4h,
* 12: flow alloc error
*/
static __attribute__((noinline)) int
cgn_pkt_handle(struct if_rule_data *d, __u8 from_priv)
cgn_pkt_handle(struct xdp_md *ctx, struct if_rule_data *d, __u8 from_priv)
{
struct xdp_md *ctx = d->ctx;
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct iphdr *ip4h = data + d->pl_off;
struct cgn_packet *cp;
struct iphdr *ip4h;
void *payload;
int ret;

struct cgn_packet cp_static = {
.ctx = ctx,
};
cp = &cp_static;
ret = 0;
cp = bpf_map_lookup_elem(&cgn_on_stack, &ret);
if (cp == NULL)
return 1;

ip4h = data + d->pl_off;
if (d->pl_off > 256 || (void *)(ip4h + 1) > data_end)
return 2;

cp->ctx = ctx;
cp->proto = ip4h->protocol;
cp->from_priv = from_priv;
cp->src_addr = bpf_ntohl(ip4h->saddr);
Expand Down
22 changes: 11 additions & 11 deletions src/bpf/lib/gtp_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ gtpu_ip_frag_timer_set(const struct ip_frag_key *frag_key)
* IPIP traffic selector
*/
static __always_inline int
gtp_fwd_handle_ipip(struct if_rule_data *d)
gtp_fwd_handle_ipip(struct xdp_md *ctx, struct if_rule_data *d)
{
void *data = (void *) (long)d->ctx->data;
void *data_end = (void *) (long)d->ctx->data_end;
void *data = (void *) (long)ctx->data;
void *data_end = (void *) (long)ctx->data_end;
struct gtp_teid_frag *gtpf = NULL;
struct gtp_teid_rule *rule;
struct iphdr *iph;
Expand Down Expand Up @@ -295,10 +295,10 @@ gtp_fwd_handle_ipip(struct if_rule_data *d)
* GTP-U traffic selector
*/
static __always_inline int
gtp_fwd_handle_gtpu(struct if_rule_data *d)
gtp_fwd_handle_gtpu(struct xdp_md *ctx, struct if_rule_data *d)
{
void *data = (void *)(long)d->ctx->data;
void *data_end = (void *)(long)d->ctx->data_end;
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct gtp_teid_rule *rule = NULL;
struct iphdr *iph;
struct udphdr *udph;
Expand Down Expand Up @@ -422,10 +422,10 @@ gtp_fwd_handle_gtpu(struct if_rule_data *d)


static __always_inline int
gtp_fwd_traffic_selector(struct if_rule_data *d)
gtp_fwd_traffic_selector(struct xdp_md *ctx, struct if_rule_data *d)
{
void *data = (void *)(long)d->ctx->data;
void *data_end = (void *)(long)d->ctx->data_end;
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct iphdr *iph;

iph = (struct iphdr *)(data + d->pl_off);
Expand All @@ -434,9 +434,9 @@ gtp_fwd_traffic_selector(struct if_rule_data *d)

switch (iph->protocol) {
case IPPROTO_UDP:
return gtp_fwd_handle_gtpu(d);
return gtp_fwd_handle_gtpu(ctx, d);
case IPPROTO_IPIP:
return gtp_fwd_handle_ipip(d);
return gtp_fwd_handle_ipip(ctx, d);
default:
return XDP_PASS;
}
Expand Down
Loading
Loading