From 691b149091d9bb9b57bf4a82bb370de72fe96aeb Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 12 Feb 2012 11:16:39 +0000 Subject: [PATCH] -ICMPv6 has a different protocol number than ICMPv4, fix code accordingly --- src/exit/gnunet-daemon-exit.c | 21 +++++++++++++++------ src/vpn/gnunet-service-vpn.c | 15 +++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 19b465634..7cd207a50 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c @@ -395,7 +395,8 @@ get_redirect_state (int af, GNUNET_HashCode key; struct TunnelState *state; - if (protocol == IPPROTO_ICMP) + if ( ( (af == AF_INET) && (proto == IPPROTO_ICMP) ) || + ( (af == AF_INET6) && (proto == IPPROTO_ICMPV6) ) ) { /* ignore ports */ destination_port = 0; @@ -642,10 +643,10 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, existing session from the IP data in the ICMP payload */ source_port = 0; destination_port = 0; - protocol = IPPROTO_ICMP; switch (af) { case AF_INET: + protocol = IPPROTO_ICMP; switch (icmp->type) { case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: @@ -680,6 +681,7 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, } break; case AF_INET6: + protocol = IPPROTO_ICMPV6; switch (icmp->type) { case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: @@ -725,6 +727,12 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, destination_ip, 0, NULL); break; + case IPPROTO_ICMPV6: + state = get_redirect_state (af, IPPROTO_ICMPV6, + source_ip, 0, + destination_ip, 0, + NULL); + break; case IPPROTO_UDP: state = get_redirect_state (af, IPPROTO_UDP, source_ip, @@ -1060,7 +1068,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED, &pkt6->destination_address, &pkt6->source_address); break; - case IPPROTO_ICMP: + case IPPROTO_ICMPV6: icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt6[1], size, AF_INET6, &pkt6->destination_address, @@ -1100,7 +1108,8 @@ setup_fresh_address (int af, local_address->proto = (uint8_t) proto; /* default "local" port range is often 32768--61000, so we pick a random value in that range */ - if (proto == IPPROTO_ICMP) + if ( ( (af == AF_INET) && (proto == IPPROTO_ICMP) ) || + ( (af == AF_INET6) && (proto == IPPROTO_ICMPV6) ) ) local_address->port = 0; else local_address->port @@ -1871,7 +1880,7 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address, tun->proto = htons (ETH_P_IPV6); GNUNET_TUN_initialize_ipv6_header (ipv6, - IPPROTO_ICMP, + IPPROTO_ICMPV6, sizeof (struct GNUNET_TUN_IcmpHeader) + payload_length, &source_address->address.ipv6, &destination_address->address.ipv6); @@ -2078,7 +2087,7 @@ receive_icmp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, if (NULL == state->heap_node) { state->ri.remote_address.af = af; - state->ri.remote_address.proto = IPPROTO_ICMP; + state->ri.remote_address.proto = IPPROTO_ICMPV6; setup_state_record (state); } /* check that ICMP type is something we want to support diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index c8ffa8586..26deeee25 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c @@ -857,7 +857,7 @@ expire_tunnel (struct TunnelState *except) * * @param destination description of the destination * @param af address family on this end (AF_INET or AF_INET6) - * @param protocol IPPROTO_TCP or IPPROTO_UDP + * @param protocol IPPROTO_TCP or IPPROTO_UDP or IPPROTO_ICMP or IPPROTO_ICMPV6 * @param source_ip source IP used by the sender (struct in_addr or struct in6_addr) * @param destination_ip destination IP used by the sender (struct in_addr or struct in6_addr) * @param payload payload of the packet after the IP header @@ -936,8 +936,14 @@ route_packet (struct DestinationEntry *destination, &key); } break; - case IPPROTO_ICMP: + case IPPROTO_ICMP: + case IPPROTO_ICMPV6: { + if ( (AF_INET == af) ^ (protocol == IPPROTO_ICMP) ) + { + GNUNET_break (0); + return; + } if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader)) { /* blame kernel? */ @@ -948,7 +954,7 @@ route_packet (struct DestinationEntry *destination, source_port = 0; destination_port = 0; get_tunnel_key_from_ips (af, - IPPROTO_ICMP, + protocol, source_ip, 0, destination_ip, @@ -1238,6 +1244,7 @@ route_packet (struct DestinationEntry *destination, } break; case IPPROTO_ICMP: + case IPPROTO_ICMPV6: if (destination->is_service) { struct GNUNET_EXIT_IcmpServiceMessage *ism; @@ -1875,7 +1882,7 @@ receive_icmp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, tun->flags = htons (0); tun->proto = htons (ETH_P_IPV6); GNUNET_TUN_initialize_ipv6_header (ipv6, - IPPROTO_ICMP, + IPPROTO_ICMPV6, sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, &ts->destination_ip.v6, &ts->source_ip.v6); -- 2.25.1