View | Details | Raw Unified | Return to bug 60536
Collapse All | Expand All

(-)a/src/core/settings/plugins/etcnet-alt/nms-etcnet-alt-reader.c (-2 / +92 lines)
Lines 1159-1164 error: Link Here
1159
    return NULL;
1159
    return NULL;
1160
}
1160
}
1161
1161
1162
static NMSetting *
1163
make_vlan_setting(options_file_t *options, GError **error)
1164
{
1165
    NMSettingVlan *s_vlan = NULL;
1166
    char *         host   = NULL;
1167
    char *         vid    = NULL;
1168
    long int       vlan_id;
1169
1170
    g_return_val_if_fail(options != NULL, NULL);
1171
1172
    host = options_get_value(options, "HOST");
1173
    if (!host || !host[0]) {
1174
        PLUGIN_SET_ERROR_LITERAL(error, "Missing VLAN HOST option");
1175
        goto done;
1176
    }
1177
1178
    vid = options_get_value(options, "VID");
1179
    if (!vid || !get_int(vid, &vlan_id) || vlan_id < 0 || vlan_id > 4094) {
1180
        PLUGIN_SET_ERROR(error, "Invalid VLAN VID '%s'", vid ? vid : "");
1181
        goto done;
1182
    }
1183
1184
    s_vlan = NM_SETTING_VLAN(nm_setting_vlan_new());
1185
    g_object_set(s_vlan,
1186
                 NM_SETTING_VLAN_PARENT,
1187
                 host,
1188
                 NM_SETTING_VLAN_ID,
1189
                 (guint32) vlan_id,
1190
                 NULL);
1191
1192
done:
1193
    g_free(host);
1194
    g_free(vid);
1195
    return NM_SETTING(s_vlan);
1196
}
1197
1198
static NMConnection *
1199
read_vlan_connection(const char *    iface_path,
1200
                     options_file_t *options,
1201
                     GError **       error)
1202
{
1203
    NMConnection *connection    = NULL;
1204
    NMSetting *   con_setting   = NULL;
1205
    NMSetting *   vlan_setting  = NULL;
1206
    NMSetting *   wired_setting = NULL;
1207
1208
    g_return_val_if_fail(iface_path != NULL, NULL);
1209
    g_return_val_if_fail(options != NULL, NULL);
1210
1211
    connection = nm_simple_connection_new();
1212
    if (!connection) {
1213
        PLUGIN_SET_ERROR(error, "Failed to allocate new connection for %s.", iface_path);
1214
        return NULL;
1215
    }
1216
1217
    con_setting = make_connection_setting(iface_path,
1218
                                          options,
1219
                                          NM_SETTING_VLAN_SETTING_NAME,
1220
                                          NULL);
1221
    if (!con_setting) {
1222
        PLUGIN_SET_ERROR_LITERAL(error, "Failed to create connection setting.");
1223
        goto error;
1224
    }
1225
    nm_connection_add_setting(connection, con_setting);
1226
1227
    vlan_setting = make_vlan_setting(options, error);
1228
    if (!vlan_setting)
1229
        goto error;
1230
    nm_connection_add_setting(connection, vlan_setting);
1231
1232
    wired_setting = make_wired_setting(iface_path, error);
1233
    if (!wired_setting)
1234
        goto error;
1235
    nm_connection_add_setting(connection, wired_setting);
1236
1237
    if (!nm_connection_verify(connection, error))
1238
        goto error;
1239
1240
    return connection;
1241
1242
error:
1243
    g_object_unref(connection);
1244
    return NULL;
1245
}
1246
1162
static char *
1247
static char *
1163
get_supplicant_config_value(GHashTable *wsconf, const char *key, gboolean to_lower)
1248
get_supplicant_config_value(GHashTable *wsconf, const char *key, gboolean to_lower)
1164
{
1249
{
Lines 1604-1611 read_wireless_connection(const char * iface_path, Link Here
1604
    return connection;
1707
    return connection;
1605
}
1708
}
1606
1709
1607
/* Only NM_DEVICE_TYPE_WIFI and NM_DEVICE_TYPE_ETHERNET are
1710
/* Only NM_DEVICE_TYPE_WIFI, NM_DEVICE_TYPE_ETHERNET and
1608
 * recognized */
1711
 * NM_DEVICE_TYPE_VLAN are recognized */
1609
static NMDeviceType
1712
static NMDeviceType
1610
get_device_type(options_file_t *options, const char *iface_name)
1713
get_device_type(options_file_t *options, const char *iface_name)
1611
{
1714
{
Lines 1626-1631 get_device_type(options_file_t *options, const char *iface_name) Link Here
1626
            dev_type = options_true_value(options, "CONFIG_WIRELESS", FALSE) ?
1729
            dev_type = options_true_value(options, "CONFIG_WIRELESS", FALSE) ?
1627
                       NM_DEVICE_TYPE_WIFI : NM_DEVICE_TYPE_ETHERNET;
1730
                       NM_DEVICE_TYPE_WIFI : NM_DEVICE_TYPE_ETHERNET;
1628
        }
1731
        }
1732
    } else if (!g_ascii_strcasecmp("vlan", options->type)) {
1733
        dev_type = NM_DEVICE_TYPE_VLAN;
1629
    }
1734
    }
1630
1735
1631
    return dev_type;
1736
    return dev_type;
Lines 1697-1702 read_connection(const char * iface_path, Link Here
1697
        connection =
1802
        connection =
1698
            read_wireless_connection(iface_path, options, wsconf, error);
1803
            read_wireless_connection(iface_path, options, wsconf, error);
1699
        break;
1804
        break;
1805
    case NM_DEVICE_TYPE_VLAN:
1806
        connection = read_vlan_connection(iface_path, options, error);
1807
        break;
1700
    default:
1808
    default:
1701
        PLUGIN_SET_ERROR(error,
1809
        PLUGIN_SET_ERROR(error,
1702
                         "Connection for %s : Unknown device type",
1810
                         "Connection for %s : Unknown device type",
(-)a/src/core/settings/plugins/etcnet-alt/tests/ifaces-config/ens19.100/ipv4address (+1 lines)
Line 0 Link Here
1
192.168.0.1/24
(-)a/src/core/settings/plugins/etcnet-alt/tests/ifaces-config/ens19.100/options (+12 lines)
Line 0 Link Here
1
TYPE=vlan
2
HOST=ens19
3
VID=100
4
ONBOOT=yes
5
CONFIG_WIRELESS=no
6
CONFIG_IPV4=yes
7
CONFIG_IPV6=no
8
BOOTPROTO=static
9
SYSTEMD_BOOTPROTO=static
10
DISABLED=yes
11
NM_CONTROLLED=yes
12
SYSTEMD_CONTROLLED=no
(-)a/src/core/settings/plugins/etcnet-alt/tests/ifaces-config/ens19.200/options (+8 lines)
Line 0 Link Here
1
TYPE=vlan
2
HOST=ens19
3
VID=200
4
ONBOOT=yes
5
CONFIG_IPV4=no
6
CONFIG_IPV6=no
7
NM_CONTROLLED=yes
8
SYSTEMD_CONTROLLED=no
(-)a/src/core/settings/plugins/etcnet-alt/tests/test-etcnet-alt.c (+98 lines)
Lines 28-33 Link Here
28
#define TEST_CONFIG_WIRELESS_DHCP TEST_CONFIGS_DIR "/ifaces-config/wl"
28
#define TEST_CONFIG_WIRELESS_DHCP TEST_CONFIGS_DIR "/ifaces-config/wl"
29
#define TEST_CONFIG_IPV6          TEST_CONFIGS_DIR "/ifaces-config/ipv6"
29
#define TEST_CONFIG_IPV6          TEST_CONFIGS_DIR "/ifaces-config/ipv6"
30
#define TEST_CONFIG_BRIDGE        TEST_CONFIGS_DIR "/ifaces-config/bridge"
30
#define TEST_CONFIG_BRIDGE        TEST_CONFIGS_DIR "/ifaces-config/bridge"
31
#define TEST_CONFIG_VLAN_STATIC   TEST_CONFIGS_DIR "/ifaces-config/ens19.100"
32
#define TEST_CONFIG_VLAN_L2       TEST_CONFIGS_DIR "/ifaces-config/ens19.200"
31
33
32
static void
34
static void
33
verify_setting_connection(NMSettingConnection *s_con, const char *expected_id,
35
verify_setting_connection(NMSettingConnection *s_con, const char *expected_id,
Lines 1475-1480 test_read_bridge_ignored(void) Link Here
1475
    test_read_bridge(TEST_CONFIG_BRIDGE, NULL, TRUE, TRUE, "System bridge");
1476
    test_read_bridge(TEST_CONFIG_BRIDGE, NULL, TRUE, TRUE, "System bridge");
1476
}
1477
}
1477
1478
1479
static void
1480
test_read_vlan(const char *             iface_path,
1481
               const char *             expected_id,
1482
               const char *             expected_iface_name,
1483
               guint32                  expected_vid,
1484
               const char *             expected_ipv4_method,
1485
               guint32                  expected_num_ipv4addr,
1486
               const test_ip_address_t *expected_ipv4addresses)
1487
{
1488
    NMConnection *       connection;
1489
    NMSettingConnection *s_con;
1490
    NMSettingVlan *      s_vlan;
1491
    NMSettingIPConfig *  s_ip4;
1492
    NMSettingIPConfig *  s_ip6;
1493
    GError *             error   = NULL;
1494
    gboolean             ignored = TRUE;
1495
1496
    connection = read_connection(iface_path, NULL, &ignored, &error);
1497
1498
    g_assert_false(ignored);
1499
    g_assert_no_error(error);
1500
    g_assert(connection);
1501
    nmtst_assert_connection_verifies(connection);
1502
1503
    s_con = nm_connection_get_setting_connection(connection);
1504
    verify_setting_connection(s_con, expected_id, TRUE);
1505
    g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con),
1506
                    ==,
1507
                    NM_SETTING_VLAN_SETTING_NAME);
1508
    g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, expected_iface_name);
1509
1510
    s_vlan = nm_connection_get_setting_vlan(connection);
1511
    g_assert(s_vlan);
1512
    g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "ens19");
1513
    g_assert_cmpuint(nm_setting_vlan_get_id(s_vlan), ==, expected_vid);
1514
1515
    s_ip4 = nm_connection_get_setting_ip4_config(connection);
1516
    verify_setting_ip(s_ip4,
1517
                      expected_id,
1518
                      expected_ipv4_method,
1519
                      expected_num_ipv4addr,
1520
                      expected_ipv4addresses,
1521
                      NULL,
1522
                      0,
1523
                      NULL,
1524
                      0,
1525
                      NULL,
1526
                      0,
1527
                      NULL);
1528
1529
    s_ip6 = nm_connection_get_setting_ip6_config(connection);
1530
    verify_setting_ip(s_ip6,
1531
                      expected_id,
1532
                      NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
1533
                      0,
1534
                      NULL,
1535
                      NULL,
1536
                      0,
1537
                      NULL,
1538
                      0,
1539
                      NULL,
1540
                      0,
1541
                      NULL);
1542
1543
    g_object_unref(connection);
1544
}
1545
1546
static void
1547
test_read_vlan_static(void)
1548
{
1549
    const test_ip_address_t addresses[1] = {{"192.168.0.1", 24}};
1550
1551
    test_read_vlan(TEST_CONFIG_VLAN_STATIC,
1552
                   "System ens19.100",
1553
                   "ens19.100",
1554
                   100,
1555
                   NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
1556
                   1,
1557
                   addresses);
1558
}
1559
1560
static void
1561
test_read_vlan_l2(void)
1562
{
1563
    test_read_vlan(TEST_CONFIG_VLAN_L2,
1564
                   "System ens19.200",
1565
                   "ens19.200",
1566
                   200,
1567
                   NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
1568
                   0,
1569
                   NULL);
1570
}
1571
1478
static void
1572
static void
1479
test_read_eth_dhcp_no_type(void)
1573
test_read_eth_dhcp_no_type(void)
1480
{
1574
{
Lines 1533-1538 main(int argc, char **argv) Link Here
1533
1610
1534
    g_test_add_func(TPATH "test_read_bridge_ignored", test_read_bridge_ignored);
1611
    g_test_add_func(TPATH "test_read_bridge_ignored", test_read_bridge_ignored);
1535
1612
1613
    g_test_add_func(TPATH "test_read_vlan_static", test_read_vlan_static);
1614
    g_test_add_func(TPATH "test_read_vlan_l2", test_read_vlan_l2);
1615
1536
    g_test_add_func(TPATH "test_read_eth_dhcp_no_type", test_read_eth_dhcp_no_type);
1616
    g_test_add_func(TPATH "test_read_eth_dhcp_no_type", test_read_eth_dhcp_no_type);
1537
1617
1538
    return g_test_run();
1618
    return g_test_run();

Return to bug 60536