Commit 4ef37e81 authored by Mikio Hara's avatar Mikio Hara Committed by Brad Fitzpatrick

internal/iana: follow the move of TOS/TC registry

The registry for IPv4 TOS Byte and IPv6 Traffic Class Octet has been
moved to DSCP registry.

Also uses HTTPS for fetching any IANA resource.

Change-Id: I6a54defc2be4415fac084fcf9dfe0a481d72df33
Reviewed-on: https://go-review.googlesource.com/115220
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 8d282c4e
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA). // Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).
package iana // import "golang.org/x/net/internal/iana" package iana // import "golang.org/x/net/internal/iana"
// Differentiated Services Field Codepoints (DSCP), Updated: 2017-05-12 // Differentiated Services Field Codepoints (DSCP), Updated: 2018-05-04
const ( const (
DiffServCS0 = 0x0 // CS0 DiffServCS0 = 0x00 // CS0
DiffServCS1 = 0x20 // CS1 DiffServCS1 = 0x20 // CS1
DiffServCS2 = 0x40 // CS2 DiffServCS2 = 0x40 // CS2
DiffServCS3 = 0x60 // CS3 DiffServCS3 = 0x60 // CS3
...@@ -28,14 +28,10 @@ const ( ...@@ -28,14 +28,10 @@ const (
DiffServAF43 = 0x98 // AF43 DiffServAF43 = 0x98 // AF43
DiffServEF = 0xb8 // EF DiffServEF = 0xb8 // EF
DiffServVOICEADMIT = 0xb0 // VOICE-ADMIT DiffServVOICEADMIT = 0xb0 // VOICE-ADMIT
) NotECNTransport = 0x00 // Not-ECT (Not ECN-Capable Transport)
ECNTransport1 = 0x01 // ECT(1) (ECN-Capable Transport(1))
// IPv4 TOS Byte and IPv6 Traffic Class Octet, Updated: 2001-09-06 ECNTransport0 = 0x02 // ECT(0) (ECN-Capable Transport(0))
const ( CongestionExperienced = 0x03 // CE (Congestion Experienced)
NotECNTransport = 0x0 // Not-ECT (Not ECN-Capable Transport)
ECNTransport1 = 0x1 // ECT(1) (ECN-Capable Transport(1))
ECNTransport0 = 0x2 // ECT(0) (ECN-Capable Transport(0))
CongestionExperienced = 0x3 // CE (Congestion Experienced)
) )
// Protocol Numbers, Updated: 2017-10-13 // Protocol Numbers, Updated: 2017-10-13
...@@ -179,7 +175,7 @@ const ( ...@@ -179,7 +175,7 @@ const (
ProtocolReserved = 255 // Reserved ProtocolReserved = 255 // Reserved
) )
// Address Family Numbers, Updated: 2016-10-25 // Address Family Numbers, Updated: 2018-04-02
const ( const (
AddrFamilyIPv4 = 1 // IP (IP version 4) AddrFamilyIPv4 = 1 // IP (IP version 4)
AddrFamilyIPv6 = 2 // IP6 (IP version 6) AddrFamilyIPv6 = 2 // IP6 (IP version 6)
......
...@@ -31,16 +31,12 @@ var registries = []struct { ...@@ -31,16 +31,12 @@ var registries = []struct {
"https://www.iana.org/assignments/dscp-registry/dscp-registry.xml", "https://www.iana.org/assignments/dscp-registry/dscp-registry.xml",
parseDSCPRegistry, parseDSCPRegistry,
}, },
{
"https://www.iana.org/assignments/ipv4-tos-byte/ipv4-tos-byte.xml",
parseTOSTCByte,
},
{ {
"https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml", "https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml",
parseProtocolNumbers, parseProtocolNumbers,
}, },
{ {
"http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml", "https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml",
parseAddrFamilyNumbers, parseAddrFamilyNumbers,
}, },
} }
...@@ -85,13 +81,16 @@ func parseDSCPRegistry(w io.Writer, r io.Reader) error { ...@@ -85,13 +81,16 @@ func parseDSCPRegistry(w io.Writer, r io.Reader) error {
if err := dec.Decode(&dr); err != nil { if err := dec.Decode(&dr); err != nil {
return err return err
} }
drs := dr.escape()
fmt.Fprintf(w, "// %s, Updated: %s\n", dr.Title, dr.Updated) fmt.Fprintf(w, "// %s, Updated: %s\n", dr.Title, dr.Updated)
fmt.Fprintf(w, "const (\n") fmt.Fprintf(w, "const (\n")
for _, dr := range drs { for _, dr := range dr.escapeDSCP() {
fmt.Fprintf(w, "DiffServ%s = %#x", dr.Name, dr.Value) fmt.Fprintf(w, "DiffServ%s = %#02x", dr.Name, dr.Value)
fmt.Fprintf(w, "// %s\n", dr.OrigName) fmt.Fprintf(w, "// %s\n", dr.OrigName)
} }
for _, er := range dr.escapeECN() {
fmt.Fprintf(w, "%s = %#02x", er.Descr, er.Value)
fmt.Fprintf(w, "// %s\n", er.OrigDescr)
}
fmt.Fprintf(w, ")\n") fmt.Fprintf(w, ")\n")
return nil return nil
} }
...@@ -101,15 +100,20 @@ type dscpRegistry struct { ...@@ -101,15 +100,20 @@ type dscpRegistry struct {
Title string `xml:"title"` Title string `xml:"title"`
Updated string `xml:"updated"` Updated string `xml:"updated"`
Note string `xml:"note"` Note string `xml:"note"`
RegTitle string `xml:"registry>title"` Registries []struct {
PoolRecords []struct { Title string `xml:"title"`
Name string `xml:"name"` Registries []struct {
Space string `xml:"space"` Title string `xml:"title"`
} `xml:"registry>record"`
Records []struct { Records []struct {
Name string `xml:"name"` Name string `xml:"name"`
Space string `xml:"space"` Space string `xml:"space"`
} `xml:"registry>registry>record"` } `xml:"record"`
} `xml:"registry"`
Records []struct {
Value string `xml:"value"`
Descr string `xml:"description"`
} `xml:"record"`
} `xml:"registry"`
} }
type canonDSCPRecord struct { type canonDSCPRecord struct {
...@@ -118,8 +122,17 @@ type canonDSCPRecord struct { ...@@ -118,8 +122,17 @@ type canonDSCPRecord struct {
Value int Value int
} }
func (drr *dscpRegistry) escape() []canonDSCPRecord { func (drr *dscpRegistry) escapeDSCP() []canonDSCPRecord {
drs := make([]canonDSCPRecord, len(drr.Records)) var drs []canonDSCPRecord
for _, preg := range drr.Registries {
if !strings.Contains(preg.Title, "Differentiated Services Field Codepoints") {
continue
}
for _, reg := range preg.Registries {
if !strings.Contains(reg.Title, "Pool 1 Codepoints") {
continue
}
drs = make([]canonDSCPRecord, len(reg.Records))
sr := strings.NewReplacer( sr := strings.NewReplacer(
"+", "", "+", "",
"-", "", "-", "",
...@@ -127,7 +140,7 @@ func (drr *dscpRegistry) escape() []canonDSCPRecord { ...@@ -127,7 +140,7 @@ func (drr *dscpRegistry) escape() []canonDSCPRecord {
".", "", ".", "",
" ", "", " ", "",
) )
for i, dr := range drr.Records { for i, dr := range reg.Records {
s := strings.TrimSpace(dr.Name) s := strings.TrimSpace(dr.Name)
drs[i].OrigName = s drs[i].OrigName = s
drs[i].Name = sr.Replace(s) drs[i].Name = sr.Replace(s)
...@@ -137,48 +150,30 @@ func (drr *dscpRegistry) escape() []canonDSCPRecord { ...@@ -137,48 +150,30 @@ func (drr *dscpRegistry) escape() []canonDSCPRecord {
} }
drs[i].Value = int(n) << 2 drs[i].Value = int(n) << 2
} }
return drs
}
func parseTOSTCByte(w io.Writer, r io.Reader) error {
dec := xml.NewDecoder(r)
var ttb tosTCByte
if err := dec.Decode(&ttb); err != nil {
return err
} }
trs := ttb.escape()
fmt.Fprintf(w, "// %s, Updated: %s\n", ttb.Title, ttb.Updated)
fmt.Fprintf(w, "const (\n")
for _, tr := range trs {
fmt.Fprintf(w, "%s = %#x", tr.Keyword, tr.Value)
fmt.Fprintf(w, "// %s\n", tr.OrigKeyword)
} }
fmt.Fprintf(w, ")\n") return drs
return nil
}
type tosTCByte struct {
XMLName xml.Name `xml:"registry"`
Title string `xml:"title"`
Updated string `xml:"updated"`
Note string `xml:"note"`
RegTitle string `xml:"registry>title"`
Records []struct {
Binary string `xml:"binary"`
Keyword string `xml:"keyword"`
} `xml:"registry>record"`
} }
type canonTOSTCByteRecord struct { type canonECNRecord struct {
OrigKeyword string OrigDescr string
Keyword string Descr string
Value int Value int
} }
func (ttb *tosTCByte) escape() []canonTOSTCByteRecord { func (drr *dscpRegistry) escapeECN() []canonECNRecord {
trs := make([]canonTOSTCByteRecord, len(ttb.Records)) var ers []canonECNRecord
for _, reg := range drr.Registries {
if !strings.Contains(reg.Title, "ECN Field") {
continue
}
ers = make([]canonECNRecord, len(reg.Records))
sr := strings.NewReplacer( sr := strings.NewReplacer(
"Capable", "", "Capable", "",
"Not-ECT", "",
"ECT(1)", "",
"ECT(0)", "",
"CE", "",
"(", "", "(", "",
")", "", ")", "",
"+", "", "+", "",
...@@ -187,23 +182,24 @@ func (ttb *tosTCByte) escape() []canonTOSTCByteRecord { ...@@ -187,23 +182,24 @@ func (ttb *tosTCByte) escape() []canonTOSTCByteRecord {
".", "", ".", "",
" ", "", " ", "",
) )
for i, tr := range ttb.Records { for i, er := range reg.Records {
s := strings.TrimSpace(tr.Keyword) s := strings.TrimSpace(er.Descr)
trs[i].OrigKeyword = s ers[i].OrigDescr = s
ss := strings.Split(s, " ") ss := strings.Split(s, " ")
if len(ss) > 1 { if len(ss) > 1 {
trs[i].Keyword = strings.Join(ss[1:], " ") ers[i].Descr = strings.Join(ss[1:], " ")
} else { } else {
trs[i].Keyword = ss[0] ers[i].Descr = ss[0]
} }
trs[i].Keyword = sr.Replace(trs[i].Keyword) ers[i].Descr = sr.Replace(er.Descr)
n, err := strconv.ParseUint(tr.Binary, 2, 8) n, err := strconv.ParseUint(er.Value, 2, 8)
if err != nil { if err != nil {
continue continue
} }
trs[i].Value = int(n) ers[i].Value = int(n)
}
} }
return trs return ers
} }
func parseProtocolNumbers(w io.Writer, r io.Reader) error { func parseProtocolNumbers(w io.Writer, r io.Reader) error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment