Skip to content

T75: migrate from pmacct to ipt_NETFLOW - #4688

Merged
dmbaturin merged 1 commit into
vyos:currentfrom
hedrok:T75-migration-to-ipt-netflow
Sep 16, 2025
Merged

T75: migrate from pmacct to ipt_NETFLOW#4688
dmbaturin merged 1 commit into
vyos:currentfrom
hedrok:T75-migration-to-ipt-netflow

Conversation

@hedrok

@hedrok hedrok commented Aug 31, 2025

Copy link
Copy Markdown
Contributor

Migrate from pmacct to ipt_NETFLOW

  • 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'

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

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.py accordingly, output:

vyos@vyos-router:~$ /usr/libexec/vyos/tests/smoke/cli/test_system_flow-accounting.py TestSystemFlowAccounting
test_basic (__main__.TestSystemFlowAccounting.test_basic) ...
ok
test_iptables (__main__.TestSystemFlowAccounting.test_iptables) ...
ok
test_netflow (__main__.TestSystemFlowAccounting.test_netflow) ...
ok
test_sampler (__main__.TestSystemFlowAccounting.test_sampler) ...
ok

----------------------------------------------------------------------
Ran 4 tests in 16.765s

OK

(I've removed kernel messages from ipt_NETFLOW for clarity and brevity)

Checklist:

@github-actions

github-actions Bot commented Aug 31, 2025

Copy link
Copy Markdown

👍
No issues in PR Title / Commit Title

@github-actions

github-actions Bot commented Aug 31, 2025

Copy link
Copy Markdown

✅ No issues found in unused-imports check. Please refer the workflow run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_rule in the list comprehension should be current_rule_parsed since current_rule is a string but you're trying to access it by index. This should be range(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.

Comment thread src/op_mode/flow_accounting_op.py Outdated
Comment thread src/op_mode/flow_accounting_op.py Outdated
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'

Copilot AI Aug 31, 2025

Copy link

Choose a reason for hiding this comment

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

Fix typo in comment: 'commas' is misspelled as 'commad'.

Copilot uses AI. Check for mistakes.
Comment thread src/op_mode/flow_accounting_op.py Outdated
key, subkeys = h.split(':', 1)
headers[i] = {'key': key, 'subkeys': subkeys.split(',')}

headers.remove('type') # Somewhy this field has no value

Copilot AI Aug 31, 2025

Copy link

Choose a reason for hiding this comment

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

Fix the comment: 'Somewhy' should be 'For some reason' or 'Somehow'.

Suggested change
headers.remove('type') # Somewhy this field has no value
headers.remove('type') # For some reason this field has no value

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +42
need_reload = True

# get nftables rule dict for chain in table
def _nftables_get_nflog(chain, table):

Copilot AI Aug 31, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread src/conf_mode/system_flow-accounting.py Outdated
Comment on lines 139 to 140
if iface in configured_ifaces_extended:
configured_ifaces_extended.remove(iface)

Copilot AI Aug 31, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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']]

Copilot uses AI. Check for mistakes.
Comment thread smoketest/configs/bgp-azure-ipsec-gateway Outdated
Comment thread smoketest/configs/bgp-azure-ipsec-gateway Outdated
Comment thread smoketest/configs/bgp-big-as-cloud Outdated
Comment thread smoketest/configs/bgp-big-as-cloud
@hedrok
hedrok force-pushed the T75-migration-to-ipt-netflow branch 2 times, most recently from ab956e7 to 331408c Compare September 1, 2025 07:44
</node>
</children>
</node>
<node name="restart">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:~$ 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've implemented restart, restarting clears all counters. Should I make clear do exactly what restart does or just remove it?..

Comment thread src/conf_mode/system_flow-accounting.py Outdated
@hedrok
hedrok force-pushed the T75-migration-to-ipt-netflow branch from dfbdf42 to b04a0f7 Compare September 1, 2025 12:59
@sever-sever
sever-sever self-requested a review September 1, 2025 22:46
@hedrok
hedrok force-pushed the T75-migration-to-ipt-netflow branch 2 times, most recently from 98282ed to cd59586 Compare September 2, 2025 12:47
Comment thread src/conf_mode/system_flow-accounting.py Outdated
call('systemctl daemon-reload')
prev_config = ''
if os.path.exists(ipt_netflow_conf_path):
with open(ipt_netflow_conf_path) as f:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use vyos.utils.file.read_file()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, nice utility function, updated.

Comment thread src/conf_mode/system_flow-accounting.py Outdated
os.unlink(uacctd_conf_path)
new_config = ''
if os.path.exists(ipt_netflow_conf_path):
with open(ipt_netflow_conf_path) as f:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use vyos.utils.file.read_file()

@hedrok
hedrok force-pushed the T75-migration-to-ipt-netflow branch 2 times, most recently from 4cbac1a to 8ec9e2f Compare September 9, 2025 18:52
@hedrok
hedrok requested a review from c-po September 10, 2025 04:12

@dmbaturin dmbaturin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I left a few suggestions regarding help string wording. The logic seems good at a glance.

Comment thread interface-definitions/system_flow-accounting.xml.in Outdated
Comment thread interface-definitions/system_flow-accounting.xml.in Outdated
</leafNode>
<leafNode name="active-timeout">
<properties>
<help>Export flow after it's active for this timeout in seconds</help>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See above.

@hedrok
hedrok force-pushed the T75-migration-to-ipt-netflow branch from f3bcc47 to 102fc58 Compare September 15, 2025 11:37
@hedrok

hedrok commented Sep 15, 2025

Copy link
Copy Markdown
Contributor Author

I left a few suggestions regarding help string wording. The logic seems good at a glance.

Thanks, I've updated messages.

Comment thread debian/control
ocserv,
# End "vpn openconnect"
# For "system flow-accounting"
pmacct (>= 1.6.0),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do not forget to remove mentions about pmacct (after merging) in the vyos-build

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks you, I missed that!
Here is PR: vyos/vyos-build#1030
I'll make it non-draft when ipt_NETFLOW is merged.

@hedrok hedrok mentioned this pull request Sep 15, 2025
11 tasks
@sever-sever
sever-sever self-requested a review September 15, 2025 16:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/op_mode/flow_accounting_op.py
Comment thread python/vyos/ipt_netflow.py
Comment thread python/vyos/ipt_netflow.py
* 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'
@hedrok
hedrok force-pushed the T75-migration-to-ipt-netflow branch from 102fc58 to e992fb4 Compare September 16, 2025 10:01
@github-actions

Copy link
Copy Markdown

CI integration ❌ failed!

Details

CI logs

  • CLI Smoketests (no interfaces) ❌ failed
  • CLI Smoketests VPP 👍 passed
  • CLI Smoketests (interfaces only) 👍 passed
  • Config tests 👍 passed
  • Config tests VPP 👍 passed
  • RAID1 tests 👍 passed
  • TPM tests 👍 passed

@sever-sever sever-sever left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My internal test looks working fine.
Other could be fixed after merging.

@dmbaturin dmbaturin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's get it into the rolling release image.

@dmbaturin
dmbaturin merged commit 8b0c9b7 into vyos:current Sep 16, 2025
17 of 18 checks passed
@dmbaturin dmbaturin added the bp/circinus Create automatic backport for circinus label Sep 16, 2025
@vyosbot vyosbot added mirror-initiated This PR initiated for mirror sync workflow mirror-completed and removed mirror-initiated This PR initiated for mirror sync workflow labels Sep 16, 2025
@andamasov andamasov removed the bp/circinus Create automatic backport for circinus label May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

7 participants