@@ -644,6 +644,7 @@ static void PrintUsage(const char *progname)
644644 printf ("\t--runmode <runmode_id> : specific runmode modification the engine should run. The argument\n"
645645 "\t supplied should be the id for the runmode obtained by running\n"
646646 "\t --list-runmodes\n" );
647+ printf ("\t--plugin <path> : load plugin in addition to config\n" );
647648
648649 printf ("\n Capture and IPS:\n" );
649650
@@ -1382,6 +1383,38 @@ static bool IsLogDirectoryWritable(const char* str)
13821383 return access (str , W_OK ) == 0 ;
13831384}
13841385
1386+ /**
1387+ * Helper functions to append option values to an array where the
1388+ * option is allowed multiple times. For example:
1389+ * - --include
1390+ * - --plugin
1391+ */
1392+ static void AddCommandLineOptionValue (
1393+ const char * * * values , const char * value , const char * description )
1394+ {
1395+ if (* values == NULL ) {
1396+ * values = SCCalloc (2 , sizeof (char * ));
1397+ if (* values == NULL ) {
1398+ FatalError ("Failed to allocate memory for %s: %s" , description , strerror (errno ));
1399+ }
1400+ (* values )[0 ] = value ;
1401+ } else {
1402+ for (int i = 0 ;; i ++ ) {
1403+ if ((* values )[i ] == NULL ) {
1404+ const char * * new_values = SCRealloc (* values , (i + 2 ) * sizeof (char * ));
1405+ if (new_values == NULL ) {
1406+ FatalError (
1407+ "Failed to allocate memory for %s: %s" , description , strerror (errno ));
1408+ }
1409+ * values = new_values ;
1410+ (* values )[i ] = value ;
1411+ (* values )[i + 1 ] = NULL ;
1412+ break ;
1413+ }
1414+ }
1415+ }
1416+ }
1417+
13851418extern int g_skip_prefilter ;
13861419
13871420TmEcode SCParseCommandLine (int argc , char * * argv )
@@ -1434,6 +1467,7 @@ TmEcode SCParseCommandLine(int argc, char **argv)
14341467 {"no-random" , 0 , & g_disable_randomness , 1 },
14351468 {"strict-rule-keywords" , optional_argument , 0 , 0 },
14361469
1470+ {"plugin" , required_argument , 0 , 0 },
14371471 {"capture-plugin" , required_argument , 0 , 0 },
14381472 {"capture-plugin-args" , required_argument , 0 , 0 },
14391473
@@ -1550,6 +1584,8 @@ TmEcode SCParseCommandLine(int argc, char **argv)
15501584 "to pass --enable-pfring to configure when building." );
15511585 return TM_ECODE_FAILED ;
15521586#endif /* HAVE_PFRING */
1587+ } else if (strcmp ((long_opts [option_index ]).name , "plugin" ) == 0 ) {
1588+ AddCommandLineOptionValue (& suri -> additional_plugins , optarg , "additional plugins" );
15531589 } else if (strcmp ((long_opts [option_index ]).name , "capture-plugin" ) == 0 ) {
15541590 suri -> run_mode = RUNMODE_PLUGIN ;
15551591 suri -> capture_plugin_name = optarg ;
@@ -1870,32 +1906,8 @@ TmEcode SCParseCommandLine(int argc, char **argv)
18701906 FatalError ("failed to duplicate 'strict' string" );
18711907 }
18721908 } else if (strcmp ((long_opts [option_index ]).name , "include" ) == 0 ) {
1873- if (suri -> additional_configs == NULL ) {
1874- suri -> additional_configs = SCCalloc (2 , sizeof (char * ));
1875- if (suri -> additional_configs == NULL ) {
1876- FatalError (
1877- "Failed to allocate memory for additional configuration files: %s" ,
1878- strerror (errno ));
1879- }
1880- suri -> additional_configs [0 ] = optarg ;
1881- } else {
1882- for (int i = 0 ;; i ++ ) {
1883- if (suri -> additional_configs [i ] == NULL ) {
1884- const char * * additional_configs =
1885- SCRealloc (suri -> additional_configs , (i + 2 ) * sizeof (char * ));
1886- if (additional_configs == NULL ) {
1887- FatalError ("Failed to allocate memory for additional configuration "
1888- "files: %s" ,
1889- strerror (errno ));
1890- } else {
1891- suri -> additional_configs = additional_configs ;
1892- }
1893- suri -> additional_configs [i ] = optarg ;
1894- suri -> additional_configs [i + 1 ] = NULL ;
1895- break ;
1896- }
1897- }
1898- }
1909+ AddCommandLineOptionValue (
1910+ & suri -> additional_configs , optarg , "additional configuration files" );
18991911 } else if (strcmp ((long_opts [option_index ]).name , "firewall-rules-exclusive" ) == 0 ) {
19001912 if (suri -> firewall_rule_file != NULL ) {
19011913 SCLogError ("can't have multiple --firewall-rules-exclusive options" );
@@ -2828,7 +2840,7 @@ int PostConfLoadedSetup(SCInstance *suri)
28282840 SigTableInit ();
28292841
28302842#ifdef HAVE_PLUGINS
2831- SCPluginsLoad (suri -> capture_plugin_name , suri -> capture_plugin_args );
2843+ SCPluginsLoad (suri -> capture_plugin_name , suri -> capture_plugin_args , suri -> additional_plugins );
28322844#endif
28332845
28342846 LiveDeviceFinalize (); // must be after EBPF extension registration
0 commit comments