60 likes | 264 Views
NETFILTER. Reading: Chapter 19. Device driver (input). Device driver (output). CRC Check Consistency check. NF_IP_PRE_ROUTING. NF_IP_POST_ROUTING. Forwarded packets. Routing. NF_IP_FORWARD (iptables: FORWARD). Routing. NF_IP_LOCAL_IN (iptables: INPUT). NF_IP_LOCAL_OUT
E N D
NETFILTER Reading: Chapter 19 FSU CIS 5930 Internet Protocols
Device driver (input) Device driver (output) CRC Check Consistency check NF_IP_PRE_ROUTING NF_IP_POST_ROUTING Forwarded packets Routing NF_IP_FORWARD (iptables: FORWARD) Routing NF_IP_LOCAL_IN (iptables: INPUT) NF_IP_LOCAL_OUT (iptables: OUTPUT) Higher layers Local processes Incoming packets Outgoing packets NETFILTER FSU CIS 5930 Internet Protocols
NETFILTER hooks • A means to insert packet filter code at well-defined locations • NF_IP_PRE_ROUTING • NF_IP_LOCAL_IN • NF_IP_FORWARD • NF_IP_LOCAL_OUT • NF_IP_POST_ROUTING FSU CIS 5930 Internet Protocols
NF_HOOK() #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (list_empty(&nf_hooks[(pf)][(hook)]) ? (okfn)(skb) : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn))) One example: return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, output_maybe_reroute); FSU CIS 5930 Internet Protocols
Register/unregister hook functions • Template of hook functions • nf_register_hook() • nf_unregister_hook() typedef unsigned int nf_hookfn(unsigned int hooknum, struct sk_buff **skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)); FSU CIS 5930 Internet Protocols
struct nf_hook_ops Struct nf_hook_ops { struct list_head list; nf_hookfn *hook; int pf; int hooknum; int priority; }; FSU CIS 5930 Internet Protocols