Skip to content
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

detect: add vlan.id keyword - v6 #12301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AkakiAlice
Copy link
Contributor

@AkakiAlice AkakiAlice commented Dec 17, 2024

Ticket: #1065

Contribution style:

Our Contribution agreements:

Changes (if applicable):

Link to ticket: https://redmine.openinfosecfoundation.org/issues/1065

Description:

  • Introduce vlan.id keyword

Documentation changes:

  • Add tables describing values and limits for id and layer: line 20, line 29;
  • Add a signature example for count: line 77.

vlan_id.rs changes:

  • Remove #no_mangle from the constants definitions: line 22;
  • Change constants definitions to pub const: line 22;
  • Change constants names to use the prefix DETECT_VLAN_ID: line 22;
  • Implement Jason's suggestion to use .ok()?: line 35, line 54;
  • Add feature count: line 46;
  • Add if to check count range: line 55;
  • Replace i8::MAX and i8::MIN with DETECT_VLAN_ID_ALL and DETECT_VLAN_ID_ANY: line 45, line 52, line 103;
  • Add rust unit tests for all and count: line 106, line 117.

detect-vlan-id.c changes:

  • Include rust.h: line 21;
  • Replace if chain with switch-case: line 32.

Commit message:

  • Add description.

SV_BRANCH=OISF/suricata-verify#2194
Previous PR= #12290

vlan.id matches on Virtual Local Area Network IDs
It is an unsigned 16-bit integer
Valid range for the default configuration = [1-4094]
Supports prefiltering

Ticket: OISF#1065
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 82.29665% with 37 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@2c0d3b8). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #12301   +/-   ##
=========================================
  Coverage          ?   83.24%           
=========================================
  Files             ?      914           
  Lines             ?   257834           
  Branches          ?        0           
=========================================
  Hits              ?   214629           
  Misses            ?    43205           
  Partials          ?        0           
Flag Coverage Δ
fuzzcorpus 61.05% <8.84%> (?)
livemode 19.39% <8.84%> (?)
pcap 44.38% <8.84%> (?)
suricata-verify 62.87% <64.60%> (?)
unittests 59.19% <61.24%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@inashivb inashivb mentioned this pull request Dec 18, 2024
5 tasks
Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI : 🟢
Code : cool, just one nit
Commits segmentation : ok
Commit messages : nice
Git ID set : looks fine for me
CLA : you already contributed
Doc update : excellent
Redmine ticket : ok
Rustfmt : looks ok for vlan_id.rs
Tests : nice, thanks, added a remark there
Dependencies added: none


pub const DETECT_VLAN_ID_ANY: i8 = i8::MIN;
pub const DETECT_VLAN_ID_ALL: i8 = i8::MAX;
pub const DETECT_VLAN_ID_COUNT: i8 = 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to transfer src/decode-vlan.h:#define VLAN_MAX_LAYERS 3 here and use VLAN_MAX_LAYERS instead of hardcoded 3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defined VLAN_MAX_LAYERS in the vlan_id.rs file like this: pub const VLAN_MAX_LAYERS: i8 = 3;
but I get this error message:

decode.h:503:22: error: ‘VLAN_MAX_LAYERS’ undeclared here (not in a function)
503 |     uint16_t vlan_id[VLAN_MAX_LAYERS];

And when I include rust.h in the decode.h file, this first error goes away, but I get several error messages similar to this one:

util-file.h:214:39: error: unknown type name ‘Flow’
214 | void FileDisableStoringForTransaction(Flow *f, const uint8_t direction, void *tx, uint64_t tx_id);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to maintain 2 copies of the constant. One on the C side and the other one on the Rust side. The important thing is to avoid using magic numbers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not spend too much time on it if it gets too complex with include order.
Just do as Shivani said, and add some comments

assert!(detect_parse_vlan_id("200abc").is_none());
assert!(detect_parse_vlan_id("4096").is_none());
assert!(detect_parse_vlan_id("600,abc").is_none());
assert!(detect_parse_vlan_id("600,100").is_none());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test 1,2,3 errors ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5, count and also 123,-4 are error cases not tested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "test 1,2,3 errors" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass 1,2,3 as args to the fn detect_parse_vlan_id and see if that errors out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes assert!(detect_parse_vlan_id("1,2,3").is_none()); because parts.len() > 2

Copy link
Contributor

@jufajardini jufajardini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for highlighting so clearly the changes (and great job!) 👏🏽

I've shared complementary stuff on the comments :)


vlan.id:300 # exactly 300
vlan.id:<300,0 # smaller than 300 at layer 0
vlan.id:>=200,1 # greater or equal than 200 at layer 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (missed this the other review x_x ):

Suggested change
vlan.id:>=200,1 # greater or equal than 200 at layer 1
vlan.id:>=200,1 # greater than or equal to 200 at layer 1

The id can be matched exactly, or compared using the ``op`` setting::

vlan.id:300 # exactly 300
vlan.id:<300,0 # smaller than 300 at layer 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
vlan.id:<300,0 # smaller than 300 at layer 0
vlan.id:<300,0 # less than 300 at layer 0

Comment on lines +20 to +27
Id values for vlan.id keyword:

======== ================================================
Value Description
======== ================================================
1 - 4094 Valid range for vlan id
0 - 3 Valid range of number of layers (with ``count``)
======== ================================================
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the .. table:: Sphinx directive and have neat table titles, here and for the following one:

Suggested change
Id values for vlan.id keyword:
======== ================================================
Value Description
======== ================================================
1 - 4094 Valid range for vlan id
0 - 3 Valid range of number of layers (with ``count``)
======== ================================================
.. table:: **Id values for vlan.id keyword**
======== ================================================
Value Description
======== ================================================
1 - 4094 Valid range for vlan id
0 - 3 Valid range of number of layers (with ``count``)
======== ================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants