1
- #include <stdio.h>
2
- #include <stdlib.h>
3
- #include <string.h>
4
- #include <unistd.h>
5
- #include <errno.h>
6
- #include <locale.h>
7
- #include <linux/types.h>
8
-
9
- #include <net/if.h>
10
-
11
- #include <sys/socket.h>
12
- #include <linux/if_link.h>
13
- #include <bpf.h>
14
- #include <xsk.h>
15
-
16
1
#include "af_xdp.h"
17
2
18
3
/* Global variables */
19
4
// The XDP flags to load the AF_XDP/XSK sockets with.
20
- __u32 xdp_flags = XDP_FLAGS_DRV_MODE ;
21
- __u32 bind_flags = XDP_USE_NEED_WAKEUP ;
5
+ u32 xdp_flags = XDP_FLAGS_DRV_MODE ;
6
+ u32 bind_flags = XDP_USE_NEED_WAKEUP ;
22
7
int is_shared_umem = 0 ;
23
- __u16 batch_size = 1 ;
8
+ u16 batch_size = 1 ;
24
9
int static_queue_id = 0 ;
25
10
int queue_id = 0 ;
26
11
27
12
// For shared UMEM.
28
13
static unsigned int global_frame_idx = 0 ;
29
14
30
15
// Pointers to the umem and XSK sockets for each thread.
31
- struct xsk_umem_info * shared_umem = NULL ;
16
+ xsk_umem_info_t * shared_umem = NULL ;
32
17
33
18
/**
34
19
* Completes the TX call via a syscall and also checks if we need to free the TX buffer.
@@ -37,7 +22,7 @@ struct xsk_umem_info *shared_umem = NULL;
37
22
*
38
23
* @return Void
39
24
**/
40
- static void complete_tx (struct xsk_socket_info * xsk )
25
+ static void complete_tx (xsk_socket_info_t * xsk )
41
26
{
42
27
// Initiate starting variables (completed amount and completion ring index).
43
28
unsigned int completed ;
@@ -75,10 +60,10 @@ static void complete_tx(struct xsk_socket_info *xsk)
75
60
*
76
61
* @return Returns a pointer to the UMEM area instead of the XSK UMEM information structure (struct xsk_umem_info).
77
62
**/
78
- static struct xsk_umem_info * configure_xsk_umem (void * buffer , __u64 size )
63
+ static xsk_umem_info_t * configure_xsk_umem (void * buffer , u64 size )
79
64
{
80
65
// Create umem pointer and return variable.
81
- struct xsk_umem_info * umem ;
66
+ xsk_umem_info_t * umem ;
82
67
int ret ;
83
68
84
69
// Allocate memory space to the umem pointer and check.
@@ -115,12 +100,12 @@ static struct xsk_umem_info *configure_xsk_umem(void *buffer, __u64 size)
115
100
*
116
101
* @return Returns a pointer to the AF_XDP/XSK socket inside of a the XSK socket info structure (struct xsk_socket_info).
117
102
**/
118
- static struct xsk_socket_info * xsk_configure_socket (struct xsk_umem_info * umem , int queue_id , const char * dev )
103
+ static xsk_socket_info_t * xsk_configure_socket (xsk_umem_info_t * umem , int queue_id , const char * dev )
119
104
{
120
105
// Initialize starting variables.
121
106
struct xsk_socket_config xsk_cfg ;
122
107
struct xsk_socket_info * xsk_info ;
123
- __u32 idx ;
108
+ u32 idx ;
124
109
int i ;
125
110
int ret ;
126
111
@@ -190,10 +175,10 @@ static struct xsk_socket_info *xsk_configure_socket(struct xsk_umem_info *umem,
190
175
*
191
176
* @return Returns 0 on success and -1 on failure.
192
177
**/
193
- int send_packet (struct xsk_socket_info * xsk , int thread_id , void * pckt , __u16 length , __u8 verbose )
178
+ int send_packet (xsk_socket_info_t * xsk , int thread_id , void * pckt , u16 length , u8 verbose )
194
179
{
195
180
// This represents the TX index.
196
- __u32 tx_idx = 0 ;
181
+ u32 tx_idx = 0 ;
197
182
198
183
// Retrieve the TX index from the TX ring to fill.
199
184
while (xsk_ring_prod__reserve (& xsk -> tx , batch_size , & tx_idx ) < batch_size )
@@ -223,7 +208,7 @@ int send_packet(struct xsk_socket_info *xsk, int thread_id, void *pckt, __u16 le
223
208
}
224
209
225
210
// We must retrieve the next available address in the UMEM.
226
- __u64 addrat = get_umem_addr (xsk , idx );
211
+ u64 addrat = get_umem_addr (xsk , idx );
227
212
228
213
// We must copy our packet data to the UMEM area at the specific index (idx * frame size). We did this earlier.
229
214
memcpy (get_umem_loc (xsk , addrat ), pckt , length );
@@ -262,7 +247,7 @@ int send_packet(struct xsk_socket_info *xsk, int thread_id, void *pckt, __u16 le
262
247
*
263
248
* @return The socket FD (-1 on failure)
264
249
*/
265
- int get_socket_fd (struct xsk_socket_info * xsk )
250
+ int get_socket_fd (xsk_socket_info_t * xsk )
266
251
{
267
252
return xsk_socket__fd (xsk -> xsk );
268
253
}
@@ -275,7 +260,7 @@ int get_socket_fd(struct xsk_socket_info *xsk)
275
260
*
276
261
* @return 64-bit address of location.
277
262
**/
278
- __u64 get_umem_addr (struct xsk_socket_info * xsk , int idx )
263
+ u64 get_umem_addr (xsk_socket_info_t * xsk , int idx )
279
264
{
280
265
return xsk -> umem_frame_addr [idx ];
281
266
}
@@ -288,7 +273,7 @@ __u64 get_umem_addr(struct xsk_socket_info *xsk, int idx)
288
273
*
289
274
* @return Pointer to address in memory of UMEM.
290
275
**/
291
- void * get_umem_loc (struct xsk_socket_info * xsk , __u64 addr )
276
+ void * get_umem_loc (xsk_socket_info_t * xsk , u64 addr )
292
277
{
293
278
return xsk_umem__get_data (xsk -> umem -> buffer , addr );
294
279
}
@@ -301,7 +286,7 @@ void *get_umem_loc(struct xsk_socket_info *xsk, __u64 addr)
301
286
*
302
287
* @return Void
303
288
**/
304
- void setup_af_xdp_variables (struct cmd_line_af_xdp * cmd_af_xdp , int verbose )
289
+ void setup_af_xdp_variables (cmd_line_af_xdp_t * cmd_af_xdp , int verbose )
305
290
{
306
291
// Check for zero-copy or copy modes.
307
292
if (cmd_af_xdp -> zero_copy )
@@ -386,11 +371,11 @@ void setup_af_xdp_variables(struct cmd_line_af_xdp *cmd_af_xdp, int verbose)
386
371
*
387
372
* @return 0 on success and -1 on failure.
388
373
**/
389
- struct xsk_umem_info * setup_umem (int thread_id )
374
+ xsk_umem_info_t * setup_umem (int thread_id )
390
375
{
391
376
// This indicates the buffer for frames and frame size for the UMEM area.
392
377
void * frame_buffer ;
393
- __u64 frame_buffer_size = NUM_FRAMES * FRAME_SIZE ;
378
+ u64 frame_buffer_size = NUM_FRAMES * FRAME_SIZE ;
394
379
395
380
// Allocate blank memory space for the UMEM (aligned in chunks). Check as well.
396
381
if (posix_memalign (& frame_buffer , getpagesize (), frame_buffer_size ))
@@ -412,7 +397,7 @@ struct xsk_umem_info *setup_umem(int thread_id)
412
397
*
413
398
* @return Returns the AF_XDP's socket FD or -1 on failure.
414
399
**/
415
- struct xsk_socket_info * setup_socket (const char * dev , __u16 thread_id , int verbose )
400
+ xsk_socket_info_t * setup_socket (const char * dev , u16 thread_id , int verbose )
416
401
{
417
402
// Verbose message.
418
403
if (verbose )
@@ -421,7 +406,7 @@ struct xsk_socket_info* setup_socket(const char *dev, __u16 thread_id, int verbo
421
406
}
422
407
423
408
// Configure and create the AF_XDP/XSK socket.
424
- struct xsk_umem_info * umem ;
409
+ xsk_umem_info_t * umem ;
425
410
426
411
// Check for shared UMEM.
427
412
if (is_shared_umem )
@@ -455,7 +440,7 @@ struct xsk_socket_info* setup_socket(const char *dev, __u16 thread_id, int verbo
455
440
return NULL ;
456
441
}
457
442
458
- struct xsk_socket_info * xsk = xsk_configure_socket (umem , (static_queue_id ) ? queue_id : thread_id , (const char * )dev );
443
+ xsk_socket_info_t * xsk = xsk_configure_socket (umem , (static_queue_id ) ? queue_id : thread_id , (const char * )dev );
459
444
460
445
// Check to make sure it's valid.
461
446
if (xsk == NULL )
@@ -484,7 +469,7 @@ struct xsk_socket_info* setup_socket(const char *dev, __u16 thread_id, int verbo
484
469
*
485
470
* @return Void
486
471
**/
487
- void cleanup_socket (struct xsk_socket_info * xsk )
472
+ void cleanup_socket (xsk_socket_info_t * xsk )
488
473
{
489
474
// If the AF_XDP/XSK socket isn't NULL, delete it.
490
475
if (xsk -> xsk != NULL )
0 commit comments