- }
-cp
- return 0;
-}
-
-/*
- accept a new tcp connect and create a
- new connection
-*/
-int handle_new_meta_connection(conn_list_t *cl)
-{
- conn_list_t *ncn;
- struct sockaddr client;
- int nfd, len = sizeof(struct sockaddr);
-cp
- if((nfd = accept(cl->meta_socket, &client, &len)) < 0)
- {
- syslog(LOG_ERR, "Accepting a new connection failed: %m");
- return -1;
- }
-
- if((ncn = create_new_connection(nfd)) == NULL)
- {
- shutdown(nfd, 2);
- close(nfd);
- syslog(LOG_NOTICE, "Closed attempted connection.");
- return 0;
- }
-
- ncn->status.meta = 1;
- ncn->next = conn_list;
- conn_list = ncn;
-cp
- return 0;
-}
-
-/*
- dispatch any incoming meta requests
-*/
-int handle_incoming_meta_data(conn_list_t *cl)
-{
- int x, l = sizeof(x), lenin;
- unsigned char tmp[1600];
- int request;
-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((lenin = recv(cl->meta_socket, &tmp, sizeof(tmp), 0)) <= 0)
- {
- syslog(LOG_ERR, "Receive failed: %m");
- return -1;
- }
-
- request = (int)(tmp[0]);
-
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, "got request %d", request);
-
- if(request_handlers[request] == NULL)
- syslog(LOG_ERR, "Unknown request %d.", request);
- else
- if(request_handlers[request](cl, tmp, lenin) < 0)
- return -1;
-cp
- return 0;
-}
-
-/*
- check all connections to see if anything
- happened on their sockets
-*/
-void check_network_activity(fd_set *f)
-{
- conn_list_t *p;
- int x, l = sizeof(x);
-cp
- for(p = conn_list; p != NULL; p = p->next)
- {
- if(p->status.remove)
- continue;
-
- if(p->status.active)
- if(FD_ISSET(p->socket, f))
- {
- /*
- The only thing that can happen to get us here is apparently an
- error on this outgoing(!) UDP socket that isn't immediate (i.e.
- something that will not trigger an error directly on send()).
- I've once got here when it said `No route to host'.
- */
- getsockopt(p->socket, SOL_SOCKET, SO_ERROR, &x, &l);
- syslog(LOG_ERR, "Outgoing data socket error: %s", sys_errlist[x]);
- terminate_connection(p);
- return;
- }
-
- if(p->status.meta)
- if(FD_ISSET(p->meta_socket, f))
- if(handle_incoming_meta_data(p) < 0)
- {
- terminate_connection(p);
- return;
- }
- }
-
- if(FD_ISSET(myself->socket, f))
- handle_incoming_vpn_data(myself);
-
- if(FD_ISSET(myself->meta_socket, f))
- handle_new_meta_connection(myself);
-cp