History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next

Pablo Neira Ayuso says: ==================== Netfilter updates for net-next The following batch contains netfilter updates for your net-next tree: 1) Expose NFT_OSF_MAXGENRELEN maximum OS name length from the new OS passive fingerprint matching extension, from Fernando Fernandez. 2) Add extension to support for fine grain conntrack timeout policies from nf_tables. As preparation works, this patchset moves nf_ct_untimeout() to nf_conntrack_timeout and it also decouples the timeout policy from the ctnl_timeout object, most work done by Harsha Sharma. 3) Enable connection tracking when conntrack helper is in place. 4) Missing enumeration in uapi header when splitting original xt_osf to nfnetlink_osf, also from Fernando. 5) Fix a sparse warning due to incorrect typing in the nf_osf_find(), from Wei Yongjun. ====================

David S. Miller committed 8 years ago

Commit fd685652 parents ebddd97 e7ea2a512 files · +304 −67Browse files

Unified · Split

12 files
  1. include/linux/netfilter/nfnetlink_osf.h +0 −12
  2. include/net/netfilter/nf_conntrack_l4proto.h +0 −2
  3. include/net/netfilter/nf_conntrack_timeout.h +13 −8
  4. include/uapi/linux/netfilter/nf_tables.h +14 −1
  5. include/uapi/linux/netfilter/nfnetlink_osf.h +12 −0
  6. include/uapi/linux/netfilter/xt_osf.h +1 −0
  7. net/netfilter/nf_conntrack_timeout.c +19 −2
  8. net/netfilter/nfnetlink_cttimeout.c +22 −33
  9. net/netfilter/nfnetlink_osf.c +1 −1
  10. net/netfilter/nft_ct.c +217 −1
  11. net/netfilter/nft_osf.c +3 −5
  12. net/netfilter/xt_CT.c +2 −2
include/linux/netfilter/nfnetlink_osf.h+0−12
@@ -4,18 +4,6 @@ · 3 unmodified lines
44
55 #include <uapi/linux/netfilter/nfnetlink_osf.h>
66
7−/* Initial window size option state machine: multiple of mss, mtu or
8− * plain numeric value. Can also be made as plain numeric value which
9− * is not a multiple of specified value.
10− */
11−enum nf_osf_window_size_options {
12− OSF_WSS_PLAIN = 0,
13− OSF_WSS_MSS,
14− OSF_WSS_MTU,
15− OSF_WSS_MODULO,
16− OSF_WSS_MAX,
17−};
18−
197 enum osf_fmatch_states {
208 /* Packet does not match the fingerprint */
219 FMATCH_WRONG = 0,
include/net/netfilter/nf_conntrack_l4proto.h+0−2
@@ -77,7 +77,6 @@ struct nf_conntrack_l4proto { · 76 unmodified lines
7777 struct nf_conntrack_tuple *t);
7878 const struct nla_policy *nla_policy;
7979
80−#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
8180 struct {
8281 int (*nlattr_to_obj)(struct nlattr *tb[],
8382 struct net *net, void *data);
@@ -87,7 +86,6 @@ struct nf_conntrack_l4proto { · 3 unmodified lines
8786 u16 nlattr_max;
8887 const struct nla_policy *nla_policy;
8988 } ctnl_timeout;
90−#endif
9189 #ifdef CONFIG_NF_CONNTRACK_PROCFS
9290 /* Print out the private part of the conntrack. */
9391 void (*print_conntrack)(struct seq_file *s, struct nf_conn *);
include/net/netfilter/nf_conntrack_timeout.h+13−8
@@ -11,24 +11,28 @@ · 10 unmodified lines
1111
1212 #define CTNL_TIMEOUT_NAME_MAX 32
1313
14+struct nf_ct_timeout {
15+ __u16 l3num;
16+ const struct nf_conntrack_l4proto *l4proto;
17+ char data[0];
18+};
19+
1420 struct ctnl_timeout {
1521 struct list_head head;
1622 struct rcu_head rcu_head;
1723 refcount_t refcnt;
1824 char name[CTNL_TIMEOUT_NAME_MAX];
19− __u16 l3num;
20− const struct nf_conntrack_l4proto *l4proto;
21− char data[0];
25+ struct nf_ct_timeout timeout;
2226 };
2327
2428 struct nf_conn_timeout {
25− struct ctnl_timeout __rcu *timeout;
29+ struct nf_ct_timeout __rcu *timeout;
2630 };
2731
2832 static inline unsigned int *
2933 nf_ct_timeout_data(struct nf_conn_timeout *t)
3034 {
31− struct ctnl_timeout *timeout;
35+ struct nf_ct_timeout *timeout;
3236
3337 timeout = rcu_dereference(t->timeout);
3438 if (timeout == NULL)
@@ -49,7 +53,7 @@ struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct) · 14 unmodified lines
4953
5054 static inline
5155 struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct,
52− struct ctnl_timeout *timeout,
56+ struct nf_ct_timeout *timeout,
5357 gfp_t gfp)
5458 {
5559 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
@@ -83,6 +87,7 @@ static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn *ct) · 27 unmodified lines
8387 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
8488 int nf_conntrack_timeout_init(void);
8589 void nf_conntrack_timeout_fini(void);
90+void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout);
8691 #else
8792 static inline int nf_conntrack_timeout_init(void)
8893 {
@@ -96,8 +101,8 @@ static inline void nf_conntrack_timeout_fini(void) · 7 unmodified lines
96101 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
97102
98103 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
99−extern struct ctnl_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
100−extern void (*nf_ct_timeout_put_hook)(struct ctnl_timeout *timeout);
104+extern struct nf_ct_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
105+extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);
101106 #endif
102107
103108 #endif /* _NF_CONNTRACK_TIMEOUT_H */
include/uapi/linux/netfilter/nf_tables.h+14−1
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #define NFT_SET_MAXNAMELEN NFT_NAME_MAXLEN
99 #define NFT_OBJ_MAXNAMELEN NFT_NAME_MAXLEN
1010 #define NFT_USERDATA_MAXLEN 256
11+#define NFT_OSF_MAXGENRELEN 16
1112
1213 /**
1314 * enum nft_registers - nf_tables registers
@@ -957,6 +958,7 @@ enum nft_socket_keys { · 943 unmodified lines
957958 * @NFT_CT_DST_IP: conntrack layer 3 protocol destination (IPv4 address)
958959 * @NFT_CT_SRC_IP6: conntrack layer 3 protocol source (IPv6 address)
959960 * @NFT_CT_DST_IP6: conntrack layer 3 protocol destination (IPv6 address)
961+ * @NFT_CT_TIMEOUT: connection tracking timeout policy assigned to conntrack
960962 */
961963 enum nft_ct_keys {
962964 NFT_CT_STATE,
@@ -982,6 +984,7 @@ enum nft_ct_keys { · 19 unmodified lines
982984 NFT_CT_DST_IP,
983985 NFT_CT_SRC_IP6,
984986 NFT_CT_DST_IP6,
987+ NFT_CT_TIMEOUT,
985988 __NFT_CT_MAX
986989 };
987990 #define NFT_CT_MAX (__NFT_CT_MAX - 1)
@@ -1410,6 +1413,15 @@ enum nft_ct_helper_attributes { · 422 unmodified lines
14101413 };
14111414 #define NFTA_CT_HELPER_MAX (__NFTA_CT_HELPER_MAX - 1)
14121415
1416+enum nft_ct_timeout_timeout_attributes {
1417+ NFTA_CT_TIMEOUT_UNSPEC,
1418+ NFTA_CT_TIMEOUT_L3PROTO,
1419+ NFTA_CT_TIMEOUT_L4PROTO,
1420+ NFTA_CT_TIMEOUT_DATA,
1421+ __NFTA_CT_TIMEOUT_MAX,
1422+};
1423+#define NFTA_CT_TIMEOUT_MAX (__NFTA_CT_TIMEOUT_MAX - 1)
1424+
14131425 #define NFT_OBJECT_UNSPEC 0
14141426 #define NFT_OBJECT_COUNTER 1
14151427 #define NFT_OBJECT_QUOTA 2
@@ -1417,7 +1429,8 @@ enum nft_ct_helper_attributes { · 1 unmodified line
14171429 #define NFT_OBJECT_LIMIT 4
14181430 #define NFT_OBJECT_CONNLIMIT 5
14191431 #define NFT_OBJECT_TUNNEL 6
1420−#define __NFT_OBJECT_MAX 7
1432+#define NFT_OBJECT_CT_TIMEOUT 7
1433+#define __NFT_OBJECT_MAX 8
14211434 #define NFT_OBJECT_MAX (__NFT_OBJECT_MAX - 1)
14221435
14231436 /**
include/uapi/linux/netfilter/nfnetlink_osf.h+12−0
@@ -88,6 +88,18 @@ enum iana_options { · 87 unmodified lines
8888 OSFOPT_EMPTY = 255,
8989 };
9090
91+/* Initial window size option state machine: multiple of mss, mtu or
92+ * plain numeric value. Can also be made as plain numeric value which
93+ * is not a multiple of specified value.
94+ */
95+enum nf_osf_window_size_options {
96+ OSF_WSS_PLAIN = 0,
97+ OSF_WSS_MSS,
98+ OSF_WSS_MTU,
99+ OSF_WSS_MODULO,
100+ OSF_WSS_MAX,
101+};
102+
91103 enum nf_osf_attr_type {
92104 OSF_ATTR_UNSPEC,
93105 OSF_ATTR_FINGER,
include/uapi/linux/netfilter/xt_osf.h+1−0
@@ -46,6 +46,7 @@ · 45 unmodified lines
4646 #define xt_osf_finger nf_osf_finger
4747 #define xt_osf_nlmsg nf_osf_nlmsg
4848
49+#define xt_osf_window_size_options nf_osf_window_size_options
4950 #define xt_osf_attr_type nf_osf_attr_type
5051 #define xt_osf_msg_types nf_osf_msg_types
5152
net/netfilter/nf_conntrack_timeout.c+19−2
@@ -24,13 +24,30 @@ · 23 unmodified lines
2424 #include <net/netfilter/nf_conntrack_extend.h>
2525 #include <net/netfilter/nf_conntrack_timeout.h>
2626
27−struct ctnl_timeout *
27+struct nf_ct_timeout *
2828 (*nf_ct_timeout_find_get_hook)(struct net *net, const char *name) __read_mostly;
2929 EXPORT_SYMBOL_GPL(nf_ct_timeout_find_get_hook);
3030
31−void (*nf_ct_timeout_put_hook)(struct ctnl_timeout *timeout) __read_mostly;
31+void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout) __read_mostly;
3232 EXPORT_SYMBOL_GPL(nf_ct_timeout_put_hook);
3333
34+static int untimeout(struct nf_conn *ct, void *timeout)
35+{
36+ struct nf_conn_timeout *timeout_ext = nf_ct_timeout_find(ct);
37+
38+ if (timeout_ext && (!timeout || timeout_ext->timeout == timeout))
39+ RCU_INIT_POINTER(timeout_ext->timeout, NULL);
40+
41+ /* We are not intended to delete this conntrack. */
42+ return 0;
43+}
44+
45+void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout)
46+{
47+ nf_ct_iterate_cleanup_net(net, untimeout, timeout, 0, 0);
48+}
49+EXPORT_SYMBOL_GPL(nf_ct_untimeout);
50+
3451 static const struct nf_ct_ext_type timeout_extend = {
3552 .len = sizeof(struct nf_conn_timeout),
3653 .align = __alignof__(struct nf_conn_timeout),
net/netfilter/nfnetlink_cttimeout.c+22−33
@@ -113,13 +113,13 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl, · 112 unmodified lines
113113 /* You cannot replace one timeout policy by another of
114114 * different kind, sorry.
115115 */
116− if (matching->l3num != l3num ||
117− matching->l4proto->l4proto != l4num)
116+ if (matching->timeout.l3num != l3num ||
117+ matching->timeout.l4proto->l4proto != l4num)
118118 return -EINVAL;
119119
120− return ctnl_timeout_parse_policy(&matching->data,
121− matching->l4proto, net,
122− cda[CTA_TIMEOUT_DATA]);
120+ return ctnl_timeout_parse_policy(&matching->timeout.data,
121+ matching->timeout.l4proto,
122+ net, cda[CTA_TIMEOUT_DATA]);
123123 }
124124
125125 return -EBUSY;
@@ -140,14 +140,14 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl, · 14 unmodified lines
140140 goto err_proto_put;
141141 }
142142
143− ret = ctnl_timeout_parse_policy(&timeout->data, l4proto, net,
143+ ret = ctnl_timeout_parse_policy(&timeout->timeout.data, l4proto, net,
144144 cda[CTA_TIMEOUT_DATA]);
145145 if (ret < 0)
146146 goto err;
147147
148148 strcpy(timeout->name, nla_data(cda[CTA_TIMEOUT_NAME]));
149− timeout->l3num = l3num;
150− timeout->l4proto = l4proto;
149+ timeout->timeout.l3num = l3num;
150+ timeout->timeout.l4proto = l4proto;
151151 refcount_set(&timeout->refcnt, 1);
152152 list_add_tail_rcu(&timeout->head, &net->nfct_timeout_list);
153153
@@ -166,7 +166,7 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 12 unmodified lines
166166 struct nlmsghdr *nlh;
167167 struct nfgenmsg *nfmsg;
168168 unsigned int flags = portid ? NLM_F_MULTI : 0;
169− const struct nf_conntrack_l4proto *l4proto = timeout->l4proto;
169+ const struct nf_conntrack_l4proto *l4proto = timeout->timeout.l4proto;
170170
171171 event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_TIMEOUT, event);
172172 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
@@ -179,8 +179,9 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 6 unmodified lines
179179 nfmsg->res_id = 0;
180180
181181 if (nla_put_string(skb, CTA_TIMEOUT_NAME, timeout->name) ||
182− nla_put_be16(skb, CTA_TIMEOUT_L3PROTO, htons(timeout->l3num)) ||
183− nla_put_u8(skb, CTA_TIMEOUT_L4PROTO, timeout->l4proto->l4proto) ||
182+ nla_put_be16(skb, CTA_TIMEOUT_L3PROTO,
183+ htons(timeout->timeout.l3num)) ||
184+ nla_put_u8(skb, CTA_TIMEOUT_L4PROTO, l4proto->l4proto) ||
184185 nla_put_be32(skb, CTA_TIMEOUT_USE,
185186 htonl(refcount_read(&timeout->refcnt))))
186187 goto nla_put_failure;
@@ -194,7 +195,8 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 7 unmodified lines
194195 if (!nest_parms)
195196 goto nla_put_failure;
196197
197− ret = l4proto->ctnl_timeout.obj_to_nlattr(skb, &timeout->data);
198+ ret = l4proto->ctnl_timeout.obj_to_nlattr(skb,
199+ &timeout->timeout.data);
198200 if (ret < 0)
199201 goto nla_put_failure;
200202
@@ -297,22 +299,6 @@ static int cttimeout_get_timeout(struct net *net, struct sock *ctnl, · 96 unmodified lines
297299 return ret;
298300 }
299301
300−static int untimeout(struct nf_conn *ct, void *timeout)
301−{
302− struct nf_conn_timeout *timeout_ext = nf_ct_timeout_find(ct);
303−
304− if (timeout_ext && (!timeout || timeout_ext->timeout == timeout))
305− RCU_INIT_POINTER(timeout_ext->timeout, NULL);
306−
307− /* We are not intended to delete this conntrack. */
308− return 0;
309−}
310−
311−static void ctnl_untimeout(struct net *net, struct ctnl_timeout *timeout)
312−{
313− nf_ct_iterate_cleanup_net(net, untimeout, timeout, 0, 0);
314−}
315−
316302 /* try to delete object, fail if it is still in use. */
317303 static int ctnl_timeout_try_del(struct net *net, struct ctnl_timeout *timeout)
318304 {
@@ -324,8 +310,8 @@ static int ctnl_timeout_try_del(struct net *net, struct ctnl_timeout *timeout) · 5 unmodified lines
324310 if (refcount_dec_if_one(&timeout->refcnt)) {
325311 /* We are protected by nfnl mutex. */
326312 list_del_rcu(&timeout->head);
327− nf_ct_l4proto_put(timeout->l4proto);
328− ctnl_untimeout(net, timeout);
313+ nf_ct_l4proto_put(timeout->timeout.l4proto);
314+ nf_ct_untimeout(net, &timeout->timeout);
329315 kfree_rcu(timeout, rcu_head);
330316 } else {
331317 ret = -EBUSY;
@@ -526,8 +512,11 @@ err: · 194 unmodified lines
526512 return matching;
527513 }
528514
529−static void ctnl_timeout_put(struct ctnl_timeout *timeout)
515+static void ctnl_timeout_put(struct nf_ct_timeout *t)
530516 {
517+ struct ctnl_timeout *timeout =
518+ container_of(t, struct ctnl_timeout, timeout);
519+
531520 if (refcount_dec_and_test(&timeout->refcnt))
532521 kfree_rcu(timeout, rcu_head);
533522
@@ -573,11 +562,11 @@ static void __net_exit cttimeout_net_exit(struct net *net) · 39 unmodified lines
573562 struct ctnl_timeout *cur, *tmp;
574563
575564 nf_ct_unconfirmed_destroy(net);
576− ctnl_untimeout(net, NULL);
565+ nf_ct_untimeout(net, NULL);
577566
578567 list_for_each_entry_safe(cur, tmp, &net->nfct_timeout_list, head) {
579568 list_del_rcu(&cur->head);
580− nf_ct_l4proto_put(cur->l4proto);
569+ nf_ct_l4proto_put(cur->timeout.l4proto);
581570
582571 if (refcount_dec_and_test(&cur->refcnt))
583572 kfree_rcu(cur, rcu_head);
net/netfilter/nfnetlink_osf.c+1−1
@@ -271,7 +271,7 @@ const char *nf_osf_find(const struct sk_buff *skb, · 270 unmodified lines
271271
272272 tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts);
273273 if (!tcp)
274− return false;
274+ return NULL;
275275
276276 list_for_each_entry_rcu(kf, &nf_osf_fingers[ctx.df], finger_entry) {
277277 f = &kf->finger;
net/netfilter/nft_ct.c+217−1
@@ -22,6 +22,8 @@ · 21 unmodified lines
2222 #include <net/netfilter/nf_conntrack_helper.h>
2323 #include <net/netfilter/nf_conntrack_ecache.h>
2424 #include <net/netfilter/nf_conntrack_labels.h>
25+#include <net/netfilter/nf_conntrack_timeout.h>
26+#include <net/netfilter/nf_conntrack_l4proto.h>
2527
2628 struct nft_ct {
2729 enum nft_ct_keys key:8;
@@ -765,6 +767,194 @@ static struct nft_expr_type nft_notrack_type __read_mostly = { · 737 unmodified lines
765767 .owner = THIS_MODULE,
766768 };
767769
770+#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
771+static int
772+nft_ct_timeout_parse_policy(void *timeouts,
773+ const struct nf_conntrack_l4proto *l4proto,
774+ struct net *net, const struct nlattr *attr)
775+{
776+ struct nlattr **tb;
777+ int ret = 0;
778+
779+ if (!l4proto->ctnl_timeout.nlattr_to_obj)
780+ return 0;
781+
782+ tb = kcalloc(l4proto->ctnl_timeout.nlattr_max + 1, sizeof(*tb),
783+ GFP_KERNEL);
784+
785+ if (!tb)
786+ return -ENOMEM;
787+
788+ ret = nla_parse_nested(tb, l4proto->ctnl_timeout.nlattr_max,
789+ attr, l4proto->ctnl_timeout.nla_policy,
790+ NULL);
791+ if (ret < 0)
792+ goto err;
793+
794+ ret = l4proto->ctnl_timeout.nlattr_to_obj(tb, net, timeouts);
795+
796+err:
797+ kfree(tb);
798+ return ret;
799+}
800+
801+struct nft_ct_timeout_obj {
802+ struct nf_conn *tmpl;
803+ u8 l4proto;
804+};
805+
806+static void nft_ct_timeout_obj_eval(struct nft_object *obj,
807+ struct nft_regs *regs,
808+ const struct nft_pktinfo *pkt)
809+{
810+ const struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
811+ struct nf_conn *ct = (struct nf_conn *)skb_nfct(pkt->skb);
812+ struct sk_buff *skb = pkt->skb;
813+
814+ if (ct ||
815+ priv->l4proto != pkt->tprot)
816+ return;
817+
818+ nf_ct_set(skb, priv->tmpl, IP_CT_NEW);
819+}
820+
821+static int nft_ct_timeout_obj_init(const struct nft_ctx *ctx,
822+ const struct nlattr * const tb[],
823+ struct nft_object *obj)
824+{
825+ const struct nf_conntrack_zone *zone = &nf_ct_zone_dflt;
826+ struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
827+ const struct nf_conntrack_l4proto *l4proto;
828+ struct nf_conn_timeout *timeout_ext;
829+ struct nf_ct_timeout *timeout;
830+ int l3num = ctx->family;
831+ struct nf_conn *tmpl;
832+ __u8 l4num;
833+ int ret;
834+
835+ if (!tb[NFTA_CT_TIMEOUT_L3PROTO] ||
836+ !tb[NFTA_CT_TIMEOUT_L4PROTO] ||
837+ !tb[NFTA_CT_TIMEOUT_DATA])
838+ return -EINVAL;
839+
840+ l3num = ntohs(nla_get_be16(tb[NFTA_CT_TIMEOUT_L3PROTO]));
841+ l4num = nla_get_u8(tb[NFTA_CT_TIMEOUT_L4PROTO]);
842+ priv->l4proto = l4num;
843+
844+ l4proto = nf_ct_l4proto_find_get(l3num, l4num);
845+
846+ if (l4proto->l4proto != l4num) {
847+ ret = -EOPNOTSUPP;
848+ goto err_proto_put;
849+ }
850+
851+ timeout = kzalloc(sizeof(struct nf_ct_timeout) +
852+ l4proto->ctnl_timeout.obj_size, GFP_KERNEL);
853+ if (timeout == NULL) {
854+ ret = -ENOMEM;
855+ goto err_proto_put;
856+ }
857+
858+ ret = nft_ct_timeout_parse_policy(&timeout->data, l4proto, ctx->net,
859+ tb[NFTA_CT_TIMEOUT_DATA]);
860+ if (ret < 0)
861+ goto err_free_timeout;
862+
863+ timeout->l3num = l3num;
864+ timeout->l4proto = l4proto;
865+ tmpl = nf_ct_tmpl_alloc(ctx->net, zone, GFP_ATOMIC);
866+ if (!tmpl) {
867+ ret = -ENOMEM;
868+ goto err_free_timeout;
869+ }
870+
871+ timeout_ext = nf_ct_timeout_ext_add(tmpl, timeout, GFP_ATOMIC);
872+ if (!timeout_ext) {
873+ ret = -ENOMEM;
874+ goto err_free_tmpl;
875+ }
876+
877+ ret = nf_ct_netns_get(ctx->net, ctx->family);
878+ if (ret < 0)
879+ goto err_free_tmpl;
880+
881+ priv->tmpl = tmpl;
882+
883+ return 0;
884+
885+err_free_tmpl:
886+ nf_ct_tmpl_free(tmpl);
887+err_free_timeout:
888+ kfree(timeout);
889+err_proto_put:
890+ nf_ct_l4proto_put(l4proto);
891+ return ret;
892+}
893+
894+static void nft_ct_timeout_obj_destroy(const struct nft_ctx *ctx,
895+ struct nft_object *obj)
896+{
897+ struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
898+ struct nf_conn_timeout *t = nf_ct_timeout_find(priv->tmpl);
899+ struct nf_ct_timeout *timeout;
900+
901+ timeout = rcu_dereference_raw(t->timeout);
902+ nf_ct_untimeout(ctx->net, timeout);
903+ nf_ct_l4proto_put(timeout->l4proto);
904+ nf_ct_netns_put(ctx->net, ctx->family);
905+ nf_ct_tmpl_free(priv->tmpl);
906+}
907+
908+static int nft_ct_timeout_obj_dump(struct sk_buff *skb,
909+ struct nft_object *obj, bool reset)
910+{
911+ const struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
912+ const struct nf_conn_timeout *t = nf_ct_timeout_find(priv->tmpl);
913+ const struct nf_ct_timeout *timeout = rcu_dereference_raw(t->timeout);
914+ struct nlattr *nest_params;
915+ int ret;
916+
917+ if (nla_put_u8(skb, NFTA_CT_TIMEOUT_L4PROTO, timeout->l4proto->l4proto) ||
918+ nla_put_be16(skb, NFTA_CT_TIMEOUT_L3PROTO, htons(timeout->l3num)))
919+ return -1;
920+
921+ nest_params = nla_nest_start(skb, NFTA_CT_TIMEOUT_DATA | NLA_F_NESTED);
922+ if (!nest_params)
923+ return -1;
924+
925+ ret = timeout->l4proto->ctnl_timeout.obj_to_nlattr(skb, &timeout->data);
926+ if (ret < 0)
927+ return -1;
928+ nla_nest_end(skb, nest_params);
929+ return 0;
930+}
931+
932+static const struct nla_policy nft_ct_timeout_policy[NFTA_CT_TIMEOUT_MAX + 1] = {
933+ [NFTA_CT_TIMEOUT_L3PROTO] = {.type = NLA_U16 },
934+ [NFTA_CT_TIMEOUT_L4PROTO] = {.type = NLA_U8 },
935+ [NFTA_CT_TIMEOUT_DATA] = {.type = NLA_NESTED },
936+};
937+
938+static struct nft_object_type nft_ct_timeout_obj_type;
939+
940+static const struct nft_object_ops nft_ct_timeout_obj_ops = {
941+ .type = &nft_ct_timeout_obj_type,
942+ .size = sizeof(struct nft_ct_timeout_obj),
943+ .eval = nft_ct_timeout_obj_eval,
944+ .init = nft_ct_timeout_obj_init,
945+ .destroy = nft_ct_timeout_obj_destroy,
946+ .dump = nft_ct_timeout_obj_dump,
947+};
948+
949+static struct nft_object_type nft_ct_timeout_obj_type __read_mostly = {
950+ .type = NFT_OBJECT_CT_TIMEOUT,
951+ .ops = &nft_ct_timeout_obj_ops,
952+ .maxattr = NFTA_CT_TIMEOUT_MAX,
953+ .policy = nft_ct_timeout_policy,
954+ .owner = THIS_MODULE,
955+};
956+#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
957+
768958 static int nft_ct_helper_obj_init(const struct nft_ctx *ctx,
769959 const struct nlattr * const tb[],
770960 struct nft_object *obj)
@@ -773,6 +963,7 @@ static int nft_ct_helper_obj_init(const struct nft_ctx *ctx, · 2 unmodified lines
773963 struct nf_conntrack_helper *help4, *help6;
774964 char name[NF_CT_HELPER_NAME_LEN];
775965 int family = ctx->family;
966+ int err;
776967
777968 if (!tb[NFTA_CT_HELPER_NAME] || !tb[NFTA_CT_HELPER_L4PROTO])
778969 return -EINVAL;
@@ -823,7 +1014,18 @@ static int nft_ct_helper_obj_init(const struct nft_ctx *ctx, · 44 unmodified lines
8231014 priv->helper4 = help4;
8241015 priv->helper6 = help6;
8251016
1017+ err = nf_ct_netns_get(ctx->net, ctx->family);
1018+ if (err < 0)
1019+ goto err_put_helper;
1020+
8261021 return 0;
1022+
1023+err_put_helper:
1024+ if (priv->helper4)
1025+ nf_conntrack_helper_put(priv->helper4);
1026+ if (priv->helper6)
1027+ nf_conntrack_helper_put(priv->helper6);
1028+ return err;
8271029 }
8281030
8291031 static void nft_ct_helper_obj_destroy(const struct nft_ctx *ctx,
@@ -835,6 +1037,8 @@ static void nft_ct_helper_obj_destroy(const struct nft_ctx *ctx, · 5 unmodified lines
8351037 nf_conntrack_helper_put(priv->helper4);
8361038 if (priv->helper6)
8371039 nf_conntrack_helper_put(priv->helper6);
1040+
1041+ nf_ct_netns_put(ctx->net, ctx->family);
8381042 }
8391043
8401044 static void nft_ct_helper_obj_eval(struct nft_object *obj,
@@ -949,9 +1153,17 @@ static int __init nft_ct_module_init(void) · 108 unmodified lines
9491153 err = nft_register_obj(&nft_ct_helper_obj_type);
9501154 if (err < 0)
9511155 goto err2;
952−
1156+#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1157+ err = nft_register_obj(&nft_ct_timeout_obj_type);
1158+ if (err < 0)
1159+ goto err3;
1160+#endif
9531161 return 0;
9541162
1163+#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1164+err3:
1165+ nft_unregister_obj(&nft_ct_helper_obj_type);
1166+#endif
9551167 err2:
9561168 nft_unregister_expr(&nft_notrack_type);
9571169 err1:
@@ -961,6 +1173,9 @@ err1: · 3 unmodified lines
9611173
9621174 static void __exit nft_ct_module_exit(void)
9631175 {
1176+#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1177+ nft_unregister_obj(&nft_ct_timeout_obj_type);
1178+#endif
9641179 nft_unregister_obj(&nft_ct_helper_obj_type);
9651180 nft_unregister_expr(&nft_notrack_type);
9661181 nft_unregister_expr(&nft_ct_type);
@@ -974,3 +1189,4 @@ MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); · 7 unmodified lines
9741189 MODULE_ALIAS_NFT_EXPR("ct");
9751190 MODULE_ALIAS_NFT_EXPR("notrack");
9761191 MODULE_ALIAS_NFT_OBJ(NFT_OBJECT_CT_HELPER);
1192+MODULE_ALIAS_NFT_OBJ(NFT_OBJECT_CT_TIMEOUT);
net/netfilter/nft_osf.c+3−5
@@ -4,8 +4,6 @@ · 3 unmodified lines
44 #include <net/netfilter/nf_tables.h>
55 #include <linux/netfilter/nfnetlink_osf.h>
66
7−#define OSF_GENRE_SIZE 32
8−
97 struct nft_osf {
108 enum nft_registers dreg:8;
119 };
@@ -37,9 +35,9 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, · 25 unmodified lines
3735
3836 os_name = nf_osf_find(skb, nf_osf_fingers);
3937 if (!os_name)
40− strncpy((char *)dest, "unknown", IFNAMSIZ);
38+ strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN);
4139 else
42− strncpy((char *)dest, os_name, IFNAMSIZ);
40+ strncpy((char *)dest, os_name, NFT_OSF_MAXGENRELEN);
4341 }
4442
4543 static int nft_osf_init(const struct nft_ctx *ctx,
@@ -51,7 +49,7 @@ static int nft_osf_init(const struct nft_ctx *ctx, · 5 unmodified lines
5149
5250 priv->dreg = nft_parse_register(tb[NFTA_OSF_DREG]);
5351 err = nft_validate_register_store(ctx, priv->dreg, NULL,
54− NFTA_DATA_VALUE, OSF_GENRE_SIZE);
52+ NFTA_DATA_VALUE, NFT_OSF_MAXGENRELEN);
5553 if (err < 0)
5654 return err;
5755
net/netfilter/xt_CT.c+2−2
@@ -104,7 +104,7 @@ xt_ct_set_helper(struct nf_conn *ct, const char *helper_name, · 103 unmodified lines
104104 }
105105
106106 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
107−static void __xt_ct_tg_timeout_put(struct ctnl_timeout *timeout)
107+static void __xt_ct_tg_timeout_put(struct nf_ct_timeout *timeout)
108108 {
109109 typeof(nf_ct_timeout_put_hook) timeout_put;
110110
@@ -121,7 +121,7 @@ xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par, · 10 unmodified lines
121121 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
122122 typeof(nf_ct_timeout_find_get_hook) timeout_find_get;
123123 const struct nf_conntrack_l4proto *l4proto;
124− struct ctnl_timeout *timeout;
124+ struct nf_ct_timeout *timeout;
125125 struct nf_conn_timeout *timeout_ext;
126126 const char *errmsg = NULL;
127127 int ret = 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t