base-bearer: remove default IP family property

There is no point in providing a configurable default IP family in the
bearer object, because we can always assume IPv4 as being the only
default expected.

Simplify the logic and also provide a new method to get the normalize
the IP family, using IPv4 as default always.
This commit is contained in:
Aleksander Morgado
2021-03-31 23:46:31 +02:00
parent 3179006351
commit 2c27a7aadc
8 changed files with 37 additions and 90 deletions
+1 -10
View File
@@ -345,16 +345,7 @@ connect_3gpp_context_step (GTask *task)
MMBearerIpFamily ip_family;
ip_family = mm_bearer_properties_get_ip_type (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
if (ip_family == MM_BEARER_IP_FAMILY_NONE ||
ip_family == MM_BEARER_IP_FAMILY_ANY) {
gchar *ip_family_str;
ip_family = mm_base_bearer_get_default_ip_family (MM_BASE_BEARER (self));
ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family);
mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", ip_family_str);
g_free (ip_family_str);
}
mm_3gpp_normalize_ip_family (&ip_family, self);
if (ip_family != MM_BEARER_IP_FAMILY_IPV4) {
g_task_return_new_error (task,
MM_CORE_ERROR,
-25
View File
@@ -70,7 +70,6 @@ enum {
PROP_MODEM,
PROP_STATUS,
PROP_CONFIG,
PROP_DEFAULT_IP_FAMILY,
PROP_LAST
};
@@ -92,8 +91,6 @@ struct _MMBaseBearerPrivate {
gboolean ignore_disconnection_reports;
/* Configuration of the bearer */
MMBearerProperties *config;
/* Default IP family of this bearer */
MMBearerIpFamily default_ip_family;
/* Cancellable for connect() */
GCancellable *connect_cancellable;
@@ -1289,12 +1286,6 @@ mm_base_bearer_get_config (MMBaseBearer *self)
NULL);
}
MMBearerIpFamily
mm_base_bearer_get_default_ip_family (MMBaseBearer *self)
{
return self->priv->default_ip_family;
}
/*****************************************************************************/
static void
@@ -1481,9 +1472,6 @@ set_property (GObject *object,
g_variant_unref (dictionary);
break;
}
case PROP_DEFAULT_IP_FAMILY:
self->priv->default_ip_family = g_value_get_flags (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1514,9 +1502,6 @@ get_property (GObject *object,
case PROP_CONFIG:
g_value_set_object (value, self->priv->config);
break;
case PROP_DEFAULT_IP_FAMILY:
g_value_set_flags (value, self->priv->default_ip_family);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1539,7 +1524,6 @@ mm_base_bearer_init (MMBaseBearer *self)
self->priv->status = MM_BEARER_STATUS_DISCONNECTED;
self->priv->reason_3gpp = CONNECTION_FORBIDDEN_REASON_NONE;
self->priv->reason_cdma = CONNECTION_FORBIDDEN_REASON_NONE;
self->priv->default_ip_family = MM_BEARER_IP_FAMILY_IPV4;
self->priv->stats = mm_bearer_stats_new ();
/* Set defaults */
@@ -1651,15 +1635,6 @@ mm_base_bearer_class_init (MMBaseBearerClass *klass)
MM_TYPE_BEARER_PROPERTIES,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONFIG, properties[PROP_CONFIG]);
properties[PROP_DEFAULT_IP_FAMILY] =
g_param_spec_flags (MM_BASE_BEARER_DEFAULT_IP_FAMILY,
"Bearer default IP family",
"IP family to use for this bearer when no IP family is specified",
MM_TYPE_BEARER_IP_FAMILY,
MM_BEARER_IP_FAMILY_IPV4,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DEFAULT_IP_FAMILY, properties[PROP_DEFAULT_IP_FAMILY]);
}
/*****************************************************************************/
+9 -12
View File
@@ -70,12 +70,11 @@ typedef struct _MMBaseBearer MMBaseBearer;
typedef struct _MMBaseBearerClass MMBaseBearerClass;
typedef struct _MMBaseBearerPrivate MMBaseBearerPrivate;
#define MM_BASE_BEARER_PATH "bearer-path"
#define MM_BASE_BEARER_CONNECTION "bearer-connection"
#define MM_BASE_BEARER_MODEM "bearer-modem"
#define MM_BASE_BEARER_STATUS "bearer-status"
#define MM_BASE_BEARER_CONFIG "bearer-config"
#define MM_BASE_BEARER_DEFAULT_IP_FAMILY "bearer-default-ip-family"
#define MM_BASE_BEARER_PATH "bearer-path"
#define MM_BASE_BEARER_CONNECTION "bearer-connection"
#define MM_BASE_BEARER_MODEM "bearer-modem"
#define MM_BASE_BEARER_STATUS "bearer-status"
#define MM_BASE_BEARER_CONFIG "bearer-config"
typedef enum { /*< underscore_name=mm_bearer_status >*/
MM_BEARER_STATUS_DISCONNECTED,
@@ -148,12 +147,10 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMBaseBearer, g_object_unref)
void mm_base_bearer_export (MMBaseBearer *self);
const gchar *mm_base_bearer_get_path (MMBaseBearer *self);
MMBearerStatus mm_base_bearer_get_status (MMBaseBearer *self);
MMBearerProperties *mm_base_bearer_peek_config (MMBaseBearer *self);
MMBearerProperties *mm_base_bearer_get_config (MMBaseBearer *self);
MMBearerIpFamily mm_base_bearer_get_default_ip_family (MMBaseBearer *self);
const gchar *mm_base_bearer_get_path (MMBaseBearer *self);
MMBearerStatus mm_base_bearer_get_status (MMBaseBearer *self);
MMBearerProperties *mm_base_bearer_peek_config (MMBaseBearer *self);
MMBearerProperties *mm_base_bearer_get_config (MMBaseBearer *self);
void mm_base_bearer_connect (MMBaseBearer *self,
GAsyncReadyCallback callback,
+1 -10
View File
@@ -1054,16 +1054,7 @@ connect_context_step (GTask *task)
}
ip_family = mm_bearer_properties_get_ip_type (ctx->properties);
if (ip_family == MM_BEARER_IP_FAMILY_NONE ||
ip_family == MM_BEARER_IP_FAMILY_ANY) {
gchar * str;
ip_family = mm_base_bearer_get_default_ip_family (MM_BASE_BEARER (self));
str = mm_bearer_ip_family_build_string_from_mask (ip_family);
mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", str);
g_free (str);
}
mm_3gpp_normalize_ip_family (&ip_family, self);
ctx->requested_ip_type = mm_bearer_ip_family_to_mbim_context_ip_type (ip_family, &error);
if (error) {
g_task_return_error (task, error);
+1 -9
View File
@@ -2068,16 +2068,8 @@ _connect (MMBaseBearer *_self,
ctx->password = g_strdup (mm_bearer_properties_get_password (properties));
ip_family = mm_bearer_properties_get_ip_type (properties);
if (ip_family == MM_BEARER_IP_FAMILY_NONE ||
ip_family == MM_BEARER_IP_FAMILY_ANY) {
gchar *ip_family_str;
ip_family = mm_base_bearer_get_default_ip_family (_self);
ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family);
mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", ip_family_str);
if (mm_3gpp_normalize_ip_family (&ip_family, self))
ctx->no_ip_family_preference = TRUE;
g_free (ip_family_str);
}
if (ip_family & MM_BEARER_IP_FAMILY_IPV4)
ctx->ipv4 = TRUE;
+7 -22
View File
@@ -80,26 +80,6 @@ mm_broadband_bearer_get_3gpp_cid (MMBroadbandBearer *self)
return self->priv->cid;
}
/*****************************************************************************/
static MMBearerIpFamily
select_bearer_ip_family (MMBroadbandBearer *self)
{
MMBearerIpFamily ip_family;
ip_family = mm_bearer_properties_get_ip_type (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
if (ip_family == MM_BEARER_IP_FAMILY_NONE || ip_family == MM_BEARER_IP_FAMILY_ANY) {
gchar *default_family;
ip_family = mm_base_bearer_get_default_ip_family (MM_BASE_BEARER (self));
default_family = mm_bearer_ip_family_build_string_from_mask (ip_family);
mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", default_family);
g_free (default_family);
}
return ip_family;
}
/*****************************************************************************/
/* Detailed connect context, used in both CDMA and 3GPP sequences */
@@ -150,7 +130,9 @@ detailed_connect_context_new (MMBroadbandBearer *self,
ctx->modem = MM_BASE_MODEM (g_object_ref (modem));
ctx->primary = g_object_ref (primary);
ctx->secondary = (secondary ? g_object_ref (secondary) : NULL);
ctx->ip_family = select_bearer_ip_family (self);
ctx->ip_family = mm_bearer_properties_get_ip_type (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
mm_3gpp_normalize_ip_family (&ctx->ip_family, self);
return ctx;
}
@@ -924,7 +906,10 @@ cid_selection_3gpp (MMBroadbandBearer *self,
ctx->modem = g_object_ref (modem);
ctx->primary = g_object_ref (primary);
ctx->cancellable = g_object_ref (cancellable);
ctx->ip_family = select_bearer_ip_family (self);
ctx->ip_family = mm_bearer_properties_get_ip_type (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
mm_3gpp_normalize_ip_family (&ctx->ip_family, self);
g_task_set_task_data (task, ctx, (GDestroyNotify) cid_selection_3gpp_context_free);
/* Validate PDP type */
+14
View File
@@ -4099,6 +4099,20 @@ mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type)
return MM_BEARER_IP_FAMILY_NONE;
}
gboolean
mm_3gpp_normalize_ip_family (MMBearerIpFamily *family,
gpointer log_object)
{
/* if nothing specific requested, default to IPv4 */
if (*family == MM_BEARER_IP_FAMILY_NONE || *family == MM_BEARER_IP_FAMILY_ANY) {
*family = MM_BEARER_IP_FAMILY_IPV4;
return TRUE;
}
/* no need to normalize */
return FALSE;
}
/*************************************************************************/
/* ICCID validation */
/*
+4 -2
View File
@@ -437,8 +437,10 @@ gboolean mm_3gpp_parse_operator_id (const gchar *operator_id,
guint16 *mnc,
GError **error);
const gchar *mm_3gpp_get_pdp_type_from_ip_family (MMBearerIpFamily family);
MMBearerIpFamily mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type);
const gchar *mm_3gpp_get_pdp_type_from_ip_family (MMBearerIpFamily family);
MMBearerIpFamily mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type);
gboolean mm_3gpp_normalize_ip_family (MMBearerIpFamily *family,
gpointer log_object);
char *mm_3gpp_parse_iccid (const char *raw_iccid, GError **error);