Class: Yast::NetworkInterfacesClass
- Inherits:
-
Module
- Object
- Module
- Yast::NetworkInterfacesClass
- Defined in:
- ../../src/modules/NetworkInterfaces.rb
Constant Summary
- ALIAS_SEPARATOR =
A single character used to separate alias id
"#"
- TYPE_REGEX =
"(ip6tnl|mip6mnha|[#{String.CAlpha}]+)"
- ID_REGEX =
"([^#{ALIAS_SEPARATOR}]*)"
- ALIAS_REGEX =
"(.*)"
- DEVNAME_REGEX =
"#{TYPE_REGEX}-?#{ID_REGEX}"
Instance Method Summary (collapse)
-
- (Object) Add
Add a new device.
-
- (Object) alias_name(typ, num, anum)
Create a alias name from its type and numbers.
-
- (Object) alias_num(dev)
Return a device alias number.
-
- (Object) CanonicalizeIP(ifcfg)
Canonicalize static ip configuration obtained from sysconfig.
-
- (Object) CanonicalizeStartmode(ifcfg)
STARTMODE: onboot, on and boot are aliases for auto.
-
- (Object) Change2(name, newdev, check)
Update Devices map.
-
- (Object) Check(dev)
Check presence of the device (alias).
-
- (Object) CleanCacheRead
re-read all settings again from system for creating new proposal from scratch (#170558).
-
- (Object) CleanHotplugSymlink
Clean the hotplug devices compatibility symlink, usually ifcfg-eth-pcmcia -> ifcfg-eth-pcmcia-0.
- - (Object) Commit
-
- (Object) ConcealSecrets(devs)
Conceal secret information, such as WEP keys, so that the output can be passed to y2log and bugzilla.
-
- (Object) ConcealSecrets1(ifcfg)
Conceal secret information, such as WEP keys, so that the output can be passed to y2log and bugzilla.
-
- (Object) Delete(name)
Delete the given device.
- - (Object) Delete2(name)
-
- (Object) DeleteAlias(device, aid)
Add the alias to the list of deleted items.
-
- (Object) device_name(typ, num)
Create a device name from its type and number.
-
- (Object) device_name_from_alias(alias_name)
Extracts device name from alias name.
-
- (Object) device_num(dev)
Return a device number Obsolete: It is incompatible with new device naming scheme.
-
- (Object) device_type(dev)
Return a device type.
-
- (Object) Edit(name)
Edit the given device.
-
- (Object) Export(devregex)
Export data.
-
- (Object) Fastest
Find the fastest available device.
- - (Object) FastestType(name)
- - (Object) Filter(devices, devregex)
-
- (Object) FilterDevices(devregex)
Used in BuildSummary, BuildOverview.
- - (Object) FilterNOT(devices, devregex)
-
- (Object) GetDeviceTypeName(dev)
Return device type in human readable form :-).
-
- (Object) GetDeviceTypes
Return supported network device types (for type netcard) for this hardware.
-
- (Object) GetDevTypeDescription(type, longdescr)
Return textual device type.
-
- (Object) GetEthTypeFromSysfs(dev)
Detects a subtype of Ethernet device type according /sys or /proc content.
-
- (Object) GetFreeDevice(type)
Return free device.
- - (Object) GetFreeDevices(type, num)
-
- (Object) GetFreeDevicesOld(type, num)
Compute free devices.
-
- (Object) GetIbTypeFromSysfs(dev)
Detects a subtype of InfiniBand device type according /sys or /proc content.
-
- (Array) GetIP(device)
get IP addres + additional IP addresses.
-
- (Object) GetType(dev)
Detects device type according cached data.
-
- (Object) GetTypeFromIfcfg(ifcfg)
Detects device type according given ifcfg configuration.
-
- (Object) GetTypeFromIfcfgOrName(dev, ifcfg)
Detects device type according its name and ifcfg configuration.
-
- (Object) GetTypeFromSysfs(dev)
Determines device type according /sys/class/net//type value.
- - (Object) GetValue(name, key)
-
- (Object) HasAliases(name)
Check if the given device has any virtual alias.
-
- (Object) HotplugRegex(devs)
Create a list of hot-pluggable device names for the given devices.
- - (Object) ifcfg_part(ifcfg, part)
-
- (Object) Import(devregex, devices)
Import data.
-
- (Object) IsConnected(dev)
Return matching inteface for this hardware ID (uses getcfg-interface) return interface name global string MatchInterface(string dev) { string cmd = “getcfg-interface ” + dev; map dn =(map) SCR::Execute(.target.bash_output, cmd); string devname = deletechars(dn:“”, “n”); return devname; } Test whether device is connected (Link:up) The info is taken from sysfs.
- - (Object) IsEmpty(value)
-
- (Object) IsHotplug(type)
Test hotplugability of a device.
-
- (Array) List(devregex)
Get devices of the given type.
-
- (Object) ListDevicesExcept(dev)
list of all devices except given one by parameter dev also loopback is ommited.
-
- (Array) Locate(key, val)
Locate devices of the given type and value.
-
- (Array) LocateNOT(key, val)
Locate devices of the given type and value.
-
- (Object) LocateProvider(provider)
Check if any device is using the specified provider.
- - (Object) main
-
- (Object) Modified(devregex)
Were the devices changed?.
- - (Object) Pop
-
- (Object) Push
DSL needs to save its config while the underlying network card is being configured.
-
- (Object) Read
Read devices from files.
-
- (Object) RealType(type, hotplug)
Return real type of the device (incl. PCMCIA, USB, …).
-
- (Object) Select(name)
Select the given device.
- - (Object) SetValue(name, key, value)
-
- (Object) UpdateModemSymlink
Update /dev/modem symlink.
-
- (Object) ValidCharsIfcfg
46803: forbid “/” (filename), maybe also “-” (separator) “_” (escape).
- - (Object) Write(devregex)
Instance Method Details
- (Object) Add
Add a new device
1497 1498 1499 1500 1501 1502 |
# File '../../src/modules/NetworkInterfaces.rb', line 1497 def Add @operation = nil return false if Select("") != true @operation = :add true end |
- (Object) alias_name(typ, num, anum)
Create a alias name from its type and numbers
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File '../../src/modules/NetworkInterfaces.rb', line 500 def alias_name(typ, num, anum) if typ == nil || typ == "" Builtins.y2error("wrong type: %1", typ) return nil end if num == nil # || num < 0 Builtins.y2error("wrong number: %1", num) return nil end if anum == nil || anum == "" Builtins.y2error("wrong alias number: %1", anum) return nil end Builtins.sformat("%1#%2", device_name(typ, num), anum) end |
- (Object) alias_num(dev)
Return a device alias number
459 460 461 |
# File '../../src/modules/NetworkInterfaces.rb', line 459 def alias_num(dev) ifcfg_part(dev, "3") end |
- (Object) CanonicalizeIP(ifcfg)
Canonicalize static ip configuration obtained from sysconfig. (suse#46885)
Static ip configuration formats supported by sysconfig: 1) IPADDR=10.0.0.1/8 2) IPADDR=10.0.0.1 PREFIXLEN=8 3) IPADDR=10.0.0.1 NETMASK=255.0.0.0
Features:
- IPADDR (in form <ip>/<prefix>) overrides
PREFIXLEN,
- NETMASK is used only if prefix length unspecified)
- If
prefix length and NETMASK are unspecified, 32 is implied.
Canonicalize it to: - IPADDR="<ipv4>" PREFIXLEN="<prefix>" NETMASK="<netmask>") in case of IPv4 config E.g. IPADDR=10.0.0.1 PREFIXLEN=8 NETMASK=255.0.0.0 - IPADDR="<ipv6>" PREFIXLEN="<prefix>" NETMASK="") in case of IPv6 config E.g. IPADDR=2001:15c0:668e::5 PREFIXLEN=48 NETMASK=""
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File '../../src/modules/NetworkInterfaces.rb', line 617 def CanonicalizeIP(ifcfg) ifcfg = deep_copy(ifcfg) return nil if ifcfg == nil ip_and_prefix = Builtins.splitstring( Ops.get_string(ifcfg, "IPADDR", ""), "/" ) ipaddr = Ops.get(ip_and_prefix, 0, "") return deep_copy(ifcfg) if ipaddr == "" # DHCP or inconsistent prefixlen = Ops.get(ip_and_prefix, 1, "") prefixlen = Ops.get_string(ifcfg, "PREFIXLEN", "") if prefixlen == "" if prefixlen == "" prefixlen = Builtins.tostring( Netmask.ToBits(Ops.get_string(ifcfg, "NETMASK", "")) ) end # Now we have ipaddr and prefixlen # Let's compute the rest netmask = "" netmask = Netmask.FromBits(Builtins.tointeger(prefixlen)) if IP.Check4( ipaddr) Ops.set(ifcfg, "IPADDR", ipaddr) Ops.set(ifcfg, "PREFIXLEN", prefixlen) Ops.set(ifcfg, "NETMASK", netmask) ifcfg end |
- (Object) CanonicalizeStartmode(ifcfg)
STARTMODE: onboot, on and boot are aliases for auto
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File '../../src/modules/NetworkInterfaces.rb', line 577 def CanonicalizeStartmode(ifcfg) ifcfg = deep_copy(ifcfg) canonicalize_startmode = { "on" => "auto", "boot" => "auto", "onboot" => "auto" } startmode = Ops.get_string(ifcfg, "STARTMODE", "") Ops.set( ifcfg, "STARTMODE", Ops.get(canonicalize_startmode, startmode, startmode) ) deep_copy(ifcfg) end |
- (Object) Change2(name, newdev, check)
Update Devices map
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 |
# File '../../src/modules/NetworkInterfaces.rb', line 1529 def Change2(name, newdev, check) newdev = deep_copy(newdev) Builtins.y2debug("Change(%1,%2,%3)", name, newdev, check) Builtins.y2debug("Devices=%1", @Devices) if Check(name) && check Builtins.y2error("Device already present: %1", name) return false end t = !IsEmpty(newdev) ? GetTypeFromIfcfgOrName(name, newdev) : GetType(name) if name == @Name int_type = Ops.get_string(@Current, "INTERFACETYPE", "") t = int_type if Ops.greater_than(Builtins.size(int_type), 0) end a = alias_num(name) Builtins.y2debug("ChangeDevice(%1)", name) devsmap = Ops.get(@Devices, t, {}) devmap = Ops.get(devsmap, name, {}) amap = Ops.get_map(devmap, "_aliases", {}) if a != "" Ops.set(amap, a, newdev) Ops.set(devmap, "_aliases", amap) else devmap = deep_copy(newdev) end Ops.set(devsmap, name, devmap) Ops.set(@Devices, t, devsmap) Builtins.y2debug("Devices=%1", @Devices) true end |
- (Object) Check(dev)
Check presence of the device (alias)
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 |
# File '../../src/modules/NetworkInterfaces.rb', line 1431 def Check(dev) Builtins.y2debug("Check(%1)", dev) typ = GetType(dev) # string num = device_num(dev); # string anum = alias_num(dev); Builtins.y2milestone("Check(%1)", dev) if @report_every_check return false if !Builtins.haskey(@Devices, typ) devsmap = Ops.get(@Devices, typ, {}) return false if !Builtins.haskey(devsmap, dev) # FIXME NI: not needed? # Name = dev; # Current = (map) eval(devsmap[num]:$[]); # if(anum != "") { # map devmap = devsmap[num]:$[]; # map amap = devmap["_aliases"]:$[]; # if(!haskey(amap, anum)) # return false; # // FIXME NI: not needed? # // Current = (map) eval(amap[anum]:$[]); # // alias = anum; # } Builtins.y2debug("Check passed") true end |
- (Object) CleanCacheRead
re-read all settings again from system for creating new proposal from scratch (#170558)
779 780 781 782 |
# File '../../src/modules/NetworkInterfaces.rb', line 779 def CleanCacheRead @initialized = false Read() end |
- (Object) CleanHotplugSymlink
Clean the hotplug devices compatibility symlink, usually ifcfg-eth-pcmcia -> ifcfg-eth-pcmcia-0.
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 |
# File '../../src/modules/NetworkInterfaces.rb', line 1744 def CleanHotplugSymlink types = ["eth-pcmcia", "eth-usb", "tr-pcmcia", "tr-usb"] Builtins.maplist(types) do |t| link = Ops.add("/etc/sysconfig/network/ifcfg-", t) Builtins.y2debug("link=%1", link) lstat = Convert.to_map(SCR.Read(path(".target.lstat"), link)) if Ops.get_boolean(lstat, "islink", false) == true file = Convert.to_string(SCR.Read(path(".target.symlink"), link)) file = Ops.add("/etc/sysconfig/network/", file) Builtins.y2debug("file=%1", file) if Ops.greater_than(SCR.Read(path(".target.size"), file), -1) Builtins.y2milestone("Cleaning hotplug symlink") Builtins.y2milestone("Devices[%1]=%2", t, Ops.get(@Devices, t, {})) Ops.set(@Devices, t, Builtins.remove(Ops.get(@Devices, t, {}), "")) Builtins.y2milestone("Devices[%1]=%2", t, Ops.get(@Devices, t, {})) end end end Builtins.y2debug("Devices=%1", @Devices) true end |
- (Object) Commit
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 |
# File '../../src/modules/NetworkInterfaces.rb', line 1616 def Commit Builtins.y2debug("Name=%1", @Name) Builtins.y2debug("Current=%1", @Current) Builtins.y2debug("Devices=%1", @Devices) Builtins.y2debug("Deleted=%1", @Deleted) Builtins.y2debug("operation=%1", @operation) if @operation == :add || @operation == :edit Change2(@Name, @Current, @operation == :add) elsif @operation == :delete Delete2(@Name) else Builtins.y2error("Unknown operation: %1 (%2)", @operation, @Name) return false end Builtins.y2debug("Devices=%1", @Devices) Builtins.y2debug("Deleted=%1", @Deleted) @Name = "" @Current = {} @operation = nil true end |
- (Object) ConcealSecrets(devs)
Conceal secret information, such as WEP keys, so that the output can be passed to y2log and bugzilla. (#65741)
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File '../../src/modules/NetworkInterfaces.rb', line 667 def ConcealSecrets(devs) devs = deep_copy(devs) return nil if devs == nil out = Builtins.mapmap( Convert.convert( devs, :from => "map", :to => "map <string, map <string, map <string, any>>>" ) ) do |t, tdevs| tout = Builtins.mapmap(tdevs) do |id, ifcfg| { id => ConcealSecrets1(ifcfg) } end { t => tout } end deep_copy(out) end |
- (Object) ConcealSecrets1(ifcfg)
Conceal secret information, such as WEP keys, so that the output can be passed to y2log and bugzilla.
653 654 655 656 657 658 659 660 661 |
# File '../../src/modules/NetworkInterfaces.rb', line 653 def ConcealSecrets1(ifcfg) ifcfg = deep_copy(ifcfg) return nil if ifcfg == nil out = Builtins.mapmap(ifcfg) do |k, v| v = "CONCEALED" if Builtins.contains(@SensitiveFields, k) && v != "" { k => v } end deep_copy(out) end |
- (Object) Delete(name)
Delete the given device
1517 1518 1519 1520 1521 1522 |
# File '../../src/modules/NetworkInterfaces.rb', line 1517 def Delete(name) @operation = nil return false if Select(name) != true @operation = :delete true end |
- (Object) Delete2(name)
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 |
# File '../../src/modules/NetworkInterfaces.rb', line 1568 def Delete2(name) if !Check(name) Builtins.y2error("Device not found: %1", name) return false end t = GetType(name) # string d = device_num(name); a = alias_num(name) devsmap = Ops.get(@Devices, t, {}) if a != "" amap = Ops.get_map(devsmap, [name, "_aliases"], {}) amap = Builtins.remove(amap, a) Ops.set(devsmap, [name, "_aliases"], amap) else devsmap = Builtins.remove(devsmap, name) end Ops.set(@Devices, t, devsmap) # Originally this avoided errors in the log when deleting an # interface that was not present at Read (had no ifcfg file). # #115448: OriginalDevices is not updated after Write so # returning to the network proposal and deleting a card would not work. if true || Builtins.haskey(@OriginalDevices, t) && Builtins.haskey(Ops.get(@OriginalDevices, t, {}), name) Builtins.y2milestone("Deleting file: %1", name) Ops.set(@Deleted, Builtins.size(@Deleted), name) else Builtins.y2milestone("Not deleting file: %1", name) Builtins.y2debug("OriginalDevices=%1", @OriginalDevices) Builtins.y2debug("a=%1", a) end true end |
- (Object) DeleteAlias(device, aid)
Add the alias to the list of deleted items. Called when exiting from the aliases-of-device dialog.
48191
1609 1610 1611 1612 1613 1614 |
# File '../../src/modules/NetworkInterfaces.rb', line 1609 def DeleteAlias(device, aid) _alias = Builtins.sformat("%1#%2", device, aid) Builtins.y2milestone("Deleting alias: %1", _alias) Ops.set(@Deleted, Builtins.size(@Deleted), _alias) true end |
- (Object) device_name(typ, num)
Create a device name from its type and number
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File '../../src/modules/NetworkInterfaces.rb', line 469 def device_name(typ, num) if typ == nil || typ == "" Builtins.y2error("wrong type: %1", typ) return nil end if num == nil # || num < 0 Builtins.y2error("wrong number: %1", num) return nil end # FIXME: devname # if(IsHotplug(typ) && num != "") return sformat("%1-%2", typ, num); # return sformat("%1%2", typ, num); if Builtins.regexpmatch(num, "^[0-9]*$") return Builtins.sformat("%1%2", typ, num) end Builtins.sformat("%1-%2", typ, num) end |
- (Object) device_name_from_alias(alias_name)
Extracts device name from alias name
alias_name := <device_name>ALIAS_SEPARATOR<alias_name>
490 491 492 |
# File '../../src/modules/NetworkInterfaces.rb', line 490 def device_name_from_alias(alias_name) alias_name.sub(/#{ALIAS_SEPARATOR}.*/, "") end |
- (Object) device_num(dev)
Return a device number Obsolete: It is incompatible with new device naming scheme.
449 450 451 452 |
# File '../../src/modules/NetworkInterfaces.rb', line 449 def device_num(dev) Builtins.y2warning( "Do not use device_num.") ifcfg_part(dev, "2") end |
- (Object) device_type(dev)
Return a device type
250 251 252 |
# File '../../src/modules/NetworkInterfaces.rb', line 250 def device_type(dev) ifcfg_part(dev, "1") end |
- (Object) Edit(name)
Edit the given device
1507 1508 1509 1510 1511 1512 |
# File '../../src/modules/NetworkInterfaces.rb', line 1507 def Edit(name) @operation = nil return false if Select(name) != true @operation = :edit true end |
- (Object) Export(devregex)
Export data
1319 1320 1321 1322 1323 |
# File '../../src/modules/NetworkInterfaces.rb', line 1319 def Export(devregex) _Devs = Filter(@Devices, devregex) Builtins.y2debug("Devs=%1", _Devs) Convert.convert(_Devs, :from => "map", :to => "map <string, map>") end |
- (Object) Fastest
Find the fastest available device
1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 |
# File '../../src/modules/NetworkInterfaces.rb', line 1810 def Fastest ret = "" devices = List("") # Find the fastest device Builtins.foreach(@FastestTypes) { |num, type| Builtins.foreach(devices) do |dev| if ret == "" && Builtins.regexpmatch( dev, Ops.add(Ops.add("^", Ops.get(@DeviceRegex, type, "")), "[0-9]*$") ) && IsConnected(dev) ret = dev end end } Builtins.y2milestone("ret=%1", ret) ret end |
- (Object) FastestType(name)
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 |
# File '../../src/modules/NetworkInterfaces.rb', line 1830 def FastestType(name) ret = "" Builtins.maplist(@FastestTypes) do |num, type| regex = Ops.get(@DeviceRegex, type, "") if ret == "" && Builtins.regexpmatch(name, Ops.add(Ops.add("^", regex), "[0-9]*$")) ret = type end end # maplist(string typ, string regex, DeviceRegex, { # if (ret == "" && regexpmatch(name, "^" + regex + "[0-9]*$")) # ret = typ; # }); ret end |
- (Object) Filter(devices, devregex)
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 |
# File '../../src/modules/NetworkInterfaces.rb', line 786 def Filter(devices, devregex) devices = deep_copy(devices) if devices == nil || devregex == nil || devregex == "" return deep_copy(devices) end regex = Ops.add( Ops.add("^(", Ops.get(@DeviceRegex, devregex, devregex)), ")[0-9]*$" ) Builtins.y2debug("regex=%1", regex) devices = Builtins.filter(devices) do |file, devmap| Builtins.regexpmatch(file, regex) == true end Builtins.y2debug("devices=%1", devices) deep_copy(devices) end |
- (Object) FilterDevices(devregex)
Used in BuildSummary, BuildOverview
805 806 807 |
# File '../../src/modules/NetworkInterfaces.rb', line 805 def FilterDevices(devregex) Filter(@Devices, devregex) end |
- (Object) FilterNOT(devices, devregex)
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 |
# File '../../src/modules/NetworkInterfaces.rb', line 810 def FilterNOT(devices, devregex) devices = deep_copy(devices) return {} if devices == nil || devregex == nil || devregex == "" regex = Ops.add( Ops.add("^(", Ops.get(@DeviceRegex, devregex, devregex)), ")[0-9]*$" ) Builtins.y2debug("regex=%1", regex) devices = Builtins.filter(devices) do |file, devmap| Builtins.regexpmatch(file, regex) != true end Builtins.y2debug("devices=%1", devices) deep_copy(devices) end |
- (Object) GetDeviceTypeName(dev)
Return device type in human readable form :-)
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File '../../src/modules/NetworkInterfaces.rb', line 415 def GetDeviceTypeName(dev) # pppN must be tried before pN, modem before netcard if Builtins.regexpmatch( dev, Ops.add("^", Ops.get(@DeviceRegex, "modem", "")) ) return _("Modem") elsif Builtins.regexpmatch( dev, Ops.add("^", Ops.get(@DeviceRegex, "netcard", "")) ) return _("Network Card") elsif Builtins.regexpmatch( dev, Ops.add("^", Ops.get(@DeviceRegex, "isdn", "")) ) return _("ISDN") elsif Builtins.regexpmatch( dev, Ops.add("^", Ops.get(@DeviceRegex, "dsl", "")) ) return _("DSL") else return _("Unknown") end end |
- (Object) GetDeviceTypes
Return supported network device types (for type netcard) for this hardware
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 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 |
# File '../../src/modules/NetworkInterfaces.rb', line 1087 def GetDeviceTypes # common linux device types available on all architectures common_dev_types = ["eth", "tr", "vlan", "br", "tun", "tap", "bond"] # s390 specific device types s390_dev_types = ["hsi", "ctc", "escon", "ficon", "iucv", "qeth", "lcs"] # device types which cannot be present on s390 arch s390_unknown_dev_types = [ "arc", "bnep", "dummy", "fddi", "myri", "usb", "wlan", "ib" ] # ia64 specific device types ia64_dev_types = ["xp"] dev_types = deep_copy(common_dev_types) if Arch.s390 dev_types = Convert.convert( Builtins.merge(dev_types, s390_dev_types), :from => "list", :to => "list <string>" ) else if Arch.ia64 dev_types = Convert.convert( Builtins.merge(dev_types, ia64_dev_types), :from => "list", :to => "list <string>" ) end dev_types = Convert.convert( Builtins.merge(dev_types, s390_unknown_dev_types), :from => "list", :to => "list <string>" ) end Builtins.foreach(dev_types) do |device| if !Builtins.contains( Builtins.splitstring(Ops.get(@DeviceRegex, "netcard", ""), "|"), device ) Builtins.y2error( "%1 is not contained in DeviceRegex[\"netcard\"]", device ) end end deep_copy(dev_types) end |
- (Object) GetDevTypeDescription(type, longdescr)
Return textual device type
1154 1155 1156 1157 1158 1159 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 1192 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 1221 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 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File '../../src/modules/NetworkInterfaces.rb', line 1154 def GetDevTypeDescription(type, longdescr) if Builtins.issubstring(type, "#") # Device type label # This is what used to be Virtual Interface (eth0:1). # In our data model, additional addresses for an interface # are represented as its sub-interfaces. # And also we frequently confuse "device" and "interface" # :-( return _("Additional Address") end device_types = { # Device type label "arc" => [_("ARCnet"), _("ARCnet Network Card")], # Device type label "atm" => [ _("ATM"), _("Asynchronous Transfer Mode (ATM)") ], # Device type label "bnep" => [ _("Bluetooth"), _("Bluetooth Connection") ], # Device type label "bond" => [_("Bond"), _("Bond Network")], # Device type label "ci" => [ _("CLAW"), _("Common Link Access for Workstation (CLAW)") ], # Device type label "contr" => [_("ISDN"), _("ISDN Card")], # Device type label "ctc" => [ _("CTC"), _("Channel to Channel Interface (CTC)") ], # Device type label "dsl" => [_("DSL"), _("DSL Connection")], # Device type label "dummy" => [_("Dummy"), _("Dummy Network Device")], # Device type label "escon" => [ _("ESCON"), _("Enterprise System Connector (ESCON)") ], # Device type label "eth" => [ _("Ethernet"), _("Ethernet Network Card") ], # Device type label "fddi" => [_("FDDI"), _("FDDI Network Card")], # Device type label "ficon" => [ _("FICON"), _("Fiberchannel System Connector (FICON)") ], # Device type label "hippi" => [ _("HIPPI"), _("HIgh Performance Parallel Interface (HIPPI)") ], # Device type label "hsi" => [ _("Hipersockets"), _("Hipersockets Interface (HSI)") ], # Device type label "ippp" => [_("ISDN"), _("ISDN Connection")], # Device type label "irlan" => [_("IrDA"), _("Infrared Network Device")], # Device type label "irda" => [_("IrDA"), _("Infrared Device")], # Device type label "isdn" => [_("ISDN"), _("ISDN Connection")], # Device type label "iucv" => [ _("IUCV"), _("Inter User Communication Vehicle (IUCV)") ], # Device type label "lcs" => [_("OSA LCS"), _("OSA LCS Network Card")], # Device type label "lo" => [_("Loopback"), _("Loopback Device")], # Device type label "modem" => [_("Modem"), _("Modem")], # Device type label "myri" => [_("Myrinet"), _("Myrinet Network Card")], # Device type label "net" => [_("ISDN"), _("ISDN Connection")], # Device type label "plip" => [ _("Parallel Line"), _("Parallel Line Connection") ], # Device type label "ppp" => [_("Modem"), _("Modem")], # Device type label "qeth" => [ _("QETH"), _("OSA-Express or QDIO Device (QETH)") ], # Device type label "sit" => [ _("IPv6-in-IPv4"), _("IPv6-in-IPv4 Encapsulation Device") ], # Device type label "slip" => [ _("Serial Line"), _("Serial Line Connection") ], # Device type label "tr" => [ _("Token Ring"), _("Token Ring Network Card") ], # Device type label "usb" => [_("USB"), _("USB Network Device")], # Device type label "vmnet" => [_("VMWare"), _("VMWare Network Device")], # Device type label "wlan" => [ _("Wireless"), _("Wireless Network Card") ], # Device type label "xp" => [_("XPNET"), _("XP Network")], # Device type label "vlan" => [_("VLAN"), _("Virtual LAN")], # Device type label "br" => [_("Bridge"), _("Network Bridge")], # Device type label "tun" => [_("TUN"), _("Network TUNnel")], # Device type label "tap" => [_("TAP"), _("Network TAP")], # Device type label "ib" => [_("InfiniBand"), _("InfiniBand Device")] } if Builtins.haskey(device_types, type) return Ops.get_string( device_types, [type, longdescr == true ? 1 : 0], "" ) end type1 = String.FirstChunk(type, "-") if Builtins.haskey(device_types, type1) return Ops.get_string( device_types, [type1, longdescr == true ? 1 : 0], "" ) end Builtins.y2error("Unknown type: %1", type) type end |
- (Object) GetEthTypeFromSysfs(dev)
Detects a subtype of Ethernet device type according /sys or /proc content
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File '../../src/modules/NetworkInterfaces.rb', line 255 def GetEthTypeFromSysfs(dev) sys_dir_path = Builtins.sformat("/sys/class/net/%1/", dev) if FileUtils.Exists(Ops.add(sys_dir_path, "wireless")) return "wlan" elsif FileUtils.Exists(Ops.add(sys_dir_path, "phy80211")) return "wlan" elsif FileUtils.Exists(Ops.add(sys_dir_path, "bridge")) return "bridge" elsif FileUtils.Exists(Ops.add(sys_dir_path, "bonding")) return "bond" elsif FileUtils.Exists(Ops.add(sys_dir_path, "tun_flags")) return "tap" elsif FileUtils.Exists(Ops.add("/proc/net/vlan/", dev)) return "vlan" elsif FileUtils.Exists(Ops.add("/sys/devices/virtual/net/", dev)) && Builtins.regexpmatch(dev, "dummy.*") return "dummy" else return "eth" end end |
- (Object) GetFreeDevice(type)
Return free device
1419 1420 1421 1422 1423 1424 1425 1426 |
# File '../../src/modules/NetworkInterfaces.rb', line 1419 def GetFreeDevice(type) Builtins.y2debug("type=%1", type) freedevs = GetFreeDevices(type, 1) ret = Ops.get(freedevs, 0) Builtins.y2error("Free device location error: %1", ret) if ret == nil Builtins.y2debug("Free device=%1", ret) ret end |
- (Object) GetFreeDevices(type, num)
1335 1336 1337 1338 1339 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 1369 1370 1371 1372 1373 1374 1375 |
# File '../../src/modules/NetworkInterfaces.rb', line 1335 def GetFreeDevices(type, num) Builtins.y2debug("Devices=%1", @Devices) Builtins.y2debug("type,num=%1,%2", type, num) Builtins.y2debug("Devices[%1]=%2", type, Ops.get(@Devices, type, {})) curdevs = [] Builtins.foreach( Convert.convert( Map.Keys(Ops.get(@Devices, type, {})), :from => "list", :to => "list <string>" ) ) do |dev| dev = device_num(dev) if Builtins.issubstring(dev, type) curdevs = Builtins.add(curdevs, dev) end i = 0 count = 0 ret = [] # Hotpluggable devices if IsHotplug(type) && !Builtins.contains(curdevs, "") Builtins.y2debug("Added simple hotplug device") count = Ops.add(count, 1) ret = Builtins.add(ret, "") end # Remaining numbered devices while Ops.less_than(count, num) ii = Builtins.sformat("%1", i) if !Builtins.contains(curdevs, ii) ret = Builtins.add(ret, ii) count = Ops.add(count, 1) end i = Ops.add(i, 1) end Builtins.y2debug("Free devices=%1", ret) deep_copy(ret) end |
- (Object) GetFreeDevicesOld(type, num)
Compute free devices
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 |
# File '../../src/modules/NetworkInterfaces.rb', line 1382 def GetFreeDevicesOld(type, num) Builtins.y2debug("Devices=%1", @Devices) Builtins.y2debug("type,num=%1,%2", type, num) Builtins.y2debug("Devices[%1]=%2", type, Ops.get(@Devices, type, {})) curdevs = Map.Keys(Ops.get(@Devices, type, {})) Builtins.y2debug("curdevs=%1", curdevs) i = 0 count = 0 ret = [] # Hotpluggable devices if IsHotplug(type) && !Builtins.contains(curdevs, "") Builtins.y2debug("Added simple hotplug device") count = Ops.add(count, 1) ret = Builtins.add(ret, "") end # Remaining numbered devices while Ops.less_than(count, num) ii = Builtins.sformat("%1", i) if !Builtins.contains(curdevs, ii) ret = Builtins.add(ret, ii) count = Ops.add(count, 1) end i = Ops.add(i, 1) end Builtins.y2debug("Free devices=%1", ret) deep_copy(ret) end |
- (Object) GetIbTypeFromSysfs(dev)
Detects a subtype of InfiniBand device type according /sys or /proc content
279 280 281 282 283 284 285 286 287 288 289 |
# File '../../src/modules/NetworkInterfaces.rb', line 279 def GetIbTypeFromSysfs(dev) sys_dir_path = Builtins.sformat("/sys/class/net/%1/", dev) if FileUtils.Exists(Ops.add(sys_dir_path, "bonding")) return "bond" elsif FileUtils.Exists(Ops.add(sys_dir_path, "create_child")) return "ib" else return "ibchild" end end |
- (Array) GetIP(device)
get IP addres + additional IP addresses
1658 1659 1660 1661 1662 1663 1664 1665 |
# File '../../src/modules/NetworkInterfaces.rb', line 1658 def GetIP(device) Select(device) ips = [GetValue(device, "IPADDR")] Builtins.foreach(Ops.get_map(@Current, "_aliases", {})) do |key, value| ips = Builtins.add(ips, Ops.get_string(value, "IPADDR", "")) end deep_copy(ips) end |
- (Object) GetType(dev)
Detects device type according cached data
If cached ifcfg for given device is found it is used as parameter for GetTypeFromIfcfgOrName( dev, ifcfg). Otherwise is device handled as unconfigured and result is equal to GetTypeFromIfcfgOrName( dev, nil)
399 400 401 402 403 404 405 406 407 408 |
# File '../../src/modules/NetworkInterfaces.rb', line 399 def GetType(dev) type = GetTypeFromIfcfgOrName(dev, nil) Builtins.foreach(@Devices) do |dev_type, confs| ifcfg = Ops.get(confs, dev, {}) type = GetTypeFromIfcfgOrName(dev, ifcfg) if !IsEmpty(ifcfg) end type end |
- (Object) GetTypeFromIfcfg(ifcfg)
Detects device type according given ifcfg configuration
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File '../../src/modules/NetworkInterfaces.rb', line 340 def GetTypeFromIfcfg(ifcfg) ifcfg = deep_copy(ifcfg) type = nil return nil if IsEmpty(ifcfg) Builtins.foreach(@TypeByValueMatch) do |key_type| rule_key = Ops.get(key_type, 0, "") rule_value = Ops.get(key_type, 1, "") rule_type = Ops.get(key_type, 2, "") type = rule_type if Ops.get_string(ifcfg, rule_key, "") == rule_value end Builtins.foreach(@TypeByKeyExistence) do |key_type| rule_key = Ops.get(key_type, 0, "") rule_type = Ops.get(key_type, 1, "") type = rule_type if Ops.get_string(ifcfg, rule_key, "") != "" end Builtins.foreach(@TypeByKeyValue) do |rule_key| rule_type = Ops.get_string(ifcfg, rule_key, "") type = rule_type if rule_type != "" end type end |
- (Object) GetTypeFromIfcfgOrName(dev, ifcfg)
Detects device type according its name and ifcfg configuration.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File '../../src/modules/NetworkInterfaces.rb', line 372 def GetTypeFromIfcfgOrName(dev, ifcfg) ifcfg = deep_copy(ifcfg) return nil if IsEmpty(dev) type = GetTypeFromSysfs(dev) type = GetTypeFromIfcfg(ifcfg) if IsEmpty(type) type = device_type(dev) if type == nil Builtins.y2debug( "GetTypeFromIfcfgOrName: device='%1', type='%2'", dev, type ) type end |
- (Object) GetTypeFromSysfs(dev)
Determines device type according /sys/class/net/<dev>/type value
Firstly, it uses /sys/class/net/<dev>/type for basic decision. Obtained values are translated to device type according <kernel src>/include/uapi/linux/if_arp.h. Sometimes it uses some other checks to specify a "subtype". E.g. in case of "eth" it checks for presence of "wireless" subdir to determine "wlan" device.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File '../../src/modules/NetworkInterfaces.rb', line 299 def GetTypeFromSysfs(dev) sys_dir_path = Builtins.sformat("/sys/class/net/%1", dev) sys_type_path = Builtins.sformat("%1/type", sys_dir_path) return nil if IsEmpty(dev) || !FileUtils.Exists(sys_type_path) sys_type = Convert.to_string( SCR.Read(path(".target.string"), sys_type_path) ) sys_type = sys_type != nil ? Builtins.regexpsub(sys_type, "(.*)\n", "\\1") : "" sys_type = String.CutBlanks(sys_type) type = nil case sys_type when "1" type = GetEthTypeFromSysfs(dev) when "32" type = GetIbTypeFromSysfs(dev) else type = Ops.get(@TypeBySysfs, sys_type) end Builtins.y2debug( "GetTypeFromSysFs: device='%1', sysfs type='%2', type='%3'", dev, sys_type, type ) return nil if IsEmpty(type) type end |
- (Object) GetValue(name, key)
1642 1643 1644 1645 |
# File '../../src/modules/NetworkInterfaces.rb', line 1642 def GetValue(name, key) return nil if !Select(name) Ops.get_string(@Current, key, "") end |
- (Object) HasAliases(name)
Check if the given device has any virtual alias.
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 |
# File '../../src/modules/NetworkInterfaces.rb', line 1849 def HasAliases(name) if !Check(name) Builtins.y2error("Device not found: %1", name) return false end t = device_type(name) d = device_num(name) a = alias_num(name) a == "" && Ops.get_map(@Devices, [t, d, "_aliases"], {}) != {} end |
- (Object) HotplugRegex(devs)
Create a list of hot-pluggable device names for the given devices
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File '../../src/modules/NetworkInterfaces.rb', line 210 def HotplugRegex(devs) devs = deep_copy(devs) ret = "" Builtins.foreach(devs) { |dev| Builtins.foreach(@HotplugTypes) do |hot| ret = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(Ops.add(Ops.add(Ops.add(ret, "|"), dev), "-"), hot), "|" ), dev ), "-" ), hot ), "-" ) end } ret end |
- (Object) ifcfg_part(ifcfg, part)
239 240 241 242 243 |
# File '../../src/modules/NetworkInterfaces.rb', line 239 def ifcfg_part(ifcfg, part) return "" if Builtins.regexpmatch(ifcfg, @ifcfg_name_regex) != true ret = Builtins.regexpsub(ifcfg, @ifcfg_name_regex, "\\#{part}") ret == nil ? "" : ret end |
- (Object) Import(devregex, devices)
Import data
All devices which confirms to <devregex> are silently removed from Devices and replaced by those supplied by <devices>.
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File '../../src/modules/NetworkInterfaces.rb', line 1042 def Import(devregex, devices) devices = deep_copy(devices) _Devs = FilterNOT(@Devices, devregex) Builtins.y2debug("Devs=%1", _Devs) devices = Builtins.mapmap(devices) do |typ, devsmap| { typ => Builtins.mapmap( Convert.convert( devsmap, :from => "map", :to => "map <string, map <string, any>>" ) ) do |num, config| config = CanonicalizeIP(config) config = CanonicalizeStartmode(config) { num => config } end } end @Devices = Convert.convert( Builtins.union(_Devs, devices), :from => "map", :to => "map <string, map <string, map <string, any>>>" ) if devices == nil || devices == {} # devices == $[] is used in lan_auto "Reset" as a way how to # rollback changes imported from AY @initialized = false else @initialized = true end Builtins.y2milestone( "NetworkInterfaces::Import - done, cache content: %1", @Devices ) true end |
- (Object) IsConnected(dev)
Return matching inteface for this hardware ID (uses getcfg-interface) return interface name global string MatchInterface(string dev) { string cmd = "getcfg-interface " + dev; map dn =(map) SCR::Execute(.target.bash_output, cmd); string devname = deletechars(dn:"", "\n");
return devname;
} Test whether device is connected (Link:up) The info is taken from sysfs
540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File '../../src/modules/NetworkInterfaces.rb', line 540 def IsConnected(dev) if !Mode.testsuite # string iface = MatchInterface(dev); cmd = Ops.add(Ops.add("cat /sys/class/net/", dev), "/carrier") ret = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) Builtins.y2milestone("Sysfs returned %1", ret) return Builtins.deletechars(Ops.get_string(ret, "stdout", ""), "\n") == "1" ? true : false else #Assume all devices are connected in testsuite mode return true end end |
- (Object) IsEmpty(value)
234 235 236 237 |
# File '../../src/modules/NetworkInterfaces.rb', line 234 def IsEmpty(value) value = deep_copy(value) TypeRepository.IsEmpty(value) end |
- (Object) IsHotplug(type)
Test hotplugability of a device
519 520 521 522 523 |
# File '../../src/modules/NetworkInterfaces.rb', line 519 def IsHotplug(type) return false if type == "" || type == nil return true if Builtins.regexpmatch(type, "(pcmcia|usb|pci)$") false end |
- (Array) List(devregex)
Get devices of the given type
1770 1771 1772 1773 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 1802 1803 1804 1805 1806 1807 |
# File '../../src/modules/NetworkInterfaces.rb', line 1770 def List(devregex) ret = [] if devregex == "" || devregex == nil Builtins.maplist(@Devices) do |t, d| Builtins.maplist( Convert.convert( Map.Keys(d), :from => "list", :to => "list <string>" ) ) { |device| Ops.set(ret, Builtins.size(ret), device) } end else # it's a regex for type, not the whole name regex = Ops.add( Ops.add("^(", Ops.get(@DeviceRegex, devregex, devregex)), ")$" ) Builtins.maplist(@Devices) do |t, d| if Builtins.regexpmatch(t, regex) Builtins.maplist( Convert.convert( Map.Keys(d), :from => "list", :to => "list <string>" ) ) { |device| Ops.set(ret, Builtins.size(ret), device) } end end end ret = Builtins.filter(ret) do |row| next true if row != nil Builtins.y2error("Filtering out : %1", row) false end Builtins.y2debug("List(%1) = %2", devregex, ret) deep_copy(ret) end |
- (Object) ListDevicesExcept(dev)
list of all devices except given one by parameter dev also loopback is ommited
1892 1893 1894 1895 |
# File '../../src/modules/NetworkInterfaces.rb', line 1892 def ListDevicesExcept(dev) devices = Builtins.filter(LocateNOT("DEVICE", dev)) { |s| s != "lo" } deep_copy(devices) end |
- (Array) Locate(key, val)
Locate devices of the given type and value
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 |
# File '../../src/modules/NetworkInterfaces.rb', line 1672 def Locate(key, val) ret = [] Builtins.maplist(@Devices) do |typ, devsmap| Builtins.maplist( Convert.convert(devsmap, :from => "map", :to => "map <string, map>") ) do |device, devmap| if Ops.get_string(devmap, key, "") == val ret = Builtins.add(ret, device) end end end deep_copy(ret) end |
- (Array) LocateNOT(key, val)
Locate devices of the given type and value
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 |
# File '../../src/modules/NetworkInterfaces.rb', line 1691 def LocateNOT(key, val) ret = [] Builtins.maplist(@Devices) do |typ, devsmap| Builtins.maplist( Convert.convert(devsmap, :from => "map", :to => "map <string, map>") ) do |device, devmap| if Ops.get_string(devmap, key, "") != val ret = Builtins.add(ret, device) end end end deep_copy(ret) end |
- (Object) LocateProvider(provider)
Check if any device is using the specified provider
1709 1710 1711 1712 |
# File '../../src/modules/NetworkInterfaces.rb', line 1709 def LocateProvider(provider) devs = Locate("PROVIDER", provider) Ops.greater_than(Builtins.size(devs), 0) end |
- (Object) main
48 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 |
# File '../../src/modules/NetworkInterfaces.rb', line 48 def main textdomain "base" Yast.import "Arch" Yast.import "Map" Yast.import "Mode" Yast.import "Netmask" Yast.import "TypeRepository" Yast.import "FileUtils" Yast.import "IP" # False suppresses tones of logs 'NetworkInterfaces.ycp:ABC Check(eth,id-00:aa:bb:cc:dd:ee,)' @report_every_check = # value is not just string, can be a map for aliases true # Current device identifier # @example eth0, eth1:blah, lo, ... # Add, Edit and Delete copy the requested device info (via Select) # to Name and Current, # Commit puts it back @Name = "" # Current device information # @example $["BOOTPROTO":"dhcp", "STARTMODE":"auto"] @Current = {} # Interface information: # Devices[string type, string id] is a map with the contents of # ifcfg-<i>type</i>-<i>id</i>. Separating type from id is useful because # the type determines the fields of the interface file. # Multiple addresses for an interface are nested maps # [type, id, "_aliases", aid] # @see #Read @Devices = {} # Devices information # @see #Read @OriginalDevices = {} # Deleted devices @Deleted = [] # True if devices are already read @initialized = false # Which operation is pending? # global @operation = nil # FIXME: used in lan/address.ycp (#17346) -> "global" # Predefined network card regular expressions @CardRegex = # other: irlan|lo|plip|... { "netcard" => "arc|ath|bnep|ci|ctc|dummy|bond|escon|eth|fddi|ficon|hsi|qeth|lcs|iucv|myri|tr|usb|wlan|xp|vlan|br|tun|tap|ib|em|p|p[0-9]+p", "modem" => "ppp|modem", "isdn" => "isdn|ippp", "dsl" => "dsl" } # define string HotplugRegex(list<string> devs); # Supported hotplug types @HotplugTypes = ["pcmcia", "usb"] #, "pci" # Predefined network device regular expressions @DeviceRegex = { # device types "netcard" => Ops.add( Ops.add( Ops.get(@CardRegex, "netcard", ""), HotplugRegex(["ath", "eth", "tr", "wlan"]) ), "|usb-usb|usb-usb-" ), "modem" => Ops.get(@CardRegex, "modem", ""), "isdn" => Ops.add( Ops.get(@CardRegex, "isdn", ""), HotplugRegex(["isdn", "ippp"]) ), "dsl" => Ops.get(@CardRegex, "dsl", ""), # device groups "dialup" => Ops.add( Ops.add( Ops.add( Ops.add(Ops.get(@CardRegex, "modem", ""), "|"), Ops.get(@CardRegex, "dsl", "") ), "|" ), Ops.get(@CardRegex, "isdn", "") ) } # Types in order from fastest to slowest. # @see #FastestRegexps @FastestTypes = { 1 => "dsl", 2 => "isdn", 3 => "modem", 4 => "netcard" } # @see #Push @stack = {} # -------------------- components of configuration names -------------------- # ifcfg name = type + id + alias_id # If id is numeric, it is not separated from type, otherwise separated by "-" # Id may be empty # Alias_id, if nonempty, is separated by alias_separator @ifcfg_name_regex = "^#{DEVNAME_REGEX}#{ALIAS_SEPARATOR}?#{ALIAS_REGEX}$" # Translates type code exposed by kernel in sysfs onto internaly used dev types. @TypeBySysfs = { "1" => "eth", "24" => "eth", "32" => "ib", "512" => "ppp", "768" => "ipip", "769" => "ip6tnl", "772" => "lo", "776" => "sit", "778" => "gre", "783" => "irda", "801" => "wlan_aux", "65534" => "tun" } @TypeByKeyValue = ["INTERFACETYPE"] @TypeByKeyExistence = [ ["ETHERDEVICE", "vlan"], ["WIRELESS_MODE", "wlan"], ["MODEM_DEVICE", "ppp"] ] @TypeByValueMatch = [ ["BONDING_MASTER", "yes", "bond"], ["BRIDGE", "yes", "br"], ["WIRELESS", "yes", "wlan"], ["TUNNEL", "tap", "tap"], ["TUNNEL", "tun", "tun"], ["TUNNEL", "sit", "sit"], ["TUNNEL", "gre", "gre"], ["TUNNEL", "ipip", "ipip"], ["PPPMODE", "pppoe", "ppp"], ["PPPMODE", "pppoatm", "ppp"], ["PPPMODE", "capi-adsl", "ppp"], ["PPPMODE", "pptp", "ppp"], ["ENCAP", "syncppp", "isdn"], ["ENCAP", "rawip", "isdn"] ] @SensitiveFields = [ "WIRELESS_WPA_PASSWORD", "WIRELESS_WPA_PSK", # the unnumbered one should be empty but just in case "WIRELESS_KEY", "WIRELESS_KEY_0", "WIRELESS_KEY_1", "WIRELESS_KEY_2", "WIRELESS_KEY_3" ] end |
- (Object) Modified(devregex)
Were the devices changed?
1327 1328 1329 1330 1331 1332 1333 |
# File '../../src/modules/NetworkInterfaces.rb', line 1327 def Modified(devregex) _Devs = Filter(@Devices, devregex) _OriginalDevs = Filter(@OriginalDevices, devregex) Builtins.y2debug("OriginalDevs=%1", _OriginalDevs) Builtins.y2debug("Devs=%1", _Devs) _Devs == _OriginalDevs end |
- (Object) Pop
1874 1875 1876 1877 1878 1879 1880 1881 1882 |
# File '../../src/modules/NetworkInterfaces.rb', line 1874 def Pop Builtins.y2milestone("POP: %1", @stack) @Name = Ops.get_string(@stack, "Name", "") @Current = Ops.get_map(@stack, "Current", {}) @operation = Ops.get_symbol(@stack, "operation") @stack = {} nil end |
- (Object) Push
DSL needs to save its config while the underlying network card is being configured.
1864 1865 1866 1867 1868 1869 1870 1871 1872 |
# File '../../src/modules/NetworkInterfaces.rb', line 1864 def Push Builtins.y2error("Stack not empty: %1", @stack) if @stack != {} Ops.set(@stack, "Name", @Name) Ops.set(@stack, "Current", @Current) Ops.set(@stack, "operation", @operation) Builtins.y2milestone("PUSH: %1", @stack) nil end |
- (Object) Read
Read devices from files
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 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
# File '../../src/modules/NetworkInterfaces.rb', line 687 def Read # initialized = true; // FIXME return true if @initialized == true @Devices = {} # Variables which could be suffixed and thus duplicated _Locals = [ "IPADDR", "REMOTE_IPADDR", "NETMASK", "PREFIXLEN", "BROADCAST", "SCOPE", "LABEL", "IP_OPTIONS" ] # preparation allfiles = SCR.Dir(path(".network.section")) allfiles = [] if allfiles == nil devices = Builtins.filter(allfiles) do |file| !Builtins.regexpmatch(file, "[~]") end Builtins.y2debug("devices=%1", devices) # FIXME: devname # devices = filter(string d, devices, { # return regexpmatch(d, "[a-z][a-z-]*[0-9]*"); # }); # y2debug("devices=%1", devices); # Read devices Builtins.maplist(devices) do |d| pth = Ops.add(Ops.add(".network.value.\"", d), "\"") Builtins.y2debug("pth=%1", pth) values = SCR.Dir(Builtins.topath(pth)) Builtins.y2debug("values=%1", values) config = {} Builtins.maplist(values) do |val| item = Convert.to_string( SCR.Read(Builtins.topath(Ops.add(Ops.add(pth, "."), val))) ) Builtins.y2debug("item=%1", item) next if item == nil # No underscore '_' -> global # Also temporarily standard globals if Ops.less_than(Builtins.find(val, "_"), 0) || Builtins.contains(_Locals, val) Ops.set(config, val, item) next end # Try to strip _suffix v = Builtins.substring(val, 0, Builtins.findlastof(val, "_")) s = Builtins.substring(val, Builtins.findlastof(val, "_")) s = Builtins.substring(s, 1) if Ops.greater_than(Builtins.size(s), 1) Builtins.y2milestone("%1:%2:%3", val, v, s) # Global if !Builtins.contains(_Locals, v) Ops.set(config, val, item) else __aliases = Ops.get_map(config, "_aliases", {}) suf = Ops.get_map(__aliases, s, {}) Ops.set(suf, v, item) Ops.set(__aliases, s, suf) Ops.set(config, "_aliases", __aliases) end end Builtins.y2milestone("config=%1", ConcealSecrets1(config)) # canonicalize, #46885 caliases = Builtins.mapmap(Ops.get_map(config, "_aliases", {})) do |a, c| { a => CanonicalizeIP(c) } end if caliases != {} # unconditionally? Ops.set(config, "_aliases", caliases) end config = CanonicalizeIP(config) config = CanonicalizeStartmode(config) devtype = GetTypeFromIfcfg(config) devtype = GetType(d) if devtype == nil dev = Ops.get(@Devices, devtype, {}) Ops.set(dev, d, config) Ops.set(@Devices, devtype, dev) end Builtins.y2debug("Devices=%1", @Devices) @OriginalDevices = deep_copy(@Devices) @initialized = true true end |
- (Object) RealType(type, hotplug)
Return real type of the device (incl. PCMCIA, USB, …)
560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File '../../src/modules/NetworkInterfaces.rb', line 560 def RealType(type, hotplug) Builtins.y2debug("type=%1", type) if type == "" || type == nil Builtins.y2error("Wrong type: %1", type) return "eth" end return type if hotplug == "" || hotplug == nil realtype = Ops.add(Ops.add(type, "-"), hotplug) Builtins.y2debug("realtype=%1", realtype) realtype end |
- (Object) Select(name)
Select the given device
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 1490 1491 1492 1493 |
# File '../../src/modules/NetworkInterfaces.rb', line 1462 def Select(name) @Name = "" @Current = {} Builtins.y2debug("name=%1", name) if name != "" && !Check(name) Builtins.y2error("No such device: %1", name) return false end @Name = name # FIXME NI: Current = Devices[device_type(Name), device_num(Name)]:$[]; # may be fixed already. or not: #39236 t = GetType(@Name) @Current = Ops.get(@Devices, [t, @Name], {}) a = alias_num(@Name) if a != nil && a != "" @Current = Ops.get_map(@Current, ["_aliases", a], {}) end if @Current == {} # Default device map @Current = # FIXME: remaining items {} end Builtins.y2debug("Name=%1", @Name) Builtins.y2debug("Current=%1", @Current) true end |
- (Object) SetValue(name, key, value)
1647 1648 1649 1650 1651 1652 |
# File '../../src/modules/NetworkInterfaces.rb', line 1647 def SetValue(name, key, value) return nil if !Edit(name) return false if key == nil || key == "" || value == nil Ops.set(@Current, key, value) Commit() end |
- (Object) UpdateModemSymlink
Update /dev/modem symlink
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 |
# File '../../src/modules/NetworkInterfaces.rb', line 1716 def UpdateModemSymlink ret = false if Builtins.contains(Map.Keys(@Devices), "modem") ml = Map.Keys(Ops.get(@Devices, "modem", {})) ms = Ops.get_string(ml, 0, "0") # map mm = Devices["modem"]:$[][ms]:$[]; mm = Ops.get(@Devices, ["modem", ms], {}) mdev = Ops.get_string(mm, "MODEM_DEVICE", "") if mdev != "" && mdev != "/dev/modem" curlink = nil m = Convert.to_map(SCR.Read(path(".target.lstat"), "/dev/modem")) if Ops.get_boolean(m, "islink", false) == true curlink = Convert.to_string( SCR.Read(path(".target.symlink"), "/dev/modem") ) end if curlink != mdev SCR.Execute(path(".target.symlink"), mdev, "/dev/modem") ret = true end end end ret end |
- (Object) ValidCharsIfcfg
46803: forbid “/” (filename), maybe also “-” (separator) “_” (escape)
1885 1886 1887 |
# File '../../src/modules/NetworkInterfaces.rb', line 1885 def ValidCharsIfcfg String.ValidCharsFilename end |
- (Object) Write(devregex)
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 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 886 887 888 889 890 891 892 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 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 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 |
# File '../../src/modules/NetworkInterfaces.rb', line 826 def Write(devregex) Builtins.y2milestone("Writing configuration") Builtins.y2debug("Devices=%1", @Devices) Builtins.y2debug("Deleted=%1", @Deleted) _Devs = Filter(@Devices, devregex) _OriginalDevs = Filter(@OriginalDevices, devregex) Builtins.y2milestone("OriginalDevs=%1", ConcealSecrets(_OriginalDevs)) Builtins.y2milestone("Devs=%1", ConcealSecrets(_Devs)) # Check for changes if _Devs == _OriginalDevs Builtins.y2milestone( "No changes to %1 devices -> nothing to write", devregex ) return true end # remove deleted devices Builtins.y2milestone("Deleted=%1", @Deleted) Builtins.foreach(@Deleted) do |d| # if(!haskey(OriginalDevs, d)) return; anum = alias_num(d) if anum == "" # delete config file p = Builtins.add(path(".network.section"), d) Builtins.y2debug("deleting: %1", p) SCR.Write(p, nil) else dev = device_name_from_alias(d) typ = GetType(dev) base = Builtins.add(path(".network.value"), dev) # look in OriginalDevs because we need to catch all variables # of the alias dev_aliases = _OriginalDevs[typ][dev]["_aliases"][anum] || {} dev_aliases.keys.each do |key| p = base + "#{key}_#{anum}" Builtins.y2debug("deleting: %1", p) SCR.Write(p, nil) end end end @Deleted = [] # write all devices Builtins.maplist( Convert.convert( _Devs, :from => "map", :to => "map <string, map <string, map <string, any>>>" ) ) { |typ, devsmap| Builtins.maplist(devsmap) do |config, devmap| next if devmap == Ops.get_map(_OriginalDevs, [typ, config], {}) # write sysconfig p = Ops.add(Ops.add(".network.value.\"", config), "\".") if Ops.greater_than( Builtins.size(Ops.get_string(devmap, "IPADDR", "")), 0 ) && Builtins.find(Ops.get_string(devmap, "IPADDR", ""), "/") == -1 if Ops.greater_than( Builtins.size(Ops.get_string(devmap, "IPADDR", "")), 0 ) && Ops.greater_than( Builtins.size(Ops.get_string(devmap, "NETMASK", "")), 0 ) Ops.set( devmap, "IPADDR", Builtins.sformat( "%1/%2", Ops.get_string(devmap, "IPADDR", ""), Netmask.ToBits(Ops.get_string(devmap, "NETMASK", "")) ) ) devmap = Builtins.remove(devmap, "NETMASK") #TODO : delete NETMASK from config file else if Ops.greater_than( Builtins.size(Ops.get_string(devmap, "IPADDR", "")), 0 ) && Ops.greater_than( Builtins.size(Ops.get_string(devmap, "PREFIXLEN", "")), 0 ) Ops.set( devmap, "IPADDR", Builtins.sformat( "%1/%2", Ops.get_string(devmap, "IPADDR", ""), Ops.get_string(devmap, "PREFIXLEN", "") ) ) devmap = Builtins.remove(devmap, "PREFIXLEN") #TODO : delete PREFIXLEN from config file end end end # write all keys to config Builtins.maplist( Convert.convert( Map.Keys(devmap), :from => "list", :to => "list <string>" ) ) do |k| # Write aliases if k == "_aliases" Builtins.maplist(Ops.get_map(devmap, k, {})) do |anum, amap| # Normally defaulting the label would be done # when creating the map, not here when # writing, but we create it in 2 ways so it's # better here. Actually it does not work because # the edit dialog nukes LABEL :-( # boolean seen_label = false; if Ops.greater_than(Builtins.size(Ops.get(amap, "IPADDR", "")), 0) && Ops.greater_than( Builtins.size(Ops.get(amap, "NETMASK", "")), 0 ) Ops.set( amap, "IPADDR", Builtins.sformat( "%1/%2", Ops.get(amap, "IPADDR", ""), Netmask.ToBits(Ops.get(amap, "NETMASK", "")) ) ) amap = Builtins.remove(amap, "NETMASK") #TODO : delete NETMASK from config file else if Ops.greater_than( Builtins.size(Ops.get(amap, "IPADDR", "")), 0 ) && Ops.greater_than( Builtins.size(Ops.get(amap, "PREFIXLEN", "")), 0 ) Ops.set( amap, "IPADDR", Builtins.sformat( "%1/%2", Ops.get(amap, "IPADDR", ""), Ops.get(amap, "PREFIXLEN", "") ) ) amap = Builtins.remove(amap, "PREFIXLEN") #TODO : delete PREFIXLEN from config file end end Builtins.maplist(amap) do |ak, av| akk = Ops.add(Ops.add(ak, "_"), anum) SCR.Write(Builtins.topath(Ops.add(p, akk)), av) # seen_label = seen_label || ak == "LABEL"; end # if (!seen_label) # { # ShellSafeWrite (topath (p + ("LABEL_" + anum)), anum); # } end else # Write regular keys SCR.Write( Builtins.topath(Ops.add(p, k)), Ops.get_string(devmap, k, "") ) end end # update libhd unique number * / # // FIXME: move it somewhere else: hardware # string unq = devmap["UNIQUE"]:""; # if(unq != "") SCR::Write(.probe.status.configured, unq, `yes); # 0600 if contains encryption key (#24842) has_key = Builtins.find(@SensitiveFields) do |k| Ops.get_string(devmap, k, "") != "" end != nil file = Ops.add("/etc/sysconfig/network/ifcfg-", config) if has_key Builtins.y2debug("Permission change: %1", config) SCR.Write( Builtins.add(path(".network.section_private"), config), true ) end @OriginalDevices = {} if @OriginalDevices == nil if Ops.get(@OriginalDevices, typ) == nil Ops.set(@OriginalDevices, typ, {}) end Ops.set( @OriginalDevices, [typ, config], Ops.get(@Devices, [typ, config], {}) ) end } # Finish him SCR.Write(path(".network"), nil) true end |