sys/netpfil/ipfw/ip_fw_sockopt.c
/**
 * Reset some or all counters on firewall rules.
 * The argument `arg' is an u_int32_t. The low 16 bit are the rule number,
 * the next 8 bits are the set number, the top 8 bits are the command:
 *	0	work with rules from all set's;
 *	1	work with rules only from specified set.
 * Specified rule number is zero if we want to clear all entries.
 * log_only is 1 if we only want to reset logs, zero otherwise.
 */
Reset some or all counters on firewall rules.
The argument `arg' is an u_int32_t. The low 16 bit are the rule number,
the next 8 bits are the set number, the top 8 bits are the command:
0       work with rules from all set's;
1       work with rules only from specified set.
Specified rule number is zero if we want to clear all entries.
log_only is 1 if we only want to reset logs, zero otherwise.
Reset some or all counters on firewall rules . The argument ` arg ' is an u_int32_t . The low 16 bit are the rule number the next 8 bits are the set number the top 8 bits are the command : 0 work with rules from all set ' s ; 1 work with rules only from specified set . Specified rule number is zero if we want to clear all entries . log_only is 1 if we only want to reset logs zero otherwise .
static int
zero_entry(struct ip_fw_chain *chain, u_int32_t arg, int log_only)
{
	struct ip_fw *rule;
	char *msg;
	int i;
	uint16_t rulenum = arg & 0xffff;
	uint8_t set = (arg >> 16) & 0xff;
	uint8_t cmd = (arg >> 24) & 0xff;
	if (cmd > 1)
		return (EINVAL);
	if (cmd == 1 && set > RESVD_SET)
		return (EINVAL);
	IPFW_UH_RLOCK(chain);
	if (rulenum == 0) {
		V_norule_counter = 0;
		for (i = 0; i < chain->n_rules; i++) {
			rule = chain->map[i];
			if (cmd == 1 && rule->set != set)
				continue;
			clear_counters(rule, log_only);
		}
		msg = log_only ? "All logging counts reset" :
		    "Accounting cleared";
	} else {
		int cleared = 0;
		for (i = 0; i < chain->n_rules; i++) {
			rule = chain->map[i];
			if (rule->rulenum == rulenum) {
				if (cmd == 0 || rule->set == set)
					clear_counters(rule, log_only);
				cleared = 1;
			}
			if (rule->rulenum > rulenum)
				break;
		}
		if (!cleared) {	
			IPFW_UH_RUNLOCK(chain);
			return (EINVAL);
		}
		msg = log_only ? "logging count reset" : "cleared";
	}
	IPFW_UH_RUNLOCK(chain);
	if (V_fw_verbose) {
		int lev = LOG_SECURITY | LOG_NOTICE;
		if (rulenum)
			log(lev, "ipfw: Entry %d %s.\n", rulenum, msg);
		else
			log(lev, "ipfw: %s.\n", msg);
	}
	return (0);
}
static int zero_entry ( struct ip_fw_chain * chain , u_int32_t arg , int log_only ) { struct ip_fw * rule ; char * msg ; int i ; uint16_t rulenum = arg & 0xffff ; uint8_t set = ( arg >> 16 ) & 0xff ; uint8_t cmd = ( arg >> 24 ) & 0xff ; if ( cmd > 1 ) return ( EINVAL ) ; if ( cmd == 1 && set > RESVD_SET ) return ( EINVAL ) ; IPFW_UH_RLOCK ( chain ) ; if ( rulenum == 0 ) { V_norule_counter = 0 ; for ( i = 0 ; i < chain -> n_rules ; i ++ ) { rule = chain -> map [ i ] ; if ( cmd == 1 && rule -> set != set ) continue ; clear_counters ( rule , log_only ) ; } msg = log_only ? " " : " " ; } else { int cleared = 0 ; for ( i = 0 ; i < chain -> n_rules ; i ++ ) { rule = chain -> map [ i ] ; if ( rule -> rulenum == rulenum ) { if ( cmd == 0 || rule -> set == set ) clear_counters ( rule , log_only ) ; cleared = 1 ; } if ( rule -> rulenum > rulenum ) break ; } if ( ! cleared ) { IPFW_UH_RUNLOCK ( chain ) ; return ( EINVAL ) ; } msg = log_only ? " " : " " ; } IPFW_UH_RUNLOCK ( chain ) ; if ( V_fw_verbose ) { int lev = LOG_SECURITY | LOG_NOTICE ; if ( rulenum ) log ( lev , " \n " , rulenum , msg ) ; else log ( lev , " \n " , msg ) ; } return ( 0 ) ; }
Reset some or all counters on firewall rules.
Reset some or all counters on firewall rules .
/* Skip rules not in our set. */ /* we did not find any matching rules */