From ae7b11f726ecce35865163d2b90209a9a98d25d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Tue, 3 Aug 2010 18:59:06 +0000 Subject: [PATCH] handle ipv4-packets --- src/vpn/gnunet-daemon-vpn.c | 49 +++++++++++++++++++------------ src/vpn/gnunet-vpn-packet.h | 18 ++++++++---- src/vpn/gnunet-vpn-pretty-print.c | 10 ++++++- src/vpn/gnunet-vpn-pretty-print.h | 1 + 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 24f141cfc..983335a10 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -66,7 +66,7 @@ static void start_helper_and_schedule(struct vpn_cls* mycls) { mycls->helper_in = GNUNET_DISK_pipe(1); mycls->helper_out = GNUNET_DISK_pipe(1); - mycls->helper_pid = GNUNET_OS_start_process(mycls->helper_in, mycls->helper_out, "gnunet-vpn-helper", "gnunet-vpn-helper", NULL); + mycls->helper_pid = GNUNET_OS_start_process(mycls->helper_in, mycls->helper_out, "gnunet-helper-vpn", "gnunet-helper-vpn", NULL); mycls->fh_from_helper = GNUNET_DISK_pipe_handle (mycls->helper_out, GNUNET_DISK_PIPE_END_READ); @@ -112,23 +112,36 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts static void message_token(void *cls, void *client, const struct GNUNET_MessageHeader *message) { if (ntohs(message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) return; - struct ip6_pkt *pkt6 = (struct ip6_pkt*) message; - struct ip6_tcp *pkt6_tcp; - struct ip6_udp *pkt6_udp; - - pkt_printf(pkt6); - switch(pkt6->ip6_hdr.nxthdr) { - case 0x06: - pkt6_tcp = (struct ip6_tcp*)pkt6; - pkt_printf_ip6tcp(pkt6_tcp); - break; - case 0x11: - pkt6_udp = (struct ip6_udp*)pkt6; - pkt_printf_ip6udp(pkt6_udp); - if (ntohs(pkt6_udp->udp_hdr.dpt) == 53) { - pkt_printf_ip6dns((struct ip6_udp_dns*)pkt6_udp); - } - break; + struct tun_pkt *pkt_tun = (struct tun_pkt*) message; + + fprintf(stderr, "Packet, Type: %x\n", ntohs(pkt_tun->tun.type)); + + if (ntohs(pkt_tun->tun.type) == 0x86dd) { + struct ip6_pkt *pkt6 = (struct ip6_pkt*) message; + struct ip6_tcp *pkt6_tcp; + struct ip6_udp *pkt6_udp; + + pkt_printf(pkt6); + switch(pkt6->ip6_hdr.nxthdr) { + case 0x06: + pkt6_tcp = (struct ip6_tcp*)pkt6; + pkt_printf_ip6tcp(pkt6_tcp); + break; + case 0x11: + pkt6_udp = (struct ip6_udp*)pkt6; + pkt_printf_ip6udp(pkt6_udp); + if (ntohs(pkt6_udp->udp_hdr.dpt) == 53) { + pkt_printf_ip6dns((struct ip6_udp_dns*)pkt6_udp); + } + break; + } + } else if (ntohs(pkt_tun->tun.type) == 0x0800) { + struct ip_pkt *pkt = (struct ip_pkt*) message; + struct ip_udp *udp = (struct ip_udp*) message; + fprintf(stderr, "IPv4\n"); + if (pkt->ip_hdr.proto == 0x11 && ntohl(udp->ip_hdr.dadr) == 0x0a0a0a02 && ntohs(udp->udp_hdr.dpt) == 53 ) { + pkt_printf_ipdns((struct ip_udp_dns*)udp); + } } } diff --git a/src/vpn/gnunet-vpn-packet.h b/src/vpn/gnunet-vpn-packet.h index 7bda6ab84..71908d10c 100644 --- a/src/vpn/gnunet-vpn-packet.h +++ b/src/vpn/gnunet-vpn-packet.h @@ -100,7 +100,17 @@ struct dns_record { unsigned char* data; }; +struct udp_dns { + struct udp_pkt udp_hdr; + struct dns_pkt data; +}; + // Complete Packets +struct tun_pkt { + struct GNUNET_MessageHeader shdr; + struct pkt_tun tun; +}; + struct ip6_pkt { struct GNUNET_MessageHeader shdr; struct pkt_tun tun; @@ -128,8 +138,7 @@ struct ip6_udp_dns { struct GNUNET_MessageHeader shdr; struct pkt_tun tun; struct ip6_hdr ip6_hdr; - struct udp_pkt udp_hdr; - struct dns_pkt data; + struct udp_dns udp_dns; }; struct ip_pkt { @@ -146,12 +155,11 @@ struct ip_udp { struct udp_pkt udp_hdr; unsigned char data[1]; }; - struct ip_udp_dns { struct GNUNET_MessageHeader shdr; struct pkt_tun tun; struct ip_hdr ip_hdr; - struct udp_pkt udp_hdr; - struct dns_pkt data; + struct udp_dns udp_dns; }; + #endif diff --git a/src/vpn/gnunet-vpn-pretty-print.c b/src/vpn/gnunet-vpn-pretty-print.c index 81678d375..ea5936074 100644 --- a/src/vpn/gnunet-vpn-pretty-print.c +++ b/src/vpn/gnunet-vpn-pretty-print.c @@ -254,7 +254,7 @@ static char* dns_classes(short class) {{{ return 0; }}} -void pkt_printf_ip6dns(struct ip6_udp_dns* pkt) {{{ +void pkt_printf_dns(struct udp_dns* pkt) {{{ printf("DNS-Packet:\n"); printf("\tid: %d\n", ntohs(pkt->data.id)); printf("\t%d: %s\n", pkt->data.qr, pkt->data.qr == 0 ? "query" : "response"); @@ -292,3 +292,11 @@ void pkt_printf_ip6dns(struct ip6_udp_dns* pkt) {{{ printf("query for %s type=%d (%s) class=%d (%s)\n", queries[i]->name, ntohs(queries[i]->qtype), dns_types(ntohs(queries[i]->qtype)), ntohs(queries[i]->qclass), dns_classes(ntohs(queries[i]->qclass))); } }}} + +void pkt_printf_ip6dns(struct ip6_udp_dns* pkt) {{{ + pkt_printf_dns(&pkt->udp_dns); +}}} + +void pkt_printf_ipdns(struct ip_udp_dns* pkt) {{{ + pkt_printf_dns(&pkt->udp_dns); +}}} diff --git a/src/vpn/gnunet-vpn-pretty-print.h b/src/vpn/gnunet-vpn-pretty-print.h index 57b1825b4..8e5ff66c2 100644 --- a/src/vpn/gnunet-vpn-pretty-print.h +++ b/src/vpn/gnunet-vpn-pretty-print.h @@ -11,4 +11,5 @@ void pkt_printf_ip6tcp(struct ip6_tcp* pkt); void pkt_printf_ip6udp(struct ip6_udp* pkt); void pkt_printf_ip6dns(struct ip6_udp_dns* pkt); +void pkt_printf_ipdns(struct ip_udp_dns* pkt); #endif -- 2.25.1