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,
|
manager = mm_base_manager_new (connection,
|
||||||
mm_context_get_test_plugin_dir (),
|
mm_context_get_test_plugin_dir (),
|
||||||
!mm_context_get_no_auto_scan (),
|
!mm_context_get_no_auto_scan (),
|
||||||
|
mm_context_get_filter_policy (),
|
||||||
mm_context_get_initial_kernel_events (),
|
mm_context_get_initial_kernel_events (),
|
||||||
mm_context_get_test_enable (),
|
mm_context_get_test_enable (),
|
||||||
&error);
|
&error);
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include <mm-gdbus-test.h>
|
#include <mm-gdbus-test.h>
|
||||||
|
|
||||||
#include "mm-base-manager.h"
|
#include "mm-base-manager.h"
|
||||||
|
#include "mm-daemon-enums-types.h"
|
||||||
#include "mm-device.h"
|
#include "mm-device.h"
|
||||||
#include "mm-plugin-manager.h"
|
#include "mm-plugin-manager.h"
|
||||||
#include "mm-auth.h"
|
#include "mm-auth.h"
|
||||||
@@ -52,6 +53,7 @@ enum {
|
|||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_CONNECTION,
|
PROP_CONNECTION,
|
||||||
PROP_AUTO_SCAN,
|
PROP_AUTO_SCAN,
|
||||||
|
PROP_FILTER_POLICY,
|
||||||
PROP_ENABLE_TEST,
|
PROP_ENABLE_TEST,
|
||||||
PROP_PLUGIN_DIR,
|
PROP_PLUGIN_DIR,
|
||||||
PROP_INITIAL_KERNEL_EVENTS,
|
PROP_INITIAL_KERNEL_EVENTS,
|
||||||
@@ -63,6 +65,8 @@ struct _MMBaseManagerPrivate {
|
|||||||
GDBusConnection *connection;
|
GDBusConnection *connection;
|
||||||
/* Whether auto-scanning is enabled */
|
/* Whether auto-scanning is enabled */
|
||||||
gboolean auto_scan;
|
gboolean auto_scan;
|
||||||
|
/* Filter policy (mask of enabled rules) */
|
||||||
|
MMFilterRule filter_policy;
|
||||||
/* Whether the test interface is enabled */
|
/* Whether the test interface is enabled */
|
||||||
gboolean enable_test;
|
gboolean enable_test;
|
||||||
/* Path to look for plugins */
|
/* Path to look for plugins */
|
||||||
@@ -962,23 +966,25 @@ out:
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
MMBaseManager *
|
MMBaseManager *
|
||||||
mm_base_manager_new (GDBusConnection *connection,
|
mm_base_manager_new (GDBusConnection *connection,
|
||||||
const gchar *plugin_dir,
|
const gchar *plugin_dir,
|
||||||
gboolean auto_scan,
|
gboolean auto_scan,
|
||||||
const gchar *initial_kernel_events,
|
MMFilterRule filter_policy,
|
||||||
gboolean enable_test,
|
const gchar *initial_kernel_events,
|
||||||
GError **error)
|
gboolean enable_test,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
||||||
|
|
||||||
return g_initable_new (MM_TYPE_BASE_MANAGER,
|
return g_initable_new (MM_TYPE_BASE_MANAGER,
|
||||||
NULL, /* cancellable */
|
NULL, /* cancellable */
|
||||||
error,
|
error,
|
||||||
MM_BASE_MANAGER_CONNECTION, connection,
|
MM_BASE_MANAGER_CONNECTION, connection,
|
||||||
MM_BASE_MANAGER_PLUGIN_DIR, plugin_dir,
|
MM_BASE_MANAGER_PLUGIN_DIR, plugin_dir,
|
||||||
MM_BASE_MANAGER_AUTO_SCAN, auto_scan,
|
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_INITIAL_KERNEL_EVENTS, initial_kernel_events,
|
||||||
MM_BASE_MANAGER_ENABLE_TEST, enable_test,
|
MM_BASE_MANAGER_ENABLE_TEST, enable_test,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1016,6 +1022,9 @@ set_property (GObject *object,
|
|||||||
case PROP_AUTO_SCAN:
|
case PROP_AUTO_SCAN:
|
||||||
priv->auto_scan = g_value_get_boolean (value);
|
priv->auto_scan = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_FILTER_POLICY:
|
||||||
|
priv->filter_policy = g_value_get_flags (value);
|
||||||
|
break;
|
||||||
case PROP_ENABLE_TEST:
|
case PROP_ENABLE_TEST:
|
||||||
priv->enable_test = g_value_get_boolean (value);
|
priv->enable_test = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
@@ -1048,6 +1057,9 @@ get_property (GObject *object,
|
|||||||
case PROP_AUTO_SCAN:
|
case PROP_AUTO_SCAN:
|
||||||
g_value_set_boolean (value, priv->auto_scan);
|
g_value_set_boolean (value, priv->auto_scan);
|
||||||
break;
|
break;
|
||||||
|
case PROP_FILTER_POLICY:
|
||||||
|
g_value_set_flags (value, priv->filter_policy);
|
||||||
|
break;
|
||||||
case PROP_ENABLE_TEST:
|
case PROP_ENABLE_TEST:
|
||||||
g_value_set_boolean (value, priv->enable_test);
|
g_value_set_boolean (value, priv->enable_test);
|
||||||
break;
|
break;
|
||||||
@@ -1127,7 +1139,7 @@ initable_init (GInitable *initable,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Create filter */
|
/* Create filter */
|
||||||
priv->filter = mm_filter_new (MM_FILTER_RULE_ALL);
|
priv->filter = mm_filter_new (priv->filter_policy);
|
||||||
|
|
||||||
/* Create plugin manager */
|
/* Create plugin manager */
|
||||||
priv->plugin_manager = mm_plugin_manager_new (priv->plugin_dir, error);
|
priv->plugin_manager = mm_plugin_manager_new (priv->plugin_dir, error);
|
||||||
@@ -1238,6 +1250,15 @@ mm_base_manager_class_init (MMBaseManagerClass *manager_class)
|
|||||||
TRUE,
|
TRUE,
|
||||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
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
|
g_object_class_install_property
|
||||||
(object_class, PROP_ENABLE_TEST,
|
(object_class, PROP_ENABLE_TEST,
|
||||||
g_param_spec_boolean (MM_BASE_MANAGER_ENABLE_TEST,
|
g_param_spec_boolean (MM_BASE_MANAGER_ENABLE_TEST,
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
#include "mm-filter.h"
|
||||||
#include "mm-gdbus-manager.h"
|
#include "mm-gdbus-manager.h"
|
||||||
|
|
||||||
#define MM_TYPE_BASE_MANAGER (mm_base_manager_get_type ())
|
#define MM_TYPE_BASE_MANAGER (mm_base_manager_get_type ())
|
||||||
@@ -30,10 +31,11 @@
|
|||||||
#define MM_IS_BASE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_BASE_MANAGER))
|
#define MM_IS_BASE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_BASE_MANAGER))
|
||||||
#define MM_BASE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BASE_MANAGER, MMBaseManagerClass))
|
#define MM_BASE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BASE_MANAGER, MMBaseManagerClass))
|
||||||
|
|
||||||
#define MM_BASE_MANAGER_CONNECTION "connection" /* Construct-only */
|
#define MM_BASE_MANAGER_CONNECTION "connection" /* Construct-only */
|
||||||
#define MM_BASE_MANAGER_AUTO_SCAN "auto-scan" /* Construct-only */
|
#define MM_BASE_MANAGER_AUTO_SCAN "auto-scan" /* Construct-only */
|
||||||
#define MM_BASE_MANAGER_ENABLE_TEST "enable-test" /* Construct-only */
|
#define MM_BASE_MANAGER_FILTER_POLICY "filter-policy" /* Construct-only */
|
||||||
#define MM_BASE_MANAGER_PLUGIN_DIR "plugin-dir" /* 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 */
|
#define MM_BASE_MANAGER_INITIAL_KERNEL_EVENTS "initial-kernel-events" /* Construct-only */
|
||||||
|
|
||||||
typedef struct _MMBaseManagerPrivate MMBaseManagerPrivate;
|
typedef struct _MMBaseManagerPrivate MMBaseManagerPrivate;
|
||||||
@@ -49,12 +51,13 @@ typedef struct {
|
|||||||
|
|
||||||
GType mm_base_manager_get_type (void);
|
GType mm_base_manager_get_type (void);
|
||||||
|
|
||||||
MMBaseManager *mm_base_manager_new (GDBusConnection *bus,
|
MMBaseManager *mm_base_manager_new (GDBusConnection *bus,
|
||||||
const gchar *plugin_dir,
|
const gchar *plugin_dir,
|
||||||
gboolean auto_scan,
|
gboolean auto_scan,
|
||||||
const gchar *initial_kernel_events,
|
MMFilterRule filter_policy,
|
||||||
gboolean enable_test,
|
const gchar *initial_kernel_events,
|
||||||
GError **error);
|
gboolean enable_test,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
void mm_base_manager_start (MMBaseManager *manager,
|
void mm_base_manager_start (MMBaseManager *manager,
|
||||||
gboolean manual_scan);
|
gboolean manual_scan);
|
||||||
|
@@ -16,6 +16,10 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <ModemManager.h>
|
||||||
|
#define _LIBMM_INSIDE_MM
|
||||||
|
#include <libmm-glib.h>
|
||||||
|
|
||||||
#include "mm-context.h"
|
#include "mm-context.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -31,13 +35,41 @@
|
|||||||
# define NO_AUTO_SCAN_DEFAULT TRUE
|
# define NO_AUTO_SCAN_DEFAULT TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static gboolean help_flag;
|
static gboolean help_flag;
|
||||||
static gboolean version_flag;
|
static gboolean version_flag;
|
||||||
static gboolean debug;
|
static gboolean debug;
|
||||||
static gboolean no_auto_scan = NO_AUTO_SCAN_DEFAULT;
|
static MMFilterRule filter_policy = MM_FILTER_POLICY_DEFAULT;
|
||||||
static const gchar *initial_kernel_events;
|
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[] = {
|
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,
|
"no-auto-scan", 0, NO_AUTO_SCAN_OPTION_FLAG, G_OPTION_ARG_NONE, &no_auto_scan,
|
||||||
"Don't auto-scan looking for devices",
|
"Don't auto-scan looking for devices",
|
||||||
@@ -84,6 +116,12 @@ mm_context_get_no_auto_scan (void)
|
|||||||
return no_auto_scan;
|
return no_auto_scan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MMFilterRule
|
||||||
|
mm_context_get_filter_policy (void)
|
||||||
|
{
|
||||||
|
return filter_policy;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Log context */
|
/* Log context */
|
||||||
|
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "mm-filter.h"
|
||||||
|
|
||||||
#if !defined(MM_DIST_VERSION)
|
#if !defined(MM_DIST_VERSION)
|
||||||
# define MM_DIST_VERSION VERSION
|
# define MM_DIST_VERSION VERSION
|
||||||
#endif
|
#endif
|
||||||
@@ -30,6 +32,9 @@ gboolean mm_context_get_debug (void);
|
|||||||
const gchar *mm_context_get_initial_kernel_events (void);
|
const gchar *mm_context_get_initial_kernel_events (void);
|
||||||
gboolean mm_context_get_no_auto_scan (void);
|
gboolean mm_context_get_no_auto_scan (void);
|
||||||
|
|
||||||
|
/* Filter support */
|
||||||
|
MMFilterRule mm_context_get_filter_policy (void);
|
||||||
|
|
||||||
/* Logging support */
|
/* Logging support */
|
||||||
const gchar *mm_context_get_log_level (void);
|
const gchar *mm_context_get_log_level (void);
|
||||||
const gchar *mm_context_get_log_file (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_MANUAL_SCAN_ONLY | \
|
||||||
MM_FILTER_RULE_TTY_PLATFORM_DRIVER)
|
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);
|
MMFilter *mm_filter_new (MMFilterRule enabled_rules);
|
||||||
|
|
||||||
gboolean mm_filter_port (MMFilter *self,
|
gboolean mm_filter_port (MMFilter *self,
|
||||||
|
Reference in New Issue
Block a user