Commit 902bbfdb authored by Lubomir Rintel's avatar Lubomir Rintel 🥕

ifcfg-rh: add tc support

Format:

  QDISC1=ingress
  QDISC2="root handle 1234: fq_codel"
  FILTER1="parent ffff: matchall action simple sdata Input"
  FILTER2="parent 1234: matchall action simple sdata Output"
parent 8bffb2c7
......@@ -1523,6 +1523,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *setting_class)
*
* Element-Type: NMTCQdisc
**/
/* ---ifcfg-rh---
* property: qdiscs
* variable: QDISC1, QDISC2, ...
* description: Queueing disciplines
* example: QDISC1=ingress, QDISC2="root handle 1234: fq_codel"
* ---end---
*/
g_object_class_install_property
(object_class, PROP_QDISCS,
g_param_spec_boxed (NM_SETTING_TC_CONFIG_QDISCS, "", "",
......@@ -1545,6 +1552,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *setting_class)
*
* Element-Type: NMTCTfilter
**/
/* ---ifcfg-rh---
* property: qdiscs
* variable: FILTER1, FILTER2, ...
* description: Traffic filters
* example: FILTER1="parent ffff: matchall action simple sdata Input", ...
* ---end---
*/
g_object_class_install_property
(object_class, PROP_TFILTERS,
g_param_spec_boxed (NM_SETTING_TC_CONFIG_TFILTERS, "", "",
......
......@@ -1964,6 +1964,59 @@ error:
return NULL;
}
static NMSetting *
make_tc_setting (shvarFile *ifcfg)
{
NMSettingTCConfig *s_tc = NULL;
char tag[256];
int i;
s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new ();
for (i = 1;; i++) {
NMTCQdisc *qdisc = NULL;
gs_free char *value_to_free = NULL;
const char *value = NULL;
GError *local = NULL;
value = svGetValueStr (ifcfg, numbered_tag (tag, "QDISC", i), &value_to_free);
if (!value)
break;
qdisc = nm_utils_tc_qdisc_from_str (value, &local);
if (!qdisc)
PARSE_WARNING ("ignoring bad qdisc: '%s': %s", value, local->message);
if (!nm_setting_tc_config_add_qdisc (s_tc, qdisc))
PARSE_WARNING ("duplicate qdisc");
}
for (i = 1;; i++) {
NMTCTfilter *tfilter = NULL;
gs_free char *value_to_free = NULL;
const char *value = NULL;
GError *local = NULL;
value = svGetValueStr (ifcfg, numbered_tag (tag, "FILTER", i), &value_to_free);
if (!value)
break;
tfilter = nm_utils_tc_tfilter_from_str (value, &local);
if (!tfilter)
PARSE_WARNING ("ignoring bad tfilter: '%s': %s", value, local->message);
if (!nm_setting_tc_config_add_tfilter (s_tc, tfilter))
PARSE_WARNING ("duplicate filter");
}
if ( nm_setting_tc_config_get_num_qdiscs (s_tc) > 0
|| nm_setting_tc_config_get_num_tfilters (s_tc) > 0)
return NM_SETTING (s_tc);
g_object_unref (s_tc);
return NULL;
}
typedef struct {
const char *enable_key;
const char *advertise_key;
......@@ -5242,7 +5295,7 @@ connection_from_file_full (const char *filename,
gs_unref_object NMConnection *connection = NULL;
gs_free char *type = NULL;
char *devtype, *bootproto;
NMSetting *s_ip4, *s_ip6, *s_proxy, *s_port, *s_dcb = NULL, *s_user;
NMSetting *s_ip4, *s_ip6, *s_tc, *s_proxy, *s_port, *s_dcb = NULL, *s_user;
const char *ifcfg_name = NULL;
gboolean has_ip4_defroute = FALSE;
gboolean has_complex_routes_v4;
......@@ -5499,6 +5552,10 @@ connection_from_file_full (const char *filename,
nm_connection_add_setting (connection, s_ip4);
}
s_tc = make_tc_setting (parsed);
if (s_tc)
nm_connection_add_setting (connection, s_tc);
/* For backwards compatibility, if IPv4 is disabled or the
* config fails for some reason, we read DOMAIN and put the
* values into IPv6 config instead of IPv4.
......
......@@ -2125,6 +2125,51 @@ write_user_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
return TRUE;
}
static gboolean
write_tc_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
{
NMSettingTCConfig *s_tc;
guint i, num, n;
char tag[64];
svUnsetAll (ifcfg, SV_KEY_TYPE_TC);
s_tc = nm_connection_get_setting_tc_config (connection);
if (!s_tc)
return TRUE;
num = nm_setting_tc_config_get_num_qdiscs (s_tc);
for (n = 1, i = 0; i < num; i++) {
NMTCQdisc *qdisc;
gs_free char *str = NULL;
qdisc = nm_setting_tc_config_get_qdisc (s_tc, i);
str = nm_utils_tc_qdisc_to_str (qdisc, error);
if (!str)
return FALSE;
svSetValueStr (ifcfg, numbered_tag (tag, "QDISC", n), str);
n++;
}
num = nm_setting_tc_config_get_num_tfilters (s_tc);
for (n = 1, i = 0; i < num; i++) {
NMTCTfilter *tfilter;
gs_free char *str = NULL;
tfilter = nm_setting_tc_config_get_tfilter (s_tc, i);
str = nm_utils_tc_tfilter_to_str (tfilter, error);
if (!str)
return FALSE;
svSetValueStr (ifcfg, numbered_tag (tag, "FILTER", n), str);
n++;
}
return TRUE;
}
static void
write_res_options (shvarFile *ifcfg, NMSettingIPConfig *s_ip, const char *var)
{
......@@ -2860,6 +2905,9 @@ do_write_construct (NMConnection *connection,
if (!write_user_setting (connection, ifcfg, error))
return FALSE;
if (!write_tc_setting (connection, ifcfg, error))
return FALSE;
svUnsetValue (ifcfg, "DHCP_HOSTNAME");
svUnsetValue (ifcfg, "DHCP_FQDN");
......
......@@ -1171,6 +1171,11 @@ svUnsetAll (shvarFile *s, SvKeyType match_key_type)
if (g_str_has_prefix (line->key, "NM_USER_"))
goto do_clear;
}
if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_TC)) {
if ( IS_NUMBERED_TAG (line->key, "QDISC")
|| IS_NUMBERED_TAG (line->key, "FILTER"))
goto do_clear;
}
continue;
do_clear:
......
......@@ -90,7 +90,8 @@ typedef enum {
SV_KEY_TYPE_ANY = (1LL << 0),
SV_KEY_TYPE_ROUTE_SVFORMAT = (1LL << 1),
SV_KEY_TYPE_IP4_ADDRESS = (1LL << 2),
SV_KEY_TYPE_USER = (1LL << 3),
SV_KEY_TYPE_TC = (1LL << 3),
SV_KEY_TYPE_USER = (1LL << 4),
} SvKeyType;
gboolean svUnsetAll (shvarFile *s, SvKeyType match_key_type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment