Skip to content

Commit

Permalink
mup: handle Type 1 ST Route Prefix as Prefix instead of single address
Browse files Browse the repository at this point in the history
  • Loading branch information
higebu committed Sep 28, 2022
1 parent 086c8c9 commit 975db96
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 658 deletions.
1,178 changes: 590 additions & 588 deletions api/attribute.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/attribute.proto
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ message MUPType1SessionTransformedRoute {
// - RouteDistinguisherIPAddress
// - RouteDistinguisherFourOctetASN
google.protobuf.Any rd = 1;
uint32 prefix_length = 2;
uint32 prefix_length = 2 [deprecated = true];
string prefix = 3;
uint32 teid = 4;
uint32 qfi = 5;
Expand Down
1 change: 1 addition & 0 deletions api/gobgp.pb.go

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

35 changes: 18 additions & 17 deletions cmd/gobgp/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ func parseEvpnArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
return nil, nil, fmt.Errorf("invalid subtype. expect [macadv|multicast|prefix] but %s", subtype)
}

func parseMUPInterworkSegmentDiscoveryRouteArgs(args []string, nexthop string) (bgp.AddrPrefixInterface, []string, error) {
func parseMUPInterworkSegmentDiscoveryRouteArgs(args []string, afi uint16, nexthop string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <ip prefix> rd <rd> [rt <rt>...]
req := 5
Expand Down Expand Up @@ -1001,10 +1001,10 @@ func parseMUPInterworkSegmentDiscoveryRouteArgs(args []string, nexthop string) (
PrefixLength: uint8(prefix.Bits()),
Prefix: prefix,
}
return bgp.NewMUPNLRI(bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_INTERWORK_SEGMENT_DISCOVERY, r), extcomms, nil
return bgp.NewMUPNLRI(afi, bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_INTERWORK_SEGMENT_DISCOVERY, r), extcomms, nil
}

func parseMUPDirectSegmentDiscoveryRouteArgs(args []string, nexthop string) (bgp.AddrPrefixInterface, []string, error) {
func parseMUPDirectSegmentDiscoveryRouteArgs(args []string, afi uint16, nexthop string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <ip address> rd <rd> [rt <rt>...] [mup <segment identifier>]
req := 5
Expand Down Expand Up @@ -1056,10 +1056,10 @@ func parseMUPDirectSegmentDiscoveryRouteArgs(args []string, nexthop string) (bgp
RD: rd,
Address: addr,
}
return bgp.NewMUPNLRI(bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_DIRECT_SEGMENT_DISCOVERY, r), extcomms, nil
return bgp.NewMUPNLRI(afi, bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_DIRECT_SEGMENT_DISCOVERY, r), extcomms, nil
}

func parseMUPType1SessionTransformedRouteArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
func parseMUPType1SessionTransformedRouteArgs(args []string, afi uint16) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <ip prefix> rd <rd> [rt <rt>...] teid <teid> qfi <qfi> endpoint <endpoint>
req := 5
Expand Down Expand Up @@ -1088,7 +1088,7 @@ func parseMUPType1SessionTransformedRouteArgs(args []string) (bgp.AddrPrefixInte
if err != nil {
return nil, nil, err
}
prefix, err := netip.ParseAddr(m[""][0])
prefix, err := netip.ParsePrefix(m[""][0])
if err != nil {
return nil, nil, err
}
Expand All @@ -1115,17 +1115,16 @@ func parseMUPType1SessionTransformedRouteArgs(args []string) (bgp.AddrPrefixInte

r := &bgp.MUPType1SessionTransformedRoute{
RD: rd,
PrefixLength: uint8(prefix.BitLen()),
Prefix: prefix,
TEID: uint32(teid),
QFI: uint8(qfi),
EndpointAddressLength: uint8(ea.BitLen()),
EndpointAddress: ea,
}
return bgp.NewMUPNLRI(bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_TYPE_1_SESSION_TRANSFORMED, r), extcomms, nil
return bgp.NewMUPNLRI(afi, bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_TYPE_1_SESSION_TRANSFORMED, r), extcomms, nil
}

func parseMUPType2SessionTransformedRouteArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
func parseMUPType2SessionTransformedRouteArgs(args []string, afi uint16) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <endpoint address> rd <rd> [rt <rt>...] teid <teid>
req := 5
Expand Down Expand Up @@ -1175,24 +1174,24 @@ func parseMUPType2SessionTransformedRouteArgs(args []string) (bgp.AddrPrefixInte
EndpointAddress: ea,
TEID: uint32(teid),
}
return bgp.NewMUPNLRI(bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_TYPE_2_SESSION_TRANSFORMED, r), extcomms, nil
return bgp.NewMUPNLRI(afi, bgp.MUP_ARCH_TYPE_UNDEFINED, bgp.MUP_ROUTE_TYPE_TYPE_2_SESSION_TRANSFORMED, r), extcomms, nil
}

func parseMUPArgs(args []string, nexthop string) (bgp.AddrPrefixInterface, []string, error) {
func parseMUPArgs(args []string, afi uint16, nexthop string) (bgp.AddrPrefixInterface, []string, error) {
if len(args) < 1 {
return nil, nil, fmt.Errorf("lack of args. need 1 but %d", len(args))
}
subtype := args[0]
args = args[1:]
switch subtype {
case "isd":
return parseMUPInterworkSegmentDiscoveryRouteArgs(args, nexthop)
return parseMUPInterworkSegmentDiscoveryRouteArgs(args, afi, nexthop)
case "dsd":
return parseMUPDirectSegmentDiscoveryRouteArgs(args, nexthop)
return parseMUPDirectSegmentDiscoveryRouteArgs(args, afi, nexthop)
case "t1st":
return parseMUPType1SessionTransformedRouteArgs(args)
return parseMUPType1SessionTransformedRouteArgs(args, afi)
case "t2st":
return parseMUPType2SessionTransformedRouteArgs(args)
return parseMUPType2SessionTransformedRouteArgs(args, afi)
}
return nil, nil, fmt.Errorf("invalid subtype. expect [isd|dsd|t1st|t2st] but %s", subtype)
}
Expand Down Expand Up @@ -1583,8 +1582,10 @@ func parsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
} else {
nlri = bgp.NewOpaqueNLRI([]byte(m["key"][0]), nil)
}
case bgp.RF_MUP_IPv4, bgp.RF_MUP_IPv6:
nlri, extcomms, err = parseMUPArgs(args, nexthop)
case bgp.RF_MUP_IPv4:
nlri, extcomms, err = parseMUPArgs(args, bgp.AFI_IP, nexthop)
case bgp.RF_MUP_IPv6:
nlri, extcomms, err = parseMUPArgs(args, bgp.AFI_IP6, nexthop)
default:
return nil, fmt.Errorf("unsupported route family: %s", rf)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/apiutil/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,6 @@ func MarshalNLRI(value bgp.AddrPrefixInterface) (*apb.Any, error) {
}
nlri = &api.MUPType1SessionTransformedRoute{
Rd: rd,
PrefixLength: uint32(r.PrefixLength),
Prefix: r.Prefix.String(),
Teid: r.TEID,
Qfi: uint32(r.QFI),
Expand Down Expand Up @@ -1239,7 +1238,7 @@ func UnmarshalNLRI(rf bgp.RouteFamily, an *apb.Any) (bgp.AddrPrefixInterface, er
if err != nil {
return nil, err
}
prefix, err := netip.ParseAddr(v.Prefix)
prefix, err := netip.ParsePrefix(v.Prefix)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/apiutil/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1259,8 +1259,7 @@ func Test_MpReachNLRIAttribute_MUPType1SessionTransformedRoute(t *testing.T) {
assert.Nil(err)
a, err := apb.New(&api.MUPType1SessionTransformedRoute{
Rd: rd,
PrefixLength: 32,
Prefix: "192.168.100.1",
Prefix: "192.168.100.1/32",
Teid: 12345,
Qfi: 9,
EndpointAddressLength: 32,
Expand Down
4 changes: 2 additions & 2 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8447,9 +8447,9 @@ func NewPrefixFromRouteFamily(afi uint16, safi uint8, prefixStr ...string) (pref
case RF_LS:
prefix = &LsAddrPrefix{}
case RF_MUP_IPv4:
prefix = NewMUPNLRI(0, 0, nil)
prefix = NewMUPNLRI(AFI_IP, 0, 0, nil)
case RF_MUP_IPv6:
prefix = NewMUPNLRI(0, 0, nil)
prefix = NewMUPNLRI(AFI_IP6, 0, 0, nil)
default:
err = fmt.Errorf("unknown route family. AFI: %d, SAFI: %d", afi, safi)
}
Expand Down
Loading

0 comments on commit 975db96

Please sign in to comment.