在NF_INET_POST_ROUTING
中是否有方法知道数据包是通过RAW套接字生成的:
#include <sys/socket.h>
#include <netinet/in.h>
raw_socket = socket(AF_INET, SOCK_RAW, int protocol);
非常感谢您的帮助!
是的,您可以使用struct socket
的type
字段。
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
挂钩中。