Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1 | /* |
| 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 McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 14 | #include <linux/netlink.h> |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 15 | #include <net/netlink.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 16 | #include <linux/seq_file.h> |
| 17 | #include <net/netfilter/nf_conntrack.h> |
| 18 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 19 | struct nf_conntrack_l3proto { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 20 | /* 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 Engelhardt | 8ce8439 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 30 | bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int nhoff, |
| 31 | struct nf_conntrack_tuple *tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 32 | |
| 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 Engelhardt | 8ce8439 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 37 | bool (*invert_tuple)(struct nf_conntrack_tuple *inverse, |
| 38 | const struct nf_conntrack_tuple *orig); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 39 | |
| 40 | /* Print out the per-protocol part of the tuple. */ |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 41 | void (*print_tuple)(struct seq_file *s, |
| 42 | const struct nf_conntrack_tuple *); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 43 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 44 | /* |
| 45 | * Called before tracking. |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 46 | * *dataoff: offset of protocol header (TCP, UDP,...) in skb |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 47 | * *protonum: protocol number |
| 48 | */ |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 49 | int (*get_l4proto)(const struct sk_buff *skb, unsigned int nhoff, |
| 50 | unsigned int *dataoff, u_int8_t *protonum); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 51 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 52 | int (*tuple_to_nlattr)(struct sk_buff *skb, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 53 | const struct nf_conntrack_tuple *t); |
| 54 | |
Holger Eitzenberger | d0dba72 | 2009-03-25 18:24:48 +0100 | [diff] [blame] | 55 | /* |
| 56 | * Calculate size of tuple nlattr |
| 57 | */ |
| 58 | int (*nlattr_tuple_size)(void); |
| 59 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 60 | int (*nlattr_to_tuple)(struct nlattr *tb[], |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 61 | struct nf_conntrack_tuple *t); |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 62 | const struct nla_policy *nla_policy; |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 63 | |
Holger Eitzenberger | d0dba72 | 2009-03-25 18:24:48 +0100 | [diff] [blame] | 64 | size_t nla_size; |
| 65 | |
Gao feng | 524a53e | 2012-05-28 21:04:10 +0000 | [diff] [blame] | 66 | /* Init l3proto pernet data */ |
| 67 | int (*init_net)(struct net *net); |
| 68 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 69 | /* Module (if any) which this is connected to. */ |
| 70 | struct module *me; |
| 71 | }; |
| 72 | |
Eric Dumazet | 0e60ebe | 2010-11-15 18:17:21 +0100 | [diff] [blame] | 73 | extern struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[AF_MAX]; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 74 | |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 75 | /* Protocol pernet registration. */ |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 76 | int nf_ct_l3proto_pernet_register(struct net *net, |
| 77 | struct nf_conntrack_l3proto *proto); |
| 78 | void nf_ct_l3proto_pernet_unregister(struct net *net, |
| 79 | struct nf_conntrack_l3proto *proto); |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 80 | |
| 81 | /* Protocol global registration. */ |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 82 | int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto); |
| 83 | void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto); |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 84 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 85 | struct nf_conntrack_l3proto *nf_ct_l3proto_find_get(u_int16_t l3proto); |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 86 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 87 | /* Existing built-in protocols */ |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 88 | extern struct nf_conntrack_l3proto nf_conntrack_l3proto_generic; |
Yasuyuki Kozakai | ddc8d02 | 2006-02-04 02:12:14 -0800 | [diff] [blame] | 89 | |
| 90 | static inline struct nf_conntrack_l3proto * |
| 91 | __nf_ct_l3proto_find(u_int16_t l3proto) |
| 92 | { |
| 93 | if (unlikely(l3proto >= AF_MAX)) |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 94 | return &nf_conntrack_l3proto_generic; |
Patrick McHardy | 923f490 | 2007-02-12 11:12:57 -0800 | [diff] [blame] | 95 | return rcu_dereference(nf_ct_l3protos[l3proto]); |
Yasuyuki Kozakai | ddc8d02 | 2006-02-04 02:12:14 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 98 | #endif /*_NF_CONNTRACK_L3PROTO_H*/ |