c-RAW套接字和NF_INET_POST_OUTING



NF_INET_POST_ROUTING中是否有方法知道数据包是通过RAW套接字生成的:

#include <sys/socket.h>
#include <netinet/in.h>
raw_socket = socket(AF_INET, SOCK_RAW, int protocol); 

非常感谢您的帮助!

是的,您可以使用struct sockettype字段。

F.e.:

static unsigned int nfh_handler(...) {
struct iphdr *ip_header = ip_hdr(skb);
if(ip_header->protocol == IPPROTO_TCP) {
struct tcphdr *tcp_header = tcp_hdr(skb);
if(skb->sk && skb->sk->sk_socket &&
skb->sk->sk_socket->type == SOCK_RAW)
printk(KERN_INFO "SOCK_RAW -> src port:%d, dst port:%dn",
ntohs(tcp_header->source), ntohs(tcp_header->dest));
}
// ...    
// return
}

请记住,转发的数据包也可能出现在NF_INET_POST_ROUTING挂钩中。

最新更新