-
Notifications
You must be signed in to change notification settings - Fork 881
WIP/RFC: add support for manual link layer offset changes #1477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
WIP/RFC: add support for manual link layer offset changes #1477
Conversation
A few pcap-filter expressions implicitly change the link layer offset. There are other less common headers without their own keywords that might require skipping over some bytes in a link layer adjacent header to get to higher layer network headers. This commit adds an "offset" term that takes a + or - value to adjust the link layer offets in the same way VLAN does. This allows for something like `ethertype 0x8926 and offset +6 and vlan 14 and ip host 192.0.2.14` to skip over a vntag header, process a VLAN header, and look for an IPv4 host.
gencode.c
Outdated
@@ -10712,3 +10712,11 @@ gen_atmmulti_abbrev(compiler_state_t *cstate, int type) | |||
} | |||
return b1; | |||
} | |||
|
|||
struct block *gen_offset_adjustment(compiler_state_t *cstate, int n) { | |||
struct block *b = new_block(cstate, BPF_JMP|BPF_JA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't think of a better way of generating a "noop" block. I tried BPF_ALU|BPF_ADD|BPF_K
with a value of 0, but the optimizer turned it into an unimplemented operator with an operand of 0xffff.
This is an odd ball in pcap-filter syntax, since it doesn't "check" for anything; it's an "always true" term that controls parsing rather than checking anything. But without returning a block something like offset+6 and host 192.0.2.68
would never work, since and
assumes a block on both sides (as best I can tell). Returning NULL or nothing doesn't really work.
From the implementation perspective, it seems a better fit to use a C function that modifies the offsets and returns
...and so on. |
78b3154
to
1ce491a
Compare
For some reason I cannot reply directly to your previous comment, so adding this here: I think I mostly follow what you're suggesting here, although
|
1a4f736
to
a1a2abd
Compare
It is difficult to provide a more specific answer at this time, but it certainly looks like a worthwhile direction to research, at least to be able to state exactly how far the solution space would extend. This will likely take some time, so if you have a use case and a good solution for VN tag (see also #770), it may be better to consider that first. |
Some keywords, like VLAN and MPLS, implicitly adjust offsets. New protocols not yet handled by pcap-filter may also require offset jumping, but are not part of the existing known protocol code. Allowing arbitrary offset adjustments by users supports overcoming long standing "vlan X or vlan Y" issues, albeit with awkward syntax, and for jumping over new protocols not yet handled explicitly, like VNTag. This second attempt switches from adjusting compile time static offsets to using the variable arguments already baked into the offset structs to allow use with nvarg to generate either fixed or dynamically computed jumps. There is no support for "set to X"; all actions are increment or decrement. There is also no support at this time for selecting which offsets to adjust. That can be added once the basic concept is flushed out and there's some agreement on if this is a desired feature, syntax, and implementation approach. Initially my thoughts for a next commit to support selecting offset are something like `off-linkhdr` or `off-nl` or `off-linkpl` for each type of offset that might be reasonable for an end user to want to adjust themseleves.
a1a2abd
to
26233df
Compare
This is mostly a check to see if there's interest in this kind of feature, if the approach is sane, and what all might need added if this is a feature with interest. If there's a better process for this, please let me know! The contribution guidelines are a little sparse in this area.
A few pcap-filter expressions implicitly change the link layer offset. There are other less common headers without their own keywords that might require skipping over some bytes in a link layer adjacent header to get to higher layer network headers. This commit adds an "offset" term that takes a + or - value to adjust the link layer offets in the same way VLAN does. This allows for something like
ethertype 0x8926 and offset +6 and vlan 14 and ip host 192.0.2.14
to skip over a vntag header, process a VLAN header, and look for an IPv4 host.