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

vlan: add vlan.id keyword - v2 #12103

Closed
wants to merge 1 commit into from

Conversation

AkakiAlice
Copy link
Contributor

@AkakiAlice AkakiAlice commented Nov 7, 2024

Ticket: #1065

Make sure these boxes are checked accordingly before submitting your Pull Request -- thank you.

Contribution style:

Our Contribution agreements:

Changes (if applicable):

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

Describe changes:

  • Introduce vlan.id keyword

SV_BRANCH= OISF/suricata-verify#2134
Previous PR: #12070

#ifndef SURICATA_DETECT_VLAN_ID_H
#define SURICATA_DETECT_VLAN_ID_H

#define ANY 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think we want to export this

typedef struct DetectVlanIdData_ {
uint16_t id; /* id to match */
uint8_t layer; /* id layer to match */
} DetectVlanIdData;
Copy link
Contributor

Choose a reason for hiding this comment

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

This structure is only used in detect-vlan-id.c: it can live there

static void DetectVlanIdRegisterTests(void);
#endif

#define PARSE_REGEX "^([0-9]+)(?:,\\s*([0-9]|any))?$"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we do not want anymore parsing with regex, rust would be welcome

@@ -0,0 +1,21 @@
Vlan.id Keyword
==============
Copy link
Contributor

Choose a reason for hiding this comment

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

Miss a =


::

alert ip any any -> any any (msg:"Vlan ID is equal to 200"; vlan.id:200,any; sid:1;)
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading the doc, what is the difference between vlan.id:200,any; and vlan.id:200; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There’s no difference, both match any of the VLAN IDs. Should I keep them both?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep only vlan.id:200; and document it


const DetectVlanIdData *vdata = (const DetectVlanIdData *)ctx;
for (int i = 0; i < p->vlan_idx; i++) {
if (p->vlan_id[i] == vdata->id && (vdata->layer == ANY || vdata->layer - 1 == i))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to use generic integer support here, to support negation for instance.

}

const DetectVlanIdData *vdata = (const DetectVlanIdData *)ctx;
for (int i = 0; i < p->vlan_idx; i++) {
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 need the loop of vdata->layer != ANY

*/
static int DetectVlanIdParseTest03(void)
{
DetectVlanIdData *vdata = DetectVlanIdParse(NULL, "200,any");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we support 200,last ? or 200,-1 ?

@@ -0,0 +1,30 @@
/* Copyright (C) 2022 Open Information Security Foundation
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit 2024


Syntax::

vlan.id: id[,layer];
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the default behavior when we do not specify a layer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It behaves just like specifying 'any', it matches any of the VLAN IDs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then it's good to have that added to the docs :)

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.

Thanks for the nice work, I think we should get rid of PCRE here

@AkakiAlice AkakiAlice closed this Dec 2, 2024

Syntax::

vlan.id: id[,layer];
Copy link
Contributor

Choose a reason for hiding this comment

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

Then it's good to have that added to the docs :)

@@ -0,0 +1,276 @@
/* Copyright (C) 2022 Open Information Security Foundation
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: copyright year should be 2024

@AkakiAlice AkakiAlice mentioned this pull request Dec 12, 2024
5 tasks
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.

3 participants