@@ -154,11 +154,11 @@ static bool xsk_page_aligned(void *buffer)
154
154
static void xsk_set_umem_config (struct xsk_umem_config * cfg ,
155
155
const struct xsk_umem_opts * opts )
156
156
{
157
- cfg -> fill_size = OPTS_GET (opts , fill_size , XSK_RING_PROD__DEFAULT_NUM_DESCS ) ;
158
- cfg -> comp_size = OPTS_GET (opts , comp_size , XSK_RING_CONS__DEFAULT_NUM_DESCS ) ;
159
- cfg -> frame_size = OPTS_GET (opts , frame_size , XSK_UMEM__DEFAULT_FRAME_SIZE ) ;
160
- cfg -> frame_headroom = OPTS_GET (opts , frame_headroom , XSK_UMEM__DEFAULT_FRAME_HEADROOM ) ;
161
- cfg -> flags = OPTS_GET (opts , flags , XSK_UMEM__DEFAULT_FLAGS ) ;
157
+ cfg -> fill_size = OPTS_GET (opts , fill_size , 0 ) ?: XSK_RING_PROD__DEFAULT_NUM_DESCS ;
158
+ cfg -> comp_size = OPTS_GET (opts , comp_size , 0 ) ?: XSK_RING_CONS__DEFAULT_NUM_DESCS ;
159
+ cfg -> frame_size = OPTS_GET (opts , frame_size , 0 ) ?: XSK_UMEM__DEFAULT_FRAME_SIZE ;
160
+ cfg -> frame_headroom = OPTS_GET (opts , frame_headroom , 0 ) ?: XSK_UMEM__DEFAULT_FRAME_HEADROOM ;
161
+ cfg -> flags = OPTS_GET (opts , flags , 0 ) ?: XSK_UMEM__DEFAULT_FLAGS ;
162
162
}
163
163
164
164
static int xsk_set_xdp_socket_config (struct xsk_socket_config * cfg ,
@@ -316,7 +316,7 @@ struct xsk_umem *xsk_umem__create_opts(void *umem_area,
316
316
err = - EINVAL ;
317
317
goto err ;
318
318
}
319
- fd = OPTS_GET (opts , fd , -1 );
319
+ fd = OPTS_GET (opts , fd , 0 );
320
320
size = OPTS_GET (opts , size , 0 );
321
321
322
322
if (!size && !xsk_page_aligned (umem_area )) {
@@ -330,7 +330,7 @@ struct xsk_umem *xsk_umem__create_opts(void *umem_area,
330
330
goto err ;
331
331
}
332
332
333
- umem -> fd = fd < 0 ? socket (AF_XDP , SOCK_RAW , 0 ) : fd ;
333
+ umem -> fd = fd > 0 ? fd : socket (AF_XDP , SOCK_RAW , 0 );
334
334
if (umem -> fd < 0 ) {
335
335
err = - errno ;
336
336
goto out_umem_alloc ;
@@ -387,18 +387,14 @@ int xsk_umem__create_with_fd(struct xsk_umem **umem_ptr, int fd,
387
387
DECLARE_LIBXDP_OPTS (xsk_umem_opts , opts ,
388
388
.fd = fd ,
389
389
.size = size ,
390
- .fill_size = usr_config ? usr_config -> fill_size
391
- : XSK_RING_PROD__DEFAULT_NUM_DESCS ,
392
- .comp_size = usr_config ? usr_config -> comp_size
393
- : XSK_RING_CONS__DEFAULT_NUM_DESCS ,
394
- .frame_size = usr_config ? usr_config -> frame_size
395
- : XSK_UMEM__DEFAULT_FRAME_SIZE ,
396
- .frame_headroom = usr_config ? usr_config -> frame_headroom
397
- : XSK_UMEM__DEFAULT_FRAME_HEADROOM ,
398
- .flags = usr_config ? usr_config -> flags
399
- : XSK_UMEM__DEFAULT_FLAGS ,
400
390
);
401
-
391
+ if (usr_config ) {
392
+ opts .fill_size = usr_config -> fill_size ;
393
+ opts .comp_size = usr_config -> comp_size ;
394
+ opts .frame_size = usr_config -> frame_size ;
395
+ opts .frame_headroom = usr_config -> frame_headroom ;
396
+ opts .flags = usr_config -> flags ;
397
+ }
402
398
umem = xsk_umem__create_opts (umem_area , fill , comp , & opts );
403
399
if (!umem )
404
400
return errno ;
@@ -412,7 +408,7 @@ int xsk_umem__create(struct xsk_umem **umem_ptr, void *umem_area,
412
408
struct xsk_ring_cons * comp ,
413
409
const struct xsk_umem_config * usr_config )
414
410
{
415
- return xsk_umem__create_with_fd (umem_ptr , -1 , umem_area , size ,
411
+ return xsk_umem__create_with_fd (umem_ptr , 0 , umem_area , size ,
416
412
fill , comp , usr_config );
417
413
}
418
414
0 commit comments