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

[CLI] Add script null_route_helper #1737

Merged
merged 1 commit into from
Aug 3, 2021

Conversation

bingwang-ms
Copy link
Contributor

Signed-off-by: bingwang [email protected]

What I did

This PR introduced a new helper script null_route_helper.

null_route_helper is a utility for blocking and unblocking traffic from given source ip_prefix on ACL tables.
The block operation will insert a DENY rule at the top of the table. The unblock operation will remove an existing DENY rule that has been created by the block operation (i.e. it does NOT insert an ALLOW rule, only removes DENY rules).
Since SONiC supports multi ACL rules share the same priority, all ACL rules created by null_route_helper will use the highest priority(9999).

Example:

Block traffic from 10.2.3.4:
./null_route_helper block acl_table_name 10.2.3.4

Unblock all traffic from 10.2.3.4:
./null_route_helper unblock acl_table_name 10.2.3.4

List all acl rules added by this script
./null_route_helper list acl_table_name

How I did it

The feature is implemented with applying ACL rules.

How to verify it

Verified with both unit test and traffic test.

tests/null_route_helper_test.py::test_ip_validation PASSED                                                                                                                                      [ 59%]
tests/null_route_helper_test.py::test_confirm_required_table_existence PASSED                                                                                                                   [ 59%]
tests/null_route_helper_test.py::test_build_rule PASSED                                                                                                                                         [ 59%]
tests/null_route_helper_test.py::test_get_rule PASSED                                                                                                                                           [ 59%]
tests/null_route_helper_test.py::test_run_when_table_absent PASSED                                                                                                                              [ 59%]
tests/null_route_helper_test.py::test_run_with_invalid_ip PASSED                                                                                                                                [ 59%]
tests/null_route_helper_test.py::test_block PASSED                                                                                                                                              [ 60%]
tests/null_route_helper_test.py::test_unblock PASSED                                                                                                                                            [ 60%]
tests/null_route_helper_test.py::test_list PASSED          
Name                                                Stmts   Miss Branch BrPart  Cover
-------------------------------------------------------------------------------------
scripts/null_route_helper                             123      4     34      3    96%

Traffic verification will be done in sonic-mgmt
sonic-net/sonic-mgmt#3812

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

@bingwang-ms bingwang-ms merged commit 394e2fb into sonic-net:master Aug 3, 2021
@qiluo-msft
Copy link
Contributor

This PR could not cleanly cherry-picked to 201911 branch. Please submit another PR.

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