-/*
- dispatch any incoming meta requests
-*/
-int handle_incoming_meta_data(conn_list_t *cl)
-{
- int x, l = sizeof(x);
- unsigned char tmp[1600];
- int request;
- int lenin = 0;
-cp
- if(getsockopt(cl->meta_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
- {
- syslog(LOG_ERR, "This is a bug: %s:%d: %d:%m", __FILE__, __LINE__, cl->meta_socket);
- return -1;
- }
- if(x)
- {
- syslog(LOG_ERR, "Metadata socket error: %s", sys_errlist[x]);
- return -1;
- }
-
- if(read(cl->meta_socket, &tmp, 1) <= 0)
- {
- syslog(LOG_ERR, "Receive failed: %m");
- return -1;
- }
-
- request = (int)(tmp[0]);
-
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, "got request %d", request);
-
- /* This is a hack. After an ACK request, multiple ADD_HOSTs can
- follow. So if the request is one of these, only read as much
- bytes as necessary. (Luckily the ADD_HOST request is of fixed
- length) :P -- ivo */
-
- if(request != ACK)
- {
- if(request == ADD_HOST)
- {
- if((lenin = read(cl->meta_socket, &tmp[1], sizeof(add_host_t) - 1)) <= 0)
- {
- syslog(LOG_ERR, "Receive failed for ADD_HOST: %m");
- return -1;
- }
- }
- else
- {
- if((lenin = read(cl->meta_socket, &tmp[1], sizeof(tmp) - 1)) <= 0)
- {
- if(errno != EAGAIN) /* talk about hacks... */
- {
- syslog(LOG_ERR, "Receive failed: %m");
- return -1;
+ if((s2 = lookup_subnet(myself, subnet))) {
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "read subnet that already exists: %p expires %d\n", s2, (int)s2->expires);
+ if(s2->expires == 1)
+ s2->expires = 0;
+
+ free_subnet(subnet);
+ } else {
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "read new subnet %p", subnet);
+ subnet_add(myself, subnet);
+ send_add_subnet(everyone, subnet);
+ subnet_update(myself, subnet, true);
+ }
+
+ cfg = lookup_config_next(config_tree, cfg);
+ }
+
+ for(node = myself->subnet_tree->head; node; node = next) {
+ next = node->next;
+ subnet_t *subnet = node->data;
+ if(subnet->expires == 1) {
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "removed subnet %p", subnet);
+ send_del_subnet(everyone, subnet);
+ subnet_update(myself, subnet, false);
+ subnet_del(myself, subnet);
+ }