Class: Yast::LanItemsClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
../../src/modules/LanItems.rb

Overview

FIXME: well this class really is not nice rubocop:disable ClassLength

Constant Summary

TRISTATE_TO_S =
{ nil => nil, false => "no", true => "yes" }.freeze

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (list <map>) :Hardware(:Hardware)

Returns:

  • (list <map>)


2591
# File '../../src/modules/LanItems.rb', line 2591

publish_variable :Hardware, "list <map>"

- (Hash<Integer, Hash<String, Object> >, map <integer, any>) :Items(:Items)

Each item, indexed by an Integer in a Hash, aggregates several aspects of a network interface. These aspects are in the inner Hash which mostly has other hashes as values:

  • ifcfg: String, just a foreign key for NetworkInterfaces#Select

  • hwinfo: Hash, detected hardware information

  • udev: Hash, udev naming rules

Returns:

  • (Hash<Integer, Hash<String, Object> >)
  • (map <integer, any>)


2589
# File '../../src/modules/LanItems.rb', line 2589

publish_variable :Items, "map <integer, any>"

- (list <string>) :Requires(:Requires)

Returns:

  • (list <string>)


2606
# File '../../src/modules/LanItems.rb', line 2606

publish_variable :Requires, "list <string>"

- (map <string, string>) :SysconfigDefaults(:SysconfigDefaults)

Returns:

  • (map <string, string>)


2659
# File '../../src/modules/LanItems.rb', line 2659

publish_variable :SysconfigDefaults, "map <string, string>"

- (string) alias

Returns:

  • (string)


2601
# File '../../src/modules/LanItems.rb', line 2601

publish_variable :alias, "string"

- (map) aliases

Returns:

  • (map)


2652
# File '../../src/modules/LanItems.rb', line 2652

publish_variable :aliases, "map"

- (map) autoinstall_settings

Returns:

  • (map)


2594
# File '../../src/modules/LanItems.rb', line 2594

publish_variable :autoinstall_settings, "map"

- (string) bond_option

Returns:

  • (string)


2627
# File '../../src/modules/LanItems.rb', line 2627

publish_variable :bond_option, "string"

- (list <string>) bond_slaves

Returns:

  • (list <string>)


2626
# File '../../src/modules/LanItems.rb', line 2626

publish_variable :bond_slaves, "list <string>"

- (string) bootproto

Returns:

  • (string)


2607
# File '../../src/modules/LanItems.rb', line 2607

publish_variable :bootproto, "string"

- (string) bridge_ports

Returns:

  • (string)


2630
# File '../../src/modules/LanItems.rb', line 2630

publish_variable :bridge_ports, "string"

- (string) chan_mode

Returns:

  • (string)


2644
# File '../../src/modules/LanItems.rb', line 2644

publish_variable :chan_mode, "string"

- (integer) current

the index into #Items

Returns:

  • (integer)


2603
# File '../../src/modules/LanItems.rb', line 2603

publish_variable :current, "integer"

- (string) description

Returns:

  • (string)


2598
# File '../../src/modules/LanItems.rb', line 2598

publish_variable :description, "string"

- (string) device

Returns:

  • (string)


2600
# File '../../src/modules/LanItems.rb', line 2600

publish_variable :device, "string"

- (map <string, any>) driver_options

Returns:

  • (map <string, any>)


2593
# File '../../src/modules/LanItems.rb', line 2593

publish_variable :driver_options, "map <string, any>"

- (string) ethtool_options

Returns:

  • (string)


2616
# File '../../src/modules/LanItems.rb', line 2616

publish_variable :ethtool_options, "string"

- (boolean) force_restart

Returns:

  • (boolean)


2597
# File '../../src/modules/LanItems.rb', line 2597

publish_variable :force_restart, "boolean"

- (list <map>) Hardware

Returns:

  • (list <map>)


2591
# File '../../src/modules/LanItems.rb', line 2591

publish_variable :Hardware, "list <map>"

- (string) hotplug

Returns:

  • (string)


2604
# File '../../src/modules/LanItems.rb', line 2604

publish_variable :hotplug, "string"

- (string) ifplugd_priority

Returns:

  • (string)


2614
# File '../../src/modules/LanItems.rb', line 2614

publish_variable :ifplugd_priority, "string"

- (boolean) ipa_takeover

Returns:

  • (boolean)


2646
# File '../../src/modules/LanItems.rb', line 2646

publish_variable :ipa_takeover, "boolean"

- (string) ipaddr

Returns:

  • (string)


2608
# File '../../src/modules/LanItems.rb', line 2608

publish_variable :ipaddr, "string"

- (Object) ipoib_mode

Returns the value of attribute ipoib_mode



45
46
47
# File '../../src/modules/LanItems.rb', line 45

def ipoib_mode
  @ipoib_mode
end

- (Object) ipoib_modes (readonly)

Returns the value of attribute ipoib_modes



44
45
46
# File '../../src/modules/LanItems.rb', line 44

def ipoib_modes
  @ipoib_modes
end

- (Hash<Integer, Hash<String, Object> >, map <integer, any>) Items

Each item, indexed by an Integer in a Hash, aggregates several aspects of a network interface. These aspects are in the inner Hash which mostly has other hashes as values:

  • ifcfg: String, just a foreign key for NetworkInterfaces#Select

  • hwinfo: Hash, detected hardware information

  • udev: Hash, udev naming rules

Returns:

  • (Hash<Integer, Hash<String, Object> >)
  • (map <integer, any>)


2589
# File '../../src/modules/LanItems.rb', line 2589

publish_variable :Items, "map <integer, any>"

- (string) iucv_user

Returns:

  • (string)


2647
# File '../../src/modules/LanItems.rb', line 2647

publish_variable :iucv_user, "string"

- (string) lcs_timeout

Returns:

  • (string)


2651
# File '../../src/modules/LanItems.rb', line 2651

publish_variable :lcs_timeout, "string"

- (boolean) modified

Returns:

  • (boolean)


2595
# File '../../src/modules/LanItems.rb', line 2595

publish_variable :modified, "boolean"

- (string) mtu

Returns:

  • (string)


2615
# File '../../src/modules/LanItems.rb', line 2615

publish_variable :mtu, "string"

- (string) netmask

Returns:

  • (string)


2610
# File '../../src/modules/LanItems.rb', line 2610

publish_variable :netmask, "string"

- (string) nm_name

Returns:

  • (string)


2657
# File '../../src/modules/LanItems.rb', line 2657

publish_variable :nm_name, "string"

- (boolean) nm_proposal_valid

Returns:

  • (boolean)


2656
# File '../../src/modules/LanItems.rb', line 2656

publish_variable :nm_proposal_valid, "boolean"

- (symbol) operation

Returns:

  • (symbol)


2596
# File '../../src/modules/LanItems.rb', line 2596

publish_variable :operation, "symbol"

- (string) prefix

Returns:

  • (string)


2612
# File '../../src/modules/LanItems.rb', line 2612

publish_variable :prefix, "string"

- (boolean) proposal_valid

Returns:

  • (boolean)


2655
# File '../../src/modules/LanItems.rb', line 2655

publish_variable :proposal_valid, "boolean"

- (string) qeth_chanids

Returns:

  • (string)


2650
# File '../../src/modules/LanItems.rb', line 2650

publish_variable :qeth_chanids, "string"

- (boolean) qeth_layer2

Returns:

  • (boolean)


2648
# File '../../src/modules/LanItems.rb', line 2648

publish_variable :qeth_layer2, "boolean"

- (string) qeth_macaddress

Returns:

  • (string)


2649
# File '../../src/modules/LanItems.rb', line 2649

publish_variable :qeth_macaddress, "string"

- (string) qeth_options

Returns:

  • (string)


2645
# File '../../src/modules/LanItems.rb', line 2645

publish_variable :qeth_options, "string"

- (string) qeth_portname

Returns:

  • (string)


2642
# File '../../src/modules/LanItems.rb', line 2642

publish_variable :qeth_portname, "string"

- (string) qeth_portnumber

Returns:

  • (string)


2643
# File '../../src/modules/LanItems.rb', line 2643

publish_variable :qeth_portnumber, "string"

- (string) remoteip

Returns:

  • (string)


2609
# File '../../src/modules/LanItems.rb', line 2609

publish_variable :remoteip, "string"

- (list <string>) Requires

Returns:

  • (list <string>)


2606
# File '../../src/modules/LanItems.rb', line 2606

publish_variable :Requires, "list <string>"

- (boolean) set_default_route

Returns:

  • (boolean)


2611
# File '../../src/modules/LanItems.rb', line 2611

publish_variable :set_default_route, "boolean"

- (string) startmode

Returns:

  • (string)


2613
# File '../../src/modules/LanItems.rb', line 2613

publish_variable :startmode, "string"

- (map <string, string>) SysconfigDefaults

Returns:

  • (map <string, string>)


2659
# File '../../src/modules/LanItems.rb', line 2659

publish_variable :SysconfigDefaults, "map <string, string>"

- (string) tunnel_set_group

Returns:

  • (string)


2654
# File '../../src/modules/LanItems.rb', line 2654

publish_variable :tunnel_set_group, "string"

- (string) tunnel_set_owner

Returns:

  • (string)


2653
# File '../../src/modules/LanItems.rb', line 2653

publish_variable :tunnel_set_owner, "string"

- (string) type

Returns:

  • (string)


2599
# File '../../src/modules/LanItems.rb', line 2599

publish_variable :type, "string"

- (map <string, any>) udev_net_rules

Returns:

  • (map <string, any>)


2592
# File '../../src/modules/LanItems.rb', line 2592

publish_variable :udev_net_rules, "map <string, any>"

- (string) vlan_etherdevice

Returns:

  • (string)


2628
# File '../../src/modules/LanItems.rb', line 2628

publish_variable :vlan_etherdevice, "string"

- (string) vlan_id

Returns:

  • (string)


2629
# File '../../src/modules/LanItems.rb', line 2629

publish_variable :vlan_id, "string"

- (string) wl_accesspoint

Returns:

  • (string)


2635
# File '../../src/modules/LanItems.rb', line 2635

publish_variable :wl_accesspoint, "string"

- (string) wl_ap_scanmode

Returns:

  • (string)


2637
# File '../../src/modules/LanItems.rb', line 2637

publish_variable :wl_ap_scanmode, "string"

- (string) wl_auth_mode

Returns:

  • (string)


2620
# File '../../src/modules/LanItems.rb', line 2620

publish_variable :wl_auth_mode, "string"

- (list <string>) wl_auth_modes

Returns:

  • (list <string>)


2638
# File '../../src/modules/LanItems.rb', line 2638

publish_variable :wl_auth_modes, "list <string>"

- (string) wl_bitrate

Returns:

  • (string)


2634
# File '../../src/modules/LanItems.rb', line 2634

publish_variable :wl_bitrate, "string"

- (list <string>) wl_bitrates

Returns:

  • (list <string>)


2641
# File '../../src/modules/LanItems.rb', line 2641

publish_variable :wl_bitrates, "list <string>"

- (string) wl_channel

Returns:

  • (string)


2632
# File '../../src/modules/LanItems.rb', line 2632

publish_variable :wl_channel, "string"

- (list <string>) wl_channels

Returns:

  • (list <string>)


2640
# File '../../src/modules/LanItems.rb', line 2640

publish_variable :wl_channels, "list <string>"

- (integer) wl_default_key

Returns:

  • (integer)


2624
# File '../../src/modules/LanItems.rb', line 2624

publish_variable :wl_default_key, "integer"

- (list <string>) wl_enc_modes

Returns:

  • (list <string>)


2639
# File '../../src/modules/LanItems.rb', line 2639

publish_variable :wl_enc_modes, "list <string>"

- (string) wl_essid

Returns:

  • (string)


2618
# File '../../src/modules/LanItems.rb', line 2618

publish_variable :wl_essid, "string"

- (string) wl_frequency

Returns:

  • (string)


2633
# File '../../src/modules/LanItems.rb', line 2633

publish_variable :wl_frequency, "string"

- (list <string>) wl_key

Returns:

  • (list <string>)


2623
# File '../../src/modules/LanItems.rb', line 2623

publish_variable :wl_key, "list <string>"

- (string) wl_key_length

Returns:

  • (string)


2622
# File '../../src/modules/LanItems.rb', line 2622

publish_variable :wl_key_length, "string"

- (string) wl_mode

Returns:

  • (string)


2617
# File '../../src/modules/LanItems.rb', line 2617

publish_variable :wl_mode, "string"

- (string) wl_nick

Returns:

  • (string)


2625
# File '../../src/modules/LanItems.rb', line 2625

publish_variable :wl_nick, "string"

- (string) wl_nwid

Returns:

  • (string)


2619
# File '../../src/modules/LanItems.rb', line 2619

publish_variable :wl_nwid, "string"

- (boolean) wl_power

Returns:

  • (boolean)


2636
# File '../../src/modules/LanItems.rb', line 2636

publish_variable :wl_power, "boolean"

- (map <string, any>) wl_wpa_eap

Returns:

  • (map <string, any>)


2631
# File '../../src/modules/LanItems.rb', line 2631

publish_variable :wl_wpa_eap, "map <string, any>"

- (string) wl_wpa_psk

Returns:

  • (string)


2621
# File '../../src/modules/LanItems.rb', line 2621

publish_variable :wl_wpa_psk, "string"

Instance Method Details

- (Object) AddNew



772
773
774
775
776
777
778
# File '../../src/modules/LanItems.rb', line 772

def AddNew
  @current = @Items.to_h.size
  @Items[@current] = { "commited" => false }
  @operation = :add

  nil
end

- (Object) BuildBondIndex



1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
# File '../../src/modules/LanItems.rb', line 1284

def BuildBondIndex
  index = {}
  bond_devs = Convert.convert(
    Ops.get(NetworkInterfaces.FilterDevices("netcard"), "bond", {}),
    from: "map",
    to:   "map <string, map>"
  )

  Builtins.foreach(bond_devs) do |bond_master, _value|
    Builtins.foreach(GetBondSlaves(bond_master)) do |slave|
      index = Builtins.add(index, slave, bond_master)
    end
  end

  Builtins.y2debug("bond slaves index: %1", index)

  deep_copy(index)
end

- (Object) BuildLanOverview

FIXME: side effect: sets @type. No reason for that. It should only build item overview. Check and remove.



1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
# File '../../src/modules/LanItems.rb', line 1372

def BuildLanOverview
  overview = []
  links = []

  LanItems.Items.each_key do |key|
    rich = ""
    ip = _("Not configured")

    item_hwinfo = LanItems.Items[key]["hwinfo"] || {}
    descr = item_hwinfo["name"] || ""

    note = ""
    bullets = []
    ifcfg_name = LanItems.Items[key]["ifcfg"] || ""

    LanItems.type = NetworkInterfaces.GetType(ifcfg_name)
    if !ifcfg_name.empty?
      ifcfg_conf = GetDeviceMap(key)
      ifcfg_desc = ifcfg_conf["NAME"]
      descr = ifcfg_desc if !ifcfg_desc.nil? && !ifcfg_desc.empty?
      descr = CheckEmptyName(LanItems.type, descr)
      ip = DeviceProtocol(ifcfg_conf)
      status = DeviceStatus(
        LanItems.type,
        ifcfg_name,
        ifcfg_conf
      )

      bullets << _("Device Name: %s") % ifcfg_name
      bullets += startmode_overview(key)
      bullets += ip_overview(ip) if ifcfg_conf["STARTMODE"] != "managed"

      if LanItems.type == "wlan" &&
          ifcfg_conf["WIRELESS_AUTH_MODE"] == "open" &&
          IsEmpty(ifcfg_conf["WIRELESS_KEY_0"])

        # avoid colons
        ifcfg_name = ifcfg_name.tr(":", "/")
        href = "lan--wifi-encryption-" + ifcfg_name
        # interface summary: WiFi without encryption
        warning = HTML.Colorize(_("Warning: no encryption is used."), "red")
        # Hyperlink: Change the configuration of an interface
        status << " " << warning << " " << Hyperlink(href, _("Change."))
        links << href
      end

      if LanItems.type == "bond"
        bond_slaves_desc = format(
          "%s: %s",
          _("Bonding slaves"),
          GetBondSlaves(ifcfg_name).join(" ")
        )
        bullets << bond_slaves_desc
      end

      bond_index = BuildBondIndex()
      bond_master = Ops.get(
        bond_index,
        ifcfg_name,
        ""
      )

      if !bond_master.empty?
        note = format(_("enslaved in %s"), bond_master)
        bond_master_desc = format("%s: %s", _("Bonding master"), bond_master)
        bullets << bond_master_desc
      end

      if renamed?(key)
        note = format("%s -> %s", GetDeviceName(key), renamed_to(key))
      end

      overview << Summary.Device(descr, status)
    else
      descr = CheckEmptyName(LanItems.type, descr)
      overview << Summary.Device(descr, Summary.NotConfigured)
    end
    conn = ""
    conn = HTML.Bold(format("(%s)", _("Not connected"))) if !item_hwinfo["link"]
    conn = HTML.Bold(format("(%s)", _("No hwinfo"))) if item_hwinfo.empty?

    mac_dev = HTML.Bold("MAC : ") + item_hwinfo["mac"].to_s + "<br>"
    bus_id  = HTML.Bold("BusID : ") + item_hwinfo["busid"].to_s + "<br>"

    rich << " " << conn << "<br>" << mac_dev if IsNotEmpty(item_hwinfo["mac"])
    rich << bus_id if IsNotEmpty(item_hwinfo["busid"])
    # display it only if we need it, don't duplicate "ifcfg_name" above
    if IsNotEmpty(item_hwinfo["dev_name"]) && ifcfg_name.empty?
      dev_name = _("Device Name: %s") %  item_hwinfo["dev_name"]
      rich << HTML.Bold(dev_name) << "<br>"
    end
    rich = HTML.Bold(descr) + rich
    if IsEmpty(item_hwinfo["dev_name"]) && !item_hwinfo.empty? && !Arch.s390
      rich << "<p>"
      rich << _("Unable to configure the network card because the kernel device (eth0, wlan0) is not present. This is mostly caused by missing firmware (for wlan devices). See dmesg output for details.")
      rich << "</p>"
    elsif !ifcfg_name.empty?
      rich << HTML.List(bullets)
    else
      rich << "<p>"
      rich << _("The device is not configured. Press <b>Edit</b>\nto configure.\n")
      rich << "</p>"

      curr = @current
      @current = key
      if needFirmwareCurrentItem
        fw = GetFirmwareForCurrentItem()
        rich << format("%s : %s", _("Needed firmware"), !fw.empty? ? fw : _("unknown"))
      end
      @current = curr
    end
    LanItems.Items[key]["table_descr"] = {
      "rich_descr"  => rich,
      "table_descr" => [descr, ip, ifcfg_name, note]
    }
  end
  [Summary.DevicesList(overview), links]
end

- (Object) Commit

Commit pending operation

Returns:

  • true if success



1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
# File '../../src/modules/LanItems.rb', line 1929

def Commit
  if @operation != :add && @operation != :edit
    log.error("Unknown operation: #{@operation}")
    raise ArgumentError, "Unknown operation: #{@operation}"
  end

  newdev = {}

  # #104494 - always write IPADDR+NETMASK, even empty
  newdev["IPADDR"] = @ipaddr
  if !@prefix.empty?
    newdev["PREFIXLEN"] = @prefix
  else
    newdev["NETMASK"] = @netmask
  end
  # #50955 omit computable fields
  newdev["BROADCAST"] = ""
  newdev["NETWORK"] = ""

  newdev["REMOTE_IPADDR"] = @remoteip

  # set LLADDR to sysconfig only for device on layer2 and only these which needs it
  # do not write incorrect LLADDR.
  if @qeth_layer2 && s390_correct_lladdr(@qeth_macaddress)
    busid = Ops.get_string(@Items, [@current, "hwinfo", "busid"], "")
    # sysfs id has changed from css0...
    sysfs_id = "/devices/qeth/#{busid}"
    log.info("busid #{busid}")
    if s390_device_needs_persistent_mac(sysfs_id, @Hardware)
      newdev["LLADDR"] = @qeth_macaddress
    end
  end

  newdev["NAME"] = @description

  newdev = setup_basic_device_options(newdev)
  newdev = setup_dhclient_options(newdev)

  case @type
  when "bond"
    i = 0
    @bond_slaves.each do |slave|
      newdev["BONDING_SLAVE#{i}"] = slave
      i += 1
    end

    # assign nil to rest BONDING_SLAVEn to remove them
    while i < @MAX_BOND_SLAVE
      newdev["BONDING_SLAVE#{i}"] = nil
      i += 1
    end

    newdev["BONDING_MODULE_OPTS"] = @bond_option
    newdev["BONDING_MASTER"] = "yes"

  when "vlan"
    newdev["ETHERDEVICE"] = @vlan_etherdevice
    newdev["VLAN_ID"] = @vlan_id

  when "br"
    newdev["BRIDGE_PORTS"] = @bridge_ports
    newdev["BRIDGE"] = "yes"
    newdev["BRIDGE_STP"] = "off"
    newdev["BRIDGE_FORWARDDELAY"] = "0"

  when "wlan"
    newdev["WIRELESS_MODE"] = @wl_mode
    newdev["WIRELESS_ESSID"] = @wl_essid
    newdev["WIRELESS_NWID"] = @wl_nwid
    newdev["WIRELESS_AUTH_MODE"] = @wl_auth_mode
    newdev["WIRELESS_WPA_PSK"] = @wl_wpa_psk
    newdev["WIRELESS_KEY_LENGTH"] = @wl_key_length
    # obsoleted by WIRELESS_KEY_0
    newdev["WIRELESS_KEY"] = "" # TODO: delete the varlable
    newdev["WIRELESS_KEY_0"] = Ops.get(@wl_key, 0, "")
    newdev["WIRELESS_KEY_1"] = Ops.get(@wl_key, 1, "")
    newdev["WIRELESS_KEY_2"] = Ops.get(@wl_key, 2, "")
    newdev["WIRELESS_KEY_3"] = Ops.get(@wl_key, 3, "")
    Ops.set(
      newdev,
      "WIRELESS_DEFAULT_KEY",
      Builtins.tostring(@wl_default_key)
    )
    Ops.set(newdev, "WIRELESS_NICK", @wl_nick)
    Ops.set(newdev, "WIRELESS_AP_SCANMODE", @wl_ap_scanmode)

    if @wl_wpa_eap != {}
      Ops.set(
        newdev,
        "WIRELESS_EAP_MODE",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_MODE", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_WPA_IDENTITY",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_IDENTITY", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_WPA_PASSWORD",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_PASSWORD", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_WPA_ANONID",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_ANONID", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_CLIENT_CERT",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_CLIENT_CERT", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_CLIENT_KEY",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_CLIENT_KEY", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_CLIENT_KEY_PASSWORD",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_CLIENT_KEY_PASSWORD", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_CA_CERT",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_CA_CERT", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_EAP_AUTH",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_AUTH", "")
      )
      Ops.set(
        newdev,
        "WIRELESS_PEAP_VERSION",
        Ops.get_string(@wl_wpa_eap, "WPA_EAP_PEAP_VERSION", "")
      )
    end

    newdev["WIRELESS_CHANNEL"] = @wl_channel
    newdev["WIRELESS_FREQUENCY"] = @wl_frequency
    newdev["WIRELESS_BITRATE"] = @wl_bitrate
    newdev["WIRELESS_AP"] = @wl_accesspoint
    newdev["WIRELESS_POWER"] = @wl_power ? "yes" : "no"

  when "ib"
    newdev["IPOIB_MODE"] = @ipoib_mode

  end

  if DriverType(@type) == "ctc"
    if Ops.get(NetworkConfig.Config, "WAIT_FOR_INTERFACES").nil? ||
        Ops.less_than(
          Ops.get_integer(NetworkConfig.Config, "WAIT_FOR_INTERFACES", 0),
          40
        )
      Ops.set(NetworkConfig.Config, "WAIT_FOR_INTERFACES", 40)
    end
  end

  if ["tun", "tap"].include?(@type)
    newdev = {
      "BOOTPROTO"        => "static",
      "STARTMODE"        => "auto",
      "TUNNEL"           => @type,
      "TUNNEL_SET_OWNER" => @tunnel_set_owner,
      "TUNNEL_SET_GROUP" => @tunnel_set_group
    }
  end

  # L3: bnc#585458
  # FIXME: INTERFACETYPE confuses sysconfig, bnc#458412
  # Only test when newdev has enough info for GetTypeFromIfcfg to work.
  implied_type = NetworkInterfaces.GetTypeFromIfcfg(newdev)
  if !implied_type.nil? && implied_type != @type
    newdev["INTERFACETYPE"] = @type
  end

  NetworkInterfaces.Name = Ops.get_string(@Items, [@current, "ifcfg"], "")
  NetworkInterfaces.Current = deep_copy(newdev)

  # bnc#752464 - can leak wireless passwords
  # useful only for debugging. Writes huge struct mostly filled by defaults.
  Builtins.y2debug("%1", NetworkInterfaces.ConcealSecrets1(newdev))

  Ops.set(@Items, [@current, "ifcfg"], "") if !NetworkInterfaces.Commit

  # configure bridge ports
  if @bridge_ports
    @bridge_ports.split.each { |bp| configure_as_bridge_port(bp) }
  end

  @modified = true
  @operation = nil
  true
end

- (Object) createS390Device



2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
# File '../../src/modules/LanItems.rb', line 2430

def createS390Device
  Builtins.y2milestone("creating device s390 network device")
  result = true
  # command to create device
  command1 = ""
  # command to find created device
  command2 = ""
  case @type
  when "hsi", "qeth"
    @portnumber_param = if Ops.greater_than(Builtins.size(@qeth_portnumber), 0)
                          Builtins.sformat("-n %1", @qeth_portnumber)
                        else
                          ""
                        end
    @portname_param = if Ops.greater_than(Builtins.size(@qeth_portname), 0)
                        Builtins.sformat("-p %1", @qeth_portname)
                      else
                        ""
                      end
    @options_param = if Ops.greater_than(Builtins.size(@qeth_options), 0)
                       Builtins.sformat("-o %1", @qeth_options)
                     else
                       ""
                     end
    command1 = Builtins.sformat(
      "qeth_configure %1 %2 %3 %4 %5 1",
      @options_param,
      @qeth_layer2 ? "-l" : "",
      @portname_param,
      @portnumber_param,
      @qeth_chanids
    )
    command2 = Builtins.sformat(
      "ls /sys/devices/qeth/%1/net/|head -n1|tr -d '\n'",
      Ops.get(Builtins.splitstring(@qeth_chanids, " "), 0, "")
    )
  when "ctc"
    # chan_ids (read, write), protocol
    command1 = Builtins.sformat(
      "ctc_configure %1 1 %2",
      @qeth_chanids,
      @chan_mode
    )
    command2 = Builtins.sformat(
      "ls /sys/devices/ctcm/%1/net/|head -n1|tr -d '\n'",
      Ops.get(Builtins.splitstring(@qeth_chanids, " "), 0, "")
    )
  when "lcs"
    # chan_ids (read, write), protocol
    command1 = Builtins.sformat(
      "ctc_configure %1 1 %2",
      @qeth_chanids,
      @chan_mode
    )
    command2 = Builtins.sformat(
      "ls /sys/devices/lcs/%1/net/|head -n1|tr -d '\n'",
      Ops.get(Builtins.splitstring(@qeth_chanids, " "), 0, "")
    )
  when "iucv"
    # router
    command1 = Builtins.sformat("iucv_configure %1 1", @iucv_user)
    command2 = Builtins.sformat(
      "ls /sys/devices/%1/*/net/|head -n1|tr -d '\n'",
      @type
    )
  else
    Builtins.y2error("Unsupported type : %1", @type)
  end
  Builtins.y2milestone("execute %1", command1)
  output1 = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command1),
    from: "any",
    to:   "map <string, any>"
)
  if Ops.get_integer(output1, "exit", -1) == 0 &&
      Builtins.size(Ops.get_string(output1, "stderr", "")) == 0
    Builtins.y2milestone("Success : %1", output1)
  else
    Builtins.y2error("Problem occured : %1", output1)
    result = false
  end
  Builtins.y2milestone("output1 %1", output1)

  if result
    Builtins.y2milestone("command2 %1", command2)
    output2 = Convert.convert(
      SCR.Execute(path(".target.bash_output"), command2),
      from: "any",
      to:   "map <string, any>"
    )
    Builtins.y2milestone("output2 %1", output2)
    if Ops.get_integer(output2, "exit", -1) == 0 &&
        Builtins.size(Ops.get_string(output2, "stderr", "")) == 0
      Ops.set(
        @Items,
        [@current, "ifcfg"],
        Ops.get_string(output2, "stdout", "")
      )
      Ops.set(
        @Items,
        [@current, "hwinfo", "dev_name"],
        Ops.get_string(output2, "stdout", "")
      )
      Builtins.y2milestone(
        "Device %1 created",
        Ops.get_string(output2, "stdout", "")
      )
    else
      Builtins.y2error("Some problem occured : %1", output2)
      result = false
    end
  end

  result
end

- (Boolean) current_renamed?

Returns:

  • (Boolean)


622
623
624
# File '../../src/modules/LanItems.rb', line 622

def current_renamed?
  renamed?(@current)
end

- (Object) current_renamed_to



610
611
612
# File '../../src/modules/LanItems.rb', line 610

def current_renamed_to
  renamed_to(@current)
end

- (Object) current_udev_name

Returns name which is going to be used in the udev rule



353
354
355
356
357
358
359
# File '../../src/modules/LanItems.rb', line 353

def current_udev_name
  if LanItems.current_renamed?
    LanItems.current_renamed_to
  else
    LanItems.GetItemUdev("NAME")
  end
end

- (Object) delete_dev(name)

Deletes item and its configuration

Item for deletion is searched using device name



2306
2307
2308
2309
# File '../../src/modules/LanItems.rb', line 2306

def delete_dev(name)
  FindAndSelect(name)
  DeleteItem()
end

- (Object) DeleteItem

Deletes the #current item and its configuration



2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
# File '../../src/modules/LanItems.rb', line 2312

def DeleteItem
  return if @current < 0
  return if @Items.nil? || @Items.empty?

  log.info("DeleteItem: #{@Items[@current]}")

  devmap = GetCurrentMap()
  drop_hosts(devmap["IPADDR"]) if devmap
  SetCurrentName("")

  current_item = @Items[@current]

  if current_item["hwinfo"].nil? || current_item["hwinfo"].empty?
    # size is always > 0 here and items are numbered 0, 1, ..., size -1
    delete_index = @Items.size - 1

    @Items[@current] = @Items[delete_index] if delete_index != @current
    @Items.delete(delete_index)

    # item was deleted, so original @current is invalid
    @current = -1
  end

  SetModified()

  nil
end

- (Object) enableCurrentEditButton



2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
# File '../../src/modules/LanItems.rb', line 2416

def enableCurrentEditButton
  return true if needFirmwareCurrentItem
  return true if Arch.s390
  if IsEmpty(Ops.get_string(getCurrentItem, ["hwinfo", "dev_name"], "")) &&
      Ops.greater_than(
        Builtins.size(Ops.get_map(getCurrentItem, "hwinfo", {})),
        0
      )
    return false
  else
    return true
  end
end

- (Object) find_configured(device)



972
973
974
# File '../../src/modules/LanItems.rb', line 972

def find_configured(device)
  @Items.select { |_k, v| v["ifcfg"] == device }.keys.first
end

- (Object) FindAndSelect(device)



976
977
978
979
980
981
# File '../../src/modules/LanItems.rb', line 976

def FindAndSelect(device)
  item_id = find_configured(device)
  @current = item_id if item_id

  !item_id.nil?
end

- (Object) FindDeviceIndex(device)

search all known devices to find it's index in Items array

Parameters:

  • device (String)

    matched with item[ “hwinfo”, “dev_name”]

Returns:

  • index in Items or -1 if not found



987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
# File '../../src/modules/LanItems.rb', line 987

def FindDeviceIndex(device)
  ret = -1

  Builtins.foreach(
    Convert.convert(
      @Items,
      from: "map <integer, any>",
      to:   "map <integer, map <string, any>>"
    )
  ) do |i, a|
    if Ops.get_string(a, ["hwinfo", "dev_name"], "") == device
      ret = i
      raise Break
    end
  end

  ret
end

- (Hash) FindMatchingDevice(interface)

Find matching device Find a device, optionally with some predefined values

Parameters:

  • interface (Hash)

    interface map

Returns:

  • (Hash)

    The map of the matching device.



2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
# File '../../src/modules/LanItems.rb', line 2175

def FindMatchingDevice(interface)
  interface = deep_copy(interface)
  tosel = nil
  # Minimal changes to code to fix both #119592 and #146965
  # Alternatively we could try to ensure that we never match a
  # device that got already matched
  matched_by_module = false

  devs = NetworkInterfaces.List("netcard")
  Builtins.y2milestone("Configured devices: %1", devs)

  # this condition is always true for SLES9, HEAD uses $[] for proposal
  if interface != {}
    # Notes for comments about matching:
    # - interface["device"] is the key which we look for in the actual hw
    # - H iterates over Hardware
    # - patterns are shell-like

    device_id = Builtins.splitstring(
      Ops.get_string(interface, "device", ""),
      "-"
    )
    # code for eth-id-00:80:c8:f6:48:4c configurations
    # *-id-$ID => find H["mac"] == $ID
    if Ops.greater_than(Builtins.size(device_id), 1) &&
        Ops.get_string(device_id, 1, "") == "id"
      hwaddr = Ops.get_string(device_id, 2, "")
      tosel = Builtins.find(@Hardware) do |h|
        Ops.get_string(h, "mac", "") == hwaddr
      end if !hwaddr.nil? &&
          hwaddr != ""
      Builtins.y2milestone("Rule: matching mac in device name")
    # code for eth-bus-pci-0000:00:0d.0 configurations
    # code for eth-bus-vio-30000001 configurations
    # *-bus-$BUS-$ID => find H["bus"] == $BUS & H["busid"] == $ID
    elsif Ops.greater_than(Builtins.size(device_id), 2) &&
        Ops.get_string(device_id, 1, "") == "bus"
      bus = Ops.get_string(device_id, 2, "")
      busid = Ops.get_string(device_id, 3, "")
      if !bus.nil? && bus != "" && !busid.nil? && busid != ""
        tosel = Builtins.find(@Hardware) do |h|
          Ops.get_string(h, "busid", "") == busid &&
            Ops.get_string(h, "bus", "") == bus
        end
      end
      Builtins.y2milestone("Rule: matching bus id in device name")
    end

    # code for module configuration
    # join with the modules list of the ay profile according to "device"
    # if exists => find H["module"] == AH["module"]
    aymodule = GetModuleForInterface(
      Ops.get_string(interface, "device", ""),
      Ops.get_list(@autoinstall_settings, "modules", [])
    )
    Builtins.y2milestone("module data: %1", aymodule)
    if tosel.nil? && aymodule != {}
      if !aymodule.nil? && Ops.get_string(aymodule, "module", "") != ""
        tosel = Builtins.find(@Hardware) do |h|
          Ops.get_string(h, "module", "") ==
            Ops.get_string(aymodule, "module", "")
        end
      end
      matched_by_module = true if !tosel.nil?
      Builtins.y2milestone("Rule: matching module configuration")
    end
  end

  # First device was already configured, we are now looking for
  # a second (third,...) one
  if Ops.greater_than(Builtins.size(devs), 0)
    # #119592, #146965: this used to be unconditional, overwriting the
    # results of the above matching.
    if matched_by_module || tosel.nil?
      # go thru all devices, check whether there's one that does
      # not have a configuration yet
      # and has the same type as the current profile item
      Builtins.foreach(@Hardware) do |h|
        Builtins.y2milestone("Checking for device=%1", h)
        SelectHWMap(h)
        #		string _device_name = NetworkInterfaces::device_name(NetworkInterfaces::RealType(type, hotplug), device);
        if !NetworkInterfaces.Check(@device) &&
            @type ==
                NetworkInterfaces.GetType(
                  Ops.get_string(interface, "device", "")
                )
          Builtins.y2milestone("Selected: %1", h)
          tosel = deep_copy(h)
          raise Break
        end
      end
    end
    Builtins.y2error("Nothing found") if tosel.nil?
  else
    # this is the first interface, match the hardware with install.inf
    # No install.inf -> select the first connected
    # find H["active"] == true
    if tosel.nil?
      tosel = Builtins.find(@Hardware) do |h|
        Ops.get_boolean(h, ["link", "state"], false)
      end
      Builtins.y2milestone("Rule: first connected")
    end

    # No install.inf driver -> select the first active
    # find H["active"] == true
    if tosel.nil?
      tosel = Builtins.find(@Hardware) do |h|
        Ops.get_boolean(h, "active", false)
      end
      Builtins.y2milestone("Rule: first active")
    end

    # No active driver -> select the first with a driver
    # find H["module"] != ""
    if tosel.nil?
      Builtins.y2milestone("No active driver found, trying further.")
      tosel = Builtins.find(@Hardware) do |h|
        Ops.get_string(h, "module", "") != "" &&
          Builtins.y2milestone("Using driver: %1", h).nil?
      end
      Builtins.y2milestone("Rule: first with driver")
    end
  end

  deep_copy(tosel)
end

- (Array) FreeAliases(_type, _num)

Return 10 free aliases

Parameters:

  • type (String)

    device type

  • num (Fixnum)

    device number

Returns:

  • (Array)

    of 10 free devices



1654
1655
1656
# File '../../src/modules/LanItems.rb', line 1654

def FreeAliases(_type, _num)
  NetworkInterfaces.GetFreeDevices("_aliases", 10)
end

- (Array) FreeDevices(type)

Return 10 free devices

Parameters:

  • type (String)

    device type

Returns:

  • (Array)

    of 10 free devices



1646
1647
1648
# File '../../src/modules/LanItems.rb', line 1646

def FreeDevices(type)
  NetworkInterfaces.GetFreeDevices(type, 10)
end

- (Object) GetBondableInterfaces(bondMaster)

Creates list of items (interfaces) which can be used as a bond slave.

Parameters:

  • bondMaster (String)

    bond device name



930
931
932
933
934
935
# File '../../src/modules/LanItems.rb', line 930

def GetBondableInterfaces(bondMaster)
  GetSlaveCandidates(
    bondMaster,
    fun_ref(method(:IsBondable), "boolean (string, integer)")
  )
end

- (Object) GetBondSlaves(bond_master)

Creates list of devices enslaved in any bond device.



1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
# File '../../src/modules/LanItems.rb', line 1259

def GetBondSlaves(bond_master)
  slaves = []
  slave_index = 0

  while Ops.less_than(slave_index, @MAX_BOND_SLAVE)
    slave = Ops.get_string(
      NetworkInterfaces.FilterDevices("netcard"),
      [
        "bond",
        bond_master,
        Builtins.sformat("BONDING_SLAVE%1", slave_index)
      ],
      ""
    )

    if Ops.greater_than(Builtins.size(slave), 0)
      slaves = Builtins.add(slaves, slave)
    end

    slave_index = Ops.add(slave_index, 1)
  end

  deep_copy(slaves)
end

- (Object) GetBridgeableInterfaces(bridgeMaster)

Creates list of items (interfaces) which can be used as a bridge slave.

Parameters:

  • bridgeMaster (String)

    bridge device name



941
942
943
944
945
946
# File '../../src/modules/LanItems.rb', line 941

def GetBridgeableInterfaces(bridgeMaster)
  GetSlaveCandidates(
    bridgeMaster,
    fun_ref(method(:IsBridgeable), "boolean (string, integer)")
  )
end

- (Object) getCurrentItem

Returns configuration for currently modified item.



315
316
317
# File '../../src/modules/LanItems.rb', line 315

def getCurrentItem
  GetLanItem(@current)
end

- (Object) GetCurrentMap



403
404
405
# File '../../src/modules/LanItems.rb', line 403

def GetCurrentMap
  GetDeviceMap(@current)
end

- (Object) GetCurrentName

Returns device name for current lan item (see LanItems::current)



371
372
373
# File '../../src/modules/LanItems.rb', line 371

def GetCurrentName
  GetDeviceName(@current)
end

- (Object) GetCurrentType

Returns device type for current lan item (see LanItems::current)



383
384
385
# File '../../src/modules/LanItems.rb', line 383

def GetCurrentType
  GetDeviceType(@current)
end

- (Object) GetDefaultsForHW

must be in sync with #SetDefaultsForHW



1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
# File '../../src/modules/LanItems.rb', line 1659

def GetDefaultsForHW
  ret = {}
  # LCS eth interfaces on s390 need the MTU of 1492. #81815.
  # TODO: lcs, or eth?
  # will eth not get mapped to lcs?
  # Apparently both LCS eth and LCS tr are represented as "lcs"
  # but it does not hurt to change the default also for tr
  # #93798: limit to s390 to minimize regressions. Probably it could
  # be also done by only testing for lcs and not eth but that
  # would need more testing.
  if Arch.s390 && Builtins.contains(["lcs", "eth"], @type)
    Builtins.y2milestone("Adding LCS: setting MTU")
    ret = Builtins.add(ret, "MTU", "1492")
  end
  deep_copy(ret)
end

- (Object) GetDescr



1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
# File '../../src/modules/LanItems.rb', line 1160

def GetDescr
  descr = []
  Builtins.foreach(
    Convert.convert(
      @Items,
      from: "map <integer, any>",
      to:   "map <integer, map <string, any>>"
    )
  ) do |key, value|
    if Builtins.haskey(value, "table_descr") &&
        Ops.greater_than(
          Builtins.size(Ops.get_map(@Items, [key, "table_descr"], {})),
          1
        )
      descr = Builtins.add(
        descr,
        "id"          => key,
        "rich_descr"  => Ops.get_string(
          @Items,
          [key, "table_descr", "rich_descr"],
          ""
),
        "table_descr" => Ops.get_list(
          @Items,
          [key, "table_descr", "table_descr"],
          []
)
      )
    end
  end
  deep_copy(descr)
end

- (Object) GetDeviceMap(itemId)

Returns ifcfg configuration for particular item

Parameters:

  • itemId (Integer)

    a key for #Items



390
391
392
393
394
395
396
397
398
399
400
401
# File '../../src/modules/LanItems.rb', line 390

def GetDeviceMap(itemId)
  return nil if !IsItemConfigured(itemId)

  devname = GetDeviceName(itemId)
  devtype = NetworkInterfaces.GetType(devname)

  Convert.convert(
    Ops.get(NetworkInterfaces.FilterDevices("netcard"), [devtype, devname]),
    from: "any",
    to:   "map <string, any>"
  )
end

- (Object) GetDeviceName(item_id)

Returns device name for given lan item.

First it looks into the item's netconfig and if it doesn't exist it uses device name from hwinfo if available.

Parameters:

  • item_id (Integer)

    a key for #Items



342
343
344
345
346
347
348
349
350
# File '../../src/modules/LanItems.rb', line 342

def GetDeviceName(item_id)
  lan_item = GetLanItem(item_id)

  return lan_item["ifcfg"] if lan_item["ifcfg"]
  return lan_item["hwinfo"]["dev_name"] || "" if lan_item["hwinfo"]

  log.error("Item #{item_id} has no dev_name nor configuration associated")
  "" # this should never happen
end

- (Object) GetDeviceNames(items)

transforms given list of item ids onto device names

item id is index into internal @Items structure



364
365
366
367
368
# File '../../src/modules/LanItems.rb', line 364

def GetDeviceNames(items)
  return [] unless items

  items.map { |itemId| GetDeviceName(itemId) }.reject(&:empty?)
end

- (Object) GetDeviceType(itemId)

Returns device type for particular lan item

Parameters:

  • itemId (Integer)

    a key for #Items



378
379
380
# File '../../src/modules/LanItems.rb', line 378

def GetDeviceType(itemId)
  NetworkInterfaces.GetType(GetDeviceName(itemId))
end

- (Object) GetFirmwareForCurrentItem



1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File '../../src/modules/LanItems.rb', line 1222

def GetFirmwareForCurrentItem
  kernel_module = ""
  if IsNotEmpty(Ops.get_string(@Items, [@current, "hwinfo", "driver"], ""))
    if Builtins.haskey(
      @request_firmware,
      Ops.get_string(@Items, [@current, "hwinfo", "driver"], "")
      )
      kernel_module = Ops.get_string(
        @Items,
        [@current, "hwinfo", "driver"],
        ""
      )
    end
  else
    Builtins.foreach(
      Ops.get_list(@Items, [@current, "hwinfo", "drivers"], [])
    ) do |driver|
      if Builtins.haskey(
        @request_firmware,
        Ops.get_string(driver, ["modules", 0, 0], "")
        )
        kernel_module = Ops.get_string(driver, ["modules", 0, 0], "")
        raise Break
      end
    end
  end
  firmware = Ops.get(@request_firmware, kernel_module, "")
  Builtins.y2milestone(
    "driver %1 needs firmware %2",
    kernel_module,
    firmware
  )

  firmware
end

- (Object) GetItemDescription



1515
1516
1517
# File '../../src/modules/LanItems.rb', line 1515

def GetItemDescription
  Ops.get_string(@Items, [@current, "table_descr", "rich_descr"], "")
end

- (Object) GetItemModules(default_module)

return list of available modules for current device with default default_module (on first possition)



783
784
785
786
787
788
789
790
791
792
793
# File '../../src/modules/LanItems.rb', line 783

def GetItemModules(default_module)
  mods = []
  mods = Builtins.add(mods, default_module) if IsNotEmpty(default_module)
  Builtins.foreach(
    Ops.get_list(@Items, [@current, "hwinfo", "drivers"], [])
  ) do |row|
    tmp_mod = Ops.get_string(row, ["modules", 0, 0], "")
    mods = Builtins.add(mods, tmp_mod) if !Builtins.contains(mods, tmp_mod)
  end
  deep_copy(mods)
end

- (Object) GetItemUdev(key)



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File '../../src/modules/LanItems.rb', line 499

def GetItemUdev(key)
  value = ""

  Builtins.foreach(getUdevFallback) do |row|
    if Builtins.issubstring(row, key)
      items = Builtins.filter(Builtins.splitstring(row, "=")) do |s|
        Ops.greater_than(Builtins.size(s), 0)
      end
      if Builtins.size(items) == 2 && Ops.get_string(items, 0, "") == key
        value = Builtins.deletechars(Ops.get_string(items, 1, ""), "\"")
      else
        Builtins.y2warning(
          "udev items %1 doesn't match the key %2",
          items,
          key
        )
      end
    end
  end
  value
end

- (Object) GetItemUdevRule(itemId)

Returns udev rule known for particular item

Parameters:

  • itemId (Integer)

    a key for #Items



436
437
438
# File '../../src/modules/LanItems.rb', line 436

def GetItemUdevRule(itemId)
  Ops.get_list(GetLanItem(itemId), ["udev", "net"], [])
end

- (Object) GetLanItem(itemId)

Returns configuration of item (see LanItems::Items) with given id.

Parameters:

  • itemId (Integer)

    a key for #Items



310
311
312
# File '../../src/modules/LanItems.rb', line 310

def GetLanItem(itemId)
  Ops.get_map(@Items, itemId, {})
end

- (Boolean) GetModified

Function which returns if the settings were modified

Returns:

  • (Boolean)

    settings were modified



761
762
763
# File '../../src/modules/LanItems.rb', line 761

def GetModified
  @modified
end

- (Hash) GetModuleForInterface(ay_device, ay_modules)

Get the module configuration for the modules configured in the interface section

Parameters:

  • ay_device (String)

    Device, for example eth0

  • ay_modules (Array<Hash>)

    list of modules from the AY profile

Returns:

  • (Hash)

    the module map with module name and options



2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
# File '../../src/modules/LanItems.rb', line 2157

def GetModuleForInterface(ay_device, ay_modules)
  ay_modules = deep_copy(ay_modules)
  ayret = {}
  ay_filtered = Builtins.filter(ay_modules) do |ay_m|
    Ops.get_string(ay_m, "device", "") == ay_device
  end

  if Ops.greater_than(Builtins.size(ay_filtered), 0)
    ayret = Ops.get(ay_filtered, 0, {})
  end

  deep_copy(ayret)
end

- (Object) GetNetcardInterfaces

Creates list of all known netcard items

It means list of item ids of all netcards which are detected and/or configured in the system



952
953
954
# File '../../src/modules/LanItems.rb', line 952

def GetNetcardInterfaces
  @Items.keys
end

- (Object) GetNetcardNames

Creates list of names of all known netcards configured even unconfigured



957
958
959
# File '../../src/modules/LanItems.rb', line 957

def GetNetcardNames
  GetDeviceNames(GetNetcardInterfaces())
end

- (Object) getNetworkInterfaces

get list of all configurations for “netcard” macro in NetworkInterfaces module



962
963
964
965
966
967
968
969
970
# File '../../src/modules/LanItems.rb', line 962

def getNetworkInterfaces
  configurations = NetworkInterfaces.FilterDevices("netcard")
  devtypes = NetworkInterfaces.CardRegex["netcard"].to_s.split("|")

  devtypes.inject([]) do |acc, type|
    conf = configurations[type].to_h
    acc.concat(conf.keys)
  end
end

- (Array) GetSlaveCandidates(master, validator)

Iterates over all items and lists those for which given validator returns true.

Parameters:

  • validator (boolean (string, integer))

    a reference to function which checks if an interface can be enslaved. Validator takes one argument - itemId.

Returns:

  • (Array)

    of lan item ids (see LanItems::Items)



893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File '../../src/modules/LanItems.rb', line 893

def GetSlaveCandidates(master, validator)
  validator = deep_copy(validator)
  if validator.nil?
    Builtins.y2error("GetSlaveCandidates: needs a validator.")
    return []
  end
  if IsEmpty(master)
    Builtins.y2error("GetSlaveCandidates: master device name is required.")
    return []
  end

  result = []

  Builtins.foreach(@Items) do |itemId, _attribs|
    if @current != itemId && validator.call(master, itemId)
      result = Builtins.add(result, itemId)
    else
      Builtins.y2debug(
        "GetSlaveCandidates: validation failed for item (%1), current (%2)",
        itemId,
        @current
      )
    end
  end

  Builtins.y2milestone(
    "GetSlaveCandidates: candidates for enslaving: %1",
    result
  )

  deep_copy(result)
end

- (Object) getUdevFallback



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File '../../src/modules/LanItems.rb', line 482

def getUdevFallback
  udev_rules = Ops.get_list(getCurrentItem, ["udev", "net"], [])

  if IsEmpty(udev_rules)
    udev_rules = GetDefaultUdevRule(
      GetCurrentName(),
      Ops.get_string(getCurrentItem, ["hwinfo", "mac"], "")
    )
    Builtins.y2milestone(
      "No Udev rules found, creating default: %1",
      udev_rules
    )
  end

  deep_copy(udev_rules)
end

- (Boolean) hotplug_usable?

Returns:

  • (Boolean)


1809
1810
1811
# File '../../src/modules/LanItems.rb', line 1809

def hotplug_usable?
  true unless Ops.get_string(@Items, [@current, "hwinfo", "hotplug"], "").empty?
end

- (Boolean) Import(settings)

Imports data from AY profile

As network related configuration is spread over the whole AY profile's networking section the function requires hash map with whole AY profile hash representation as returned by LanAutoClient#FromAY profile.

Parameters:

  • AY (Hash)

    profile converted into hash

Returns:

  • (Boolean)

    on success



1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
# File '../../src/modules/LanItems.rb', line 1141

def Import(settings)
  reset_cache

  NetworkInterfaces.Import("netcard", settings["devices"] || {})
  NetworkInterfaces.List("netcard").each do |device|
    AddNew()
    LanItems.Items[current] = { "ifcfg" => device }
  end

  autoinstall_settings["start_immediately"] = settings.fetch("start_immediately", false)
  autoinstall_settings["strict_IP_check_timeout"] = settings.fetch("strict_IP_check_timeout", -1)
  autoinstall_settings["keep_install_network"] = settings.fetch("keep_install_network", false)

  # settings == {} has special meaning 'Reset' used by AY
  SetModified() if !settings.empty?

  true
end

- (Object) InitS390VarsByDefaults



1803
1804
1805
1806
1807
# File '../../src/modules/LanItems.rb', line 1803

def InitS390VarsByDefaults
  SetS390Vars({}, @s390_defaults)

  nil
end

- (Object) ip_overview(ip)



1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
# File '../../src/modules/LanItems.rb', line 1340

def ip_overview(ip)
  bullets = []

  case ip
  when "NONE", ""
  # do nothing
  when /DHCP/
    bullets << format("%s %s", _("IP address assigned using"), ip)
  else
    prefixlen = NetworkInterfaces.Current["PREFIXLEN"]
    if prefixlen
      bullets << format(_("IP address: %s/%s"), ip, prefixlen)
    else
      subnetmask = NetworkInterfaces.Current["NETMASK"]
      bullets << format(_("IP address: %s, subnet mask %s"), ip, subnetmask)
    end
  end

  # build aliases overview
  item_aliases = NetworkInterfaces.Current["_aliases"] || {}
  if !item_aliases.empty? && !NetworkService.is_network_manager
    item_aliases.each do |_key2, desc|
      parameters = format("%s/%s", desc["IPADDR"], desc["PREFIXLEN"])
      bullets << format("%s (%s)", desc["LABEL"], parameters)
    end
  end

  bullets
end

- (Object) IsBondable(bondMaster, itemId)

Searches map of known devices and decides if referenced lan item can be enslaved in a bond device

TODO: Check for valid configurations. E.g. bond device over vlan is nonsense and is not supported by netconfig. Also devices enslaved in a bridge should be excluded too.

Parameters:

  • bondMaster (String)

    name of master device

  • itemId (Fixnum)

    index into LanItems::Items



803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File '../../src/modules/LanItems.rb', line 803

def IsBondable(bondMaster, itemId)
  ret = true
  devname = GetDeviceName(itemId)
  bonded = BuildBondIndex()

  # check if the device is L2 capable
  if Arch.s390
    s390_config = s390_ReadQethConfig(devname)

    # only devices with L2 support can be enslaved in bond. See bnc#719881
    ret &&= Ops.get_string(s390_config, "QETH_LAYER2", "no") == "yes"
  end

  ifcfg = GetDeviceMap(itemId)

  itemBondMaster = Ops.get(bonded, devname, "")

  if IsNotEmpty(itemBondMaster) && bondMaster != itemBondMaster
    Builtins.y2debug(
      "IsBondable: excluding lan item (%1: %2) for %3 - is already bonded",
      itemId,
      devname,
      GetDeviceName(@current)
    )
    return false
  end

  return ret if ifcfg.nil?

  # filter the eth devices (BOOTPROTO=none)
  # don't care about STARTMODE (see bnc#652987c6)
  ret &&= Ops.get_string(ifcfg, "BOOTPROTO", "") == "none"

  ret
end

- (Object) IsBridgeable(_bridgeMaster, itemId)

Decides if given lan item can be enslaved in a bridge.

TODO: bridgeMaster is not used yet bcs detection of bridge master for checked device is missing.

Parameters:

  • bridgeMaster (String)

    name of master device

  • itemId (Fixnum)

    index into LanItems::Items



845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
# File '../../src/modules/LanItems.rb', line 845

def IsBridgeable(_bridgeMaster, itemId)
  ifcfg = GetDeviceMap(itemId)

  # no netconfig configuration has been found so nothing
  # blocks using the device as bridge slave
  return true if ifcfg.nil?

  devname = GetDeviceName(itemId)
  bonded = BuildBondIndex()

  if bonded[devname]
    log.debug("Excluding lan item (#{itemId}: #{devname}) - is bonded")
    return false
  end

  devtype = GetDeviceType(itemId)

  # exclude forbidden configurations
  case devtype
  when "br"
    log.debug("Excluding lan item (#{itemId}: #{devname}) - is bridge")
    return false

  when "tun"
    log.debug("Excluding lan item (#{itemId}: #{devname}) - is tun")
    return false
  end

  case ifcfg["STARTMODE"]
  when "nfsroot"
    log.debug("Excluding lan item (#{itemId}: #{devname}) - is nfsroot")
    return false

  when "ifplugd"
    log.debug("Excluding lan item (#{itemId}: #{devname}) - ifplugd")
    return false

  else
    return true
  end
end

- (Object) IsCurrentConfigured

Returns true if current (see LanItems::current) has configuration



332
333
334
# File '../../src/modules/LanItems.rb', line 332

def IsCurrentConfigured
  IsItemConfigured(@current)
end

- (Object) isCurrentDHCP

Check if currently edited device gets its IP address from DHCP (v4, v6 or both)

Returns:

  • true if it is



1511
1512
1513
# File '../../src/modules/LanItems.rb', line 1511

def isCurrentDHCP
  Builtins.regexpmatch(@bootproto, "dhcp[46]?")
end

- (Object) isCurrentHotplug

Is current device hotplug or not? I.e. is connected via usb/pcmci?



1499
1500
1501
1502
1503
1504
1505
1506
# File '../../src/modules/LanItems.rb', line 1499

def isCurrentHotplug
  hotplugtype = Ops.get_string(getCurrentItem, ["hwinfo", "hotplug"], "")
  if hotplugtype == "usb" || hotplugtype == "pcmci"
    return true
  else
    return false
  end
end

- (Object) IsItemConfigured(itemId)

Returns true if the item (see LanItems::Items) has netconfig configuration.

Parameters:

  • itemId (Integer)

    a key for #Items



323
324
325
326
327
328
# File '../../src/modules/LanItems.rb', line 323

def IsItemConfigured(itemId)
  ret = !GetLanItem(itemId)["ifcfg"].to_s.empty?
  log.info("IsItemConfigured: item=#{itemId} configured=#{ret}")

  ret
end

- (Object) main



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File '../../src/modules/LanItems.rb', line 49

def main
  Yast.import "UI"
  textdomain "network"

  Yast.import "NetworkInterfaces"
  Yast.import "ProductFeatures"
  Yast.import "NetworkConfig"
  Yast.import "NetworkStorage"
  Yast.import "Host"
  Yast.import "Storage"
  Yast.import "Stage"
  Yast.include self, "network/complex.rb"
  Yast.include self, "network/routines.rb"
  Yast.include self, "network/lan/s390.rb"
  Yast.include self, "network/lan/udev.rb"
  Yast.include self, "network/lan/bridge.rb"

  reset_cache

  # Hardware information
  # @see #ReadHardware
  @Hardware = []
  @udev_net_rules = {}
  @driver_options = {}

  # used at autoinstallation time
  @autoinstall_settings = {}

  # Data was modified?
  # current selected HW
  @hw = {}

  # Which operation is pending?
  @operation = nil

  # in special cases when rcnetwork reload is not enought
  @force_restart = false

  @description = ""

  @type = ""
  # ifcfg name for the @current device
  @device = ""
  # FIXME: always empty string - remove all occuriences
  @alias = ""
  @current = -1
  @hotplug = ""

  @Requires = []

  # address options
  # boot protocol: BOOTPROTO
  @bootproto = "static"
  @ipaddr = ""
  @remoteip = ""
  @netmask = ""
  @prefix = ""

  @startmode = "auto"
  @ifplugd_priority = "0"
  @mtu = ""
  @ethtool_options = ""

  # wireless options
  @wl_mode = ""
  @wl_essid = ""
  @wl_nwid = ""
  @wl_auth_mode = ""
  # when adding another key, don't forget the chmod 600 in NetworkInterfaces
  @wl_wpa_psk = ""
  @wl_key_length = ""
  @wl_key = []
  @wl_default_key = 0
  @wl_nick = ""

  # bond options
  @bond_slaves = []
  @bond_option = ""

  @MAX_BOND_SLAVE = 10

  # VLAN option
  @vlan_etherdevice = ""
  @vlan_id = ""

  # interfaces attached to bridge (list delimited by ' ')
  @bridge_ports = ""
  # wl_wpa_eap aggregates the settings in a map for easier CWM access.
  #
  # **Structure:**
  #
  #     wpa_eap
  #      WPA_EAP_MODE: string ("TTLS" "PEAP" or "TLS")
  #      WPA_EAP_IDENTITY: string
  #      WPA_EAP_PASSWORD: string (for TTLS and PEAP)
  #      WPA_EAP_ANONID: string (for TTLS and PEAP)
  #      WPA_EAP_CLIENT_CERT: string (for TLS, file name)
  #      WPA_EAP_CLIENT_KEY: string (for TLS, file name)
  #      WPA_EAP_CLIENT_KEY_PASSWORD: string (for TLS)
  #      WPA_EAP_CA_CERT: string (file name)
  #      WPA_EAP_AUTH: string ("", "MD5", "GTC", "CHAP"*, "PAP"*, "MSCHAP"*, "MSCHAPV2") (*: TTLS only)
  #      WPA_EAP_PEAP_VERSION: string ("", "0", "1")
  @wl_wpa_eap = {}
  @wl_channel = ""
  @wl_frequency = ""
  @wl_bitrate = ""
  @wl_accesspoint = ""
  @wl_power = true
  @wl_ap_scanmode = ""

  # Card Features from hwinfo
  # if not provided, we use the default full list
  @wl_auth_modes = nil
  @wl_enc_modes = nil
  @wl_channels = nil
  @wl_bitrates = nil
  @nilliststring = nil # to save some casting

  # s390 options
  @qeth_portname = ""
  @qeth_portnumber = ""
  # * ctc as PROTOCOL (or ctc mode, number in { 0, 1, .., 4 }, default: 0)
  @chan_mode = "0"
  @qeth_options = ""
  @ipa_takeover = false
  # * iucv as ROUTER (or iucv user, a zVM guest, string of 1 to 8 chars )
  @iucv_user = ""
  # #84148
  # 26bdd00.pdf
  # Ch 7: qeth device driver for OSA-Express (QDIO) and HiperSockets
  # MAC address handling for IPv4 with the layer2 option
  @qeth_layer2 = false
  @qeth_macaddress = "00:00:00:00:00:00"
  @qeth_chanids = ""
  # Timeout for LCS LANCMD
  @lcs_timeout = "5"

  # aliases
  @aliases = {}

  # for TUN / TAP devices
  @tunnel_set_owner = ""
  @tunnel_set_group = ""

  # infiniband options
  @ipoib_mode = ""
  @ipoib_modes = {
    # translators: a possible value for: IPoIB device mode
    "connected" => _("connected"),
    "datagram"  => _("datagram")
  }

  # propose options
  @proposal_valid = false
  @nm_proposal_valid = false

  # NetworkModules:: name
  @nm_name = ""

  # this is the map of kernel modules vs. requested firmware
  # non-empty keys are firmware packages shipped by SUSE
  @request_firmware = {
    "atmel_pci"      => "atmel-firmware",
    "atmel_cs"       => "atmel-firmware",
    "at76_usb"       => "atmel-firmware",
    "ipw2100"        => "ipw-firmware",
    "ipw2200"        => "ipw-firmware",
    "ipw3945"        => "ipw-firmware",
    "iwl1000"        => "kernel-firmware",
    "iwl3945"        => "kernel-firmware",
    "iwl4965"        => "kernel-firmware",
    "iwl5000"        => "kernel-firmware",
    "iwl5150"        => "kernel-firmware",
    "iwl6000"        => "kernel-firmware",
    "b43"            => "b43-fwcutter",
    "b43-pci-bridge" => "b43-fwcutter",
    "bcm43xx"        => "",
    "prism54"        => "",
    "spectrum_cs"    => "",
    "zd1201"         => "",
    "zd1211rw"       => "",
    "acx"            => "",
    "rt73usb"        => "",
    "prism54usb"     => ""
  }

  Yast.include self, "network/hardware.rb"

  # the defaults here are what sysconfig defaults to
  # (as opposed to what a new interface gets, in {#Select)}
  @SysconfigDefaults = {
    "BOOTPROTO"                    => "static",
    "IPADDR"                       => "",
    "PREFIXLEN"                    => "",
    "REMOTE_IPADDR"                => "",
    "NETMASK"                      => "",
    "MTU"                          => "",
    "ETHTOOL_OPTIONS"              => "",
    "NAME"                         => "",
    "STARTMODE"                    => "manual",
    "IFPLUGD_PRIORITY"             => "0",
    "WIRELESS_MODE"                => "Managed",
    "WIRELESS_ESSID"               => "",
    "WIRELESS_NWID"                => "",
    "WIRELESS_AUTH_MODE"           => "open",
    "WIRELESS_WPA_PSK"             => "",
    "WIRELESS_KEY_LENGTH"          => "128",
    "WIRELESS_KEY"                 => "",
    "WIRELESS_KEY_0"               => "",
    "WIRELESS_KEY_1"               => "",
    "WIRELESS_KEY_2"               => "",
    "WIRELESS_KEY_3"               => "",
    "WIRELESS_DEFAULT_KEY"         => "0",
    "WIRELESS_NICK"                => "",
    "WIRELESS_CHANNEL"             => "",
    "WIRELESS_FREQUENCY"           => "",
    "WIRELESS_BITRATE"             => "auto",
    "WIRELESS_AP"                  => "",
    "WIRELESS_POWER"               => "",
    "WIRELESS_EAP_MODE"            => "",
    "WIRELESS_WPA_IDENTITY"        => "",
    "WIRELESS_WPA_PASSWORD"        => "",
    "WIRELESS_WPA_ANONID"          => "",
    "WIRELESS_CLIENT_CERT"         => "",
    "WIRELESS_CLIENT_KEY"          => "",
    "WIRELESS_CLIENT_KEY_PASSWORD" => "",
    "WIRELESS_CA_CERT"             => "",
    "WIRELESS_EAP_AUTH"            => "",
    "WIRELESS_PEAP_VERSION"        => "",
    "WIRELESS_AP_SCANMODE"         => "1",
    # default options for bonding (bnc#404449)
    "BONDING_MODULE_OPTS"          => "mode=active-backup miimon=100",
    # defaults for tun/tap devices
    "TUNNEL_SET_OWNER"             => "",
    "TUNNEL_SET_GROUP"             => "",
    # Infiniband
    # default mode for IPoIB devices suggested in fate#315501
    "IPOIB_MODE"                   => "connected"
  }

  # Default values used when creating an emulated NIC for physical s390 hardware.
  @s390_defaults = {
    "CHAN_MODE"       => "0",
    "QETH_PORTNAME"   => "",
    "QETH_PORTNUMBER" => "",
    "QETH_OPTIONS"    => "",
    "QETH_LAYER2"     => "no",
    "QETH_CHANIDS"    => "",
    "IPA_TAKEOVER"    => "no",
    "IUCV_USER"       => "",
    "LLADDR"          => "00:00:00:00:00:00"
  }

  # ifplugd sometimes does not work for wifi
  # so wired needs higher priority to override it
  @ifplugd_priorities = { "eth" => "20", "wlan" => "10" }
end

- (Object) needFirmwareCurrentItem



1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
# File '../../src/modules/LanItems.rb', line 1193

def needFirmwareCurrentItem
  need = false
  if IsNotEmpty(Ops.get_string(@Items, [@current, "hwinfo", "driver"], ""))
    if Builtins.haskey(
      @request_firmware,
      Ops.get_string(@Items, [@current, "hwinfo", "driver"], "")
      )
      need = true
    end
  else
    Builtins.foreach(
      Ops.get_list(@Items, [@current, "hwinfo", "drivers"], [])
    ) do |driver|
      if Builtins.haskey(
        @request_firmware,
        Ops.get_string(driver, ["modules", 0, 0], "")
        )
        Builtins.y2milestone(
          "driver %1 needs firmware",
          Ops.get_string(driver, ["modules", 0, 0], "")
        )
        need = true
      end
    end
  end
  Builtins.y2milestone("item %1 needs firmware:%2", @current, need)
  need
end

- (Object) new_device_startmode

returns default startmode for a new device

startmode is returned according product, Arch and current device type



1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
# File '../../src/modules/LanItems.rb', line 1824

def new_device_startmode
  product_startmode = ProductFeatures.GetStringFeature(
    "network",
    "startmode"
  )

  Builtins.y2milestone("Startmode by product: #{product_startmode}")

  case product_startmode
  when "ifplugd"
    if replace_ifplugd?
      startmode = hotplug_usable? ? "hotplug" : "auto"
    else
      startmode = product_startmode
    end
  when "auto"
    startmode = "auto"
  else
    startmode = hotplug_usable? ? "hotplug" : "auto"
  end

  Builtins.y2milestone("New device startmode: #{startmode}")

  startmode
end

- (Object) new_item_default_options

returns a map with device options for newly created item



1851
1852
1853
1854
1855
1856
1857
1858
1859
# File '../../src/modules/LanItems.rb', line 1851

def new_item_default_options
  {
    # bnc#46369
    "NETMASK"                    => NetHwDetection.result["NETMASK"] || "255.255.255.0",
    "STARTMODE"                  => new_device_startmode,
    # bnc#883836 bnc#868187
    "DHCLIENT_SET_DEFAULT_ROUTE" => "no"
  }
end

- (Object) Overview

Create an overview table with all configured devices

Returns:

  • table items



1493
1494
1495
1496
# File '../../src/modules/LanItems.rb', line 1493

def Overview
  BuildLanOverview()
  GetDescr()
end

- (Object) ProposeItem



2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
# File '../../src/modules/LanItems.rb', line 2372

def ProposeItem
  Builtins.y2milestone("Propose configuration for %1", getCurrentItem)
  @operation = nil
  return false if Select("") != true
  SetDefaultsForHW()
  @ipaddr = ""
  @netmask = ""
  @bootproto = "dhcp"
  # #176804
  if Storage.IsDeviceOnNetwork(NetworkStorage.getDevice("/")) != :no
    @startmode = "nfsroot"
    Builtins.y2milestone("startmode nfsroot")
  end
  NetworkInterfaces.Add
  @operation = :edit
  Ops.set(
    @Items,
    [@current, "ifcfg"],
    Ops.get_string(getCurrentItem, ["hwinfo", "dev_name"], "")
  )
  @description = HardwareName(
    [Ops.get_map(getCurrentItem, "hwinfo", {})],
    Ops.get_string(getCurrentItem, ["hwinfo", "dev_name"], "")
  )
  Commit()
  Builtins.y2milestone("After configuration propose %1", getCurrentItem)
  true
end

- (Object) Read

initializates @Items

It does: (1) read hardware present on the system (2) read known configurations (e.g. ifcfg-eth0) (3) joins together. Join is done via device name (e.g. eth0) as key. It is full outer join in -> you can have hwinfo part with no coresponding netconfig part (or vice versa) in @Items when the method is done.



1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
# File '../../src/modules/LanItems.rb', line 1066

def Read
  ReadHw()
  NetworkInterfaces.Read
  NetworkInterfaces.CleanHotplugSymlink

  interfaces = getNetworkInterfaces
  # match configurations to Items list with hwinfo
  Builtins.foreach(interfaces) do |confname|
    pos = nil
    val = {}
    Builtins.foreach(
      Convert.convert(
        @Items,
        from: "map <integer, any>",
        to:   "map <integer, map <string, any>>"
      )
    ) do |key, value|
      if Ops.get_string(value, ["hwinfo", "dev_name"], "") == confname
        pos = key
        val = deep_copy(value)
      end
    end
    if pos.nil?
      pos = Builtins.size(@Items)
      Ops.set(@Items, pos, {})
    end
    Ops.set(@Items, [pos, "ifcfg"], confname)
  end

  # add to Items also virtual devices (configurations) without hwinfo
  Builtins.foreach(interfaces) do |confname|
    already = false
    Builtins.foreach(
      Convert.convert(
        Map.Keys(@Items),
        from: "list",
        to:   "list <integer>"
      )
    ) do |key|
      if confname == Ops.get_string(@Items, [key, "ifcfg"], "")
        already = true
        raise Break
      end
    end
    if !already
      AddNew()
      Ops.set(@Items, @current, "ifcfg" => confname)
    end
  end
  Builtins.y2milestone("Read Configuration LanItems::Items %1", @Items)

  nil
end

- (Object) ReadHw

preinitializates @Items according info on physically detected network cards



1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
# File '../../src/modules/LanItems.rb', line 1007

def ReadHw
  @Items = {}
  @Hardware = ReadHardware("netcard")
  # Hardware = [$["active":true, "bus":"pci", "busid":"0000:02:00.0", "dev_name":"wlan0", "drivers":[$["active":true, "modprobe":true, "modules":[["ath5k" , ""]]]], "link":true, "mac":"00:22:43:37:55:c3", "modalias":"pci:v0000168Cd0000001Csv00001A3Bsd00001026bc02s c00i00", "module":"ath5k", "name":"AR242x 802.11abg Wireless PCI Express Adapter", "num":0, "options":"", "re quires":[], "sysfs_id":"/devices/pci0000:00/0000:00:1c.1/0000:02:00.0", "type":"wlan", "udi":"/org/freedeskto p/Hal/devices/pci_168c_1c", "wl_auth_modes":["open", "sharedkey", "wpa-psk", "wpa-eap"], "wl_bitrates":nil, " wl_channels":["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"], "wl_enc_modes":["WEP40", "WEP104", "T KIP", "CCMP"]], $["active":true, "bus":"pci", "busid":"0000:01:00.0", "dev_name":"eth0", "drivers":[$["active ":true, "modprobe":true, "modules":[["atl1e", ""]]]], "link":false, "mac":"00:23:54:3f:7c:c3", "modalias":"pc i:v00001969d00001026sv00001043sd00008324bc02sc00i00", "module":"atl1e", "name":"L1 Gigabit Ethernet Adapter", "num":1, "options":"", "requires":[], "sysfs_id":"/devices/pci0000:00/0000:00:1c.3/0000:01:00.0", "type":"et h", "udi":"/org/freedesktop/Hal/devices/pci_1969_1026", "wl_auth_modes":nil, "wl_bitrates":nil, "wl_channels" :nil, "wl_enc_modes":nil]];
  ReadUdevDriverRules()

  udev_drivers_rules = Convert.convert(
    SCR.Read(path(".udev_persistent.drivers")),
    from: "any",
    to:   "map <string, any>"
  )
  Builtins.foreach(@Hardware) do |hwitem|
    udev_net = if Ops.get_string(hwitem, "dev_name", "") != ""
                 Ops.get_list(
                   @udev_net_rules,
                   Ops.get_string(hwitem, "dev_name", ""),
                   []
                 )
               else
                 []
               end
    mod = Builtins.deletechars(
      Ops.get(
        Builtins.splitstring(
          Ops.get(
            Ops.get_list(
              udev_drivers_rules,
              Ops.get_string(hwitem, "modalias", ""),
              []
            ),
            1,
            ""
          ),
          "="
        ),
        1,
        ""
      ),
      "\""
    )
    Ops.set(
      @Items,
      Builtins.size(@Items),
      "hwinfo" => hwitem,
      "udev"   => { "net" => udev_net, "driver" => mod }
    )
  end

  nil
end

- (Object) ReadUdevDriverRules



440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File '../../src/modules/LanItems.rb', line 440

def ReadUdevDriverRules
  Builtins.y2milestone("Reading udev rules ...")
  @udev_net_rules = Convert.convert(
    SCR.Read(path(".udev_persistent.net")),
    from: "any",
    to:   "map <string, any>"
  )

  Builtins.y2milestone("Reading driver options ...")
  Builtins.foreach(SCR.Dir(path(".modules.options"))) do |driver|
    pth = Builtins.sformat(".modules.options.%1", driver)
    Builtins.foreach(
      Convert.convert(
        SCR.Read(Builtins.topath(pth)),
        from: "any",
        to:   "map <string, string>"
      )
    ) do |key, value|
      Ops.set(
        @driver_options,
        driver,
        Builtins.sformat(
          "%1%2%3=%4",
          Ops.get_string(@driver_options, driver, ""),
          if Ops.greater_than(
            Builtins.size(Ops.get_string(@driver_options, driver, "")),
            0
            )
            " "
          else
            ""
          end,
          key,
          value
        )
      )
    end
  end

  true
end

- (Object) rename(name)

Sets new device name for current item



595
596
597
598
599
600
601
# File '../../src/modules/LanItems.rb', line 595

def rename(name)
  if (GetCurrentName() != name)
    @Items[@current]["renamed_to"] = name
  else
    @Items[@current].delete("renamed_to")
  end
end

- (Boolean) renamed?(item_id)

Tells if current item was renamed

Parameters:

  • item_id (Integer)

    a key for #Items

Returns:

  • (Boolean)


617
618
619
620
# File '../../src/modules/LanItems.rb', line 617

def renamed?(item_id)
  return false if !LanItems.Items[item_id].key?("renamed_to")
  renamed_to(item_id) != GetDeviceName(item_id)
end

- (Object) renamed_to(item_id)

Returns new name for current item

Parameters:

  • item_id (Integer)

    a key for #Items



606
607
608
# File '../../src/modules/LanItems.rb', line 606

def renamed_to(item_id)
  @Items[item_id]["renamed_to"]
end

- (Boolean) replace_ifplugd?

Returns:

  • (Boolean)


1813
1814
1815
1816
1817
1818
1819
# File '../../src/modules/LanItems.rb', line 1813

def replace_ifplugd?
  return true if !Arch.is_laptop
  return true if NetworkService.is_network_manager
  return true if ["bond", "vlan", "br"].include? type

  false
end

- (Object) ReplaceItemUdev(replace_key, new_key, new_val)



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File '../../src/modules/LanItems.rb', line 521

def ReplaceItemUdev(replace_key, new_key, new_val)
  new_rules = []
  # udev syntax distinguishes among others:
  # =    for assignment
  # ==   for equality checks
  operator = new_key == "NAME" ? "=" : "=="

  Builtins.foreach(getUdevFallback) do |row|
    if Builtins.issubstring(row, replace_key)
      row = Builtins.sformat("%1%2\"%3\"", new_key, operator, new_val)
    end
    new_rules = Builtins.add(new_rules, row)
  end

  Builtins.y2debug(
    "LanItems::ReplaceItemUdev: udev rules %1",
    Ops.get_list(@Items, [@current, "udev", "net"], [])
  )

  Ops.set(@Items, [@current, "udev", "net"], new_rules)

  Builtins.y2debug(
    "LanItems::ReplaceItemUdev(%1, %2, %3) %4",
    replace_key,
    new_key,
    new_val,
    new_rules
  )

  deep_copy(new_rules)
end

- (Object) reset_cache

Clears internal cache of the module to default values

TODO: LanItems consists of several sets of internal variables. 1) cache of items describing network interface 2) variables used as a kind of iterator in the cache 3) variables which keeps (some of) attributes of the current item (= item which is being pointed by the iterator)



1127
1128
1129
1130
1131
# File '../../src/modules/LanItems.rb', line 1127

def reset_cache
  LanItems.Items = {}

  @modified = false
end

- (Object) Rollback



2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
# File '../../src/modules/LanItems.rb', line 2126

def Rollback
  if Ops.get_boolean(getCurrentItem, "commited", true) == false
    Builtins.y2milestone("rollback item %1", @current)
    if !Ops.greater_than(
      Builtins.size(Ops.get_map(getCurrentItem, "hwinfo", {})),
      0
      )
      @Items = Builtins.remove(@Items, @current)
    else
      if Builtins.haskey(Ops.get_map(@Items, @current, {}), "ifcfg")
        if !Builtins.contains(
          getNetworkInterfaces,
          Ops.get_string(getCurrentItem, "ifcfg", "")
          )
          Ops.set(
            @Items,
            @current,
            Builtins.remove(Ops.get_map(@Items, @current, {}), "ifcfg")
          )
        end
      end
    end
  end
  true
end

- (Object) Select(dev)

Select the given device FIXME: currently dev is always “”

Parameters:

  • dev (String)

    device to select (“” for new device, default values)

Returns:

  • true if success



1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
# File '../../src/modules/LanItems.rb', line 1865

def Select(dev)
  Builtins.y2debug("dev=%1", dev)

  devmap = new_item_default_options

  # FIXME: encapsulate into LanItems.GetItemType ?
  @type = Ops.get_string(@Items, [@current, "hwinfo", "type"], "eth")
  @device = @type + NetworkInterfaces.GetFreeDevice(@type)

  # TODO: instead of udev use hwinfo dev_name
  NetworkInterfaces.Name = GetItemUdev("NAME")
  if Ops.less_than(Builtins.size(@Items), @current)
    Ops.set(@Items, @current, "ifcfg" => NetworkInterfaces.Name)
  else
    Ops.set(@Items, [@current, "ifcfg"], NetworkInterfaces.Name)
  end

  # FIXME: alias: how to prefill new alias?
  @alias = ""

  # general stuff
  @description = BuildDescription(@type, @device, devmap, @Hardware)

  SetDeviceVars(devmap, @SysconfigDefaults)
  InitS390VarsByDefaults()

  @hotplug = ""
  Builtins.y2debug("type=%1", @type)
  if Builtins.issubstring(@type, "-")
    @type = Builtins.regexpsub(@type, "([^-]+)-.*$", "\\1")
  end
  Builtins.y2debug("type=%1", @type)

  true
end

- (Object) SelectHW(which)

Select the hardware component

Parameters:

  • which (Fixnum)

    index of the component



1634
1635
1636
1637
1638
# File '../../src/modules/LanItems.rb', line 1634

def SelectHW(which)
  SelectHWMap(FindHardware(@Hardware, which))

  nil
end

- (Object) SelectHWMap(hardware)

Select the hardware component

Parameters:

  • hardware

    the component



1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
# File '../../src/modules/LanItems.rb', line 1521

def SelectHWMap(hardware)
  hardware = deep_copy(hardware)
  sel = SelectHardwareMap(hardware)

  # common stuff
  @description = Ops.get_string(sel, "name", "")
  @type = Ops.get_string(sel, "type", "eth")
  @hotplug = Ops.get_string(sel, "hotplug", "")

  @Requires = Ops.get_list(sel, "requires", [])
  # #44977: Requires now contain the appropriate kernel packages
  # but they are handled differently due to multiple kernel flavors
  # (see Package::InstallKernel)
  # Leave only those not starting with "kernel".
  @Requires = Builtins.filter(@Requires) do |r|
    Builtins.search(r, "kernel") != 0
  end
  Builtins.y2milestone("requires=%1", @Requires)

  # FIXME: devname
  @hotplug = ""

  # Wireless Card Features
  @wl_auth_modes = Builtins.prepend(
    Convert.convert(
      Ops.get(hardware, "wl_auth_modes", @nilliststring),
      from: "any",
      to:   "list <string>"
    ),
    "no-encryption"
  )
  @wl_enc_modes = Convert.convert(
    Ops.get(hardware, "wl_enc_modes", @nilliststring),
    from: "any",
    to:   "list <string>"
  )
  @wl_channels = Convert.convert(
    Ops.get(hardware, "wl_channels", @nilliststring),
    from: "any",
    to:   "list <string>"
  )
  @wl_bitrates = Convert.convert(
    Ops.get(hardware, "wl_bitrates", @nilliststring),
    from: "any",
    to:   "list <string>"
  )

  Builtins.y2milestone("hw=%1", hardware)
  @hw = deep_copy(hardware)
  if Arch.s390 && @operation == :add
    Builtins.y2internal("Propose chan_ids values for %1", @hw)
    devid = 0
    devstr = ""
    s390chanid = "[0-9]+\\.[0-9]+\\."
    if Builtins.regexpmatch(Ops.get_string(@hw, "busid", ""), s390chanid)
      devid = Builtins.tointeger(
        Ops.add(
          "0x",
          Builtins.regexpsub(
            Ops.get_string(@hw, "busid", ""),
            Ops.add(s390chanid, "(.*)"),
            "\\1"
          )
        )
      )
      devstr = Builtins.regexpsub(
        Ops.get_string(@hw, "busid", ""),
        Ops.add(Ops.add("(", s390chanid), ").*"),
        "\\1"
      )
    end

    Builtins.y2milestone("devid=%1(%2)", devid, devstr)
    devid = 0 if devid.nil?
    devid0 = String.PadZeros(
      Builtins.regexpsub(Builtins.tohexstring(devid), "0x(.*)", "\\1"),
      4
    )
    devid1 = String.PadZeros(
      Builtins.regexpsub(
        Builtins.tohexstring(Ops.add(devid, 1)),
        "0x(.*)",
        "\\1"
      ),
      4
    )
    devid2 = String.PadZeros(
      Builtins.regexpsub(
        Builtins.tohexstring(Ops.add(devid, 2)),
        "0x(.*)",
        "\\1"
      ),
      4
    )
    if DriverType(@type) == "ctc" || DriverType(@type) == "lcs"
      @qeth_chanids = Builtins.sformat("%1%2 %1%3", devstr, devid0, devid1)
    else
      @qeth_chanids = Builtins.sformat(
        "%1%2 %1%3 %1%4",
        devstr,
        devid0,
        devid1,
        devid2
      )
    end
  end

  nil
end

- (Object) SetCurrentName(name)

Updates current device name.

It updates device's udev rules and config name. Updating config name means that old configuration is deleted from the system.

Returns new name



590
591
592
# File '../../src/modules/LanItems.rb', line 590

def SetCurrentName(name)
  SetItemName(@current, name)
end

- (Object) SetDefaultsForHW

must be in sync with #GetDefaultsForHW



1677
1678
1679
1680
1681
1682
# File '../../src/modules/LanItems.rb', line 1677

def SetDefaultsForHW
  Builtins.y2milestone("SetDefaultsForHW type %1", @type)
  @mtu = "1492" if Arch.s390 && Builtins.contains(["lcs", "eth"], @type)

  nil
end

- (Object) SetDeviceMap(item_id, devmap)

Sets item's sysconfig device map to given one

It updates NetworkInterfaces according given map. Map is expected to be a hash where both key even value are strings

Parameters:

  • item_id (Integer)

    a key for #Items



413
414
415
416
417
418
# File '../../src/modules/LanItems.rb', line 413

def SetDeviceMap(item_id, devmap)
  devname = GetDeviceName(item_id)
  return false if devname.nil? || devname.empty?

  NetworkInterfaces.Change2(devname, devmap, false)
end

- (void) SetDeviceVars(devmap, defaults)

This method returns an undefined value.

Distributes an ifcfg hash to individual attributes.

Parameters:

  • devmap (Hash)

    an ifcfg, values are strings

  • defaults (Hash)

    should provide defaults for devmap



1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
# File '../../src/modules/LanItems.rb', line 1688

def SetDeviceVars(devmap, defaults)
  d = defaults.merge(devmap)
  # address options
  @bootproto         = d["BOOTPROTO"]
  @ipaddr            = d["IPADDR"]
  @prefix            = d["PREFIXLEN"]
  @remoteip          = d["REMOTE_IPADDR"]
  @netmask           = d["NETMASK"]
  @set_default_route = case d["DHCLIENT_SET_DEFAULT_ROUTE"]
                       when "yes" then true
                       when "no" then  false
                         # all other values! count as unspecified which is default value
                       end

  @mtu               = d["MTU"]
  @ethtool_options   = d["ETHTOOL_OPTIONS"]
  @startmode         = d["STARTMODE"]
  @ifplugd_priority  = d["IFPLUGD_PRIORITY"]
  @description       = d["NAME"]
  @bond_option       = d["BONDING_MODULE_OPTS"]
  @vlan_etherdevice  = d["ETHERDEVICE"]
  # FIXME, remember that it can be implied from the name. probably
  @vlan_id           = d["VLAN_ID"]

  @bridge_ports = d["BRIDGE_PORTS"]

  @bond_slaves = []
  Builtins.foreach(devmap) do |key, value|
    if Builtins.regexpmatch(Convert.to_string(key), "BONDING_SLAVE[0-9]+")
      if !Convert.to_string(value).nil?
        @bond_slaves = Builtins.add(@bond_slaves, Convert.to_string(value))
      end
    end
  end

  # tun/tap settings
  @tunnel_set_owner = d["TUNNEL_SET_OWNER"]
  @tunnel_set_group = d["TUNNEL_SET_GROUP"]

  # wireless options
  @wl_mode            = d["WIRELESS_MODE"]
  @wl_essid           = d["WIRELESS_ESSID"]
  @wl_nwid            = d["WIRELESS_NWID"]
  @wl_auth_mode       = d["WIRELESS_AUTH_MODE"]
  @wl_wpa_psk         = d["WIRELESS_WPA_PSK"]
  @wl_key_length      = d["WIRELESS_KEY_LENGTH"]
  @wl_key             = [
    d["WIRELESS_KEY_0"],
    d["WIRELESS_KEY_1"],
    d["WIRELESS_KEY_2"],
    d["WIRELESS_KEY_3"]
  ]
  @wl_key[0]          = d["WIRELESS_KEY"] if (@wl_key[0] || "").empty?

  @wl_default_key     = d["WIRELESS_DEFAULT_KEY"].to_i
  @wl_nick            = d["WIRELESS_NICK"]
  @wl_wpa_eap = {
    "WPA_EAP_MODE"                => d["WIRELESS_EAP_MODE"],
    "WPA_EAP_IDENTITY"            => d["WIRELESS_WPA_IDENTITY"],
    "WPA_EAP_PASSWORD"            => d["WIRELESS_WPA_PASSWORD"],
    "WPA_EAP_ANONID"              => d["WIRELESS_WPA_ANONID"],
    "WPA_EAP_CLIENT_CERT"         => d["WIRELESS_CLIENT_CERT"],
    "WPA_EAP_CLIENT_KEY"          => d["WIRELESS_CLIENT_KEY"],
    "WPA_EAP_CLIENT_KEY_PASSWORD" => d["WIRELESS_CLIENT_KEY_PASSWORD"],
    "WPA_EAP_CA_CERT"             => d["WIRELESS_CA_CERT"],
    "WPA_EAP_AUTH"                => d["WIRELESS_EAP_AUTH"],
    "WPA_EAP_PEAP_VERSION"        => d["WIRELESS_PEAP_VERSION"]
  }
  @wl_channel     = d["WIRELESS_CHANNEL"]
  @wl_frequency   = d["WIRELESS_FREQUENCY"]
  @wl_bitrate     = d["WIRELESS_BITRATE"]
  @wl_accesspoint = d["WIRELESS_AP"]
  @wl_power       = d["WIRELESS_POWER"] == "yes"
  @wl_ap_scanmode = d["WIRELESS_AP_SCANMODE"]

  @ipoib_mode = d["IPOIB_MODE"]

  @aliases = Ops.get_map(devmap, "_aliases", {})

  nil
end

- (Object) setDriver(driver)



2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
# File '../../src/modules/LanItems.rb', line 2401

def setDriver(driver)
  Builtins.y2milestone(
    "driver %1, %2",
    driver,
    Ops.get_string(getCurrentItem, ["hwinfo", "module"], "")
  )
  if Ops.get_string(getCurrentItem, ["hwinfo", "module"], "") == driver &&
      IsEmpty(Ops.get_string(getCurrentItem, ["udev", "driver"], ""))
    return
  end
  Ops.set(@Items, [@current, "udev", "driver"], driver)

  nil
end

- (Object) SetItem



2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
# File '../../src/modules/LanItems.rb', line 2340

def SetItem
  @operation = :edit
  @device = Ops.get_string(getCurrentItem, "ifcfg", "")

  NetworkInterfaces.Edit(@device)
  @type = Ops.get_string(getCurrentItem, ["hwinfo", "type"], "")

  @type = NetworkInterfaces.GetType(@device) if IsEmpty(@type)

  @alias = NetworkInterfaces.alias_num(@device)

  # general stuff
  devmap = deep_copy(NetworkInterfaces.Current)
  s390_devmap = s390_ReadQethConfig(
    Ops.get_string(getCurrentItem, ["hwinfo", "dev_name"], "")
  )

  @description = BuildDescription(@type, @device, devmap, @Hardware)

  SetDeviceVars(devmap, @SysconfigDefaults)
  SetS390Vars(s390_devmap, @s390_defaults)

  @hotplug = ""
  Builtins.y2debug("type=%1", @type)
  if Builtins.issubstring(@type, "-")
    @type = Builtins.regexpsub(@type, "([^-]+)-.*$", "\\1")
  end
  Builtins.y2debug("type=%1", @type)

  nil
end

- (Object) SetItemName(itemId, name)

Updates device name.

It updates device's udev rules and config name. Updating config name means that old configuration is deleted from the system.

Returns new name

Parameters:

  • itemId (Integer)

    a key for #Items



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File '../../src/modules/LanItems.rb', line 562

def SetItemName(itemId, name)
  lan_items = LanItems.Items

  if name && !name.empty?
    if lan_items[itemId]["udev"]
      updated_rule = update_udev_rule_key(GetItemUdevRule(itemId), "NAME", name)
      lan_items[itemId]["udev"]["net"] = updated_rule
    end
  else
    # rewrite rule for empty name is meaningless
    lan_items[itemId].delete("udev")
  end

  if lan_items[itemId].key?("ifcfg")
    NetworkInterfaces.Delete2(lan_items[itemId]["ifcfg"])
    lan_items[itemId]["ifcfg"] = name.to_s
  end

  name
end

- (Object) SetItemSysconfigOpt(item_id, opt, value)

Sets one option in items sysconfig device map

Currently no checks on sysconfig option validity are performed

Parameters:

  • item_id (Integer)

    a key for #Items



425
426
427
428
429
430
431
# File '../../src/modules/LanItems.rb', line 425

def SetItemSysconfigOpt(item_id, opt, value)
  devmap = GetDeviceMap(item_id)
  return false if devmap.nil?

  devmap[opt] = value
  SetDeviceMap(item_id, devmap)
end

- (Object) SetModified

Function sets internal variable, which indicates, that any settings were modified, to “true”



766
767
768
769
770
# File '../../src/modules/LanItems.rb', line 766

def SetModified
  @modified = true

  nil
end

- (Object) SetS390Vars(devmap, defaults)

Initializes s390 specific device variables.

Parameters:

  • devmap (Hash)

    map with s390 specific attributes and its values

  • defaults (Hash)

    map with default values for attributes not found in devmap



1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
# File '../../src/modules/LanItems.rb', line 1774

def SetS390Vars(devmap, defaults)
  return if !Arch.s390
  d = defaults.merge(devmap)

  @qeth_portname   = d["QETH_PORTNAME"]
  @qeth_portnumber = d["QETH_PORTNUMBER"]
  @qeth_layer2     = d["QETH_LAYER2"] == "yes"
  @qeth_chanids    = d["QETH_CHANIDS"]

  # s/390 options
  # We always have to set the MAC Address for qeth Layer2 support.
  # It is used mainly as a hint for user that MAC is expected in case
  # of Layer2 devices. Other devices do not need it. Simply
  # because such devices do not emulate Layer2
  @qeth_macaddress = d["LLADDR"] if @qeth_layer2

  # qeth attribute. FIXME: currently not read from system.
  @ipa_takeover = Ops.get_string(defaults, "IPA_TAKEOVER", "") == "yes"

  # not device attribute
  @qeth_options = Ops.get_string(defaults, "QETH_OPTIONS", "")

  # handle non qeth devices
  @iucv_user = Ops.get_string(defaults, "IUCV_USER", "")
  @chan_mode = Ops.get_string(defaults, "CHAN_MODE", "")

  nil
end

- (Object) setup_basic_device_options(devmap)

Sets device map items for device when it is not alias



1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
# File '../../src/modules/LanItems.rb', line 1912

def setup_basic_device_options(devmap)
  return devmap if !@alias.empty?

  devmap["MTU"] = @mtu
  devmap["ETHTOOL_OPTIONS"] = @ethtool_options
  devmap["STARTMODE"] = @startmode
  devmap["IFPLUGD_PRIORITY"] = @ifplugd_priority.to_i if @startmode == "ifplugd"
  devmap["BOOTPROTO"] = @bootproto
  devmap["_aliases"] = @aliases

  log.info("aliases #{@aliases}")

  devmap
end

- (Object) setup_dhclient_options(devmap)

Sets device map items related to dhclient



1904
1905
1906
1907
1908
1909
# File '../../src/modules/LanItems.rb', line 1904

def setup_dhclient_options(devmap)
  if isCurrentDHCP
    devmap["DHCLIENT_SET_DEFAULT_ROUTE"] = TRISTATE_TO_S.fetch(@set_default_route)
  end
  devmap
end

- (Object) startmode_overview(item_id)

Creates item's startmode human description

Parameters:

  • item_id (Integer)

    a key for #Items



1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
# File '../../src/modules/LanItems.rb', line 1306

def startmode_overview(item_id)
  startmode_descrs = {
    # summary description of STARTMODE=auto
    "auto"    => _(
      "Started automatically at boot"
    ),
    # summary description of STARTMODE=auto
    "onboot"  => _(
      "Started automatically at boot"
    ),
    # summary description of STARTMODE=hotplug
    "hotplug" => _(
      "Started automatically at boot"
    ),
    # summary description of STARTMODE=ifplugd
    "ifplugd" => _(
      "Started automatically on cable connection"
    ),
    # summary description of STARTMODE=managed
    "managed" => _(
      "Managed by NetworkManager"
    ),
    # summary description of STARTMODE=off
    "off"     => _(
      "Will not be started at all"
    )
  }

  ifcfg = GetDeviceMap(item_id) || {}
  startmode_descr = startmode_descrs[ifcfg["STARTMODE"].to_s] || _("Started manually")

  [startmode_descr]
end

- (Object) write



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File '../../src/modules/LanItems.rb', line 735

def write
  renamed_items = @Items.keys.select { |item_id| renamed?(item_id) }
  renamed_items.each do |item_id|
    devmap = GetDeviceMap(item_id)
    # change configuration name if device is configured
    NetworkInterfaces.Change2(renamed_to(item_id), devmap, false) if devmap
    SetItemName(item_id, renamed_to(item_id))
  end

  # FIXME: in case of AY, writing udev rules was partly moved into first stage
  # (bnc#955217). However, it is so only in case of ssh / vnc installation.
  # Otherwise, udev rules are written in second stage in *LanUdevAuto* module
  # and it breaks consistency of data stored in Items. So, moving writing
  # udev rules into first stage should be completed ASAP even fo non-ssh / vnc
  # AY installations and LanUdevAuto module should be dropped.
  # When refactored at least these use cases need to be retested:
  # - bnc#955217
  # - bnc#956605
  LanItems.WriteUdevRules if !Stage.cont && LanUdevAuto.AllowUdevModify

  # FIXME: hack: no "netcard" filter as biosdevname names it diferently (bnc#712232)
  NetworkInterfaces.Write("")
end

- (Object) WriteUdevDriverRules



668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File '../../src/modules/LanItems.rb', line 668

def WriteUdevDriverRules
  udev_drivers_rules = {}

  Builtins.foreach(
    Convert.convert(
      Map.Keys(@Items),
      from: "list",
      to:   "list <integer>"
    )
  ) do |key|
    driver = Ops.get_string(@Items, [key, "udev", "driver"], "")
    if IsNotEmpty(driver)
      modalias = Ops.get_string(@Items, [key, "hwinfo", "modalias"], "")
      driver_rule = []

      driver_rule = AddToUdevRule(
        driver_rule,
        Builtins.sformat("ENV{MODALIAS}==\"%1\"", modalias)
      )
      driver_rule = AddToUdevRule(
        driver_rule,
        Builtins.sformat("ENV{MODALIAS}=\"%1\"", driver)
      )

      Ops.set(udev_drivers_rules, driver, driver_rule)
    end
  end

  Builtins.y2milestone("write drivers udev rules: %1", udev_drivers_rules)

  SCR.Write(path(".udev_persistent.drivers"), udev_drivers_rules)

  # write rules from driver
  Builtins.foreach(
    Convert.convert(
      @driver_options,
      from: "map <string, any>",
      to:   "map <string, string>"
    )
  ) do |key, value|
    val = {}
    Builtins.foreach(Builtins.splitstring(value, " ")) do |k|
      l = Builtins.splitstring(k, "=")
      Ops.set(val, Ops.get(l, 0, ""), Ops.get(l, 1, ""))
    end
    val = nil if IsEmpty(value)
    SCR.Write(Builtins.add(path(".modules.options"), key), val)
  end

  SCR.Write(path(".modules"), nil)

  nil
end

- (Object) WriteUdevItemsRules

Writes udev rules for all items.

Currently only interesting change is renaming interface.



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File '../../src/modules/LanItems.rb', line 629

def WriteUdevItemsRules
  # loop over all items and checks if device name has changed
  net_rules = []

  Builtins.foreach(
    Convert.convert(
      Map.Keys(@Items),
      from: "list",
      to:   "list <integer>"
    )
  ) do |key|
    item_udev_net = GetItemUdevRule(key)
    next if IsEmpty(item_udev_net)
    dev_name = Ops.get_string(@Items, [key, "hwinfo", "dev_name"], "")
    @current = key
    if dev_name != GetItemUdev("NAME")
      # when changing device name you have a choice
      # - change kernel "match rule", or
      # - remove it completely
      # removing is less error prone when tracking name changes, so it was chosen.
      item_udev_net = RemoveKeyFromUdevRule(item_udev_net, "KERNEL")
      # setting links down during AY is forbidden bcs it can freeze ssh installation
      SetLinkDown(dev_name) if !Mode.autoinst

      @force_restart = true
    end
    net_rules = Builtins.add(
      net_rules,
      Builtins.mergestring(item_udev_net, ", ")
    )
  end

  Builtins.y2milestone("write net udev rules: %1", net_rules)

  write_update_udevd(net_rules)

  true
end

- (Object) WriteUdevRules



722
723
724
725
726
727
728
729
730
731
732
733
# File '../../src/modules/LanItems.rb', line 722

def WriteUdevRules
  WriteUdevItemsRules()
  WriteUdevDriverRules()

  # wait so that ifcfgs written in NetworkInterfaces are newer
  # (1-second-wise) than netcontrol status files,
  # and rcnetwork reload actually works (bnc#749365)
  SCR.Execute(path(".target.bash"), "udevadm settle")
  sleep(1)

  nil
end