aya-rs / aya

Aya is an eBPF library for the Rust programming language, built with a focus on developer experience and operability.
https://aya-rs.dev/book/
Apache License 2.0
3.2k stars 286 forks source link

Error running demo eBPF application #724

Open invent360 opened 1 year ago

invent360 commented 1 year ago

I had the following errors after scaffolding an example application following the instructions in the documentation https://aya-rs.dev/book/start/development/#prerequisites.

When i ran the command: cargo xtask run -- -h

I had the following error output: error[E0432]: unresolved importslibc::nlattr,libc::nlmsgerr,libc::nlmsghdr,libc::sockaddr_nl,libc::AF_NETLINK,libc::ETH_P_ALL,libc::IFLA_XDP,libc::NETLINK_EXT_ACK,libc::NETLINK_ROUTE,libc::NLA_ALIGNTO,libc::NLA_F_NESTED,libc::NLA_TYPE_MASK,libc::NLMSG_DONE,libc::NLMSG_ERROR,libc::NLM_F_ACK,libc::NLM_F_CREATE,libc::NLM_F_DUMP,libc::NLM_F_ECHO,libc::NLM_F_EXCL,libc::NLM_F_MULTI,libc::NLM_F_REQUEST,libc::RTM_DELTFILTER,libc::RTM_GETTFILTER,libc::RTM_NEWQDISC,libc::RTM_NEWTFILTER,libc::RTM_SETLINK,libc::SOL_NETLINK` --> /Users//.cargo/git/checkouts/aya-c55fbc69175ac116/1979da9/aya/src/sys/netlink.rs:5:25 5 close, getsockname, nlattr, nlmsgerr, nlmsghdr, recv, send, setsockopt, sockaddr_nl, socket, ^^^^^^ ^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^ no sockaddr_nl in the root
no nlmsghdr in the root
no nlmsgerr in the root
no nlattr in the root
6 AF_NETLINK, AF_UNSPEC, ETH_P_ALL, IFF_UP, IFLA_XDP, NETLINK_EXT_ACK, NETLINK_ROUTE,
^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ no NETLINK_ROUTE in the root
no NETLINK_EXT_ACK in the root
no IFLA_XDP in the root
no ETH_P_ALL in the root
no AF_NETLINK in the root
7 NLA_ALIGNTO, NLA_F_NESTED, NLA_TYPE_MASK, NLMSG_DONE, NLMSG_ERROR, NLM_F_ACK, NLM_F_CREATE,
^^^^^^^^^^^ ^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^
no NLA_ALIGNTO in the root
8 NLM_F_DUMP, NLM_F_ECHO, NLM_F_EXCL, NLM_F_MULTI, NLM_F_REQUEST, RTM_DELTFILTER, RTM_GETTFILTER,
^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
9 RTM_NEWQDISC, RTM_NEWTFILTER, RTM_SETLINK, SOCK_RAW, SOL_NETLINK,
^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^
help: a similar name exists in the module 5 close, getsockname, nlattr, nlmsgerr, msghdr, recv, send, setsockopt, sockaddr_nl, socket, ~~ help: a similar name exists in the module
5 close, getsockname, nlattr, nlmsgerr, nlmsghdr, recv, send, setsockopt, sockaddr_dl, socket,
~~~

help: a similar name exists in the module | 6 | AF_IMPLINK, AF_UNSPEC, ETH_P_ALL, IFF_UP, IFLA_XDP, NETLINK_EXT_ACK, NETLINK_ROUTE, | ~~

error[E0432]: unresolved imports libc::SYS_bpf, libc::SYS_perf_event_open --> /Users//.cargo/git/checkouts/aya-c55fbc69175ac116/1979da9/aya/src/sys/mod.rs:8:34 8 use libc::{c_int, c_long, pid_t, SYS_bpf, SYS_perf_event_open}; ^^^^^^^ ^^^^^^^^^^^^^^^^^^^ no SYS_perf_event_open in the root
no SYS_bpf in the root
error[E0308]: match arms have incompatible types --> /Users//.cargo/git/checkouts/aya-c55fbc69175ac116/1979da9/aya/src/sys/mod.rs:106:17 94 / match call { 95 Syscall::Bpf { cmd, attr } => { 96 libc::syscall(SYS_bpf, cmd, attr, mem::size_of::()) ------------------------------------------------------------- this is found to be of type i32 97 } ... 104 } => libc::syscall(SYS_perf_event_open, &attr, pid, cpu, group, flags), ----------------------------------------------------------------- this is found to be of type i32 105 Syscall::PerfEventIoctl { fd, request, arg } => { 106 libc::ioctl(fd.as_raw_fd(), request.try_into().unwrap(), arg) as libc::c_long ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i32, found i64 107 } 108 } _____- match arms have incompatible types

help: you can convert an i64 to an i32 and panic if the converted value doesn't fit | 106 | (libc::ioctl(fd.as_raw_fd(), request.try_into().unwrap(), arg) as libc::c_long).try_into().unwrap() | + +++++++++++++++++++++

Some errors have detailed explanations: E0308, E0432. For more information about an error, try rustc --explain E0308. error: could not compile aya (lib) due to 3 previous errors thread 'main' panicked at 'assertion failed: status.success()', xtask/src/run.rs:34:5 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace `

alessandrod commented 1 year ago

It looks like you're trying to cross compile, see https://aya-rs.dev/book/aya/crosscompile/

invent360 commented 1 year ago

thanks @alessandrod for your prompt reply, sorry i forgot to mention my system architecture. I am using an Apple M1 Pro (Chip). arch cmd outputs arm64