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

Netmap 11 to 12 fix #3616

Closed
wants to merge 1 commit into from
Closed

Netmap 11 to 12 fix #3616

wants to merge 1 commit into from

Conversation

muratbalaban43
Copy link

@muratbalaban43 muratbalaban43 commented Jan 18, 2019

Although, there are no visible API changes, moving from API version
11 to 12, for every rx/tx ring that is being opened, one needs to
explicitly call NETMAP_IF to get the fresh address of the netmap_if
struct.

When the netmap-rework branch is done, it will also handle the
situation, but anyhow, this is a quick fix for 4.1.3 so that Suricata
can still happily run on FreeBSD 12 & 11 newcoming releases, since
they all come with the new netmap code.

Contributed by: Sunny Valley Networks

Attn: @inliniac

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

Link to redmine ticket:

Describe changes:

PRScript output (if applicable):

11 to 12, for every rx/tx ring that is being opened, one needs to
explicitly call NETMAP_IF to get the fresh address of the netmap_if
struct.

When the netmap-rework branch is done, it will also handle the
situation, but anyhow, this is a quick fix for 4.1.3 so that Suricata
can still happily run on FreeBSD 12 & 11 newcoming releases, since
they all come with the new netmap code.

Contributed by: Sunny Valley Networks

Attn: @inliniac
@muratbalaban43 muratbalaban43 requested a review from a team as a code owner January 18, 2019 07:06
@vmaffione
Copy link

Hi,
No fix should be necessary, just a recompilation.
As you say, there is no visible change for the legacy API (NIOCREGIF).
If this is not true, it may be that support for the legacy API has some bugs.
Could you please share a minimal configuration of suricata, so that I can try myself and see where the problem is?

@muratbalaban43
Copy link
Author

@vmaffione , here is the relavent netmap section. Suricata-netmap bridges igb0 hw <-> sw rings:

netmap:

  • interface: default
    threads: auto
    copy-mode: ips
    disable-promisc: yes # promiscuous mode
    checksum-checks: auto

  • interface: igb0
    copy-iface: igb0+

  • interface: igb0+
    copy-iface: igb0

@vmaffione
Copy link

Is this a complete configuration that I can just copy-paste and it should work?
I'm sorry, I've never used suricata before.

@muratbalaban43
Copy link
Author

@vmaffione , no worries. Attached. Make sure you rename it to suricata.yaml (github was not happy with .yaml extension).

suricata.yaml.txt

@vmaffione
Copy link

Thanks a lot, I will try asap.

@vmaffione
Copy link

Hi,
I tried to install suricata from these github sources, on FreeBSD 12.0-RELEASE, and without this patch.
I use the following commands to run suricata over an em interface:

sudo ifconfig em1 up -arp promisc -rxcsum -txcsum -rxcsum6 -txcsum6 -tso -tso4 -tso6 -lro -vlanmtu -vlanhwtag -vlanhwfilter -vlanhwtso
sudo suricata -c /etc/suricata/suricata.yaml --netmap=em1 -v

This is the netmap section of my suricata.yaml:

netmap:
  - interface: default
    threads: auto
    copy-mode: ips
    disable-promisc: yes #  promiscuous mode
    checksum-checks: auto

  - interface: em1
    copy-iface: em1+

  - interface: em1+
    copy-iface: em1

and I see packets being captured

[100078] 3/2/2019 -- 14:01:59 - (util-device.c:329) <Notice> (LiveDeviceListClean) -- Stats for 'em1':  pkts: 4892, drop: 0 (0.00%), invalid chksum: 0

So why is this patch needed?

@vmaffione
Copy link

(more information here https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=230465#c14)

@fichtner
Copy link

fichtner commented Feb 3, 2019

You're not using em1+ likely because you stuff --netmap=em1 from the command line

@vmaffione
Copy link

My bad, sorry. I'm not familiar with suricata.
The question is, though, what should I do to reproduce the issue?

@fichtner
Copy link

fichtner commented Feb 3, 2019

Give the yaml to suricata, do not mention interfaces on the command line. Run traffic through em1. It should block instead of flowing through when suricata is running (ping is enough to reproduce).

@muratbalaban43
Copy link
Author

@vmaffione , try adding --netmap (without interface name)

suricata -c suricata.yaml --netmap -s signatures.rules

@vmaffione
Copy link

Yes, indeed, thanks.
I'm able to reproduce the issue :)

@muratbalaban43
Copy link
Author

All welcome 👍

@vmaffione
Copy link

I see the problem now, and your patch is the right fix. In the original netmap implementation, you could only open all the RX/TX/host rings, so all or none.
This means that the struct netmap_if always had all the ring_ofs entries valid, e.g. pointing to all the TX, RX and host rings.
And suricata is written making this assumption.

However, with the introduction of the "partial opening" feature, that was not the case anymore.
If you open netmap:ix-3, for example, only the fourth TX ring and the fourth RX ring are reachable through the netmap_if. The others just point to a special invalid ring with all the slots pointing to a special invalid buffer, which means that you can't use those rings.
In other words, each NIOCREGIF registration allocates an independent instance of struct netmap_if, and thus if you separately open hw rings and sw rings you'll get two struct netmap_if, one with the valid hw rings, and the other with valid sw rings. That's why you need to use NETMAP_IF after each NIOCREGIF.

@vmaffione
Copy link

Btw this change of behavior happened way before switching from 11 to 12, so the latter control API change is not responsible for this issue (as the title suggests).

@victorjulien
Copy link
Member

@vmaffione thanks a lot for your feedback, appreciate it a lot that you've taken the time for this!

@muratbalaban43 can you submit a new PR with the suggested updates? Also the coding style was a bit off and the commit message needs to be cleaned up a bit.

Please see https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Github_work_flow#Create-a-new-branch-for-incorporating-feedback
and
https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Code_Submission_Quality_Criteria

Thanks!

@vmaffione
Copy link

@victorjulien no problems, I want suricata to work properly on netmap.

Btw, is there any particular reason why you open each netmap ring using a separate instance of /dev/netmap and a separate NIOCREGIF?
From what I can see from your code this is unnecessary, and you can use a single NIOCREGIF, which would make the code simpler (and also remove the issue btw). Maybe I'm missing something?
I could do the change, if you wish.

@vmaffione
Copy link

Of course you do that because you want to process each ring in a different thread.. please ignore my last message, and let's go for Murat's patch :)

@muratbalaban43
Copy link
Author

@vmaffione Thanks for the comments. @victorjulien , I'll be creating another request. Thank you for the pointers.

victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Buffers with transforms are based on the non-transformed "base"
buffer, with a new ID assigned and the transform callbacks added.

This patch stores the id of the original buffer in the new buffer
inspect and prefilter structures. This way the buffers with and
without transforms can share some of the logic are progression
of file and body inspection trackers.

Related tickets: OISF#4361 OISF#4199 OISF#3616
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the File API.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the HTTP inspection logic.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular http.request_body
along with transform combinations.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Buffers with transforms are based on the non-transformed "base"
buffer, with a new ID assigned and the transform callbacks added.

This patch stores the id of the original buffer in the new buffer
inspect and prefilter structures. This way the buffers with and
without transforms can share some of the logic are progression
of file and body inspection trackers.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit 975062c)
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the File API.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit 54ad7de)
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the HTTP inspection logic.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit ea3fb4a)
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular http.request_body
along with transform combinations.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit 4a1482a)
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Buffers with transforms are based on the non-transformed "base"
buffer, with a new ID assigned and the transform callbacks added.

This patch stores the id of the original buffer in the new buffer
inspect and prefilter structures. This way the buffers with and
without transforms can share some of the logic are progression
of file and body inspection trackers.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit 975062c)
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the File API.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit 54ad7de)
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the HTTP inspection logic.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit ea3fb4a)
victorjulien added a commit to victorjulien/suricata that referenced this pull request Feb 26, 2021
Fix handling of file progress tracking for regular http.request_body
along with transform combinations.

This is done by implementing the 'base id' logic.

Related tickets: OISF#4361 OISF#4199 OISF#3616

(cherry picked from commit 4a1482a)
jasonish pushed a commit that referenced this pull request Jun 30, 2021
Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the File API.

This is done by implementing the 'base id' logic.

Related tickets: #4361 #4199 #3616

(cherry picked from commit 54ad7de)
jasonish pushed a commit that referenced this pull request Jun 30, 2021
Buffers with transforms are based on the non-transformed "base"
buffer, with a new ID assigned and the transform callbacks added.

This patch stores the id of the original buffer in the new buffer
inspect and prefilter structures. This way the buffers with and
without transforms can share some of the logic are progression
of file and body inspection trackers.

Related tickets: #4361 #4199 #3616

(cherry picked from commit 975062c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants