1
Netfilter를 빌드하려고합니다. 첫 번째 단계는 vlan 패킷 만 받아 들인 다음 올바른 vlan ID인지 확인하는 것입니다. 문제는 내가 어떤 VLAN을 패킷을 얻을. 코드 간단한 예 :vlan 패킷 만 받아들이도록 Netfilter 모듈 작성
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/if_ether.h>
static struct nf_hook_ops nfho;
static void __exit_filter(void) {
printk("__exit_filter\n");
nf_unregister_hook(&nfho); //unregister our hook
}
static u32
recv_packet_handler(const struct nf_hook_ops *ops,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *)){
//NEED TO GET HERE VLAN PACKETS
return NF_ACCEPT;
}
static int __init_filter(void) {
nfho.hook = recv_packet_handler;
nfho.hooknum = NF_INET_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
printk("insert filter\n");
return 0;
}
module_init(__init_filter);
module_exit(__exit_filter);
나는 문제가 nfho.pf
함께하지만 난 할 모르겠어요 같아요. 도와 주셔서 감사합니다
내 시스템의 브리지가 VLAN 패킷을 전달하지 못하기 때문에 브리지를 통과하기 전에 eth0 수준에서 패킷을 잡아야합니다. NFPROTO_BRIDGE (으)로 변경하면 작동하지 않습니다. – Izik
특히 eth0 tc 입구 훅에서 VLAN 태그를 기반으로 필터링해야하는 경우 더 좋지 않습니까? L2 VLAN의 경우 IP 계층에서 왜 그렇게합니까? –
이 작업을 수행하는 방법을 모른다. 예제를 보여줄 수 있습니까? – Izik