summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-05-12 10:04:09 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-05-23 11:11:10 +0900
commit87fe4fa604fff41c4d930f128e91a58c0fa1ead4 (patch)
treecbcf4289c9831fc4ae86ddd86ce6a0d03f6cd395
parent7497ce7eb7e19be757a5b46aeacf11c4271dc1f6 (diff)
cli: Add User Interface for Redirect-IPv6 action
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
-rw-r--r--docs/sources/flowspec.md4
-rw-r--r--gobgp/cmd/global.go32
-rw-r--r--packet/bgp/bgp.go8
3 files changed, 32 insertions, 12 deletions
diff --git a/docs/sources/flowspec.md b/docs/sources/flowspec.md
index bb498a48..da7d17f0 100644
--- a/docs/sources/flowspec.md
+++ b/docs/sources/flowspec.md
@@ -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
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index c7d07db1..3c09e7dd 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -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)
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index 5d924b10..1879d1f0 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -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