Class: OsCtld::Routing::Table
- Inherits:
-
Object
- Object
- OsCtld::Routing::Table
- Defined in:
- lib/osctld/routing/table.rb
Overview
Represents routing table for a network interface
Defined Under Namespace
Classes: Version
Instance Attribute Summary collapse
-
#tables ⇒ Object
readonly
protected
Returns the value of attribute tables.
Class Method Summary collapse
-
.load(cfg) ⇒ Object
Load the table from config.
Instance Method Summary collapse
- #<<(addr) ⇒ Object
- #add(addr, via: nil) ⇒ Routing::Route
-
#any?(v) ⇒ Boolean
Check if there are any routes for given IP version.
-
#contains?(addr) ⇒ Boolean
Check if there is an exact entry for ‘addr`.
-
#dump ⇒ Hash
Dump the table into config.
-
#each(_ip_v) {|version, addr| ... } ⇒ Object
Iterate over all routes.
-
#each_version(ip_v) {|addr| ... } ⇒ Object
Iterate over all routes for IP version.
- #empty?(v) ⇒ Boolean
-
#export ⇒ Hash
Export the table to clients.
-
#initialize(tables: nil) ⇒ Table
constructor
A new instance of Table.
- #remove(addr) ⇒ Routing::Route?
- #remove_all(ip_v = nil) ⇒ Array<Routing::Route>
-
#remove_version_if(ip_v) {|addr| ... } ⇒ Object
Remove routes for which the block returns truthy value.
-
#route?(addr) ⇒ Boolean
Check if the table routes ‘addr`.
- #t(addr) ⇒ Object protected
Constructor Details
Instance Attribute Details
#tables ⇒ Object (readonly, protected)
Returns the value of attribute tables.
210 211 212 |
# File 'lib/osctld/routing/table.rb', line 210 def tables @tables end |
Class Method Details
Instance Method Details
#<<(addr) ⇒ Object
114 115 116 117 |
# File 'lib/osctld/routing/table.rb', line 114 def <<(addr) add(addr) self end |
#add(addr, via: nil) ⇒ Routing::Route
122 123 124 |
# File 'lib/osctld/routing/table.rb', line 122 def add(addr, via: nil) t(addr).add(addr, via:) end |
#any?(v) ⇒ Boolean
Check if there are any routes for given IP version
159 160 161 |
# File 'lib/osctld/routing/table.rb', line 159 def any?(v) tables[v].any? end |
#contains?(addr) ⇒ Boolean
Check if there is an exact entry for ‘addr`
153 154 155 |
# File 'lib/osctld/routing/table.rb', line 153 def contains?(addr) t(addr).contains?(addr) end |
#dump ⇒ Hash
Dump the table into config
204 205 206 |
# File 'lib/osctld/routing/table.rb', line 204 def dump tables.to_h { |version, table| ["v#{version}", table.dump] } end |
#each(_ip_v) {|version, addr| ... } ⇒ Object
Iterate over all routes
171 172 173 174 175 176 177 178 179 |
# File 'lib/osctld/routing/table.rb', line 171 def each(_ip_v, &) ret = [] tables.each do |version, table| ret.concat(table.get.map { |route| [version, route] }) end ret.to_h.each(&) end |
#each_version(ip_v) {|addr| ... } ⇒ Object
Iterate over all routes for IP version
184 185 186 |
# File 'lib/osctld/routing/table.rb', line 184 def each_version(ip_v, &) tables[ip_v].get.each(&) end |
#empty?(v) ⇒ Boolean
164 165 166 |
# File 'lib/osctld/routing/table.rb', line 164 def empty?(v) tables[v].empty? end |
#export ⇒ Hash
Export the table to clients
198 199 200 |
# File 'lib/osctld/routing/table.rb', line 198 def export tables.transform_values(&:export) end |
#remove(addr) ⇒ Routing::Route?
128 129 130 |
# File 'lib/osctld/routing/table.rb', line 128 def remove(addr) t(addr).remove(addr) end |
#remove_all(ip_v = nil) ⇒ Array<Routing::Route>
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/osctld/routing/table.rb', line 134 def remove_all(ip_v = nil) ret = [] (ip_v ? [ip_v] : [4, 6]).each do |v| ret.concat(tables[v].get) tables[v].clear end ret end |
#remove_version_if(ip_v) {|addr| ... } ⇒ Object
Remove routes for which the block returns truthy value
192 193 194 |
# File 'lib/osctld/routing/table.rb', line 192 def remove_version_if(ip_v, &) tables[ip_v].remove_if(&) end |
#route?(addr) ⇒ Boolean
Check if the table routes ‘addr`
147 148 149 |
# File 'lib/osctld/routing/table.rb', line 147 def route?(addr) t(addr).route?(addr) end |
#t(addr) ⇒ Object (protected)
212 213 214 |
# File 'lib/osctld/routing/table.rb', line 212 def t(addr) addr.ipv4? ? tables[4] : tables[6] end |