-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ncm-network: Move route schema into seperate backend templates
- Loading branch information
Showing
3 changed files
with
99 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
ncm-network/src/main/pan/components/network/types/network/route.pan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,3 @@ | ||
declaration template components/network/types/network/route; | ||
|
||
type network_valid_routing_table = string with exists("/system/network/routing_table/" + SELF); | ||
|
||
@documentation{ | ||
Add route (IPv4 of IPv6) | ||
Presence of ':' in any of the values indicates this is IPv6 related. | ||
} | ||
type network_route = { | ||
@{The ADDRESS in ADDRESS/PREFIX via GATEWAY} | ||
"address" ? string with {SELF == 'default' || is_ip(SELF)} | ||
@{The PREFIX in ADDRESS/PREFIX via GATEWAY} | ||
"prefix" ? long | ||
@{The GATEWAY in ADDRESS/PREFIX via GATEWAY} | ||
"gateway" ? type_ip | ||
@{alternative notation for prefix (cannot be combined with prefix)} | ||
"netmask" ? type_ip | ||
@{routing table} | ||
"table" ? network_valid_routing_table | ||
@{pretend that the nexthop is directly attached to this link} | ||
"onlink" ? boolean | ||
@{route add command options to use (cannot be combined with other options)} | ||
"command" ? string with !match(SELF, '[;]') | ||
} with { | ||
if (exists(SELF['command'])) { | ||
network_exclude_backend('nmstate', 'command routes'); | ||
if (length(SELF) != 1) error("Cannot use command and any of the other attributes as route"); | ||
} else { | ||
if (!exists(SELF['address'])) | ||
error("Address is mandatory for route (in absence of command)"); | ||
if (exists(SELF['prefix']) && exists(SELF['netmask'])) | ||
error("Use either prefix or netmask as route"); | ||
}; | ||
|
||
if (exists(SELF['prefix'])) { | ||
pref = SELF['prefix']; | ||
ipv6 = false; | ||
foreach (k; v; SELF) { | ||
if (match(to_string(v), ':')) { | ||
ipv6 = true; | ||
}; | ||
}; | ||
if (ipv6) { | ||
if (!is_ipv6_prefix_length(pref)) { | ||
error("Prefix %s is not a valid IPv6 prefix", pref); | ||
}; | ||
} else { | ||
if (!is_ipv4_prefix_length(pref)) { | ||
error("Prefix %s is not a valid IPv4 prefix", pref); | ||
}; | ||
}; | ||
}; | ||
|
||
true; | ||
}; |