@@ -35,7 +35,7 @@ static void formatKey(const FFNetUsageOptions* options, FFNetUsageIoCounters* in
3535void ffPrintNetUsage (FFNetUsageOptions * options )
3636{
3737 FF_LIST_AUTO_DESTROY result = ffListCreate (sizeof (FFNetUsageIoCounters ));
38- const char * error = ffDetectNetUsage (& result );
38+ const char * error = ffDetectNetUsage (& result , options );
3939
4040 if (error )
4141 {
@@ -63,6 +63,8 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
6363 ffStrbufAppendS (& buffer , "/s (in) - " );
6464 ffParseSize (inf -> txBytes , & buffer );
6565 ffStrbufAppendS (& buffer , "/s (out)" );
66+ if (!options -> defaultRouteOnly && inf -> defaultRoute )
67+ ffStrbufAppendS (& buffer , " *" );
6668 ffStrbufPutTo (& buffer , stdout );
6769 }
6870 else
@@ -82,16 +84,25 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
8284 {FF_FORMAT_ARG_TYPE_UINT64 , & inf -> txErrors },
8385 {FF_FORMAT_ARG_TYPE_UINT64 , & inf -> rxDrops },
8486 {FF_FORMAT_ARG_TYPE_UINT64 , & inf -> txDrops },
87+ {FF_FORMAT_ARG_TYPE_BOOL , & inf -> defaultRoute },
8588 });
8689 }
8790 ++ index ;
8891 }
92+
93+ FF_LIST_FOR_EACH (FFNetUsageIoCounters , inf , result )
94+ {
95+ ffStrbufDestroy (& inf -> name );
96+ }
8997}
9098
9199void ffInitNetUsageOptions (FFNetUsageOptions * options )
92100{
93101 ffOptionInitModuleBaseInfo (& options -> moduleInfo , FF_NETUSAGE_MODULE_NAME , ffParseNetUsageCommandOptions , ffParseNetUsageJsonObject , ffPrintNetUsage , ffGenerateNetUsageJson );
94102 ffOptionInitModuleArg (& options -> moduleArgs );
103+
104+ ffStrbufInit (& options -> namePrefix );
105+ options -> defaultRouteOnly = false;
95106}
96107
97108bool ffParseNetUsageCommandOptions (FFNetUsageOptions * options , const char * key , const char * value )
@@ -101,12 +112,25 @@ bool ffParseNetUsageCommandOptions(FFNetUsageOptions* options, const char* key,
101112 if (ffOptionParseModuleArgs (key , subKey , value , & options -> moduleArgs ))
102113 return true;
103114
115+ if (ffStrEqualsIgnCase (subKey , "name-prefix" ))
116+ {
117+ ffOptionParseString (key , value , & options -> namePrefix );
118+ return true;
119+ }
120+
121+ if (ffStrEqualsIgnCase (subKey , "default-route-only" ))
122+ {
123+ options -> defaultRouteOnly = ffOptionParseBoolean (value );
124+ return true;
125+ }
126+
104127 return false;
105128}
106129
107130void ffDestroyNetUsageOptions (FFNetUsageOptions * options )
108131{
109132 ffOptionDestroyModuleArg (& options -> moduleArgs );
133+ ffStrbufDestroy (& options -> namePrefix );
110134}
111135
112136void ffParseNetUsageJsonObject (FFNetUsageOptions * options , yyjson_val * module )
@@ -122,14 +146,26 @@ void ffParseNetUsageJsonObject(FFNetUsageOptions* options, yyjson_val* module)
122146 if (ffJsonConfigParseModuleArgs (key , val , & options -> moduleArgs ))
123147 continue ;
124148
149+ if (ffStrEqualsIgnCase (key , "namePrefix" ))
150+ {
151+ ffStrbufSetS (& options -> namePrefix , yyjson_get_str (val ));
152+ continue ;
153+ }
154+
155+ if (ffStrEqualsIgnCase (key , "defaultRouteOnly" ))
156+ {
157+ options -> defaultRouteOnly = yyjson_get_bool (val );
158+ continue ;
159+ }
160+
125161 ffPrintError (FF_NETUSAGE_MODULE_NAME , 0 , & options -> moduleArgs , "Unknown JSON key %s" , key );
126162 }
127163}
128164
129- void ffGenerateNetUsageJson (FF_MAYBE_UNUSED FFNetUsageOptions * options , yyjson_mut_doc * doc , yyjson_mut_val * module )
165+ void ffGenerateNetUsageJson (FFNetUsageOptions * options , yyjson_mut_doc * doc , yyjson_mut_val * module )
130166{
131167 FF_LIST_AUTO_DESTROY result = ffListCreate (sizeof (FFNetUsageIoCounters ));
132- const char * error = ffDetectNetUsage (& result );
168+ const char * error = ffDetectNetUsage (& result , options );
133169
134170 if (error )
135171 {
@@ -150,6 +186,11 @@ void ffGenerateNetUsageJson(FF_MAYBE_UNUSED FFNetUsageOptions* options, yyjson_m
150186 yyjson_mut_obj_add_uint (doc , obj , "txErrors" , counter -> txErrors );
151187 yyjson_mut_obj_add_uint (doc , obj , "rxDrops" , counter -> rxDrops );
152188 yyjson_mut_obj_add_uint (doc , obj , "txDrops" , counter -> txDrops );
189+ yyjson_mut_obj_add_bool (doc , obj , "defaultRoute" , counter -> defaultRoute );
190+ }
153191
192+ FF_LIST_FOR_EACH (FFNetUsageIoCounters , inf , result )
193+ {
194+ ffStrbufDestroy (& inf -> name );
154195 }
155196}
0 commit comments