@@ -644,6 +644,7 @@ enum {
644
644
FLOW_LIP ,
645
645
FLOW_UIP ,
646
646
FLOW_SERVER_IP ,
647
+ FLOW_DIRECTION ,
647
648
};
648
649
649
650
static int find_expiry_index (guint64 lifetime )
@@ -689,6 +690,9 @@ static void g_inet_flow_get_property(GObject * object, guint prop_id,
689
690
case FLOW_PROTOCOL :
690
691
g_value_set_uint (value , g_inet_tuple_get_protocol (& flow -> tuple ));
691
692
break ;
693
+ case FLOW_DIRECTION :
694
+ g_value_set_schar (value , flow -> direction );
695
+ break ;
692
696
case FLOW_LPORT :
693
697
case FLOW_SERVER_PORT :
694
698
{
@@ -756,6 +760,11 @@ static void g_inet_flow_class_init(GInetFlowClass * class)
756
760
g_param_spec_uint ("protocol" , "Protocol" ,
757
761
"IP Protocol for the flow" ,
758
762
0 , G_MAXUINT16 , 0 , G_PARAM_READABLE ));
763
+ g_object_class_install_property (object_class , FLOW_DIRECTION ,
764
+ g_param_spec_char ("direction" , "Direction" ,
765
+ "Original or Reply" ,
766
+ G_MININT8 , G_MAXINT8 , 0 ,
767
+ G_PARAM_READABLE ));
759
768
g_object_class_install_property (object_class , FLOW_LPORT ,
760
769
g_param_spec_uint ("lport" , "LPort" ,
761
770
"Lower L4 port (smaller value)" ,
@@ -802,18 +811,29 @@ void g_inet_flow_update_tcp(GInetFlow * flow, GInetFlow * packet)
802
811
} else {
803
812
flow -> state = FLOW_NEW ;
804
813
flow -> lifetime = G_INET_FLOW_DEFAULT_NEW_TIMEOUT ;
814
+ flow -> server_port = g_inet_tuple_get_dst_port (& packet -> tuple );
805
815
}
806
816
}
807
817
/* RST */
808
818
else if (CHECK_BIT (packet -> flags , 2 )) {
809
819
flow -> state = FLOW_CLOSED ;
810
820
flow -> lifetime = G_INET_FLOW_DEFAULT_CLOSED_TIMEOUT ;
811
821
}
822
+
823
+ if (packet -> direction == FLOW_DIRECTION_UNKNOWN ) {
824
+ packet -> direction = g_inet_tuple_get_dst_port (& packet -> tuple ) == flow -> server_port ?
825
+ FLOW_DIRECTION_ORIGINAL : FLOW_DIRECTION_REPLY ;
826
+ }
812
827
}
813
828
814
829
void g_inet_flow_update_udp (GInetFlow * flow , GInetFlow * packet )
815
830
{
816
- if (packet -> direction != flow -> direction ) {
831
+ packet -> direction =
832
+ g_inet_tuple_get_dst_port (& packet -> tuple ) <
833
+ g_inet_tuple_get_src_port (& packet ->
834
+ tuple ) ? FLOW_DIRECTION_ORIGINAL : FLOW_DIRECTION_REPLY ;
835
+
836
+ if (flow -> direction && packet -> direction && packet -> direction != flow -> direction ) {
817
837
flow -> state = FLOW_OPEN ;
818
838
flow -> lifetime = G_INET_FLOW_DEFAULT_OPEN_TIMEOUT ;
819
839
}
@@ -826,6 +846,7 @@ void g_inet_flow_update(GInetFlow * flow, GInetFlow * packet)
826
846
} else if (g_inet_tuple_get_protocol (& flow -> tuple ) == IP_PROTOCOL_UDP ) {
827
847
g_inet_flow_update_udp (flow , packet );
828
848
}
849
+ flow -> direction = packet -> direction ;
829
850
}
830
851
831
852
static void g_inet_flow_init (GInetFlow * flow )
@@ -907,7 +928,10 @@ GInetFlow *g_inet_flow_get_full(GInetFlowTable * table,
907
928
flow -> direction = packet .direction ;
908
929
flow -> hash = packet .hash ;
909
930
flow -> tuple = packet .tuple ;
910
- flow -> server_port = packet .server_port ;
931
+ if (packet .server_port )
932
+ {
933
+ flow -> server_port = packet .server_port ;
934
+ }
911
935
memcpy (flow -> server_ip , packet .server_ip , sizeof (packet .server_ip ));
912
936
g_hash_table_replace (table -> table , (gpointer ) flow , (gpointer ) flow );
913
937
table -> misses ++ ;
0 commit comments