Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions api/gobgp.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions pkg/config/oc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to check the range here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I missed this, fixed

pconf.AsPathOptions.Config.ReplacePeerAs = a.Conf.ReplacePeerAsn
pconf.AsPathOptions.Config.AllowAsPathLoopLocal = a.Conf.AllowAspathLoopLocal

switch a.Conf.RemovePrivate {
case api.RemovePrivate_REMOVE_PRIVATE_ALL:
Expand Down
10 changes: 10 additions & 0 deletions pkg/server/grpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions proto/api/gobgp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down