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

bpfilter: add in "Quick Start" guide within the "Usage" page #177

Merged
merged 5 commits into from
Jan 1, 2025

Conversation

ryanbsull
Copy link
Contributor

No description provided.

@ryanbsull ryanbsull force-pushed the quick_start_docs branch 2 times, most recently from 6de6520 to b55f4b3 Compare December 15, 2024 23:43
Copy link

codecov bot commented Dec 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.93%. Comparing base (dfeea3d) to head (b55f4b3).
Report is 93 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #177      +/-   ##
==========================================
- Coverage   28.54%   26.93%   -1.61%     
==========================================
  Files          54       57       +3     
  Lines        4618     4900     +282     
==========================================
+ Hits         1318     1320       +2     
- Misses       3300     3580     +280     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

.. code-block:: bash

> cd path/to/bpfilter/
> sudo ./build/output/bpfilter -t -v debug --no-iptables
Copy link
Contributor

Choose a reason for hiding this comment

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

Use long options here, it's easier to understand for people learning about bpfilter.


.. code-block:: bash

> cd path/to/bpfilter/
Copy link
Contributor

Choose a reason for hiding this comment

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

path/to/bpfilter/ -> path/to/bpfilter/repo

.. note::
If you run into errors here there may be problems with your system worth diagnosing before continuing

Now let's try changing the filter from ``{192.168.1.1} ACCEPT`` to ``DENY``
Copy link
Contributor

Choose a reason for hiding this comment

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

DENY -> DROP

--- 192.168.1.1 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss

Congratulations you have now officially used ``bpfilter`` to systematically filter out your own packets. For documentation for more complex filtering options please check under the ``DEVELOPERS`` links and good luck!
Copy link
Contributor

Choose a reason for hiding this comment

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

"DEVELOPERS link`" -> "DEVELOPERS section"


sudo ./build/output/bfcli --str "chain BF_HOOK_NF_LOCAL_IN policy ACCEPT rule ip4.saddr in {192.168.1.1} DROP"

You should now observe a change in the behavior of ``ping``
Copy link
Contributor

Choose a reason for hiding this comment

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

"behavior of ping" -> "behavior of ping."

doc/usage/index.rst Show resolved Hide resolved
> cd path/to/bpfilter/
> sudo ./build/output/bfcli --str "chain BF_HOOK_NF_LOCAL_IN policy ACCEPT rule ip4.saddr in {192.168.1.1} ACCEPT"

The above program is just to make sure that ``bfcli`` is able to communicate with ``bpfilter``, when you run the commands you should see output from ``bpfilter`` registering that a filter has been loaded.
Copy link
Contributor

Choose a reason for hiding this comment

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

Detail what the command is doing: "The above command will...", also for a quick example, I would avoid using a set ({...}) and use a single address instead (ip4.saddr eq 192.168.1.1).

@ryanbsull
Copy link
Contributor Author

@qdeslandes let me know if the additions are acceptable or if more detail is needed


.. note::

This is only to be used as an example and a more interactive test to familiarize you with ``bpfilter``, more in-depth information can be found throughout the docs.
Copy link
Contributor

Choose a reason for hiding this comment

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

"throughout the docs" -> "throughout the documentation"


.. code-block:: bash

> cd path/to/bpfilter/repo/
Copy link
Contributor

Choose a reason for hiding this comment

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

This path should be the same for all the examples. It might be simpler to remove the cd command from the code blocks and mention something along the lines of "we assume the following commands are run from the bpfilter source directory".

> cd path/to/bpfilter/
> sudo ./build/output/bfcli --str "chain BF_HOOK_NF_LOCAL_IN policy ACCEPT rule ip4.saddr eq 192.168.1.1 ACCEPT"

The above command is just to make sure that ``bfcli`` is able to communicate with ``bpfilter``, but it's still worth working through it. This command is telling ``bpfilter`` to check incoming traffic from the ``BF_HOOK_NF_LOCAL_IN`` hook location and accept those connections. Then the command asks ``bpfilter`` to check to see if the incoming IP address is equal to ``192.168.1.1`` (yourself) and to accept the connection if that is true. When you run the commands you should see output from ``bpfilter`` registering that a filter has been loaded.
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is confusing and inaccurate:

  • "bpfilter to check incoming traffic": it sends a request to bpfilter to create a new filter. bpfilter itself doesn't process the traffic
  • "accept those connections": "connections" when it comes to packet filtering have a very specific meaning (e.g. TCP connection), bpfilter's programs works at the packet level
  • "asks bpfilter to check": bpfilter won't check anything but generate a program that does
  • "192.168.1.1 (yourself)": that is very specific to one's network.

I would prefer something simpler and more straightforward such as:

The command above will send a request to the bpfilter daemon to create a chain and attach it to the BF_HOOK_NF_LOCAL_IN hook, located after the packet has been routed in the kernel network stack. A single rule is defined, which will accept the packet if its source IPv4 address is 192.168.1.1. If the rule doesn't match the packet, the chain's policy is applied and the packet is accepted. In its current shape, the chain will always accept incoming packets.

Comment on lines +83 to +86
> ping 192.168.1.1
... [attempting to ping] ...
--- 192.168.1.1 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss
Copy link
Contributor

Choose a reason for hiding this comment

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

We define a rule to block a specific IP and the ping fails, but does this do what you expect it to do? The command above creates a filter for BF_HOOK_LOCAL_IN, i.e. an input hook, meaning packets coming to the local host with the source IP 192.168.1.1 are accepted. It won't block packets going out of the local host, but the answer coming back from 192.168.1.1.

--- 192.168.1.1 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss

Congratulations you have now officially used ``bpfilter`` to systematically filter out your own packets. For documentation for more complex filtering options please check under the ``DEVELOPERS`` section and good luck!
Copy link
Contributor

Choose a reason for hiding this comment

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

systematically filter out your own packets

We only filter packets coming from 192.168.1.1.

Copy link
Contributor

@qdeslandes qdeslandes left a comment

Choose a reason for hiding this comment

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

Almost there, one last nit. Also, please fix the command regarding the usage of the long options in the examples.

@@ -56,7 +59,7 @@ While the ``bpfilter`` daemon runs, now we will open up a separate window to use
> cd path/to/bpfilter/
> sudo ./build/output/bfcli --str "chain BF_HOOK_NF_LOCAL_IN policy ACCEPT rule ip4.saddr eq 192.168.1.1 ACCEPT"

The above command is just to make sure that ``bfcli`` is able to communicate with ``bpfilter``, but it's still worth working through it. This command is telling ``bpfilter`` to check incoming traffic from the ``BF_HOOK_NF_LOCAL_IN`` hook location and accept those connections. Then the command asks ``bpfilter`` to check to see if the incoming IP address is equal to ``192.168.1.1`` (yourself) and to accept the connection if that is true. When you run the commands you should see output from ``bpfilter`` registering that a filter has been loaded.
The command above will send a request to the bpfilter daemon to create a chain and attach it to the BF_HOOK_NF_LOCAL_IN hook, located after the packet has been routed in the kernel network stack. A single rule is defined, which will accept the packet if its source IPv4 address is 192.168.1.1. If the rule doesn't match the packet, the chain's policy is applied and the packet is accepted. In its current shape, the chain will always accept incoming packets.
Copy link
Contributor

Choose a reason for hiding this comment

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

Use double backticks around BF_HOOK_NF_LOCAL_IN and the IP address.

@qdeslandes qdeslandes self-requested a review December 19, 2024 13:09
…in explanatory section

Signed-off-by: Ryan B Sullivan <[email protected]>
@ryanbsull
Copy link
Contributor Author

Hey, @qdeslandes just wanted to ping regarding this

doc/usage/index.rst Show resolved Hide resolved
doc/usage/index.rst Outdated Show resolved Hide resolved
@qdeslandes qdeslandes merged commit c8f2d66 into facebook:main Jan 1, 2025
11 checks passed
@qdeslandes
Copy link
Contributor

Hi @ryanbsull ,

Non-code changes are usually not the most straightforward for some reason, thanks for pushing through, I appreciate your contribution. This change is now merged!

@ryanbsull
Copy link
Contributor Author

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants