@@ -95,6 +95,7 @@ static bool use_friendly_names = true;
95
95
OVS_NO_RETURN static void usage (void );
96
96
static void parse_options (int argc , char * argv []);
97
97
static char * trace (const char * datapath , const char * flow );
98
+ static void clear_data (void );
98
99
static void read_db (void );
99
100
static unixctl_cb_func ovntrace_exit ;
100
101
static unixctl_cb_func ovntrace_trace ;
@@ -136,14 +137,16 @@ main(int argc, char *argv[])
136
137
if (error ) {
137
138
ovs_fatal (error , "failed to create unixctl server" );
138
139
}
140
+ puts (unixctl_server_get_path (server ));
141
+ fflush (stdout );
142
+
139
143
unixctl_command_register ("exit" , "" , 0 , 0 , ovntrace_exit , & exiting );
140
144
unixctl_command_register ("trace" , "[OPTIONS] [DATAPATH] MICROFLOW" ,
141
145
1 , INT_MAX , ovntrace_trace , NULL );
142
146
}
143
147
ovnsb_idl = ovsdb_idl_create (db , & sbrec_idl_class , true, false);
144
148
ovsdb_idl_set_leader_only (ovnsb_idl , leader_only );
145
149
146
- bool already_read = false;
147
150
for (;;) {
148
151
ovsdb_idl_run (ovnsb_idl );
149
152
unixctl_server_run (server );
@@ -154,11 +157,8 @@ main(int argc, char *argv[])
154
157
}
155
158
156
159
if (ovsdb_idl_has_ever_connected (ovnsb_idl )) {
157
- if (!already_read ) {
158
- already_read = true;
159
- read_db ();
160
- }
161
-
160
+ clear_data ();
161
+ read_db ();
162
162
daemonize_complete ();
163
163
if (!get_detach ()) {
164
164
const char * dp_s = argc > 1 ? argv [0 ] : NULL ;
@@ -443,7 +443,7 @@ struct ovntrace_port {
443
443
struct uuid uuid ;
444
444
char * name ;
445
445
char * name2 ;
446
- const char * friendly_name ;
446
+ char * friendly_name ;
447
447
char * type ;
448
448
uint16_t tunnel_key ;
449
449
struct ovntrace_port * peer ; /* Patch ports only. */
@@ -679,6 +679,120 @@ shorten_uuid(const char *s)
679
679
: xstrdup (s ));
680
680
}
681
681
682
+ static void
683
+ ovntrace_fdbs_destroy (struct hmap * fdbs )
684
+ {
685
+ struct ovntrace_fdb * fdb ;
686
+ HMAP_FOR_EACH_POP (fdb , node , fdbs ) {
687
+ free (fdb );
688
+ }
689
+ hmap_destroy (fdbs );
690
+ }
691
+
692
+ static void
693
+ ovntrace_mac_bindings_destroy (struct hmap * bindings )
694
+ {
695
+ struct ovntrace_mac_binding * binding ;
696
+ HMAP_FOR_EACH_POP (binding , node , bindings ) {
697
+ free (binding );
698
+ }
699
+ hmap_destroy (bindings );
700
+ }
701
+
702
+ static void
703
+ ovntrace_flows_destroy (struct ovntrace_flow * * flows , size_t n_flows )
704
+ {
705
+ for (size_t i = 0 ; i < n_flows ; i ++ ) {
706
+ struct ovntrace_flow * flow = flows [i ];
707
+ free (flow -> stage_name );
708
+ free (flow -> source );
709
+ expr_destroy (flow -> match );
710
+ free (flow -> match_s );
711
+ ovnacts_free (flow -> ovnacts , flow -> ovnacts_len );
712
+ free (flow -> ovnacts );
713
+ free (flow );
714
+ }
715
+ free (flows );
716
+ }
717
+
718
+ static void
719
+ ovntrace_mcgroups_destroy (struct ovs_list * mcgroups )
720
+ {
721
+ struct ovntrace_mcgroup * mcgroup ;
722
+ LIST_FOR_EACH_POP (mcgroup , list_node , mcgroups ) {
723
+ free (mcgroup -> name );
724
+ free (mcgroup -> ports );
725
+ free (mcgroup );
726
+ }
727
+ }
728
+
729
+ static void
730
+ ovntrace_datapaths_destroy (void )
731
+ {
732
+ struct ovntrace_datapath * dp ;
733
+ HMAP_FOR_EACH_POP (dp , sb_uuid_node , & datapaths ) {
734
+ ovntrace_mcgroups_destroy (& dp -> mcgroups );
735
+ ovntrace_mac_bindings_destroy (& dp -> mac_bindings );
736
+ ovntrace_fdbs_destroy (& dp -> fdbs );
737
+ ovntrace_flows_destroy (dp -> flows , dp -> n_flows );
738
+ free (dp -> name );
739
+ free (dp -> name2 );
740
+ free (dp -> friendly_name );
741
+ free (dp );
742
+ }
743
+ hmap_destroy (& datapaths );
744
+ }
745
+
746
+ static void
747
+ ovntrace_ports_destroy (void )
748
+ {
749
+ struct shash_node * node , * node_next ;
750
+ SHASH_FOR_EACH_SAFE (node , node_next , & ports ) {
751
+ struct ovntrace_port * port = node -> data ;
752
+ free (port -> name );
753
+ free (port -> type );
754
+ free (port -> name2 );
755
+ free (port -> friendly_name );
756
+ free (port );
757
+ shash_delete (& ports , node );
758
+ }
759
+ shash_destroy (& ports );
760
+ }
761
+
762
+ static void
763
+ address_sets_destroy (void )
764
+ {
765
+ expr_const_sets_destroy (& address_sets );
766
+ shash_destroy (& address_sets );
767
+ }
768
+
769
+ static void
770
+ port_groups_destroy (void )
771
+ {
772
+ expr_const_sets_destroy (& port_groups );
773
+ shash_destroy (& port_groups );
774
+ }
775
+
776
+ static void
777
+ clear_data (void )
778
+ {
779
+ static bool first_clear = true;
780
+ if (first_clear ) {
781
+ first_clear = false;
782
+ } else {
783
+ ovntrace_datapaths_destroy ();
784
+ ovntrace_ports_destroy ();
785
+ address_sets_destroy ();
786
+ port_groups_destroy ();
787
+ dhcp_opts_destroy (& dhcp_opts );
788
+ dhcp_opts_destroy (& dhcpv6_opts );
789
+ nd_ra_opts_destroy (& nd_ra_opts );
790
+ controller_event_opts_destroy (& event_opts );
791
+ expr_symtab_destroy (& symtab );
792
+ shash_destroy (& symtab );
793
+ }
794
+ }
795
+
682
796
static void
683
797
read_datapaths (void )
684
798
{
0 commit comments