Skip to contentSkip to conversation

Constify option structures

PATCH In review Gargi Sharma 2 participants 6 messages Mar 27, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

cover Constify option structures

The struct option is generally used only to initialise fields inside certain structs and is not modified anywhere. Done using Coccinelle:

@r1 disable optional_qualifier@
identifier s,i;
position p;
@@

static struct option i@p[] ={...};

@ok1@
identifier r1.i;
expression e;
position p;
@@
e = i@p

@bad@
position p != {r1.p,ok1.p};
identifier r1.i;
@@
e@i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct option i[] = { ... };

Gargi Sharma (4):
extensions: libebt_limit: Constify option struct
extenstions: libebt_mark_m: Constify option struct
extensions: libebt_mark: Constify option struct
extensions: libebt_nflog: Constify option struct

 extensions/libebt_limit.c  | 2 +-
 extensions/libebt_mark.c   | 2 +-
 extensions/libebt_mark_m.c | 2 +-
 extensions/libebt_nflog.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 extensions: libebt_limit: Constify option struct

The struct brlimit_opts of the type option is only used to initialise a field inside the xtables_match struct and is not modified anywhere.

---
 extensions/libebt_limit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libebt_limit.c +1 -1
index 6b9bb16..988f678 100644
@@ -29,7 +29,7 @@
 #define ARG_LIMIT		'1'
 #define ARG_LIMIT_BURST		'2'
 
-static struct option brlimit_opts[] =
+static const struct option brlimit_opts[] =
 {
 	{ .name = "limit",	.has_arg = true,	.val = ARG_LIMIT },
 	{ .name = "limit-burst",.has_arg = true,	.val = ARG_LIMIT_BURST },
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/4 extenstions: libebt_mark_m: Constify option struct

In reply to Gargi Sharma

The struct brmark_m_opts of the type option is only used to initialise extra_opts field inside the xtables_match struct and is not modified anywhere.

---
 extensions/libebt_mark_m.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libebt_mark_m.c +1 -1
index ab9d234..eb08dba 100644
@@ -18,7 +18,7 @@
 
 #define MARK '1'
 
-static struct option brmark_m_opts[] = {
+static const struct option brmark_m_opts[] = {
 	{ .name = "mark",	.has_arg = true, .val = MARK },
 	XT_GETOPT_TABLEEND,
 };
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/4 extensions: libebt_mark: Constify option struct

In reply to Gargi Sharma

The struct brmark_opts of the type option is only used to initialise the extra_opts field in xtables_target struct and is no modified anywhere.

---
 extensions/libebt_mark.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libebt_mark.c +1 -1
index a1a208c..7b80b22 100644
@@ -25,7 +25,7 @@ static int mark_supplied;
 #define MARK_ORMARK  '3'
 #define MARK_ANDMARK '4'
 #define MARK_XORMARK '5'
-static struct option brmark_opts[] = {
+static const struct option brmark_opts[] = {
 	{ .name = "mark-target",.has_arg = true,	.val = MARK_TARGET },
 	/* an oldtime messup, we should have always used the scheme
 	 * <extension-name>-<option> */
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/4 extensions: libebt_nflog: Constify option struct

In reply to Gargi Sharma

The struct brnflog_opts of the type options is used to initialise extra_opts field inside the xtables_target struct and is not modified anywhere.

---
 extensions/libebt_nflog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libebt_nflog.c +1 -1
index fef7196..5f1d13b 100644
@@ -30,7 +30,7 @@ enum {
 	NFLOG_NFLOG	= 0x16,
 };
 
-static struct option brnflog_opts[] = {
+static const struct option brnflog_opts[] = {
 	{ .name = "nflog-group",     .has_arg = true,  .val = NFLOG_GROUP},
 	{ .name = "nflog-prefix",    .has_arg = true,  .val = NFLOG_PREFIX},
 	{ .name = "nflog-range",     .has_arg = true,  .val = NFLOG_RANGE},
Signature · 1 line
2.7.4
#5 lore raw
In reply to Gargi Sharma
Quoted 24 lines · Gargi Sharma

The struct option is generally used only to initialise fields inside certain structs and is not modified anywhere. Done using Coccinelle:

@r1 disable optional_qualifier@
identifier s,i;
position p;
@@

static struct option i@p[] ={...};

@ok1@
identifier r1.i;
expression e;
position p;
@@
e = i@p

@bad@
position p != {r1.p,ok1.p};
identifier r1.i;
@@
e@i@p

Quoted 6 lines

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct option i[] = { ... };

Please indicate what userspace tree in the subject, I guess this is iptables.

And merge them all into one single patch, they are part of the same logical change.

Thanks!