summaryrefslogtreecommitdiffhomepage
path: root/zebra
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-08-25 15:05:39 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-11-02 00:14:09 +0900
commitd2a34c964aa0a43afc488f1d4497e4cd51a8c15a (patch)
tree2c86b9b69e9db679ced84a5813bc6ebbae04805c /zebra
parent1dc56d5a724a394f5db5cb75e305e8da286c52dc (diff)
zclient: Enable to connect to FRRouting
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'zebra')
-rw-r--r--zebra/zapi.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/zebra/zapi.go b/zebra/zapi.go
index 6998bd4e..e9e91015 100644
--- a/zebra/zapi.go
+++ b/zebra/zapi.go
@@ -23,6 +23,7 @@ import (
"strings"
"syscall"
+ "github.com/osrg/gobgp/packet/bgp"
log "github.com/sirupsen/logrus"
)
@@ -751,6 +752,43 @@ func (c *Client) SendRedistributeDelete(t ROUTE_TYPE) error {
return nil
}
+func (c *Client) SendIPRoute(vrfId uint16, body *IPRouteBody, isWithdraw bool) error {
+ command := IPV4_ROUTE_ADD
+ if c.Version <= 3 {
+ if isWithdraw {
+ command = IPV4_ROUTE_DELETE
+ }
+ } else { // version >= 4
+ if isWithdraw {
+ command = FRR_IPV4_ROUTE_DELETE
+ } else {
+ command = FRR_IPV4_ROUTE_ADD
+ }
+ }
+ return c.SendCommand(command, vrfId, body)
+}
+
+func (c *Client) SendNexthopRegister(vrfId uint16, body *NexthopRegisterBody, isWithdraw bool) error {
+ // Note: NEXTHOP_REGISTER and NEXTHOP_UNREGISTER messages are not
+ // supported in Zebra protocol version<3.
+ if c.Version < 3 {
+ return fmt.Errorf("NEXTHOP_REGISTER/NEXTHOP_UNREGISTER are not supported in version: %d", c.Version)
+ }
+ command := NEXTHOP_REGISTER
+ if c.Version == 3 {
+ if isWithdraw {
+ command = NEXTHOP_UNREGISTER
+ }
+ } else { // version >= 4
+ if isWithdraw {
+ command = FRR_NEXTHOP_UNREGISTER
+ } else {
+ command = FRR_NEXTHOP_REGISTER
+ }
+ }
+ return c.SendCommand(command, vrfId, body)
+}
+
func (c *Client) Close() error {
close(c.outgoing)
return c.conn.Close()
@@ -1046,6 +1084,26 @@ type IPRouteBody struct {
Api API_TYPE
}
+func (b *IPRouteBody) RouteFamily() bgp.RouteFamily {
+ switch b.Api {
+ case IPV4_ROUTE_ADD, IPV4_ROUTE_DELETE, FRR_REDISTRIBUTE_IPV4_ADD, FRR_REDISTRIBUTE_IPV4_DEL:
+ return bgp.RF_IPv4_UC
+ case IPV6_ROUTE_ADD, IPV6_ROUTE_DELETE, FRR_REDISTRIBUTE_IPV6_ADD, FRR_REDISTRIBUTE_IPV6_DEL:
+ return bgp.RF_IPv6_UC
+ default:
+ return bgp.RF_OPAQUE
+ }
+}
+
+func (b *IPRouteBody) IsWithdraw() bool {
+ switch b.Api {
+ case IPV4_ROUTE_DELETE, FRR_REDISTRIBUTE_IPV4_DEL, IPV6_ROUTE_DELETE, FRR_REDISTRIBUTE_IPV6_DEL:
+ return true
+ default:
+ return false
+ }
+}
+
func (b *IPRouteBody) Serialize(version uint8) ([]byte, error) {
var buf []byte