关于netlink_unicast的问题
我现在在实现一个系统调用劫持的功能,就是如果有某个进程调用open打开特定文件的话,我会像一个告警进程发送消息。现在的问题是我调用netlink_unicast发送消息给告警进程的时候,这边显示发送成功,但是告警进程却没有收到。但是如果是我的内核模块直接调用netlink_unicast发送消息就没有问题,也就是说,当我的内核模块处于用户进程的上下文的时候,调用netlink_unicast发送消息就会失败,不知道什么原因,是不是这种情况不能用netlink_unicast发送消息啊,那该怎么和另外一个进程通信呢?
主要代码如下:
asmlinkage int our_sys_open(const char* filename, int flags, int mode)
{
int i = 0;
char ch;
struct task_struct * pcurrent;
char filenm;
if(strcmp(filename, "test") == 0)
{
send_to_user(g_nlskt,"PID send success");
}
return original_call(filename, flags, mode);
}
int send_to_user(struct sock *nlfd,char *info) //发送到用户态
{
struct sk_buff*skb;
struct nlmsghdr *nlh;
void *data;
int ret;
skb = nlmsg_new(strlen(info), GFP_KERNEL);
if (!skb)
return 0;
nlh = NLMSG_NEW(skb, pids, 0, WARN_MSG, strlen(info), 0);
data = NLMSG_DATA(nlh);
memcpy(data, info, strlen(info));
ret = netlink_unicast(nlfd, skb, pids, MSG_DONTWAIT);
return 0;
nlmsg_failure:
if(skb)
kfree_skb(skb);
return 0;
}
内核直接调用send_to_user发送给告警模块是没问题的,就是当用户调用open的时候再调用就不行,也就是说在用户上下文环境中调用send_to_user函数,告警模块是收不到消息的,请高人指点一下,万分感谢! skb = nlmsg_new(strlen(info), GFP_KERNEL);
if (!skb)
return 0;
nlh = NLMSG_NEW(skb, pids, 0, WARN_MSG, strlen(info), 0);
data = NLMSG_DATA(nlh);
memcpy(data, info, strlen(info));
ret = netlink_unicast(nlfd, skb, pids, MSG_DONTWAIT);
return 0;
nlmsg_failure:
if(skb)
kfree_skb(skb);
return 0;
}
内核直接调用send_to_user发送给告警模块是没问题的,就是当用户调用open的时候再调用就不行,也就是说在用户上下文环境中调用send_to_user函数,告警模块是收不到消息的,请高人指点一下,万分感谢 抱歉,多发了 为什么总是没有问题回答啊,是我的问题太简单了,还是我的表述有问题? 你以为这是QQ吗?
别人也没有义务给你回呀。
发贴要有耐心。CU的回贴率和回贴质量还是比较高的。 把netlink_unicast的返回结果打出来看看。 不好意思,主要是比较急。netlink_unicast发送是返回成功的,但是另外一个进程就是接收不到,所以我就怀疑是不是处于用户上下文的时候,netlink_unicast发送消息是不是不行 ret = netlink_unicast(nlfd, skb, pids, MSG_DONTWAIT);
pids是啥玩意?
内核很多地方都是在进程上下文调用 netlink_unicast的
页:
[1]