指向整数转换的指针不兼容,该整数从'struct net *'分配给'u32'(又名'unsigned int') [英] Incompatible pointer to integer conversion assigning to 'u32' (aka 'unsigned int') from 'struct net *'

查看:227
本文介绍了指向整数转换的指针不兼容,该整数从'struct net *'分配给'u32'(又名'unsigned int')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的

向execsnoop 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< bits / libc-header-start.h> 警告 $ c>存在于 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; 是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.

此结构可以在< linux中找到/ns_common.h> 头文件。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆