Opened 9 months ago
#18810 new enhancement
support for sending raw link-layer packets
Reported by: | dovsienko | Owned by: | axeld |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | Network & Internet/Stack | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
As discussed on IRC yesterday and today. For certain types of networking software it is necessary to have full control over the protocol headers at a specific level. Haiku currently supports sending custom L3 (IPv4 or IPv6) packets, but not L2 (link-layer) packets. In particular, this makes it impossible to implement a packet injection function for Haiku in libpcap, so pcap_inject_haiku() in pcap-haiku.c is a stub function.
For clarity, the sendto() function Haiku implements takes only the destination as a sockaddr_dl and the payload. This does not match the problem space, which consists of the exact complete sequence of bytes to put on the wire, and of the exact interface to use. Ethernet is probably the most common use case, but it is important to note that the outgoing packet is link-level: if the interface is an L3 tunnel, a correct packet is supposed to be either IPv4 or IPv6, and it is a responsibility of the sending process to make the packet well-formed for the interface type.
Other OSes provide means for sending complete packets, for example, in Linux this is AF_PACKET. The exact way to specify the outgoing interface varies, I note existence of bind() and setsockopt(SO_BINDTODEVICE). Attached is a small test program that tries both of those on all permutations of {AF_LINK, AF_INET, AF_INET6} × {SOCK_RAW, SOCK_DGRAM} sockets and confirms none of these currently work, typically due to send() failing with EDESTADDRREQ.
It is difficult to advise which specific combination(s) of parameters and function calls would fit the existing network stack best (a new AF or a new socket type, or an equivalent of IP_HDRINCL for an existing AF/type combination), but it would be nice to have at least one that works.
the test program