Fix build with musl

pull/1/head
Alessandro Decina 4 years ago
parent 68a633fe51
commit 3e8a279a59

@ -3,3 +3,4 @@
#include <linux/perf_event.h> #include <linux/perf_event.h>
#include <linux/if_link.h> #include <linux/if_link.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <asm-generic/socket.h>

@ -36,7 +36,9 @@ BPF_VARS="\
BPF_DW \ BPF_DW \
BPF_W \ BPF_W \
BPF_H \ BPF_H \
BPF_B BPF_B \
SO_ATTACH_BPF \
SO_DETACH_BPF
" "
BTF_TYPES="\ BTF_TYPES="\

@ -128,6 +128,8 @@ pub const XDP_FLAGS_HW_MODE: u32 = 8;
pub const XDP_FLAGS_REPLACE: u32 = 16; pub const XDP_FLAGS_REPLACE: u32 = 16;
pub const XDP_FLAGS_MODES: u32 = 14; pub const XDP_FLAGS_MODES: u32 = 14;
pub const XDP_FLAGS_MASK: u32 = 31; pub const XDP_FLAGS_MASK: u32 = 31;
pub const SO_ATTACH_BPF: u32 = 50;
pub const SO_DETACH_BPF: u32 = 27;
pub type __u8 = ::std::os::raw::c_uchar; pub type __u8 = ::std::os::raw::c_uchar;
pub type __s16 = ::std::os::raw::c_short; pub type __s16 = ::std::os::raw::c_short;
pub type __u16 = ::std::os::raw::c_ushort; pub type __u16 = ::std::os::raw::c_ushort;

@ -128,6 +128,8 @@ pub const XDP_FLAGS_HW_MODE: u32 = 8;
pub const XDP_FLAGS_REPLACE: u32 = 16; pub const XDP_FLAGS_REPLACE: u32 = 16;
pub const XDP_FLAGS_MODES: u32 = 14; pub const XDP_FLAGS_MODES: u32 = 14;
pub const XDP_FLAGS_MASK: u32 = 31; pub const XDP_FLAGS_MASK: u32 = 31;
pub const SO_ATTACH_BPF: u32 = 50;
pub const SO_DETACH_BPF: u32 = 27;
pub type __u8 = ::std::os::raw::c_uchar; pub type __u8 = ::std::os::raw::c_uchar;
pub type __s16 = ::std::os::raw::c_short; pub type __s16 = ::std::os::raw::c_short;
pub type __u16 = ::std::os::raw::c_ushort; pub type __u16 = ::std::os::raw::c_ushort;

@ -1,9 +1,9 @@
use libc::{setsockopt, SOL_SOCKET, SO_ATTACH_BPF, SO_DETACH_BPF}; use libc::{setsockopt, SOL_SOCKET};
use std::{io, mem, os::unix::prelude::RawFd}; use std::{io, mem, os::unix::prelude::RawFd};
use thiserror::Error; use thiserror::Error;
use crate::{ use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_SOCKET_FILTER, generated::{bpf_prog_type::BPF_PROG_TYPE_SOCKET_FILTER, SO_ATTACH_BPF, SO_DETACH_BPF},
programs::{load_program, Link, LinkRef, ProgramData, ProgramError}, programs::{load_program, Link, LinkRef, ProgramData, ProgramError},
}; };
@ -33,7 +33,7 @@ impl SocketFilter {
setsockopt( setsockopt(
socket, socket,
SOL_SOCKET, SOL_SOCKET,
SO_ATTACH_BPF, SO_ATTACH_BPF as i32,
&prog_fd as *const _ as *const _, &prog_fd as *const _ as *const _,
mem::size_of::<RawFd>() as u32, mem::size_of::<RawFd>() as u32,
) )
@ -64,7 +64,7 @@ impl Link for SocketFilterLink {
setsockopt( setsockopt(
self.socket, self.socket,
SOL_SOCKET, SOL_SOCKET,
SO_DETACH_BPF, SO_DETACH_BPF as i32,
&fd as *const _ as *const _, &fd as *const _ as *const _,
mem::size_of::<RawFd>() as u32, mem::size_of::<RawFd>() as u32,
); );

@ -5,7 +5,7 @@ mod perf_event;
#[cfg(test)] #[cfg(test)]
mod fake; mod fake;
use std::{ffi::CString, io, mem}; use std::{convert::TryInto, ffi::CString, io, mem};
use libc::{c_int, c_long, c_ulong, pid_t, utsname}; use libc::{c_int, c_long, c_ulong, pid_t, utsname};
@ -61,7 +61,9 @@ unsafe fn syscall_impl(call: Syscall) -> SysResult {
group, group,
flags, flags,
} => libc::syscall(SYS_perf_event_open, &attr, pid, cpu, group, flags), } => libc::syscall(SYS_perf_event_open, &attr, pid, cpu, group, flags),
PerfEventIoctl { fd, request, arg } => libc::ioctl(fd, request, arg) as i64, PerfEventIoctl { fd, request, arg } => {
libc::ioctl(fd, request.try_into().unwrap(), arg) as i64
}
}; };
if ret < 0 { if ret < 0 {

Loading…
Cancel
Save