From b6d01c868304dcfc9e74a4204477dc42e4ccb48d Mon Sep 17 00:00:00 2001 From: FAELIX SALT Date: Mon, 30 Mar 2020 08:56:27 +0000 Subject: [PATCH] reduce CPU usage by doing netflow samping in iptables --- bcp38.iptables.v4 | 4 ++-- bcp38.iptables.v6 | 4 ++-- vyos.conf.j2 | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bcp38.iptables.v4 b/bcp38.iptables.v4 index adeabeb..17b1bcb 100644 --- a/bcp38.iptables.v4 +++ b/bcp38.iptables.v4 @@ -27,13 +27,13 @@ COMMIT *mangle :PREROUTING ACCEPT [0:0] {% for iface_name, iface_data in pillar['netbox']['interfaces'].items() %}{% if salt['pillar.get']('interfaces:'+iface_name+':netflow') %} --A PREROUTING -i {{ iface_name }} -j NFLOG --nflog-group 2 --nflog-size 64 --nflog-threshold 64 +-A PREROUTING -i {{ iface_name }} -m statistic --mode nth --packet 1 --every {{ salt['pillar.get']('netflow:sampling-rate',64) }} -j NFLOG --nflog-group 2 {% if salt['grains.get']('kernelrelease','') in ["4.19.52-amd64-vyos","4.19.84-amd64-vyos"] %}--nflog-range 64{% else %}--nflog-size 64{% endif %} --nflog-threshold 64 {% endif %}{% endfor %} :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] {% for iface_name, iface_data in pillar['netbox']['interfaces'].items() %}{% if salt['pillar.get']('interfaces:'+iface_name+':netflow') %} --A POSTROUTING -o {{ iface_name }} -j NFLOG --nflog-group 2 --nflog-size 64 --nflog-threshold 64 +-A POSTROUTING -o {{ iface_name }} -m statistic --mode nth --packet 1 --every {{ salt['pillar.get']('netflow:sampling-rate',64) }} -j NFLOG --nflog-group 2 {% if salt['grains.get']('kernelrelease','') in ["4.19.52-amd64-vyos","4.19.84-amd64-vyos"] %}--nflog-range 64{% else %}--nflog-size 64{% endif %} --nflog-threshold 64 {% endif %}{% endfor %} COMMIT diff --git a/bcp38.iptables.v6 b/bcp38.iptables.v6 index 671e737..61a30d7 100644 --- a/bcp38.iptables.v6 +++ b/bcp38.iptables.v6 @@ -27,13 +27,13 @@ COMMIT *mangle :PREROUTING ACCEPT [0:0] {% for iface_name, iface_data in pillar['netbox']['interfaces'].items() %}{% if salt['pillar.get']('interfaces:'+iface_name+':netflow') %} --A PREROUTING -i {{ iface_name }} -j NFLOG --nflog-group 2 --nflog-size 64 --nflog-threshold 64 +-A PREROUTING -i {{ iface_name }} -m statistic --mode nth --packet 1 --every {{ salt['pillar.get']('netflow:sampling-rate',64) }} -j NFLOG --nflog-group 2 {% if salt['grains.get']('kernelrelease','') in ["4.19.52-amd64-vyos","4.19.84-amd64-vyos"] %}--nflog-range 64{% else %}--nflog-size 64{% endif %} --nflog-threshold 64 {% endif %}{% endfor %} :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] {% for iface_name, iface_data in pillar['netbox']['interfaces'].items() %}{% if salt['pillar.get']('interfaces:'+iface_name+':netflow') %} --A POSTROUTING -o {{ iface_name }} -j NFLOG --nflog-group 2 --nflog-size 64 --nflog-threshold 64 +-A POSTROUTING -o {{ iface_name }} -m statistic --mode nth --packet 1 --every {{ salt['pillar.get']('netflow:sampling-rate',64) }} -j NFLOG --nflog-group 2 {% if salt['grains.get']('kernelrelease','') in ["4.19.52-amd64-vyos","4.19.84-amd64-vyos"] %}--nflog-range 64{% else %}--nflog-size 64{% endif %} --nflog-threshold 64 {% endif %}{% endfor %} COMMIT diff --git a/vyos.conf.j2 b/vyos.conf.j2 index 01a74c5..ba6b14c 100644 --- a/vyos.conf.j2 +++ b/vyos.conf.j2 @@ -1332,7 +1332,7 @@ system { interface {{ iface_name }} {% endif %}{% endfor %} netflow { - sampling-rate {{ pillar['netflow']['sampling-rate']}} + sampling-rate 1 {% for server in pillar['netflow']['servers'] %} server {{ server.split(":")[0] }} { port {{ server.split(":")[1] }}