Comparing version 1.3.1 to 1.4.0
@@ -23,3 +23,3 @@ /* | ||
* | ||
* Copyright (c) 2016, Joyent, Inc. All rights reserved. | ||
* Copyright 2017, Joyent, Inc. All rights reserved. | ||
* | ||
@@ -97,10 +97,2 @@ * | ||
parser.yy.validateIPv4subnet = function validateIPv4subnet(subnet) { | ||
if (!validators.validateIPv4subnet(subnet)) { | ||
throw new validators.InvalidParamError('rule', | ||
'Subnet "%s" is invalid (must be in CIDR format)', subnet); | ||
} | ||
}; | ||
parser.yy.validateIPv6address = function validateIPv6address(ip) { | ||
@@ -114,7 +106,4 @@ if (!mod_net.isIPv6(ip)) { | ||
parser.yy.validateIPv6subnet = function validateIPv6subnet(subnet) { | ||
if (!validators.validateIPv6subnet(subnet)) { | ||
throw new validators.InvalidParamError('rule', | ||
'Subnet "%s" is invalid (must be in CIDR format)', subnet); | ||
} | ||
parser.yy.validateSubnet = function validateSubnet(input) { | ||
validators.validateSubnet('rule', input, parser.yy.enforceSubnetMask); | ||
}; | ||
@@ -237,2 +226,5 @@ | ||
// Whether we should check if CIDRs have bits set past mask | ||
parser.yy.enforceSubnetMask = !!opts.enforceSubnetMask; | ||
return parser.parse(input); | ||
@@ -239,0 +231,0 @@ } |
@@ -23,3 +23,3 @@ /* | ||
* | ||
* Copyright (c) 2016, Joyent, Inc. All rights reserved. | ||
* Copyright 2017, Joyent, Inc. All rights reserved. | ||
* | ||
@@ -59,3 +59,3 @@ * | ||
break; | ||
case 19: yy.validateIPv4subnet($$[$0-1] + $$[$0]); | ||
case 19: yy.validateSubnet($$[$0-1] + $$[$0]); | ||
this.$ = [ ['subnet', $$[$0-1] + $$[$0]] ]; | ||
@@ -68,3 +68,3 @@ break; | ||
case 21: yy.validateOKVersion(3, 'IPv6'); | ||
yy.validateIPv6subnet($$[$0-1] + $$[$0]); | ||
yy.validateSubnet($$[$0-1] + $$[$0]); | ||
this.$ = [ ['subnet', $$[$0-1] + $$[$0]] ]; | ||
@@ -99,3 +99,4 @@ break; | ||
break; | ||
case 35: this.$ = { 'name': $$[$0-1].toLowerCase(), 'targets': $$[$0] } | ||
case 35: yy.validateOKVersion(3, 'IPv6'); | ||
this.$ = { 'name': $$[$0-1].toLowerCase(), 'targets': $$[$0] }; | ||
break; | ||
@@ -102,0 +103,0 @@ case 36: this.$ = $$[$0-1]; |
@@ -33,2 +33,3 @@ /* | ||
var ipaddr = require('ip6addr'); | ||
var net = require('net'); | ||
@@ -97,20 +98,2 @@ var util = require('util'); | ||
/** | ||
* Returns true if subnet is a valid IPv6 CIDR range | ||
*/ | ||
function validateIPv6subnet(subnet) { | ||
var parts = subnet.split('/'); | ||
var plen = Number(parts[1]); | ||
if (!net.isIPv6(parts[0])) { | ||
return false; | ||
} | ||
if (!plen || (plen < 1) || (plen > 128)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
/** | ||
* Returns true if port is a valid port number | ||
@@ -207,2 +190,31 @@ */ | ||
/** | ||
* Throws an InvalidParamError if the subnet is invalid | ||
*/ | ||
function validateSubnet(name, input, enforceSubnetMask) { | ||
var parts = input.split('/'); | ||
var addr, plen, subnet; | ||
try { | ||
addr = ipaddr.parse(parts[0]); | ||
plen = Number(parts[1]); | ||
} catch (_) { | ||
throw new InvalidParamError(name, | ||
'Subnet "%s" is invalid (bad address component)', input); | ||
} | ||
try { | ||
subnet = ipaddr.createCIDR(addr, plen); | ||
} catch (_) { | ||
throw new InvalidParamError(name, | ||
'Subnet "%s" is invalid (bad prefix length)', input); | ||
} | ||
if (enforceSubnetMask && subnet.address().compare(addr) !== 0) { | ||
throw new InvalidParamError(name, | ||
'Subnet "%s" is invalid (bits set to right of mask)', input); | ||
} | ||
} | ||
/** | ||
* Returns true if uuid is a valid UUID | ||
@@ -221,3 +233,3 @@ */ | ||
validateIPv4subnet: validateIPv4subnet, | ||
validateIPv6subnet: validateIPv6subnet, | ||
validateSubnet: validateSubnet, | ||
validatePort: validatePort, | ||
@@ -224,0 +236,0 @@ validatePortOrAll: validatePortOrAll, |
{ | ||
"name": "fwrule", | ||
"description": "Parser for Joyent firewall rules", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"author": "Joyent (joyent.com)", | ||
@@ -12,2 +12,3 @@ "keywords": [ "smartos", "triton" ], | ||
"dependencies": { | ||
"ip6addr": "0.2.2", | ||
"node-uuid": "1.2.0", | ||
@@ -14,0 +15,0 @@ "extsprintf": "1.0.1", |
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
58194
6
1582
1
70
4
5
+ Addedip6addr@0.2.2
+ Addedassert-plus@1.0.0(transitive)
+ Addedip6addr@0.2.2(transitive)