struct GNUNET_SCHEDULER_Handle *sched;
struct GNUNET_CLIENT_Connection *dns_connection;
+ unsigned char restart_hijack;
pid_t helper_pid;
static struct vpn_cls mycls;
+size_t send_query(void* cls, size_t size, void* buf);
+
static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
PLIBC_KILL(mycls.helper_pid, SIGTERM);
PLIBC_KILL(mycls.helper_pid, SIGKILL);
GNUNET_OS_process_wait(mycls.helper_pid);
- // FIXME: send msg to service-dns -- the hijacker has to be started again, too, the routing table is flushed if it depends on one interface
+ /* Tell the dns-service to rehijack the dns-port
+ * The routing-table gets flushed if an interface disappears.
+ */
+ mycls.restart_hijack = 1;
+ GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL);
GNUNET_DISK_pipe_close(mycls.helper_in);
GNUNET_DISK_pipe_close(mycls.helper_out);
size_t send_query(void* cls, size_t size, void* buf)
{
+ size_t len;
+ if (mycls.restart_hijack == 1)
+ {
+ mycls.restart_hijack = 0;
+ GNUNET_assert(sizeof(struct GNUNET_MessageHeader) >= size);
+ struct GNUNET_MessageHeader* hdr = buf;
+ len = sizeof(struct GNUNET_MessageHeader);
+ hdr->size = htons(len);
+ hdr->type = htons(GNUNET_MESSAGE_TYPE_REHIJACK);
+ }
+ else
+ {
struct query_packet_list* query = mycls.head;
- size_t len = ntohs(query->pkt.hdr.size);
+ len = ntohs(query->pkt.hdr.size);
GNUNET_assert(len <= size);
GNUNET_CONTAINER_DLL_remove (mycls.head, mycls.tail, query);
GNUNET_free(query);
+ }
- if (mycls.head != NULL) {
+ if (mycls.head != NULL || mycls.restart_hijack == 1) {
GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, ntohs(mycls.head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL);
}
mycls.sched = sched;
mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL);
mycls.cfg = cfg;
+ mycls.restart_hijack = 0;
GNUNET_SCHEDULER_add_now (sched, &reconnect_to_service_dns, NULL);
GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
GNUNET_SCHEDULER_add_now (sched, start_helper_and_schedule, NULL);
GNUNET_DHT_get_stop(handle);
}
+/**
+ * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
+ */
+void rehijack(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) {
+ unhijack(mycls.dnsoutport);
+ hijack(mycls.dnsoutport);
+}
+
/**
* This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket
*/
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
/* callback, cls, type, size */
{&receive_query, NULL, GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS, 0},
+ {&rehijack, NULL, GNUNET_MESSAGE_TYPE_REHIJACK, sizeof(struct GNUNET_MessageHeader)},
{NULL, NULL, 0, 0}
};