Line data Source code
1 : #if !defined(__linux__) 2 : #error "fd_xdp_redirect_user requires Linux operating system with XDP support" 3 : #endif 4 : 5 : #define _DEFAULT_SOURCE 6 : #include "fd_xdp_redirect_user.h" 7 : #include "../ebpf/fd_linux_bpf.h" 8 : #include <errno.h> 9 : 10 : fd_xsk_t * 11 : fd_xsk_activate( fd_xsk_t * xsk, 12 0 : int xsk_map_fd ) { 13 : 14 0 : uint key = xsk->if_queue_id; 15 0 : int value = xsk->xsk_fd; 16 0 : if( FD_UNLIKELY( 0!=fd_bpf_map_update_elem( xsk_map_fd, &key, &value, BPF_ANY ) ) ) { 17 0 : FD_LOG_WARNING(( "bpf_map_update_elem(fd=%d,key=%u,value=%#x,flags=%#x) failed (%i-%s)", 18 0 : xsk_map_fd, key, (uint)value, (uint)BPF_ANY, errno, fd_io_strerror( errno ) )); 19 0 : return NULL; 20 0 : } 21 : 22 0 : FD_LOG_INFO(( "Attached to XDP on interface %u queue %u", 23 0 : xsk->if_idx, xsk->if_queue_id )); 24 0 : return xsk; 25 0 : } 26 : 27 : fd_xsk_t * 28 : fd_xsk_deactivate( fd_xsk_t * xsk, 29 0 : int xsk_map_fd ) { 30 : 31 0 : uint key = xsk->if_queue_id; 32 0 : if( FD_UNLIKELY( 0!=fd_bpf_map_delete_elem( xsk_map_fd, &key ) ) ) { 33 0 : FD_LOG_WARNING(( "bpf_map_delete_elem(fd=%d,key=%u) failed (%i-%s)", xsk_map_fd, key, errno, fd_io_strerror( errno ) )); 34 0 : return NULL; 35 0 : } 36 : 37 0 : FD_LOG_INFO(( "Detached from XDP on interface %u queue %u", 38 0 : xsk->if_idx, xsk->if_queue_id )); 39 0 : return xsk; 40 0 : }