From 32b7d8f986ec2af4490289e1a7c872f599484ac3 Mon Sep 17 00:00:00 2001 From: "Justin.Su" Date: Wed, 6 Nov 2019 16:39:12 +0800 Subject: [PATCH 1/3] add nofilter option check. --- CHANGES.md | 5 +++++ CMakeLists.txt | 2 +- INSTALL.md | 12 ++++++------ README-zh-Hans.md | 16 ++++++++-------- README.md | 16 ++++++++-------- USAGE.md | 6 +++--- scripts/ansible_pktg.md | 2 +- scripts/ansible_pktg.yaml | 4 ++-- scripts/puppet_packet_agent.pp | 16 ++++++++-------- src/pktminerg.cpp | 19 ++++++++++++++++++- src/socketgre.cpp | 25 +++++++++++++++---------- 11 files changed, 75 insertions(+), 48 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a31c71cb0..2a50e85dc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,11 @@ The list of the most significant changes made in Netis Packet Agent over time. +## Netis Packet Agent 0.3.5 + +### Features +* Support option check for --nofilter option invalid usage. + ## Netis Packet Agent 0.3.4 ### Features diff --git a/CMakeLists.txt b/CMakeLists.txt index f8d301975..0d3b22d7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ endif () # set PKTMINERG_MAJOR_VERSION, PKTMINERG_MINOR_VERSION, etc. set(PKTMINERG_MAJOR_VERSION "0") set(PKTMINERG_MINOR_VERSION "3") -set(PKTMINERG_PATCH_VERSION "4") +set(PKTMINERG_PATCH_VERSION "5") set(PKTMINERG_VERSION_STRING "${PKTMINERG_MAJOR_VERSION}.${PKTMINERG_MINOR_VERSION}.${PKTMINERG_PATCH_VERSION}") if(WIN32) diff --git a/INSTALL.md b/INSTALL.md index 5e3072c26..e3d334ebd 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -12,8 +12,8 @@ Note: The default libpcap with TPACKET_V3 enabled has some performance issue. If 2. Download and install the RPM package. Find the latest package from [Releases Page](https://github.com/Netis/packet-agent/releases). ```shell -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm -rpm -ivh netis-packet-agent-0.3.4.el6.x86_64.rpm +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm +rpm -ivh netis-packet-agent-0.3.5.el6.x86_64.rpm ``` @@ -26,8 +26,8 @@ sudo apt-get install libpcap-dev wget 2. Download and install the DEB package. Find the latest package from [Releases Page](https://github.com/Netis/packet-agent/releases). ```bash -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4_amd64.deb -sudo dpkg -i netis-packet-agent-0.3.4_amd64.deb +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5_amd64.deb +sudo dpkg -i netis-packet-agent-0.3.5_amd64.deb ``` 3. If libpcap.so.1 not found when running pktminerg, create softlink for libpcap.so.1 in suitable directory. @@ -49,8 +49,8 @@ yum install libpcap wget 2. Download and install the RPM package. Find the latest package from [Releases Page](https://github.com/Netis/packet-agent/releases). ```shell -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm -rpm -ivh netis-packet-agent-0.3.4.el6.x86_64.rpm +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm +rpm -ivh netis-packet-agent-0.3.5.el6.x86_64.rpm ``` diff --git a/README-zh-Hans.md b/README-zh-Hans.md index 1487b5075..b9d0d6436 100644 --- a/README-zh-Hans.md +++ b/README-zh-Hans.md @@ -2,9 +2,9 @@ [English](README.md) ∙ 简体中文 ![packet agent's title](./img/title.jpg) -# Netis Packet Agent 0.3.4 +# Netis Packet Agent 0.3.5 -[![Stable release](https://img.shields.io/badge/version-0.3.4-green.svg)](https://github.com/Netis/packet-agent/releases/tag/0.3.4) +[![Stable release](https://img.shields.io/badge/version-0.3.5-green.svg)](https://github.com/Netis/packet-agent/releases/tag/0.3.5) [![Software License](https://img.shields.io/badge/license-BSD3-green.svg)](./LICENSE.md) @@ -35,14 +35,14 @@ yum install libpcap wget 2. 下载并安装RPM包。您可以从[这个地址](https://github.com/Netis/packet-agent/releases)获取最新版本的软件包。 ```bash -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm -rpm -ivh netis-packet-agent-0.3.4.el6.x86_64.rpm +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm +rpm -ivh netis-packet-agent-0.3.5.el6.x86_64.rpm ``` #### SUSE12 1. 下载并安装RPM包。您可以从[这个地址](https://github.com/Netis/packet-agent/releases)获取最新版本的软件包。 ```bash -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm -rpm -ivh netis-packet-agent-0.3.4.el6.x86_64.rpm +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm +rpm -ivh netis-packet-agent-0.3.5.el6.x86_64.rpm ``` #### Ubuntu 18.04LTS @@ -53,8 +53,8 @@ sudo apt-get install libpcap-dev wget 2. 下载并安装DEB包。您可以从[这个地址](https://github.com/Netis/packet-agent/releases)获取最新版本的软件包。 ```bash -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4_amd64.deb -sudo dpkg -i netis-packet-agent-0.3.4_amd64.deb +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5_amd64.deb +sudo dpkg -i netis-packet-agent-0.3.5_amd64.deb ``` 3. 如果提示libpcap.so找不到,到libpcap.so所在目录下创建libpcap.so.1软链接。 diff --git a/README.md b/README.md index b18b7c609..22f1ef5a3 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ English ∙ [简体中文](README-zh-Hans.md) ![packet agent's title](./img/title.jpg) -# Netis Packet Agent 0.3.4 +# Netis Packet Agent 0.3.5 -[![Stable release](https://img.shields.io/badge/version-0.3.4-green.svg)](https://github.com/Netis/packet-agent/releases/tag/0.3.4) +[![Stable release](https://img.shields.io/badge/version-0.3.5-green.svg)](https://github.com/Netis/packet-agent/releases/tag/0.3.5) [![Software License](https://img.shields.io/badge/license-BSD3-green.svg)](./LICENSE.md) ## What is Netis Packet Agent? @@ -35,15 +35,15 @@ yum install libpcap wget 2. Download and install the RPM package. Find the latest package from [Releases Page](https://github.com/Netis/packet-agent/releases). ```bash -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm -rpm -ivh netis-packet-agent-0.3.4.el6.x86_64.rpm +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm +rpm -ivh netis-packet-agent-0.3.5.el6.x86_64.rpm ``` #### SUSE 12 1. Download and install the RPM package. Find the latest package from [Releases Page](https://github.com/Netis/packet-agent/releases). ```bash -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm -rpm -ivh netis-packet-agent-0.3.4.el6.x86_64.rpm +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm +rpm -ivh netis-packet-agent-0.3.5.el6.x86_64.rpm ``` @@ -55,8 +55,8 @@ sudo apt-get install libpcap-dev wget 2. Download and install the DEB package. Find the latest package from [Releases Page](https://github.com/Netis/packet-agent/releases). ```bash -wget https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4_amd64.deb -sudo dpkg -i netis-packet-agent-0.3.4_amd64.deb +wget https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5_amd64.deb +sudo dpkg -i netis-packet-agent-0.3.5_amd64.deb ``` 3. If libpcap.so.1 not found when running pktminerg, create softlink for libpcap.so.1 in suitable directory. diff --git a/USAGE.md b/USAGE.md index 1f88a157f..40c9647eb 100644 --- a/USAGE.md +++ b/USAGE.md @@ -33,9 +33,9 @@ Allowed options: --expression FILTER filter packets with FILTER; FILTER as same as tcpdump BPF expression syntax --dump specify dump file, mostly for integrated test - --nofilter force no filter; only use when you confirm - that the snoop interface is different from - the gre interface + --nofilter force no filter; In online mode, only use when GRE interface + is set via CLI, AND you confirm that the snoop interface is + different from the gre interface. ``` diff --git a/scripts/ansible_pktg.md b/scripts/ansible_pktg.md index 9f9cfca5a..beb88b873 100644 --- a/scripts/ansible_pktg.md +++ b/scripts/ansible_pktg.md @@ -1,6 +1,6 @@ # 说明 1. 在主控的中心服务器上需要安装有 ansible 程序。如果没有,可以使用类似 yum install ansible 的命令安装。
2. 将需要安装 packet-agent 的机器加入 ansible 的 hosts 文件:比如添加组 [servers_to_install_pktg] 到 /etc/ansible/hosts,并在该组下加入若干机器IP。
-3. 拷贝待安装的 packet-agent rpm/deb 到 ansible_pktg.yaml 同一目录下。如果待安装的 rpm/deb 不是 yaml 中指定的 netis-packet-agent-0.3.4.el6.x86_64.rpm / netis-packet-agent-0.3.3_amd64.deb,则将 ansible_pktg.yaml 中 rpm_file/deb_file 修改为你需要的文件名。
+3. 拷贝待安装的 packet-agent rpm/deb 到 ansible_pktg.yaml 同一目录下。如果待安装的 rpm/deb 不是 yaml 中指定的 netis-packet-agent-0.3.5.el6.x86_64.rpm / netis-packet-agent-0.3.5_amd64.deb,则将 ansible_pktg.yaml 中 rpm_file/deb_file 修改为你需要的文件名。
4. 执行 ansible-playbook ansible_pktg.yaml 命令,将 packet-agent 程序安装到各个目标机器上。
diff --git a/scripts/ansible_pktg.yaml b/scripts/ansible_pktg.yaml index 71479d636..d96b73b83 100644 --- a/scripts/ansible_pktg.yaml +++ b/scripts/ansible_pktg.yaml @@ -2,8 +2,8 @@ - name: install packet-agent and its depends hosts: servers_to_install_pktg vars: - rpm_file: netis-packet-agent-0.3.4.el6.x86_64.rpm - deb_file: netis-packet-agent-0.3.4_amd64.deb + rpm_file: netis-packet-agent-0.3.5.el6.x86_64.rpm + deb_file: netis-packet-agent-0.3.5_amd64.deb remote_user: root gather_facts: True diff --git a/scripts/puppet_packet_agent.pp b/scripts/puppet_packet_agent.pp index 3ab35df13..8230483dc 100644 --- a/scripts/puppet_packet_agent.pp +++ b/scripts/puppet_packet_agent.pp @@ -3,30 +3,30 @@ 'Suse': { $lib_pcap = 'libpcap'; $cur_dir = '/tmp/'; - $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm'; + $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm'; $package_provider = 'rpm'; - $install_file = '/tmp/netis-packet-agent-0.3.4.el6.x86_64.rpm' + $install_file = '/tmp/netis-packet-agent-0.3.5.el6.x86_64.rpm' } 'RedHat': { $lib_pcap = 'libpcap'; $cur_dir = '/tmp/'; - $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm'; + $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm'; $package_provider = 'rpm'; - $install_file = '/tmp/netis-packet-agent-0.3.4.el6.x86_64.rpm' + $install_file = '/tmp/netis-packet-agent-0.3.5.el6.x86_64.rpm' } 'Debian': { $lib_pcap = 'libpcap-dev'; $cur_dir = '/tmp/'; - $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4_amd64.deb'; + $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5_amd64.deb'; $package_provider = 'dpkg'; - $install_file = '/tmp/netis-packet-agent-0.3.4_amd64.deb' + $install_file = '/tmp/netis-packet-agent-0.3.5_amd64.deb' } default: { $lib_pcap = 'libpcap'; $cur_dir = '/tmp/'; - $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.4/netis-packet-agent-0.3.4.el6.x86_64.rpm'; + $download_link = 'https://github.com/Netis/packet-agent/releases/download/v0.3.5/netis-packet-agent-0.3.5.el6.x86_64.rpm'; $package_provider = 'rpm'; - $install_file = '/tmp/netis-packet-agent-0.3.4.el6.x86_64.rpm' + $install_file = '/tmp/netis-packet-agent-0.3.5.el6.x86_64.rpm' } } diff --git a/src/pktminerg.cpp b/src/pktminerg.cpp index 971424f40..57d53b6c8 100644 --- a/src/pktminerg.cpp +++ b/src/pktminerg.cpp @@ -43,7 +43,9 @@ int main(int argc, const char* argv[]) { R"(filter packets with FILTER; FILTER as same as tcpdump BPF expression syntax)") ("dump", "specify dump file, mostly for integrated test") ("nofilter", - "force no filter; only use when you confirm that the snoop interface is different from the gre interface"); + "force no filter; In online mode, only use when GRE interface " + "is set via CLI, AND you confirm that the snoop interface is " + "different from the gre interface."); boost::program_options::positional_options_description position; position.add("expression", -1); @@ -129,6 +131,21 @@ int main(int argc, const char* argv[]) { bool nofilter = false; if (vm.count("nofilter")) { nofilter = true; + if (vm.count("interface")) { + if (bind_device == "") { + std::cerr << StatisLogContext::getTimeString() << "Can't enable --nofilter option " + << "because GRE bind devices(-B) is not set, GRE packet might be sent via packet captured interface(-i)" + << std::endl; + return 1; + } else if (bind_device == vm["interface"].as()) { + std::cerr << StatisLogContext::getTimeString() << "Can't enable --nofilter option " + << "because packet captured interface(-i) is equal to GRE bind devices(-B)" + << std::endl; + return 1; + } else { + // valid + } + } } if (nofilter) { diff --git a/src/socketgre.cpp b/src/socketgre.cpp index bc2a6f475..baadd6d03 100644 --- a/src/socketgre.cpp +++ b/src/socketgre.cpp @@ -65,21 +65,26 @@ int PcapExportGre::initSockets(size_t index, uint32_t keybit) { #else if (setsockopt(socketfd, SOL_SOCKET, SO_BINDTODEVICE, _bind_device.c_str(), _bind_device.length()) < 0) { std::cerr << StatisLogContext::getTimeString() << "SO_BINDTODEVICE failed, error code is " << errno - << ", error is " << strerror(errno) << "." - << std::endl; + << ", error is " << strerror(errno) << "." + << std::endl; return -1; } +#endif // WIN32 + } - if (_pmtudisc >= 0) { - if (setsockopt(socketfd, SOL_IP, IP_MTU_DISCOVER, &_pmtudisc, sizeof(_pmtudisc)) == -1) { - std::cerr << StatisLogContext::getTimeString() << "IP_MTU_DISCOVER failed, error code is " << errno - << ", error is " << strerror(errno) << "." - << std::endl; - return -1; - } +#ifdef WIN32 + //TODO: bind device on WIN32 +#else + if (_pmtudisc >= 0) { + if (setsockopt(socketfd, SOL_IP, IP_MTU_DISCOVER, &_pmtudisc, sizeof(_pmtudisc)) == -1) { + std::cerr << StatisLogContext::getTimeString() << "IP_MTU_DISCOVER failed, error code is " << errno + << ", error is " << strerror(errno) << "." + << std::endl; + return -1; } -#endif // WIN32 } +#endif // WIN32 + } From 1bf66ee3fd975c8b080e6227b9483139a766e265 Mon Sep 17 00:00:00 2001 From: Justin Su Date: Thu, 7 Nov 2019 11:33:36 +0800 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2a50e85dc..956dc526e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,9 @@ The list of the most significant changes made in Netis Packet Agent over time. ## Netis Packet Agent 0.3.5 ### Features -* Support option check for --nofilter option invalid usage. +* Support option check for '--nofilter' option invalid usage. Above the version 0.3.5, pktminerg will exit directly in the following cases: + - if you enable '--nofilter' option without specifying gre bind device(-B) in online mode. + - if you enable '--nofilter' option and gre bind device(-B) is same as packet captured interface(-i) in online mode. ## Netis Packet Agent 0.3.4 From e8a5c99245c737d0d1d4bde0274a59d96cc740be Mon Sep 17 00:00:00 2001 From: Justin Su Date: Thu, 7 Nov 2019 11:38:11 +0800 Subject: [PATCH 3/3] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 956dc526e..5ef103014 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ The list of the most significant changes made in Netis Packet Agent over time. ## Netis Packet Agent 0.3.5 ### Features -* Support option check for '--nofilter' option invalid usage. Above the version 0.3.5, pktminerg will exit directly in the following cases: +* Support option check for '--nofilter' option invalid usage. In version 0.3.5 or later, pktminerg will exit directly in the following cases: - if you enable '--nofilter' option without specifying gre bind device(-B) in online mode. - if you enable '--nofilter' option and gre bind device(-B) is same as packet captured interface(-i) in online mode.