FreeBSD/sys/netpfil/ipfw/ip_fw_sockopt.c
/*
 * Dumps static rules with table TLVs in buffer @sd.
 *
 * Returns 0 on success.
 */
Dumps static rules with table TLVs in buffer @sd.
Returns 0 on success.
Dumps static rules with table TLVs in buffer @sd . Returns 0 on success .
static int
dump_static_rules(struct ip_fw_chain *chain, struct dump_args *da,
    uint32_t *bmask, struct sockopt_data *sd)
{
	int error;
	int i, l;
	uint32_t tcount;
	ipfw_obj_ctlv *ctlv;
	struct ip_fw *krule;
	struct namedobj_instance *ni;
	caddr_t dst;
	if (da->tcount > 0) {
		ctlv = (ipfw_obj_ctlv *)ipfw_get_sopt_space(sd, sizeof(*ctlv));
		if (ctlv == NULL)
			return (ENOMEM);
		ctlv->head.type = IPFW_TLV_TBLNAME_LIST;
		ctlv->head.length = da->tcount * sizeof(ipfw_obj_ntlv) + 
		    sizeof(*ctlv);
		ctlv->count = da->tcount;
		ctlv->objsize = sizeof(ipfw_obj_ntlv);
	}
	i = 0;
	tcount = da->tcount;
	ni = ipfw_get_table_objhash(chain);
	while (tcount > 0) {
		if ((bmask[i / 32] & (1 << (i % 32))) == 0) {
			i++;
			continue;
		}
		if (i >= IPFW_TABLES_MAX) {
			ni = CHAIN_TO_SRV(chain);
			i -= IPFW_TABLES_MAX;
			bmask += IPFW_TABLES_MAX / 32;
		}
		if ((error = export_objhash_ntlv(ni, i, sd)) != 0)
			return (error);
		i++;
		tcount--;
	}
	ctlv = (ipfw_obj_ctlv *)ipfw_get_sopt_space(sd, sizeof(*ctlv));
	if (ctlv == NULL)
		return (ENOMEM);
	ctlv->head.type = IPFW_TLV_RULE_LIST;
	ctlv->head.length = da->rsize + sizeof(*ctlv);
	ctlv->count = da->rcount;
	for (i = da->b; i < da->e; i++) {
		krule = chain->map[i];
		l = RULEUSIZE1(krule) + sizeof(ipfw_obj_tlv);
		if (da->rcounters != 0)
			l += sizeof(struct ip_fw_bcounter);
		dst = (caddr_t)ipfw_get_sopt_space(sd, l);
		if (dst == NULL)
			return (ENOMEM);
		export_rule1(krule, dst, l, da->rcounters);
	}
	return (0);
}
static int dump_static_rules ( struct ip_fw_chain * chain , struct dump_args * da , uint32_t * bmask , struct sockopt_data * sd ) { int error ; int i , l ; uint32_t tcount ; ipfw_obj_ctlv * ctlv ; struct ip_fw * krule ; struct namedobj_instance * ni ; caddr_t dst ; if ( da -> tcount > 0 ) { ctlv = ( ipfw_obj_ctlv * ) ipfw_get_sopt_space ( sd , sizeof ( * ctlv ) ) ; if ( ctlv == NULL ) return ( ENOMEM ) ; ctlv -> head . type = IPFW_TLV_TBLNAME_LIST ; ctlv -> head . length = da -> tcount * sizeof ( ipfw_obj_ntlv ) + sizeof ( * ctlv ) ; ctlv -> count = da -> tcount ; ctlv -> objsize = sizeof ( ipfw_obj_ntlv ) ; } i = 0 ; tcount = da -> tcount ; ni = ipfw_get_table_objhash ( chain ) ; while ( tcount > 0 ) { if ( ( bmask [ i / 32 ] & ( 1 << ( i % 32 ) ) ) == 0 ) { i ++ ; continue ; } if ( i >= IPFW_TABLES_MAX ) { ni = CHAIN_TO_SRV ( chain ) ; i -= IPFW_TABLES_MAX ; bmask += IPFW_TABLES_MAX / 32 ; } if ( ( error = export_objhash_ntlv ( ni , i , sd ) ) != 0 ) return ( error ) ; i ++ ; tcount -- ; } ctlv = ( ipfw_obj_ctlv * ) ipfw_get_sopt_space ( sd , sizeof ( * ctlv ) ) ; if ( ctlv == NULL ) return ( ENOMEM ) ; ctlv -> head . type = IPFW_TLV_RULE_LIST ; ctlv -> head . length = da -> rsize + sizeof ( * ctlv ) ; ctlv -> count = da -> rcount ; for ( i = da -> b ; i < da -> e ; i ++ ) { krule = chain -> map [ i ] ; l = RULEUSIZE1 ( krule ) + sizeof ( ipfw_obj_tlv ) ; if ( da -> rcounters != 0 ) l += sizeof ( struct ip_fw_bcounter ) ; dst = ( caddr_t ) ipfw_get_sopt_space ( sd , l ) ; if ( dst == NULL ) return ( ENOMEM ) ; export_rule1 ( krule , dst , l , da -> rcounters ) ; } return ( 0 ) ; }
Dumps static rules with table TLVs in buffer @sd.
Dumps static rules with table TLVs in buffer @sd .
/* Dump table names first (if any) */ /* Header first */ /* Jump to shared named object bitmask */ /* Dump rules */