-
Notifications
You must be signed in to change notification settings - Fork 26
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
contains operator #99
Changes from 41 commits
20fe19a
bef16a8
8df748b
4b7e21f
11781bd
5389bfb
173dee7
7c7890f
bb0050e
a0fe1c4
367b3af
ba08336
03748a1
9cca865
6618a6a
c827e69
4148289
c54628e
4e14510
df83183
b521cbf
85ba991
1fc287d
25ed1cb
87616f5
903bb37
5a60ea4
88e3f5e
321925d
9261eca
94d4255
94c05c2
318f257
d02ef53
8a2e9eb
f5ad411
694485d
82cf7c7
ad463fa
0a8b1a3
043df3d
54fc635
2fd2a17
3b7021e
b0ddc49
af22b63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,16 +141,17 @@ | |
//! | Byte | `|32 2E 30|` | | ||
//! | ||
//! ## Binary comparison operators | ||
//! | Operator | Alias | Description | Example | | ||
//! |----------|-----------|----------------------------|---------------------------------| | ||
//! | `=` | | Equals | `ipv4.addr = 127.0.0.1` | | ||
//! | `!=` | `ne` | Not equals | `udp.dst_port != 53` | | ||
//! | `>=` | `ge` | Greater than or equals | `tcp.port >= 1024` | | ||
//! | `<=` | `le` | Less than or equals | `tls.version <= 771` | | ||
//! | `>` | `gt` | Greater than | `ipv4.time_to_live > 64` | | ||
//! | `<` | `lt` | Less than | `ipv6.payload_length < 500` | | ||
//! | `in` | | In a range, or in a subnet | `ipv4.src_addr in 1.2.3.4/16` | | ||
//! | `~` | `matches` | Regular expression match | `tls.sni ~ 'netflix\\.com$'` | | ||
//! | Operator | Alias | Description | Example | | ||
//! |------------|-----------|--------------------------------|------------------------------------| | ||
//! | `=` | | Equals | `ipv4.addr = 127.0.0.1` | | ||
//! | `!=` | `ne` | Not equals | `udp.dst_port != 53` | | ||
//! | `>=` | `ge` | Greater than or equals | `tcp.port >= 1024` | | ||
//! | `<=` | `le` | Less than or equals | `tls.version <= 771` | | ||
//! | `>` | `gt` | Greater than | `ipv4.time_to_live > 64` | | ||
//! | `<` | `lt` | Less than | `ipv6.payload_length < 500` | | ||
//! | `in` | | In a range, or in a subnet | `ipv4.src_addr in 1.2.3.4/16` | | ||
//! | `~` | `matches` | Regular expression match | `tls.sni ~ 'netflix\\.com$'` | | ||
//! | `contains` | | Check if right appears in left | `tls.sni contains \|2E 63 6F 6D\|` | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the |
||
//! | ||
//! **Possible pitfalls involving `!=`** | ||
//! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,12 @@ pub(crate) fn binary_to_tokens( | |
// Regex::new(#val_lit).unwrap().is_match(#proto.#field()) | ||
// } | ||
} | ||
BinOp::Contains => { | ||
let val_lit = syn::LitStr::new(text, Span::call_site()); | ||
quote! { | ||
#proto.#field().contains(#val_lit) | ||
} | ||
} | ||
_ => panic!("Invalid binary operation `{}` for value: `{}`.", op, value), | ||
} | ||
} | ||
|
@@ -162,6 +168,13 @@ pub(crate) fn binary_to_tokens( | |
#proto.#field().as_bytes() == #bytes_lit | ||
} | ||
} | ||
BinOp::Contains => { | ||
let bytes_lit = syn::LitByteStr::new(b, Span::call_site()); | ||
let num_bytes = bytes_lit.value().len(); | ||
quote! { | ||
#proto.#field().as_bytes().windows(#num_bytes).any(|w| w == #bytes_lit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that we talked about this and I said
Could you do a bit of research into these and figure out which one makes the most sense? I don't know that we have to go into depth profiling them, but worth taking a look. |
||
} | ||
} | ||
_ => panic!("Invalid binary operation `{}` for value: `{}`.", op, value), | ||
}, | ||
} | ||
|
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.
Not a huge deal, but do you know what changed here to cause this diff? Seems like there shouldn't actually be a change here.