Skip to content

Is there a netfilter hook that has the receiving socket already associated?

The NF_INET_LOCAL_OUT hook has skb->sk pointing to a struct sock for the socket that sent the packet. If there a hook that has it set for the socket that receives the packet? In the NF_INET_LOCAL_IN hook, skb->sk is null.

Will I have to use __inet_lookup_skb()? If so, what is the complexity of that function?

EDIT: looks like __inet_lookup_skb() is for TCP only, since there’s no udp_hashinfo. I’m doing this for UDP initially.



It seems there isn’t, but for my case, the LSM hook socket_recvmsg was suitable. It gets a pointer to a struct sock, which points to the struct sk_buffs in the receive queue.

User contributions licensed under: CC BY-SA
7 People found this is helpful