Ejemplo n.º 1
0
int garden_patricia_rem(pass_through *pt, patricia_tree_t *ptree) {
  uint32_t mask;
  unsigned char count;
  prefix_t *prefix;
  patricia_node_t *pfx;
  struct in_addr sin;

  for (count = 0, mask = 0x80000000; mask != 0; mask >>= 1) {
    if (pt->mask.s_addr & mask)
      count++;
  }

  sin.s_addr = pt->host.s_addr;
  prefix = patricia_prefix_new (AF_INET, &sin, count);

  pfx = patricia_search_exact (ptree, prefix);
  if (pfx != NULL) {
    struct node_pass_through_list *
        nd = PATRICIA_DATA_GET(pfx, struct node_pass_through_list);

    if (nd != NULL) {
      int i;

      for (i=0; i < nd->ptcnt; i++) {
	if (pt_equal(&nd->ptlist[i], pt)) {
          if (_options.debug) {
            syslog(LOG_DEBUG, "(Patricia)Uamallowed removing #%d:%d: proto=%d host=%s port=%d",
                   i, nd->ptcnt, pt->proto, inet_ntoa(pt->host), pt->port);
            syslog(LOG_DEBUG, "Shifting uamallowed list %d to %d", i, nd->ptcnt);
          }

	  for (; i < nd->ptcnt-1; i++)
	    memcpy(&nd->ptlist[i], &nd->ptlist[i+1], sizeof(pass_through));

	  nd->ptcnt--;

	  if (nd->ptcnt > 0) {

	    nd = realloc(nd,
			 sizeof(struct node_pass_through_list)+
			 (sizeof(pass_through)*nd->ptcnt));

	    PATRICIA_DATA_SET(pfx, nd);

	  } else {
	    free(nd);
	    patricia_remove (ptree, pfx);
	  }

	  break;
	}
      }
    }
  }

  patricia_prefix_deref (prefix);
  return 0;
}
Ejemplo n.º 2
0
static banrecord_t *
ban_find(uint32_t ip)
{
	prefix_t *pfx;
	patricia_node_t *node;
	struct in_addr sin;

	sin.s_addr = ip;
	pfx = New_Prefix(AF_INET, &sin, 32);

	node = patricia_search_exact(banrecord_trie, pfx);

	Deref_Prefix(pfx);

	return node != NULL ? node->data : NULL;
}