gpt4 book ai didi

c - netfilter 队列数

转载 作者:太空宇宙 更新时间:2023-11-04 03:57:09 25 4
gpt4 key购买 nike

我正在用 netfilter 的钩子(Hook)编写一些内核模块。钩子(Hook)函数:

uint main_hook(uint hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *) )
{
struct iphdr *ip;
struct udphdr *udp;
if (skb->protocol == htons(ETH_P_IP)){
ip = (struct iphdr *)skb->data;//skb_network_header(skb);
if (ip->version == 4 && ip->protocol == IPPROTO_UDP){
udp = (struct udphdr *)(skb->data + sizeof(struct iphdr));
printk("[udp-catch] packet from %d to %d\n", ntohs(udp->source), ntohs(udp->dest));
return NF_QUEUE;
}
}
return NF_ACCEPT;
}

我可以指定多个队列吗?如果没有,我怎样才能找到这个号码?

最佳答案

libnetfilter_queue 和 ip 表

libnetfilter_queue 网页的函数文档:

create_queue()

创建队列时,num 的默认值为 0。

如果你有两个队列在同一台机器上运行,比如说一个发送IP数据包另一个接收,你需要创建两个不同编号的队列:

发送:

qh = nfq_create_queue(h,  0, &cb, NULL);

接收:

qh = nfq_create_queue(h,  1, &cb, NULL);

要正确过滤 IP 表,您应该指定 netfilter 队列号:

发件人:

sudo iptables -A OUTPUT -p all -d <dest ip> -j NFQUEUE --queue-num 0

接收者:

sudo iptables -A INPUT -p all -s <src ip> -d <dest ip> -j NFQUEUE --queue-num 1

您还可以查看 iptables 手册并搜索 NFQUEUE。

希望这能有所帮助。

关于c - netfilter 队列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15389719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com