mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
pping: Use designated initialization for parsing_context
Change how intitalization of pctx is done in tc and xdp programs. Also, len to pkt_len in parsing_context. Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
@ -29,7 +29,7 @@ struct parsing_context {
|
|||||||
void *data; //Start of eth hdr
|
void *data; //Start of eth hdr
|
||||||
void *data_end; //End of safe acessible area
|
void *data_end; //End of safe acessible area
|
||||||
struct hdr_cursor nh; //Position to parse next
|
struct hdr_cursor nh; //Position to parse next
|
||||||
__u32 len; //Full packet length (headers+data)
|
__u32 pkt_len; //Full packet length (headers+data)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -109,7 +109,7 @@ static int parse_tcp_identifier(struct parsing_context *ctx, bool is_egress,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Do not timestamp pure ACKs
|
// Do not timestamp pure ACKs
|
||||||
if (is_egress && ctx->nh.pos - ctx->data >= ctx->len && !tcph->syn)
|
if (is_egress && ctx->nh.pos - ctx->data >= ctx->pkt_len && !tcph->syn)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (parse_tcp_ts(tcph, ctx->data_end, &tsval, &tsecr) < 0)
|
if (parse_tcp_ts(tcph, ctx->data_end, &tsval, &tsecr) < 0)
|
||||||
|
@ -31,14 +31,14 @@ struct bpf_elf_map SEC("maps") ts_start = {
|
|||||||
SEC(TCBPF_PROG_SEC)
|
SEC(TCBPF_PROG_SEC)
|
||||||
int tc_bpf_prog_egress(struct __sk_buff *skb)
|
int tc_bpf_prog_egress(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct parsing_context pctx;
|
|
||||||
struct packet_id p_id = { 0 };
|
struct packet_id p_id = { 0 };
|
||||||
struct packet_timestamp p_ts = { 0 };
|
struct packet_timestamp p_ts = { 0 };
|
||||||
|
struct parsing_context pctx = {
|
||||||
pctx.data = (void *)(long)skb->data;
|
.data = (void *)(long)skb->data,
|
||||||
pctx.data_end = (void *)(long)skb->data_end;
|
.data_end = (void *)(long)skb->data_end,
|
||||||
pctx.len = skb->len;
|
.pkt_len = skb->len,
|
||||||
pctx.nh.pos = pctx.data;
|
.nh = { .pos = pctx.data },
|
||||||
|
};
|
||||||
|
|
||||||
if (parse_packet_identifier(&pctx, true, &p_id) < 0)
|
if (parse_packet_identifier(&pctx, true, &p_id) < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -25,15 +25,15 @@ struct {
|
|||||||
SEC(XDP_PROG_SEC)
|
SEC(XDP_PROG_SEC)
|
||||||
int xdp_prog_ingress(struct xdp_md *ctx)
|
int xdp_prog_ingress(struct xdp_md *ctx)
|
||||||
{
|
{
|
||||||
struct parsing_context pctx;
|
|
||||||
struct packet_id p_id = { 0 };
|
struct packet_id p_id = { 0 };
|
||||||
struct packet_timestamp *p_ts;
|
struct packet_timestamp *p_ts;
|
||||||
struct rtt_event event = { 0 };
|
struct rtt_event event = { 0 };
|
||||||
|
struct parsing_context pctx = {
|
||||||
pctx.data = (void *)(long)ctx->data;
|
.data = (void *)(long)ctx->data,
|
||||||
pctx.data_end = (void *)(long)ctx->data_end;
|
.data_end = (void *)(long)ctx->data_end,
|
||||||
pctx.len = pctx.data_end - pctx.data;
|
.pkt_len = pctx.data_end - pctx.data,
|
||||||
pctx.nh.pos = pctx.data;
|
.nh = { .pos = pctx.data },
|
||||||
|
};
|
||||||
|
|
||||||
if (parse_packet_identifier(&pctx, false, &p_id) < 0)
|
if (parse_packet_identifier(&pctx, false, &p_id) < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
Reference in New Issue
Block a user