rewrite using if_nametoindex(3) instead of the unsupported SIOCGIFINDEX
This commit is contained in:
parent
949e740949
commit
1208dd2c12
@ -1,10 +1,11 @@
|
||||
# $OpenBSD: Makefile,v 1.11 2020/06/25 07:28:29 jasper Exp $
|
||||
# $OpenBSD: Makefile,v 1.12 2020/07/20 05:53:41 jasper Exp $
|
||||
|
||||
COMMENT = DDoS detector with multiple packet capture engines
|
||||
|
||||
GH_ACCOUNT = pavel-odintsov
|
||||
GH_PROJECT = fastnetmon
|
||||
GH_TAGNAME = v1.1.6
|
||||
REVISION = 0
|
||||
|
||||
HOMEPAGE = https://fastnetmon.com/guides/
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
$OpenBSD: patch-src_afpacket_plugin_afpacket_collector_cpp,v 1.1 2020/06/25 07:28:29 jasper Exp $
|
||||
|
||||
Revert https://github.com/pavel-odintsov/fastnetmon/commit/87b102d8b004322861e828edbe51bdbca77a1436
|
||||
which requires SIOCGIFINDEX (not supported on OpenBSD).
|
||||
|
||||
Index: src/afpacket_plugin/afpacket_collector.cpp
|
||||
--- src/afpacket_plugin/afpacket_collector.cpp.orig
|
||||
+++ src/afpacket_plugin/afpacket_collector.cpp
|
||||
@@ -103,7 +103,25 @@ int get_fanout_by_name(std::string fanout_name) {
|
||||
// Return default one
|
||||
logger << log4cpp::Priority::ERROR << "Unknown FANOUT mode: " << fanout_name << " switched to default (CPU)";
|
||||
return PACKET_FANOUT_CPU;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// Get interface number by name
|
||||
+int get_interface_number_by_device_name(int socket_fd, std::string interface_name) {
|
||||
+ struct ifreq ifr;
|
||||
+ memset(&ifr, 0, sizeof(ifr));
|
||||
+
|
||||
+ if (interface_name.size() > IFNAMSIZ) {
|
||||
+ return -1;
|
||||
}
|
||||
+
|
||||
+ strncpy(ifr.ifr_name, interface_name.c_str(), sizeof(ifr.ifr_name));
|
||||
+
|
||||
+ if (ioctl(socket_fd, SIOCGIFINDEX, &ifr) == -1) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ return ifr.ifr_ifindex;
|
||||
}
|
||||
|
||||
void flush_block(struct block_desc* pbd) {
|
||||
@@ -178,12 +196,9 @@ bool setup_socket(std::string interface_name, bool ena
|
||||
return false;
|
||||
}
|
||||
|
||||
- int interface_number = 0;
|
||||
+ int interface_number = get_interface_number_by_device_name(packet_socket, interface_name);
|
||||
|
||||
- bool get_interface_number_result =
|
||||
- get_interface_number_by_device_name(packet_socket, interface_name, interface_number);
|
||||
-
|
||||
- if (!get_interface_number_result) {
|
||||
+ if (interface_number == -1) {
|
||||
logger << log4cpp::Priority::ERROR << "Can't get interface number by interface name for " << interface_name;
|
||||
return false;
|
||||
}
|
||||
@@ -332,7 +347,7 @@ void start_afpacket_collection(process_packet_pointer
|
||||
}
|
||||
|
||||
if (configuration_map.count("mirror_af_packet_fanout_mode") != 0) {
|
||||
- // Set FANOUT mode
|
||||
+ // Set FANOUT mode
|
||||
fanout_type = get_fanout_by_name(configuration_map["mirror_af_packet_fanout_mode"]);
|
||||
}
|
||||
|
@ -1,31 +1,26 @@
|
||||
$OpenBSD: patch-src_fast_library_cpp,v 1.1 2020/06/25 07:28:29 jasper Exp $
|
||||
$OpenBSD: patch-src_fast_library_cpp,v 1.2 2020/07/20 05:53:41 jasper Exp $
|
||||
|
||||
Revert https://github.com/pavel-odintsov/fastnetmon/commit/87b102d8b004322861e828edbe51bdbca77a1436
|
||||
which requires SIOCGIFINDEX (not supported on OpenBSD).
|
||||
Use if_nametoindex(3) instead of SIOCGIFINDEX
|
||||
|
||||
Index: src/fast_library.cpp
|
||||
--- src/fast_library.cpp.orig
|
||||
+++ src/fast_library.cpp
|
||||
@@ -1295,22 +1295,3 @@ bool convert_hex_as_string_to_uint(std::string hex, ui
|
||||
@@ -1307,10 +1307,18 @@ bool get_interface_number_by_device_name(int socket_fd
|
||||
|
||||
return ss.fail();
|
||||
strncpy(ifr.ifr_name, interface_name.c_str(), sizeof(ifr.ifr_name));
|
||||
|
||||
+/* Attempt to use SIOCGIFINDEX if present. */
|
||||
+#ifdef SIOCGIFINDEX
|
||||
if (ioctl(socket_fd, SIOCGIFINDEX, &ifr) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
interface_number = ifr.ifr_ifindex;
|
||||
+#else
|
||||
+ /* Fallback to if_nametoindex(3) otherwise. */
|
||||
+ interface_number = if_nametoindex(interface_name.c_str());
|
||||
+ if (interface_number == 0)
|
||||
+ return false;
|
||||
+#endif /* SIOCGIFINDEX */
|
||||
return true;
|
||||
}
|
||||
-
|
||||
-// Get interface number by name
|
||||
-bool get_interface_number_by_device_name(int socket_fd, std::string interface_name, int& interface_number) {
|
||||
- struct ifreq ifr;
|
||||
- memset(&ifr, 0, sizeof(ifr));
|
||||
-
|
||||
- if (interface_name.size() > IFNAMSIZ) {
|
||||
- return false;
|
||||
- }
|
||||
-
|
||||
- strncpy(ifr.ifr_name, interface_name.c_str(), sizeof(ifr.ifr_name));
|
||||
-
|
||||
- if (ioctl(socket_fd, SIOCGIFINDEX, &ifr) == -1) {
|
||||
- return false;
|
||||
- }
|
||||
-
|
||||
- interface_number = ifr.ifr_ifindex;
|
||||
- return true;
|
||||
-}
|
||||
|
@ -1,15 +0,0 @@
|
||||
$OpenBSD: patch-src_fast_library_h,v 1.1 2020/06/25 07:28:29 jasper Exp $
|
||||
|
||||
Revert https://github.com/pavel-odintsov/fastnetmon/commit/87b102d8b004322861e828edbe51bdbca77a1436
|
||||
which requires SIOCGIFINDEX (not supported on OpenBSD).
|
||||
|
||||
Index: src/fast_library.h
|
||||
--- src/fast_library.h.orig
|
||||
+++ src/fast_library.h
|
||||
@@ -131,6 +131,5 @@ std::string serialize_statistic_counters_about_attack(
|
||||
|
||||
std::string dns_lookup(std::string domain_name);
|
||||
bool store_data_to_stats_server(unsigned short int graphite_port, std::string graphite_host, std::string buffer_as_string);
|
||||
-bool get_interface_number_by_device_name(int socket_fd, std::string interface_name, int& interface_number);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user