From 4077ba3bd186016d46db0421e67b509cf9733024 Mon Sep 17 00:00:00 2001 From: Philipp Tölke Date: Wed, 26 Oct 2011 15:40:02 +0000 Subject: save at the tunnel whether this is an ipv4 or ipv6 connection --- src/vpn/gnunet-daemon-vpn-helper.c | 13 +++++++++++++ src/vpn/gnunet-daemon-vpn.c | 19 ++++++++++--------- src/vpn/gnunet-daemon-vpn.h | 6 ++++++ 3 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c index c3cc4bc91..a91a0591f 100644 --- a/src/vpn/gnunet-daemon-vpn-helper.c +++ b/src/vpn/gnunet-daemon-vpn-helper.c @@ -152,6 +152,15 @@ start_helper_and_schedule (void *cls, /*}}}*/ +void +initialize_tunnel_state(struct GNUNET_MESH_Tunnel* tunnel, int addrlen, struct GNUNET_MESH_TransmitHandle* th) +{ + struct tunnel_state* ts = GNUNET_malloc(sizeof *ts); + ts->addrlen = addrlen; + ts->th = th; + GNUNET_MESH_tunnel_set_data(tunnel, ts); +} + /** * Send an dns-answer-packet to the helper */ @@ -424,6 +433,7 @@ message_token (void *cls __attribute__ ((unused)), void *client send_pkt_to_peer, NULL, cls); me->tunnel = *cls; + initialize_tunnel_state(me->tunnel, 16, NULL); } else if (NULL != cls) { @@ -471,6 +481,7 @@ message_token (void *cls __attribute__ ((unused)), void *client send_pkt_to_peer, NULL, cls); me->tunnel = *cls; + initialize_tunnel_state(me->tunnel, 16, NULL); if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type) udp_tunnel = *cls; else if (GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY == app_type) @@ -627,6 +638,7 @@ message_token (void *cls __attribute__ ((unused)), void *client send_pkt_to_peer, NULL, cls); me->tunnel = *cls; + initialize_tunnel_state(me->tunnel, 4, NULL); } else if (NULL != cls) { @@ -670,6 +682,7 @@ message_token (void *cls __attribute__ ((unused)), void *client send_pkt_to_peer, NULL, cls); me->tunnel = *cls; + initialize_tunnel_state(me->tunnel, 4, NULL); } else if (NULL != cls) { diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index a6d051e9c..bd5938604 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -282,7 +282,8 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) { struct GNUNET_MESH_Tunnel **tunnel = cls; - GNUNET_MESH_tunnel_set_data (*tunnel, NULL); + struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); + ts->th = NULL; if (NULL != buf) { @@ -310,7 +311,7 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) GNUNET_MESH_tunnel_set_head (*tunnel, head); GNUNET_MESH_tunnel_set_tail (*tunnel, tail); - struct GNUNET_MESH_TransmitHandle *th = + ts->th = GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, @@ -322,7 +323,6 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) element->cls); /* save the handle */ - GNUNET_MESH_tunnel_set_data (*tunnel, th); GNUNET_free (element); } GNUNET_free (cls); @@ -355,9 +355,10 @@ send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_assert (NULL != tunnel); GNUNET_assert (NULL != *tunnel); - if (NULL == GNUNET_MESH_tunnel_get_data (*tunnel)) + struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); + if (NULL == ts->th) { - struct GNUNET_MESH_TransmitHandle *th = + ts->th = GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, @@ -368,8 +369,6 @@ send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, ntohs (hdr->size), send_pkt_to_peer_notify_callback, cls); - - GNUNET_MESH_tunnel_set_data (*tunnel, th); } else { @@ -882,8 +881,9 @@ receive_udp_back (void *cls struct remote_addr *s = (struct remote_addr *) desc; struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel); + struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(tunnel); - if (16 == s->addrlen) + if (16 == ts->addrlen) { size_t size = sizeof (struct ip6_udp) + ntohs (pkt->len) - 1 - @@ -1063,6 +1063,7 @@ receive_tcp_back (void *cls struct remote_addr *s = (struct remote_addr *) desc; struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel); + struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(tunnel); size_t pktlen = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - @@ -1071,7 +1072,7 @@ receive_tcp_back (void *cls GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet back, addrlen = %d\n", s->addrlen); if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK || - s->addrlen == 16) + ts->addrlen == 16) { size_t size = pktlen + sizeof (struct ip6_tcp) - 1; diff --git a/src/vpn/gnunet-daemon-vpn.h b/src/vpn/gnunet-daemon-vpn.h index 7d3b0e68a..641be914d 100644 --- a/src/vpn/gnunet-daemon-vpn.h +++ b/src/vpn/gnunet-daemon-vpn.h @@ -129,4 +129,10 @@ struct remote_addr char proto; }; +struct tunnel_state +{ + struct GNUNET_MESH_TransmitHandle *th; + int addrlen; +}; + #endif /* end of include guard: GNUNET-DAEMON-VPN_H */ -- cgit v1.2.3