2017-10-01 4 views
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 함께하지만 난 할 모르겠어요 같아요. 도와 주셔서 감사합니다

+0

내 시스템의 브리지가 VLAN 패킷을 전달하지 못하기 때문에 브리지를 통과하기 전에 eth0 수준에서 패킷을 잡아야합니다. NFPROTO_BRIDGE (으)로 변경하면 작동하지 않습니다. – Izik

+0

특히 eth0 tc 입구 훅에서 VLAN 태그를 기반으로 필터링해야하는 경우 더 좋지 않습니까? L2 VLAN의 경우 IP 계층에서 왜 그렇게합니까? –

+0

이 작업을 수행하는 방법을 모른다. 예제를 보여줄 수 있습니까? – Izik

답변

0

그럼,/config/network가 구성 오류 때문에 예상대로 작동하지 않는다는 것을 알게 된 후에 많은 시간을 보냈습니다. u는 당신의 OpenWrt에서 VLAN을 사용하려면 u는이 명령이 필요합니다

uci add network switch_vlan 
uci set [email protected]_vlan[-1].device='switch0' 
uci set [email protected]_vlan[-1].vlan=[any number from ?-15] 
uci set [email protected]_vlan[-1].ports='0t 2t 5t' 
uci set [email protected]_vlan[-1].vid=[any number between ?-4094] 
uci commit network 

임금 "포트"변화하는 것을 관심과 하드웨어에 의존합니다. 하나의 AP에서 2t를 사용했고 다른 하나는 5t가 필요했기 때문에 두 가지 경우를 처리하기 위해 두 가지를 모두 포함 시켰습니다. 사례가 다를 수 있습니다.