FreeBSD/sys/netpfil/ipfw/ip_fw_sockopt.c
/*
 * Generic function to handler moving and swapping sets.
 */
Generic function to handler moving and swapping sets.
Generic function to handler moving and swapping sets .
int
ipfw_obj_manage_sets(struct namedobj_instance *ni, uint16_t type,
    uint16_t set, uint8_t new_set, enum ipfw_sets_cmd cmd)
{
	struct manage_sets_args args;
	struct named_object *no;
	args.set = set;
	args.new_set = new_set;
	switch (cmd) {
	case SWAP_ALL:
		return (ipfw_objhash_foreach_type(ni, swap_sets_cb,
		    &args, type));
	case TEST_ALL:
		return (ipfw_objhash_foreach_type(ni, test_sets_cb,
		    &args, type));
	case MOVE_ALL:
		return (ipfw_objhash_foreach_type(ni, move_sets_cb,
		    &args, type));
	case COUNT_ONE:
		no = ipfw_objhash_lookup_kidx(ni, set);
		if (new_set != 0)
			no->ocnt++;
		else
			no->ocnt = 0;
		return (0);
	case TEST_ONE:
		no = ipfw_objhash_lookup_kidx(ni, set);
		if (no->ocnt != no->refcnt)
			return (EBUSY);
		if (ipfw_objhash_lookup_name_type(ni, new_set, type,
		    no->name) != NULL)
			return (EEXIST);
		return (0);
	case MOVE_ONE:
		no = ipfw_objhash_lookup_kidx(ni, set);
		no->set = new_set;
		return (0);
	}
	return (EINVAL);
}
int ipfw_obj_manage_sets ( struct namedobj_instance * ni , uint16_t type , uint16_t set , uint8_t new_set , enum ipfw_sets_cmd cmd ) { struct manage_sets_args args ; struct named_object * no ; args . set = set ; args . new_set = new_set ; switch ( cmd ) { case SWAP_ALL : return ( ipfw_objhash_foreach_type ( ni , swap_sets_cb , & args , type ) ) ; case TEST_ALL : return ( ipfw_objhash_foreach_type ( ni , test_sets_cb , & args , type ) ) ; case MOVE_ALL : return ( ipfw_objhash_foreach_type ( ni , move_sets_cb , & args , type ) ) ; case COUNT_ONE : no = ipfw_objhash_lookup_kidx ( ni , set ) ; if ( new_set != 0 ) no -> ocnt ++ ; else no -> ocnt = 0 ; return ( 0 ) ; case TEST_ONE : no = ipfw_objhash_lookup_kidx ( ni , set ) ; if ( no -> ocnt != no -> refcnt ) return ( EBUSY ) ; if ( ipfw_objhash_lookup_name_type ( ni , new_set , type , no -> name ) != NULL ) return ( EEXIST ) ; return ( 0 ) ; case MOVE_ONE : no = ipfw_objhash_lookup_kidx ( ni , set ) ; no -> set = new_set ; return ( 0 ) ; } return ( EINVAL ) ; }
Generic function to handler moving and swapping sets.
Generic function to handler moving and swapping sets .
/*
		 * @set used to pass kidx.
		 * When @new_set is zero - reset object counter,
		 * otherwise increment it.
		 */ /* @set used to pass kidx */ /*
		 * First check number of references:
		 * when it differs, this mean other rules are holding
		 * reference to given object, so it is not possible to
		 * change its set. Note that refcnt may account references
		 * to some going-to-be-added rules. Since we don't know
		 * their numbers (and even if they will be added) it is
		 * perfectly OK to return error here.
		 */ /* @set used to pass kidx */