mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
cli: Add User Interface for Redirect-IPv6 action
Signed-off-by: Satoshi Fujimoto <[email protected]>
This commit is contained in:
committed by
FUJITA Tomonori
parent
7497ce7eb7
commit
87fe4fa604
@@ -52,7 +52,7 @@ CLI syntax to add ipv4/ipv6 flowspec rule is
|
||||
<TCPFLAG> : U, C, E, F, S, R, P, A
|
||||
<ITEM> : &?{<|>|>=|<=|==|!=}<value>
|
||||
<THEN_EXPR> : { accept | discard | rate-limit <value> | redirect <RT> | mark <value> | action { sample | terminal | sample-terminal } | rt <RT>... }...
|
||||
<RT> : xxx:yyy, xx.xx.xx.xx:yyy, xxx.xxx:yyy
|
||||
<RT> : xxx:yyy, xx.xx.xx.xx:yyy, xxx.xxx:yyy, <ipv6_address>:yyy
|
||||
```
|
||||
|
||||
that for l2vpn flowspec rule is
|
||||
@@ -63,7 +63,7 @@ that for l2vpn flowspec rule is
|
||||
<ETHER_TYPE> : arp, vmtp, ipx, snmp, net-bios, xtp, pppoe-discovery, ipv4, rarp, ipv6, pppoe-session, loopback, apple-talk, aarp
|
||||
<ITEM> : &?{<|>|>=|<=|==|!=}<value>
|
||||
<THEN_EXPR> : { accept | discard | rate-limit <value> | redirect <RT> | mark <value> | action { sample | terminal | sample-terminal } | rt <RT>... }...
|
||||
<RT> : xxx:yyy, xx.xx.xx.xx:yyy, xxx.xxx:yyy
|
||||
<RT> : xxx:yyy, xx.xx.xx.xx:yyy, xxx.xxx:yyy, <ipv6_address>:yyy
|
||||
```
|
||||
### Decimal values and Operators
|
||||
|
||||
|
||||
+25
-7
@@ -108,17 +108,19 @@ func redirectParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t, _ := rt.GetTypes()
|
||||
switch t {
|
||||
case bgp.EC_TYPE_TRANSITIVE_TWO_OCTET_AS_SPECIFIC:
|
||||
switch rt.(type) {
|
||||
case *bgp.TwoOctetAsSpecificExtended:
|
||||
r := rt.(*bgp.TwoOctetAsSpecificExtended)
|
||||
return []bgp.ExtendedCommunityInterface{bgp.NewRedirectTwoOctetAsSpecificExtended(r.AS, r.LocalAdmin)}, nil
|
||||
case bgp.EC_TYPE_TRANSITIVE_IP4_SPECIFIC:
|
||||
case *bgp.IPv4AddressSpecificExtended:
|
||||
r := rt.(*bgp.IPv4AddressSpecificExtended)
|
||||
return []bgp.ExtendedCommunityInterface{bgp.NewRedirectIPv4AddressSpecificExtended(r.IPv4.String(), r.LocalAdmin)}, nil
|
||||
case bgp.EC_TYPE_TRANSITIVE_FOUR_OCTET_AS_SPECIFIC:
|
||||
case *bgp.FourOctetAsSpecificExtended:
|
||||
r := rt.(*bgp.FourOctetAsSpecificExtended)
|
||||
return []bgp.ExtendedCommunityInterface{bgp.NewRedirectFourOctetAsSpecificExtended(r.AS, r.LocalAdmin)}, nil
|
||||
case *bgp.IPv6AddressSpecificExtended:
|
||||
r := rt.(*bgp.IPv6AddressSpecificExtended)
|
||||
return []bgp.ExtendedCommunityInterface{bgp.NewRedirectIPv6AddressSpecificExtended(r.IPv6.String(), r.LocalAdmin)}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("invalid redirect")
|
||||
}
|
||||
@@ -809,8 +811,24 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*table.Path, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := bgp.NewPathAttributeExtendedCommunities(extcomms)
|
||||
attrs = append(attrs, p)
|
||||
normalextcomms := make([]bgp.ExtendedCommunityInterface, 0)
|
||||
ipv6extcomms := make([]bgp.ExtendedCommunityInterface, 0)
|
||||
for _, com := range extcomms {
|
||||
switch com.(type) {
|
||||
case *bgp.RedirectIPv6AddressSpecificExtended:
|
||||
ipv6extcomms = append(ipv6extcomms, com)
|
||||
default:
|
||||
normalextcomms = append(normalextcomms, com)
|
||||
}
|
||||
}
|
||||
if len(normalextcomms) != 0 {
|
||||
p := bgp.NewPathAttributeExtendedCommunities(normalextcomms)
|
||||
attrs = append(attrs, p)
|
||||
}
|
||||
if len(ipv6extcomms) != 0 {
|
||||
ip6p := bgp.NewPathAttributeIP6ExtendedCommunities(ipv6extcomms)
|
||||
attrs = append(attrs, ip6p)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(attrs)
|
||||
|
||||
+5
-3
@@ -1258,9 +1258,9 @@ func GetRouteDistinguisher(data []byte) RouteDistinguisherInterface {
|
||||
}
|
||||
|
||||
func parseRdAndRt(input string) ([]string, error) {
|
||||
exp := regexp.MustCompile("^((\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)|((\\d+)\\.)?(\\d+)):(\\d+)$")
|
||||
exp := regexp.MustCompile("^((\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)|((\\d+)\\.)?(\\d+)|([\\w]+:[\\w:]*:[\\w]+)):(\\d+)$")
|
||||
elems := exp.FindStringSubmatch(input)
|
||||
if len(elems) != 10 {
|
||||
if len(elems) != 11 {
|
||||
return nil, fmt.Errorf("failed to parse")
|
||||
}
|
||||
return elems, nil
|
||||
@@ -5759,12 +5759,14 @@ func ParseExtendedCommunity(subtype ExtendedCommunityAttrSubType, com string) (E
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localAdmin, _ := strconv.Atoi(elems[9])
|
||||
localAdmin, _ := strconv.Atoi(elems[10])
|
||||
ip := net.ParseIP(elems[1])
|
||||
isTransitive := true
|
||||
switch {
|
||||
case ip.To4() != nil:
|
||||
return NewIPv4AddressSpecificExtended(subtype, elems[1], uint16(localAdmin), isTransitive), nil
|
||||
case ip.To16() != nil:
|
||||
return NewIPv6AddressSpecificExtended(subtype, elems[1], uint16(localAdmin), isTransitive), nil
|
||||
case elems[6] == "" && elems[7] == "":
|
||||
asn, _ := strconv.Atoi(elems[8])
|
||||
return NewTwoOctetAsSpecificExtended(subtype, uint16(asn), uint32(localAdmin), isTransitive), nil
|
||||
|
||||
Reference in New Issue
Block a user