Skip to content

Commit

Permalink
Merge pull request #65 from Netis/feature/nofilter
Browse files Browse the repository at this point in the history
add nofilter option check.
  • Loading branch information
lcywoodlucy committed Nov 7, 2019
2 parents 0df97c5 + e8a5c99 commit 0715198
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 48 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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. 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.

## Netis Packet Agent 0.3.4

### Features
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand All @@ -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.
Expand All @@ -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
```


Expand Down
16 changes: 8 additions & 8 deletions README-zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand All @@ -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软链接。
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
```


Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```

Expand Down
2 changes: 1 addition & 1 deletion scripts/ansible_pktg.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 说明
1. 在主控的中心服务器上需要安装有 ansible 程序。如果没有,可以使用类似 yum install ansible 的命令安装。</br>
2. 将需要安装 packet-agent 的机器加入 ansible 的 hosts 文件:比如添加组 [servers_to_install_pktg] 到 /etc/ansible/hosts,并在该组下加入若干机器IP。</br>
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 修改为你需要的文件名。</br>
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 修改为你需要的文件名。</br>
4. 执行 ansible-playbook ansible_pktg.yaml 命令,将 packet-agent 程序安装到各个目标机器上。</br>

4 changes: 2 additions & 2 deletions scripts/ansible_pktg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions scripts/puppet_packet_agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/pktminerg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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::string>()) {
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) {
Expand Down
25 changes: 15 additions & 10 deletions src/socketgre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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



}
Expand Down

0 comments on commit 0715198

Please sign in to comment.