From 610685d27b32e0fbfab6b75c1c8c1142a6598ada Mon Sep 17 00:00:00 2001 From: Stephen Sun <5379172+stephenxs@users.noreply.github.com> Date: Sun, 24 Mar 2024 08:04:00 +0800 Subject: [PATCH] Do not pass the option "device" in rsyslog.conf by default when syslog server's source address is configured (#17616) ### Why I did it An in-band syslog server will not receive any syslog if it is configured without a VRF specified, which is because `eth0` is always specified as the `device` of a syslog server and the syslog packets will be sent to `eth0` regardless of its destination IP address. ### How I did it Pass the option "device" in rsyslog.conf only if when syslog server's source address is configured with a non-default VRF #### How to verify it Manually test: 1. Configuring a syslog server without VRF specified or with `default` as the VRF: no `device` passed in `rsyslog.conf` 2. Configuring a syslog server with non-default VRF: the configured VRF passed as `device` in `rsyslog.conf` --- files/image_config/rsyslog/rsyslog.conf.j2 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/files/image_config/rsyslog/rsyslog.conf.j2 b/files/image_config/rsyslog/rsyslog.conf.j2 index c29d803d08..f6d4804940 100644 --- a/files/image_config/rsyslog/rsyslog.conf.j2 +++ b/files/image_config/rsyslog/rsyslog.conf.j2 @@ -107,7 +107,7 @@ $RepeatedMsgReduction on {% set regex = conf.get('filter_regex') -%} {% set fmodifier = '!' if filter == 'exclude' else '' %} -{% set device = 'eth0' if vrf == 'default' else vrf -%} +{% set device = vrf if vrf != '' and vrf != 'default' -%} {% set template = 'WelfRemoteFormat' if format == 'welf' else 'SONiCFileFormat' -%} {# Server extra options -#} @@ -115,11 +115,16 @@ $RepeatedMsgReduction on {% if source -%} {% set options = options ~ ' Address="' ~ source ~ '"'-%} + {% set device = device if device != 'eth0' else '' -%} +{% endif -%} + +{% if device -%} + {% set options = options ~ ' Device="' ~ device ~ '"'-%} {% endif -%} {% if filter %} :msg, {{ fmodifier }}ereregex, "{{ regex }}" {% endif %} *.{{ severity }} -action(type="omfwd" Target="{{ server }}" Port="{{ port }}" Protocol="{{ proto }}" Device="{{ device }}" Template="{{ template }}"{{ options }}) +action(type="omfwd" Target="{{ server }}" Port="{{ port }}" Protocol="{{ proto }}" Template="{{ template }}"{{ options }}) {% endfor %}