|
From: <cn...@us...> - 2024-06-19 19:27:17
|
Revision: 1473
http://sourceforge.net/p/seq/svn/1473
Author: cn187
Date: 2024-06-19 19:27:15 +0000 (Wed, 19 Jun 2024)
Log Message:
-----------
Rework capture filter logic
- reduce code duplication
- fix bug with session detection when an IP address isn't specified
Modified Paths:
--------------
showeq/branches/cn187_devel/src/packet.cpp
showeq/branches/cn187_devel/src/packetcapture.cpp
showeq/branches/cn187_devel/src/packetcommon.h
Modified: showeq/branches/cn187_devel/src/packet.cpp
===================================================================
--- showeq/branches/cn187_devel/src/packet.cpp 2024-06-19 19:22:47 UTC (rev 1472)
+++ showeq/branches/cn187_devel/src/packet.cpp 2024-06-19 19:27:15 UTC (rev 1473)
@@ -36,6 +36,7 @@
#include "everquest.h"
#include "packet.h"
+#include "packetcommon.h"
#include "packetcapture.h"
#include "packetformat.h"
#include "packetstream.h"
@@ -73,14 +74,6 @@
//----------------------------------------------------------------------
// constants
-const in_port_t WorldServerGeneralMinPort = 9000;
-const in_port_t WorldServerGeneralMaxPort = 9013;
-const in_port_t WorldServerChatPort = 9876;
-const in_port_t WorldServerChat2Port = 9875; // xgame tells, mail
-const in_port_t LoginServerMinPort = 15900;
-const in_port_t LoginServerMaxPort = 15910;
-const in_port_t ChatServerPort = 5998;
-
//----------------------------------------------------------------------
// Here begins the code
Modified: showeq/branches/cn187_devel/src/packetcapture.cpp
===================================================================
--- showeq/branches/cn187_devel/src/packetcapture.cpp 2024-06-19 19:22:47 UTC (rev 1472)
+++ showeq/branches/cn187_devel/src/packetcapture.cpp 2024-06-19 19:27:15 UTC (rev 1473)
@@ -31,6 +31,7 @@
#include <arpa/inet.h>
#include "packetcapture.h"
+#include "packetcommon.h"
#include "diagnosticmessages.h"
//#define PCAP_DEBUG 1
@@ -89,39 +90,8 @@
seqInfo("Initializing Packet Capture Thread: ");
m_pcache_closed = false;
- // Fetch the netmask for the device to use later with the filter.
- if (pcap_lookupnet(device, &net, &mask, ebuf) == -1)
- {
- // Couldn't find net mask. Just leave it open.
- seqWarn("Couldn't determine netmask of device %s. Using 0.0.0.0. Error was %s",
- device, ebuf);
- }
+ this->setFilter(device, host, realtime, address_type, 0, 0);
- // create pcap style filter expressions
- if (address_type == IP_ADDRESS_TYPE)
- {
- if (strcmp(host, AUTOMATIC_CLIENT_IP) == 0)
- {
- seqInfo("Filtering packets on device %s, searching for EQ client...", device);
- sprintf (filter_buf, "udp[0:2] > 1024 and udp[2:2] > 1024 and ether proto 0x0800 and not broadcast and not multicast");
- }
- else
- {
- seqInfo("Filtering packets on device %s, IP host %s", device, host);
- sprintf (filter_buf, "udp[0:2] > 1024 and udp[2:2] > 1024 and host %s and ether proto 0x0800 and not broadcast and not multicast", host);
- }
- }
- else if (address_type == MAC_ADDRESS_TYPE)
- {
- seqInfo("Filtering packets on device %s, MAC host %s", device, host);
- sprintf (filter_buf, "udp[0:2] > 1024 and udp[2:2] > 1024 and ether host %s and ether proto 0x0800 and not broadcast and not multicast", host);
- }
- else
- {
- seqFatal("pcap_error:filter_string: unknown address_type (%d)", address_type);
- exit(0);
- }
-
/* A word about pcap_open_live() from the docs
** to_ms specifies the read timeout in milliseconds. The
** read timeout is used to arrange that the read not necessarily
@@ -391,7 +361,8 @@
uint16_t zone_port,
uint16_t client_port)
{
- char filter_buf[256]; // pcap filter buffer
+ char filter_buf[256]; // pcap filter buffer
+ char* pfb = filter_buf;
char ebuf[PCAP_ERRBUF_SIZE];
struct bpf_program bpp;
struct sched_param sp;
@@ -406,51 +377,43 @@
device, ebuf);
}
- /* Listen to World Server or the specified Zone Server */
- if (address_type == IP_ADDRESS_TYPE && client_port)
+ if (!client_port && !zone_port)
{
- // Restrict to client port and ip, plus world streams.
- sprintf(filter_buf,
- "udp and (portrange 9000-9007 or port 9876 or port %d) and host %s and ether proto 0x0800 and not broadcast and not multicast",
- client_port, hostname);
+ //no client/zone port detected, so leave it open
+ pfb += sprintf(pfb, "udp[0:2] > 1024 and udp[2:2] > 1024");
}
- else if (address_type == IP_ADDRESS_TYPE && zone_port)
+ else
{
- // Restrict to zone port and world streams.
- sprintf(filter_buf,
- "udp and (portrange 9000-9007 or port 9876 or port %d) and host %s and ether proto 0x0800 and not broadcast and not multicast",
- zone_port, hostname);
+ // restrict to client/zone port and world server ports
+ pfb += sprintf(pfb, "udp");
+ pfb += sprintf(pfb, " and (portrange %d-%d or port %d or port %d)",
+ WorldServerGeneralMinPort, WorldServerGeneralMaxPort,
+ WorldServerChatPort, (client_port) ? client_port : zone_port);
}
- else if (address_type == MAC_ADDRESS_TYPE && client_port)
+
+ if (address_type == IP_ADDRESS_TYPE)
{
- // Restrict to client port and world streams.
- sprintf(filter_buf,
- "udp and (portrange 9000-9007 or port 9876 or port %d) and ether host %s and ether proto 0x0800 and not broadcast and not multicast",
- client_port, hostname);
+ if (hostname && strcmp(hostname, AUTOMATIC_CLIENT_IP) != 0)
+ // host was specified/detected
+ pfb += sprintf(" and host %s", hostname);
}
- else if (address_type == MAC_ADDRESS_TYPE && zone_port)
+ else if (address_type == MAC_ADDRESS_TYPE)
{
- // Restrict to zone port and world streams.
- sprintf(filter_buf,
- "udp and (portrange 9000-9007 or port 9876 or port %d) and ether host %s and ether proto 0x0800 and not broadcast and not multicast",
- zone_port, hostname);
+ if (hostname && strcmp(hostname, AUTOMATIC_CLIENT_IP) != 0)
+ // mac was specified
+ pfb += sprintf(" and ether host %s", hostname);
}
- else if (hostname != NULL && !client_port && !zone_port)
- {
- // Leave wide open.
- sprintf(filter_buf,
- "udp[0:2] > 1024 and udp[2:2] > 1024 and ether proto 0x0800 and host %s and not broadcast and not multicast",
- hostname);
- }
else
{
- // Not even a hostname. Leave really wide open!
- seqInfo("Filtering packets on device %s, searching for EQ client...",
- device);
- sprintf(filter_buf,
- "udp[0:2] > 1024 and udp[2:2] > 1024 and ether proto 0x0800 and not broadcast and not multicast");
+ seqFatal("pcap_error:filter_string: unknown address_type (%d)", address_type);
+ exit(0);
}
+ //restrict to ipv4, and ignore broad/multi-cast packets
+ pfb += sprintf(pfb, " and ether proto 0x800 and not broadcast and not multicast");
+
+ seqInfo("Filtering packets on device %s", device);
+
if (pcap_compile (m_pcache_pcap, &bpp, filter_buf, 1, net) == -1)
{
seqWarn("%s",filter_buf);
Modified: showeq/branches/cn187_devel/src/packetcommon.h
===================================================================
--- showeq/branches/cn187_devel/src/packetcommon.h 2024-06-19 19:22:47 UTC (rev 1472)
+++ showeq/branches/cn187_devel/src/packetcommon.h 2024-06-19 19:27:15 UTC (rev 1473)
@@ -46,11 +46,20 @@
#include <endian.h>
#endif
+#include <netdb.h>
//----------------------------------------------------------------------
// Constants
const char* const AUTOMATIC_CLIENT_IP = "127.0.0.0";
+const in_port_t WorldServerGeneralMinPort = 9000;
+const in_port_t WorldServerGeneralMaxPort = 9015;
+const in_port_t WorldServerChatPort = 9876;
+const in_port_t WorldServerChat2Port = 9875; // xgame tells, mail
+const in_port_t LoginServerMinPort = 15900;
+const in_port_t LoginServerMaxPort = 15910;
+const in_port_t ChatServerPort = 5998;
+
// Preference constants for VPacket.Playback.
#define PLAYBACK_OFF 0
#define PLAYBACK_FORMAT_SEQ 1
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|