From c8b8a34f3dc7e5b108783b1b17a402e518868989 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Mon, 22 Aug 2016 17:21:38 +0900 Subject: BGPSpeaker: Raise exception when validation fails In the validator for the API arguments should raise exception when the validator detects invalid arguments, otherwise the decorator for registering API functions, RegisterWithArgChecks, can pass through the invalid arguments. This patch fixes this problem. Signed-off-by: IWASE Yusuke Signed-off-by: FUJITA Tomonori --- ryu/services/protocols/bgp/api/prefix.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ryu/services/protocols/bgp/api/prefix.py b/ryu/services/protocols/bgp/api/prefix.py index 3340112f..f047b6ae 100644 --- a/ryu/services/protocols/bgp/api/prefix.py +++ b/ryu/services/protocols/bgp/api/prefix.py @@ -64,13 +64,19 @@ class PrefixError(RuntimeConfigError): @validate(name=PREFIX) -def is_valid_prefix(ipv4_prefix): - return validation.is_valid_ipv4_prefix(ipv4_prefix) +def is_valid_prefix(prefix): + if not (validation.is_valid_ipv4_prefix(prefix) + or validation.is_valid_ipv6_prefix(prefix)): + raise ConfigValueError(conf_name=PREFIX, + conf_value=prefix) @validate(name=NEXT_HOP) -def is_valid_next_hop(next_hop_addr): - return validation.is_valid_ipv4(next_hop_addr) +def is_valid_next_hop(next_hop): + if not (validation.is_valid_ipv4(next_hop) + or validation.is_valid_ipv6(next_hop)): + raise ConfigValueError(conf_name=NEXT_HOP, + conf_value=next_hop) @validate(name=EVPN_ROUTE_TYPE) -- cgit v1.2.3