From 70fadc9180eb4a56ea366045c01d3ce83e9592da Mon Sep 17 00:00:00 2001
From: Leonid Komarianskyi <leonid_komarianskyi@epam.com>
Date: Mon, 20 Mar 2023 10:20:36 +0200
Subject: [PATCH 2/4] [domd] Add Snort and required S4 R-Switch specific libdaq

Signed-off-by: Leonid Komarianskyi <leonid_komarianskyi@epam.com>
---
 aos-rcar-gen4.yaml                            |  1 +
 .../daq/daq_2.0.6.bbappend                    |  5 ++
 ...e-tirpc-checking-for-fedora-snort-20.patch | 60 +++++++++++++++++++
 .../snort/snort/snort-tsn0.service            | 11 ++++
 .../snort/snort/snort-tsn1.service            | 11 ++++
 .../snort/snort/snort-tsn2.service            | 11 ++++
 .../snort/snort_%.bbappend                    | 34 +++++++++++
 7 files changed, 133 insertions(+)
 create mode 100644 meta-aos-rcar-gen4-domd/recipes-connectivity/daq/daq_2.0.6.bbappend
 create mode 100644 meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/configure.in-disable-tirpc-checking-for-fedora-snort-20.patch
 create mode 100644 meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn0.service
 create mode 100644 meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn1.service
 create mode 100644 meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn2.service
 create mode 100644 meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort_%.bbappend

diff --git a/aos-rcar-gen4.yaml b/aos-rcar-gen4.yaml
index 6c14682..c87e448 100644
--- a/aos-rcar-gen4.yaml
+++ b/aos-rcar-gen4.yaml
@@ -191,6 +191,7 @@ components:
         - [XT_DOM_NAME, "domd"]
         - [XT_DEVICE_TREES, "%{XT_DOMD_DTB_NAME} %{XT_XEN_DTB_NAME}"]
         - [IMAGE_INSTALL_append, " iperf3"]
+        - [IMAGE_INSTALL_append, " snort"]
 
         # Enable seccomp for crun
         - [DISTRO_FEATURES_append, " seccomp"]
diff --git a/meta-aos-rcar-gen4-domd/recipes-connectivity/daq/daq_2.0.6.bbappend b/meta-aos-rcar-gen4-domd/recipes-connectivity/daq/daq_2.0.6.bbappend
new file mode 100644
index 0000000..77a03d5
--- /dev/null
+++ b/meta-aos-rcar-gen4-domd/recipes-connectivity/daq/daq_2.0.6.bbappend
@@ -0,0 +1,5 @@
+SRC_URI = "git://github.com/xen-troops/libdaq-legacy;protocol=https"
+BRANCH = "master"
+SRCREV = "${AUTOREV}"
+S = "${WORKDIR}/git"
+DISABLE_STATIC = " --disable-static"
diff --git a/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/configure.in-disable-tirpc-checking-for-fedora-snort-20.patch b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/configure.in-disable-tirpc-checking-for-fedora-snort-20.patch
new file mode 100644
index 0000000..d8c945a
--- /dev/null
+++ b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/configure.in-disable-tirpc-checking-for-fedora-snort-20.patch
@@ -0,0 +1,60 @@
+From 65463a7c5cb2514b1523a81911810effffb75a79 Mon Sep 17 00:00:00 2001
+From: Yi Zhao <yi.zhao@windriver.com>
+Date: Fri, 28 Jun 2019 15:05:31 +0800
+Subject: [PATCH] configure.in: disable tirpc checking for fedora
+
+The Fedora 28+ does not have inbuilt SunRPC support in glibc and is
+separately availble in tirpc package. So it enables tirpc checking for
+fedora in configure.
+
+Drop this piece of code since we had specify '-ltirpc' in LDFLAGS
+explicitly. Otherwise it will cause a compile-host-path QA issue if the
+host is Fedora 28+:
+cc1: warning: include location "/usr/include/tirpc" is unsafe for
+cross-compilation [-Wpoison-system-directories]
+
+Upstream-Status: Inappropriate [embedded specific]
+
+Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
+---
+ configure.in | 24 ------------------------
+ 1 file changed, 24 deletions(-)
+
+diff --git a/configure.in b/configure.in
+index 8662cdd..0ff7e27 100644
+--- a/configure.in
++++ b/configure.in
+@@ -895,30 +895,6 @@ if test "x$enable_dlclose" = "xno"; then
+     AC_DEFINE([DISABLE_DLCLOSE_FOR_VALGRIND_TESTING],[1],[Don't close opened shared objects for valgrind leak testing of dynamic libraries])
+ fi
+ 
+-##################################################
+-# Fedora 28+ does not have inbuilt SunRPC support#
+-# in glibc and is separately availble in tirpc   #
+-# package. Make sure we've got the library and   #
+-# link it                                        #
+-##################################################
+-
+-if test -f /etc/fedora-release ; then
+-    DISTRO_VERSION=$(awk '{ print $3 }' /etc/fedora-release)
+-    if test $DISTRO_VERSION -ge 28 ; then
+-        TIRPC=""
+-        AC_CHECK_LIB(tirpc,bindresvport,, TIRPC="no")
+-        echo "$TIRPC"
+-        if test "x$TIRPC" = "xno"; then
+-            echo
+-            echo " ERROR! tirpc not found, get it by running "
+-            echo " yum install libtirpc-devel "
+-            exit
+-        fi
+-        LIBS="${LIBS} -ltirpc"
+-        extra_incl="-I/usr/include/tirpc"
+-    fi
+-fi
+-
+ ##################################################
+ # Centos 8+ does not have inbuilt SunRPC support  #
+ # in glibc and is separately availble in tirpc   #
+-- 
+2.7.4
+
diff --git a/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn0.service b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn0.service
new file mode 100644
index 0000000..931af1f
--- /dev/null
+++ b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn0.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Snort for TSN0
+After=network.target
+
+[Service]
+ExecStartPre=-mkdir /var/log/snort
+ExecStartPre=-tc qdisc add dev tsn0 ingress
+ExecStart=/usr/bin/snort --daq-dir /usr/lib/daq/ -Q -c /etc/snort/snort.conf -i tsn0:rmon0
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn1.service b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn1.service
new file mode 100644
index 0000000..172c9b9
--- /dev/null
+++ b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn1.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Snort for TSN1
+After=network.target
+
+[Service]
+ExecStartPre=-mkdir /var/log/snort
+ExecStartPre=-tc qdisc add dev tsn1 ingress
+ExecStart=/usr/bin/snort --daq-dir /usr/lib/daq/ -Q -c /etc/snort/snort.conf -i tsn1:rmon1
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn2.service b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn2.service
new file mode 100644
index 0000000..b205cd3
--- /dev/null
+++ b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort/snort-tsn2.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Snort for TSN2
+After=network.target
+
+[Service]
+ExecStartPre=-mkdir /var/log/snort
+ExecStartPre=-tc qdisc add dev tsn2 ingress
+ExecStart=/usr/bin/snort --daq-dir /usr/lib/daq/ -Q -c /etc/snort/snort.conf -i tsn2:rmon2
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort_%.bbappend b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort_%.bbappend
new file mode 100644
index 0000000..e7b1fe1
--- /dev/null
+++ b/meta-aos-rcar-gen4-domd/recipes-connectivity/snort/snort_%.bbappend
@@ -0,0 +1,34 @@
+PV = "2.9.20"
+SRC_URI[md5sum] = ""
+SRC_URI[sha256sum] = "29400e13f53b1831e0b8b10ec1224a1cbaa6dc1533a5322a20dd80bb84b4981c"
+
+SRC_URI_remove = "file://configure.in-disable-tirpc-checking-for-fedora.patch"
+
+SRC_URI += " file://snort-tsn0.service \
+    file://snort-tsn1.service \
+    file://snort-tsn2.service \
+    file://configure.in-disable-tirpc-checking-for-fedora-snort-20.patch \
+"
+
+FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
+
+
+do_install_append() {
+    install -d ${D}${systemd_unitdir}/system
+    install -m 0644 ${WORKDIR}/snort-tsn0.service ${D}${systemd_unitdir}/system/
+    install -m 0644 ${WORKDIR}/snort-tsn1.service ${D}${systemd_unitdir}/system/
+    install -m 0644 ${WORKDIR}/snort-tsn2.service ${D}${systemd_unitdir}/system/
+    echo "config daq: rswitch_offload" >> ${D}/etc/snort/snort.conf
+}
+
+
+SYSTEMD_PACKAGES = "snort-tsn0 snort-tsn1 snort-tsn2 "
+SYSTEMD_SERVICE_snort-tsn0 = "snort-tsn0.service"
+SYSTEMD_SERVICE_snort-tsn1 = "snort-tsn1.service"
+SYSTEMD_SERVICE_snort-tsn2 = "snort-tsn2.service"
+
+FILES_${PN} += " ${systemd_unitdir}/system/snort-tsn0.service \
+    ${systemd_unitdir}/system/snort-tsn1.service \
+    ${systemd_unitdir}/system/snort-tsn2.service \
+"
+
-- 
2.25.1

