diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index 8af794f88..a60b72c95 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -7551,19 +7551,22 @@ func (x *PeerConf) GetAllowAspathLoopLocal() bool { } type PeerGroupConf struct { - state protoimpl.MessageState `protogen:"open.v1"` - AuthPassword string `protobuf:"bytes,1,opt,name=auth_password,json=authPassword,proto3" json:"auth_password,omitempty"` - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - LocalAsn uint32 `protobuf:"varint,3,opt,name=local_asn,json=localAsn,proto3" json:"local_asn,omitempty"` - PeerAsn uint32 `protobuf:"varint,4,opt,name=peer_asn,json=peerAsn,proto3" json:"peer_asn,omitempty"` - PeerGroupName string `protobuf:"bytes,5,opt,name=peer_group_name,json=peerGroupName,proto3" json:"peer_group_name,omitempty"` - Type PeerType `protobuf:"varint,6,opt,name=type,proto3,enum=api.PeerType" json:"type,omitempty"` - RemovePrivate RemovePrivate `protobuf:"varint,7,opt,name=remove_private,json=removePrivate,proto3,enum=api.RemovePrivate" json:"remove_private,omitempty"` - RouteFlapDamping bool `protobuf:"varint,8,opt,name=route_flap_damping,json=routeFlapDamping,proto3" json:"route_flap_damping,omitempty"` - SendCommunity uint32 `protobuf:"varint,9,opt,name=send_community,json=sendCommunity,proto3" json:"send_community,omitempty"` - SendSoftwareVersion bool `protobuf:"varint,10,opt,name=send_software_version,json=sendSoftwareVersion,proto3" json:"send_software_version,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + AuthPassword string `protobuf:"bytes,1,opt,name=auth_password,json=authPassword,proto3" json:"auth_password,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + LocalAsn uint32 `protobuf:"varint,3,opt,name=local_asn,json=localAsn,proto3" json:"local_asn,omitempty"` + PeerAsn uint32 `protobuf:"varint,4,opt,name=peer_asn,json=peerAsn,proto3" json:"peer_asn,omitempty"` + PeerGroupName string `protobuf:"bytes,5,opt,name=peer_group_name,json=peerGroupName,proto3" json:"peer_group_name,omitempty"` + Type PeerType `protobuf:"varint,6,opt,name=type,proto3,enum=api.PeerType" json:"type,omitempty"` + RemovePrivate RemovePrivate `protobuf:"varint,7,opt,name=remove_private,json=removePrivate,proto3,enum=api.RemovePrivate" json:"remove_private,omitempty"` + RouteFlapDamping bool `protobuf:"varint,8,opt,name=route_flap_damping,json=routeFlapDamping,proto3" json:"route_flap_damping,omitempty"` + SendCommunity uint32 `protobuf:"varint,9,opt,name=send_community,json=sendCommunity,proto3" json:"send_community,omitempty"` + SendSoftwareVersion bool `protobuf:"varint,10,opt,name=send_software_version,json=sendSoftwareVersion,proto3" json:"send_software_version,omitempty"` + AllowOwnAsn uint32 `protobuf:"varint,11,opt,name=allow_own_asn,json=allowOwnAsn,proto3" json:"allow_own_asn,omitempty"` + ReplacePeerAsn bool `protobuf:"varint,12,opt,name=replace_peer_asn,json=replacePeerAsn,proto3" json:"replace_peer_asn,omitempty"` + AllowAspathLoopLocal bool `protobuf:"varint,13,opt,name=allow_aspath_loop_local,json=allowAspathLoopLocal,proto3" json:"allow_aspath_loop_local,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *PeerGroupConf) Reset() { @@ -7666,6 +7669,27 @@ func (x *PeerGroupConf) GetSendSoftwareVersion() bool { return false } +func (x *PeerGroupConf) GetAllowOwnAsn() uint32 { + if x != nil { + return x.AllowOwnAsn + } + return 0 +} + +func (x *PeerGroupConf) GetReplacePeerAsn() bool { + if x != nil { + return x.ReplacePeerAsn + } + return false +} + +func (x *PeerGroupConf) GetAllowAspathLoopLocal() bool { + if x != nil { + return x.AllowAspathLoopLocal + } + return false +} + type PeerGroupState struct { state protoimpl.MessageState `protogen:"open.v1"` AuthPassword string `protobuf:"bytes,1,opt,name=auth_password,json=authPassword,proto3" json:"auth_password,omitempty"` @@ -13599,7 +13623,7 @@ const file_api_gobgp_proto_rawDesc = "" + "\n" + "admin_down\x18\x0f \x01(\bR\tadminDown\x122\n" + "\x15send_software_version\x18\x10 \x01(\bR\x13sendSoftwareVersion\x125\n" + - "\x17allow_aspath_loop_local\x18\x11 \x01(\bR\x14allowAspathLoopLocal\"\x9d\x03\n" + + "\x17allow_aspath_loop_local\x18\x11 \x01(\bR\x14allowAspathLoopLocal\"\xa2\x04\n" + "\rPeerGroupConf\x12#\n" + "\rauth_password\x18\x01 \x01(\tR\fauthPassword\x12 \n" + "\vdescription\x18\x02 \x01(\tR\vdescription\x12\x1b\n" + @@ -13611,7 +13635,10 @@ const file_api_gobgp_proto_rawDesc = "" + "\x12route_flap_damping\x18\b \x01(\bR\x10routeFlapDamping\x12%\n" + "\x0esend_community\x18\t \x01(\rR\rsendCommunity\x122\n" + "\x15send_software_version\x18\n" + - " \x01(\bR\x13sendSoftwareVersion\"\xb2\x03\n" + + " \x01(\bR\x13sendSoftwareVersion\x12\"\n" + + "\rallow_own_asn\x18\v \x01(\rR\vallowOwnAsn\x12(\n" + + "\x10replace_peer_asn\x18\f \x01(\bR\x0ereplacePeerAsn\x125\n" + + "\x17allow_aspath_loop_local\x18\r \x01(\bR\x14allowAspathLoopLocal\"\xb2\x03\n" + "\x0ePeerGroupState\x12#\n" + "\rauth_password\x18\x01 \x01(\tR\fauthPassword\x12 \n" + "\vdescription\x18\x02 \x01(\tR\vdescription\x12\x1b\n" + diff --git a/pkg/config/oc/util.go b/pkg/config/oc/util.go index 240b2250f..ca7014a90 100644 --- a/pkg/config/oc/util.go +++ b/pkg/config/oc/util.go @@ -675,14 +675,17 @@ func NewPeerGroupFromConfigStruct(pconf *PeerGroup) *api.PeerGroup { return &api.PeerGroup{ ApplyPolicy: newApplyPolicyFromConfigStruct(&pconf.ApplyPolicy), Conf: &api.PeerGroupConf{ - PeerAsn: pconf.Config.PeerAs, - LocalAsn: pconf.Config.LocalAs, - Type: toPeerType(pconf.Config.PeerType), - AuthPassword: pconf.Config.AuthPassword, - RouteFlapDamping: pconf.Config.RouteFlapDamping, - Description: pconf.Config.Description, - PeerGroupName: pconf.Config.PeerGroupName, - SendSoftwareVersion: pconf.Config.SendSoftwareVersion, + PeerAsn: pconf.Config.PeerAs, + LocalAsn: pconf.Config.LocalAs, + Type: toPeerType(pconf.Config.PeerType), + AuthPassword: pconf.Config.AuthPassword, + RouteFlapDamping: pconf.Config.RouteFlapDamping, + Description: pconf.Config.Description, + PeerGroupName: pconf.Config.PeerGroupName, + SendSoftwareVersion: pconf.Config.SendSoftwareVersion, + AllowOwnAsn: uint32(pconf.AsPathOptions.Config.AllowOwnAs), + ReplacePeerAsn: pconf.AsPathOptions.Config.ReplacePeerAs, + AllowAspathLoopLocal: pconf.AsPathOptions.Config.AllowAsPathLoopLocal, }, Info: &api.PeerGroupState{ PeerAsn: s.PeerAs, diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index 554eadb7c..ac4745cd0 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -1154,6 +1154,12 @@ func newPeerGroupFromAPIStruct(a *api.PeerGroup) (*oc.PeerGroup, error) { pconf.Config.Description = a.Conf.Description pconf.Config.PeerGroupName = a.Conf.PeerGroupName pconf.Config.SendSoftwareVersion = a.Conf.SendSoftwareVersion + if a.Conf.AllowOwnAsn > math.MaxUint8 { + return nil, fmt.Errorf("allow_own_asn is out of range: %d", a.Conf.AllowOwnAsn) + } + pconf.AsPathOptions.Config.AllowOwnAs = uint8(a.Conf.AllowOwnAsn) + pconf.AsPathOptions.Config.ReplacePeerAs = a.Conf.ReplacePeerAsn + pconf.AsPathOptions.Config.AllowAsPathLoopLocal = a.Conf.AllowAspathLoopLocal switch a.Conf.RemovePrivate { case api.RemovePrivate_REMOVE_PRIVATE_ALL: diff --git a/pkg/server/grpc_server_test.go b/pkg/server/grpc_server_test.go index 0c70ec630..241a35e37 100644 --- a/pkg/server/grpc_server_test.go +++ b/pkg/server/grpc_server_test.go @@ -64,6 +64,16 @@ func TestParseHost(t *testing.T) { } } +func TestNewPeerGroupFromAPIStructRejectsInvalidAllowOwnAsn(t *testing.T) { + _, err := newPeerGroupFromAPIStruct(&api.PeerGroup{ + Conf: &api.PeerGroupConf{ + PeerGroupName: "pg", + AllowOwnAsn: 256, + }, + }) + assert.ErrorContains(t, err, "allow_own_asn is out of range") +} + func TestToPathApi(t *testing.T) { type args struct { path *table.Path diff --git a/proto/api/gobgp.proto b/proto/api/gobgp.proto index b679141cb..b0354be32 100644 --- a/proto/api/gobgp.proto +++ b/proto/api/gobgp.proto @@ -780,6 +780,9 @@ message PeerGroupConf { bool route_flap_damping = 8; uint32 send_community = 9; bool send_software_version = 10; + uint32 allow_own_asn = 11; + bool replace_peer_asn = 12; + bool allow_aspath_loop_local = 13; } message PeerGroupState {