filter: allow selection of filter policy on startup
Added a new '--filter-policy=[POLICY]' option in the daemon, which allows selecting between the supported filter policies. For now, only two policies are defined: * default: the default policy used by ModemManager, where it tries to probe and detect as many modem ports as possible. * whitelist-only: only devices explicitly tagged via udev (with the ID_MM_DEVICE_PROCESS tag) will be probed and used.
This commit is contained in:
@@ -87,6 +87,7 @@ bus_acquired_cb (GDBusConnection *connection,
|
||||
manager = mm_base_manager_new (connection,
|
||||
mm_context_get_test_plugin_dir (),
|
||||
!mm_context_get_no_auto_scan (),
|
||||
mm_context_get_filter_policy (),
|
||||
mm_context_get_initial_kernel_events (),
|
||||
mm_context_get_test_enable (),
|
||||
&error);
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include <mm-gdbus-test.h>
|
||||
|
||||
#include "mm-base-manager.h"
|
||||
#include "mm-daemon-enums-types.h"
|
||||
#include "mm-device.h"
|
||||
#include "mm-plugin-manager.h"
|
||||
#include "mm-auth.h"
|
||||
@@ -52,6 +53,7 @@ enum {
|
||||
PROP_0,
|
||||
PROP_CONNECTION,
|
||||
PROP_AUTO_SCAN,
|
||||
PROP_FILTER_POLICY,
|
||||
PROP_ENABLE_TEST,
|
||||
PROP_PLUGIN_DIR,
|
||||
PROP_INITIAL_KERNEL_EVENTS,
|
||||
@@ -63,6 +65,8 @@ struct _MMBaseManagerPrivate {
|
||||
GDBusConnection *connection;
|
||||
/* Whether auto-scanning is enabled */
|
||||
gboolean auto_scan;
|
||||
/* Filter policy (mask of enabled rules) */
|
||||
MMFilterRule filter_policy;
|
||||
/* Whether the test interface is enabled */
|
||||
gboolean enable_test;
|
||||
/* Path to look for plugins */
|
||||
@@ -965,6 +969,7 @@ MMBaseManager *
|
||||
mm_base_manager_new (GDBusConnection *connection,
|
||||
const gchar *plugin_dir,
|
||||
gboolean auto_scan,
|
||||
MMFilterRule filter_policy,
|
||||
const gchar *initial_kernel_events,
|
||||
gboolean enable_test,
|
||||
GError **error)
|
||||
@@ -977,6 +982,7 @@ mm_base_manager_new (GDBusConnection *connection,
|
||||
MM_BASE_MANAGER_CONNECTION, connection,
|
||||
MM_BASE_MANAGER_PLUGIN_DIR, plugin_dir,
|
||||
MM_BASE_MANAGER_AUTO_SCAN, auto_scan,
|
||||
MM_BASE_MANAGER_FILTER_POLICY, filter_policy,
|
||||
MM_BASE_MANAGER_INITIAL_KERNEL_EVENTS, initial_kernel_events,
|
||||
MM_BASE_MANAGER_ENABLE_TEST, enable_test,
|
||||
NULL);
|
||||
@@ -1016,6 +1022,9 @@ set_property (GObject *object,
|
||||
case PROP_AUTO_SCAN:
|
||||
priv->auto_scan = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_FILTER_POLICY:
|
||||
priv->filter_policy = g_value_get_flags (value);
|
||||
break;
|
||||
case PROP_ENABLE_TEST:
|
||||
priv->enable_test = g_value_get_boolean (value);
|
||||
break;
|
||||
@@ -1048,6 +1057,9 @@ get_property (GObject *object,
|
||||
case PROP_AUTO_SCAN:
|
||||
g_value_set_boolean (value, priv->auto_scan);
|
||||
break;
|
||||
case PROP_FILTER_POLICY:
|
||||
g_value_set_flags (value, priv->filter_policy);
|
||||
break;
|
||||
case PROP_ENABLE_TEST:
|
||||
g_value_set_boolean (value, priv->enable_test);
|
||||
break;
|
||||
@@ -1127,7 +1139,7 @@ initable_init (GInitable *initable,
|
||||
#endif
|
||||
|
||||
/* Create filter */
|
||||
priv->filter = mm_filter_new (MM_FILTER_RULE_ALL);
|
||||
priv->filter = mm_filter_new (priv->filter_policy);
|
||||
|
||||
/* Create plugin manager */
|
||||
priv->plugin_manager = mm_plugin_manager_new (priv->plugin_dir, error);
|
||||
@@ -1238,6 +1250,15 @@ mm_base_manager_class_init (MMBaseManagerClass *manager_class)
|
||||
TRUE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_FILTER_POLICY,
|
||||
g_param_spec_flags (MM_BASE_MANAGER_FILTER_POLICY,
|
||||
"Filter policy",
|
||||
"Mask of rules enabled in the filter",
|
||||
MM_TYPE_FILTER_RULE,
|
||||
MM_FILTER_RULE_NONE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ENABLE_TEST,
|
||||
g_param_spec_boolean (MM_BASE_MANAGER_ENABLE_TEST,
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "mm-filter.h"
|
||||
#include "mm-gdbus-manager.h"
|
||||
|
||||
#define MM_TYPE_BASE_MANAGER (mm_base_manager_get_type ())
|
||||
@@ -32,6 +33,7 @@
|
||||
|
||||
#define MM_BASE_MANAGER_CONNECTION "connection" /* Construct-only */
|
||||
#define MM_BASE_MANAGER_AUTO_SCAN "auto-scan" /* Construct-only */
|
||||
#define MM_BASE_MANAGER_FILTER_POLICY "filter-policy" /* Construct-only */
|
||||
#define MM_BASE_MANAGER_ENABLE_TEST "enable-test" /* Construct-only */
|
||||
#define MM_BASE_MANAGER_PLUGIN_DIR "plugin-dir" /* Construct-only */
|
||||
#define MM_BASE_MANAGER_INITIAL_KERNEL_EVENTS "initial-kernel-events" /* Construct-only */
|
||||
@@ -52,6 +54,7 @@ GType mm_base_manager_get_type (void);
|
||||
MMBaseManager *mm_base_manager_new (GDBusConnection *bus,
|
||||
const gchar *plugin_dir,
|
||||
gboolean auto_scan,
|
||||
MMFilterRule filter_policy,
|
||||
const gchar *initial_kernel_events,
|
||||
gboolean enable_test,
|
||||
GError **error);
|
||||
|
@@ -16,6 +16,10 @@
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <ModemManager.h>
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include "mm-context.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -34,10 +38,38 @@
|
||||
static gboolean help_flag;
|
||||
static gboolean version_flag;
|
||||
static gboolean debug;
|
||||
static MMFilterRule filter_policy = MM_FILTER_POLICY_DEFAULT;
|
||||
static gboolean no_auto_scan = NO_AUTO_SCAN_DEFAULT;
|
||||
static const gchar *initial_kernel_events;
|
||||
|
||||
static gboolean
|
||||
filter_policy_option_arg (const gchar *option_name,
|
||||
const gchar *value,
|
||||
gpointer data,
|
||||
GError **error)
|
||||
{
|
||||
if (!g_ascii_strcasecmp (value, "default")) {
|
||||
filter_policy = MM_FILTER_POLICY_DEFAULT;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!g_ascii_strcasecmp (value, "whitelist-only")) {
|
||||
filter_policy = MM_FILTER_POLICY_WHITELIST_ONLY;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Invalid filter policy value given: %s",
|
||||
value);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const GOptionEntry entries[] = {
|
||||
{
|
||||
"filter-policy", 0, 0, G_OPTION_ARG_CALLBACK, filter_policy_option_arg,
|
||||
"Filter policy: one of DEFAULT, WHITELIST-ONLY",
|
||||
"[POLICY]"
|
||||
},
|
||||
{
|
||||
"no-auto-scan", 0, NO_AUTO_SCAN_OPTION_FLAG, G_OPTION_ARG_NONE, &no_auto_scan,
|
||||
"Don't auto-scan looking for devices",
|
||||
@@ -84,6 +116,12 @@ mm_context_get_no_auto_scan (void)
|
||||
return no_auto_scan;
|
||||
}
|
||||
|
||||
MMFilterRule
|
||||
mm_context_get_filter_policy (void)
|
||||
{
|
||||
return filter_policy;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Log context */
|
||||
|
||||
|
@@ -19,6 +19,8 @@
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "mm-filter.h"
|
||||
|
||||
#if !defined(MM_DIST_VERSION)
|
||||
# define MM_DIST_VERSION VERSION
|
||||
#endif
|
||||
@@ -30,6 +32,9 @@ gboolean mm_context_get_debug (void);
|
||||
const gchar *mm_context_get_initial_kernel_events (void);
|
||||
gboolean mm_context_get_no_auto_scan (void);
|
||||
|
||||
/* Filter support */
|
||||
MMFilterRule mm_context_get_filter_policy (void);
|
||||
|
||||
/* Logging support */
|
||||
const gchar *mm_context_get_log_level (void);
|
||||
const gchar *mm_context_get_log_file (void);
|
||||
|
@@ -65,6 +65,22 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/
|
||||
MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \
|
||||
MM_FILTER_RULE_TTY_PLATFORM_DRIVER)
|
||||
|
||||
/* This is the default ModemManager policy that tries to automatically probe
|
||||
* device ports unless they're blacklisted in some way or another. */
|
||||
#define MM_FILTER_POLICY_DEFAULT \
|
||||
(MM_FILTER_RULE_EXPLICIT_WHITELIST | \
|
||||
MM_FILTER_RULE_VIRTUAL | \
|
||||
MM_FILTER_RULE_NET | \
|
||||
MM_FILTER_RULE_CDC_WDM | \
|
||||
MM_FILTER_RULE_TTY | \
|
||||
MM_FILTER_RULE_TTY_BLACKLIST | \
|
||||
MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \
|
||||
MM_FILTER_RULE_TTY_PLATFORM_DRIVER)
|
||||
|
||||
/* This policy only allows using device ports explicitly whitelisted via
|
||||
* udev rules. i.e. ModemManager won't do any kind of automatic probing. */
|
||||
#define MM_FILTER_POLICY_WHITELIST_ONLY MM_FILTER_RULE_EXPLICIT_WHITELIST
|
||||
|
||||
MMFilter *mm_filter_new (MMFilterRule enabled_rules);
|
||||
|
||||
gboolean mm_filter_port (MMFilter *self,
|
||||
|
Reference in New Issue
Block a user