Blame SOURCES/iptables-do_not_set_changed_for_check_options.patch

26b15f
commit 9b8cb7564a53865bf0e239bbc3e057de70edf65d
26b15f
Author: Dan Williams <dcbw@redhat.com>
26b15f
Date:   Sat Feb 25 22:02:03 2017 -0600
26b15f
26b15f
    libiptc: don't set_changed() when checking rules with module jumps
26b15f
    
26b15f
    Checking a rule that includes a jump to a module-based target currently
26b15f
    sets the "changed" flag on the handle, which then causes TC_COMMIT() to
26b15f
    run through the whole SO_SET_REPLACE/SO_SET_ADD_COUNTERS path.  This
26b15f
    seems wrong for simply checking rules, an operation which is documented
26b15f
    as "...does not alter the existing iptables configuration..." but yet
26b15f
    it clearly could do so.
26b15f
    
26b15f
    Fix that by ensuring that rule check operations for module targets
26b15f
    don't set the changed flag, and thus exit early from TC_COMMIT().
26b15f
    
26b15f
    Signed-off-by: Dan Williams <dcbw@redhat.com>
26b15f
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
26b15f
26b15f
diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
26b15f
index 2c66d04..a6e7057 100644
26b15f
--- a/libiptc/libiptc.c
26b15f
+++ b/libiptc/libiptc.c
26b15f
@@ -1686,7 +1686,8 @@ iptcc_standard_map(struct rule_head *r, int verdict)
26b15f
 
26b15f
 static int
26b15f
 iptcc_map_target(struct xtc_handle *const handle,
26b15f
-	   struct rule_head *r)
26b15f
+	   struct rule_head *r,
26b15f
+	   bool dry_run)
26b15f
 {
26b15f
 	STRUCT_ENTRY *e = r->entry;
26b15f
 	STRUCT_ENTRY_TARGET *t = GET_TARGET(e);
26b15f
@@ -1731,7 +1732,8 @@ iptcc_map_target(struct xtc_handle *const handle,
26b15f
 	       0,
26b15f
 	       FUNCTION_MAXNAMELEN - 1 - strlen(t->u.user.name));
26b15f
 	r->type = IPTCC_R_MODULE;
26b15f
-	set_changed(handle);
26b15f
+	if (!dry_run)
26b15f
+		set_changed(handle);
26b15f
 	return 1;
26b15f
 }
26b15f
 
26b15f
@@ -1781,7 +1783,7 @@ TC_INSERT_ENTRY(const IPT_CHAINLABEL chain,
26b15f
 	memcpy(r->entry, e, e->next_offset);
26b15f
 	r->counter_map.maptype = COUNTER_MAP_SET;
26b15f
 
26b15f
-	if (!iptcc_map_target(handle, r)) {
26b15f
+	if (!iptcc_map_target(handle, r, false)) {
26b15f
 		free(r);
26b15f
 		return 0;
26b15f
 	}
26b15f
@@ -1831,7 +1833,7 @@ TC_REPLACE_ENTRY(const IPT_CHAINLABEL chain,
26b15f
 	memcpy(r->entry, e, e->next_offset);
26b15f
 	r->counter_map.maptype = COUNTER_MAP_SET;
26b15f
 
26b15f
-	if (!iptcc_map_target(handle, r)) {
26b15f
+	if (!iptcc_map_target(handle, r, false)) {
26b15f
 		free(r);
26b15f
 		return 0;
26b15f
 	}
26b15f
@@ -1870,7 +1872,7 @@ TC_APPEND_ENTRY(const IPT_CHAINLABEL chain,
26b15f
 	memcpy(r->entry, e, e->next_offset);
26b15f
 	r->counter_map.maptype = COUNTER_MAP_SET;
26b15f
 
26b15f
-	if (!iptcc_map_target(handle, r)) {
26b15f
+	if (!iptcc_map_target(handle, r, false)) {
26b15f
 		DEBUGP("unable to map target of rule for chain `%s'\n", chain);
26b15f
 		free(r);
26b15f
 		return 0;
26b15f
@@ -1976,7 +1978,7 @@ static int delete_entry(const IPT_CHAINLABEL chain, const STRUCT_ENTRY *origfw,
26b15f
 
26b15f
 	memcpy(r->entry, origfw, origfw->next_offset);
26b15f
 	r->counter_map.maptype = COUNTER_MAP_NOMAP;
26b15f
-	if (!iptcc_map_target(handle, r)) {
26b15f
+	if (!iptcc_map_target(handle, r, dry_run)) {
26b15f
 		DEBUGP("unable to map target of rule for chain `%s'\n", chain);
26b15f
 		free(r);
26b15f
 		return 0;