forked from ChimeraOS/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf: adding tests for bpf_xdp_adjust_tail
adding selftests for bpf_xdp_adjust_tail helper. in this synthetic test we are testing that 1) if data_end < data helper will return EINVAL 2) for normal use case packet's length would be reduced. Signed-off-by: Nikita V. Shirokov <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
- Loading branch information
Showing
5 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 | ||
* Copyright (c) 2018 Facebook | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of version 2 of the GNU General Public | ||
* License as published by the Free Software Foundation. | ||
*/ | ||
#include <linux/bpf.h> | ||
#include <linux/if_ether.h> | ||
#include "bpf_helpers.h" | ||
|
||
int _version SEC("version") = 1; | ||
|
||
SEC("xdp_adjust_tail") | ||
int _xdp_adjust_tail(struct xdp_md *xdp) | ||
{ | ||
void *data_end = (void *)(long)xdp->data_end; | ||
void *data = (void *)(long)xdp->data; | ||
int offset = 0; | ||
|
||
if (data_end - data == 54) | ||
offset = 256; | ||
else | ||
offset = 20; | ||
if (bpf_xdp_adjust_tail(xdp, 0 - offset)) | ||
return XDP_DROP; | ||
return XDP_TX; | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters