|
NAMEng_patch —
trivial mbuf data modifying netgraph node type
SYNOPSIS#include <netgraph/ng_patch.h>
DESCRIPTIONThepatch node performs data modification of packets
passing through it. Modifications are restricted to a subset of C language
operations on unsigned integers of 8, 16, 32 or 64 bit size. These are: set to
new value (=), addition (+=), subtraction (-=), multiplication (*=), division
(/=), negation (= -), bitwise AND (&=), bitwise OR (|=), bitwise eXclusive
OR (^=), shift left (<<=), shift right (>>=). A negation operation
is the one exception: integer is treated as signed and second operand (the
value) is not used. If there is more than one
modification operation, they are applied to packets sequentially in the order
they were specified by the user. The data payload of a packet is viewed as an
array of bytes, with a zero offset corresponding to the very first byte of
packet headers, and the length bytes beginning from
offset as a single integer in network byte order. An
additional offset can be optionally requested at configuration time to account
for packet type.
HOOKSThis node type has two hooks:
CONTROL MESSAGESThis node type supports the generic control messages, plus the following:
SHUTDOWNThis node shuts down upon receipt of aNGM_SHUTDOWN
control message, or when all hooks have been disconnected.
EXAMPLESThisng_patch node was designed to modify TTL and
TOS/DSCP fields in IP packets. As an example, suppose you have two adjacent
simplex links to a remote network (e.g. satellite), so that the packets
expiring in between will generate unwanted ICMP-replies which have to go
forth, not back. Thus you need to raise TTL of every packet entering link by 2
to ensure the TTL will not reach zero there. To achieve this you can set an
ipfw(8)
rule to use the netgraph action to inject packets
which are going to the simplex link into the patch node, by using the
following
ngctl(8)
script:
/usr/sbin/ngctl -f- <<-SEQ mkpeer ipfw: patch 200 in name ipfw:200 ttl_add msg ttl_add: setconfig { count=1 csum_flags=1 ops=[ \ { mode=2 value=3 length=1 offset=8 } ] } SEQ /sbin/ipfw add 150 netgraph 200 ip from any to simplex.remote.net Here the “ Another example would be two consecutive modifications of packet
TOS field: say, you need to clear the
/usr/sbin/ngctl -f- <<-SEQ mkpeer ipfw: patch 300 in name ipfw:300 tos_chg msg tos_chg: setconfig { count=2 csum_flags=1 ops=[ \ { mode=7 value=0xf7 length=1 offset=1 } \ { mode=8 value=0x02 length=1 offset=1 } ] } SEQ /sbin/ipfw add 160 netgraph 300 ip from any to any not dst-port 80 This first does In both examples the csum_flags field indicates that IP checksum (but not TCP or UDP checksum) should be recalculated before transmit. Note: one should ensure that packets are returned to ipfw after processing inside netgraph(4), by setting appropriate sysctl(8) variable: sysctl net.inet.ip.fw.one_pass=0 SEE ALSOnetgraph(4), ng_ipfw(4), ngctl(8)HISTORYTheng_patch node type was implemented in
FreeBSD 8.1.
AUTHORSMaxim Ignatenko ⟨gelraen.ua@gmail.com⟩.Relative offset code by
This manual page was written by
BUGSThe node blindly tries to apply every patching operation to each packet (except those which offset if greater than length of the packet), so be sure that you supply only the right packets to it (e.g. changing bytes in the ARP packets meant to be in IP header could corrupt them and make your machine unreachable from the network).!!! WARNING !!! The output path of the IP stack assumes correct fields and lengths in the packets - changing them by to incorrect values can cause unpredictable results including kernel panics.
Visit the GSP FreeBSD Man Page Interface. |