dffb111262758158252fb98cc9c14b46e8ec37ff
[smo/teiv.git] /
1 module ietf-inet-types {
2
3   namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types";
4   prefix "inet";
5
6   organization
7    "IETF Network Modeling (NETMOD) Working Group";
8
9   contact
10    "WG Web:   <https://datatracker.ietf.org/wg/netmod/>
11     WG List:  <mailto:netmod@ietf.org>
12
13     Editor:   Juergen Schoenwaelder
14               <mailto:j.schoenwaelder@jacobs-university.de>";
15
16   description
17    "This module contains a collection of generally useful derived
18     YANG data types for Internet addresses and related things.
19
20     The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL
21     NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'NOT RECOMMENDED',
22     'MAY', and 'OPTIONAL' in this document are to be interpreted as
23     described in BCP 14 (RFC 2119) (RFC 8174) when, and only when,
24     they appear in all capitals, as shown here.
25
26     Copyright (c) 2019 IETF Trust and the persons identified as
27     authors of the code.  All rights reserved.
28
29     Redistribution and use in source and binary forms, with or
30     without modification, is permitted pursuant to, and subject
31     to the license terms contained in, the Simplified BSD License
32     set forth in Section 4.c of the IETF Trust's Legal Provisions
33     Relating to IETF Documents
34     (http://trustee.ietf.org/license-info).
35
36     This version of this YANG module is part of RFC XXXX;
37     see the RFC itself for full legal notices.";
38   revision 2019-11-04 {
39     description
40      "This revision adds the following new data types:
41       - ip-address-and-prefix
42       - ipv4-address-and-prefix
43       - ipv6-address-and-prefix
44       - email-address";
45     reference
46      "RFC XXXX: Common YANG Data Types";
47   }
48
49   revision 2013-07-15 {
50     description
51      "This revision adds the following new data types:
52       - ip-address-no-zone
53       - ipv4-address-no-zone
54       - ipv6-address-no-zone";
55     reference
56      "RFC 6991: Common YANG Data Types";
57   }
58
59   revision 2010-09-24 {
60     description
61      "Initial revision.";
62     reference
63      "RFC 6021: Common YANG Data Types";
64   }
65
66   /*** collection of types related to protocol fields ***/
67
68   typedef ip-version {
69     type enumeration {
70       enum unknown {
71         value "0";
72         description
73          "An unknown or unspecified version of the Internet
74           protocol.";
75       }
76       enum ipv4 {
77         value "1";
78         description
79          "The IPv4 protocol as defined in RFC 791.";
80       }
81       enum ipv6 {
82         value "2";
83         description
84          "The IPv6 protocol as defined in RFC 2460.";
85       }
86     }
87     description
88      "This value represents the version of the IP protocol.
89
90       In the value set and its semantics, this type is equivalent
91       to the InetVersion textual convention of the SMIv2.";
92     reference
93      "RFC  791: Internet Protocol
94       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
95       RFC 4001: Textual Conventions for Internet Network Addresses";
96   }
97
98   typedef dscp {
99     type uint8 {
100       range "0..63";
101     }
102     description
103      "The dscp type represents a Differentiated Services Code Point
104       that may be used for marking packets in a traffic stream.
105
106       In the value set and its semantics, this type is equivalent
107       to the Dscp textual convention of the SMIv2.";
108     reference
109      "RFC 3289: Management Information Base for the Differentiated
110                 Services Architecture
111       RFC 2474: Definition of the Differentiated Services Field
112                 (DS Field) in the IPv4 and IPv6 Headers
113       RFC 2780: IANA Allocation Guidelines For Values In
114                 the Internet Protocol and Related Headers";
115   }
116
117   typedef ipv6-flow-label {
118     type uint32 {
119       range "0..1048575";
120     }
121     description
122      "The ipv6-flow-label type represents the flow identifier or
123       Flow Label in an IPv6 packet header that may be used to
124       discriminate traffic flows.
125
126       In the value set and its semantics, this type is equivalent
127       to the IPv6FlowLabel textual convention of the SMIv2.";
128     reference
129      "RFC 3595: Textual Conventions for IPv6 Flow Label
130       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification";
131   }
132
133   typedef port-number {
134     type uint16 {
135       range "0..65535";
136     }
137     description
138      "The port-number type represents a 16-bit port number of an
139       Internet transport-layer protocol such as UDP, TCP, DCCP, or
140       SCTP.  Port numbers are assigned by IANA.  A current list of
141       all assignments is available from <http://www.iana.org/>.
142
143       Note that the port number value zero is reserved by IANA.  In
144       situations where the value zero does not make sense, it can
145       be excluded by subtyping the port-number type.
146
147       In the value set and its semantics, this type is equivalent
148       to the InetPortNumber textual convention of the SMIv2.";
149     reference
150      "RFC  768: User Datagram Protocol
151       RFC  793: Transmission Control Protocol
152       RFC 4960: Stream Control Transmission Protocol
153       RFC 4340: Datagram Congestion Control Protocol (DCCP)
154       RFC 4001: Textual Conventions for Internet Network Addresses";
155   }
156
157   /*** collection of types related to autonomous systems ***/
158
159   typedef as-number {
160     type uint32;
161     description
162      "The as-number type represents autonomous system numbers
163       which identify an Autonomous System (AS).  An AS is a set
164       of routers under a single technical administration, using
165       an interior gateway protocol and common metrics to route
166       packets within the AS, and using an exterior gateway
167       protocol to route packets to other ASes.  IANA maintains
168       the AS number space and has delegated large parts to the
169       regional registries.
170
171       Autonomous system numbers were originally limited to 16
172       bits.  BGP extensions have enlarged the autonomous system
173       number space to 32 bits.  This type therefore uses an uint32
174       base type without a range restriction in order to support
175       a larger autonomous system number space.
176
177       In the value set and its semantics, this type is equivalent
178       to the InetAutonomousSystemNumber textual convention of
179       the SMIv2.";
180     reference
181      "RFC 1930: Guidelines for creation, selection, and registration
182                 of an Autonomous System (AS)
183       RFC 4271: A Border Gateway Protocol 4 (BGP-4)
184       RFC 4001: Textual Conventions for Internet Network Addresses
185       RFC 6793: BGP Support for Four-Octet Autonomous System (AS)
186                 Number Space";
187   }
188
189   /*** collection of types related to IP addresses and hostnames ***/
190
191   typedef ip-address {
192     type union {
193       type inet:ipv4-address;
194       type inet:ipv6-address;
195     }
196     description
197      "The ip-address type represents an IP address and is IP
198       version neutral.  The format of the textual representation
199       implies the IP version.  This type supports scoped addresses
200       by allowing zone identifiers in the address format.";
201     reference
202      "RFC 4007: IPv6 Scoped Address Architecture";
203   }
204
205   typedef ipv4-address {
206     type string {
207       pattern
208         '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
209       +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
210       + '(%[\p{N}\p{L}]+)?';
211     }
212     description
213       "The ipv4-address type represents an IPv4 address in
214        dotted-quad notation.  The IPv4 address may include a zone
215        index, separated by a % sign.
216
217        The zone index is used to disambiguate identical address
218        values.  For link-local addresses, the zone index will
219        typically be the interface index number or the name of an
220        interface.  If the zone index is not present, the default
221        zone of the device will be used.
222
223        The canonical format for the zone index is the numerical
224        format";
225   }
226
227   typedef ipv6-address {
228     type string {
229       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
230             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
231             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
232             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
233             + '(%[\p{N}\p{L}]+)?';
234       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
235             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
236             + '(%.+)?';
237     }
238     description
239      "The ipv6-address type represents an IPv6 address in full,
240       mixed, shortened, and shortened-mixed notation.  The IPv6
241       address may include a zone index, separated by a % sign.
242
243       The zone index is used to disambiguate identical address
244       values.  For link-local addresses, the zone index will
245       typically be the interface index number or the name of an
246       interface.  If the zone index is not present, the default
247       zone of the device will be used.
248
249       The canonical format of IPv6 addresses uses the textual
250       representation defined in Section 4 of RFC 5952.  The
251       canonical format for the zone index is the numerical
252       format as described in Section 11.2 of RFC 4007.";
253     reference
254      "RFC 4291: IP Version 6 Addressing Architecture
255       RFC 4007: IPv6 Scoped Address Architecture
256       RFC 5952: A Recommendation for IPv6 Address Text
257                 Representation";
258   }
259
260   typedef ip-address-no-zone {
261     type union {
262       type inet:ipv4-address-no-zone;
263       type inet:ipv6-address-no-zone;
264     }
265     description
266      "The ip-address-no-zone type represents an IP address and is
267       IP version neutral.  The format of the textual representation
268       implies the IP version.  This type does not support scoped
269       addresses since it does not allow zone identifiers in the
270       address format.";
271     reference
272      "RFC 4007: IPv6 Scoped Address Architecture";
273   }
274
275   typedef ipv4-address-no-zone {
276     type inet:ipv4-address {
277       pattern '[0-9\.]*';
278     }
279     description
280       "An IPv4 address without a zone index.  This type, derived from
281        ipv4-address, may be used in situations where the zone is known
282        from the context and hence no zone index is needed.";
283   }
284
285   typedef ipv6-address-no-zone {
286     type inet:ipv6-address {
287       pattern '[0-9a-fA-F:\.]*';
288     }
289     description
290       "An IPv6 address without a zone index.  This type, derived from
291        ipv6-address, may be used in situations where the zone is known
292        from the context and hence no zone index is needed.";
293     reference
294      "RFC 4291: IP Version 6 Addressing Architecture
295       RFC 4007: IPv6 Scoped Address Architecture
296       RFC 5952: A Recommendation for IPv6 Address Text
297                 Representation";
298   }
299
300   typedef ip-prefix {
301     type union {
302       type inet:ipv4-prefix;
303       type inet:ipv6-prefix;
304     }
305     description
306      "The ip-prefix type represents an IP prefix and is IP
307       version neutral.  The format of the textual representations
308       implies the IP version.";
309   }
310
311   typedef ipv4-prefix {
312     type string {
313       pattern
314          '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
315        +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
316        + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
317     }
318     description
319      "The ipv4-prefix type represents an IPv4 prefix.
320       The prefix length is given by the number following the
321       slash character and must be less than or equal to 32.
322
323       A prefix length value of n corresponds to an IP address
324       mask that has n contiguous 1-bits from the most
325       significant bit (MSB) and all other bits set to 0.
326       The canonical format of an IPv4 prefix has all bits of
327       the IPv4 address set to zero that are not part of the
328       IPv4 prefix.
329
330       The definition of ipv4-prefix does not require that bits,
331       which are not part of the prefix, are set to zero. However,
332       implementations have to return values in canonical format,
333       which requires non-prefix bits to be set to zero. This means
334       that 192.0.2.1/24 must be accepted as a valid value but it
335       will be converted into the canonical format 192.0.2.0/24.";
336   }
337
338   typedef ipv6-prefix {
339     type string {
340       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
341             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
342             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
343             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
344             + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
345       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
346             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
347             + '(/.+)';
348     }
349     description
350      "The ipv6-prefix type represents an IPv6 prefix.
351       The prefix length is given by the number following the
352       slash character and must be less than or equal to 128.
353
354       A prefix length value of n corresponds to an IP address
355       mask that has n contiguous 1-bits from the most
356       significant bit (MSB) and all other bits set to 0.
357
358       The canonical format of an IPv6 prefix has all bits of
359       the IPv6 address set to zero that are not part of the
360       IPv6 prefix.  Furthermore, the IPv6 address is represented
361       as defined in Section 4 of RFC 5952.
362
363       The definition of ipv6-prefix does not require that bits,
364       which are not part of the prefix, are set to zero. However,
365       implementations have to return values in canonical format,
366       which requires non-prefix bits to be set to zero. This means
367       that 2001:db8::1/64 must be accepted as a valid value but it
368       will be converted into the canonical format 2001:db8::/64.";
369     reference
370      "RFC 5952: A Recommendation for IPv6 Address Text
371                 Representation";
372   }
373
374   typedef ip-address-and-prefix {
375     type union {
376       type inet:ipv4-address-and-prefix;
377       type inet:ipv6-address-and-prefix;
378     }
379     description
380      "The ip-address-and-prefix type represents an IP address and
381       prefix and is IP version neutral.  The format of the textual
382       representations implies the IP version.";
383   }
384
385   typedef ipv4-address-and-prefix {
386     type string {
387       pattern
388          '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
389        +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
390        + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
391     }
392     description
393      "The ipv4-address-and-prefix type represents an IPv4
394       address and an associated ipv4 prefix.
395       The prefix length is given by the number following the
396       slash character and must be less than or equal to 32.
397
398       A prefix length value of n corresponds to an IP address
399       mask that has n contiguous 1-bits from the most
400       significant bit (MSB) and all other bits set to 0.";
401   }
402
403   typedef ipv6-address-and-prefix {
404     type string {
405       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
406             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
407             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
408             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
409             + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
410       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
411             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
412             + '(/.+)';
413     }
414     description
415      "The ipv6-address-and-prefix type represents an IPv6
416       address and an associated ipv4 prefix.
417       The prefix length is given by the number following the
418       slash character and must be less than or equal to 128.
419
420       A prefix length value of n corresponds to an IP address
421       mask that has n contiguous 1-bits from the most
422       significant bit (MSB) and all other bits set to 0.
423
424       The canonical format requires that the IPv6 address is
425       represented as defined in Section 4 of RFC 5952.";
426     reference
427      "RFC 5952: A Recommendation for IPv6 Address Text
428                 Representation";
429   }
430
431   /*** collection of domain name and URI types ***/
432
433   typedef domain-name {
434     type string {
435       length "1..253";
436       pattern
437         '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*'
438       + '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)'
439       + '|\.';
440     }
441     description
442      "The domain-name type represents a DNS domain name.  The
443       name SHOULD be fully qualified whenever possible. This
444       type does not support wildcards (see RFC 4592) or
445       classless in-addr.arpa delegations (see RFC 2317).
446
447       Internet domain names are only loosely specified.  Section
448       3.5 of RFC 1034 recommends a syntax (modified in Section
449       2.1 of RFC 1123).  The pattern above is intended to allow
450       for current practice in domain name use, and some possible
451       future expansion.  Note that Internet host names have a
452       stricter syntax (described in RFC 952) than the DNS
453       recommendations in RFCs 1034 and 1123, and that systems
454       that want to store host names in schema node instances
455       using the domain-name type are recommended to adhere to
456       this stricter standard to ensure interoperability.
457
458       The encoding of DNS names in the DNS protocol is limited
459       to 255 characters.  Since the encoding consists of labels
460       prefixed by a length bytes and there is a trailing NULL
461       byte, only 253 characters can appear in the textual dotted
462       notation.
463
464       The description clause of schema nodes using the domain-name
465       type MUST describe when and how these names are resolved to
466       IP addresses.  Note that the resolution of a domain-name value
467       may require to query multiple DNS records (e.g., A for IPv4
468       and AAAA for IPv6).  The order of the resolution process and
469       which DNS record takes precedence can either be defined
470       explicitly or may depend on the configuration of the
471       resolver.
472
473       Domain-name values use the US-ASCII encoding.  Their canonical
474       format uses lowercase US-ASCII characters.  Internationalized
475       domain names MUST be A-labels as per RFC 5890.";
476     reference
477      "RFC  952: DoD Internet Host Table Specification
478       RFC 1034: Domain Names - Concepts and Facilities
479       RFC 1123: Requirements for Internet Hosts -- Application
480                 and Support
481       RFC 2317: Classless IN-ADDR.ARPA delegation
482       RFC 2782: A DNS RR for specifying the location of services
483                 (DNS SRV)
484       RFC 4592: The Role of Wildcards in the Domain Name System
485       RFC 5890: Internationalized Domain Names in Applications
486                 (IDNA): Definitions and Document Framework";
487   }
488
489   typedef host {
490     type union {
491       type inet:ip-address;
492       type inet:domain-name;
493     }
494     description
495      "The host type represents either an IP address or a DNS
496       domain name.";
497   }
498
499   /*
500    * DISCUSS:
501    * - Lada suggested to replace the inet:domain-name usage in
502    *   the union with a new host-name definition that follows
503    *   the NR-LDH definition in RFC 5890.
504    */
505
506   typedef uri {
507     type string;
508     description
509      "The uri type represents a Uniform Resource Identifier
510       (URI) as defined by STD 66.
511
512       Objects using the uri type MUST be in US-ASCII encoding,
513       and MUST be normalized as described by RFC 3986 Sections
514       6.2.1, 6.2.2.1, and 6.2.2.2.  All unnecessary
515       percent-encoding is removed, and all case-insensitive
516       characters are set to lowercase except for hexadecimal
517       digits, which are normalized to uppercase as described in
518       Section 6.2.2.1.
519
520       The purpose of this normalization is to help provide
521       unique URIs.  Note that this normalization is not
522       sufficient to provide uniqueness.  Two URIs that are
523       textually distinct after this normalization may still be
524       equivalent.
525
526       Objects using the uri type may restrict the schemes that
527       they permit.  For example, 'data:' and 'urn:' schemes
528       might not be appropriate.
529
530       A zero-length URI is not a valid URI.  This can be used to
531       express 'URI absent' where required.
532
533       In the value set and its semantics, this type is equivalent
534       to the Uri SMIv2 textual convention defined in RFC 5017.";
535     reference
536      "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
537       RFC 3305: Report from the Joint W3C/IETF URI Planning Interest
538                 Group: Uniform Resource Identifiers (URIs), URLs,
539                 and Uniform Resource Names (URNs): Clarifications
540                 and Recommendations
541       RFC 5017: MIB Textual Conventions for Uniform Resource
542                 Identifiers (URIs)";
543   }
544
545   typedef email-address {
546     type string {
547       // dot-atom-text "@" ...
548       pattern '[a-zA-Z0-9!#$%&'+"'"+'*+/=?^_`{|}~-]+'
549             + '(\.[a-zA-Z0-9!#$%&'+"'"+'*+/=?^_`{|}~-]+)*'
550             + '@'
551             + '[a-zA-Z0-9!#$%&'+"'"+'*+/=?^_`{|}~-]+'
552             + '(\.[a-zA-Z0-9!#$%&'+"'"+'*+/=?^_`{|}~-]+)*';
553     }
554     description
555       "The email-address type represents an email address as
556        defined as addr-spec in RFC 5322 section 3.4.1.";
557     reference
558       "RFC 5322: Internet Message Format";
559   }
560
561   /*
562    * DISCUSS:
563    * - It was suggested to add email types following RFC 5322
564    *   email-address        (addr-spec, per Section 3.4.1)
565    *   named-email-address  (name-addr, per Section 3.4)
566    * - This sounds useful but the devil is in the details,
567    *   in particular name-addr is a quite complex construct;
568    *   perhaps addr-spec is sufficient, this is also the
569    *   format allowed in mailto: URIs (mailto: seems to use
570    *   only a subset of addr-spec which may be good enough
571    *   here as well).
572    * - Need to define a pattern that has a meaningful trade-off
573    *   between precision and complexity (there are very tight
574    *   pattern that are very long and complex). The current
575    *   pattern does not take care of quoted-string, obs-local-part,
576    *   domain-literal, obs-domain.
577    */
578
579   /*
580    * DISCUSS:
581    * - There was a request to add types for URI fields (scheme,
582    *   authority, path, query, fragment) but it is not clear how
583    *   commonly useful these types are, the WG was pretty silent
584    *   about this proposal. On the technical side, it is unclear
585    *   whether data is represented with percent escapes resolved
586    *   or not. (Mahesh's proposal does not spell this out, the
587    *   pattern does not allow the % character, which may be wrong.)
588    */
589 }