1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* RFC 3513 - Internet Protocol Version 6 (IPv6) Addressing Architecture. |
7
|
|
|
* |
8
|
|
|
* Obsoleted by RFC 4291 |
9
|
|
|
* Obsoletes RFC 2373 |
10
|
|
|
* |
11
|
|
|
* @see https://tools.ietf.org/html/rfc4408 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Vanderlee\Comprehend\Library; |
15
|
|
|
|
16
|
|
|
use Vanderlee\Comprehend\Builder\AbstractRuleset; |
17
|
|
|
use Vanderlee\Comprehend\Parser\Parser; |
18
|
|
|
use Vanderlee\Comprehend\Parser\Terminal\Integer; |
19
|
|
|
|
20
|
|
|
require_once 'functions.php'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* IPv6 address |
24
|
|
|
* Supports formats: |
25
|
|
|
* 1234:0:0:0:0:0:200C:417A |
26
|
|
|
* 1234::200C:417A, |
27
|
|
|
* 1234:0:0:0:0:0:12.34.56.78 |
28
|
|
|
* 1234::12.34.56.78. |
29
|
|
|
* |
30
|
|
|
* @property-read Parser ipv6 IPv6 address with CIDR range |
31
|
|
|
* @property-read Parser ipv6_address IPv6 address without CIDR range |
32
|
|
|
*/ |
33
|
|
|
class Rfc3513 extends AbstractRuleset |
34
|
|
|
{ |
35
|
|
|
protected static $name = 'Rfc4408'; |
36
|
|
|
|
37
|
2 |
|
public function __construct($overwrites = []) |
38
|
|
|
{ |
39
|
|
|
/* |
40
|
|
|
* We'll use RFC3986 for the IPv6 definition for convenience' sake. |
41
|
|
|
* This may not be 100% accurate, but RFC 3513's definition is sloppy at best. |
42
|
|
|
*/ |
43
|
2 |
|
$rfc3986 = new Rfc3986(); |
44
|
|
|
|
45
|
|
|
/* |
46
|
|
|
* Normal rules |
47
|
|
|
*/ |
48
|
|
|
$rules = [ |
49
|
|
|
// 2.3 Text Representation of Address Prefixes |
50
|
2 |
|
'ipv6' => [$this->ipv6_address, '/', $this->prefix_length], |
|
|
|
|
51
|
2 |
|
'ipv6_address' => $rfc3986->IPv6address, |
52
|
2 |
|
'prefix_length' => new Integer(0, 128), |
53
|
|
|
|
54
|
2 |
|
self::ROOT => $this->ipv6, |
55
|
|
|
]; |
56
|
|
|
|
57
|
2 |
|
parent::__construct(array_merge($rules, $overwrites)); |
58
|
2 |
|
} |
59
|
|
|
} |
60
|
|
|
|