+static gboolean cache_check_is_valid(struct cache_data *data,
+ time_t current_time)
+{
+ if (data == NULL)
+ return FALSE;
+
+ if (data->cache_until < current_time)
+ return FALSE;
+
+ return TRUE;
+}
+
+/*
+ * remove stale cached entries so that they can be refreshed
+ */
+static void cache_enforce_validity(struct cache_entry *entry)
+{
+ time_t current_time = time(NULL);
+
+ if (cache_check_is_valid(entry->ipv4, current_time) == FALSE
+ && entry->ipv4) {
+ DBG("cache timeout \"%s\" type A", entry->key);
+ g_free(entry->ipv4->data);
+ g_free(entry->ipv4);
+ entry->ipv4 = NULL;
+
+ }
+
+ if (cache_check_is_valid(entry->ipv6, current_time) == FALSE
+ && entry->ipv6) {
+ DBG("cache timeout \"%s\" type AAAA", entry->key);
+ g_free(entry->ipv6->data);
+ g_free(entry->ipv6);
+ entry->ipv6 = NULL;
+ }
+}
+
+static uint16_t cache_check_validity(char *question, uint16_t type,
+ struct cache_entry *entry)
+{
+ time_t current_time = time(NULL);
+ int want_refresh = 0;
+
+ /*
+ * if we have a popular entry, we want a refresh instead of
+ * total destruction of the entry.
+ */
+ if (entry->hits > 2)
+ want_refresh = 1;
+
+ cache_enforce_validity(entry);
+
+ switch (type) {
+ case 1: /* IPv4 */
+ if (cache_check_is_valid(entry->ipv4, current_time) == FALSE) {
+ DBG("cache %s \"%s\" type A", entry->ipv4 ?
+ "timeout" : "entry missing", question);
+
+ if (want_refresh)
+ entry->want_refresh = 1;
+
+ /*
+ * We do not remove cache entry if there is still
+ * valid IPv6 entry found in the cache.
+ */
+ if (cache_check_is_valid(entry->ipv6, current_time)
+ == FALSE && want_refresh == FALSE) {
+ g_hash_table_remove(cache, question);
+ type = 0;
+ }
+ }
+ break;
+
+ case 28: /* IPv6 */
+ if (cache_check_is_valid(entry->ipv6, current_time) == FALSE) {
+ DBG("cache %s \"%s\" type AAAA", entry->ipv6 ?
+ "timeout" : "entry missing", question);
+
+ if (want_refresh)
+ entry->want_refresh = 1;
+
+ if (cache_check_is_valid(entry->ipv4, current_time)
+ == FALSE && want_refresh == FALSE) {
+ g_hash_table_remove(cache, question);
+ type = 0;
+ }
+ }
+ break;
+ }
+
+ return type;
+}
+
+static struct cache_entry *cache_check(gpointer request, int *qtype)
+{
+ char *question = request + 12;
+ struct cache_entry *entry;
+ struct domain_question *q;
+ uint16_t type;
+ int offset;
+
+ offset = strlen(question) + 1;
+ q = (void *) (question + offset);
+ type = ntohs(q->type);
+
+ /* We only cache either A (1) or AAAA (28) requests */
+ if (type != 1 && type != 28)
+ return NULL;
+
+ entry = g_hash_table_lookup(cache, question);
+ if (entry == NULL)
+ return NULL;
+
+ type = cache_check_validity(question, type, entry);
+ if (type == 0)
+ return NULL;
+
+ *qtype = type;
+ return entry;
+}
+
+/*
+ * Get a label/name from DNS resource record. The function decompresses the
+ * label if necessary. The function does not convert the name to presentation
+ * form. This means that the result string will contain label lengths instead
+ * of dots between labels. We intentionally do not want to convert to dotted
+ * format so that we can cache the wire format string directly.
+ */
+static int get_name(int counter,
+ unsigned char *pkt, unsigned char *start, unsigned char *max,
+ unsigned char *output, int output_max, int *output_len,
+ unsigned char **end, char *name, int *name_len)
+{
+ unsigned char *p;
+
+ /* Limit recursion to 10 (this means up to 10 labels in domain name) */
+ if (counter > 10)
+ return -EINVAL;
+
+ p = start;
+ while (*p) {
+ if ((*p & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
+ uint16_t offset = (*p & 0x3F) * 256 + *(p + 1);
+
+ if (offset >= max - pkt)
+ return -ENOBUFS;
+
+ if (*end == NULL)
+ *end = p + 2;
+
+ return get_name(counter + 1, pkt, pkt + offset, max,
+ output, output_max, output_len, end,
+ name, name_len);
+ } else {
+ unsigned label_len = *p;
+
+ if (pkt + label_len > max)
+ return -ENOBUFS;
+
+ if (*output_len > output_max)
+ return -ENOBUFS;
+
+ /*
+ * We need the original name in order to check
+ * if this answer is the correct one.
+ */
+ name[(*name_len)++] = label_len;
+ memcpy(name + *name_len, p + 1, label_len + 1);
+ *name_len += label_len;
+
+ /* We compress the result */
+ output[0] = NS_CMPRSFLGS;
+ output[1] = 0x0C;
+ *output_len = 2;
+
+ p += label_len + 1;
+
+ if (*end == NULL)
+ *end = p;
+
+ if (p >= max)
+ return -ENOBUFS;
+ }
+ }
+
+ return 0;
+}
+
+static int parse_rr(unsigned char *buf, unsigned char *start,
+ unsigned char *max,
+ unsigned char *response, unsigned int *response_size,
+ uint16_t *type, uint16_t *class, int *ttl, int *rdlen,
+ unsigned char **end,
+ char *name)
+{
+ struct domain_rr *rr;
+ int err, offset;
+ int name_len = 0, output_len = 0, max_rsp = *response_size;
+
+ err = get_name(0, buf, start, max, response, max_rsp,
+ &output_len, end, name, &name_len);
+ if (err < 0)
+ return err;
+
+ offset = output_len;
+
+ if ((unsigned int) offset > *response_size)
+ return -ENOBUFS;
+
+ rr = (void *) (*end);
+
+ if (rr == NULL)
+ return -EINVAL;
+
+ *type = ntohs(rr->type);
+ *class = ntohs(rr->class);
+ *ttl = ntohl(rr->ttl);
+ *rdlen = ntohs(rr->rdlen);
+
+ if (*ttl < 0)
+ return -EINVAL;
+
+ memcpy(response + offset, *end, sizeof(struct domain_rr));
+
+ offset += sizeof(struct domain_rr);
+ *end += sizeof(struct domain_rr);
+
+ if ((unsigned int) (offset + *rdlen) > *response_size)
+ return -ENOBUFS;
+
+ memcpy(response + offset, *end, *rdlen);
+
+ *end += *rdlen;
+
+ *response_size = offset + *rdlen;
+
+ return 0;
+}
+
+static gboolean check_alias(GSList *aliases, char *name)
+{
+ GSList *list;
+
+ if (aliases != NULL) {
+ for (list = aliases; list; list = list->next) {
+ int len = strlen((char *)list->data);
+ if (strncmp((char *)list->data, name, len) == 0)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static int parse_response(unsigned char *buf, int buflen,
+ char *question, int qlen,
+ uint16_t *type, uint16_t *class, int *ttl,
+ unsigned char *response, unsigned int *response_len,
+ uint16_t *answers)
+{
+ struct domain_hdr *hdr = (void *) buf;
+ struct domain_question *q;
+ unsigned char *ptr;
+ uint16_t qdcount = ntohs(hdr->qdcount);
+ uint16_t ancount = ntohs(hdr->ancount);
+ int err, i;
+ uint16_t qtype, qclass;
+ unsigned char *next = NULL;
+ unsigned int maxlen = *response_len;
+ GSList *aliases = NULL, *list;
+ char name[NS_MAXDNAME + 1];
+
+ if (buflen < 12)
+ return -EINVAL;
+
+ DBG("qr %d qdcount %d", hdr->qr, qdcount);
+
+ /* We currently only cache responses where question count is 1 */
+ if (hdr->qr != 1 || qdcount != 1)
+ return -EINVAL;
+
+ ptr = buf + sizeof(struct domain_hdr);
+
+ strncpy(question, (char *) ptr, qlen);
+ qlen = strlen(question);
+ ptr += qlen + 1; /* skip \0 */
+
+ q = (void *) ptr;
+ qtype = ntohs(q->type);
+
+ /* We cache only A and AAAA records */
+ if (qtype != 1 && qtype != 28)
+ return -ENOMSG;
+
+ qclass = ntohs(q->class);
+
+ ptr += 2 + 2; /* ptr points now to answers */
+
+ err = -ENOMSG;
+ *response_len = 0;
+ *answers = 0;
+
+ /*
+ * We have a bunch of answers (like A, AAAA, CNAME etc) to
+ * A or AAAA question. We traverse the answers and parse the
+ * resource records. Only A and AAAA records are cached, all
+ * the other records in answers are skipped.
+ */
+ for (i = 0; i < ancount; i++) {
+ /*
+ * Get one address at a time to this buffer.
+ * The max size of the answer is
+ * 2 (pointer) + 2 (type) + 2 (class) +
+ * 4 (ttl) + 2 (rdlen) + addr (16 or 4) = 28
+ * for A or AAAA record.
+ * For CNAME the size can be bigger.
+ */
+ unsigned char rsp[NS_MAXCDNAME];
+ unsigned int rsp_len = sizeof(rsp) - 1;
+ int ret, rdlen;
+
+ memset(rsp, 0, sizeof(rsp));
+
+ ret = parse_rr(buf, ptr, buf + buflen, rsp, &rsp_len,
+ type, class, ttl, &rdlen, &next, name);
+ if (ret != 0) {
+ err = ret;
+ goto out;
+ }
+
+ /*
+ * Now rsp contains compressed or uncompressed resource
+ * record. Next we check if this record answers the question.
+ * The name var contains the uncompressed label.
+ * One tricky bit is the CNAME records as they alias
+ * the name we might be interested in.
+ */
+
+ /*
+ * Go to next answer if the class is not the one we are
+ * looking for.
+ */
+ if (*class != qclass) {
+ ptr = next;
+ next = NULL;
+ continue;
+ }
+
+ /*
+ * Try to resolve aliases also, type is CNAME(5).
+ * This is important as otherwise the aliased names would not
+ * be cached at all as the cache would not contain the aliased
+ * question.
+ *
+ * If any CNAME is found in DNS packet, then we cache the alias
+ * IP address instead of the question (as the server
+ * said that question has only an alias).
+ * This means in practice that if e.g., ipv6.google.com is
+ * queried, DNS server returns CNAME of that name which is
+ * ipv6.l.google.com. We then cache the address of the CNAME
+ * but return the question name to client. So the alias
+ * status of the name is not saved in cache and thus not
+ * returned to the client. We do not return DNS packets from
+ * cache to client saying that ipv6.google.com is an alias to
+ * ipv6.l.google.com but we return instead a DNS packet that
+ * says ipv6.google.com has address xxx which is in fact the
+ * address of ipv6.l.google.com. For caching purposes this
+ * should not cause any issues.
+ */
+ if (*type == 5 && strncmp(question, name, qlen) == 0) {
+ /*
+ * So now the alias answered the question. This is
+ * not very useful from caching point of view as
+ * the following A or AAAA records will not match the
+ * question. We need to find the real A/AAAA record
+ * of the alias and cache that.
+ */
+ unsigned char *end = NULL;
+ int name_len = 0, output_len;
+
+ memset(rsp, 0, sizeof(rsp));
+ rsp_len = sizeof(rsp) - 1;
+
+ /*
+ * Alias is in rdata part of the message,
+ * and next-rdlen points to it. So we need to get
+ * the real name of the alias.
+ */
+ ret = get_name(0, buf, next - rdlen, buf + buflen,
+ rsp, rsp_len, &output_len, &end,
+ name, &name_len);
+ if (ret != 0) {
+ /* just ignore the error at this point */
+ ptr = next;
+ next = NULL;
+ continue;
+ }
+
+ /*
+ * We should now have the alias of the entry we might
+ * want to cache. Just remember it for a while.
+ * We check the alias list when we have parsed the
+ * A or AAAA record.
+ */
+ aliases = g_slist_prepend(aliases, g_strdup(name));
+
+ ptr = next;
+ next = NULL;
+ continue;
+ }
+
+ if (*type == qtype) {
+ /*
+ * We found correct type (A or AAAA)
+ */
+ if (check_alias(aliases, name) == TRUE ||
+ (aliases == NULL && strncmp(question, name,
+ qlen) == 0)) {
+ /*
+ * We found an alias or the name of the rr
+ * matches the question. If so, we append
+ * the compressed label to the cache.
+ * The end result is a response buffer that
+ * will contain one or more cached and
+ * compressed resource records.
+ */
+ if (*response_len + rsp_len > maxlen) {
+ err = -ENOBUFS;
+ goto out;
+ }
+ memcpy(response + *response_len, rsp, rsp_len);
+ *response_len += rsp_len;
+ (*answers)++;
+ err = 0;
+ }
+ }
+
+ ptr = next;
+ next = NULL;
+ }
+
+out:
+ for (list = aliases; list; list = list->next)
+ g_free(list->data);
+ g_slist_free(aliases);
+
+ return err;
+}
+
+struct cache_timeout {
+ time_t current_time;
+ int max_timeout;
+ int try_harder;
+};
+
+static gboolean cache_check_entry(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ struct cache_timeout *data = user_data;
+ struct cache_entry *entry = value;
+ int max_timeout;
+
+ /* Scale the number of hits by half as part of cache aging */
+
+ entry->hits /= 2;
+
+ /*
+ * If either IPv4 or IPv6 cached entry has expired, we
+ * remove both from the cache.
+ */
+
+ if (entry->ipv4 != NULL && entry->ipv4->timeout > 0) {
+ max_timeout = entry->ipv4->cache_until;
+ if (max_timeout > data->max_timeout)
+ data->max_timeout = max_timeout;
+
+ if (entry->ipv4->cache_until < data->current_time)
+ return TRUE;
+ }
+
+ if (entry->ipv6 != NULL && entry->ipv6->timeout > 0) {
+ max_timeout = entry->ipv6->cache_until;
+ if (max_timeout > data->max_timeout)
+ data->max_timeout = max_timeout;
+
+ if (entry->ipv6->cache_until < data->current_time)
+ return TRUE;
+ }
+
+ /*
+ * if we're asked to try harder, also remove entries that have
+ * few hits
+ */
+ if (data->try_harder && entry->hits < 4)
+ return TRUE;
+
+ return FALSE;
+}
+
+static void cache_cleanup(void)
+{
+ static int max_timeout;
+ struct cache_timeout data;
+ int count = 0;
+
+ data.current_time = time(NULL);
+ data.max_timeout = 0;
+ data.try_harder = 0;
+
+ /*
+ * In the first pass, we only remove entries that have timed out.
+ * We use a cache of the first time to expire to do this only
+ * when it makes sense.
+ */
+ if (max_timeout <= data.current_time) {
+ count = g_hash_table_foreach_remove(cache, cache_check_entry,
+ &data);
+ }
+ DBG("removed %d in the first pass", count);
+
+ /*
+ * In the second pass, if the first pass turned up blank,
+ * we also expire entries with a low hit count,
+ * while aging the hit count at the same time.
+ */
+ data.try_harder = 1;
+ if (count == 0)
+ count = g_hash_table_foreach_remove(cache, cache_check_entry,
+ &data);
+
+ if (count == 0)
+ /*
+ * If we could not remove anything, then remember
+ * what is the max timeout and do nothing if we
+ * have not yet reached it. This will prevent
+ * constant traversal of the cache if it is full.
+ */
+ max_timeout = data.max_timeout;
+ else
+ max_timeout = 0;
+}
+
+static gboolean cache_invalidate_entry(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ struct cache_entry *entry = value;
+
+ /* first, delete any expired elements */
+ cache_enforce_validity(entry);
+
+ /* if anything is not expired, mark the entry for refresh */
+ if (entry->hits > 0 && (entry->ipv4 || entry->ipv6))
+ entry->want_refresh = 1;
+
+ /* delete the cached data */
+ if (entry->ipv4) {
+ g_free(entry->ipv4->data);
+ g_free(entry->ipv4);
+ entry->ipv4 = NULL;
+ }
+
+ if (entry->ipv6) {
+ g_free(entry->ipv6->data);
+ g_free(entry->ipv6);
+ entry->ipv6 = NULL;
+ }
+
+ /* keep the entry if we want it refreshed, delete it otherwise */
+ if (entry->want_refresh)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+/*
+ * cache_invalidate is called from places where the DNS landscape
+ * has changed, say because connections are added or we entered a VPN.
+ * The logic is to wipe all cache data, but mark all non-expired
+ * parts of the cache for refresh rather than deleting the whole cache.
+ */
+static void cache_invalidate(void)
+{
+ DBG("Invalidating the DNS cache %p", cache);
+
+ if (cache == NULL)
+ return;
+
+ g_hash_table_foreach_remove(cache, cache_invalidate_entry, NULL);
+}
+
+static void cache_refresh_entry(struct cache_entry *entry)
+{
+
+ cache_enforce_validity(entry);
+
+ if (entry->hits > 2 && entry->ipv4 == NULL)
+ entry->want_refresh = 1;
+ if (entry->hits > 2 && entry->ipv6 == NULL)
+ entry->want_refresh = 1;
+
+ if (entry->want_refresh) {
+ char *c;
+ char dns_name[NS_MAXDNAME + 1];
+ entry->want_refresh = 0;
+
+ /* turn a DNS name into a hostname with dots */
+ strncpy(dns_name, entry->key, NS_MAXDNAME);
+ c = dns_name;
+ while (c && *c) {
+ int jump;
+ jump = *c;
+ *c = '.';
+ c += jump + 1;
+ }
+ DBG("Refreshing %s\n", dns_name);
+ /* then refresh the hostname */
+ refresh_dns_entry(entry, &dns_name[1]);
+ }
+}
+
+static void cache_refresh_iterator(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ struct cache_entry *entry = value;
+
+ cache_refresh_entry(entry);
+}
+
+static void cache_refresh(void)
+{
+ if (cache == NULL)
+ return;
+
+ g_hash_table_foreach(cache, cache_refresh_iterator, NULL);
+}
+
+static int reply_query_type(unsigned char *msg, int len)
+{
+ unsigned char *c;
+ uint16_t *w;
+ int l;
+ int type;
+
+ /* skip the header */
+ c = msg + sizeof(struct domain_hdr);
+ len -= sizeof(struct domain_hdr);
+
+ if (len < 0)
+ return 0;
+
+ /* now the query, which is a name and 2 16 bit words */
+ l = dns_name_length(c) + 1;
+ c += l;
+ w = (uint16_t *) c;
+ type = ntohs(*w);
+
+ return type;
+}
+
+static int cache_update(struct server_data *srv, unsigned char *msg,
+ unsigned int msg_len)
+{
+ int offset = protocol_offset(srv->protocol);
+ int err, qlen, ttl = 0;
+ uint16_t answers = 0, type = 0, class = 0;
+ struct domain_question *q;
+ struct cache_entry *entry;
+ struct cache_data *data;
+ char question[NS_MAXDNAME + 1];
+ unsigned char response[NS_MAXDNAME + 1];
+ unsigned char *ptr;
+ unsigned int rsplen;
+ gboolean new_entry = TRUE;
+ time_t current_time;
+
+ if (cache_size >= MAX_CACHE_SIZE) {
+ cache_cleanup();
+ if (cache_size >= MAX_CACHE_SIZE)
+ return 0;
+ }
+
+ current_time = time(NULL);
+
+ /* don't do a cache refresh more than twice a minute */
+ if (next_refresh < current_time) {
+ cache_refresh();
+ next_refresh = current_time + 30;
+ }
+
+
+ /* Continue only if response code is 0 (=ok) */
+ if (msg[3] & 0x0f)
+ return 0;
+
+ if (offset < 0)
+ return 0;
+
+ rsplen = sizeof(response) - 1;
+ question[sizeof(question) - 1] = '\0';
+
+ err = parse_response(msg + offset, msg_len - offset,
+ question, sizeof(question) - 1,
+ &type, &class, &ttl,
+ response, &rsplen, &answers);
+
+ /*
+ * special case: if we do a ipv6 lookup and get no result
+ * for a record that's already in our ipv4 cache.. we want
+ * to cache the negative response.
+ */
+ if ((err == -ENOMSG || err == -ENOBUFS) &&
+ reply_query_type(msg, msg_len) == 28) {
+ entry = g_hash_table_lookup(cache, question);
+ if (entry && entry->ipv4 && entry->ipv6 == NULL) {
+ data = g_try_new(struct cache_data, 1);
+ if (data == NULL)
+ return -ENOMEM;
+ data->inserted = entry->ipv4->inserted;
+ data->type = type;
+ data->answers = msg[5];
+ data->timeout = entry->ipv4->timeout;
+ data->data_len = msg_len;
+ data->data = ptr = g_malloc(msg_len);
+ data->valid_until = entry->ipv4->valid_until;
+ data->cache_until = entry->ipv4->cache_until;
+ memcpy(data->data, msg, msg_len);
+ entry->ipv6 = data;
+ /*
+ * we will get a "hit" when we serve the response
+ * out of the cache
+ */
+ entry->hits--;
+ if (entry->hits < 0)
+ entry->hits = 0;
+ return 0;
+ }
+ }
+
+ if (err < 0 || ttl == 0)
+ return 0;
+
+ qlen = strlen(question);
+
+ /*
+ * If the cache contains already data, check if the
+ * type of the cached data is the same and do not add
+ * to cache if data is already there.
+ * This is needed so that we can cache both A and AAAA
+ * records for the same name.
+ */
+ entry = g_hash_table_lookup(cache, question);
+ if (entry == NULL) {
+ entry = g_try_new(struct cache_entry, 1);
+ if (entry == NULL)
+ return -ENOMEM;
+
+ data = g_try_new(struct cache_data, 1);
+ if (data == NULL) {
+ g_free(entry);
+ return -ENOMEM;
+ }
+
+ entry->key = g_strdup(question);
+ entry->ipv4 = entry->ipv6 = NULL;
+ entry->want_refresh = 0;
+ entry->hits = 0;
+
+ if (type == 1)
+ entry->ipv4 = data;
+ else
+ entry->ipv6 = data;
+ } else {
+ if (type == 1 && entry->ipv4 != NULL)
+ return 0;
+
+ if (type == 28 && entry->ipv6 != NULL)
+ return 0;
+
+ data = g_try_new(struct cache_data, 1);
+ if (data == NULL)
+ return -ENOMEM;
+
+ if (type == 1)
+ entry->ipv4 = data;
+ else
+ entry->ipv6 = data;
+
+ /*
+ * compensate for the hit we'll get for serving
+ * the response out of the cache
+ */
+ entry->hits--;
+ if (entry->hits < 0)
+ entry->hits = 0;
+
+ new_entry = FALSE;
+ }
+
+ if (ttl < MIN_CACHE_TTL)
+ ttl = MIN_CACHE_TTL;
+
+ data->inserted = current_time;
+ data->type = type;
+ data->answers = answers;
+ data->timeout = ttl;
+ data->data_len = 12 + qlen + 1 + 2 + 2 + rsplen;
+ data->data = ptr = g_malloc(data->data_len);
+ data->valid_until = current_time + ttl;
+
+ /*
+ * Restrict the cached DNS record TTL to some sane value
+ * in order to prevent data staying in the cache too long.
+ */
+ if (ttl > MAX_CACHE_TTL)
+ ttl = MAX_CACHE_TTL;
+
+ data->cache_until = round_down_ttl(current_time + ttl, ttl);
+
+ if (data->data == NULL) {
+ g_free(entry->key);
+ g_free(data);
+ g_free(entry);
+ return -ENOMEM;
+ }
+
+ memcpy(ptr, msg, 12);
+ memcpy(ptr + 12, question, qlen + 1); /* copy also the \0 */
+
+ q = (void *) (ptr + 12 + qlen + 1);
+ q->type = htons(type);
+ q->class = htons(class);
+ memcpy(ptr + 12 + qlen + 1 + sizeof(struct domain_question),
+ response, rsplen);
+
+ if (new_entry == TRUE) {
+ g_hash_table_replace(cache, entry->key, entry);
+ cache_size++;
+ }
+
+ DBG("cache %d %squestion \"%s\" type %d ttl %d size %zd",
+ cache_size, new_entry ? "new " : "old ",
+ question, type, ttl,
+ sizeof(*entry) + sizeof(*data) + data->data_len + qlen);
+
+ return 0;
+}
+