summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp.go20
-rw-r--r--packet/bgpattrtype_string.go28
2 files changed, 39 insertions, 9 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index ddb81814..747957fa 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -983,8 +983,10 @@ const (
BGP_ATTR_FLAG_OPTIONAL = 1 << 7
)
+type BGPAttrType uint8
+
const (
- _ = iota
+ _ BGPAttrType = iota
BGP_ATTR_TYPE_ORIGIN
BGP_ATTR_TYPE_AS_PATH
BGP_ATTR_TYPE_NEXT_HOP
@@ -1084,7 +1086,7 @@ type PathAttributeInterface interface {
type PathAttribute struct {
Flags uint8
- Type uint8
+ Type BGPAttrType
Length uint16
Value []byte
}
@@ -1101,7 +1103,7 @@ func (p *PathAttribute) Len() int {
func (p *PathAttribute) DecodeFromBytes(data []byte) error {
p.Flags = data[0]
- p.Type = data[1]
+ p.Type = BGPAttrType(data[1])
if p.Flags&BGP_ATTR_FLAG_EXTENDED_LENGTH != 0 {
p.Length = binary.BigEndian.Uint16(data[2:4])
@@ -1124,7 +1126,7 @@ func (p *PathAttribute) Serialize() ([]byte, error) {
}
buf := make([]byte, p.Len())
buf[0] = p.Flags
- buf[1] = p.Type
+ buf[1] = uint8(p.Type)
if p.Flags&BGP_ATTR_FLAG_EXTENDED_LENGTH != 0 {
binary.BigEndian.PutUint16(buf[2:4], p.Length)
copy(buf[4:], p.Value)
@@ -1157,7 +1159,7 @@ type AsPathParam struct {
func (a *AsPathParam) Serialize() ([]byte, error) {
buf := make([]byte, 2+len(a.AS)*2)
- buf[0] = a.Type
+ buf[0] = uint8(a.Type)
buf[1] = a.Num
for j, as := range a.AS {
binary.BigEndian.PutUint16(buf[2+j*2:], as)
@@ -1734,13 +1736,13 @@ func (e *OpaqueExtended) Serialize() ([]byte, error) {
}
type UnknownExtended struct {
- Type uint8
+ Type BGPAttrType
Value []byte
}
func (e *UnknownExtended) Serialize() ([]byte, error) {
buf := make([]byte, 8)
- buf[0] = e.Type
+ buf[0] = uint8(e.Type)
copy(buf[1:], e.Value)
return buf, nil
}
@@ -1777,7 +1779,7 @@ func parseExtended(data []byte) ExtendedCommunityInterface {
return e
}
e := &UnknownExtended{}
- e.Type = data[1]
+ e.Type = BGPAttrType(data[1])
e.Value = data[2:8]
return e
}
@@ -1884,7 +1886,7 @@ type PathAttributeUnknown struct {
}
func getPathAttribute(data []byte) PathAttributeInterface {
- switch data[1] {
+ switch BGPAttrType(data[1]) {
case BGP_ATTR_TYPE_ORIGIN:
return &PathAttributeOrigin{}
case BGP_ATTR_TYPE_AS_PATH:
diff --git a/packet/bgpattrtype_string.go b/packet/bgpattrtype_string.go
new file mode 100644
index 00000000..1a2cf1d0
--- /dev/null
+++ b/packet/bgpattrtype_string.go
@@ -0,0 +1,28 @@
+// generated by stringer -type BGPAttrType bgp.go; DO NOT EDIT
+
+package bgp
+
+import "fmt"
+
+const (
+ _BGPAttrType_name_0 = "BGP_ATTR_TYPE_ORIGINBGP_ATTR_TYPE_AS_PATHBGP_ATTR_TYPE_NEXT_HOPBGP_ATTR_TYPE_MULTI_EXIT_DISCBGP_ATTR_TYPE_LOCAL_PREFBGP_ATTR_TYPE_ATOMIC_AGGREGATEBGP_ATTR_TYPE_AGGREGATORBGP_ATTR_TYPE_COMMUNITIESBGP_ATTR_TYPE_ORIGINATOR_IDBGP_ATTR_TYPE_CLUSTER_LIST"
+ _BGPAttrType_name_1 = "BGP_ATTR_TYPE_MP_REACH_NLRIBGP_ATTR_TYPE_MP_UNREACH_NLRIBGP_ATTR_TYPE_EXTENDED_COMMUNITIESBGP_ATTR_TYPE_AS4_PATHBGP_ATTR_TYPE_AS4_AGGREGATOR"
+)
+
+var (
+ _BGPAttrType_index_0 = [...]uint8{0, 20, 41, 63, 92, 116, 146, 170, 195, 222, 248}
+ _BGPAttrType_index_1 = [...]uint8{0, 27, 56, 90, 112, 140}
+)
+
+func (i BGPAttrType) String() string {
+ switch {
+ case 1 <= i && i <= 10:
+ i -= 1
+ return _BGPAttrType_name_0[_BGPAttrType_index_0[i]:_BGPAttrType_index_0[i+1]]
+ case 14 <= i && i <= 18:
+ i -= 14
+ return _BGPAttrType_name_1[_BGPAttrType_index_1[i]:_BGPAttrType_index_1[i+1]]
+ default:
+ return fmt.Sprintf("BGPAttrType(%d)", i)
+ }
+}