指向从“struct net *"分配给“u32"(又名“unsigned int")的整数转换的不兼容指针 [英] Incompatible pointer to integer conversion assigning to 'u32' (aka 'unsigned int') from 'struct net *'
问题描述
我想要的:
向 execsnoop bcc 工具添加网络命名空间选项,以仅跟踪具有指定网络命名空间的日志,就像我们在许多其他 bcc 工具中具有过滤器 PID 选项一样.例如:execsnoop -N "ns_id"
To add a network namespace option to execsnoop bcc tool to trace only the logs with specified network namespace just like we have filter PID option in many other bcc tools. For eg: execsnoop -N "ns_id"
我正在使用 linux 内核结构来检索名称空间 ID net = task->nsproxy->net_ns;
并且需要将检索到的 ns 分配给 data.netns
这是 u32 int.
I am using linux kernel structures to retrieve namespace id net = task->nsproxy->net_ns;
and need to assign the retrieved ns to data.netns
which is u32 int.
我在做什么:
int syscall__execve(struct pt_regs *ctx,
const char __user *filename,
const char __user *const __user *__argv,
const char __user *const __user *__envp)
{
// create data here and pass to submit_arg to save stack space (#555)
//int ret = PT_REGS_RC(ctx);
struct data_t data = {};
struct task_struct *task;
struct nsproxy *nsproxy;
struct net *net;
//struct mnt_namespace *mnt_ns;
data.pid = bpf_get_current_pid_tgid() >> 32;
u32 net_ns_inum = 0;
//net = (struct net *)get_net_ns_by_pid(data.pid); //
//net_ns_inum = (uintptr_t)net;
task = (struct task_struct *)bpf_get_current_task();
// Some kernels, like Ubuntu 4.13.0-generic, return 0
// as the real_parent->tgid.
// We use the get_ppid function as a fallback in those cases. (#1883)
data.ppid = task->real_parent->tgid;
net = task->nsproxy->net_ns;
FILTER_NETNS
data.netns = (uintptr_t)net; //here have to perform casting
我添加了 #include </usr/include/stdint.h>
但得到 警告 尽管 include
存在于 stdint.h
文件中:
I have added #include </usr/include/stdint.h>
but getting the warning though include <bits/libc-header-start.h>
is present in stdint.h
file:
In file included from /virtual/main.c:8:
/usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found
#include <bits/libc-header-start.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~
如果我解决了这个错误,它会继续生成其他丢失的头文件错误.
and it keeps on generating other missing header files error if I resolve this one.
推荐答案
我已经解决了这个问题:
I have resolved this issue:
我没有使用 net = task->nsproxy->net_ns;
我使用了 net = task->nsproxy->net_ns->ns.inum;
code> 是 unsigned int,我们可以直接从中检索命名空间.
Instead of using net = task->nsproxy->net_ns;
I used net = task->nsproxy->net_ns->ns.inum;
which is unsigned int and we can directly retrieve namespace from it.
这个结构可以在
头文件中找到.
This structure can be found in <linux/ns_common.h>
header file.
struct ns_common {
atomic_long_t stashed;
const struct proc_ns_operations *ops;
unsigned int inum;
};
要获得在 execsnoop 工具中添加命名空间选项的修改代码,请点击此链接:https://github.com/Sheenam3/ebpf/blob/master/execsnoop.py#L143
To get a modified code with added namespace option in execsnoop tool, please follow this link: https://github.com/Sheenam3/ebpf/blob/master/execsnoop.py#L143
这篇关于指向从“struct net *"分配给“u32"(又名“unsigned int")的整数转换的不兼容指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!