divert - kernel packet diversion mechanism
To enable support for divert sockets, place the following lines in the kernel configuration file:
options IPFIREWALL options IPDIVERT
Alternatively, to load as a module at boot time, add the following lines into the loader.conf5 file:
ipfw_load="YES" ipdivert_load="YES"
Divert sockets are normally used in conjunction with Fx Ns 's packet filtering implementation and the ipfw(8) program. By reading from and writing to a divert socket, matching packets can be passed through an arbitrary ``filter'' as they travel through the host machine, special routing tricks can be done, etc.
Diverted packets may be read unaltered via read(2), recv(2), or recvfrom(2). In the latter case, the address returned will have its port set to some tag supplied by the packet diverter, (usually the ipfw rule number) and the IP address set to the (first) address of the interface on which the packet was received (if the packet was incoming) or INADDR_ANY (if the packet was outgoing). The interface name (if defined for the packet) will be placed in the 8 bytes following the address, if it fits.
In the latter case, the IP address specified must match the address of some local interface, or an interface name must be found after the IP address. If an interface name is found, that interface will be used and the value of the IP address will be ignored (other than the fact that it is not INADDR_ANY ) This is to indicate on which interface the packet ``arrived''
Normally, packets read as incoming should be written as incoming; similarly for outgoing packets. When reading and then writing back packets, passing the same socket address supplied by recvfrom(2) unmodified to sendto(2) simplifies things (see below).
The port part of the socket address passed to the
sendto(2)
contains a tag that should be meaningful to the diversion module.
#include <the>
case of
ipfw(8)
the tag is interpreted as the rule number
after which
rule processing should restart.
Incoming packet fragments which get diverted are fully reassembled before delivery; the diversion of any one fragment causes the entire packet to get diverted. If different fragments divert to different ports, then which port ultimately gets chosen is unpredictable.
Note that packets arriving on the divert socket by the ipfw(8) tee action are delivered as-is and packet fragments do not get reassembled in this case.
Packets are received and sent unchanged, except that packets read as outgoing have invalid IP header checksums, and packets written as outgoing have their IP header checksums overwritten with the correct value. Packets written as incoming and having incorrect checksums will be dropped. Otherwise, all header fields are unchanged (and therefore in network order).
Binding to port numbers less than 1024 requires super-user access, as does creating a socket of type SOCK_RAW.
It is questionable whether incoming fragments should be reassembled before being diverted. For example, if only some fragments of a packet destined for another machine do not get routed through the local machine, the packet is lost. This should probably be a settable socket option in any case.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |