diff options
author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-05-24 09:55:03 +0300 |
---|---|---|
committer | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-05-24 09:55:03 +0300 |
commit | 94d720ff40644d09d99829d6a1520075b9f8475a (patch) | |
tree | 4fc816ce7ad55a140e81aec21018e1bd38ce5d9a | |
parent | cbdb752b10847163d9f942853b67cf173b6aa151 (diff) |
Add FQDN capability
It's not kinda RFC (draft), but it's implemented and used in various
other open-source software like FRRouting, Bird, ExaBGP.
It's very handy when dealing with lots of peers.
Exampe between GoBGP and FRRouting:
```
% ./cmd/gobgp/gobgp neighbor 192.168.10.123 | grep -A4 fqdn:
fqdn: advertised and received
Local:
name: donatas-pc, domain:
Remote:
name: exit1-debian-9, domain:
```
```
% vtysh -c 'show bgp neighbors 192.168.10.17 json' | jq .'"192.168.10.17".neighborCapabilities.hostName'
{
"advHostName": "exit1-debian-9",
"advDomainName": "n/a",
"rcvHostName": "donatas-pc",
"rcvDomainName": "n/a"
}
```
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
-rw-r--r-- | api/attribute.pb.go | 1 | ||||
-rw-r--r-- | api/capability.pb.go | 115 | ||||
-rw-r--r-- | api/capability.proto | 9 | ||||
-rw-r--r-- | cmd/gobgp/neighbor.go | 10 | ||||
-rw-r--r-- | internal/pkg/apiutil/capability.go | 13 | ||||
-rw-r--r-- | pkg/packet/bgp/bgp.go | 69 | ||||
-rw-r--r-- | pkg/server/fsm.go | 4 |
7 files changed, 185 insertions, 36 deletions
diff --git a/api/attribute.pb.go b/api/attribute.pb.go index 3113bce6..2adb2f88 100644 --- a/api/attribute.pb.go +++ b/api/attribute.pb.go @@ -136,6 +136,7 @@ It has these top-level messages: LongLivedGracefulRestartCapabilityTuple LongLivedGracefulRestartCapability RouteRefreshCiscoCapability + FQDNCapability UnknownCapability StartBgpRequest StopBgpRequest diff --git a/api/capability.pb.go b/api/capability.pb.go index 957b30b4..7fe4a7cc 100644 --- a/api/capability.pb.go +++ b/api/capability.pb.go @@ -298,6 +298,46 @@ func (m *RouteRefreshCiscoCapability) String() string { return proto. func (*RouteRefreshCiscoCapability) ProtoMessage() {} func (*RouteRefreshCiscoCapability) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{13} } +type FQDNCapability struct { + HostNameLen uint32 `protobuf:"varint,1,opt,name=host_name_len,json=hostNameLen" json:"host_name_len,omitempty"` + HostName string `protobuf:"bytes,2,opt,name=host_name,json=hostName" json:"host_name,omitempty"` + DomainNameLen uint32 `protobuf:"varint,3,opt,name=domain_name_len,json=domainNameLen" json:"domain_name_len,omitempty"` + DomainName string `protobuf:"bytes,4,opt,name=domain_name,json=domainName" json:"domain_name,omitempty"` +} + +func (m *FQDNCapability) Reset() { *m = FQDNCapability{} } +func (m *FQDNCapability) String() string { return proto.CompactTextString(m) } +func (*FQDNCapability) ProtoMessage() {} +func (*FQDNCapability) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{14} } + +func (m *FQDNCapability) GetHostNameLen() uint32 { + if m != nil { + return m.HostNameLen + } + return 0 +} + +func (m *FQDNCapability) GetHostName() string { + if m != nil { + return m.HostName + } + return "" +} + +func (m *FQDNCapability) GetDomainNameLen() uint32 { + if m != nil { + return m.DomainNameLen + } + return 0 +} + +func (m *FQDNCapability) GetDomainName() string { + if m != nil { + return m.DomainName + } + return "" +} + type UnknownCapability struct { Code uint32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"` Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` @@ -306,7 +346,7 @@ type UnknownCapability struct { func (m *UnknownCapability) Reset() { *m = UnknownCapability{} } func (m *UnknownCapability) String() string { return proto.CompactTextString(m) } func (*UnknownCapability) ProtoMessage() {} -func (*UnknownCapability) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{14} } +func (*UnknownCapability) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{15} } func (m *UnknownCapability) GetCode() uint32 { if m != nil { @@ -337,6 +377,7 @@ func init() { proto.RegisterType((*LongLivedGracefulRestartCapabilityTuple)(nil), "gobgpapi.LongLivedGracefulRestartCapabilityTuple") proto.RegisterType((*LongLivedGracefulRestartCapability)(nil), "gobgpapi.LongLivedGracefulRestartCapability") proto.RegisterType((*RouteRefreshCiscoCapability)(nil), "gobgpapi.RouteRefreshCiscoCapability") + proto.RegisterType((*FQDNCapability)(nil), "gobgpapi.FQDNCapability") proto.RegisterType((*UnknownCapability)(nil), "gobgpapi.UnknownCapability") proto.RegisterEnum("gobgpapi.AddPathMode", AddPathMode_name, AddPathMode_value) } @@ -344,38 +385,42 @@ func init() { func init() { proto.RegisterFile("capability.proto", fileDescriptor1) } var fileDescriptor1 = []byte{ - // 520 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0xc5, 0x49, 0x88, 0x60, 0xd2, 0x44, 0xee, 0x0a, 0x4a, 0x4a, 0xd4, 0x28, 0xda, 0x0b, 0x01, - 0x89, 0x48, 0x0d, 0x07, 0xb8, 0x20, 0x51, 0x52, 0x17, 0x22, 0xe5, 0xa3, 0x72, 0x0b, 0x37, 0x54, - 0x36, 0xf6, 0xc6, 0x59, 0xb1, 0xde, 0xb5, 0xec, 0x75, 0x69, 0x0e, 0x9c, 0xb9, 0xf0, 0xa3, 0x91, - 0x3f, 0x62, 0x9b, 0x54, 0x6e, 0x2b, 0xa4, 0xde, 0x66, 0xbc, 0x33, 0x6f, 0xde, 0x9b, 0xb7, 0x6b, - 0xd0, 0x2d, 0xe2, 0x91, 0x05, 0xe3, 0x4c, 0xad, 0x07, 0x9e, 0x2f, 0x95, 0x44, 0x8f, 0x1c, 0xb9, - 0x70, 0x3c, 0xe2, 0xb1, 0xe7, 0x8d, 0x38, 0x4a, 0x3e, 0xe3, 0x11, 0x3c, 0x9b, 0x86, 0x5c, 0xb1, - 0xd3, 0x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 0xd4, 0x34, - 0x46, 0xc6, 0xf8, 0xab, 0xa1, 0x6b, 0x59, 0xc1, 0x99, 0x31, 0x3b, 0xd6, 0x2b, 0x59, 0xfa, 0x71, - 0x7e, 0xfe, 0x59, 0xaf, 0x2e, 0xea, 0xf1, 0x9f, 0xf0, 0xcd, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x3b, 0xec, 0xd3, 0x4d, 0x34, 0x05, 0x00, 0x00, + // 590 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0xc5, 0x49, 0xa8, 0xda, 0x71, 0x13, 0xdc, 0x15, 0x94, 0x94, 0xa8, 0x25, 0xda, 0x03, 0x04, + 0x24, 0x22, 0x35, 0x1c, 0xe0, 0x82, 0x44, 0x49, 0x1c, 0x88, 0x94, 0x38, 0xc5, 0x2d, 0xdc, 0x50, + 0xd8, 0xd8, 0x9b, 0xc4, 0xc2, 0xde, 0xb5, 0xec, 0x75, 0x69, 0x0e, 0x9c, 0xb9, 0xf0, 0x05, 0x7c, + 0x2d, 0xb2, 0xd7, 0xb1, 0x4d, 0xaa, 0xb4, 0x15, 0x12, 0xb7, 0x9d, 0x9d, 0x37, 0x6f, 0xde, 0x9b, + 0x1d, 0x1b, 0x34, 0x8b, 0xf8, 0x64, 0xea, 0xb8, 0x8e, 0x58, 0xb6, 0xfd, 0x80, 0x0b, 0x8e, 0xb6, + 0xe7, 0x7c, 0x3a, 0xf7, 0x89, 0xef, 0x3c, 0x52, 0x93, 0x93, 0xbc, 0xc6, 0x5d, 0x78, 0x38, 0x8a, + 0x5c, 0xe1, 0x9c, 0xc6, 0x91, 0xc5, 0xdd, 0x6e, 0x56, 0x87, 0x5a, 0xb0, 0x35, 0x23, 0x9e, 0xe3, + 0x2e, 0xeb, 0x4a, 0x53, 0x69, 0xa9, 0x1d, 0xad, 0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 0x7d, 0x62, 0xdf, 0x18, 0xff, 0xce, 0x0a, 0xf2, 0x10, 0x54, 0xac, 0x78, + 0xb9, 0xa4, 0xaa, 0xe4, 0x1c, 0xcf, 0xff, 0x82, 0xb8, 0x91, 0x94, 0xb2, 0x6b, 0xca, 0xe0, 0xf9, + 0x10, 0xd4, 0xc2, 0xc2, 0xa1, 0x2a, 0xec, 0x8c, 0xc6, 0x3d, 0x7d, 0x62, 0x8c, 0x0d, 0x5d, 0xbb, + 0x83, 0x34, 0xd8, 0x4d, 0x42, 0x53, 0xef, 0xea, 0x83, 0xcf, 0xba, 0xa6, 0x64, 0x80, 0x33, 0xdd, + 0xe8, 0x69, 0xa5, 0x2c, 0x7c, 0x37, 0x3e, 0xff, 0xa0, 0x95, 0xa7, 0x5b, 0xc9, 0x6f, 0xfa, 0xe5, + 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x77, 0x70, 0x63, 0xd1, 0x05, 0x00, 0x00, } diff --git a/api/capability.proto b/api/capability.proto index 78504b5d..5bab741e 100644 --- a/api/capability.proto +++ b/api/capability.proto @@ -94,7 +94,14 @@ message LongLivedGracefulRestartCapability { message RouteRefreshCiscoCapability { } +message FQDNCapability { + uint32 host_name_len = 1; + string host_name = 2; + uint32 domain_name_len = 3; + string domain_name = 4; +} + message UnknownCapability { uint32 code = 1; bytes value = 2; -}
\ No newline at end of file +} diff --git a/cmd/gobgp/neighbor.go b/cmd/gobgp/neighbor.go index 8c80338b..8964cf9e 100644 --- a/cmd/gobgp/neighbor.go +++ b/cmd/gobgp/neighbor.go @@ -452,6 +452,16 @@ func showNeighbor(args []string) error { fmt.Printf(" %s:\t%s\n", item.RouteFamily, item.Mode) } } + case bgp.BGP_CAP_FQDN: + fmt.Printf(" %s:\t%s\n", c.Code(), support) + if m := lookup(c, lcaps); m != nil { + fmt.Println(" Local:") + fmt.Printf(" name: %s, domain: %s\n", m.(*bgp.CapFQDN).HostName, m.(*bgp.CapFQDN).DomainName) + } + if m := lookup(c, rcaps); m != nil { + fmt.Println(" Remote:") + fmt.Printf(" name: %s, domain: %s\n", m.(*bgp.CapFQDN).HostName, m.(*bgp.CapFQDN).DomainName) + } default: fmt.Printf(" %s:\t%s\n", c.Code(), support) } diff --git a/internal/pkg/apiutil/capability.go b/internal/pkg/apiutil/capability.go index d135713a..125427db 100644 --- a/internal/pkg/apiutil/capability.go +++ b/internal/pkg/apiutil/capability.go @@ -110,6 +110,15 @@ func NewRouteRefreshCiscoCapability(a *bgp.CapRouteRefreshCisco) *api.RouteRefre return &api.RouteRefreshCiscoCapability{} } +func NewFQDNCapability(a *bgp.CapFQDN) *api.FQDNCapability { + return &api.FQDNCapability{ + HostNameLen: uint32(a.HostNameLen), + HostName: a.HostName, + DomainNameLen: uint32(a.DomainNameLen), + DomainName: a.DomainName, + } +} + func NewUnknownCapability(a *bgp.CapUnknown) *api.UnknownCapability { return &api.UnknownCapability{ Code: uint32(a.CapCode), @@ -140,6 +149,8 @@ func MarshalCapability(value bgp.ParameterCapabilityInterface) (*any.Any, error) m = NewLongLivedGracefulRestartCapability(n) case *bgp.CapRouteRefreshCisco: m = NewRouteRefreshCiscoCapability(n) + case *bgp.CapFQDN: + m = NewFQDNCapability(n) case *bgp.CapUnknown: m = NewUnknownCapability(n) default: @@ -227,6 +238,8 @@ func unmarshalCapability(a *any.Any) (bgp.ParameterCapabilityInterface, error) { return bgp.NewCapLongLivedGracefulRestart(tuples), nil case *api.RouteRefreshCiscoCapability: return bgp.NewCapRouteRefreshCisco(), nil + case *api.FQDNCapability: + return bgp.NewCapFQDN(a.HostName, a.DomainName), nil case *api.UnknownCapability: return bgp.NewCapUnknown(bgp.BGPCapabilityCode(a.Code), a.Value), nil } diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go index 15e15362..5403a5f3 100644 --- a/pkg/packet/bgp/bgp.go +++ b/pkg/packet/bgp/bgp.go @@ -295,6 +295,7 @@ const ( BGP_CAP_ADD_PATH BGPCapabilityCode = 69 BGP_CAP_ENHANCED_ROUTE_REFRESH BGPCapabilityCode = 70 BGP_CAP_LONG_LIVED_GRACEFUL_RESTART BGPCapabilityCode = 71 + BGP_CAP_FQDN BGPCapabilityCode = 73 BGP_CAP_ROUTE_REFRESH_CISCO BGPCapabilityCode = 128 ) @@ -309,6 +310,7 @@ var CapNameMap = map[BGPCapabilityCode]string{ BGP_CAP_ENHANCED_ROUTE_REFRESH: "enhanced-route-refresh", BGP_CAP_ROUTE_REFRESH_CISCO: "cisco-route-refresh", BGP_CAP_LONG_LIVED_GRACEFUL_RESTART: "long-lived-graceful-restart", + BGP_CAP_FQDN: "fqdn", } func (c BGPCapabilityCode) String() string { @@ -916,6 +918,71 @@ func NewCapLongLivedGracefulRestart(tuples []*CapLongLivedGracefulRestartTuple) } } +type CapFQDN struct { + DefaultParameterCapability + HostNameLen uint8 + HostName string + DomainNameLen uint8 + DomainName string +} + +func (c *CapFQDN) DecodeFromBytes(data []byte) error { + c.DefaultParameterCapability.DecodeFromBytes(data) + data = data[2:] + if len(data) < 2 { + return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityFQDN bytes allowed") + } + hostNameLen := uint8(data[0]) + c.HostNameLen = hostNameLen + c.HostName = string(data[1 : c.HostNameLen+1]) + domainNameLen := uint8(data[c.HostNameLen+1]) + c.DomainNameLen = domainNameLen + c.DomainName = string(data[c.HostNameLen+2:]) + return nil +} + +func (c *CapFQDN) Serialize() ([]byte, error) { + buf := make([]byte, c.HostNameLen+c.DomainNameLen+2) + buf[0] = c.HostNameLen + copy(buf[1:c.HostNameLen+1], c.HostName) + buf[c.HostNameLen+1] = c.DomainNameLen + copy(buf[c.HostNameLen+2:], c.DomainName) + c.DefaultParameterCapability.CapValue = buf + return c.DefaultParameterCapability.Serialize() +} + +func (c *CapFQDN) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + HostNameLen uint8 `json:"hostname_len"` + HostName string `json:"hostname"` + DomainNameLen uint8 `json:"domainname_len"` + DomainName string `json:"domainname"` + }{ + HostNameLen: c.HostNameLen, + HostName: c.HostName, + DomainNameLen: c.DomainNameLen, + DomainName: c.DomainName, + }) +} + +func NewCapFQDN(hostname string, domainname string) *CapFQDN { + if len(hostname) > 64 { + hostname = hostname[:64] + } + if len(domainname) > 64 { + domainname = domainname[:64] + } + return &CapFQDN{ + DefaultParameterCapability{ + CapCode: BGP_CAP_FQDN, + }, + uint8(len(hostname)), + hostname, + uint8(len(domainname)), + domainname, + } +} + type CapUnknown struct { DefaultParameterCapability } @@ -955,6 +1022,8 @@ func DecodeCapability(data []byte) (ParameterCapabilityInterface, error) { c = &CapRouteRefreshCisco{} case BGP_CAP_LONG_LIVED_GRACEFUL_RESTART: c = &CapLongLivedGracefulRestart{} + case BGP_CAP_FQDN: + c = &CapFQDN{} default: c = &CapUnknown{} } diff --git a/pkg/server/fsm.go b/pkg/server/fsm.go index b024cf3e..abd94ed9 100644 --- a/pkg/server/fsm.go +++ b/pkg/server/fsm.go @@ -21,6 +21,7 @@ import ( "io" "math/rand" "net" + "os" "strconv" "sync" "syscall" @@ -714,8 +715,11 @@ func capAddPathFromConfig(pConf *config.Neighbor) bgp.ParameterCapabilityInterfa } func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInterface { + fqdn, _ := os.Hostname() caps := make([]bgp.ParameterCapabilityInterface, 0, 4) caps = append(caps, bgp.NewCapRouteRefresh()) + caps = append(caps, bgp.NewCapFQDN(fqdn, "")) + for _, af := range pConf.AfiSafis { caps = append(caps, bgp.NewCapMultiProtocol(af.State.Family)) } |