static void pico_dns_client_retransmission(unsigned long now, void *arg)
{
  struct pico_dns_key *key = (struct pico_dns_key *)arg;
  struct pico_dns_ns *q_ns = NULL;

  if (!key->retrans) {
    dns_dbg("DNS: no retransmission!\n");
    pico_free(key->q_hdr);

    if(pico_tree_delete(&DNSTable,key))
      pico_free(key);
  }
  else if (key->retrans <= PICO_DNS_CLIENT_MAX_RETRANS) {
    key->retrans++;
    dns_dbg("DNS: retransmission! (%u attempts)\n", key->retrans);
        // ugly hack
    q_ns = pico_tree_next(pico_tree_findNode(&NSTable,&key->q_ns))->keyValue;
    if (q_ns)
      key->q_ns = *q_ns; 
    else
        key->q_ns = *((struct pico_dns_ns *)pico_tree_first(&NSTable));
    pico_dns_client_send(key);
    pico_timer_add(PICO_DNS_CLIENT_RETRANS, pico_dns_client_retransmission, key);
  } else {
    dns_dbg("DNS ERROR: no reply from nameservers! (%u attempts)\n", key->retrans);
    pico_socket_close(key->s);
    pico_err = PICO_ERR_EIO;
    key->callback(NULL, key->arg);
    pico_free(key->q_hdr);
    /* RB_REMOVE returns pointer to removed element, NULL to indicate error */

    if(pico_tree_delete(&DNSTable,key))
      pico_free(key);
  }
}
Beispiel #2
0
void pico_mock_destroy(struct pico_device *dev)
{
    struct mock_device search = {
        .dev = dev
    };
    struct mock_device*mock = pico_tree_findKey(&mock_device_tree, &search);
    struct mock_frame*nxt;

    if(!mock)
        return;

    nxt = mock->in_head;
    while(nxt != NULL) {
        mock->in_head = mock->in_head->next;
        PICO_FREE(nxt);
        nxt = mock->in_head;
    }
    nxt = mock->out_head;
    while(nxt != NULL) {
        mock->out_head = mock->out_head->next;
        PICO_FREE(nxt);
        nxt = mock->out_head;
    }
    pico_tree_delete(&mock_device_tree, mock);
}
int pico_dhcp_server_destroy(struct pico_device *dev)
{
    struct pico_dhcp_server_setting *found, test = { 0 };
    test.dev = dev;
    found = pico_tree_findKey(&DHCPSettings, &test);
    if (!found) {
        pico_err = PICO_ERR_ENOENT;
        return -1;
    }

    pico_tree_delete(&DHCPSettings, found);
    PICO_FREE(found);
    return 0;
}
Beispiel #4
0
int pico_ipv4_filter_del(uint32_t filter_id)
{
    struct filter_node *node = NULL;
    struct filter_node dummy = {
        .filter_id = filter_id
    };
    if((node = pico_tree_delete(&filter_tree, &dummy)) == NULL)
    {
        ipf_dbg("ipfilter> failed to delete filter :%d\n", filter_id);
        return -1;
    }

    PICO_FREE(node);
    return 0;
}
static void pico_fragments_empty_tree(struct pico_tree *tree)
{
    struct pico_tree_node *index, *tmp;

    if (!tree)
    {
        return;
    }

    pico_tree_foreach_safe(index, tree, tmp) {
        struct pico_frame * old = index->keyValue;
        pico_tree_delete(tree, old);
        pico_frame_discard(old);
    }

}
Beispiel #6
0
static int pico_dns_client_del_query(uint16_t id)
{
    struct pico_dns_query test = {
        0
    }, *found = NULL;

    test.id = id;
    found = pico_tree_findKey(&DNSTable, &test);
    if (!found)
        return -1;

    pico_free(found->query);
    pico_socket_close(found->s);
    pico_tree_delete(&DNSTable, found);
    pico_free(found);
    return 0;
}
Beispiel #7
0
static int pico_dhcp_client_del_cookie(uint32_t xid)
{
    struct pico_dhcp_client_cookie test = {
        0
    }, *found = NULL;

    test.xid = xid;
    found = pico_tree_findKey(&DHCPCookies, &test);
    if (!found)
        return -1;

    pico_socket_close(found->s);
    pico_ipv4_link_del(found->dev, found->address);
    pico_tree_delete(&DHCPCookies, found);
    pico_free(found);
    return 0;
}
Beispiel #8
0
static int pico_dns_client_del_ns(struct pico_ip4 *ns_addr)
{
    struct pico_dns_ns test = {{0}}, *found = NULL;

    test.ns = *ns_addr;
    found = pico_tree_findKey(&NSTable, &test);
    if (!found)
        return -1;

    pico_tree_delete(&NSTable, found);
    pico_free(found);

    /* no NS left, add default NS */
    if (pico_tree_empty(&NSTable))
        pico_dns_client_init();

    return 0;
}
Beispiel #9
0
static void ping_timeout(uint32_t now, void *arg)
{
  struct pico_icmp4_ping_cookie *cookie = (struct pico_icmp4_ping_cookie *)arg;
  IGNORE_PARAMETER(now);

  if(pico_tree_findKey(&Pings,cookie)){
    if (cookie->err == PICO_PING_ERR_PENDING) {
      struct pico_icmp4_stats stats;
      stats.dst = cookie->dst;
      stats.seq = cookie->seq;
      stats.time = 0;
      stats.size = cookie->size;
      stats.err = PICO_PING_ERR_TIMEOUT;
      dbg(" ---- Ping timeout!!!\n");
      cookie->cb(&stats);
    }

    pico_tree_delete(&Pings,cookie);
    pico_free(cookie);
  }
}
int pico_dns_client_nameserver(struct pico_ip4 *ns, uint8_t flag)
{
  struct pico_dns_ns test, *key = NULL;

  if (!ns) {
    pico_err = PICO_ERR_EINVAL;
    return -1;
  }

  switch (flag)
  {
    case PICO_DNS_NS_ADD:
      key = pico_zalloc(sizeof(struct pico_dns_ns));
      if (!key) {
        pico_err = PICO_ERR_ENOMEM;
        return -1;
      }
      key->ns = *ns;

      if(pico_tree_insert(&NSTable,key)){
        dns_dbg("DNS WARNING: nameserver %08X already added\n",ns->addr);
        pico_err = PICO_ERR_EINVAL;
        pico_free(key);
        return -1; /* Element key already exists */
      }
      dns_dbg("DNS: nameserver %08X added\n", ns->addr);
      /* If default NS found, remove it */
      pico_string_to_ipv4(PICO_DNS_NS_GOOGLE, &test.ns.addr);
      if (ns->addr != test.ns.addr) {

          key = pico_tree_findKey(&NSTable,&test);
        if (key) {
            if(pico_tree_delete(&NSTable,key)) {
            dns_dbg("DNS: default nameserver %08X removed\n", test.ns.addr);
            pico_free(key);
          } else {
            pico_err = PICO_ERR_EAGAIN;
            return -1;
          }
        }
      }
      break;

    case PICO_DNS_NS_DEL:
      test.ns = *ns;

      key = pico_tree_findKey(&NSTable,&test);
      if (!key) {
        dns_dbg("DNS WARNING: nameserver %08X not found\n", ns->addr);
        pico_err = PICO_ERR_EINVAL;
        return -1;
      }
      /* RB_REMOVE returns pointer to removed element, NULL to indicate error */

            if(pico_tree_delete(&NSTable,key)) {
        dns_dbg("DNS: nameserver %08X removed\n",key->ns.addr);
        pico_free(key);
      } else {
        pico_err = PICO_ERR_EAGAIN;
        return -1;
      }
      /* If no NS left, add default NS */
      if(pico_tree_first(&NSTable) == NULL){
        dns_dbg("DNS: add default nameserver\n");
        return pico_dns_client_init();
      }
      break;

    default:
      pico_err = PICO_ERR_EINVAL;
      return -1;
  }
  return 0;
}