Skip to content

Commit

Permalink
T6375: Fix/Update NAT logging
Browse files Browse the repository at this point in the history
Fixed broken logging for "show log nat"

Added the following commands:
show log nat source
show log nat source rule <ruleNum>
show log nat destination nat
show log nat destination nat rule <ruleNum>
show log nat static
show log nat static rule <ruleNum>
  • Loading branch information
l0crian1 committed May 21, 2024
1 parent 9f55afc commit 5cb9b84
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions interface-definitions/nat.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
</children>
</node>
#include <include/inbound-interface.xml.i>
#include <include/firewall/log.xml.i>
<node name="translation">
<properties>
<help>Translation address or prefix</help>
Expand Down
50 changes: 47 additions & 3 deletions op-mode-definitions/show-log.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,56 @@
</properties>
<command>journalctl --no-hostname --boot --unit lldpd.service</command>
</leafNode>
<leafNode name="nat">
<node name="nat">
<properties>
<help>Show log for Network Address Translation (NAT)</help>
</properties>
<command>egrep -i "kernel:.*\[NAT-[A-Z]{3,}-[0-9]+(-MASQ)?\]" $(find /var/log -maxdepth 1 -type f -name messages\* | sort -t. -k2nr)</command>
</leafNode>
<children>
<node name="destination">
<properties>
<help>Show NAT destination log</help>
</properties>
<command>journalctl --no-hostname --boot -k | egrep "\[DST-NAT-[0-9]+\]"</command>
<children>
<tagNode name="rule">
<properties>
<help>Show NAT destination log for specified rule</help>
</properties>
<command>journalctl --no-hostname --boot -k | egrep "\[DST-NAT-$6\]"</command>
</tagNode>
</children>
</node>
<node name="source">
<properties>
<help>Show NAT source log</help>
</properties>
<command>journalctl --no-hostname --boot -k | egrep "\[SRC-NAT-[0-9]+(-MASQ)?\]"&quot;"</command>
<children>
<tagNode name="rule">
<properties>
<help>Show NAT source log for specified rule</help>
</properties>
<command>journalctl --no-hostname --boot -k | egrep "\[SRC-NAT-$6(-MASQ)?\]"</command>
</tagNode>
</children>
</node>
<node name="static">
<properties>
<help>Show NAT static log</help>
</properties>
<command>journalctl --no-hostname --boot -k | egrep "\[STATIC-(SRC|DST)-NAT-[0-9]+\]"</command>
<children>
<tagNode name="rule">
<properties>
<help>Show NAT static log for specified rule</help>
</properties>
<command>journalctl --no-hostname --boot -k | egrep "\[STATIC-(SRC|DST)-NAT-$6\]"</command>
</tagNode>
</children>
</node>
</children>
<command>journalctl --no-hostname --boot -k | egrep "\[(STATIC-)?(DST|SRC)-NAT-[0-9]+(-MASQ)?\]"</command>
</node>
<leafNode name="ndp-proxy">
<properties>
<help>Show log for Neighbor Discovery Protocol (NDP) Proxy</help>
Expand Down
6 changes: 3 additions & 3 deletions python/vyos/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ def parse_nat_static_rule(rule_conf, rule_id, nat_type):

output.append('counter')

if translation_str:
output.append(translation_str)

if 'log' in rule_conf:
output.append(f'log prefix "[{log_prefix}{log_suffix}]"')

if translation_str:
output.append(translation_str)

output.append(f'comment "{log_prefix}"')

return " ".join(output)

0 comments on commit 5cb9b84

Please sign in to comment.