mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 17:10:08 +01:00
ifcfg-rh: add ifcfg-vlan writer
add write_vlan_setting() and modify test-ifcfg-rh.c to test it. Signed-off-by: Weiping Pan <wpan@redhat.com> (updates by dcbw for changes made to original patch series)
This commit is contained in:
parent
0c3efb1787
commit
ccea442504
2 changed files with 133 additions and 0 deletions
|
|
@ -44,6 +44,7 @@
|
|||
#include <nm-setting-gsm.h>
|
||||
#include <nm-setting-cdma.h>
|
||||
#include <nm-setting-serial.h>
|
||||
#include <nm-setting-vlan.h>
|
||||
|
||||
#include "nm-test-helpers.h"
|
||||
|
||||
|
|
@ -11820,6 +11821,46 @@ test_read_vlan_interface (void)
|
|||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_vlan (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
char *routefile = NULL;
|
||||
char *route6file = NULL;
|
||||
char *written = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GError *error = NULL;
|
||||
gboolean success = FALSE;
|
||||
|
||||
connection = connection_from_file (TEST_IFCFG_VLAN_INTERFACE,
|
||||
NULL,
|
||||
TYPE_VLAN,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&routefile,
|
||||
&route6file,
|
||||
&error,
|
||||
&ignore_error);
|
||||
g_assert (connection != NULL);
|
||||
|
||||
success = writer_new_connection (connection,
|
||||
TEST_SCRATCH_DIR "/network-scripts/",
|
||||
&written,
|
||||
&error);
|
||||
g_assert (success);
|
||||
|
||||
unlink (written);
|
||||
g_free (written);
|
||||
|
||||
g_free (unmanaged);
|
||||
g_free (keyfile);
|
||||
g_free (routefile);
|
||||
g_free (route6file);
|
||||
}
|
||||
|
||||
#define TEST_IFCFG_BOND_MAIN TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bond-main"
|
||||
|
||||
static void
|
||||
|
|
@ -12311,6 +12352,7 @@ int main (int argc, char **argv)
|
|||
test_read_bridge_main ();
|
||||
test_read_bridge_component ();
|
||||
test_read_vlan_interface ();
|
||||
test_write_vlan ();
|
||||
test_read_bond_main ();
|
||||
test_read_bond_slave ();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
#include <nm-setting-ip4-config.h>
|
||||
#include <nm-setting-ip6-config.h>
|
||||
#include <nm-setting-pppoe.h>
|
||||
#include <nm-setting-vlan.h>
|
||||
#include <nm-utils.h>
|
||||
|
||||
#include "common.h"
|
||||
|
|
@ -1125,6 +1126,93 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static GString *vlan_priority_maplist_to_stringlist (NMSettingVlan *s_vlan, NMVlanPriorityMap map)
|
||||
{
|
||||
GSList *strlist = NULL, *iter;
|
||||
GString *value = NULL;
|
||||
|
||||
if (map == NM_VLAN_INGRESS_MAP)
|
||||
g_object_get (G_OBJECT (s_vlan), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, &strlist, NULL);
|
||||
else if (map == NM_VLAN_EGRESS_MAP)
|
||||
g_object_get (G_OBJECT (s_vlan), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, &strlist, NULL);
|
||||
else
|
||||
return NULL;
|
||||
|
||||
value = g_string_new ("");
|
||||
for (iter = strlist; iter; iter = g_slist_next (iter))
|
||||
g_string_append_printf (value, "%s%s", value->len ? "," : "", (const char *) iter->data);
|
||||
|
||||
nm_utils_slist_free (strlist, g_free);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
||||
{
|
||||
NMSettingVlan *s_vlan;
|
||||
NMSettingConnection *s_con;
|
||||
const char *master = NULL;
|
||||
guint32 vlan_flags = 0;
|
||||
GString *text = NULL;
|
||||
|
||||
s_con = nm_connection_get_setting_connection (connection);
|
||||
if (!s_con) {
|
||||
g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "Missing connection setting");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
s_vlan = nm_connection_get_setting_vlan (connection);
|
||||
if (!s_vlan) {
|
||||
g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "Missing VLAN setting");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "VLAN", "yes", FALSE);
|
||||
svSetValue (ifcfg, "TYPE", TYPE_VLAN, FALSE);
|
||||
|
||||
master = nm_setting_connection_get_master (s_con);
|
||||
if (!master) {
|
||||
g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0,
|
||||
"Missing VLAN master interface name or connection UUID");
|
||||
return FALSE;
|
||||
}
|
||||
svSetValue (ifcfg, "PHYSDEV", master, FALSE);
|
||||
svSetValue (ifcfg, "MASTER", master, FALSE);
|
||||
|
||||
svSetValue (ifcfg, "DEVICE", nm_setting_vlan_get_interface_name (s_vlan), FALSE);
|
||||
|
||||
vlan_flags = nm_setting_vlan_get_flags (s_vlan);
|
||||
if (vlan_flags & NM_VLAN_FLAG_REORDER_HEADERS)
|
||||
svSetValue (ifcfg, "REORDER_HDR", "1", FALSE);
|
||||
else
|
||||
svSetValue (ifcfg, "REORDER_HDR", "0", FALSE);
|
||||
|
||||
if (vlan_flags & NM_VLAN_FLAG_GVRP) {
|
||||
if (vlan_flags & NM_VLAN_FLAG_LOOSE_BINDING)
|
||||
svSetValue (ifcfg, "VLAN_FLAGS", "GVRP,LOOSE_BINDING", FALSE);
|
||||
else
|
||||
svSetValue (ifcfg, "VLAN_FLAGS", "GVRP", FALSE);
|
||||
} else {
|
||||
if (vlan_flags & NM_VLAN_FLAG_LOOSE_BINDING)
|
||||
svSetValue (ifcfg, "VLAN_FLAGS", "LOOSE_BINDING", FALSE);
|
||||
}
|
||||
|
||||
text = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP);
|
||||
if (text != NULL)
|
||||
svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", text->str, FALSE);
|
||||
g_string_free (text, TRUE);
|
||||
text = NULL;
|
||||
|
||||
text = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_EGRESS_MAP);
|
||||
if (text != NULL)
|
||||
svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", text->str, FALSE);
|
||||
g_string_free (text, TRUE);
|
||||
text = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg)
|
||||
{
|
||||
|
|
@ -1831,6 +1919,9 @@ write_connection (NMConnection *connection,
|
|||
if (!write_wired_setting (connection, ifcfg, error))
|
||||
goto out;
|
||||
wired = TRUE;
|
||||
} else if (!strcmp (type, NM_SETTING_VLAN_SETTING_NAME)) {
|
||||
if (!write_vlan_setting (connection, ifcfg, error))
|
||||
goto out;
|
||||
} else if (!strcmp (type, NM_SETTING_WIRELESS_SETTING_NAME)) {
|
||||
if (!write_wireless_setting (connection, ifcfg, &no_8021x, error))
|
||||
goto out;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue