summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2018-09-01 21:51:21 +0000
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2021-01-23 09:03:18 +0900
commit4c8ab0d4b5090b5b9ca115bdeb3dd8e1a627f5e2 (patch)
treef688d7e0bd48816b92e70c92830d4c5a16c05310 /pkg
parent89e404be46cfa30fdb994464a1c8e4fd93d3407f (diff)
support UDP destination port sub-TLV
As specified in draft-ietf-idr-tunnel-encaps. Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/packet/bgp/bgp.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go
index 9add140f..263d684a 100644
--- a/pkg/packet/bgp/bgp.go
+++ b/pkg/packet/bgp/bgp.go
@@ -257,6 +257,7 @@ const (
ENCAP_SUBTLV_TYPE_ENCAPSULATION EncapSubTLVType = 1
ENCAP_SUBTLV_TYPE_PROTOCOL EncapSubTLVType = 2
ENCAP_SUBTLV_TYPE_COLOR EncapSubTLVType = 4
+ ENCAP_SUBTLV_TYPE_UDP_DEST_PORT EncapSubTLVType = 8
ENCAP_SUBTLV_TYPE_SRPREFERENCE EncapSubTLVType = 12
ENCAP_SUBTLV_TYPE_SRBINDING_SID EncapSubTLVType = 13
ENCAP_SUBTLV_TYPE_SRENLP EncapSubTLVType = 14
@@ -11596,6 +11597,52 @@ func NewTunnelEncapSubTLVColor(color uint32) *TunnelEncapSubTLVColor {
}
}
+type TunnelEncapSubTLVUDPDestPort struct {
+ TunnelEncapSubTLV
+ UDPDestPort uint16
+}
+
+func (t *TunnelEncapSubTLVUDPDestPort) DecodeFromBytes(data []byte) error {
+ value, err := t.TunnelEncapSubTLV.DecodeFromBytes(data)
+ if err != nil {
+ return err
+ }
+ if t.Length < 2 {
+ return NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, "Not all TunnelEncapSubTLVUDPDestPort bytes available")
+ }
+ t.UDPDestPort = binary.BigEndian.Uint16(value[0:2])
+ return nil
+}
+
+func (t *TunnelEncapSubTLVUDPDestPort) Serialize() ([]byte, error) {
+ buf := make([]byte, 2)
+ binary.BigEndian.PutUint16(buf, t.UDPDestPort)
+ return t.TunnelEncapSubTLV.Serialize(buf)
+}
+
+func (t *TunnelEncapSubTLVUDPDestPort) String() string {
+ return fmt.Sprintf("{UDPDestPort: %d}", t.UDPDestPort)
+}
+
+func (t *TunnelEncapSubTLVUDPDestPort) MarshalJSON() ([]byte, error) {
+ return json.Marshal(struct {
+ Type EncapSubTLVType `json:"type"`
+ UDPDestPort uint16 `json:"port"`
+ }{
+ Type: t.Type,
+ UDPDestPort: t.UDPDestPort,
+ })
+}
+
+func NewTunnelEncapSubTLVUDPDestPort(port uint16) *TunnelEncapSubTLVUDPDestPort {
+ return &TunnelEncapSubTLVUDPDestPort{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: ENCAP_SUBTLV_TYPE_UDP_DEST_PORT,
+ },
+ UDPDestPort: port,
+ }
+}
+
type TunnelEncapTLV struct {
Type TunnelType
Length uint16
@@ -11628,6 +11675,8 @@ func (t *TunnelEncapTLV) DecodeFromBytes(data []byte) error {
subTlv = &TunnelEncapSubTLVProtocol{}
case ENCAP_SUBTLV_TYPE_COLOR:
subTlv = &TunnelEncapSubTLVColor{}
+ case ENCAP_SUBTLV_TYPE_UDP_DEST_PORT:
+ subTlv = &TunnelEncapSubTLVUDPDestPort{}
case ENCAP_SUBTLV_TYPE_SRPREFERENCE:
subTlv = &TunnelEncapSubTLVSRPreference{}
case ENCAP_SUBTLV_TYPE_SRBINDING_SID: