FreeBSD/sys/netpfil/ipfw/ip_fw_sockopt.c
/*
 * Copy the static and dynamic rules to the supplied buffer
 * and return the amount of space actually used.
 * Must be run under IPFW_UH_RLOCK
 */
Copy the static and dynamic rules to the supplied buffer
and return the amount of space actually used.
Must be run under IPFW_UH_RLOCK
Copy the static and dynamic rules to the supplied buffer and return the amount of space actually used . Must be run under IPFW_UH_RLOCK
static size_t
ipfw_getrules(struct ip_fw_chain *chain, void *buf, size_t space)
{
	char *bp = buf;
	char *ep = bp + space;
	struct ip_fw *rule;
	struct ip_fw_rule0 *dst;
	int error, i, l, warnflag;
	time_t	boot_seconds;
	warnflag = 0;
        boot_seconds = boottime.tv_sec;
	for (i = 0; i < chain->n_rules; i++) {
		rule = chain->map[i];
		if (is7) {
		    l = RULESIZE7(rule);
		    if (bp + l + sizeof(uint32_t) <= ep) {
			bcopy(rule, bp, l + sizeof(uint32_t));
			error = set_legacy_obj_kidx(chain,
			    (struct ip_fw_rule0 *)bp);
			if (error != 0)
				return (0);
			error = convert_rule_to_7((struct ip_fw_rule0 *) bp);
			if (error)
				return 0; 
			bcopy(&V_set_disable,
				&(((struct ip_fw7 *)bp)->next_rule),
				sizeof(V_set_disable));
			if (((struct ip_fw7 *)bp)->timestamp)
			    ((struct ip_fw7 *)bp)->timestamp += boot_seconds;
			bp += l;
		    }
		    continue; 
		}
		l = RULEUSIZE0(rule);
		if (bp + l > ep) { 
			printf("overflow dumping static rules\n");
			break;
		}
		dst = (struct ip_fw_rule0 *)bp;
		export_rule0(rule, dst, l);
		error = set_legacy_obj_kidx(chain, dst);
		bcopy(&V_set_disable, &dst->next_rule, sizeof(V_set_disable));
		if (dst->timestamp)
			dst->timestamp += boot_seconds;
		bp += l;
		if (error != 0) {
			if (error == 2) {
				warnflag = 1;
				continue;
			}
			printf("Stop on rule %d. Fail to convert table\n",
			    rule->rulenum);
			break;
		}
	}
	if (warnflag != 0)
		printf("ipfw: process %s is using legacy interfaces,"
		    " consider rebuilding\n", "");
	ipfw_get_dynamic(chain, &bp, ep); 
	return (bp - (char *)buf);
}
static size_t ipfw_getrules ( struct ip_fw_chain * chain , void * buf , size_t space ) { char * bp = buf ; char * ep = bp + space ; struct ip_fw * rule ; struct ip_fw_rule0 * dst ; int error , i , l , warnflag ; time_t boot_seconds ; warnflag = 0 ; boot_seconds = boottime . tv_sec ; for ( i = 0 ; i < chain -> n_rules ; i ++ ) { rule = chain -> map [ i ] ; if ( is7 ) { l = RULESIZE7 ( rule ) ; if ( bp + l + sizeof ( uint32_t ) <= ep ) { bcopy ( rule , bp , l + sizeof ( uint32_t ) ) ; error = set_legacy_obj_kidx ( chain , ( struct ip_fw_rule0 * ) bp ) ; if ( error != 0 ) return ( 0 ) ; error = convert_rule_to_7 ( ( struct ip_fw_rule0 * ) bp ) ; if ( error ) return 0 ; bcopy ( & V_set_disable , & ( ( ( struct ip_fw7 * ) bp ) -> next_rule ) , sizeof ( V_set_disable ) ) ; if ( ( ( struct ip_fw7 * ) bp ) -> timestamp ) ( ( struct ip_fw7 * ) bp ) -> timestamp += boot_seconds ; bp += l ; } continue ; } l = RULEUSIZE0 ( rule ) ; if ( bp + l > ep ) { printf ( " \n " ) ; break ; } dst = ( struct ip_fw_rule0 * ) bp ; export_rule0 ( rule , dst , l ) ; error = set_legacy_obj_kidx ( chain , dst ) ; bcopy ( & V_set_disable , & dst -> next_rule , sizeof ( V_set_disable ) ) ; if ( dst -> timestamp ) dst -> timestamp += boot_seconds ; bp += l ; if ( error != 0 ) { if ( error == 2 ) { warnflag = 1 ; continue ; } printf ( " \n " , rule -> rulenum ) ; break ; } } if ( warnflag != 0 ) printf ( " " " \n " , " " ) ; ipfw_get_dynamic ( chain , & bp , ep ) ; return ( bp - ( char * ) buf ) ; }
Copy the static and dynamic rules to the supplied buffer
 and return the amount of space actually used.
Copy the static and dynamic rules to the supplied buffer and return the amount of space actually used .
/* Convert rule to FreeBSd 7.2 format */ /*XXX correct? */ /*
			 * XXX HACK. Store the disable mask in the "next"
			 * pointer in a wild attempt to keep the ABI the same.
			 * Why do we do this on EVERY rule?
			 */ /* go to next rule */ /* should not happen */ /*
		 * XXX HACK. Store the disable mask in the "next"
		 * pointer in a wild attempt to keep the ABI the same.
		 * Why do we do this on EVERY rule?
		 *
		 * XXX: "ipfw set show" (ab)uses IP_FW_GET to read disabled mask
		 * so we need to fail _after_ saving at least one mask.
		 */ /* Non-fatal table rewrite error. */ /* protected by the dynamic lock */