From e6b332aa4a1399e33df68998cf8351bccaee3fc4 Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Sun, 24 Jul 2022 17:46:24 +0200 Subject: Add support for flow client/server information (#1671) In a lot of places in ndPI we use *packet* source/dest info (address/port/direction) when we are interested in *flow* client/server info, instead. Add basic logic to autodetect this kind of information. nDPI doesn't perform any "flow management" itself but this task is delegated to the external application. It is then likely that the application might provide more reliable hints about flow client/server direction and about the TCP handshake presence: in that case, these information might be (optionally) passed to the library, disabling the internal "autodetect" logic. These new fields have been used in some LRU caches and in the "guessing" algorithm. It is quite likely that some other code needs to be updated. --- python/ndpi_example.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'python/ndpi_example.py') diff --git a/python/ndpi_example.py b/python/ndpi_example.py index 8606ae84b..f3f07a879 100644 --- a/python/ndpi_example.py +++ b/python/ndpi_example.py @@ -14,7 +14,7 @@ If not, see . """ from collections import namedtuple -from ndpi import NDPI, NDPIFlow +from ndpi import NDPI, NDPIFlow, ffi import argparse import socket import dpkt @@ -131,7 +131,7 @@ if __name__ == "__main__": key = ppkt_to_flow_key(ppkt) try: # Try a Flow update flow = flow_cache[key] - flow.detected_protocol = nDPI.process_packet(flow.ndpi_flow, ppkt.ip_bytes, time_ms) + flow.detected_protocol = nDPI.process_packet(flow.ndpi_flow, ppkt.ip_bytes, time_ms, ffi.NULL) flow.pkts += 1 flow.bytes += len(packet) except KeyError: # New Flow @@ -139,7 +139,7 @@ if __name__ == "__main__": flow.index = flow_count flow_count += 1 flow.ndpi_flow = NDPIFlow() # We create an nDPIFlow object per Flow - flow.detected_protocol = nDPI.process_packet(flow.ndpi_flow, ppkt.ip_bytes, time_ms) + flow.detected_protocol = nDPI.process_packet(flow.ndpi_flow, ppkt.ip_bytes, time_ms, ffi.NULL) flow.pkts += 1 flow.bytes += len(packet) flow_cache[key] = flow -- cgit v1.2.3