blob: 9f99d36d5de902b6e6209da5a4e53befaa0e24d0 [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/*
2 * Copyright (C)2003,2004 USAGI/WIDE Project
3 *
4 * Header for use in defining a given L3 protocol for connection tracking.
5 *
6 * Author:
7 * Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
8 *
9 * Derived from include/netfilter_ipv4/ip_conntrack_protocol.h
10 */
11
12#ifndef _NF_CONNTRACK_L3PROTO_H
13#define _NF_CONNTRACK_L3PROTO_H
Patrick McHardydf6fb862007-09-28 14:37:03 -070014#include <linux/netlink.h>
Patrick McHardyf73e9242007-09-28 14:39:55 -070015#include <net/netlink.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080016#include <linux/seq_file.h>
17#include <net/netfilter/nf_conntrack.h>
18
19struct nf_conntrack_l3proto
20{
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080021 /* L3 Protocol Family number. ex) PF_INET */
22 u_int16_t l3proto;
23
24 /* Protocol name */
25 const char *name;
26
27 /*
28 * Try to fill in the third arg: nhoff is offset of l3 proto
29 * hdr. Return true if possible.
30 */
Jan Engelhardt8ce84392008-04-14 11:15:52 +020031 bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int nhoff,
32 struct nf_conntrack_tuple *tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080033
34 /*
35 * Invert the per-proto part of the tuple: ie. turn xmit into reply.
36 * Some packets can't be inverted: return 0 in that case.
37 */
Jan Engelhardt8ce84392008-04-14 11:15:52 +020038 bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
39 const struct nf_conntrack_tuple *orig);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080040
41 /* Print out the per-protocol part of the tuple. */
42 int (*print_tuple)(struct seq_file *s,
43 const struct nf_conntrack_tuple *);
44
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080045 /*
46 * Called before tracking.
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -070047 * *dataoff: offset of protocol header (TCP, UDP,...) in skb
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080048 * *protonum: protocol number
49 */
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -070050 int (*get_l4proto)(const struct sk_buff *skb, unsigned int nhoff,
51 unsigned int *dataoff, u_int8_t *protonum);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080052
Patrick McHardyfdf70832007-09-28 14:37:41 -070053 int (*tuple_to_nlattr)(struct sk_buff *skb,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080054 const struct nf_conntrack_tuple *t);
55
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010056 /*
57 * Calculate size of tuple nlattr
58 */
59 int (*nlattr_tuple_size)(void);
60
Patrick McHardyfdf70832007-09-28 14:37:41 -070061 int (*nlattr_to_tuple)(struct nlattr *tb[],
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080062 struct nf_conntrack_tuple *t);
Patrick McHardyf73e9242007-09-28 14:39:55 -070063 const struct nla_policy *nla_policy;
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080064
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010065 size_t nla_size;
66
Patrick McHardyd62f9ed2006-11-29 02:35:17 +010067#ifdef CONFIG_SYSCTL
68 struct ctl_table_header *ctl_table_header;
Pavel Emelyanovb3fd3ff2008-01-09 00:34:02 -080069 struct ctl_path *ctl_table_path;
Patrick McHardyd62f9ed2006-11-29 02:35:17 +010070 struct ctl_table *ctl_table;
71#endif /* CONFIG_SYSCTL */
72
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080073 /* Module (if any) which this is connected to. */
74 struct module *me;
75};
76
77extern struct nf_conntrack_l3proto *nf_ct_l3protos[AF_MAX];
78
79/* Protocol registration. */
80extern int nf_conntrack_l3proto_register(struct nf_conntrack_l3proto *proto);
Patrick McHardyfe3eb202007-02-12 11:14:28 -080081extern void nf_conntrack_l3proto_unregister(struct nf_conntrack_l3proto *proto);
Patrick McHardya3c50292007-03-14 16:39:25 -070082extern struct nf_conntrack_l3proto *nf_ct_l3proto_find_get(u_int16_t l3proto);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080083extern void nf_ct_l3proto_put(struct nf_conntrack_l3proto *p);
84
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080085/* Existing built-in protocols */
Martin Josefsson605dcad2006-11-29 02:35:06 +010086extern struct nf_conntrack_l3proto nf_conntrack_l3proto_generic;
Yasuyuki Kozakaiddc8d022006-02-04 02:12:14 -080087
88static inline struct nf_conntrack_l3proto *
89__nf_ct_l3proto_find(u_int16_t l3proto)
90{
91 if (unlikely(l3proto >= AF_MAX))
Martin Josefsson605dcad2006-11-29 02:35:06 +010092 return &nf_conntrack_l3proto_generic;
Patrick McHardy923f4902007-02-12 11:12:57 -080093 return rcu_dereference(nf_ct_l3protos[l3proto]);
Yasuyuki Kozakaiddc8d022006-02-04 02:12:14 -080094}
95
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080096#endif /*_NF_CONNTRACK_L3PROTO_H*/