forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packetbeat: Enable setting promiscuous mode automatically (elastic#11366
) packetbeat: Enable setting promiscuous mode automatically (elastic#11366)
- Loading branch information
1 parent
b9791ad
commit 49b0eb9
Showing
13 changed files
with
269 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM golang:1.13.7 | ||
|
||
RUN \ | ||
apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
python-pip \ | ||
virtualenv \ | ||
librpm-dev \ | ||
netcat \ | ||
libpcap-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install --upgrade setuptools | ||
RUN pip install --upgrade docker-compose==1.23.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
version: '2.3' | ||
services: | ||
beat: | ||
build: ${PWD}/. | ||
depends_on: | ||
- proxy_dep | ||
working_dir: /go/src/github.com/elastic/beats/packetbeat | ||
environment: | ||
- ES_HOST=elasticsearch | ||
- ES_PORT=9200 | ||
- ES_USER=beats | ||
- ES_PASS=testing | ||
- KIBANA_HOST=kibana | ||
- KIBANA_PORT=5601 | ||
volumes: | ||
- ${PWD}/..:/go/src/github.com/elastic/beats/ | ||
command: make | ||
privileged: true | ||
pid: host | ||
|
||
# This is a proxy used to block beats until all services are healthy. | ||
# See: https://github.com/docker/compose/issues/4369 | ||
proxy_dep: | ||
image: busybox | ||
depends_on: | ||
elasticsearch: { condition: service_healthy } | ||
kibana: { condition: service_healthy } | ||
|
||
elasticsearch: | ||
extends: | ||
file: ../testing/environments/${TESTING_ENVIRONMENT}.yml | ||
service: elasticsearch | ||
|
||
kibana: | ||
extends: | ||
file: ../testing/environments/${TESTING_ENVIRONMENT}.yml | ||
service: kibana |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
import time | ||
import unittest | ||
from packetbeat import BaseTest | ||
|
||
""" | ||
Tests for afpacket. | ||
""" | ||
|
||
|
||
def is_root(): | ||
if 'geteuid' not in dir(os): | ||
return False | ||
euid = os.geteuid() | ||
print("euid is", euid) | ||
return euid == 0 | ||
|
||
|
||
class Test(BaseTest): | ||
|
||
@unittest.skipUnless( | ||
sys.platform.startswith("linux"), | ||
"af_packet only on Linux") | ||
@unittest.skipUnless(is_root(), "Requires root") | ||
def test_afpacket_promisc(self): | ||
""" | ||
Should switch to promisc mode and back. | ||
""" | ||
|
||
# get device name, leave out loopback device | ||
devices = [f for f in os.listdir( | ||
"/sys/class/net") if f.startswith("lo")] | ||
assert len(devices) > 0 | ||
|
||
device = devices[0] | ||
|
||
ip_proc = subprocess.Popen( | ||
["ip", "link", "show", device], stdout=subprocess.PIPE) | ||
o, e = ip_proc.communicate() | ||
assert e is None | ||
|
||
prev_promisc = "PROMISC" in o.decode("utf-8") | ||
|
||
# turn off promics if was on | ||
if prev_promisc: | ||
subprocess.call(["ip", "link", "set", device, | ||
"promisc", "off"], stdout=subprocess.PIPE) | ||
|
||
self.render_config_template( | ||
af_packet=True, | ||
iface_device=device | ||
) | ||
packetbeat = self.start_packetbeat() | ||
|
||
# wait for promisc to be turned on, cap(90s) | ||
for x in range(10): | ||
time.sleep(5) | ||
|
||
ip_proc = subprocess.Popen( | ||
["ip", "link", "show", device], stdout=subprocess.PIPE) | ||
o, e = ip_proc.communicate() | ||
|
||
is_promisc = "PROMISC" in o.decode("utf-8") | ||
if is_promisc: | ||
break | ||
|
||
assert is_promisc | ||
|
||
# stop packetbeat and check if promisc is set to previous state | ||
packetbeat.kill_and_wait() | ||
|
||
ip_proc = subprocess.Popen( | ||
["ip", "link", "show", device], stdout=subprocess.PIPE) | ||
o, e = ip_proc.communicate() | ||
assert e is None | ||
|
||
is_promisc = "PROMISC" in o.decode("utf-8") | ||
assert is_promisc == False | ||
|
||
# reset device | ||
if prev_promisc: | ||
subprocess.call(["ip", "link", "set", device, "promisc", "on"]) |