Class: Yast::RoutingClass
- Inherits:
-
Module
- Object
- Module
- Yast::RoutingClass
- Includes:
- Logger
- Defined in:
- ../../src/modules/Routing.rb
Constant Summary
- ROUTES_DIR =
“routes” and ifroute-DEV file directory
"/etc/sysconfig/network"
- ROUTES_FILE =
“routes” file location
"/etc/sysconfig/network/routes"
- SYSCTL_IPV4_PATH =
".etc.sysctl_conf.\"net.ipv4.ip_forward\""
- SYSCTL_IPV6_PATH =
".etc.sysctl_conf.\"net.ipv6.conf.all.forwarding\""
- ANY_DEVICE =
see man routes - difference on implicit device param (aka “-”) in case of /etc/sysconfig/network/routes and /etc/sysconfig/network/ /ifroute-<device>
"-"
Instance Attribute Summary (collapse)
-
- (Array<String>) devices
readonly
Names of devices with sysconfig configuration.
Instance Method Summary (collapse)
-
- (Object) Export
Dump the Routing settings to a map, for autoinstallation use.
-
- (Object) GetDevices
Get the current devices list.
-
- (Object) GetGateway
Get the default gateway.
-
- (Object) Import(settings)
Get all the Routing configuration from a map.
- - (Object) main
-
- (Object) Modified
Data was modified?.
-
- (Object) Read
Read routing settings If no routes, sets a default gateway from Detection.
-
- (Object) ReadFromGateway(gw)
Set the routes to contain only the default route, if it is defined.
- - (Object) ReadIPForwarding
-
- (Object) RemoveDefaultGw
Remove route with default gateway from Routes list.
-
- (Object) SetDevices(devs)
Set the available devices list (for expert routing dialog).
-
- (Object) Summary
Create routing text summary.
-
- (Object) Write
Write routing settings and apply changes.
-
- (true, false) write_route_file(device, routes)
From routes, select those belonging to device and write an appropriate config file.
-
- (true, false) write_routes(routes)
Updates routing configuration files.
- - (Object) WriteIPForwarding
Instance Attribute Details
- (Array<String>) devices (readonly)
Returns names of devices with sysconfig configuration
37 38 39 |
# File '../../src/modules/Routing.rb', line 37 def devices @devices end |
Instance Method Details
- (Object) Export
Dump the Routing settings to a map, for autoinstallation use.
364 365 366 367 368 369 370 371 372 |
# File '../../src/modules/Routing.rb', line 364 def Export exproute = {} exproute["routes"] = deep_copy(@Routes) unless @Routes.empty? exproute["ipv4_forward"] = @Forward_v4 exproute["ipv6_forward"] = @Forward_v6 exproute end |
- (Object) GetDevices
Get the current devices list
376 377 378 |
# File '../../src/modules/Routing.rb', line 376 def GetDevices deep_copy(@devices) end |
- (Object) GetGateway
Get the default gateway
382 383 384 385 386 387 388 389 390 |
# File '../../src/modules/Routing.rb', line 382 def GetGateway defgw = "" Builtins.maplist(@Routes) do |r| if Ops.get_string(r, "destination", "") == "default" defgw = Ops.get_string(r, "gateway", "") end end defgw end |
- (Object) Import(settings)
Get all the Routing configuration from a map. When called by routing_auto (preparing autoinstallation data) the map may be empty.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File '../../src/modules/Routing.rb', line 338 def Import(settings) settings = deep_copy(settings) # Getting a list of devices which have already been imported by Lan.Import # (bnc#900352) @devices = NetworkInterfaces.List("") ip_forward = Ops.get_boolean(settings, "ip_forward", false) ipv4_forward = Ops.get_boolean(settings, "ipv4_forward", ip_forward) ipv6_forward = Ops.get_boolean(settings, "ipv6_forward", ip_forward) @Routes = deep_copy(Ops.get_list(settings, "routes", [])) @Forward_v4 = ipv4_forward @Forward_v6 = ipv6_forward @Orig_Routes = nil @Orig_Forward_v4 = nil @Orig_Forward_v6 = nil @modified = true true end |
- (Object) main
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 |
# File '../../src/modules/Routing.rb', line 61 def main Yast.import "UI" textdomain "network" Yast.import "NetHwDetection" Yast.import "NetworkInterfaces" Yast.import "Map" Yast.import "Mode" Yast.import "SuSEFirewall" Yast.include self, "network/runtime.rb" Yast.include self, "network/routines.rb" # All routes # list <map <string, string> >: # keys: destination, gateway, netmask, [device, [extrapara]] @Routes = [] # Enable IP forwarding # .etc.sysctl_conf."net.ipv4.ip_forward" @Forward_v4 = false @Forward_v6 = false # List of available devices @devices = [] end |
- (Object) Modified
Data was modified?
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File '../../src/modules/Routing.rb', line 90 def Modified # probably called without Read() (bnc#649494) no_orig_values = @Orig_Routes.nil? no_orig_values &&= @Orig_Forward_v4.nil? no_orig_values &&= @Orig_Forward_v6.nil? no_orig_values &&= @modified != true return false if no_orig_values ret = @Routes != @Orig_Routes ret ||= @Forward_v4 != @Orig_Forward_v4 ret ||= @Forward_v6 != @Orig_Forward_v6 Builtins.y2debug("Routing#modified: #{ret}") ret end |
- (Object) Read
Read routing settings If no routes, sets a default gateway from Detection
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 |
# File '../../src/modules/Routing.rb', line 191 def Read # read available devices NetworkInterfaces.Read @devices = NetworkInterfaces.List("") # read routes @Routes = SCR.Read(path(".routes")) || [] @devices.each do |device| # Mode.test required for old testsuite. Dynamic agent registration break # stubing there register_ifroute_agent_for_device(device) unless Mode.test dev_routes = SCR.Read(path(".ifroute-#{device}")) || [] next if dev_routes.nil? || dev_routes.empty? dev_routes.map! do |route| route["device"] = device if route["device"] == ANY_DEVICE route end @Routes.concat dev_routes end @Routes.uniq! log.info("Routes=#{@Routes}") ReadIPForwarding() # save routes to check for changes later @Orig_Routes = deep_copy(@Routes) @Orig_Forward_v4 = @Forward_v4 @Orig_Forward_v6 = @Forward_v6 if @Routes.empty? ReadFromGateway(NetHwDetection.result["GATEWAY"] || "") end true end |
- (Object) ReadFromGateway(gw)
Set the routes to contain only the default route, if it is defined. Used when there is nothing better.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File '../../src/modules/Routing.rb', line 111 def ReadFromGateway(gw) return false if gw == "" || gw == nil @Routes = [ { "destination" => "default", "gateway" => gw, "netmask" => "-", "device" => ANY_DEVICE } ] true end |
- (Object) ReadIPForwarding
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File '../../src/modules/Routing.rb', line 140 def ReadIPForwarding if SuSEFirewall.IsEnabled @Forward_v4 = SuSEFirewall.GetSupportRoute # FIXME: missing support for setting IPv6 forwarding enablement in # SuSEFirewall module and in SuSEFirewall2 at all else @Forward_v4 = SCR.Read(path(SYSCTL_IPV4_PATH)) == "1" @Forward_v6 = SCR.Read(path(SYSCTL_IPV6_PATH)) == "1" end log.info("Forward_v4=#{@Forward_v4}") log.info("Forward_v6=#{@Forward_v6}") nil end |
- (Object) RemoveDefaultGw
Remove route with default gateway from Routes list
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File '../../src/modules/Routing.rb', line 125 def RemoveDefaultGw route = [] Builtins.y2milestone( "Resetting default gateway - interface has been set to DHCP mode" ) Builtins.foreach(@Routes) do |row| if Ops.get_string(row, "destination", "") != "default" route = Builtins.add(route, row) end end @Routes = deep_copy(route) nil end |
- (Object) SetDevices(devs)
Set the available devices list (for expert routing dialog)
395 396 397 398 399 400 401 402 403 |
# File '../../src/modules/Routing.rb', line 395 def SetDevices(devs) devs = deep_copy(devs) if devs == nil @devices = [] return false end @devices = deep_copy(devs) true end |
- (Object) Summary
Create routing text summary
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File '../../src/modules/Routing.rb', line 407 def Summary return "" if @Routes.nil? || @Routes.empty? Yast.import "Summary" summary = "" gw = GetGateway() gwhost = NetHwDetection.ResolveIP(gw) gw = "#{gw} (#{gwhost})" unless gwhost.empty? # Summary text summary = Summary.AddListItem(summary, _("Gateway: %s") % gw) unless gw.empty? on_off = @Forward_v4 ? "on" : "off" # Summary text summary = Summary.AddListItem(summary, _("IP Forwarding for IPv4: %s") % on_off) on_off = @Forward_v6 ? "on" : "off" # Summary text summary = Summary.AddListItem(summary, _("IP Forwarding for IPv6: %s") % on_off) return "" if summary.empty? "<ul>#{summary}</ul>" end |
- (Object) Write
Write routing settings and apply changes
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 |
# File '../../src/modules/Routing.rb', line 235 def Write Builtins.y2milestone("Writing configuration") if !Modified() Builtins.y2milestone("No changes to routing -> nothing to write") return true end steps = [ # Progress stage 1 _("Write IP forwarding settings"), # Progress stage 2 _("Write routing settings") ] caption = _("Saving Routing Configuration") Progress.New(caption, " ", Builtins.size(steps), steps, [], "") #Progress stage 1/2 ProgressNextStage(_("Writing IP forwarding settings...")) WriteIPForwarding() # at first stop the running routes # FIXME SCR::Execute(.target.bash, "/etc/init.d/route stop"); # sysconfig does not support restarting routes only, # so we let our caller do it together with other things #Progress stage 2/2 ProgressNextStage(_("Writing routing settings...")) ret = write_routes(@Routes) Progress.NextStage ret end |
- (true, false) write_route_file(device, routes)
From routes, select those belonging to device and write an appropriate config file.
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File '../../src/modules/Routing.rb', line 278 def write_route_file(device, routes) routes = routes.select { |r| r["device"] == device } if routes.empty? # work around bnc#19476 if device == ANY_DEVICE filename = ROUTES_FILE return SCR.Write(path(".target.string"), filename, "") else filename = "#{ROUTES_DIR}/ifroute-#{device}" return SCR.Execute(path(".target.remove"), filename) end else if device == ANY_DEVICE scr_path = path(".routes") else scr_path = register_ifroute_agent_for_device(device) end return SCR.Write(scr_path, routes) end end |
- (true, false) write_routes(routes)
Updates routing configuration files
It means /etc/sysconfig/network/routes and /etc/sysconfig/network/ifroute-*
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File '../../src/modules/Routing.rb', line 307 def write_routes(routes) # create if not exists, otherwise backup if SCR.Read(path(".target.size"), ROUTES_FILE) > 0 SCR.Execute( path(".target.bash"), "/bin/cp #{ROUTES_FILE} #{ROUTES_FILE}.YaST2save" ) else SCR.Write(path(".target.string"), ROUTES_FILE, "") end ret = true # update the routes config Routing.devices.each do |device| written = write_route_file(device, routes) ret &&= written end written = write_route_file(ANY_DEVICE, routes) ret &&= written return ret end |
- (Object) WriteIPForwarding
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 |
# File '../../src/modules/Routing.rb', line 156 def WriteIPForwarding forward_ipv4 = @Forward_v4 ? "1" : "0" forward_ipv6 = @Forward_v6 ? "1" : "0" if SuSEFirewall.IsEnabled # FIXME: missing support for setting IPv6 forwarding enablement in # SuSEFirewall module and in SuSEFirewall2 at all SuSEFirewall.SetSupportRoute(@Forward_v4) else SCR.Write( path(SYSCTL_IPV4_PATH), forward_ipv4 ) SCR.Write( path(SYSCTL_IPV6_PATH), forward_ipv6 ) SCR.Write(path(".etc.sysctl_conf"), nil) end SCR.Execute( path(".target.bash"), "echo #{forward_ipv4} > /proc/sys/net/ipv4/ip_forward" ) SCR.Execute( path(".target.bash"), "echo #{forward_ipv6} > /proc/sys/net/ipv6/conf/all/forwarding", ) nil end |