1010#include " utf8.hpp"
1111#include " match.h"
1212#include " fingerprint.h"
13+ #include " result.h"
14+ #include " util_obj.h"
1315#include < unordered_map>
1416
1517namespace stun {
@@ -471,6 +473,8 @@ namespace stun {
471473
472474 uint16_t get_type () const { return type; }
473475
476+ datum get_value () const { return value; }
477+
474478 };
475479
476480
@@ -772,6 +776,7 @@ namespace stun {
772776 class message : public base_protocol {
773777 header hdr;
774778 datum body;
779+ datum software;
775780
776781 public:
777782
@@ -959,6 +964,13 @@ namespace stun {
959964 } else {
960965 ; // by default, attribute information is not included in fingerprint
961966 }
967+
968+ // remember SOFTWARE for later use in analysis
969+ //
970+ if (attr.value .get_type () == attr_type::SOFTWARE) {
971+ software = attr.value .get_value ();
972+ }
973+
962974 } else {
963975 break ;
964976 }
@@ -970,10 +982,33 @@ namespace stun {
970982 // analyzes the dst_ip, dst_port, and SOFTWARE attribute
971983 // value, using a classifier selected by the stun fingerprint
972984 //
973- bool do_analysis (const struct key &, struct analysis_context &, classifier*) {
985+ // request format: dst_addr, dst_port
986+ // response format: src_addr, src_port
987+
988+ bool do_analysis (const struct key &flow_key, struct analysis_context &ac, classifier*) {
989+
990+ // create a json-friendly utf8 copy of the SOFTWARE atribute's value field
974991 //
975- // TBD
992+ utf8_safe_string<MAX_USER_AGENT_LEN> utf8_software{software};
993+
994+ // handle message classes appropriately: reverse the
995+ // addresses and ports in the flow key for responses,
996+ // leave the flow key untouched for requests, and ignore
997+ // all other message classes
976998 //
999+ key k{flow_key};
1000+ if ((hdr.get_message_class () & 0b10 ) == 0b10 ) {
1001+ //
1002+ // success_resp and error_resp: swap addrs and ports
1003+ //
1004+ k.reverse ();
1005+ }
1006+ ac.destination .init ({nullptr ,nullptr }, // domain name
1007+ utf8_software.get_datum (), // user agent
1008+ {nullptr ,nullptr }, // alpn
1009+ k // flow key, used for dst_addr and dst_port
1010+ );
1011+
9771012 return false ;
9781013 }
9791014
0 commit comments