I'm trying to send IPv6 packets with scapy. I don't really care what higher-level protocol is used, so I simply send:
send(IPv6(dst="2001:db9:1::4"))
I have a route toward that destination, running ip -6 route show I see:
2001:db9:1::4 dev vt0 metric 1024
If I send a ping request from the command line, I can see it in tcpdump in the destination device. But if I send the IPv6 packet with scapy, I get these messages, and I don't see anything in tcpdump:
WARNING: No route found for IPv6 destination 2001:db9:1::4 (no default route?)
WARNING: No route found for IPv6 destination 2001:db9:1::4 (no default route?)
WARNING: more No route found for IPv6 destination 2001:db9:1::4 (no default route?)
.
Sent 1 packets.
But it works if I use the link-local address of the destination device. I only get one warning message (similar to the first line in the messages above), and I see the packet in tcpdump.
Any idea why this happens, and how can I fix it?
The sending interface needs to have a global IPv6 address.
Packets with a global destination address must have a global source address as well, otherwise the packet won't be forwarded.
Related
Recently I found that I was able to bind Apache on 127.0.0.73 without 127.0.0.73 to be present.
Only 127.0.0.1 is present as normal.
I also spoke with a friend and he said that is "normal" on Linux and probably on Windows and not works on MacOS, but he has no idea why.
I can do following:
[nmmm#zenbook nmmm]$ curl 127.10.0.123
curl: (7) Failed to connect to 127.10.0.123 port 80: Connection refused
and it shows that whole A class network is available.
How this works?
I do not see anything special in ifconfig and ip, except lo interface has no broadcast. Is that the key point?
According to https://en.wikipedia.org/wiki/Localhost
IPv4 network standards reserve the entire address block 127.0.0.0/8 (more than 16 million addresses) for loopback purposes.2 That means any packet sent to any of those addresses is looped back. The address 127.0.0.1 is the standard address for IPv4 loopback traffic; the rest are not supported by all operating systems. However they can be used to set up multiple server applications on the host, all listening on the same port number. The IPv6 standard assigns only a single address for loopback: ::1.
Or from https://www.rfc-editor.org/rfc/rfc3330
127.0.0.0/8 - This block is assigned for use as the Internet host
loopback address. A datagram sent by a higher level protocol to an
address anywhere within this block should loop back inside the host.
Even though you can't see anything from ifconfig or ip, you still can ping all the addresses in that 127.0.0.0/8 block.
I tried to receive broadcast packets on an interface that has no IPv4 address set.
The packets are visible via tcpdump. But the network stack seems to drop the packets before they can be received via a socket.
Is this possible without libpcap?
Which is the source IP address in tcp socket if bind is called on a multihomed client host? Client has two interfaces eth0(IP0) and eth1(IP1) and the client tcp socket is bound to IP0. After socket, bind, connect in client, it sends a packet to server.The destination IP isservIP. But servIP and IP0 are not in a same subnet(Maybe servIP and IP1 are). Which is the source IP in the packet sent to server? And what will getsockname return?
There are two separate issues here:
1) Which IP to bind on?
When calling bind() you have an option to specify and address to bind on or you can leave this decision to TCP/IP stack on your computer. You can pass a specific address in 'addr' parameter or leave it as INADDR_ANY. You can find more information how to do it in manual page of ip(7). If you call bind() providing the valid IP address and call to bind() succeeds, then datagrams sent using the binded socket will have their source address set to the value provided in call to bind().
2) How the packet is routed?
The way your packet is routed depend only on the destination address and not the source address. It can be that your source address will be the one from eth0 and it will go out through eht1. This is because the routing system in your OS is using destination based routing as opposed to source based routing. You can always see which adapter will be used by issuing "route" command in the console of your OS and comparing the output with the destination address
Working with Linux.
Given a specific destination IP address, I need to populate the ARP cache with its next hop MAC address and interface.
Other mechanism in my software project will take this MAC address and push it to an FPGA.
If I open a TCP connection to the address it will be resolved and TCP handshake packets are sent. If I open a UDP socket and 'connect' it to the address it will not be resolved. If I send a single packet over the connected UDP socket it is resolved.
arp(7) documentation explains this: "... Requests are sent only when there is data queued for sending".
I can't call the 'arp' utility directly.
My question: is there a way to convince the system to populate an address by sending ARP in the background without the need for actually sending a packet?
I hope for some ioctl or setsockopt.
I prefer a generic solution that will also work for IPv6 neighbor resolution.
Thanks,
Gur
I am learning datalink raw socket programming on Linux, and I found these helpful examples. I compiled the icmp4_ll.c, and used it to send an ICMP packet to anther computer in the same LAN. I can receive the reply from the destination computer. However, when I used it to send an ICMP packet to the local computer, that is, I set the source and destination Ethernet MAC and IP addresses to the MAC and IP address of eth0, I cannot receive the ICMP reply on either eth0 or lo interface (In Wireshark, I only noticed the ICMP request sent over eth0, but no ICMP reply on any interface.)
I think the ICMP request message is composed correctly, (otherwise the remote destination wont reply). But I don't know why the OS just doesn't reply the request. Any help or hints are appreciated.
RFC 792 defined special conditions for the ICMP messages:
No ICMP error messages are sent in response to ICMP error messages to avoid infinite repetition.
For fragmented IP datagrams, ICMP messages are only sent for errors on fragmented zero (the first fragment).
ICMP error messages are never sent in response to a datagram that is destined to a broadcast or a multicast address.
ICMP error messages are never sent in response to a datagram sent as a link layer broadcast.
ICMP error messages are never sent in response to a datagram whose source address does not represents a unique host (the source address
cannot be zero, a loopback address, a broadcast address or a multicast
address).
ICMP error messages are never sent in response to an IGMP message of any kind. When an ICMP message of unknown type is received, it must
be silently discarded.
Routers will almost always generate ICMP messages but when it comes to a destination host, the number of ICMP messages generated is implementation dependent.