Question

I'm trying to send an ICMPV6 echo request. Bellow my code:

        struct icmp6_hdr icmp6;
        int sock;
        struct icmp6_filter filterv6;
        struct ifreq ifr;

        sock = socket(AF_INET6, SOCK_RAW,IPPROTO_ICMPV6);

        ICMP6_FILTER_SETBLOCKALL(&filterv6);
        ICMP6_FILTER_SETPASS(ICMP6_DST_UNREACH, &filterv6);
        ICMP6_FILTER_SETPASS(ICMP6_PACKET_TOO_BIG, &filterv6);
        ICMP6_FILTER_SETPASS(ICMP6_TIME_EXCEEDED, &filterv6);
        ICMP6_FILTER_SETPASS(ICMP6_PARAM_PROB, &filterv6);  
        ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filterv6);
        ICMP6_FILTER_SETPASS(ND_REDIRECT, &filterv6);

        setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filterv6, sizeof (filterv6));
        ...
        setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr);
        ...

        icmp6.icmp6_type = ICMP6_ECHO_REQUEST;
        icmp6.icmp6_code = 0;
        icmp6.icmp6_cksum = 0;
        icmp6.icmp6_id = id;
        icmp6.icmp6_seq = 100;

       if( (sendto(sock, &icmp6, sizeof(struct icmp6_hdr), 0, (struct sockaddr *)dest, socklen)) != sizeof(struct icmp6_hdr))

However, for an unknown reason, the sent packet is an NDS:

[root@jingo ~]# tcpdump -v -i any  -s0 | grep icmp6
tcpdump: WARNING: Promiscuous mode not supported on the "any" device
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes

11:57:08.397368 IP6 (hlim 255, next-header: ICMPv6 (58), length: 32) 2001:db8:0:85a3::ac1f:8003 > ff02::1:ff1f:8009: [icmp6 sum ok] ICMP6, neighbor solicitation, length 32, who has 2001:db8:0:85a3::ac1f:8009
11:57:09.397331 IP6 (hlim 64, next-header: ICMPv6 (58), length: 112) 2001:db8:0:85a3::ac1f:8003 > 2001:db8:0:85a3::ac1f:8003: [icmp6 sum ok] ICMP6, destination unreachable, length 112, unreachable address 2001:db8:0:85a3::ac1f:8009

I'm using 2.6.18-308.el5PAE kernel , Red Hat Enterprise Linux Server release 5.1 (Tikanga).

Was it helpful?

Solution

This is normal behavior.

Since you can't send IP traffic until you have the correct MAC address to direct packets to, something has to find that MAC address. In IPv4, you would have seen an ARP packet. NDP (neighbor discovery protocol) replaced ARP in IPv6, which is why you're seeing NDP traffic.

The real problem here is that the destination host is not reachable. It may be down, or the router may not know how to reach it. Your router might be configured incorrectly, but that seems unlikely.

Try pinging a host that is up, and you will see the NDP traffic followed by your ICMP echo request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top