blob: 8992e4229da95a07b771736a317d253f4fd2a61c [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
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000019struct nf_conntrack_l3proto {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080020 /* L3 Protocol Family number. ex) PF_INET */
21 u_int16_t l3proto;
22
23 /* Protocol name */
24 const char *name;
25
26 /*
27 * Try to fill in the third arg: nhoff is offset of l3 proto
28 * hdr. Return true if possible.
29 */
Jan Engelhardt8ce84392008-04-14 11:15:52 +020030 bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int nhoff,
31 struct nf_conntrack_tuple *tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080032
33 /*
34 * Invert the per-proto part of the tuple: ie. turn xmit into reply.
35 * Some packets can't be inverted: return 0 in that case.
36 */
Jan Engelhardt8ce84392008-04-14 11:15:52 +020037 bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
38 const struct nf_conntrack_tuple *orig);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080039
40 /* Print out the per-protocol part of the tuple. */
Joe Perches824f1fb2014-09-29 16:08:22 -070041 void (*print_tuple)(struct seq_file *s,
42 const struct nf_conntrack_tuple *);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080043
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080044 /*
45 * Called before tracking.
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -070046 * *dataoff: offset of protocol header (TCP, UDP,...) in skb
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080047 * *protonum: protocol number
48 */
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -070049 int (*get_l4proto)(const struct sk_buff *skb, unsigned int nhoff,
50 unsigned int *dataoff, u_int8_t *protonum);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080051
Patrick McHardyfdf70832007-09-28 14:37:41 -070052 int (*tuple_to_nlattr)(struct sk_buff *skb,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080053 const struct nf_conntrack_tuple *t);
54
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010055 /*
56 * Calculate size of tuple nlattr
57 */
58 int (*nlattr_tuple_size)(void);
59
Patrick McHardyfdf70832007-09-28 14:37:41 -070060 int (*nlattr_to_tuple)(struct nlattr *tb[],
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080061 struct nf_conntrack_tuple *t);
Patrick McHardyf73e9242007-09-28 14:39:55 -070062 const struct nla_policy *nla_policy;
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080063
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010064 size_t nla_size;
65
Gao feng524a53e2012-05-28 21:04:10 +000066 /* Init l3proto pernet data */
67 int (*init_net)(struct net *net);
68
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080069 /* Module (if any) which this is connected to. */
70 struct module *me;
71};
72
Eric Dumazet0e60ebe2010-11-15 18:17:21 +010073extern struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[AF_MAX];
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080074
Gao feng63307502013-01-21 22:10:33 +000075/* Protocol pernet registration. */
Joe Perches4e77be42013-09-23 11:37:48 -070076int nf_ct_l3proto_pernet_register(struct net *net,
77 struct nf_conntrack_l3proto *proto);
78void nf_ct_l3proto_pernet_unregister(struct net *net,
79 struct nf_conntrack_l3proto *proto);
Gao feng63307502013-01-21 22:10:33 +000080
81/* Protocol global registration. */
Joe Perches4e77be42013-09-23 11:37:48 -070082int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto);
83void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto);
Gao feng63307502013-01-21 22:10:33 +000084
Joe Perches4e77be42013-09-23 11:37:48 -070085struct nf_conntrack_l3proto *nf_ct_l3proto_find_get(u_int16_t l3proto);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080086
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080087/* Existing built-in protocols */
Martin Josefsson605dcad2006-11-29 02:35:06 +010088extern struct nf_conntrack_l3proto nf_conntrack_l3proto_generic;
Yasuyuki Kozakaiddc8d022006-02-04 02:12:14 -080089
90static inline struct nf_conntrack_l3proto *
91__nf_ct_l3proto_find(u_int16_t l3proto)
92{
93 if (unlikely(l3proto >= AF_MAX))
Martin Josefsson605dcad2006-11-29 02:35:06 +010094 return &nf_conntrack_l3proto_generic;
Patrick McHardy923f4902007-02-12 11:12:57 -080095 return rcu_dereference(nf_ct_l3protos[l3proto]);
Yasuyuki Kozakaiddc8d022006-02-04 02:12:14 -080096}
97
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080098#endif /*_NF_CONNTRACK_L3PROTO_H*/