Skip to content

Commit a67cde6

Browse files
authored
Merge pull request #3493 from l0crian1/T6375-fix-add-nat-logging
T6375: Fix/Update NAT logging
2 parents 9f55afc + 5cb9b84 commit a67cde6

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

interface-definitions/nat.xml.in

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
</children>
142142
</node>
143143
#include <include/inbound-interface.xml.i>
144+
#include <include/firewall/log.xml.i>
144145
<node name="translation">
145146
<properties>
146147
<help>Translation address or prefix</help>

op-mode-definitions/show-log.xml.in

+47-3
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,56 @@
464464
</properties>
465465
<command>journalctl --no-hostname --boot --unit lldpd.service</command>
466466
</leafNode>
467-
<leafNode name="nat">
467+
<node name="nat">
468468
<properties>
469469
<help>Show log for Network Address Translation (NAT)</help>
470470
</properties>
471-
<command>egrep -i "kernel:.*\[NAT-[A-Z]{3,}-[0-9]+(-MASQ)?\]" $(find /var/log -maxdepth 1 -type f -name messages\* | sort -t. -k2nr)</command>
472-
</leafNode>
471+
<children>
472+
<node name="destination">
473+
<properties>
474+
<help>Show NAT destination log</help>
475+
</properties>
476+
<command>journalctl --no-hostname --boot -k | egrep "\[DST-NAT-[0-9]+\]"</command>
477+
<children>
478+
<tagNode name="rule">
479+
<properties>
480+
<help>Show NAT destination log for specified rule</help>
481+
</properties>
482+
<command>journalctl --no-hostname --boot -k | egrep "\[DST-NAT-$6\]"</command>
483+
</tagNode>
484+
</children>
485+
</node>
486+
<node name="source">
487+
<properties>
488+
<help>Show NAT source log</help>
489+
</properties>
490+
<command>journalctl --no-hostname --boot -k | egrep "\[SRC-NAT-[0-9]+(-MASQ)?\]"&quot;"</command>
491+
<children>
492+
<tagNode name="rule">
493+
<properties>
494+
<help>Show NAT source log for specified rule</help>
495+
</properties>
496+
<command>journalctl --no-hostname --boot -k | egrep "\[SRC-NAT-$6(-MASQ)?\]"</command>
497+
</tagNode>
498+
</children>
499+
</node>
500+
<node name="static">
501+
<properties>
502+
<help>Show NAT static log</help>
503+
</properties>
504+
<command>journalctl --no-hostname --boot -k | egrep "\[STATIC-(SRC|DST)-NAT-[0-9]+\]"</command>
505+
<children>
506+
<tagNode name="rule">
507+
<properties>
508+
<help>Show NAT static log for specified rule</help>
509+
</properties>
510+
<command>journalctl --no-hostname --boot -k | egrep "\[STATIC-(SRC|DST)-NAT-$6\]"</command>
511+
</tagNode>
512+
</children>
513+
</node>
514+
</children>
515+
<command>journalctl --no-hostname --boot -k | egrep "\[(STATIC-)?(DST|SRC)-NAT-[0-9]+(-MASQ)?\]"</command>
516+
</node>
473517
<leafNode name="ndp-proxy">
474518
<properties>
475519
<help>Show log for Neighbor Discovery Protocol (NDP) Proxy</help>

python/vyos/nat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ def parse_nat_static_rule(rule_conf, rule_id, nat_type):
300300

301301
output.append('counter')
302302

303-
if translation_str:
304-
output.append(translation_str)
305-
306303
if 'log' in rule_conf:
307304
output.append(f'log prefix "[{log_prefix}{log_suffix}]"')
308305

306+
if translation_str:
307+
output.append(translation_str)
308+
309309
output.append(f'comment "{log_prefix}"')
310310

311311
return " ".join(output)

0 commit comments

Comments
 (0)