1 /* Header for use in defining a given protocol for connection tracking. */
2 #ifndef _IP_CONNTRACK_PROTOCOL_H
3 #define _IP_CONNTRACK_PROTOCOL_H
4 #include <linux/netfilter_ipv4/ip_conntrack.h>
5 #include <linux/netfilter/nfnetlink_conntrack.h>
9 struct ip_conntrack_protocol
11 /* Protocol number. */
17 /* Try to fill in the third arg: dataoff is offset past IP
18 hdr. Return true if possible. */
19 int (*pkt_to_tuple)(const struct sk_buff *skb,
21 struct ip_conntrack_tuple *tuple);
23 /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
24 * Some packets can't be inverted: return 0 in that case.
26 int (*invert_tuple)(struct ip_conntrack_tuple *inverse,
27 const struct ip_conntrack_tuple *orig);
29 /* Print out the per-protocol part of the tuple. Return like seq_* */
30 int (*print_tuple)(struct seq_file *,
31 const struct ip_conntrack_tuple *);
33 /* Print out the private part of the conntrack. */
34 int (*print_conntrack)(struct seq_file *, const struct ip_conntrack *);
36 /* Returns verdict for packet, or -1 for invalid. */
37 int (*packet)(struct ip_conntrack *conntrack,
38 const struct sk_buff *skb,
39 enum ip_conntrack_info ctinfo);
41 /* Called when a new connection for this protocol found;
42 * returns TRUE if it's OK. If so, packet() called next. */
43 int (*new)(struct ip_conntrack *conntrack, const struct sk_buff *skb);
45 /* Called when a conntrack entry is destroyed */
46 void (*destroy)(struct ip_conntrack *conntrack);
48 int (*error)(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
49 unsigned int hooknum);
51 /* convert protoinfo to nfnetink attributes */
52 int (*to_nfattr)(struct sk_buff *skb, struct nfattr *nfa,
53 const struct ip_conntrack *ct);
55 int (*tuple_to_nfattr)(struct sk_buff *skb,
56 const struct ip_conntrack_tuple *t);
57 int (*nfattr_to_tuple)(struct nfattr *tb[],
58 struct ip_conntrack_tuple *t);
60 /* Module (if any) which this is connected to. */
64 /* Protocol registration. */
65 extern int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto);
66 extern void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto);
67 /* Existing built-in protocols */
68 extern struct ip_conntrack_protocol ip_conntrack_protocol_tcp;
69 extern struct ip_conntrack_protocol ip_conntrack_protocol_udp;
70 extern struct ip_conntrack_protocol ip_conntrack_protocol_icmp;
71 extern struct ip_conntrack_protocol ip_conntrack_generic_protocol;
72 extern int ip_conntrack_protocol_tcp_init(void);
74 /* Log invalid packets */
75 extern unsigned int ip_ct_log_invalid;
77 extern int ip_ct_port_tuple_to_nfattr(struct sk_buff *,
78 const struct ip_conntrack_tuple *);
79 extern int ip_ct_port_nfattr_to_tuple(struct nfattr *tb[],
80 struct ip_conntrack_tuple *);
83 #ifdef DEBUG_INVALID_PACKETS
84 #define LOG_INVALID(proto) \
85 (ip_ct_log_invalid == (proto) || ip_ct_log_invalid == IPPROTO_RAW)
87 #define LOG_INVALID(proto) \
88 ((ip_ct_log_invalid == (proto) || ip_ct_log_invalid == IPPROTO_RAW) \
92 #define LOG_INVALID(proto) 0
93 #endif /* CONFIG_SYSCTL */
95 #endif /*_IP_CONNTRACK_PROTOCOL_H*/