-
Notifications
You must be signed in to change notification settings - Fork 1
/
address-family.go
199 lines (179 loc) · 9.68 KB
/
address-family.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
© 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package iana
import (
"strconv"
"github.com/haraldrudell/parl/ints"
"github.com/haraldrudell/parl/perrors"
"github.com/haraldrudell/parl/sets"
"golang.org/x/exp/constraints"
)
// AddressFamily contains iana Address Family Numbers such as IP versions 4 and 6 for the Internet.
// - AddressFamily is ordered
// - AddressFamily implements fmt.Stringer
// - AddressFamily has methods IsValid Description Int Uint16
//
// IANA [address-family-numbers]
//
// [address-family-numbers]: https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml
type AddressFamily uint16
const (
AFreserved0 AddressFamily = iota // 0 Reserved
AFip // IP (IP version 4)
AFip6 // IP6 (IP version 6)
AFnsap // NSAP NSAP
AFhdlc // HDLC HDLC (8-bit multidrop)
AFbbn // BBN BBN 1822
AF802 // 802 (includes all 802 media plus Ethernet
AFe163 // E.163 E.163
AFe164 // E.164 E.164 (SMDS, Frame Relay, ATM)
AFf69 // F.69 F.69 (Telex)
AFx121 // X.121 X.121 (X.25, Frame Relay)
AFips // IPX IPX
AFappletalk // Appletalk Appletalk
AFdecnet // DECNET Decnet IV
AFbv // BV Banyan Vines
AFe164n // E.164N E.164 with NSAP format subaddress
AFdns // DNS DNS (Domain Name System)
AFdn // DN Distinguished Name
AFas // AS AS Number
AFxtpip // XTPIP XTP over IP version 4
AFxtpip6 // XTPIP6 XTP over IP version 6
AFxtp // XTP XTP native mode XTP
AFwwp // WWP Fibre Channel World-Wide Port Name
AFwwn // WWN Fibre Channel World-Wide Node Name
AFgwid // GWID GWID
AFafi // AFI AFI for L2VPN information [RFC4761][RFC6074]
AFmplss // MPLSS MPLS-TP Section Endpoint Identifier [RFC7212]
AFmplse // MPLSE MPLS-TP LSP Endpoint Identifier [RFC7212]
AFmplsp // MPLSP MPLS-TP Pseudowire Endpoint Identifier [RFC7212]
AFmtip // MTIP MT IP: Multi-Topology IP version 4 [RFC7307]
AFmtip6 // MTIP6 MT IPv6: Multi-Topology IP version 6 [RFC7307]
AFbgp // BGP BGP SFC [RFC9015]
AFeigrp AddressFamily = 16352 + iota // EIGRP EIGRP Common Service Family
AFeigrp4 // EIGRP4 EIGRP IPv4 Service Family
AFeigrp6 // EIGRP6 EIGRP IPv6 Service Family
AFlisp // LISP LISP Canonical Address Format (LCAF)
AFbgpls // BGP-LS BGP-LS [RFC7752]
AFmac48 // MAC48 48-bit MAC [RFC7042] 2013-05-06
AFmac64 // MAC64 64-bit MAC [RFC7042] 2013-05-06
AFoui // OUI OUI [RFC7961]
AFmac24 // MAC/24 MAC/24 [RFC7961]
AFmac40 // MAC/40 MAC/40 [RFC7961]
AFipv664 // IPv6/64 IPv6/64 [RFC7961]
AFrb // RBridge RBridge Port ID [RFC7961]
AFtrill // TRILL TRILL Nickname [RFC7455]
AFuuid // UUID Universally Unique Identifier (UUID)
AFafir // AFI Routing Policy AFI [draft-ietf-idr-rpd-02]
AFmplsns // MPLSNS MPLS Namespaces
AFreserved AddressFamily = 65535 // 65535 65535 Reserved
)
// NewAddressFamily returns iana.AddressFamily for any integer value.
// - values larger that 255 produce error testable with errors.Is(err, ints.ErrTooLarge)
// - addressFamily may be invalid, ie. not an iana-assigned value, check with addressFamily.IsValid
// - or use NewValidAddressFamily
func NewAddressFamily[T constraints.Integer](integer T) (addressFamily AddressFamily, err error) {
// convert to uint16
var u16 uint16
if u16, err = ints.Unsigned[uint16](integer, perrors.PackFunc()); err != nil {
return
}
// convert to iana.AddressFamily, allow for invalid values
addressFamily = AddressFamily(u16)
return
}
// NewValidAddressFamily returns iana.AddressFamily for any integer value.
// - values larger that 65535 produce error testable with errors.Is(err, ints.ErrTooLarge)
// - addressFamily is valid
func NewValidAddressFamily[T constraints.Integer](integer T) (addressFamily AddressFamily, err error) {
if addressFamily, err = NewAddressFamily(integer); err != nil {
return
}
if !addressFamily.IsValid() {
err = perrors.ErrorfPF("invalid address family value: %d 0x%[1]x", addressFamily)
return
}
return
}
// NewAddressFamily1 returns iana.NewAddressFamily1 for any integer value.
// - if value is too large, panic
// - addressFamily may be invalid, ie. not an iana-assigned value, check with addressFamily.IsValid
// - or use NewValidAddressFamily
func NewAddressFamily1[T constraints.Integer](integer T) (addressFamily AddressFamily) {
var err error
if addressFamily, err = NewAddressFamily(integer); err != nil {
panic(err)
}
return
}
func (af AddressFamily) String() (s string) {
return addressFamilySet.StringT(af)
}
func (af AddressFamily) StringInt() (s string) {
return addressFamilySet.StringT(af) + "-0x" + strconv.FormatUint(uint64(af), 16)
}
func (af AddressFamily) Int() (addressFamilyInt int) {
return int(af)
}
func (af AddressFamily) Uint16() (addressFamilyInt uint16) {
return uint16(af)
}
func (af AddressFamily) IsValid() (isValid bool) {
return addressFamilySet.IsValid(af)
}
func (af AddressFamily) Description() (full string) {
return addressFamilySet.Description(af)
}
var addressFamilySet = sets.NewSet[AddressFamily]([]sets.SetElementFull[AddressFamily]{
//{ValueV: AFreserved0, Name: "0", Full: "Reserved"},
{ValueV: AFip, Name: "IP", Full: "(IP version 4)"},
{ValueV: AFip6, Name: "IP6", Full: "(IP version 6)"},
{ValueV: AFnsap, Name: "NSAP", Full: "NSAP"},
{ValueV: AFhdlc, Name: "HDLC", Full: "HDLC (8-bit multidrop)"},
{ValueV: AFbbn, Name: "BBN", Full: "BBN 1822"},
{ValueV: AF802, Name: "802", Full: "(includes all 802 media plus Ethernet"},
{ValueV: AFe163, Name: "E.163", Full: "E.163"},
{ValueV: AFe164, Name: "E.164", Full: "E.164 (SMDS, Frame Relay, ATM)"},
{ValueV: AFf69, Name: "F.69", Full: "F.69 (Telex)"},
{ValueV: AFx121, Name: "X.121", Full: "X.121 (X.25, Frame Relay)"},
{ValueV: AFips, Name: "IPX", Full: "IPX"},
{ValueV: AFappletalk, Name: "Appletalk", Full: "Appletalk"},
{ValueV: AFdecnet, Name: "DECNET", Full: "Decnet IV"},
{ValueV: AFbv, Name: "BV", Full: "Banyan Vines"},
{ValueV: AFe164n, Name: "E.164N", Full: "E.164 with NSAP format subaddress"},
{ValueV: AFdns, Name: "DNS", Full: "DNS (Domain Name System)"},
{ValueV: AFdn, Name: "DN", Full: "Distinguished Name"},
{ValueV: AFas, Name: "AS", Full: "AS Number"},
{ValueV: AFxtpip, Name: "XTPIP", Full: "XTP over IP version 4"},
{ValueV: AFxtpip6, Name: "XTPIP6", Full: "XTP over IP version 6"},
{ValueV: AFxtp, Name: "XTP", Full: "XTP native mode XTP"},
{ValueV: AFwwp, Name: "WWP", Full: "Fibre Channel World-Wide Port Name"},
{ValueV: AFwwn, Name: "WWN", Full: "Fibre Channel World-Wide Node Name"},
{ValueV: AFgwid, Name: "GWID", Full: "GWID"},
{ValueV: AFafi, Name: "AFI", Full: "AFI for L2VPN information [RFC4761][RFC6074]"},
{ValueV: AFmplss, Name: "MPLSS", Full: "MPLS-TP Section Endpoint Identifier [RFC7212]"},
{ValueV: AFmplse, Name: "MPLSE", Full: "MPLS-TP LSP Endpoint Identifier [RFC7212]"},
{ValueV: AFmplsp, Name: "MPLSP", Full: "MPLS-TP Pseudowire Endpoint Identifier [RFC7212]"},
{ValueV: AFmtip, Name: "MTIP", Full: "MT IP: Multi-Topology IP version 4 [RFC7307]"},
{ValueV: AFmtip6, Name: "MTIP6", Full: "MT IPv6: Multi-Topology IP version 6 [RFC7307]"},
{ValueV: AFbgp, Name: "BGP", Full: "BGP SFC [RFC9015]"},
{ValueV: AFeigrp, Name: "EIGRP", Full: "EIGRP Common Service Family"},
{ValueV: AFeigrp4, Name: "EIGRP4", Full: "EIGRP IPv4 Service Family"},
{ValueV: AFeigrp6, Name: "EIGRP6", Full: "EIGRP IPv6 Service Family"},
{ValueV: AFlisp, Name: "LISP", Full: "LISP Canonical Address Format (LCAF)"},
{ValueV: AFbgpls, Name: "BGP-LS", Full: "BGP-LS [RFC7752]"},
{ValueV: AFmac48, Name: "MAC48", Full: "48-bit MAC [RFC7042] 2013-05-06"},
{ValueV: AFmac64, Name: "MAC64", Full: "64-bit MAC [RFC7042] 2013-05-06"},
{ValueV: AFoui, Name: "OUI", Full: "OUI [RFC7961]"},
{ValueV: AFmac24, Name: "MAC/24", Full: "MAC/24 [RFC7961]"},
{ValueV: AFmac40, Name: "MAC/40", Full: "MAC/40 [RFC7961]"},
{ValueV: AFipv664, Name: "IPv6/64", Full: "IPv6/64 [RFC7961]"},
{ValueV: AFrb, Name: "RBridge", Full: "RBridge Port ID [RFC7961]"},
{ValueV: AFtrill, Name: "TRILL", Full: "TRILL Nickname [RFC7455]"},
{ValueV: AFuuid, Name: "UUID", Full: "Universally Unique Identifier (UUID)"},
{ValueV: AFafir, Name: "AFI", Full: "Routing Policy AFI [draft-ietf-idr-rpd-02]"},
{ValueV: AFmplsns, Name: "MPLSNS", Full: "MPLS Namespaces"},
//{ValueV: AFreserved, Name: "65535", Full: "65535 Reserved"},
})