Class: OsCtld::Routing::Route
- Inherits:
-
Object
- Object
- OsCtld::Routing::Route
- Defined in:
- lib/osctld/routing/route.rb
Overview
Represents one route from a routing table
Instance Attribute Summary collapse
- #addr ⇒ IPAddress::IPv4, IPAddress::IPv6 readonly
-
#ip_spec ⇒ Array
readonly
Arguments for ‘ip` that identify the route.
- #ip_version ⇒ Integer readonly
- #via ⇒ IPAddress::IPv4, ... readonly
Class Method Summary collapse
-
.load(cfg) ⇒ Object
Load route from config.
Instance Method Summary collapse
-
#dump ⇒ Object
Dump to config.
-
#export ⇒ Object
Export to clients.
-
#initialize(addr, via: nil) ⇒ Route
constructor
A new instance of Route.
- #route?(addr) ⇒ Boolean
Constructor Details
#initialize(addr, via: nil) ⇒ Route
Returns a new instance of Route.
31 32 33 34 35 36 37 |
# File 'lib/osctld/routing/route.rb', line 31 def initialize(addr, via: nil) @addr = addr @via = via @ip_version = addr.ipv4? ? 4 : 6 @ip_spec = [addr.to_string] @ip_spec.push('via', via.to_s, 'onlink') if via end |
Instance Attribute Details
#addr ⇒ IPAddress::IPv4, IPAddress::IPv6 (readonly)
19 20 21 |
# File 'lib/osctld/routing/route.rb', line 19 def addr @addr end |
#ip_spec ⇒ Array (readonly)
Arguments for ‘ip` that identify the route
29 30 31 |
# File 'lib/osctld/routing/route.rb', line 29 def ip_spec @ip_spec end |
#ip_version ⇒ Integer (readonly)
25 26 27 |
# File 'lib/osctld/routing/route.rb', line 25 def ip_version @ip_version end |
#via ⇒ IPAddress::IPv4, ... (readonly)
22 23 24 |
# File 'lib/osctld/routing/route.rb', line 22 def via @via end |
Class Method Details
.load(cfg) ⇒ Object
Load route from config
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/osctld/routing/route.rb', line 7 def self.load(cfg) if cfg.is_a?(Hash) new( IPAddress.parse(cfg['address']), via: cfg['via'] && IPAddress.parse(cfg['via']) ) else new(IPAddress.parse(cfg)) end end |
Instance Method Details
#dump ⇒ Object
Dump to config
45 46 47 48 49 50 51 |
# File 'lib/osctld/routing/route.rb', line 45 def dump if via { 'address' => addr.to_string, 'via' => via.to_s } else addr.to_string end end |
#export ⇒ Object
Export to clients
54 55 56 |
# File 'lib/osctld/routing/route.rb', line 54 def export { address: addr, via: } end |
#route?(addr) ⇒ Boolean
40 41 42 |
# File 'lib/osctld/routing/route.rb', line 40 def route?(addr) @addr == addr || (@addr.network? && @addr.include?(addr)) end |