Patrick McHardy | 48b1de4 | 2013-08-27 08:50:14 +0200 | [diff] [blame] | 1 | #ifndef _NF_CONNTRACK_SYNPROXY_H |
| 2 | #define _NF_CONNTRACK_SYNPROXY_H |
| 3 | |
| 4 | #include <net/netns/generic.h> |
| 5 | |
| 6 | struct nf_conn_synproxy { |
| 7 | u32 isn; |
| 8 | u32 its; |
| 9 | u32 tsoff; |
| 10 | }; |
| 11 | |
| 12 | static inline struct nf_conn_synproxy *nfct_synproxy(const struct nf_conn *ct) |
| 13 | { |
| 14 | #if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY) |
| 15 | return nf_ct_ext_find(ct, NF_CT_EXT_SYNPROXY); |
| 16 | #else |
| 17 | return NULL; |
| 18 | #endif |
| 19 | } |
| 20 | |
| 21 | static inline struct nf_conn_synproxy *nfct_synproxy_ext_add(struct nf_conn *ct) |
| 22 | { |
| 23 | #if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY) |
| 24 | return nf_ct_ext_add(ct, NF_CT_EXT_SYNPROXY, GFP_ATOMIC); |
| 25 | #else |
| 26 | return NULL; |
| 27 | #endif |
| 28 | } |
| 29 | |
Gao Feng | 4440a2a | 2016-09-13 08:49:18 +0800 | [diff] [blame] | 30 | static inline bool nf_ct_add_synproxy(struct nf_conn *ct, |
| 31 | const struct nf_conn *tmpl) |
| 32 | { |
| 33 | if (tmpl && nfct_synproxy(tmpl)) { |
| 34 | if (!nfct_seqadj_ext_add(ct)) |
| 35 | return false; |
| 36 | |
| 37 | if (!nfct_synproxy_ext_add(ct)) |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | return true; |
| 42 | } |
| 43 | |
Patrick McHardy | 48b1de4 | 2013-08-27 08:50:14 +0200 | [diff] [blame] | 44 | struct synproxy_stats { |
| 45 | unsigned int syn_received; |
| 46 | unsigned int cookie_invalid; |
| 47 | unsigned int cookie_valid; |
| 48 | unsigned int cookie_retrans; |
| 49 | unsigned int conn_reopened; |
| 50 | }; |
| 51 | |
| 52 | struct synproxy_net { |
| 53 | struct nf_conn *tmpl; |
| 54 | struct synproxy_stats __percpu *stats; |
| 55 | }; |
| 56 | |
| 57 | extern int synproxy_net_id; |
| 58 | static inline struct synproxy_net *synproxy_pernet(struct net *net) |
| 59 | { |
| 60 | return net_generic(net, synproxy_net_id); |
| 61 | } |
| 62 | |
| 63 | struct synproxy_options { |
| 64 | u8 options; |
| 65 | u8 wscale; |
| 66 | u16 mss; |
| 67 | u32 tsval; |
| 68 | u32 tsecr; |
| 69 | }; |
| 70 | |
| 71 | struct tcphdr; |
| 72 | struct xt_synproxy_info; |
David S. Miller | 4fbef95 | 2013-10-01 17:06:14 -0400 | [diff] [blame] | 73 | bool synproxy_parse_options(const struct sk_buff *skb, unsigned int doff, |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 74 | const struct tcphdr *th, |
| 75 | struct synproxy_options *opts); |
| 76 | unsigned int synproxy_options_size(const struct synproxy_options *opts); |
| 77 | void synproxy_build_options(struct tcphdr *th, |
| 78 | const struct synproxy_options *opts); |
Patrick McHardy | 48b1de4 | 2013-08-27 08:50:14 +0200 | [diff] [blame] | 79 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 80 | void synproxy_init_timestamp_cookie(const struct xt_synproxy_info *info, |
| 81 | struct synproxy_options *opts); |
| 82 | void synproxy_check_timestamp_cookie(struct synproxy_options *opts); |
Patrick McHardy | 48b1de4 | 2013-08-27 08:50:14 +0200 | [diff] [blame] | 83 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 84 | unsigned int synproxy_tstamp_adjust(struct sk_buff *skb, unsigned int protoff, |
| 85 | struct tcphdr *th, struct nf_conn *ct, |
| 86 | enum ip_conntrack_info ctinfo, |
| 87 | const struct nf_conn_synproxy *synproxy); |
Patrick McHardy | 48b1de4 | 2013-08-27 08:50:14 +0200 | [diff] [blame] | 88 | |
| 89 | #endif /* _NF_CONNTRACK_SYNPROXY_H */ |