T75: migrate from pmacct to ipt_NETFLOW - #4688
Conversation
|
👍 |
|
✅ No issues found in unused-imports check. Please refer the workflow run |
There was a problem hiding this comment.
Pull Request Overview
This PR migrates VyOS flow accounting from pmacct to ipt_NETFLOW, changing the underlying implementation while maintaining similar functionality. The migration simplifies configuration by removing pmacct-specific options and introduces more flexible NetFlow server configuration with per-server source addressing.
- Replaces pmacct daemon with ipt_NETFLOW kernel module for flow accounting
- Moves interface configuration under the netflow tree structure
- Updates operational commands to work with the new implementation
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/op_mode/flow_accounting_op.py | Replaces pmacct-based flow parsing with ipt_NETFLOW /proc interface parsing |
| src/migration-scripts/flow-accounting/2-to-3 | Migrates configuration from pmacct format to ipt_NETFLOW format |
| src/conf_mode/system_flow-accounting.py | Replaces nftables/pmacct with iptables/ipt_NETFLOW configuration |
| smoketest/scripts/cli/test_system_flow-accounting.py | Updates tests for new ipt_NETFLOW implementation |
| interface-definitions/system_flow-accounting.xml.in | Removes pmacct options and restructures NetFlow configuration |
| data/templates/ipt-netflow/ipt_NETFLOW.conf.j2 | New template for ipt_NETFLOW module configuration |
Comments suppressed due to low confidence (1)
src/op_mode/flow_accounting_op.py:1
- Using
current_rulein the list comprehension should becurrent_rule_parsedsincecurrent_ruleis a string but you're trying to access it by index. This should berange(min(len(current_rule_parsed), len(columns))).
#!/usr/bin/env python3
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| elif re.match(r'^\d+,.*\d$', arg): | ||
| # Port list | ||
| ports = re.split(r',+', arg) # This allows duplicate commad like '1,,2,3,4' | ||
| ports = re.split(r',+', arg) # This allows duplicate commas like '1,,2,3,4' |
There was a problem hiding this comment.
Fix typo in comment: 'commas' is misspelled as 'commad'.
| key, subkeys = h.split(':', 1) | ||
| headers[i] = {'key': key, 'subkeys': subkeys.split(',')} | ||
|
|
||
| headers.remove('type') # Somewhy this field has no value |
There was a problem hiding this comment.
Fix the comment: 'Somewhy' should be 'For some reason' or 'Somehow'.
| headers.remove('type') # Somewhy this field has no value | |
| headers.remove('type') # For some reason this field has no value |
| need_reload = True | ||
|
|
||
| # get nftables rule dict for chain in table | ||
| def _nftables_get_nflog(chain, table): | ||
|
|
There was a problem hiding this comment.
The global variable need_reload is a problematic pattern. Consider passing this state through function parameters or using a class-based approach to avoid global state management issues.
| if iface in configured_ifaces_extended: | ||
| configured_ifaces_extended.remove(iface) |
There was a problem hiding this comment.
This condition will always be false because iface is from active_ifaces which contains dictionaries, while configured_ifaces_extended contains dictionaries. The comparison should check if iface is in active_ifaces instead, or the logic needs to be restructured.
| if iface in configured_ifaces_extended: | |
| configured_ifaces_extended.remove(iface) | |
| # Remove any entry in configured_ifaces_extended whose 'iface' matches iface['iface'] | |
| configured_ifaces_extended[:] = [entry for entry in configured_ifaces_extended if entry['iface'] != iface['iface']] |
ab956e7 to
331408c
Compare
| </node> | ||
| </children> | ||
| </node> | ||
| <node name="restart"> |
There was a problem hiding this comment.
What about other op-mode commands?
vyos@r14:~$ show conf com | match flow
set system flow-accounting netflow interface 'eth99'
set system flow-accounting netflow interface 'eth1'
set system flow-accounting netflow interface 'eth0'
set system flow-accounting netflow sampling-rate '1'
set system flow-accounting netflow server 127.0.0.1
set system flow-accounting netflow version '10'
set system flow-accounting vrf 'red'
set vrf name red table '1010'
vyos@r14:~$
vyos@r14:~$ show flow-accounting
Traceback (most recent call last):
File "/usr/libexec/vyos/op_mode/flow_accounting_op.py", line 268, in <module>
flows_list = _get_flows_list()
^^^^^^^^^^^^^^^^^
File "/usr/libexec/vyos/op_mode/flow_accounting_op.py", line 120, in _get_flows_list
headers.remove('type') # Somewhy this field has no value
^^^^^^^^^^^^^^^^^^^^^^
ValueError: list.remove(x): x not in list
vyos@r14:~$
vyos@r14:~$
vyos@r14:~$
vyos@r14:~$ show flow-accounting interface eth0
Traceback (most recent call last):
File "/usr/libexec/vyos/op_mode/flow_accounting_op.py", line 268, in <module>
flows_list = _get_flows_list()
^^^^^^^^^^^^^^^^^
File "/usr/libexec/vyos/op_mode/flow_accounting_op.py", line 120, in _get_flows_list
headers.remove('type') # Somewhy this field has no value
^^^^^^^^^^^^^^^^^^^^^^
ValueError: list.remove(x): x not in list
vyos@r14:~$
There was a problem hiding this comment.
I've fixed the issue with show and tested it with current ipt_NETFLOW module.
I don't see how to implement 'clear' command with ipt_NETFLOW.
I'll implement restart...
There was a problem hiding this comment.
I've implemented restart, restarting clears all counters. Should I make clear do exactly what restart does or just remove it?..
dfbdf42 to
b04a0f7
Compare
98282ed to
cd59586
Compare
| call('systemctl daemon-reload') | ||
| prev_config = '' | ||
| if os.path.exists(ipt_netflow_conf_path): | ||
| with open(ipt_netflow_conf_path) as f: |
There was a problem hiding this comment.
Please use vyos.utils.file.read_file()
There was a problem hiding this comment.
Thank you, nice utility function, updated.
| os.unlink(uacctd_conf_path) | ||
| new_config = '' | ||
| if os.path.exists(ipt_netflow_conf_path): | ||
| with open(ipt_netflow_conf_path) as f: |
There was a problem hiding this comment.
Please use vyos.utils.file.read_file()
4cbac1a to
8ec9e2f
Compare
dmbaturin
left a comment
There was a problem hiding this comment.
I left a few suggestions regarding help string wording. The logic seems good at a glance.
| </leafNode> | ||
| <leafNode name="active-timeout"> | ||
| <properties> | ||
| <help>Export flow after it's active for this timeout in seconds</help> |
f3bcc47 to
102fc58
Compare
Thanks, I've updated messages. |
| ocserv, | ||
| # End "vpn openconnect" | ||
| # For "system flow-accounting" | ||
| pmacct (>= 1.6.0), |
There was a problem hiding this comment.
Do not forget to remove mentions about pmacct (after merging) in the vyos-build
There was a problem hiding this comment.
Thanks you, I missed that!
Here is PR: vyos/vyos-build#1030
I'll make it non-draft when ipt_NETFLOW is merged.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
src/op_mode/flow_accounting_op.py:89
- There's a typo in the comment: 'dictioanry' should be 'dictionary'.
# return dictioanry
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
* Change nft to iptables in system_flow-accounting.py as ipt_NETFLOW is iptales plugin * Remove specific and non-relevant pmacct options * Add ipt_NETFLOW options * Move 'interfaces' to 'netflow' tree * Support more flexible 'source-address' and 'source-interface' for each server instead of one source * Add migration script * Update op mode command 'show flow-accounting' * Update op mode command 'restart flow-accounting'
102fc58 to
e992fb4
Compare
|
CI integration ❌ failed! Details
|
sever-sever
left a comment
There was a problem hiding this comment.
My internal test looks working fine.
Other could be fixed after merging.
dmbaturin
left a comment
There was a problem hiding this comment.
Let's get it into the rolling release image.
Migrate from pmacct to ipt_NETFLOW
Types of changes
Related Task(s)
Related PR(s)
Update of ipt_NETFLOW module to provide sampler, MAC address and VLAN recording.
This PR should work without that one too.
How to test / Smoketest result
I've update smoke test
smoketest/scripts/cli/test_system_flow-accounting.pyaccordingly, output:(I've removed kernel messages from ipt_NETFLOW for clarity and brevity)
Checklist: