Compare commits
14 Commits
v1.0.3.20.
...
v3.0.6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57c2feb69d | ||
|
|
2a25c20cea | ||
|
|
ab097e3bff | ||
|
|
badd5547da | ||
|
|
95bdca7514 | ||
|
|
9e4ed53bb1 | ||
|
|
4942106aab | ||
|
|
28cfd57e98 | ||
|
|
dab58fabe1 | ||
|
|
3d2324bb43 | ||
|
|
453c5330c0 | ||
|
|
aafcea896f | ||
|
|
2e50b5347f | ||
|
|
1e14cf83ca |
173
.gitlab-ci.yml
173
.gitlab-ci.yml
@@ -1,110 +1,115 @@
|
|||||||
image: "docker:stable"
|
image: "git.mesalab.cn:7443/mesa_platform/build-env:master"
|
||||||
|
|
||||||
services:
|
|
||||||
- docker:dind
|
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
GIT_STRATEGY: "clone"
|
GIT_STRATEGY: "clone"
|
||||||
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
|
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
|
||||||
|
INSTALL_PREFIX: "/home/mesasoft/sapp_run/"
|
||||||
|
INSTALL_DEPENDENCY_LIBRARY: libMESA_handle_logger-devel libcjson-devel libMESA_field_stat2-devel sapp-devel framework_env libMESA_prof_load-devel http-devel dns-devel ftp-devel mail-devel ssl-devel librdkafka-devel libmaatframe-devel tsg_master-devel libdocumentanalyze-devel libasan
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
- package
|
|
||||||
- release
|
.build_by_travis:
|
||||||
|
|
||||||
.build_before_script:
|
|
||||||
before_script:
|
before_script:
|
||||||
- mkdir -p /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_NAMESPACE/
|
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
|
||||||
- ln -s $CI_PROJECT_DIR /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH
|
- ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||||
- cd /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH
|
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||||
|
- chmod +x ./ci/travis.sh
|
||||||
.build_fw_dns_plug:
|
|
||||||
extends: .build_before_script
|
|
||||||
image: git.mesalab.cn:7443/tango/tsg_master:master
|
|
||||||
script:
|
script:
|
||||||
- source /etc/profile.d/MESA.sh
|
- yum makecache
|
||||||
- mkdir -p build
|
- ./ci/travis.sh
|
||||||
- cd build
|
- cd build
|
||||||
- cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
tags:
|
||||||
- make
|
- share
|
||||||
- make package
|
|
||||||
|
|
||||||
.package_fw_dns_plug:
|
|
||||||
extends: .build_before_script
|
|
||||||
image: git.mesalab.cn:7443/tango/tsg_master:master
|
|
||||||
script:
|
|
||||||
- source /etc/profile.d/MESA.sh
|
|
||||||
- mkdir -p build
|
|
||||||
- cd build
|
|
||||||
- cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
|
||||||
- make package
|
|
||||||
|
|
||||||
build:
|
branch_build_debug:
|
||||||
stage: build
|
stage: build
|
||||||
extends: .build_fw_dns_plug
|
extends: .build_by_travis
|
||||||
tags:
|
|
||||||
- share
|
|
||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: "Debug"
|
BUILD_TYPE: Debug
|
||||||
artifacts:
|
|
||||||
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
|
||||||
paths:
|
|
||||||
- ./build/*.rpm
|
|
||||||
except:
|
except:
|
||||||
|
- /^develop.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
- tags
|
- tags
|
||||||
|
|
||||||
fw_dns_plug_debug:
|
branch_build_release:
|
||||||
stage: package
|
stage: build
|
||||||
extends: .package_fw_dns_plug
|
|
||||||
tags:
|
|
||||||
- share
|
|
||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: "Debug"
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
extends: .build_by_travis
|
||||||
|
except:
|
||||||
|
- /^develop.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
|
- tags
|
||||||
|
|
||||||
|
develop_build_debug:
|
||||||
|
stage: build
|
||||||
|
extends: .build_by_travis
|
||||||
|
variables:
|
||||||
|
BUILD_TYPE: Debug
|
||||||
|
PACKAGE: 1
|
||||||
|
UPLOAD_RPM: 1
|
||||||
|
ASAN_OPTION: ADDRESS
|
||||||
|
TESTING_VERSION_BUILD: 1
|
||||||
|
PULP3_REPO_NAME: tsg-testing-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: tsg-testing-x86_64.el7
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
name: "fw_dns_plug-$CI_COMMIT_REF_NAME-debug"
|
||||||
paths:
|
paths:
|
||||||
- ./build/*.rpm
|
- build/*.rpm
|
||||||
only:
|
only:
|
||||||
- tags
|
- /^develop.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
fw_dns_plug_release:
|
|
||||||
stage: package
|
develop_build_release:
|
||||||
extends: .package_fw_dns_plug
|
stage: build
|
||||||
tags:
|
extends: .build_by_travis
|
||||||
- share
|
|
||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: "Release"
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
PACKAGE: 1
|
||||||
|
UPLOAD_RPM: 1
|
||||||
|
TESTING_VERSION_BUILD: 1
|
||||||
|
PULP3_REPO_NAME: tsg-testing-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: tsg-testing-x86_64.el7
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
name: "fw_dns_plug-$CI_COMMIT_REF_NAME-release"
|
||||||
paths:
|
paths:
|
||||||
- ./build/*.rpm
|
- build/*.rpm
|
||||||
only:
|
only:
|
||||||
- tags
|
- /^develop.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
fw_dns_plug_release-release:
|
|
||||||
stage: release
|
|
||||||
image: git.mesalab.cn:7443/tango/tsg_master:master
|
release_build_debug:
|
||||||
tags:
|
stage: build
|
||||||
- share
|
|
||||||
variables:
|
variables:
|
||||||
ARTIFACTS_JOB: "fw_dns_plug_release"
|
BUILD_TYPE: Debug
|
||||||
PROJECT_NAME: "fw-dns-plug"
|
PACKAGE: 1
|
||||||
USER_DEFINE: "release"
|
UPLOAD_RPM: 1
|
||||||
|
PULP3_REPO_NAME: tsg-stable-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: tsg-stable-x86_64.el7
|
||||||
|
extends: .build_by_travis
|
||||||
|
artifacts:
|
||||||
|
name: "fw_dns_plug-$CI_COMMIT_REF_NAME-release"
|
||||||
|
paths:
|
||||||
|
- build/*.rpm
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
|
||||||
- /bin/bash -x ./autorelease.sh $CI_API_V4_URL $CI_PROJECT_URL $CI_PROJECT_ID $CI_TOKEN $CI_COMMIT_TAG $ARTIFACTS_JOB $PROJECT_NAME $USER_DEFINE
|
release_build_release:
|
||||||
|
stage: build
|
||||||
fw_dns_plug_debug-release:
|
|
||||||
stage: release
|
|
||||||
image: git.mesalab.cn:7443/tango/tsg_master:master
|
|
||||||
tags:
|
|
||||||
- share
|
|
||||||
variables:
|
variables:
|
||||||
ARTIFACTS_JOB: "fw_dns_plug_debug"
|
BUILD_TYPE: RelWithDebInfo
|
||||||
PROJECT_NAME: "fw-dns-plug"
|
ENABLE_DEVEL_SWITCH: "ON"
|
||||||
USER_DEFINE: "debug"
|
PACKAGE: 1
|
||||||
|
UPLOAD_RPM: 1
|
||||||
|
UPLOAD_SYMBOL_FILES: 1
|
||||||
|
SYMBOL_TARGET: fw_dns_plug
|
||||||
|
PULP3_REPO_NAME: tsg-stable-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: tsg-stable-x86_64.el7
|
||||||
|
extends: .build_by_travis
|
||||||
|
artifacts:
|
||||||
|
name: "fw_dns_plug-$CI_COMMIT_REF_NAME-release"
|
||||||
|
paths:
|
||||||
|
- build/*.rpm
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
|
||||||
- /bin/bash -x ./autorelease.sh $CI_API_V4_URL $CI_PROJECT_URL $CI_PROJECT_ID $CI_TOKEN $CI_COMMIT_TAG $ARTIFACTS_JOB $PROJECT_NAME $USER_DEFINE
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
cmake_minimum_required (VERSION 2.8)
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
|
||||||
|
set(lib_name fw_dns_plug)
|
||||||
project(fw_dns_plug)
|
project(fw_dns_plug)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||||
@@ -33,41 +34,4 @@ set(CMAKE_INSTALL_PREFIX /home/mesasoft/sapp_run)
|
|||||||
|
|
||||||
add_subdirectory (src)
|
add_subdirectory (src)
|
||||||
|
|
||||||
set(CONFLIST /plug/conflist.inf)
|
|
||||||
set(MASTER_INF "./plug/business/fw_dns_plug/fw_dns_plug.inf")
|
|
||||||
set(MAIN_CONF /tsgconf/main.conf)
|
|
||||||
|
|
||||||
file(WRITE ${PROJECT_SOURCE_DIR}/install.sh "#!/bin/sh\r\n")
|
|
||||||
file(WRITE ${PROJECT_SOURCE_DIR}/uninstall.sh "#!/bin/sh\r\n")
|
|
||||||
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "DST=\${RPM_INSTALL_PREFIX}\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/uninstall.sh "DST=\${RPM_INSTALL_PREFIX}\r\n")
|
|
||||||
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "mkdir -p \${DST}/plug/business/\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/uninstall.sh "mkdir -p \${DST}/plug/business/\r\n")
|
|
||||||
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "touch \${DST}${CONFLIST}\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/uninstall.sh "touch \${DST}${CONFLIST}\r\n")
|
|
||||||
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "mkdir -p \${DST}/tsgconf/\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/uninstall.sh "mkdir -p \${DST}/tsgconf/\r\n")
|
|
||||||
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "touch \${DST}${MAIN_CONF}\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/uninstall.sh "touch \${DST}${MAIN_CONF}\r\n")
|
|
||||||
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "if [[ -z `grep -rn 'fw_dns_plug.inf' \${DST}${CONFLIST}` ]];then\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "\tsed -i '/\\[business\\]/a\\${MASTER_INF}' \${DST}${CONFLIST}\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "fi\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/uninstall.sh "sed -i '/fw_dns_plug.inf/d' \${DST}${CONFLIST}\r\n")
|
|
||||||
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "if [[ -z `grep -rn '\\[DNS_PLUG\\]' \${DST}${MAIN_CONF}` ]];then\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "\tsed -i '1i\\\\[DNS_PLUG\\]' \${DST}${MAIN_CONF}\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "\tsed -i '/\\[DNS_PLUG\\]/a\\LOG_LEVEL=30' \${DST}${MAIN_CONF}\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "\tsed -i '/\\[DNS_PLUG\\]/a\\LOG_PATH=./tsglog/fw_dns_plug/fw_dns_plug' \${DST}${MAIN_CONF}\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/install.sh "fi\r\n")
|
|
||||||
file(APPEND ${PROJECT_SOURCE_DIR}/uninstall.sh "sed -i '/\\[DNS_PLUG\\]/,+2d' \${DST}${MAIN_CONF}\r\n")
|
|
||||||
|
|
||||||
SET(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/install.sh")
|
|
||||||
SET(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/uninstall.sh")
|
|
||||||
|
|
||||||
include(Package)
|
include(Package)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
PLUGNAME=FW_DNS_PLUG
|
PLUGNAME=FW_DNS_PLUG
|
||||||
SO_PATH=./plug/business/fw_dns_plug/fw_dns_plug.so
|
SO_PATH=./plug/business/fw_dns_plug/fw_dns_plug.so
|
||||||
INIT_FUNC=FW_DNS_PLUG_INIT
|
INIT_FUNC=FW_DNS_PLUG_INIT
|
||||||
DESTROY_FUNC=FW_DNS_PLUG_DESTORY
|
DESTROY_FUNC=FW_DNS_PLUG_DESTROY
|
||||||
|
|
||||||
[DNS]
|
[DNS]
|
||||||
FUNC_FLAG=DNS_ALL
|
FUNC_FLAG=DNS_ALL
|
||||||
|
|||||||
48
ci/get-nprocessors.sh
Normal file
48
ci/get-nprocessors.sh
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2017 Google Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions are
|
||||||
|
# met:
|
||||||
|
#
|
||||||
|
# * Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# * Redistributions in binary form must reproduce the above
|
||||||
|
# copyright notice, this list of conditions and the following disclaimer
|
||||||
|
# in the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# * Neither the name of Google Inc. nor the names of its
|
||||||
|
# contributors may be used to endorse or promote products derived from
|
||||||
|
# this software without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
# This file is typically sourced by another script.
|
||||||
|
# if possible, ask for the precise number of processors,
|
||||||
|
# otherwise take 2 processors as reasonable default; see
|
||||||
|
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
|
||||||
|
if [ -x /usr/bin/getconf ]; then
|
||||||
|
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
|
||||||
|
else
|
||||||
|
NPROCESSORS=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
|
||||||
|
# crashes if parallelized too much (maybe memory consumption problem),
|
||||||
|
# so limit to 4 processors for the time being.
|
||||||
|
if [ $NPROCESSORS -gt 4 ] ; then
|
||||||
|
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
|
||||||
|
NPROCESSORS=4
|
||||||
|
fi
|
||||||
3
ci/perpare_pulp3_netrc.sh
Normal file
3
ci/perpare_pulp3_netrc.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -evx
|
||||||
|
echo "machine ${PULP3_SERVER_URL}\nlogin ${PULP3_SERVER_LOGIN}\npassword ${PULP3_SERVER_PASSWORD}\n" > ~/.netrc
|
||||||
72
ci/travis.sh
Normal file
72
ci/travis.sh
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -evx
|
||||||
|
|
||||||
|
chmod +x ci/get-nprocessors.sh
|
||||||
|
. ci/get-nprocessors.sh
|
||||||
|
|
||||||
|
# if possible, ask for the precise number of processors,
|
||||||
|
# otherwise take 2 processors as reasonable default; see
|
||||||
|
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
|
||||||
|
if [ -x /usr/bin/getconf ]; then
|
||||||
|
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
|
||||||
|
else
|
||||||
|
NPROCESSORS=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
|
||||||
|
# crashes if parallelized too much (maybe memory consumption problem),
|
||||||
|
# so limit to 4 processors for the time being.
|
||||||
|
if [ $NPROCESSORS -gt 4 ] ; then
|
||||||
|
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
|
||||||
|
NPROCESSORS=4
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tell make to use the processors. No preceding '-' required.
|
||||||
|
MAKEFLAGS="j${NPROCESSORS}"
|
||||||
|
export MAKEFLAGS
|
||||||
|
|
||||||
|
env | sort
|
||||||
|
|
||||||
|
# Set default values to OFF for these variables if not specified.
|
||||||
|
: "${NO_EXCEPTION:=OFF}"
|
||||||
|
: "${NO_RTTI:=OFF}"
|
||||||
|
: "${COMPILER_IS_GNUCXX:=OFF}"
|
||||||
|
|
||||||
|
# Install dependency from YUM
|
||||||
|
if [ -n "${INSTALL_DEPENDENCY_LIBRARY}" ]; then
|
||||||
|
yum install -y $INSTALL_DEPENDENCY_LIBRARY
|
||||||
|
source /etc/profile.d/framework.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $ASAN_OPTION ];then
|
||||||
|
source /opt/rh/devtoolset-7/enable
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir build || true
|
||||||
|
cd build
|
||||||
|
|
||||||
|
cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \
|
||||||
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||||
|
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
|
||||||
|
-DASAN_OPTION=$ASAN_OPTION \
|
||||||
|
-DVERSION_DAILY_BUILD=$TESTING_VERSION_BUILD \
|
||||||
|
..
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
if [ -n "${PACKAGE}" ]; then
|
||||||
|
make package
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${UPLOAD_RPM}" ]; then
|
||||||
|
cp ~/rpm_upload_tools.py ./
|
||||||
|
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
|
||||||
|
rpm -i $SYMBOL_TARGET*debuginfo*.rpm
|
||||||
|
_symbol_file=`find /usr/lib/debug/ -name "$SYMBOL_TARGET*.so*.debug"`
|
||||||
|
cp $_symbol_file ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
|
||||||
|
sentry-cli upload-dif -t elf ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
|
||||||
|
fi
|
||||||
|
|
||||||
@@ -1,41 +1,57 @@
|
|||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-debug")
|
set(MY_RPM_NAME_PREFIX "${lib_name}-debug")
|
||||||
else()
|
else()
|
||||||
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
|
set(MY_RPM_NAME_PREFIX "${lib_name}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "Package: ${CPACK_PACKAGE_NAME}")
|
message(STATUS "Package: ${MY_RPM_NAME_PREFIX}")
|
||||||
|
|
||||||
set(CPACK_PACKAGE_VECDOR "MESA")
|
set(CPACK_PACKAGE_VECDOR "MESA")
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
|
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
|
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
|
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
|
||||||
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
|
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
|
||||||
|
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}")
|
||||||
|
execute_process(COMMAND bash -c "echo -ne \"`uname -r | awk -F'.' '{print $5\".\"$6\".\"$7}'`\"" OUTPUT_VARIABLE SYSTEM_VERSION)
|
||||||
|
|
||||||
set(CPACK_COMPONENTS_ALL devel)
|
execute_process(COMMAND sh changelog.sh ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/cmake)
|
||||||
set(CPACK_RPM_PACKAGE_DEBUG 1)
|
SET(CPACK_RPM_CHANGELOG_FILE ${CMAKE_BINARY_DIR}/changelog.txt)
|
||||||
set(CPACK_RPM_COMPONENT_INSTALL OFF)
|
|
||||||
set(CPACK_RPM_DEVEL_FILE_NAME "${PROJECT_NAME}-devel.rpm")
|
|
||||||
set(CPACK_RPM_DEVEL_DEBUGINFO_FILE_NAME "${PROJECT_NAME}-devel-debuginfo.rpm")
|
|
||||||
|
|
||||||
# RPM Build
|
# RPM Build
|
||||||
set(CPACK_GENERATOR "RPM")
|
set(CPACK_GENERATOR "RPM")
|
||||||
set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON)
|
|
||||||
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
|
|
||||||
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
|
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
|
||||||
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
|
set(CPACK_RPM_PACKAGE_AUTOREQPROV "yes")
|
||||||
set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
|
set(CPACK_RPM_PACKAGE_RELEASE_LIBRARY "on")
|
||||||
set(CPACK_RPM_DEBUGINFO_PACKAGE ON)
|
set(CPACK_RPM_DEBUGINFO_PACKAGE "on")
|
||||||
|
set(CPACK_RPM_PACKAGE_DEBUG 1)
|
||||||
|
|
||||||
|
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
|
||||||
|
set(CPACK_RPM_PACKAGE_AUTOREQ "no")
|
||||||
|
|
||||||
|
set(CPACK_RPM_COMPONENT_INSTALL ON)
|
||||||
|
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
|
||||||
|
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
|
||||||
|
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
|
||||||
|
|
||||||
|
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE)
|
||||||
|
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
|
||||||
|
set(CPACK_RPM_LIBRARIES_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||||
|
set(CPACK_RPM_LIBRARIES_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||||
|
|
||||||
|
set(CPACK_COMPONENT_LIBRARIES_GROUP "libraries")
|
||||||
|
set(CPACK_COMPONENT_PROFILE_GROUP "libraries")
|
||||||
|
|
||||||
|
set(CPACK_RPM_HEADER_PACKAGE_CONFLICTS ${CPACK_RPM_HEADER_PACKAGE_NAME})
|
||||||
|
|
||||||
|
set(CPACK_COMPONENTS_ALL LIBRARIES PROFILE)
|
||||||
|
|
||||||
|
SET(CPACK_RPM_LIBRARIES_PRE_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/cmake/PreInstall.sh")
|
||||||
|
SET(CPACK_RPM_LIBRARIES_PRE_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/cmake/PreUninstall.sh")
|
||||||
|
|
||||||
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")
|
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")
|
||||||
|
|
||||||
# Must uninstall the debug package before install release package
|
# Must uninstall the debug package before install release package
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
set(CPACK_RPM_PACKAGE_CONFLICTS ${MY_RPM_NAME_PREFIX})
|
||||||
set(CPACK_RPM_PACKAGE_CONFLICTS "${PROJECT_NAME}-debug")
|
|
||||||
else()
|
|
||||||
set(CPACK_RPM_PACKAGE_CONFLICTS ${PROJECT_NAME})
|
|
||||||
# set(CPACK_STRIP_FILES TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
# set(CPACK_STRIP_FILES TRUE)
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
|||||||
14
cmake/PreInstall.sh
Normal file
14
cmake/PreInstall.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
DST=${RPM_INSTALL_PREFIX}
|
||||||
|
mkdir -p ${DST}/plug/business/
|
||||||
|
touch ${DST}/plug/conflist.inf
|
||||||
|
mkdir -p ${DST}/tsgconf/
|
||||||
|
touch ${DST}/tsgconf/main.conf
|
||||||
|
if [[ -z `grep -rn 'fw_dns_plug.inf' ${DST}/plug/conflist.inf` ]];then
|
||||||
|
sed -i '/\[business\]/a\./plug/business/fw_dns_plug/fw_dns_plug.inf' ${DST}/plug/conflist.inf
|
||||||
|
fi
|
||||||
|
if [[ -z `grep -rn '\[DNS_PLUG\]' ${DST}/tsgconf/main.conf` ]];then
|
||||||
|
sed -i '1i\\[DNS_PLUG\]' ${DST}/tsgconf/main.conf
|
||||||
|
sed -i '/\[DNS_PLUG\]/a\LOG_LEVEL=30' ${DST}/tsgconf/main.conf
|
||||||
|
sed -i '/\[DNS_PLUG\]/a\LOG_PATH=./tsglog/fw_dns_plug/fw_dns_plug' ${DST}/tsgconf/main.conf
|
||||||
|
fi
|
||||||
12
cmake/PreUninstall.sh
Normal file
12
cmake/PreUninstall.sh
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
if [ $1 == 0 ]; then
|
||||||
|
DST=${RPM_INSTALL_PREFIX}
|
||||||
|
|
||||||
|
mkdir -p ${DST}/plug/business/
|
||||||
|
touch ${DST}/plug/conflist.inf
|
||||||
|
mkdir -p ${DST}/tsgconf/
|
||||||
|
touch ${DST}/tsgconf/main.conf
|
||||||
|
|
||||||
|
sed -i '/fw_dns_plug.inf/d' ${DST}/plug/conflist.inf
|
||||||
|
sed -i '/\[DNS_PLUG\]/,+2d' ${DST}/tsgconf/main.conf
|
||||||
|
fi
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
# Using autorevision.sh to generate version information
|
# Using autorevision.sh to generate version information
|
||||||
|
|
||||||
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
|
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
|
||||||
@@ -18,6 +19,11 @@ include(${__VERSION_CONFIG})
|
|||||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}")
|
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}")
|
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}")
|
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}")
|
||||||
|
string(REGEX REPLACE "[T\\:\\+\\-]" "" VERSION_DATE "${VCS_DATE}")
|
||||||
|
|
||||||
|
if(VERSION_DAILY_BUILD)
|
||||||
|
set(VERSION_PATCH ${VERSION_PATCH}.${VERSION_DATE})
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT VERSION_MAJOR)
|
if(NOT VERSION_MAJOR)
|
||||||
set(VERSION_MAJOR 1)
|
set(VERSION_MAJOR 1)
|
||||||
@@ -37,7 +43,12 @@ set(VERSION_BUILD "${VCS_SHORT_HASH}")
|
|||||||
# print information
|
# print information
|
||||||
message(STATUS "Version: ${VERSION}-${VERSION_BUILD}")
|
message(STATUS "Version: ${VERSION}-${VERSION_BUILD}")
|
||||||
|
|
||||||
set(GIT_VERSION
|
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to TRUE or FALSE" TRUE)
|
||||||
"${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_TAG}-${VCS_DATE}")
|
|
||||||
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
if(DEFINE_GIT_VERSION)
|
||||||
add_definitions(-DGIT_VERSION=${GIT_VERSION})
|
set(GIT_VERSION
|
||||||
|
"${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_TAG}-${VCS_DATE}")
|
||||||
|
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
||||||
|
|
||||||
|
add_definitions(-DGIT_VERSION=${GIT_VERSION})
|
||||||
|
endif()
|
||||||
|
|||||||
4
cmake/changelog.sh
Normal file
4
cmake/changelog.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
work_path=$1
|
||||||
|
branch=`git status | grep branch | awk '{print $NF}'`
|
||||||
|
git log --branches=$branch --no-merges --date=local --show-signature --pretty="* %ad %an %ae %nhash: %H%ncommit:%n%B" | awk -F"-" '{print "- "$0}' | sed 's/- \*/\*/g' | sed 's/- $//g' | sed 's/-/ -/g' | sed 's/[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}//g' > $work_path/changelog.txt
|
||||||
@@ -8,12 +8,12 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
|
|||||||
include_directories(/opt/MESA/include/)
|
include_directories(/opt/MESA/include/)
|
||||||
include_directories(/opt/MESA/include/tsg/)
|
include_directories(/opt/MESA/include/tsg/)
|
||||||
|
|
||||||
set(FW_DNS_PLUG_DEPEND_DYN_LIB MESA_handle_logger MESA_prof_load maatframe pthread MESA_field_stat2)
|
set(FW_DNS_PLUG_DEPEND_DYN_LIB maatframe pthread MESA_field_stat2)
|
||||||
|
|
||||||
add_library(fw_dns_plug SHARED ${SRC})
|
add_library(fw_dns_plug SHARED ${SRC})
|
||||||
target_link_libraries(fw_dns_plug ${FW_DNS_PLUG_DEPEND_DYN_LIB})
|
target_link_libraries(fw_dns_plug ${FW_DNS_PLUG_DEPEND_DYN_LIB})
|
||||||
set_target_properties(fw_dns_plug PROPERTIES PREFIX "")
|
set_target_properties(fw_dns_plug PROPERTIES PREFIX "")
|
||||||
|
|
||||||
install(TARGETS fw_dns_plug DESTINATION ${CMAKE_INSTALL_PREFIX}/plug/business/fw_dns_plug)
|
install(TARGETS fw_dns_plug LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/plug/business/fw_dns_plug COMPONENT LIBRARIES)
|
||||||
install(FILES ../bin/fw_dns_plug.inf DESTINATION ${CMAKE_INSTALL_PREFIX}/plug/business/fw_dns_plug)
|
install(FILES ../bin/fw_dns_plug.inf DESTINATION ${CMAKE_INSTALL_PREFIX}/plug/business/fw_dns_plug COMPONENT PROFILE)
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,39 @@
|
|||||||
#include <MESA/MESA_handle_logger.h>
|
#include <MESA/MESA_handle_logger.h>
|
||||||
|
|
||||||
#include "tsg_rule.h"
|
#include "tsg_rule.h"
|
||||||
|
#include "tsg_label.h"
|
||||||
#include "tsg_send_log.h"
|
#include "tsg_send_log.h"
|
||||||
#include "fw_dns_plug.h"
|
#include "fw_dns_plug.h"
|
||||||
#include "tsg_statistic.h"
|
#include "tsg_statistic.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define GIT_VERSION_CATTER(v) __attribute__((__used__)) const char * GIT_VERSION_##v = NULL
|
||||||
|
#define GIT_VERSION_EXPEND(v) GIT_VERSION_CATTER(v)
|
||||||
|
|
||||||
|
/* VERSION TAG */
|
||||||
|
#ifdef GIT_VERSION
|
||||||
|
GIT_VERSION_EXPEND(GIT_VERSION);
|
||||||
|
#else
|
||||||
|
static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
|
||||||
|
#endif
|
||||||
|
#undef GIT_VERSION_CATTER
|
||||||
|
#undef GIT_VERSION_EXPEND
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRINTADDR
|
||||||
|
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char FW_DNS_PLUG_VERSION_20210607=0;
|
||||||
|
struct fw_dns_plug g_fw_dns_plug_info;
|
||||||
char *g_fw_dns_conffile=(char *)"tsgconf/main.conf";
|
char *g_fw_dns_conffile=(char *)"tsgconf/main.conf";
|
||||||
char FW_DNS_PLUG_VERSION_20191220=0;
|
|
||||||
struct _fw_dns_plug g_fw_dns_plug_info;
|
|
||||||
|
|
||||||
static int get_answer_ttl(cJSON *object)
|
static int get_answer_ttl(cJSON *object)
|
||||||
{
|
{
|
||||||
@@ -23,6 +49,11 @@ static int get_answer_ttl(cJSON *object)
|
|||||||
int max=0;
|
int max=0;
|
||||||
cJSON *item=NULL;
|
cJSON *item=NULL;
|
||||||
|
|
||||||
|
if(object==NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
item=cJSON_GetObjectItem(object, "min");
|
item=cJSON_GetObjectItem(object, "min");
|
||||||
min=item->valueint;
|
min=item->valueint;
|
||||||
|
|
||||||
@@ -56,62 +87,97 @@ static cJSON * get_answer_records(cJSON *object, int qtype)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maat_rule_t *p_result, const void *a_packet)
|
static int build_answer_records(struct streaminfo *a_stream, dns_info_t *dns_info, cJSON *object, cheat_pkt_opt_t *cheat_opt, int cheat_opt_num)
|
||||||
{
|
{
|
||||||
|
int ttl=0;
|
||||||
int record_id=0;
|
int record_id=0;
|
||||||
int i=0,used_num=0;
|
int i=0,used_num=0;
|
||||||
int answer_size=0,ret=0;
|
int answer_size=0;
|
||||||
int payload_len=0,ttl=0;
|
cJSON *one_record=NULL;
|
||||||
|
cJSON *a_item=NULL;
|
||||||
|
cJSON *answer_array=NULL;
|
||||||
|
int answer_type=DNS_TYPE_UNKNOWN;
|
||||||
|
|
||||||
|
answer_array=get_answer_records(object, dns_info->query_question.qtype);
|
||||||
|
if(answer_array!=NULL)
|
||||||
|
{
|
||||||
|
memset(cheat_opt, 0, sizeof(cheat_pkt_opt_t)*cheat_opt_num);
|
||||||
|
answer_size=cJSON_GetArraySize(answer_array);
|
||||||
|
for(i=0; i<answer_size; i++)
|
||||||
|
{
|
||||||
|
one_record=cJSON_GetArrayItem(answer_array, i);
|
||||||
|
a_item=cJSON_GetObjectItem(one_record, "atype");
|
||||||
|
if(a_item==NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
answer_type=fw_dns_type2index(a_item->valuestring);
|
||||||
|
a_item=cJSON_GetObjectItem(one_record, "ttl");
|
||||||
|
ttl=get_answer_ttl(a_item);
|
||||||
|
|
||||||
|
a_item=cJSON_GetObjectItem(one_record, "value");
|
||||||
|
if(a_item!=NULL)
|
||||||
|
{
|
||||||
|
cheat_opt[used_num].res_type=answer_type;
|
||||||
|
cheat_opt[used_num].cfg_type=answer_type;
|
||||||
|
cheat_opt[used_num].ttl=ttl;
|
||||||
|
|
||||||
|
switch(answer_type)
|
||||||
|
{
|
||||||
|
case DNS_TYPE_A:
|
||||||
|
cheat_opt[used_num].res_len=sizeof(unsigned int);
|
||||||
|
inet_pton(AF_INET, a_item->valuestring, (void *)cheat_opt[used_num].res_info);
|
||||||
|
break;
|
||||||
|
case DNS_TYPE_AAAA:
|
||||||
|
cheat_opt[used_num].res_len=IPV6_ADDR_LEN;
|
||||||
|
inet_pton(AF_INET6, a_item->valuestring, (void *)cheat_opt[used_num].res_info);
|
||||||
|
break;
|
||||||
|
case DNS_TYPE_NS:
|
||||||
|
case DNS_TYPE_TXT:
|
||||||
|
case DNS_TYPE_PTR:
|
||||||
|
case DNS_TYPE_CNAME:
|
||||||
|
cheat_opt[used_num].res_len=(strlen(a_item->valuestring) > sizeof(cheat_opt[used_num].res_info)-1) ? sizeof(cheat_opt[used_num].res_info)-1 : strlen(a_item->valuestring);
|
||||||
|
memcpy(cheat_opt[used_num].res_info, a_item->valuestring, cheat_opt[used_num].res_len);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
used_num++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
a_item=cJSON_GetObjectItem(one_record, "record_id");
|
||||||
|
record_id=a_item->valueint;
|
||||||
|
|
||||||
|
a_item=cJSON_GetObjectItem(one_record, "selected_num");
|
||||||
|
used_num+=dns_get_cheat_opt(record_id, a_item->valueint, ttl, answer_type, cheat_opt+used_num, cheat_opt_num-used_num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return used_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maat_rule_t *p_result, const void *a_packet)
|
||||||
|
{
|
||||||
|
int ret=0;
|
||||||
|
int payload_len=0;
|
||||||
|
int answer_records_num=0;
|
||||||
dns_hdr_t *dns_hdr = NULL;
|
dns_hdr_t *dns_hdr = NULL;
|
||||||
cJSON *item=NULL;
|
cJSON *item=NULL;
|
||||||
cJSON *a_item=NULL;
|
|
||||||
cJSON *object=NULL;
|
cJSON *object=NULL;
|
||||||
cJSON *answer_array=NULL;
|
|
||||||
char *tmp_buff=NULL;
|
char *tmp_buff=NULL;
|
||||||
unsigned char senddir=0;
|
unsigned char senddir=0;
|
||||||
char state=PROT_STATE_GIVEME;
|
char state=PROT_STATE_GIVEME;
|
||||||
int answer_type=DNS_TYPE_UNKNOWN;
|
|
||||||
int method_type=TSG_METHOD_TYPE_UNKNOWN;
|
int method_type=TSG_METHOD_TYPE_UNKNOWN;
|
||||||
cheat_pkt_opt_t cheat_opt[MAX_ANSWER_RECORDS_NUM];
|
cheat_pkt_opt_t cheat_opt[MAX_ANSWER_RECORDS_NUM];
|
||||||
unsigned char cheat_pkt_payload[MAX_CHEAT_PKT_PAYLOAD_LEN];
|
unsigned char cheat_pkt_payload[MAX_CHEAT_PKT_PAYLOAD_LEN];
|
||||||
|
|
||||||
if(p_result->serv_def_len<128)
|
tmp_buff=(char *)calloc(1, p_result->serv_def_len+1);
|
||||||
{
|
Maat_read_rule(g_tsg_maat_feather, p_result, MAAT_RULE_SERV_DEFINE, tmp_buff, p_result->serv_def_len);
|
||||||
object=cJSON_Parse(p_result->service_defined);
|
|
||||||
|
object=cJSON_Parse(tmp_buff);
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
|
||||||
RLOG_LV_DEBUG,
|
|
||||||
"DO_ACTION",
|
|
||||||
"Hit policy_id: %d service: %d action: %d user_reagion: %s domain: %s qtype: %d addr: %s",
|
|
||||||
p_result->config_id,
|
|
||||||
p_result->service_id,
|
|
||||||
p_result->action,
|
|
||||||
p_result->service_defined,
|
|
||||||
(char *)dns_info->query_question.qname,
|
|
||||||
dns_info->query_question.qtype,
|
|
||||||
printaddr(&a_stream->addr, a_stream->threadnum)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tmp_buff=(char *)calloc(1, p_result->serv_def_len+1);
|
|
||||||
Maat_read_rule(g_tsg_maat_feather, p_result, MAAT_RULE_SERV_DEFINE, tmp_buff, p_result->serv_def_len);
|
|
||||||
object=cJSON_Parse(tmp_buff);
|
|
||||||
|
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
|
||||||
RLOG_LV_DEBUG,
|
|
||||||
"DO_ACTION",
|
|
||||||
"Hit policy_id: %d service: %d action: %d user_reagion: %s domain: %s qtype: %d addr: %s",
|
|
||||||
p_result->config_id,
|
|
||||||
p_result->service_id,
|
|
||||||
p_result->action,
|
|
||||||
tmp_buff,
|
|
||||||
(char *)dns_info->query_question.qname,
|
|
||||||
dns_info->query_question.qtype,
|
|
||||||
printaddr(&a_stream->addr, a_stream->threadnum)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(object==NULL)
|
if(object==NULL)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
@@ -124,134 +190,117 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
|
|||||||
(tmp_buff==NULL) ? p_result->service_defined : tmp_buff,
|
(tmp_buff==NULL) ? p_result->service_defined : tmp_buff,
|
||||||
(char *)dns_info->query_question.qname,
|
(char *)dns_info->query_question.qname,
|
||||||
dns_info->query_question.qtype,
|
dns_info->query_question.qtype,
|
||||||
printaddr(&a_stream->addr, a_stream->threadnum)
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
);
|
);
|
||||||
|
method_type=TSG_METHOD_TYPE_DROP;
|
||||||
if(tmp_buff!=NULL)
|
|
||||||
{
|
|
||||||
free(tmp_buff);
|
|
||||||
tmp_buff=NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROT_STATE_GIVEME;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
item=cJSON_GetObjectItem(object, "method");
|
|
||||||
if(item!=NULL)
|
|
||||||
{
|
{
|
||||||
method_type=tsg_get_method_id(item->valuestring);
|
item=cJSON_GetObjectItem(object, "method");
|
||||||
|
if(item!=NULL)
|
||||||
|
{
|
||||||
|
method_type=tsg_get_method_id(item->valuestring);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(method_type)
|
switch(method_type)
|
||||||
{
|
{
|
||||||
case TSG_METHOD_TYPE_DROP:
|
case TSG_METHOD_TYPE_DROP:
|
||||||
state=PROT_STATE_DROPME|PROT_STATE_DROPPKT;
|
state=PROT_STATE_GIVEME|PROT_STATE_DROPPKT;
|
||||||
break;
|
break;
|
||||||
case TSG_METHOD_TYPE_REDIRECTION:
|
case TSG_METHOD_TYPE_REDIRECTION:
|
||||||
answer_array=get_answer_records(object, dns_info->query_question.qtype);
|
if(g_fw_dns_plug_info.mode==0 && dns_info->hdr_info.qr==1) //mirror
|
||||||
if(answer_array!=NULL)
|
|
||||||
{
|
{
|
||||||
memset(cheat_opt, 0, sizeof(cheat_opt));
|
break;
|
||||||
answer_size=cJSON_GetArraySize(answer_array);
|
|
||||||
for(i=0; i<answer_size; i++)
|
|
||||||
{
|
|
||||||
item=cJSON_GetArrayItem(answer_array, i);
|
|
||||||
a_item=cJSON_GetObjectItem(item, "atype");
|
|
||||||
answer_type=fw_dns_type2index(a_item->valuestring);
|
|
||||||
|
|
||||||
a_item=cJSON_GetObjectItem(item, "ttl");
|
|
||||||
ttl=get_answer_ttl(a_item);
|
|
||||||
|
|
||||||
a_item=cJSON_GetObjectItem(item, "value");
|
|
||||||
if(a_item!=NULL)
|
|
||||||
{
|
|
||||||
cheat_opt[used_num].res_type=answer_type;
|
|
||||||
cheat_opt[used_num].cfg_type=answer_type;
|
|
||||||
cheat_opt[used_num].ttl=ttl;
|
|
||||||
|
|
||||||
switch(answer_type)
|
|
||||||
{
|
|
||||||
case DNS_TYPE_A:
|
|
||||||
cheat_opt[used_num].res_len=sizeof(unsigned int);
|
|
||||||
inet_pton(AF_INET, a_item->valuestring, (void *)cheat_opt[used_num].res_info);
|
|
||||||
break;
|
|
||||||
case DNS_TYPE_AAAA:
|
|
||||||
cheat_opt[used_num].res_len=IPV6_ADDR_LEN;
|
|
||||||
inet_pton(AF_INET6, a_item->valuestring, (void *)cheat_opt[used_num].res_info);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cheat_opt[used_num].res_len=(strlen(a_item->valuestring) > sizeof(cheat_opt[used_num].res_info)-1) ? sizeof(cheat_opt[used_num].res_info)-1 : strlen(a_item->valuestring);
|
|
||||||
memcpy(cheat_opt[used_num].res_info, a_item->valuestring, cheat_opt[used_num].res_len);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
used_num++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
a_item=cJSON_GetObjectItem(object, "record_id");
|
|
||||||
record_id=a_item->valueint;
|
|
||||||
|
|
||||||
a_item=cJSON_GetObjectItem(object, "selected_num");
|
|
||||||
used_num+=get_cheat_opt(record_id, a_item->valueint, ttl, answer_type, cheat_opt+used_num, MAX_ANSWER_RECORDS_NUM-used_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(cheat_pkt_payload, 0, MAX_CHEAT_PKT_PAYLOAD_LEN);
|
|
||||||
|
|
||||||
dns_hdr = (dns_hdr_t *)cheat_pkt_payload;
|
|
||||||
dns_hdr->id = dns_info->hdr_info.id;
|
|
||||||
dns_hdr->qdcount = 1;
|
|
||||||
dns_hdr->ancount = used_num;
|
|
||||||
|
|
||||||
payload_len=build_cheat_pkt(cheat_pkt_payload, MAX_CHEAT_PKT_PAYLOAD_LEN, &dns_info->query_question, cheat_opt, used_num);
|
|
||||||
if(payload_len==-1)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
senddir = MESA_dir_reverse(a_stream->routedir);
|
|
||||||
ret=MESA_inject_pkt(a_stream, (const char *)cheat_pkt_payload, payload_len, (const char *)a_packet, senddir);
|
|
||||||
if(ret<0)
|
|
||||||
{
|
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
|
||||||
RLOG_LV_FATAL,
|
|
||||||
"SEND_CHEAT_PKT",
|
|
||||||
"Return of MESA_inject_pkt_feedback function is %d, qname: %s qtype: %d cfg_id: %d service: %d addr: %s",
|
|
||||||
ret,
|
|
||||||
dns_info->query_question.qname,
|
|
||||||
dns_info->query_question.qtype,
|
|
||||||
p_result->config_id,
|
|
||||||
p_result->service_id,
|
|
||||||
printaddr(&a_stream->addr, a_stream->threadnum)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
state=PROT_STATE_DROPME|PROT_STATE_DROPPKT;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(g_fw_dns_plug_info.mode==1 && dns_info->hdr_info.qr==0) //inline or transparent
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
answer_records_num=build_answer_records(a_stream, dns_info, object, cheat_opt, MAX_ANSWER_RECORDS_NUM);
|
||||||
|
if(answer_records_num<=0)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
RLOG_LV_FATAL,
|
RLOG_LV_FATAL,
|
||||||
"DO_ACTION",
|
"DO_ACTION",
|
||||||
"Hit policy_id: %d service: %d action: %d user_reagion: %s domain: %s qtype: %d addr: %s",
|
"Hit policy_id: %d service: %d action: %d user_region: %s domain: %s qtype: %d addr: %s",
|
||||||
p_result->config_id,
|
p_result->config_id,
|
||||||
p_result->service_id,
|
p_result->service_id,
|
||||||
p_result->action,
|
p_result->action,
|
||||||
(tmp_buff==NULL) ? p_result->service_defined : tmp_buff,
|
(tmp_buff==NULL) ? p_result->service_defined : tmp_buff,
|
||||||
(char *)dns_info->query_question.qname,
|
(char *)dns_info->query_question.qname,
|
||||||
dns_info->query_question.qtype,
|
dns_info->query_question.qtype,
|
||||||
printaddr(&a_stream->addr, a_stream->threadnum)
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
);
|
);
|
||||||
state=PROT_STATE_GIVEME;
|
state=PROT_STATE_GIVEME|PROT_STATE_DROPPKT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(cheat_pkt_payload, 0, MAX_CHEAT_PKT_PAYLOAD_LEN);
|
||||||
|
dns_hdr = (dns_hdr_t *)cheat_pkt_payload;
|
||||||
|
dns_hdr->id = dns_info->hdr_info.id;
|
||||||
|
dns_hdr->qdcount = 1;
|
||||||
|
dns_hdr->ancount = answer_records_num;
|
||||||
|
|
||||||
|
payload_len=build_cheat_pkt(cheat_pkt_payload, MAX_CHEAT_PKT_PAYLOAD_LEN, &dns_info->query_question, cheat_opt, answer_records_num);
|
||||||
|
if(payload_len==-1)
|
||||||
|
{
|
||||||
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
|
RLOG_LV_FATAL,
|
||||||
|
"DO_ACTION",
|
||||||
|
"Hit policy_id: %d service: %d action: %d build_cheat_pkt ret: %d addr: %s",
|
||||||
|
p_result->config_id,
|
||||||
|
p_result->service_id,
|
||||||
|
p_result->action,
|
||||||
|
payload_len,
|
||||||
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dns_info->hdr_info.qr==0)
|
||||||
|
{
|
||||||
|
senddir = MESA_dir_reverse(a_stream->routedir);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
senddir = a_stream->routedir;
|
||||||
|
}
|
||||||
|
ret=MESA_inject_pkt(a_stream, (const char *)cheat_pkt_payload, payload_len, (const char *)a_packet, senddir);
|
||||||
|
if(ret<0)
|
||||||
|
{
|
||||||
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
|
RLOG_LV_FATAL,
|
||||||
|
"SEND_CHEAT_PKT",
|
||||||
|
"Return of MESA_inject_pkt_feedback function is %d, qname: %s qtype: %d cfg_id: %d service: %d addr: %s",
|
||||||
|
ret,
|
||||||
|
dns_info->query_question.qname,
|
||||||
|
dns_info->query_question.qtype,
|
||||||
|
p_result->config_id,
|
||||||
|
p_result->service_id,
|
||||||
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
state=PROT_STATE_GIVEME|PROT_STATE_DROPPKT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(object!=NULL)
|
||||||
|
{
|
||||||
|
cJSON_Delete(object);
|
||||||
|
object=NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tmp_buff!=NULL)
|
||||||
|
{
|
||||||
|
free(tmp_buff);
|
||||||
|
tmp_buff=NULL;
|
||||||
|
}
|
||||||
|
|
||||||
cJSON_Delete(object);
|
|
||||||
object=NULL;
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,10 +351,11 @@ static int fw_dns_send_log(struct streaminfo *a_stream, dns_info_t *dns_info, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
cname=cJSON_PrintUnformatted(cname_array);
|
cname=cJSON_PrintUnformatted(cname_array);
|
||||||
if(strlen(cname)>0)
|
if(cname!=NULL && strlen(cname)>0)
|
||||||
{
|
{
|
||||||
TLD_append(handle, (char *)"dns_cname", (void *)cname, TLD_TYPE_STRING);
|
TLD_append(handle, (char *)"dns_cname", (void *)cname, TLD_TYPE_STRING);
|
||||||
free(cname);
|
cJSON_free(cname);
|
||||||
|
cname=NULL;
|
||||||
}
|
}
|
||||||
cJSON_Delete(cname_array);
|
cJSON_Delete(cname_array);
|
||||||
cname_array=NULL;
|
cname_array=NULL;
|
||||||
@@ -314,7 +364,11 @@ static int fw_dns_send_log(struct streaminfo *a_stream, dns_info_t *dns_info, st
|
|||||||
get_rr_str2json(object, dns_info, &dns_sec);
|
get_rr_str2json(object, dns_info, &dns_sec);
|
||||||
rr_buf=cJSON_PrintUnformatted(object);
|
rr_buf=cJSON_PrintUnformatted(object);
|
||||||
TLD_append(handle, (char *)"dns_rr", (void *)rr_buf, TLD_TYPE_STRING);
|
TLD_append(handle, (char *)"dns_rr", (void *)rr_buf, TLD_TYPE_STRING);
|
||||||
free(rr_buf);
|
|
||||||
|
cJSON_Delete(object);
|
||||||
|
object=NULL;
|
||||||
|
|
||||||
|
cJSON_free(rr_buf);
|
||||||
rr_buf=NULL;
|
rr_buf=NULL;
|
||||||
|
|
||||||
TLD_append(handle, (char *)"dns_sub", (void *)(long)dns_sec, TLD_TYPE_LONG);
|
TLD_append(handle, (char *)"dns_sub", (void *)(long)dns_sec, TLD_TYPE_LONG);
|
||||||
@@ -332,21 +386,28 @@ static int fw_dns_send_log(struct streaminfo *a_stream, dns_info_t *dns_info, st
|
|||||||
|
|
||||||
extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int thread_seq,struct streaminfo *a_stream,const void *a_packet)
|
extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int thread_seq,struct streaminfo *a_stream,const void *a_packet)
|
||||||
{
|
{
|
||||||
int ret=0,hit_num=0;
|
int i=0,ret=0,hit_num=0;
|
||||||
scan_status_t mid=NULL;
|
scan_status_t mid=NULL;
|
||||||
|
int category_id_num=0;
|
||||||
char state=PROT_STATE_GIVEME;
|
char state=PROT_STATE_GIVEME;
|
||||||
|
unsigned int category_id[MAX_CATEGORY_ID_NUM]={0};
|
||||||
struct Maat_rule_t result[MAX_RESULT_NUM], *p_result=NULL;
|
struct Maat_rule_t result[MAX_RESULT_NUM], *p_result=NULL;
|
||||||
dns_info_t *dns_info=(dns_info_t *)session_info->app_info;
|
dns_info_t *dns_info=(dns_info_t *)session_info->app_info;
|
||||||
|
|
||||||
if(dns_info==NULL || strlen((char *)dns_info->query_question.qname)==0)
|
if(dns_info==NULL || a_stream==NULL)
|
||||||
|
{
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strlen((char *)dns_info->query_question.qname)==0)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
RLOG_LV_FATAL,
|
RLOG_LV_DEBUG,
|
||||||
"DNS_PLUG",
|
"DNS_PLUG",
|
||||||
"Qname is %s, addr: %s",
|
"Qname is %s, addr: %s",
|
||||||
(dns_info==NULL) ? "NULL" : ((strlen((char *)dns_info->query_question.qname)==0) ? "NULL" : (char *)dns_info->query_question.qname),
|
(dns_info==NULL) ? "NULL" : ((strlen((char *)dns_info->query_question.qname)==0) ? "NULL" : (char *)dns_info->query_question.qname),
|
||||||
printaddr(&a_stream->addr, thread_seq)
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
);
|
);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,72 +415,107 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
|
|||||||
if(ret>0)
|
if(ret>0)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
RLOG_LV_DEBUG,
|
RLOG_LV_DEBUG,
|
||||||
"SCAN_NEST_ADDR",
|
"SCAN_NEST_ADDR",
|
||||||
"Hit policy_id: %d service: %d action: %d domain: %s qtype: %d addr: %s",
|
"Hit policy_id: %d service: %d action: %d domain: %s qtype: %d addr: %s",
|
||||||
result[hit_num].config_id,
|
result[hit_num].config_id,
|
||||||
result[hit_num].service_id,
|
result[hit_num].service_id,
|
||||||
result[hit_num].action,
|
result[hit_num].action,
|
||||||
(char *)dns_info->query_question.qname,
|
(char *)dns_info->query_question.qname,
|
||||||
dns_info->query_question.qtype,
|
dns_info->query_question.qtype,
|
||||||
printaddr(&a_stream->addr, thread_seq)
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
);
|
);
|
||||||
hit_num+=ret;
|
hit_num+=ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
RLOG_LV_DEBUG,
|
RLOG_LV_DEBUG,
|
||||||
"SCAN_NEST_ADDR",
|
"SCAN_NEST_ADDR",
|
||||||
"Scan domain: %s qtype: %d ret: %d addr: %s",
|
"Scan domain: %s qtype: %d ret: %d addr: %s",
|
||||||
(char *)dns_info->query_question.qname,
|
(char *)dns_info->query_question.qname,
|
||||||
dns_info->query_question.qtype,
|
dns_info->query_question.qtype,
|
||||||
ret,
|
ret,
|
||||||
printaddr(&a_stream->addr, thread_seq)
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret=Maat_full_scan_string(g_tsg_maat_feather,
|
ret=Maat_full_scan_string(g_tsg_maat_feather,
|
||||||
g_fw_dns_plug_info.table_qname_id,
|
g_fw_dns_plug_info.table_qname_id,
|
||||||
CHARSET_UTF8,
|
CHARSET_UTF8,
|
||||||
(char *)dns_info->query_question.qname,
|
(char *)dns_info->query_question.qname,
|
||||||
strlen((char *)dns_info->query_question.qname),
|
strlen((char *)dns_info->query_question.qname),
|
||||||
result+hit_num,
|
result+hit_num,
|
||||||
NULL,
|
NULL,
|
||||||
MAX_RESULT_NUM-hit_num,
|
MAX_RESULT_NUM-hit_num,
|
||||||
&mid,
|
&mid,
|
||||||
thread_seq);
|
thread_seq
|
||||||
|
);
|
||||||
|
|
||||||
if(ret>0)
|
if(ret>0)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
RLOG_LV_DEBUG,
|
RLOG_LV_DEBUG,
|
||||||
"SCAN_DOMAIN",
|
"SCAN_DOMAIN",
|
||||||
"Hit domain: %s qtype: %d policy_id: %d service: %d action: %d addr: %s",
|
"Hit domain: %s qtype: %d policy_id: %d service: %d action: %d addr: %s",
|
||||||
(char *)dns_info->query_question.qname,
|
(char *)dns_info->query_question.qname,
|
||||||
dns_info->query_question.qtype,
|
dns_info->query_question.qtype,
|
||||||
result[hit_num].config_id,
|
result[hit_num].config_id,
|
||||||
result[hit_num].service_id,
|
result[hit_num].service_id,
|
||||||
result[hit_num].action,
|
result[hit_num].action,
|
||||||
printaddr(&a_stream->addr, thread_seq)
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
);
|
);
|
||||||
hit_num+=ret;
|
hit_num+=ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
RLOG_LV_DEBUG,
|
RLOG_LV_DEBUG,
|
||||||
"SCAN_DOMAIN",
|
"SCAN_DOMAIN",
|
||||||
"Scan domain: %s qtype: %d ret: %d addr: %s",
|
"Scan domain: %s qtype: %d ret: %d addr: %s",
|
||||||
(char *)dns_info->query_question.qname,
|
(char *)dns_info->query_question.qname,
|
||||||
dns_info->query_question.qtype,
|
dns_info->query_question.qtype,
|
||||||
ret,
|
ret,
|
||||||
printaddr(&a_stream->addr, thread_seq)
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
category_id_num=tsg_get_fqdn_category_id(g_tsg_maat_feather, (char *)dns_info->query_question.qname, category_id, MAX_CATEGORY_ID_NUM, g_fw_dns_plug_info.logger, thread_seq);
|
||||||
|
for(i=0; i< category_id_num; i++)
|
||||||
|
{
|
||||||
|
ret=Maat_scan_intval(g_tsg_maat_feather, g_fw_dns_plug_info.table_qname_id, (unsigned int)category_id[i], result+hit_num,MAX_RESULT_NUM-hit_num, &mid, thread_seq);
|
||||||
|
if(ret>0)
|
||||||
|
{
|
||||||
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
|
RLOG_LV_DEBUG,
|
||||||
|
"SCAN_FQDN_CAT_ID",
|
||||||
|
"Hit qname: %s category id: %d policy_id: %d service: %d action: %d addr: %s",
|
||||||
|
(char *)dns_info->query_question.qname,
|
||||||
|
category_id[i],
|
||||||
|
result[hit_num].config_id,
|
||||||
|
result[hit_num].service_id,
|
||||||
|
result[hit_num].action,
|
||||||
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
|
);
|
||||||
|
hit_num+=ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
|
||||||
|
RLOG_LV_DEBUG,
|
||||||
|
"SCAN_DOMAIN",
|
||||||
|
"Scan domain: %s category id: %d ret: %d addr: %s",
|
||||||
|
(char *)dns_info->query_question.qname,
|
||||||
|
category_id[i],
|
||||||
|
ret,
|
||||||
|
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(hit_num>0)
|
if(hit_num>0)
|
||||||
{
|
{
|
||||||
p_result=tsg_fetch_deny_rule(result, hit_num);
|
p_result=tsg_fetch_deny_rule(result, hit_num);
|
||||||
@@ -446,20 +542,19 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
|
|||||||
|
|
||||||
extern "C" int FW_DNS_PLUG_INIT(void)
|
extern "C" int FW_DNS_PLUG_INIT(void)
|
||||||
{
|
{
|
||||||
int level=30,ret=0;
|
int ret=0,len=0;
|
||||||
char log_path[256]={0};
|
|
||||||
memset(&g_fw_dns_plug_info, 0, sizeof(g_fw_dns_plug_info));
|
memset(&g_fw_dns_plug_info, 0, sizeof(g_fw_dns_plug_info));
|
||||||
|
|
||||||
MESA_load_profile_int_def(g_fw_dns_conffile, "DNS_PLUG", "LOG_LEVEL", &level, 30);
|
MESA_load_profile_int_def(g_fw_dns_conffile, "DNS_PLUG", "LOG_LEVEL", &g_fw_dns_plug_info.level, RLOG_LV_FATAL);
|
||||||
MESA_load_profile_string_def(g_fw_dns_conffile, "DNS_PLUG", "LOG_PATH", log_path, sizeof(log_path), "tsglog/fw_dns_plug/fw_dns_plug");
|
MESA_load_profile_string_def(g_fw_dns_conffile, "DNS_PLUG", "LOG_PATH", g_fw_dns_plug_info.log_path, sizeof(g_fw_dns_plug_info.log_path), "tsglog/fw_dns_plug/fw_dns_plug");
|
||||||
|
|
||||||
|
|
||||||
MESA_load_profile_string_def(g_fw_dns_conffile, "DNS_PLUG", "TABLE_QNAME", g_fw_dns_plug_info.table_qname, MAX_TABLE_NAME_LEN, "TSG_FIELD_DNS_QNAME");
|
MESA_load_profile_string_def(g_fw_dns_conffile, "DNS_PLUG", "TABLE_QNAME", g_fw_dns_plug_info.table_qname, MAX_TABLE_NAME_LEN, "TSG_FIELD_DNS_QNAME");
|
||||||
|
|
||||||
g_fw_dns_plug_info.logger=MESA_create_runtime_log_handle(log_path, level);
|
g_fw_dns_plug_info.logger=MESA_create_runtime_log_handle(g_fw_dns_plug_info.log_path, g_fw_dns_plug_info.level);
|
||||||
if(g_fw_dns_plug_info.logger==NULL)
|
if(g_fw_dns_plug_info.logger==NULL)
|
||||||
{
|
{
|
||||||
printf("MESA_create_runtime_log_handle failed, log_path: %s level: %d", (log_path==NULL) ? NULL : log_path, level);
|
printf("MESA_create_runtime_log_handle failed, log_path: %s level: %d", (g_fw_dns_plug_info.log_path==NULL) ? NULL : g_fw_dns_plug_info.log_path, g_fw_dns_plug_info.level);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,12 +570,26 @@ extern "C" int FW_DNS_PLUG_INIT(void)
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len=sizeof(g_fw_dns_plug_info.s_mode);
|
||||||
|
ret=sapp_get_platform_opt(SPO_DEPLOYMENT_MODE_STR, g_fw_dns_plug_info.s_mode, &len);
|
||||||
|
if(ret>=0)
|
||||||
|
{
|
||||||
|
if((memcmp(g_fw_dns_plug_info.s_mode, "mirror", strlen(g_fw_dns_plug_info.s_mode)))==0 || (memcmp(g_fw_dns_plug_info.s_mode, "dumpfile", strlen(g_fw_dns_plug_info.s_mode)))==0)
|
||||||
|
{
|
||||||
|
g_fw_dns_plug_info.mode=0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_fw_dns_plug_info.mode=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" void FW_DNS_PLUG_DESTORY(void)
|
extern "C" void FW_DNS_PLUG_DESTROY(void)
|
||||||
{
|
{
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,14 @@
|
|||||||
|
|
||||||
#define MAX_ANSWER_RECORDS_NUM 32
|
#define MAX_ANSWER_RECORDS_NUM 32
|
||||||
|
|
||||||
struct _fw_dns_plug
|
struct fw_dns_plug
|
||||||
{
|
{
|
||||||
|
int mode;
|
||||||
|
int level;
|
||||||
int table_qname_id;
|
int table_qname_id;
|
||||||
char table_qname[MAX_TABLE_NAME_LEN];
|
char table_qname[MAX_TABLE_NAME_LEN];
|
||||||
|
char s_mode[MAX_TABLE_NAME_LEN];
|
||||||
|
char log_path[MAX_TABLE_NAME_LEN*2];
|
||||||
void *logger;
|
void *logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include <MESA/stream.h>
|
#include <MESA/stream.h>
|
||||||
@@ -12,10 +13,10 @@
|
|||||||
#include "tsg_rule.h"
|
#include "tsg_rule.h"
|
||||||
#include "fw_dns_rule.h"
|
#include "fw_dns_rule.h"
|
||||||
|
|
||||||
fw_dns_rule_t g_fw_dns_rule_info;
|
struct fw_dns_rule g_fw_dns_rule_info;
|
||||||
char FW_DNS_RULE_VERSION_20191201=0;
|
char FW_DNS_RULE_VERSION_20191201=0;
|
||||||
|
|
||||||
struct _dns_str2idx str2index[]={{DNS_TYPE_CNAME, 5, (char *)"CNAME"},
|
struct dns_str2idx str2index[]={{DNS_TYPE_CNAME, 5, (char *)"CNAME"},
|
||||||
{DNS_TYPE_MX, 2, (char *)"MX"},
|
{DNS_TYPE_MX, 2, (char *)"MX"},
|
||||||
{DNS_TYPE_A, 1, (char *)"A"},
|
{DNS_TYPE_A, 1, (char *)"A"},
|
||||||
{DNS_TYPE_NS, 2, (char *)"NS"},
|
{DNS_TYPE_NS, 2, (char *)"NS"},
|
||||||
@@ -28,7 +29,7 @@ int fw_dns_type2index(char *type)
|
|||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
for(i=0; i<(int)(sizeof(str2index)/sizeof(struct _dns_str2idx)); i++)
|
for(i=0; i<(int)(sizeof(str2index)/sizeof(struct dns_str2idx)); i++)
|
||||||
{
|
{
|
||||||
if(str2index[i].len==(int)strlen(type) && (strncasecmp(str2index[i].type, type, str2index[i].len))==0)
|
if(str2index[i].len==(int)strlen(type) && (strncasecmp(str2index[i].type, type, str2index[i].len))==0)
|
||||||
{
|
{
|
||||||
@@ -39,65 +40,31 @@ int fw_dns_type2index(char *type)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_cheat_opt(int record_id, int select_num, int ttl, int atype, cheat_pkt_opt_t* cheat_opt, int cheat_opt_num)
|
|
||||||
{
|
|
||||||
int i=0,idx=0;
|
|
||||||
int used_num=0,real_num=0;
|
|
||||||
cb_rule_t *cb_rule=NULL;
|
|
||||||
|
|
||||||
real_num=(select_num>cheat_opt_num) ? cheat_opt_num : select_num;
|
|
||||||
|
|
||||||
cb_rule=(cb_rule_t *)Maat_plugin_get_EX_data(g_tsg_maat_feather, g_fw_dns_rule_info.table_records_id, (char *)&record_id);
|
|
||||||
if(cb_rule!=NULL && real_num>0)
|
|
||||||
{
|
|
||||||
idx = (cb_rule->record_num>=real_num) ? (random()%(cb_rule->record_num-real_num+1)) : 0;
|
|
||||||
for(i=0; i<real_num && i+idx<cb_rule->record_num; i++)
|
|
||||||
{
|
|
||||||
cheat_opt[used_num].ttl=ttl;
|
|
||||||
cheat_opt[used_num].res_type=atype;
|
|
||||||
cheat_opt[used_num].cfg_type=atype;
|
|
||||||
switch(atype)
|
|
||||||
{
|
|
||||||
case DNS_TYPE_A:
|
|
||||||
cheat_opt[used_num].res_len=sizeof(unsigned int);
|
|
||||||
break;
|
|
||||||
case DNS_TYPE_AAAA:
|
|
||||||
cheat_opt[used_num].res_len=IPV6_ADDR_LEN;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cheat_opt[used_num].res_len=MIN(strlen((char *)(cb_rule->record_values[i+idx])), sizeof(cheat_opt[used_num].res_info)-1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(cheat_opt[used_num].res_info, (char *)(cb_rule->record_values[i+idx]), cheat_opt[used_num].res_len);
|
|
||||||
used_num++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return used_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void fw_dns_EX_data_create(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp)
|
void fw_dns_EX_data_create(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
cJSON *pSub=NULL;
|
cJSON *one_record=NULL,*pSub=NULL;
|
||||||
cb_rule_t *cb_rule=(cb_rule_t *)calloc(1, sizeof(cb_rule_t));
|
|
||||||
char *tmp_records=(char *)calloc(1, strlen(table_line)+1);
|
|
||||||
|
|
||||||
sscanf(table_line, "%d %s %s %s %d", &cb_rule->record_id, cb_rule->record_name, cb_rule->record_type, tmp_records, &cb_rule->is_valid);
|
|
||||||
|
|
||||||
int index=fw_dns_type2index(cb_rule->record_type);
|
struct dns_records *records=(struct dns_records *)calloc(1, sizeof(struct dns_records));
|
||||||
|
char *tmp_records=(char *)calloc(1, strlen(table_line)+1);
|
||||||
|
sscanf(table_line, "%d %s %s %s %d", &records->record_id, records->record_name, records->record_type, tmp_records, &records->is_valid);
|
||||||
|
|
||||||
|
int index=fw_dns_type2index(records->record_type);
|
||||||
cJSON *tmp_array=cJSON_Parse(tmp_records);
|
cJSON *tmp_array=cJSON_Parse(tmp_records);
|
||||||
if(tmp_array != NULL)
|
if(tmp_array!=NULL)
|
||||||
{
|
{
|
||||||
cb_rule->record_num=cJSON_GetArraySize(tmp_array);
|
records->record_num=cJSON_GetArraySize(tmp_array);
|
||||||
*cb_rule->record_values=(void *)malloc(cb_rule->record_num*sizeof(void *));
|
records->record_values=(void **)malloc(records->record_num*sizeof(void *));
|
||||||
|
|
||||||
for(i=0; i<cb_rule->record_num; i++)
|
for(i=0; i<records->record_num; i++)
|
||||||
{
|
{
|
||||||
pSub = cJSON_GetArrayItem(tmp_array, i);
|
one_record=cJSON_GetArrayItem(tmp_array, i);
|
||||||
|
if(one_record==NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pSub=cJSON_GetObjectItem(one_record, "value");
|
||||||
if(NULL==pSub )
|
if(NULL==pSub )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -106,12 +73,12 @@ void fw_dns_EX_data_create(int table_id, const char* key, const char* table_line
|
|||||||
switch(index)
|
switch(index)
|
||||||
{
|
{
|
||||||
case DNS_TYPE_A:
|
case DNS_TYPE_A:
|
||||||
cb_rule->record_values[i]=calloc(1, sizeof(unsigned int));
|
records->record_values[i]=calloc(1, sizeof(unsigned int));
|
||||||
inet_pton(AF_INET, pSub->valuestring, cb_rule->record_values[i]);
|
inet_pton(AF_INET, pSub->valuestring, records->record_values[i]);
|
||||||
break;
|
break;
|
||||||
case DNS_TYPE_AAAA:
|
case DNS_TYPE_AAAA:
|
||||||
cb_rule->record_values[i]=calloc(1, IPV6_ADDR_LEN);
|
records->record_values[i]=calloc(1, IPV6_ADDR_LEN);
|
||||||
inet_pton(AF_INET6, pSub->valuestring, cb_rule->record_values[i]);
|
inet_pton(AF_INET6, pSub->valuestring, records->record_values[i]);
|
||||||
break;
|
break;
|
||||||
case DNS_TYPE_MX:
|
case DNS_TYPE_MX:
|
||||||
break;
|
break;
|
||||||
@@ -119,45 +86,141 @@ void fw_dns_EX_data_create(int table_id, const char* key, const char* table_line
|
|||||||
case DNS_TYPE_TXT:
|
case DNS_TYPE_TXT:
|
||||||
case DNS_TYPE_PTR:
|
case DNS_TYPE_PTR:
|
||||||
case DNS_TYPE_CNAME:
|
case DNS_TYPE_CNAME:
|
||||||
cb_rule->record_values[i]=calloc(1, strlen(pSub->valuestring)+1);
|
records->record_values[i]=calloc(1, strlen(pSub->valuestring)+1);
|
||||||
memcpy(cb_rule->record_values[i], pSub->valuestring, strlen(pSub->valuestring));
|
memcpy(records->record_values[i], pSub->valuestring, strlen(pSub->valuestring));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
records->table_id=table_id;
|
||||||
|
atomic_inc(&records->ref_cnt);
|
||||||
|
(*ad)=(MAAT_PLUGIN_EX_DATA)(records);
|
||||||
|
|
||||||
|
cJSON_Delete(tmp_array);
|
||||||
|
tmp_array=NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(records);
|
||||||
|
records=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tmp_records);
|
free(tmp_records);
|
||||||
|
tmp_records=NULL;
|
||||||
|
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fw_dns_EX_data_free(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp)
|
void fw_dns_EX_data_free(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
cb_rule_t *cb_rule=(cb_rule_t *)*ad;
|
struct dns_records *records=(struct dns_records *)*ad;
|
||||||
|
|
||||||
if(cb_rule!=NULL)
|
if(records!=NULL)
|
||||||
{
|
{
|
||||||
for(i=0; i<cb_rule->record_num; i++)
|
atomic_dec(&records->ref_cnt);
|
||||||
|
if(records->ref_cnt<=0)
|
||||||
{
|
{
|
||||||
free(cb_rule->record_values[i]);
|
for(i=0; i<records->record_num; i++)
|
||||||
cb_rule->record_values[i]=NULL;
|
{
|
||||||
}
|
free(records->record_values[i]);
|
||||||
free(*cb_rule->record_values);
|
records->record_values[i]=NULL;
|
||||||
*cb_rule->record_values=NULL;
|
}
|
||||||
|
|
||||||
|
free(*records->record_values);
|
||||||
|
*records->record_values=NULL;
|
||||||
|
|
||||||
free(cb_rule);
|
free(records);
|
||||||
cb_rule=NULL;
|
records=NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fw_dns_EX_data_dup(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp)
|
void fw_dns_EX_data_dup(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp)
|
||||||
{
|
{
|
||||||
|
struct dns_records *records=(struct dns_records *)(*from);
|
||||||
|
|
||||||
|
if(records!=NULL)
|
||||||
|
{
|
||||||
|
atomic_inc(&records->ref_cnt);
|
||||||
|
(*to)=(*from);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fw_dns_EX_data_key2index(const char* key)
|
static int set_one_cheat_opt(cheat_pkt_opt_t *cheat_opt, int ttl, int atype, char *record_values)
|
||||||
{
|
{
|
||||||
return 0;
|
cheat_opt->ttl=ttl;
|
||||||
|
cheat_opt->res_type=atype;
|
||||||
|
cheat_opt->cfg_type=atype;
|
||||||
|
|
||||||
|
switch(atype)
|
||||||
|
{
|
||||||
|
case DNS_TYPE_A:
|
||||||
|
cheat_opt->res_len=sizeof(unsigned int);
|
||||||
|
break;
|
||||||
|
case DNS_TYPE_AAAA:
|
||||||
|
cheat_opt->res_len=IPV6_ADDR_LEN;
|
||||||
|
break;
|
||||||
|
case DNS_TYPE_NS:
|
||||||
|
case DNS_TYPE_TXT:
|
||||||
|
case DNS_TYPE_PTR:
|
||||||
|
case DNS_TYPE_CNAME:
|
||||||
|
cheat_opt->res_len=MIN(strlen(record_values), sizeof(cheat_opt->res_info)-1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(cheat_opt->res_info, record_values, cheat_opt->res_len);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dns_get_cheat_opt(int record_id, int select_num, int ttl, int atype, cheat_pkt_opt_t* cheat_opt, int cheat_opt_num)
|
||||||
|
{
|
||||||
|
int i=0,idx=0;
|
||||||
|
char record_id_str[32]={0};
|
||||||
|
int used_num=0,real_num=0;
|
||||||
|
struct dns_records *records=NULL;
|
||||||
|
|
||||||
|
real_num=MIN(select_num, cheat_opt_num);
|
||||||
|
if(real_num<=0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(record_id_str, sizeof(record_id_str), "%d", record_id);
|
||||||
|
records=(struct dns_records *)Maat_plugin_get_EX_data(g_tsg_maat_feather, g_fw_dns_rule_info.table_records_id, record_id_str);
|
||||||
|
if(records!=NULL)
|
||||||
|
{
|
||||||
|
if(records->record_num<=real_num)
|
||||||
|
{
|
||||||
|
for(i=0; i<records->record_num; i++)
|
||||||
|
{
|
||||||
|
used_num+=set_one_cheat_opt(&(cheat_opt[used_num]), ttl, atype, (char *)(records->record_values[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
srand(time(0));
|
||||||
|
idx=rand()%(records->record_num-real_num+1);
|
||||||
|
for(i=0; i<real_num; i++)
|
||||||
|
{
|
||||||
|
used_num+=set_one_cheat_opt(&(cheat_opt[used_num]), ttl, atype, (char *)(records->record_values[idx+i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fw_dns_EX_data_free(records->table_id, (MAAT_PLUGIN_EX_DATA *)&records, 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return used_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -181,7 +244,7 @@ int fw_dns_rule_init(const char *conffile, void *logger)
|
|||||||
fw_dns_EX_data_create,
|
fw_dns_EX_data_create,
|
||||||
fw_dns_EX_data_free,
|
fw_dns_EX_data_free,
|
||||||
fw_dns_EX_data_dup,
|
fw_dns_EX_data_dup,
|
||||||
fw_dns_EX_data_key2index,
|
NULL,
|
||||||
arg,
|
arg,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,51 @@
|
|||||||
#ifndef __FW_DNS_RULE_H__
|
#ifndef __FW_DNS_RULE_H__
|
||||||
#define __FW_DNS_RULE_H__
|
#define __FW_DNS_RULE_H__
|
||||||
|
|
||||||
|
#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 411)
|
||||||
|
#define atomic_inc(x) __sync_add_and_fetch((x),1)
|
||||||
|
#define atomic_dec(x) __sync_sub_and_fetch((x),1)
|
||||||
|
#define atomic_add(x,y) __sync_add_and_fetch((x),(y))
|
||||||
|
#define atomic_sub(x,y) __sync_sub_and_fetch((x),(y))
|
||||||
|
typedef int atomic_t;
|
||||||
|
#define ATOMIC_INIT(i) { (i) }
|
||||||
|
#define atomic_read(x) __sync_add_and_fetch((x),0)
|
||||||
|
#define atomic_set(x,y) __sync_lock_test_and_set((x),y)
|
||||||
|
#else
|
||||||
|
#include <alsa/iatomic.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MIN(a, b) ((a>b) ? b: a)
|
#define MIN(a, b) ((a>b) ? b: a)
|
||||||
|
|
||||||
#define MAX_TABLE_NAME_LEN 32
|
#define MAX_TABLE_NAME_LEN 32
|
||||||
|
|
||||||
struct _dns_str2idx
|
struct dns_str2idx
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
int len;
|
int len;
|
||||||
char *type;
|
char *type;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _cb_rule
|
struct dns_records
|
||||||
{
|
{
|
||||||
|
int ref_cnt;
|
||||||
int record_id;
|
int record_id;
|
||||||
int record_num;
|
int record_num;
|
||||||
int is_valid;
|
int is_valid;
|
||||||
|
int table_id;
|
||||||
char record_type[128];
|
char record_type[128];
|
||||||
char record_name[MAX_TABLE_NAME_LEN];
|
char record_name[MAX_TABLE_NAME_LEN];
|
||||||
void **record_values;
|
void **record_values;
|
||||||
}cb_rule_t;
|
};
|
||||||
|
|
||||||
typedef struct _fw_dns_rule
|
struct fw_dns_rule
|
||||||
{
|
{
|
||||||
int table_records_id;
|
int table_records_id;
|
||||||
char table_records_name[MAX_TABLE_NAME_LEN];
|
char table_records_name[MAX_TABLE_NAME_LEN];
|
||||||
}fw_dns_rule_t;
|
};
|
||||||
|
|
||||||
|
|
||||||
int fw_dns_type2index(char *type);
|
int fw_dns_type2index(char *type);
|
||||||
int fw_dns_rule_init(const char *conffile, void *logger);
|
int fw_dns_rule_init(const char *conffile, void *logger);
|
||||||
int get_cheat_opt(int record_id, int select_num, int ttl, int atype, cheat_pkt_opt_t* cheat_opt, int cheat_opt_num);
|
int dns_get_cheat_opt(int record_id, int select_num, int ttl, int atype, cheat_pkt_opt_t* cheat_opt, int cheat_opt_num);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user