Example #1
0
static void *
rsa_lookup_key_one(void *entry, void *data)
{
	int local_score, remote_score;
	struct lookup_result *req = data;
	struct rsa_key *key = entry;

	local_score = naddr_score(key->src, req->iph1->local);
	remote_score = naddr_score(key->dst, req->iph1->remote);

	plog(LLV_DEBUG, LOCATION, NULL, "Entry %s scored %d/%d\n",
		naddrwop2str_fromto("%s -> %s", key->src, key->dst),
		local_score, remote_score);

	if (local_score >= 0 && remote_score >= 0) {
		if (local_score + remote_score > req->max_score) {
			req->max_score = local_score + remote_score;
//			genlist_free(req->winners, NULL);
		}

		if (local_score + remote_score >= req->max_score) {
			genlist_append(req->winners, key);
		}
	}

	/* Always traverse the whole list */
	return NULL;
}
Example #2
0
genlist *
genlist_insert(genlist *list, void *data, int position)
{
    genlist *p;
    genlist *h = genlist_first(list);
    
    /* assume the length was checked by user.
       0 is prepend, length is append */
    while(position--)
    {
        h = h->next;
    }

    if(!h)
    {
        return genlist_append(list, data);
    }

    if(!h->prev)
    {
        return genlist_prepend(list, data);
    }
    
    p = genlist_alloc();
    p->data = data;

    p->prev = h->prev;
    p->next = h;

    h->prev->next = p;
    h->prev = p;

    return p;
}
Example #3
0
/************************************************************************
  Returns a new genlist that's a copy of the existing one.
************************************************************************/
struct genlist *genlist_copy(const struct genlist *pgenlist)
{
  struct genlist *pcopy = genlist_new();

  if (pgenlist) {
    struct genlist_link *plink;

    for (plink = pgenlist->head_link; plink; plink = plink->next) {
      genlist_append(pcopy, plink->dataptr);
    }
  }

  return pcopy;
}
Example #4
0
int
rsa_key_insert(struct genlist *list, struct netaddr *src,
	       struct netaddr *dst, RSA *rsa)
{
	struct rsa_key *rsa_key;

	rsa_key = calloc(sizeof(struct rsa_key), 1);
	rsa_key->rsa = rsa;

	if (src)
		rsa_key->src = src;
	else
		rsa_key->src = calloc(sizeof(*rsa_key->src), 1);

	if (dst)
		rsa_key->dst = dst;
	else
		rsa_key->dst = calloc(sizeof(*rsa_key->dst), 1);

	genlist_append(list, rsa_key);

	return 0;
}