FreeBSD/sys/netpfil/ipfw/ip_fw_table.c
/*
 * Switch between "set 0" and "rule's set" table binding,
 * Check all ruleset bindings and permits changing
 * IFF each binding has both rule AND table in default set (set 0).
 *
 * Returns 0 on success.
 */
Switch between "set 0" and "rule's set" table binding,
Check all ruleset bindings and permits changing
IFF each binding has both rule AND table in default set (set 0).

Returns 0 on success.
Switch between " set 0 " and " rule ' s set " table binding Check all ruleset bindings and permits changing IFF each binding has both rule AND table in default set ( set 0 ) . Returns 0 on success .
int
ipfw_switch_tables_namespace(struct ip_fw_chain *ch, unsigned int sets)
{
	struct opcode_obj_rewrite *rw;
	struct namedobj_instance *ni;
	struct named_object *no;
	struct ip_fw *rule;
	ipfw_insn *cmd;
	int cmdlen, i, l;
	uint16_t kidx;
	uint8_t subtype;
	IPFW_UH_WLOCK(ch);
	if (V_fw_tables_sets == sets) {
		IPFW_UH_WUNLOCK(ch);
		return (0);
	}
	ni = CHAIN_TO_NI(ch);
	if (sets == 0) {
		if (ipfw_objhash_foreach_type(ni, test_sets_cb,
		    NULL, IPFW_TLV_TBL_NAME) != 0) {
			IPFW_UH_WUNLOCK(ch);
			return (EBUSY);
		}
	}
	for (i = 0; i < ch->n_rules; i++) {
		rule = ch->map[i];
		l = rule->cmd_len;
		cmd = rule->cmd;
		cmdlen = 0;
		for ( ;	l > 0 ; l -= cmdlen, cmd += cmdlen) {
			cmdlen = F_LEN(cmd);
			for (kidx = 0, rw = opcodes;
			    rw < opcodes + nitems(opcodes); rw++) {
				if (rw->opcode != cmd->opcode)
					continue;
				if (rw->classifier(cmd, &kidx, &subtype) == 0)
					break;
			}
			if (kidx == 0)
				continue;
			no = ipfw_objhash_lookup_kidx(ni, kidx);
			if (no->set != 0 || rule->set != 0) {
				IPFW_UH_WUNLOCK(ch);
				return (EBUSY);
			}
		}
	}
	V_fw_tables_sets = sets;
	IPFW_UH_WUNLOCK(ch);
	return (0);
}
int ipfw_switch_tables_namespace ( struct ip_fw_chain * ch , unsigned int sets ) { struct opcode_obj_rewrite * rw ; struct namedobj_instance * ni ; struct named_object * no ; struct ip_fw * rule ; ipfw_insn * cmd ; int cmdlen , i , l ; uint16_t kidx ; uint8_t subtype ; IPFW_UH_WLOCK ( ch ) ; if ( V_fw_tables_sets == sets ) { IPFW_UH_WUNLOCK ( ch ) ; return ( 0 ) ; } ni = CHAIN_TO_NI ( ch ) ; if ( sets == 0 ) { if ( ipfw_objhash_foreach_type ( ni , test_sets_cb , NULL , IPFW_TLV_TBL_NAME ) != 0 ) { IPFW_UH_WUNLOCK ( ch ) ; return ( EBUSY ) ; } } for ( i = 0 ; i < ch -> n_rules ; i ++ ) { rule = ch -> map [ i ] ; l = rule -> cmd_len ; cmd = rule -> cmd ; cmdlen = 0 ; for ( ; l > 0 ; l -= cmdlen , cmd += cmdlen ) { cmdlen = F_LEN ( cmd ) ; for ( kidx = 0 , rw = opcodes ; rw < opcodes + nitems ( opcodes ) ; rw ++ ) { if ( rw -> opcode != cmd -> opcode ) continue ; if ( rw -> classifier ( cmd , & kidx , & subtype ) == 0 ) break ; } if ( kidx == 0 ) continue ; no = ipfw_objhash_lookup_kidx ( ni , kidx ) ; if ( no -> set != 0 || rule -> set != 0 ) { IPFW_UH_WUNLOCK ( ch ) ; return ( EBUSY ) ; } } } V_fw_tables_sets = sets ; IPFW_UH_WUNLOCK ( ch ) ; return ( 0 ) ; }
Switch between "set 0" and "rule's set" table binding,
 Check all ruleset bindings and permits changing
 IFF each binding has both rule AND table in default set (set 0).
Switch between " set 0 " and " rule ' s set " table binding Check all ruleset bindings and permits changing IFF each binding has both rule AND table in default set ( set 0 ) .
/*
		 * Prevent disabling sets support if we have some tables
		 * in not default sets.
		 */ /*
	 * Scan all rules and examine tables opcodes.
	 */ /* Check only tables opcodes */ /* Check if both table object and rule has the set 0 */