From d4e3feb2e2f042fb4c981b3012e5d51656ad6f8b Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Wed, 18 Nov 2020 05:56:36 -0600 Subject: [PATCH] Add chain elements for connectioncontext ipaddress and routes Signed-off-by: Ed Warnicke --- .../ipcontext/ipaddress/client.go | 77 +++++++++++++ .../ipcontext/ipaddress/common.go | 60 ++++++++++ .../ipcontext/ipaddress/doc.go | 18 +++ .../ipcontext/ipaddress/server.go | 70 ++++++++++++ .../ipcontext/routes/client.go | 78 +++++++++++++ .../ipcontext/routes/common.go | 108 ++++++++++++++++++ .../connectioncontext/ipcontext/routes/doc.go | 18 +++ .../ipcontext/routes/server.go | 74 ++++++++++++ pkg/tools/types/doc.go | 18 +++ pkg/tools/types/ip_types.go | 55 +++++++++ pkg/tools/types/route.go | 33 ++++++ 11 files changed, 609 insertions(+) create mode 100644 pkg/networkservice/connectioncontext/ipcontext/ipaddress/client.go create mode 100644 pkg/networkservice/connectioncontext/ipcontext/ipaddress/common.go create mode 100644 pkg/networkservice/connectioncontext/ipcontext/ipaddress/doc.go create mode 100644 pkg/networkservice/connectioncontext/ipcontext/ipaddress/server.go create mode 100644 pkg/networkservice/connectioncontext/ipcontext/routes/client.go create mode 100644 pkg/networkservice/connectioncontext/ipcontext/routes/common.go create mode 100644 pkg/networkservice/connectioncontext/ipcontext/routes/doc.go create mode 100644 pkg/networkservice/connectioncontext/ipcontext/routes/server.go create mode 100644 pkg/tools/types/doc.go create mode 100644 pkg/tools/types/ip_types.go create mode 100644 pkg/tools/types/route.go diff --git a/pkg/networkservice/connectioncontext/ipcontext/ipaddress/client.go b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/client.go new file mode 100644 index 00000000..8ec0e297 --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/client.go @@ -0,0 +1,77 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ipaddress + +import ( + "context" + + "git.fd.io/govpp.git/api" + "github.com/golang/protobuf/ptypes/empty" + "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" + "google.golang.org/grpc" + + "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" +) + +type ipaddressClient struct { + vppConn api.Connection +} + +// NewClient creates a NetworkServiceClient chain element to set the ip address on a vpp interface +// It sets the IP Address on the *vpp* side of an interface leaving the +// Endpoint. +// Endpoint +// +---------------------------+ +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// | ipaddress.NewClient()+-------------------+ +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// +---------------------------+ +// +func NewClient(vppConn api.Connection) networkservice.NetworkServiceClient { + return &ipaddressClient{ + vppConn: vppConn, + } +} + +func (i *ipaddressClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { + conn, err := next.Client(ctx).Request(ctx, request, opts...) + if err != nil { + return nil, err + } + if err := addDel(ctx, conn, i.vppConn, metadata.IsClient(i), true); err != nil { + _, _ = i.Close(ctx, conn, opts...) + return nil, err + } + return conn, nil +} + +func (i *ipaddressClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { + return next.Client(ctx).Close(ctx, conn, opts...) +} diff --git a/pkg/networkservice/connectioncontext/ipcontext/ipaddress/common.go b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/common.go new file mode 100644 index 00000000..0b05390d --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/common.go @@ -0,0 +1,60 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ipaddress + +import ( + "context" + "time" + + "git.fd.io/govpp.git/api" + interfaces "github.com/edwarnicke/govpp/binapi/interface" + "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/trace" + "github.com/pkg/errors" + + "github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex" + "github.com/networkservicemesh/sdk-vpp/pkg/tools/types" +) + +func addDel(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection, isClient, isAdd bool) error { + swIfIndex, ok := ifindex.Load(ctx, isClient) + if !ok { + return errors.New("no swIfIndex available") + } + ipNet := conn.GetContext().GetIpContext().GetDstIPNet() + if isClient { + ipNet = conn.GetContext().GetIpContext().GetSrcIPNet() + } + if ipNet == nil { + return nil + } + now := time.Now() + if _, err := interfaces.NewServiceClient(vppConn).SwInterfaceAddDelAddress(ctx, &interfaces.SwInterfaceAddDelAddress{ + SwIfIndex: swIfIndex, + IsAdd: isAdd, + Prefix: types.ToVppAddressWithPrefix(ipNet), + }); err != nil { + return errors.WithStack(err) + } + trace.Log(ctx). + WithField("swIfIndex", swIfIndex). + WithField("prefix", ipNet). + WithField("isAdd", isAdd). + WithField("duration", time.Since(now)). + WithField("vppapi", "SwInterfaceAddDelAddress").Debug("completed") + return nil +} diff --git a/pkg/networkservice/connectioncontext/ipcontext/ipaddress/doc.go b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/doc.go new file mode 100644 index 00000000..da865a23 --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/doc.go @@ -0,0 +1,18 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package ipaddress provides networkservice chain elements to set the ip address on vpp interfaces +package ipaddress diff --git a/pkg/networkservice/connectioncontext/ipcontext/ipaddress/server.go b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/server.go new file mode 100644 index 00000000..4e7edac8 --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/ipaddress/server.go @@ -0,0 +1,70 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ipaddress + +import ( + "context" + + "git.fd.io/govpp.git/api" + "github.com/golang/protobuf/ptypes/empty" + "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" + "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" +) + +type ipaddressServer struct { + vppConn api.Connection +} + +// NewServer creates a NetworkServiceServer chain element to set the ip address on a vpp interface +// It sets the IP Address on the *vpp* side of an interface plugged into the +// Endpoint. +// Endpoint +// +---------------------------+ +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// +-------------------+ ipaddress.NewServer() | +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// +---------------------------+ +// +func NewServer(vppConn api.Connection) networkservice.NetworkServiceServer { + return &ipaddressServer{ + vppConn: vppConn, + } +} + +func (i *ipaddressServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { + if err := addDel(ctx, request.GetConnection(), i.vppConn, metadata.IsClient(i), true); err != nil { + return nil, err + } + return next.Server(ctx).Request(ctx, request) +} + +func (i *ipaddressServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { + return next.Server(ctx).Close(ctx, conn) +} diff --git a/pkg/networkservice/connectioncontext/ipcontext/routes/client.go b/pkg/networkservice/connectioncontext/ipcontext/routes/client.go new file mode 100644 index 00000000..2468c0be --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/routes/client.go @@ -0,0 +1,78 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package routes + +import ( + "context" + + "git.fd.io/govpp.git/api" + "github.com/golang/protobuf/ptypes/empty" + "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" + "google.golang.org/grpc" + + "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" +) + +type routesClient struct { + vppConn api.Connection +} + +// NewClient creates a NetworkServiceClient chain element to set routes in vpp +// Client +// +---------------------------+ +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// | routes.NewClient() +-------------------+ +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// +---------------------------+ +// +func NewClient(vppConn api.Connection) networkservice.NetworkServiceClient { + return &routesClient{ + vppConn: vppConn, + } +} + +func (r *routesClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { + conn, err := next.Client(ctx).Request(ctx, request, opts...) + if err != nil { + return nil, err + } + if err := addDel(ctx, conn, r.vppConn, metadata.IsClient(r), true); err != nil { + _, _ = r.Close(ctx, conn, opts...) + return nil, err + } + return conn, nil +} + +func (r *routesClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { + if err := addDel(ctx, conn, r.vppConn, metadata.IsClient(r), false); err != nil { + return nil, err + } + return next.Client(ctx).Close(ctx, conn, opts...) +} diff --git a/pkg/networkservice/connectioncontext/ipcontext/routes/common.go b/pkg/networkservice/connectioncontext/ipcontext/routes/common.go new file mode 100644 index 00000000..fbca08ea --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/routes/common.go @@ -0,0 +1,108 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package routes + +import ( + "context" + "net" + "time" + + "git.fd.io/govpp.git/api" + "github.com/edwarnicke/govpp/binapi/fib_types" + "github.com/edwarnicke/govpp/binapi/interface_types" + "github.com/edwarnicke/govpp/binapi/ip" + "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/trace" + "github.com/pkg/errors" + + "github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex" + "github.com/networkservicemesh/sdk-vpp/pkg/tools/types" +) + +func addDel(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection, isClient, isAdd bool) error { + swIfIndex, ok := ifindex.Load(ctx, isClient) + if !ok { + return nil + } + from := conn.GetContext().GetIpContext().GetDstIPNet() + to := conn.GetContext().GetIpContext().GetSrcIPNet() + if isClient { + from = conn.GetContext().GetIpContext().GetSrcIPNet() + to = conn.GetContext().GetIpContext().GetDstIPNet() + } + routes := conn.GetContext().GetIpContext().GetDstRoutes() + if isClient { + routes = conn.GetContext().GetIpContext().GetSrcRoutes() + } + for _, route := range routes { + if err := routeAddDel(ctx, vppConn, swIfIndex, isAdd, route.GetPrefixIPNet(), to); err != nil { + return err + } + } + if to != nil && !to.Contains(from.IP) { + if err := routeAddDel(ctx, vppConn, swIfIndex, isAdd, to, nil); err != nil { + return err + } + } + return nil +} + +func routeAddDel(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex, isAdd bool, prefix, gw *net.IPNet) error { + if prefix == nil { + return errors.New("route prefix must not be nil") + } + route := route(prefix, swIfIndex, gw) + now := time.Now() + if _, err := ip.NewServiceClient(vppConn).IPRouteAddDel(ctx, &ip.IPRouteAddDel{ + IsAdd: isAdd, + IsMultipath: true, + Route: route, + }); err != nil { + return errors.WithStack(err) + } + trace.Log(ctx). + WithField("swIfIndex", swIfIndex). + WithField("prefix", prefix). + WithField("isAdd", isAdd). + WithField("type", isAdd). + WithField("duration", time.Since(now)). + WithField("vppapi", "IPRouteAddDel").Debug("completed") + return nil +} + +func route(dst *net.IPNet, via interface_types.InterfaceIndex, nh *net.IPNet) ip.IPRoute { + route := ip.IPRoute{ + StatsIndex: 0, + Prefix: types.ToVppPrefix(dst), + NPaths: 1, + Paths: []fib_types.FibPath{ + { + SwIfIndex: uint32(via), + TableID: 0, + RpfID: 0, + Weight: 1, + Type: fib_types.FIB_API_PATH_TYPE_NORMAL, + Flags: fib_types.FIB_API_PATH_FLAG_NONE, + Proto: types.IsV6toFibProto(dst.IP.To4() == nil), + }, + }, + } + if nh != nil { + route.Paths[0].Nh.Address = types.ToVppAddress(nh.IP).Un + } + return route +} diff --git a/pkg/networkservice/connectioncontext/ipcontext/routes/doc.go b/pkg/networkservice/connectioncontext/ipcontext/routes/doc.go new file mode 100644 index 00000000..a02e9a67 --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/routes/doc.go @@ -0,0 +1,18 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package routes - configure routes on vpp using vppagent when used as client or endpoint +package routes diff --git a/pkg/networkservice/connectioncontext/ipcontext/routes/server.go b/pkg/networkservice/connectioncontext/ipcontext/routes/server.go new file mode 100644 index 00000000..18631725 --- /dev/null +++ b/pkg/networkservice/connectioncontext/ipcontext/routes/server.go @@ -0,0 +1,74 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package routes + +import ( + "context" + + "git.fd.io/govpp.git/api" + "github.com/golang/protobuf/ptypes/empty" + "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" + + "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" +) + +type routesServer struct { + vppConn api.Connection +} + +// NewServer creates a NetworkServiceServer chain element to set the ip address on a vpp interface +// It sets the IP Address on the *vpp* side of an interface plugged into the +// Endpoint. +// Endpoint +// +---------------------------+ +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// +-------------------+ ipaddress.NewServer() | +// | | +// | | +// | | +// | | +// | | +// | | +// | | +// +---------------------------+ +// +func NewServer(vppConn api.Connection) networkservice.NetworkServiceServer { + return &routesServer{ + vppConn: vppConn, + } +} + +func (r *routesServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { + if err := addDel(ctx, request.GetConnection(), r.vppConn, metadata.IsClient(r), true); err != nil { + return nil, err + } + return next.Server(ctx).Request(ctx, request) +} + +func (r *routesServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { + if err := addDel(ctx, conn, r.vppConn, metadata.IsClient(r), false); err != nil { + return nil, err + } + return next.Server(ctx).Close(ctx, conn) +} diff --git a/pkg/tools/types/doc.go b/pkg/tools/types/doc.go new file mode 100644 index 00000000..738bdb85 --- /dev/null +++ b/pkg/tools/types/doc.go @@ -0,0 +1,18 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package types provides conversion from Go native types to vpp binapi types +package types diff --git a/pkg/tools/types/ip_types.go b/pkg/tools/types/ip_types.go new file mode 100644 index 00000000..453be6be --- /dev/null +++ b/pkg/tools/types/ip_types.go @@ -0,0 +1,55 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "net" + + "github.com/edwarnicke/govpp/binapi/ip_types" +) + +// ToVppAddress - converts addr to ip_types.Address +func ToVppAddress(addr net.IP) ip_types.Address { + a := ip_types.Address{} + if addr.To4() == nil { + a.Af = ip_types.ADDRESS_IP6 + ip := [16]uint8{} + copy(ip[:], addr) + a.Un = ip_types.AddressUnionIP6(ip) + } else { + a.Af = ip_types.ADDRESS_IP4 + ip := [4]uint8{} + copy(ip[:], addr.To4()) + a.Un = ip_types.AddressUnionIP4(ip) + } + return a +} + +// ToVppAddressWithPrefix - converts prefix to ip_types.AddressWithPrefix +func ToVppAddressWithPrefix(prefix *net.IPNet) ip_types.AddressWithPrefix { + return ip_types.AddressWithPrefix(ToVppPrefix(prefix)) +} + +// ToVppPrefix - converts prefix to ip_types.Prefix +func ToVppPrefix(prefix *net.IPNet) ip_types.Prefix { + length, _ := prefix.Mask.Size() + r := ip_types.Prefix{ + Address: ToVppAddress(prefix.IP), + Len: uint8(length), + } + return r +} diff --git a/pkg/tools/types/route.go b/pkg/tools/types/route.go new file mode 100644 index 00000000..477e791a --- /dev/null +++ b/pkg/tools/types/route.go @@ -0,0 +1,33 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "github.com/edwarnicke/govpp/binapi/fib_types" +) + +// IsV6toFibProto - returns fib_types.FIB_API_PATH_NH_PROTO_IP6 if isv6 is true +// fib_types.FIB_API_PATH_NH_PROTO_IP4 if isv6 is false +// Example: +// Given a *net.IPNet dst: +// types.IsV6toFibProto(dst.IP.To4() == nil) +func IsV6toFibProto(isv6 bool) fib_types.FibPathNhProto { + if isv6 { + return fib_types.FIB_API_PATH_NH_PROTO_IP6 + } + return fib_types.FIB_API_PATH_NH_PROTO_IP4 +}