Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
tsn-measures
Commits
b4730e0b
Commit
b4730e0b
authored
Jun 19, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add xdp_kern
parent
fffebb53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
packet-exchange/build/Makefile
packet-exchange/build/Makefile
+1
-0
packet-exchange/src/xdp_kern.c
packet-exchange/src/xdp_kern.c
+62
-0
No files found.
packet-exchange/build/Makefile
View file @
b4730e0b
...
...
@@ -11,6 +11,7 @@ CLIENT_SRCS = client.c
CLIENT_SRCS
+=
recv_packet.c
CLIENT_SRCS
+=
send_packet.c
CLIENT_SRCS
+=
utilities.c
CLIENT_SRCS
+=
xdp_kern.c
SERVER_OBJS
=
$(SERVER_SRCS:%.c=%.o)
CLIENT_OBJS
=
$(CLIENT_SRCS:%.c=%.o)
...
...
packet-exchange/src/xdp_kern.c
0 → 100644
View file @
b4730e0b
#define KBUILD_MODNAME "blub"
#include <linux/bpf.h>
#include <linux/if_link.h>
#include <linux/if_xdp.h>
#include <linux/if_ether.h>
#include <linux/udp.h>
#include <linux/ip.h>
#include <linux/in.h>
#include "bpf_helpers.h"
struct
bpf_map_def
SEC
(
"maps"
)
xsks_map
=
{
.
type
=
BPF_MAP_TYPE_XSKMAP
,
.
key_size
=
sizeof
(
int
),
.
value_size
=
sizeof
(
int
),
.
max_entries
=
64
,
};
static
inline
int
parse_ipv4
(
void
*
data
,
unsigned
long
long
nh_off
,
void
*
data_end
)
{
struct
iphdr
*
iph
=
data
+
nh_off
;
if
((
void
*
)(
iph
+
1
)
>
data_end
)
return
0
;
return
iph
->
protocol
;
}
SEC
(
"xdp_sock"
)
int
xdp_sock_prog
(
struct
xdp_md
*
ctx
)
{
void
*
data_end
=
(
void
*
)(
long
)
ctx
->
data_end
;
void
*
data
=
(
void
*
)(
long
)
ctx
->
data
;
struct
ethhdr
*
eth
=
data
;
int
idx
=
ctx
->
rx_queue_index
;
unsigned
int
ipproto
=
0
;
unsigned
long
long
nh_off
;
/* Check if it's a UDP frame: If UDP -> Redirect to active xsk for user
* space. If not -> pass to stack.
*/
nh_off
=
sizeof
(
*
eth
);
if
(
data
+
nh_off
>
data_end
)
return
XDP_PASS
;
if
(
eth
->
h_proto
==
__builtin_bswap16
(
ETH_P_IP
))
ipproto
=
parse_ipv4
(
data
,
nh_off
,
data_end
);
if
(
ipproto
!=
IPPROTO_UDP
)
return
XDP_PASS
;
/* If socket bound to rx_queue than redirect to user space */
if
(
bpf_map_lookup_elem
(
&
xsks_map
,
&
idx
))
return
bpf_redirect_map
(
&
xsks_map
,
idx
,
0
);
/* Else pass to Linux' network stack */
return
XDP_PASS
;
}
char
_license
[]
SEC
(
"license"
)
=
"GPL"
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment