FreeBSD/sys/netpfil/ipfw/ip_fw_eaction.c
/*
 * Resets all eaction opcodes to default handlers.
 */
Resets all eaction opcodes to default handlers.
Resets all eaction opcodes to default handlers .
static void
reset_eaction_obj(struct ip_fw_chain *ch, uint16_t eaction_id)
{
	struct named_object *no;
	struct ip_fw *rule;
	ipfw_insn *cmd;
	int i;
	IPFW_UH_WLOCK_ASSERT(ch);
	no = ipfw_objhash_lookup_name_type(CHAIN_TO_SRV(ch), 0,
	    IPFW_TLV_EACTION, default_eaction_typename);
	if (no == NULL)
		panic("Default external action handler is not found");
	if (eaction_id == no->kidx)
		panic("Wrong eaction_id");
	EACTION_DEBUG("replace id %u with %u", eaction_id, no->kidx);
	IPFW_WLOCK(ch);
	for (i = 0; i < ch->n_rules; i++) {
		rule = ch->map[i];
		cmd = ACTION_PTR(rule);
		if (cmd->opcode != O_EXTERNAL_ACTION)
			continue;
		if (cmd->arg1 != eaction_id)
			continue;
		cmd->arg1 = no->kidx; 
		no->refcnt++;
		if (rule->act_ofs < rule->cmd_len - 1) {
			EACTION_DEBUG("truncate rule %d", rule->rulenum);
			rule->cmd_len--;
		}
	}
	IPFW_WUNLOCK(ch);
}
static void reset_eaction_obj ( struct ip_fw_chain * ch , uint16_t eaction_id ) { struct named_object * no ; struct ip_fw * rule ; ipfw_insn * cmd ; int i ; IPFW_UH_WLOCK_ASSERT ( ch ) ; no = ipfw_objhash_lookup_name_type ( CHAIN_TO_SRV ( ch ) , 0 , IPFW_TLV_EACTION , default_eaction_typename ) ; if ( no == NULL ) panic ( " " ) ; if ( eaction_id == no -> kidx ) panic ( " " ) ; EACTION_DEBUG ( " " , eaction_id , no -> kidx ) ; IPFW_WLOCK ( ch ) ; for ( i = 0 ; i < ch -> n_rules ; i ++ ) { rule = ch -> map [ i ] ; cmd = ACTION_PTR ( rule ) ; if ( cmd -> opcode != O_EXTERNAL_ACTION ) continue ; if ( cmd -> arg1 != eaction_id ) continue ; cmd -> arg1 = no -> kidx ; no -> refcnt ++ ; if ( rule -> act_ofs < rule -> cmd_len - 1 ) { EACTION_DEBUG ( " " , rule -> rulenum ) ; rule -> cmd_len -- ; } } IPFW_WUNLOCK ( ch ) ; }
Resets all eaction opcodes to default handlers.
Resets all eaction opcodes to default handlers .
/* Set to default id */ /*
		 * XXX: we only bump refcount on default_eaction.
		 * Refcount on the original object will be just
		 * ignored on destroy. But on default_eaction it
		 * will be decremented on rule deletion.
		 */ /*
		 * Since named_object related to this instance will be
		 * also destroyed, truncate the chain of opcodes to
		 * remove O_EXTERNAL_INSTANCE opcode.
		 */