Пример #1
0
/*
 * GeoIPRegion lookups are performed if the previous lookup was
 * from a different IP address than the current, or was for a search
 * outside the Region database.
 */
static GeoIPRegion *
region_lookup(GeoIP *db, dns_geoip_subtype_t subtype,
	      isc_uint32_t ipnum, isc_uint8_t *scope)
{
	GeoIPRegion *region = NULL;
	geoip_state_t *prev_state = NULL;
	GeoIPLookup gl;

	REQUIRE(db != NULL);

	prev_state = get_state_for(AF_INET, ipnum, NULL);
	if (prev_state != NULL && is_region(prev_state->subtype)) {
		region = prev_state->region;
		if (scope != NULL)
			*scope = prev_state->scope;
	}

	if (region == NULL) {
		region = GeoIP_region_by_ipnum_gl(db, ipnum, &gl);
		if (region == NULL)
			return (NULL);

		if (scope != NULL)
			*scope = gl.netmask;

		set_state(AF_INET, ipnum, NULL, gl.netmask,
			  subtype, NULL, region, NULL, NULL, 0);
	}

	return (region);
}
Пример #2
0
/*
 * GeoIPRegion lookups are performed if the previous lookup was
 * from a different IP address than the current, or was for a search
 * outside the Region database.
 */
static GeoIPRegion *
region_lookup(GeoIP *db, dns_geoip_subtype_t subtype, isc_uint32_t ipnum) {
	GeoIPRegion *region = NULL;
	geoip_state_t *prev_state = NULL;

	REQUIRE(db != NULL);

	prev_state = get_state_for(AF_INET, ipnum, NULL);
	if (prev_state != NULL && is_region(prev_state->subtype))
		region = prev_state->region;

	if (region == NULL) {
		region = GeoIP_region_by_ipnum(db, ipnum);
		if (region == NULL)
			return (NULL);

		set_state(AF_INET, ipnum, NULL,
			  subtype, NULL, region, NULL, NULL, 0);
	}

	return (region);
}