* [PATCH 0/1 v2] constify nf_conntrack_l3/4proto parameters @ 2017-07-30 19:38 ` Julia Lawall 0 siblings, 0 replies; 6+ messages in thread From: Julia Lawall @ 2017-07-30 19:38 UTC (permalink / raw) To: Pablo Neira Ayuso Cc: bhumirks, kernel-janitors, Jozsef Kadlecsik, Florian Westphal, David S. Miller, netfilter-devel, coreteam, netdev, linux-kernel When a nf_conntrack_l3/4proto parameter is not on the left hand side of an assignment, its address is not taken, and it is not passed to a function that may modify its fields, then it can be declared as const. This change is useful from a documentation point of view, and can possibly facilitate making some nf_conntrack_l4proto structures const subsequently. Done with the help of Coccinelle. The following semantic patch shows the nf_conntrack_l4proto case. // <smpl> virtual update_results virtual after_start @initialize:ocaml@ @@ let unsafe = Hashtbl.create 101 let is_unsafe f = Hashtbl.mem unsafe f let changed = ref false (* The next three rules relate to the fact that we do not know the type of void * variables. Fortunately this is only neede on the first iteration, but it still means that the whole kernel will end up being considered. *) @has depends on !after_start && !update_results@ identifier f,x; position p; @@ f@p(...,struct nf_conntrack_l3proto *x,...) { ... } @hasa depends on !after_start@ identifier f,x; position p; @@ f@p(...,struct nf_conntrack_l3proto *x[],...) { ... } @others depends on !after_start && !update_results@ position p != {has.p,hasa.p}; identifier f,x; @@ f@p(...,void *x,...) { ... } @script:ocaml@ f << others.f; @@ changed := true; Hashtbl.add unsafe f () @fpb depends on !update_results disable optional_qualifier, drop_cast exists@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x,fld; identifier bad : script:ocaml() { is_unsafe(bad) }; assignment operator aop; expression e; local idexpression fp; type T; @@ f(...,struct nf_conntrack_l3proto *x,...) { ... ( return x; | (<+...x...+>) aop e | e aop x | (T)x | &(<+...x...+>) | bad(...,x,...) | fp(...,x,...) | (<+...e->fld...+>)(...,x,...) ) ...when any } @script:ocaml@ f << fpb.f; @@ changed := true; Printf.eprintf "%s is unsafe\n" f; Hashtbl.add unsafe f () @fpba depends on !update_results disable optional_qualifier, drop_cast exists@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x,fld; identifier bad : script:ocaml() { is_unsafe(bad) }; assignment operator aop; expression e; local idexpression fp; type T; @@ f(...,struct nf_conntrack_l3proto *x[],...) { ... ( return \(x\|x[...]\); | (<+...x...+>) aop e | e aop \(x\|x[...]\) | (T)\(x\|x[...]\) | &(<+...x...+>) | bad(...,\(x\|x[...]\),...) | fp(...,\(x\|x[...]\),...) | (<+...e->fld...+>)(...,\(x\|x[...]\),...) ) ... when any } @script:ocaml@ f << fpba.f; @@ changed := true; Printf.eprintf "%s is unsafe\n" f; Hashtbl.add unsafe f () @finalize:ocaml depends on !update_results@ tbls << merge.unsafe; c << merge.changed; @@ List.iter (fun t -> Hashtbl.iter (fun k v -> if not (Hashtbl.mem unsafe k) then Hashtbl.add unsafe k ()) t) tbls; changed := false; let changed = List.exists (fun x -> !x) c in let it = new iteration() in it#add_virtual_rule After_start; (if not changed then it#add_virtual_rule Update_results); it#register() @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; @@ f(..., + const struct nf_conntrack_l3proto *x,...) { ... } @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; type T; @@ T f(..., + const struct nf_conntrack_l3proto *x,...); @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; @@ f(..., + const struct nf_conntrack_l3proto *x[],...) { ... } @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; type T; @@ T f(..., + const struct nf_conntrack_l3proto *x[],...); // </smpl> --- v2: Added consideration of array parameters. This adds transformation of nf_ct_l4proto_pernet_register and nf_ct_l4proto_pernet_unregister. This patch also adds transformation of ctnl_timeout_parse_policy that was somehow overlooked previously. include/net/netfilter/nf_conntrack_l3proto.h | 6 ++--- include/net/netfilter/nf_conntrack_l4proto.h | 14 ++++++------ include/net/netfilter/nf_conntrack_timeout.h | 2 - net/netfilter/nf_conntrack_core.c | 8 +++---- net/netfilter/nf_conntrack_netlink.c | 6 ++--- net/netfilter/nf_conntrack_proto.c | 30 +++++++++++++-------------- net/netfilter/nfnetlink_cttimeout.c | 5 ++-- 7 files changed, 36 insertions(+), 35 deletions(-) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 0/1 v2] constify nf_conntrack_l3/4proto parameters @ 2017-07-30 19:38 ` Julia Lawall 0 siblings, 0 replies; 6+ messages in thread From: Julia Lawall @ 2017-07-30 19:38 UTC (permalink / raw) To: Pablo Neira Ayuso Cc: bhumirks, kernel-janitors, Jozsef Kadlecsik, Florian Westphal, David S. Miller, netfilter-devel, coreteam, netdev, linux-kernel When a nf_conntrack_l3/4proto parameter is not on the left hand side of an assignment, its address is not taken, and it is not passed to a function that may modify its fields, then it can be declared as const. This change is useful from a documentation point of view, and can possibly facilitate making some nf_conntrack_l4proto structures const subsequently. Done with the help of Coccinelle. The following semantic patch shows the nf_conntrack_l4proto case. // <smpl> virtual update_results virtual after_start @initialize:ocaml@ @@ let unsafe = Hashtbl.create 101 let is_unsafe f = Hashtbl.mem unsafe f let changed = ref false (* The next three rules relate to the fact that we do not know the type of void * variables. Fortunately this is only neede on the first iteration, but it still means that the whole kernel will end up being considered. *) @has depends on !after_start && !update_results@ identifier f,x; position p; @@ f@p(...,struct nf_conntrack_l3proto *x,...) { ... } @hasa depends on !after_start@ identifier f,x; position p; @@ f@p(...,struct nf_conntrack_l3proto *x[],...) { ... } @others depends on !after_start && !update_results@ position p != {has.p,hasa.p}; identifier f,x; @@ f@p(...,void *x,...) { ... } @script:ocaml@ f << others.f; @@ changed := true; Hashtbl.add unsafe f () @fpb depends on !update_results disable optional_qualifier, drop_cast exists@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x,fld; identifier bad : script:ocaml() { is_unsafe(bad) }; assignment operator aop; expression e; local idexpression fp; type T; @@ f(...,struct nf_conntrack_l3proto *x,...) { ... ( return x; | (<+...x...+>) aop e | e aop x | (T)x | &(<+...x...+>) | bad(...,x,...) | fp(...,x,...) | (<+...e->fld...+>)(...,x,...) ) ...when any } @script:ocaml@ f << fpb.f; @@ changed := true; Printf.eprintf "%s is unsafe\n" f; Hashtbl.add unsafe f () @fpba depends on !update_results disable optional_qualifier, drop_cast exists@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x,fld; identifier bad : script:ocaml() { is_unsafe(bad) }; assignment operator aop; expression e; local idexpression fp; type T; @@ f(...,struct nf_conntrack_l3proto *x[],...) { ... ( return \(x\|x[...]\); | (<+...x...+>) aop e | e aop \(x\|x[...]\) | (T)\(x\|x[...]\) | &(<+...x...+>) | bad(...,\(x\|x[...]\),...) | fp(...,\(x\|x[...]\),...) | (<+...e->fld...+>)(...,\(x\|x[...]\),...) ) ... when any } @script:ocaml@ f << fpba.f; @@ changed := true; Printf.eprintf "%s is unsafe\n" f; Hashtbl.add unsafe f () @finalize:ocaml depends on !update_results@ tbls << merge.unsafe; c << merge.changed; @@ List.iter (fun t -> Hashtbl.iter (fun k v -> if not (Hashtbl.mem unsafe k) then Hashtbl.add unsafe k ()) t) tbls; changed := false; let changed = List.exists (fun x -> !x) c in let it = new iteration() in it#add_virtual_rule After_start; (if not changed then it#add_virtual_rule Update_results); it#register() @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; @@ f(..., + const struct nf_conntrack_l3proto *x,...) { ... } @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; type T; @@ T f(..., + const struct nf_conntrack_l3proto *x,...); @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; @@ f(..., + const struct nf_conntrack_l3proto *x[],...) { ... } @depends on update_results disable optional_qualifier@ identifier f : script:ocaml() { not(is_unsafe(f)) }; identifier x; type T; @@ T f(..., + const struct nf_conntrack_l3proto *x[],...); // </smpl> --- v2: Added consideration of array parameters. This adds transformation of nf_ct_l4proto_pernet_register and nf_ct_l4proto_pernet_unregister. This patch also adds transformation of ctnl_timeout_parse_policy that was somehow overlooked previously. include/net/netfilter/nf_conntrack_l3proto.h | 6 ++--- include/net/netfilter/nf_conntrack_l4proto.h | 14 ++++++------ include/net/netfilter/nf_conntrack_timeout.h | 2 - net/netfilter/nf_conntrack_core.c | 8 +++---- net/netfilter/nf_conntrack_netlink.c | 6 ++--- net/netfilter/nf_conntrack_proto.c | 30 +++++++++++++-------------- net/netfilter/nfnetlink_cttimeout.c | 5 ++-- 7 files changed, 36 insertions(+), 35 deletions(-) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/1 v2] netfilter: constify nf_conntrack_l3/4proto parameters 2017-07-30 19:38 ` Julia Lawall @ 2017-07-30 19:38 ` Julia Lawall -1 siblings, 0 replies; 6+ messages in thread From: Julia Lawall @ 2017-07-30 19:38 UTC (permalink / raw) To: David S. Miller Cc: bhumirks, kernel-janitors, Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal, netfilter-devel, coreteam, netdev, linux-kernel When a nf_conntrack_l3/4proto parameter is not on the left hand side of an assignment, its address is not taken, and it is not passed to a function that may modify its fields, then it can be declared as const. This change is useful from a documentation point of view, and can possibly facilitate making some nf_conntrack_l3/4proto structures const subsequently. Done with the help of Coccinelle. Some spacing adjusted to fit within 80 characters. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> --- v2: Added consideration of array parameters. This adds transformation of nf_ct_l4proto_pernet_register and nf_ct_l4proto_pernet_unregister. This patch also adds transformation of ctnl_timeout_parse_policy that was somehow overlooked previously. include/net/netfilter/nf_conntrack_l3proto.h | 6 ++--- include/net/netfilter/nf_conntrack_l4proto.h | 14 ++++++------ include/net/netfilter/nf_conntrack_timeout.h | 2 - net/netfilter/nf_conntrack_core.c | 8 +++---- net/netfilter/nf_conntrack_netlink.c | 6 ++--- net/netfilter/nf_conntrack_proto.c | 30 +++++++++++++-------------- net/netfilter/nfnetlink_cttimeout.c | 5 ++-- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/include/net/netfilter/nf_conntrack_l3proto.h b/include/net/netfilter/nf_conntrack_l3proto.h index 6d14b36..4782b15 100644 --- a/include/net/netfilter/nf_conntrack_l3proto.h +++ b/include/net/netfilter/nf_conntrack_l3proto.h @@ -76,17 +76,17 @@ struct nf_conntrack_l3proto { #ifdef CONFIG_SYSCTL /* Protocol pernet registration. */ int nf_ct_l3proto_pernet_register(struct net *net, - struct nf_conntrack_l3proto *proto); + const struct nf_conntrack_l3proto *proto); #else static inline int nf_ct_l3proto_pernet_register(struct net *n, - struct nf_conntrack_l3proto *p) + const struct nf_conntrack_l3proto *p) { return 0; } #endif void nf_ct_l3proto_pernet_unregister(struct net *net, - struct nf_conntrack_l3proto *proto); + const struct nf_conntrack_l3proto *proto); /* Protocol global registration. */ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto); diff --git a/include/net/netfilter/nf_conntrack_l4proto.h b/include/net/netfilter/nf_conntrack_l4proto.h index 7032e04..c86e946 100644 --- a/include/net/netfilter/nf_conntrack_l4proto.h +++ b/include/net/netfilter/nf_conntrack_l4proto.h @@ -125,23 +125,23 @@ struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u_int16_t l3proto, struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u_int16_t l3proto, u_int8_t l4proto); -void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p); +void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p); /* Protocol pernet registration. */ int nf_ct_l4proto_pernet_register_one(struct net *net, - struct nf_conntrack_l4proto *proto); + const struct nf_conntrack_l4proto *proto); void nf_ct_l4proto_pernet_unregister_one(struct net *net, - struct nf_conntrack_l4proto *proto); + const struct nf_conntrack_l4proto *proto); int nf_ct_l4proto_pernet_register(struct net *net, - struct nf_conntrack_l4proto *proto[], + struct nf_conntrack_l4proto * const proto[], unsigned int num_proto); void nf_ct_l4proto_pernet_unregister(struct net *net, - struct nf_conntrack_l4proto *proto[], - unsigned int num_proto); + struct nf_conntrack_l4proto * const proto[], + unsigned int num_proto); /* Protocol global registration. */ int nf_ct_l4proto_register_one(struct nf_conntrack_l4proto *proto); -void nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *proto); +void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *proto); int nf_ct_l4proto_register(struct nf_conntrack_l4proto *proto[], unsigned int num_proto); void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *proto[], diff --git a/include/net/netfilter/nf_conntrack_timeout.h b/include/net/netfilter/nf_conntrack_timeout.h index d40b893..b222957 100644 --- a/include/net/netfilter/nf_conntrack_timeout.h +++ b/include/net/netfilter/nf_conntrack_timeout.h @@ -68,7 +68,7 @@ struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct, static inline unsigned int * nf_ct_timeout_lookup(struct net *net, struct nf_conn *ct, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { #ifdef CONFIG_NF_CONNTRACK_TIMEOUT struct nf_conn_timeout *timeout_ext; diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 51390fe..ed4e04e 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1183,8 +1183,8 @@ void nf_conntrack_free(struct nf_conn *ct) static noinline struct nf_conntrack_tuple_hash * init_conntrack(struct net *net, struct nf_conn *tmpl, const struct nf_conntrack_tuple *tuple, - struct nf_conntrack_l3proto *l3proto, - struct nf_conntrack_l4proto *l4proto, + const struct nf_conntrack_l3proto *l3proto, + const struct nf_conntrack_l4proto *l4proto, struct sk_buff *skb, unsigned int dataoff, u32 hash) { @@ -1295,8 +1295,8 @@ void nf_conntrack_free(struct nf_conn *ct) unsigned int dataoff, u_int16_t l3num, u_int8_t protonum, - struct nf_conntrack_l3proto *l3proto, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l3proto *l3proto, + const struct nf_conntrack_l4proto *l4proto) { const struct nf_conntrack_zone *zone; struct nf_conntrack_tuple tuple; diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 7999e70..5d08602 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -61,8 +61,8 @@ static char __initdata version[] = "0.93"; static int ctnetlink_dump_tuples_proto(struct sk_buff *skb, - const struct nf_conntrack_tuple *tuple, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_tuple *tuple, + const struct nf_conntrack_l4proto *l4proto) { int ret = 0; struct nlattr *nest_parms; @@ -86,7 +86,7 @@ static int ctnetlink_dump_tuples_proto(struct sk_buff *skb, static int ctnetlink_dump_tuples_ip(struct sk_buff *skb, const struct nf_conntrack_tuple *tuple, - struct nf_conntrack_l3proto *l3proto) + const struct nf_conntrack_l3proto *l3proto) { int ret = 0; struct nlattr *nest_parms; diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c index 1dcad22..62a2923 100644 --- a/net/netfilter/nf_conntrack_proto.c +++ b/net/netfilter/nf_conntrack_proto.c @@ -188,7 +188,7 @@ struct nf_conntrack_l4proto * } EXPORT_SYMBOL_GPL(nf_ct_l4proto_find_get); -void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p) +void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p) { module_put(p->me); } @@ -242,7 +242,7 @@ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto) extern unsigned int nf_conntrack_default_on; int nf_ct_l3proto_pernet_register(struct net *net, - struct nf_conntrack_l3proto *proto) + const struct nf_conntrack_l3proto *proto) { if (nf_conntrack_default_on == 0) return 0; @@ -271,7 +271,7 @@ void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto) EXPORT_SYMBOL_GPL(nf_ct_l3proto_unregister); void nf_ct_l3proto_pernet_unregister(struct net *net, - struct nf_conntrack_l3proto *proto) + const struct nf_conntrack_l3proto *proto) { /* * nf_conntrack_default_on *might* have registered hooks. @@ -286,7 +286,7 @@ void nf_ct_l3proto_pernet_unregister(struct net *net, EXPORT_SYMBOL_GPL(nf_ct_l3proto_pernet_unregister); static struct nf_proto_net *nf_ct_l4proto_net(struct net *net, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { if (l4proto->get_net_proto) { /* statically built-in protocols use static per-net */ @@ -301,7 +301,7 @@ static struct nf_proto_net *nf_ct_l4proto_net(struct net *net, static int nf_ct_l4proto_register_sysctl(struct net *net, struct nf_proto_net *pn, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { int err = 0; @@ -324,8 +324,8 @@ int nf_ct_l4proto_register_sysctl(struct net *net, static void nf_ct_l4proto_unregister_sysctl(struct net *net, - struct nf_proto_net *pn, - struct nf_conntrack_l4proto *l4proto) + struct nf_proto_net *pn, + const struct nf_conntrack_l4proto *l4proto) { #ifdef CONFIG_SYSCTL if (pn->ctl_table_header != NULL) @@ -395,7 +395,7 @@ int nf_ct_l4proto_register_one(struct nf_conntrack_l4proto *l4proto) EXPORT_SYMBOL_GPL(nf_ct_l4proto_register_one); int nf_ct_l4proto_pernet_register_one(struct net *net, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { int ret = 0; struct nf_proto_net *pn = NULL; @@ -420,7 +420,7 @@ int nf_ct_l4proto_pernet_register_one(struct net *net, } EXPORT_SYMBOL_GPL(nf_ct_l4proto_pernet_register_one); -static void __nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) +static void __nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto) { BUG_ON(l4proto->l3proto >= ARRAY_SIZE(nf_ct_protos)); @@ -433,7 +433,7 @@ static void __nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) &nf_conntrack_l4proto_generic); } -void nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) +void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto) { mutex_lock(&nf_ct_proto_mutex); __nf_ct_l4proto_unregister_one(l4proto); @@ -444,7 +444,7 @@ void nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) EXPORT_SYMBOL_GPL(nf_ct_l4proto_unregister_one); void nf_ct_l4proto_pernet_unregister_one(struct net *net, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { struct nf_proto_net *pn = nf_ct_l4proto_net(net, l4proto); @@ -478,8 +478,8 @@ int nf_ct_l4proto_register(struct nf_conntrack_l4proto *l4proto[], EXPORT_SYMBOL_GPL(nf_ct_l4proto_register); int nf_ct_l4proto_pernet_register(struct net *net, - struct nf_conntrack_l4proto *l4proto[], - unsigned int num_proto) + struct nf_conntrack_l4proto * const l4proto[], + unsigned int num_proto) { int ret = -EINVAL; unsigned int i; @@ -514,8 +514,8 @@ void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *l4proto[], EXPORT_SYMBOL_GPL(nf_ct_l4proto_unregister); void nf_ct_l4proto_pernet_unregister(struct net *net, - struct nf_conntrack_l4proto *l4proto[], - unsigned int num_proto) + struct nf_conntrack_l4proto * const l4proto[], + unsigned int num_proto) { while (num_proto-- != 0) nf_ct_l4proto_pernet_unregister_one(net, l4proto[num_proto]); diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c index 400e9ae..707a0d8 100644 --- a/net/netfilter/nfnetlink_cttimeout.c +++ b/net/netfilter/nfnetlink_cttimeout.c @@ -47,7 +47,8 @@ }; static int -ctnl_timeout_parse_policy(void *timeouts, struct nf_conntrack_l4proto *l4proto, +ctnl_timeout_parse_policy(void *timeouts, + const struct nf_conntrack_l4proto *l4proto, struct net *net, const struct nlattr *attr) { int ret = 0; @@ -401,7 +402,7 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl, static int cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid, u32 seq, u32 type, int event, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { struct nlmsghdr *nlh; struct nfgenmsg *nfmsg; ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 1/1 v2] netfilter: constify nf_conntrack_l3/4proto parameters @ 2017-07-30 19:38 ` Julia Lawall 0 siblings, 0 replies; 6+ messages in thread From: Julia Lawall @ 2017-07-30 19:38 UTC (permalink / raw) To: David S. Miller Cc: bhumirks, kernel-janitors, Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal, netfilter-devel, coreteam, netdev, linux-kernel When a nf_conntrack_l3/4proto parameter is not on the left hand side of an assignment, its address is not taken, and it is not passed to a function that may modify its fields, then it can be declared as const. This change is useful from a documentation point of view, and can possibly facilitate making some nf_conntrack_l3/4proto structures const subsequently. Done with the help of Coccinelle. Some spacing adjusted to fit within 80 characters. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> --- v2: Added consideration of array parameters. This adds transformation of nf_ct_l4proto_pernet_register and nf_ct_l4proto_pernet_unregister. This patch also adds transformation of ctnl_timeout_parse_policy that was somehow overlooked previously. include/net/netfilter/nf_conntrack_l3proto.h | 6 ++--- include/net/netfilter/nf_conntrack_l4proto.h | 14 ++++++------ include/net/netfilter/nf_conntrack_timeout.h | 2 - net/netfilter/nf_conntrack_core.c | 8 +++---- net/netfilter/nf_conntrack_netlink.c | 6 ++--- net/netfilter/nf_conntrack_proto.c | 30 +++++++++++++-------------- net/netfilter/nfnetlink_cttimeout.c | 5 ++-- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/include/net/netfilter/nf_conntrack_l3proto.h b/include/net/netfilter/nf_conntrack_l3proto.h index 6d14b36..4782b15 100644 --- a/include/net/netfilter/nf_conntrack_l3proto.h +++ b/include/net/netfilter/nf_conntrack_l3proto.h @@ -76,17 +76,17 @@ struct nf_conntrack_l3proto { #ifdef CONFIG_SYSCTL /* Protocol pernet registration. */ int nf_ct_l3proto_pernet_register(struct net *net, - struct nf_conntrack_l3proto *proto); + const struct nf_conntrack_l3proto *proto); #else static inline int nf_ct_l3proto_pernet_register(struct net *n, - struct nf_conntrack_l3proto *p) + const struct nf_conntrack_l3proto *p) { return 0; } #endif void nf_ct_l3proto_pernet_unregister(struct net *net, - struct nf_conntrack_l3proto *proto); + const struct nf_conntrack_l3proto *proto); /* Protocol global registration. */ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto); diff --git a/include/net/netfilter/nf_conntrack_l4proto.h b/include/net/netfilter/nf_conntrack_l4proto.h index 7032e04..c86e946 100644 --- a/include/net/netfilter/nf_conntrack_l4proto.h +++ b/include/net/netfilter/nf_conntrack_l4proto.h @@ -125,23 +125,23 @@ struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u_int16_t l3proto, struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u_int16_t l3proto, u_int8_t l4proto); -void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p); +void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p); /* Protocol pernet registration. */ int nf_ct_l4proto_pernet_register_one(struct net *net, - struct nf_conntrack_l4proto *proto); + const struct nf_conntrack_l4proto *proto); void nf_ct_l4proto_pernet_unregister_one(struct net *net, - struct nf_conntrack_l4proto *proto); + const struct nf_conntrack_l4proto *proto); int nf_ct_l4proto_pernet_register(struct net *net, - struct nf_conntrack_l4proto *proto[], + struct nf_conntrack_l4proto * const proto[], unsigned int num_proto); void nf_ct_l4proto_pernet_unregister(struct net *net, - struct nf_conntrack_l4proto *proto[], - unsigned int num_proto); + struct nf_conntrack_l4proto * const proto[], + unsigned int num_proto); /* Protocol global registration. */ int nf_ct_l4proto_register_one(struct nf_conntrack_l4proto *proto); -void nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *proto); +void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *proto); int nf_ct_l4proto_register(struct nf_conntrack_l4proto *proto[], unsigned int num_proto); void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *proto[], diff --git a/include/net/netfilter/nf_conntrack_timeout.h b/include/net/netfilter/nf_conntrack_timeout.h index d40b893..b222957 100644 --- a/include/net/netfilter/nf_conntrack_timeout.h +++ b/include/net/netfilter/nf_conntrack_timeout.h @@ -68,7 +68,7 @@ struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct, static inline unsigned int * nf_ct_timeout_lookup(struct net *net, struct nf_conn *ct, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { #ifdef CONFIG_NF_CONNTRACK_TIMEOUT struct nf_conn_timeout *timeout_ext; diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 51390fe..ed4e04e 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1183,8 +1183,8 @@ void nf_conntrack_free(struct nf_conn *ct) static noinline struct nf_conntrack_tuple_hash * init_conntrack(struct net *net, struct nf_conn *tmpl, const struct nf_conntrack_tuple *tuple, - struct nf_conntrack_l3proto *l3proto, - struct nf_conntrack_l4proto *l4proto, + const struct nf_conntrack_l3proto *l3proto, + const struct nf_conntrack_l4proto *l4proto, struct sk_buff *skb, unsigned int dataoff, u32 hash) { @@ -1295,8 +1295,8 @@ void nf_conntrack_free(struct nf_conn *ct) unsigned int dataoff, u_int16_t l3num, u_int8_t protonum, - struct nf_conntrack_l3proto *l3proto, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l3proto *l3proto, + const struct nf_conntrack_l4proto *l4proto) { const struct nf_conntrack_zone *zone; struct nf_conntrack_tuple tuple; diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 7999e70..5d08602 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -61,8 +61,8 @@ static char __initdata version[] = "0.93"; static int ctnetlink_dump_tuples_proto(struct sk_buff *skb, - const struct nf_conntrack_tuple *tuple, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_tuple *tuple, + const struct nf_conntrack_l4proto *l4proto) { int ret = 0; struct nlattr *nest_parms; @@ -86,7 +86,7 @@ static int ctnetlink_dump_tuples_proto(struct sk_buff *skb, static int ctnetlink_dump_tuples_ip(struct sk_buff *skb, const struct nf_conntrack_tuple *tuple, - struct nf_conntrack_l3proto *l3proto) + const struct nf_conntrack_l3proto *l3proto) { int ret = 0; struct nlattr *nest_parms; diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c index 1dcad22..62a2923 100644 --- a/net/netfilter/nf_conntrack_proto.c +++ b/net/netfilter/nf_conntrack_proto.c @@ -188,7 +188,7 @@ struct nf_conntrack_l4proto * } EXPORT_SYMBOL_GPL(nf_ct_l4proto_find_get); -void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p) +void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p) { module_put(p->me); } @@ -242,7 +242,7 @@ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto) extern unsigned int nf_conntrack_default_on; int nf_ct_l3proto_pernet_register(struct net *net, - struct nf_conntrack_l3proto *proto) + const struct nf_conntrack_l3proto *proto) { if (nf_conntrack_default_on = 0) return 0; @@ -271,7 +271,7 @@ void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto) EXPORT_SYMBOL_GPL(nf_ct_l3proto_unregister); void nf_ct_l3proto_pernet_unregister(struct net *net, - struct nf_conntrack_l3proto *proto) + const struct nf_conntrack_l3proto *proto) { /* * nf_conntrack_default_on *might* have registered hooks. @@ -286,7 +286,7 @@ void nf_ct_l3proto_pernet_unregister(struct net *net, EXPORT_SYMBOL_GPL(nf_ct_l3proto_pernet_unregister); static struct nf_proto_net *nf_ct_l4proto_net(struct net *net, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { if (l4proto->get_net_proto) { /* statically built-in protocols use static per-net */ @@ -301,7 +301,7 @@ static struct nf_proto_net *nf_ct_l4proto_net(struct net *net, static int nf_ct_l4proto_register_sysctl(struct net *net, struct nf_proto_net *pn, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { int err = 0; @@ -324,8 +324,8 @@ int nf_ct_l4proto_register_sysctl(struct net *net, static void nf_ct_l4proto_unregister_sysctl(struct net *net, - struct nf_proto_net *pn, - struct nf_conntrack_l4proto *l4proto) + struct nf_proto_net *pn, + const struct nf_conntrack_l4proto *l4proto) { #ifdef CONFIG_SYSCTL if (pn->ctl_table_header != NULL) @@ -395,7 +395,7 @@ int nf_ct_l4proto_register_one(struct nf_conntrack_l4proto *l4proto) EXPORT_SYMBOL_GPL(nf_ct_l4proto_register_one); int nf_ct_l4proto_pernet_register_one(struct net *net, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { int ret = 0; struct nf_proto_net *pn = NULL; @@ -420,7 +420,7 @@ int nf_ct_l4proto_pernet_register_one(struct net *net, } EXPORT_SYMBOL_GPL(nf_ct_l4proto_pernet_register_one); -static void __nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) +static void __nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto) { BUG_ON(l4proto->l3proto >= ARRAY_SIZE(nf_ct_protos)); @@ -433,7 +433,7 @@ static void __nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) &nf_conntrack_l4proto_generic); } -void nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) +void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto) { mutex_lock(&nf_ct_proto_mutex); __nf_ct_l4proto_unregister_one(l4proto); @@ -444,7 +444,7 @@ void nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) EXPORT_SYMBOL_GPL(nf_ct_l4proto_unregister_one); void nf_ct_l4proto_pernet_unregister_one(struct net *net, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { struct nf_proto_net *pn = nf_ct_l4proto_net(net, l4proto); @@ -478,8 +478,8 @@ int nf_ct_l4proto_register(struct nf_conntrack_l4proto *l4proto[], EXPORT_SYMBOL_GPL(nf_ct_l4proto_register); int nf_ct_l4proto_pernet_register(struct net *net, - struct nf_conntrack_l4proto *l4proto[], - unsigned int num_proto) + struct nf_conntrack_l4proto * const l4proto[], + unsigned int num_proto) { int ret = -EINVAL; unsigned int i; @@ -514,8 +514,8 @@ void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *l4proto[], EXPORT_SYMBOL_GPL(nf_ct_l4proto_unregister); void nf_ct_l4proto_pernet_unregister(struct net *net, - struct nf_conntrack_l4proto *l4proto[], - unsigned int num_proto) + struct nf_conntrack_l4proto * const l4proto[], + unsigned int num_proto) { while (num_proto-- != 0) nf_ct_l4proto_pernet_unregister_one(net, l4proto[num_proto]); diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c index 400e9ae..707a0d8 100644 --- a/net/netfilter/nfnetlink_cttimeout.c +++ b/net/netfilter/nfnetlink_cttimeout.c @@ -47,7 +47,8 @@ }; static int -ctnl_timeout_parse_policy(void *timeouts, struct nf_conntrack_l4proto *l4proto, +ctnl_timeout_parse_policy(void *timeouts, + const struct nf_conntrack_l4proto *l4proto, struct net *net, const struct nlattr *attr) { int ret = 0; @@ -401,7 +402,7 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl, static int cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid, u32 seq, u32 type, int event, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l4proto *l4proto) { struct nlmsghdr *nlh; struct nfgenmsg *nfmsg; ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1 v2] netfilter: constify nf_conntrack_l3/4proto parameters 2017-07-30 19:38 ` Julia Lawall @ 2017-07-31 18:44 ` Pablo Neira Ayuso -1 siblings, 0 replies; 6+ messages in thread From: Pablo Neira Ayuso @ 2017-07-31 18:44 UTC (permalink / raw) To: Julia Lawall Cc: David S. Miller, bhumirks, kernel-janitors, Jozsef Kadlecsik, Florian Westphal, netfilter-devel, coreteam, netdev, linux-kernel Hi Julia, On Sun, Jul 30, 2017 at 09:38:44PM +0200, Julia Lawall wrote: > When a nf_conntrack_l3/4proto parameter is not on the left hand side > of an assignment, its address is not taken, and it is not passed to a > function that may modify its fields, then it can be declared as const. > > This change is useful from a documentation point of view, and can > possibly facilitate making some nf_conntrack_l3/4proto structures const > subsequently. > > Done with the help of Coccinelle. > > Some spacing adjusted to fit within 80 characters. patching file include/net/netfilter/nf_conntrack_l3proto.h Hunk #1 FAILED at 76. 1 out of 1 hunk FAILED -- saving rejects to file include/net/netfilter/nf_conntrack_l3proto.h.rej patching file include/net/netfilter/nf_conntrack_l4proto.h patching file include/net/netfilter/nf_conntrack_timeout.h patching file net/netfilter/nf_conntrack_core.c Hunk #1 succeeded at 1176 (offset -7 lines). Hunk #2 succeeded at 1288 (offset -7 lines). patching file net/netfilter/nf_conntrack_netlink.c patching file net/netfilter/nf_conntrack_proto.c Hunk #2 FAILED at 242. Hunk #3 FAILED at 271. Hunk #4 succeeded at 257 with fuzz 1 (offset -29 lines). Hunk #5 succeeded at 272 (offset -29 lines). Hunk #6 succeeded at 295 (offset -29 lines). Hunk #7 succeeded at 366 (offset -29 lines). Hunk #8 succeeded at 391 (offset -29 lines). Hunk #9 succeeded at 404 (offset -29 lines). Hunk #10 succeeded at 415 (offset -29 lines). Hunk #11 succeeded at 449 (offset -29 lines). Hunk #12 succeeded at 485 (offset -29 lines). 2 out of 12 hunks FAILED -- saving rejects to file net/netfilter/nf_conntrack_proto.c.rej patching file net/netfilter/nfnetlink_cttimeout.c Could you rebase on top of nf-next git tree? Thanks a lot! ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1 v2] netfilter: constify nf_conntrack_l3/4proto parameters @ 2017-07-31 18:44 ` Pablo Neira Ayuso 0 siblings, 0 replies; 6+ messages in thread From: Pablo Neira Ayuso @ 2017-07-31 18:44 UTC (permalink / raw) To: Julia Lawall Cc: David S. Miller, bhumirks, kernel-janitors, Jozsef Kadlecsik, Florian Westphal, netfilter-devel, coreteam, netdev, linux-kernel Hi Julia, On Sun, Jul 30, 2017 at 09:38:44PM +0200, Julia Lawall wrote: > When a nf_conntrack_l3/4proto parameter is not on the left hand side > of an assignment, its address is not taken, and it is not passed to a > function that may modify its fields, then it can be declared as const. > > This change is useful from a documentation point of view, and can > possibly facilitate making some nf_conntrack_l3/4proto structures const > subsequently. > > Done with the help of Coccinelle. > > Some spacing adjusted to fit within 80 characters. patching file include/net/netfilter/nf_conntrack_l3proto.h Hunk #1 FAILED at 76. 1 out of 1 hunk FAILED -- saving rejects to file include/net/netfilter/nf_conntrack_l3proto.h.rej patching file include/net/netfilter/nf_conntrack_l4proto.h patching file include/net/netfilter/nf_conntrack_timeout.h patching file net/netfilter/nf_conntrack_core.c Hunk #1 succeeded at 1176 (offset -7 lines). Hunk #2 succeeded at 1288 (offset -7 lines). patching file net/netfilter/nf_conntrack_netlink.c patching file net/netfilter/nf_conntrack_proto.c Hunk #2 FAILED at 242. Hunk #3 FAILED at 271. Hunk #4 succeeded at 257 with fuzz 1 (offset -29 lines). Hunk #5 succeeded at 272 (offset -29 lines). Hunk #6 succeeded at 295 (offset -29 lines). Hunk #7 succeeded at 366 (offset -29 lines). Hunk #8 succeeded at 391 (offset -29 lines). Hunk #9 succeeded at 404 (offset -29 lines). Hunk #10 succeeded at 415 (offset -29 lines). Hunk #11 succeeded at 449 (offset -29 lines). Hunk #12 succeeded at 485 (offset -29 lines). 2 out of 12 hunks FAILED -- saving rejects to file net/netfilter/nf_conntrack_proto.c.rej patching file net/netfilter/nfnetlink_cttimeout.c Could you rebase on top of nf-next git tree? Thanks a lot! ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-07-31 18:44 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-07-30 19:38 [PATCH 0/1 v2] constify nf_conntrack_l3/4proto parameters Julia Lawall 2017-07-30 19:38 ` Julia Lawall 2017-07-30 19:38 ` [PATCH 1/1 v2] netfilter: " Julia Lawall 2017-07-30 19:38 ` Julia Lawall 2017-07-31 18:44 ` Pablo Neira Ayuso 2017-07-31 18:44 ` Pablo Neira Ayuso
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.