Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ A service for automating the management distributed switch or router based on EV
* **Reconciliation Loop Design:** Built on a closed-loop control architecture to ensure fault tolerance and reduce the impact of external factors
* **Configurability:** Flexible setup via INI daemon configuration files and JSON clients configuration files

Set `[ovs] restrict_tunnel_sources = True` to accept VXLAN ingress only
from source addresses learned as next hops in EVPN
Type 2, 3 and 5 routes. The connector updates this set automatically and
retains the source admission rules during a control-plane outage with fail-static
enabled. BGP peer addresses, including route reflectors, are not added merely
because they are peers. This relies on trusted EVPN announcements; it does
not authenticate the sender or prevent underlay source address spoofing.
The option defaults to `False`, preserving unrestricted tunnel source
admission for existing installations. When enabled, table 0 admits each VTEP
once and table 3 classifies VNIs without duplicating their rules per VTEP.
Legacy snapshot classifiers are moved behind this source check; qualified
snapshot rules also restore their permitted sources.

## Documentation
The details of the EVPN's operation and evpn-connector daemon workflow are described in the [presentation](https://vkvideo.ru/video-164978780_456239752) (in Russian only).

Expand Down
1 change: 1 addition & 0 deletions etc/evpn_connector/evpn_connector.cfg.sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source_ip = "10.10.10.2"
as_number = 1

[ovs]
restrict_tunnel_sources = False
switch_name = "evpn"
vxlan_udp_port = 4789
enable_sudo = True
Expand Down
8 changes: 8 additions & 0 deletions evpn_connector/bgp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def __init__(self, gobgp_channel, grpc_timeout_sec, router_mac_type5):
self._router_mac_type5 = router_mac_type5
self.gobgp_channel = gobgp_channel
self.timeout_seconds = grpc_timeout_sec
self.vtep_addresses = set()
self.bgp_origin = Any()
self.bgp_origin.Pack(attribute_pb2.OriginAttribute(origin=BGP_ORIGIN))

Expand Down Expand Up @@ -592,6 +593,7 @@ def _get_paths_from_gobgp(self, prefix_type):

def _get_paths(self):
"""Get paths from GoBGP"""
self.vtep_addresses.clear()
return (
self._get_obj(constants.EVPN_MACADV_TYPE),
self._get_obj(constants.EVPN_MULTICAST_TYPE),
Expand All @@ -604,6 +606,12 @@ def _get_obj(self, prefix_type):
req = self._get_paths_from_gobgp(prefix_type=prefix_type)
start_time = time.time()
for line in req:
for path in line.destination.paths:
for attribute in path.pattrs:
if attribute.type_url == MPREACHNLRI_TYPE_NAME:
self.vtep_addresses.update(
unpack_protobuf_message(attribute).next_hops
)
simplify_func = self.simplify_map[prefix_type]
func_res = simplify_func(line.destination)
if type(func_res) is list:
Expand Down
1 change: 1 addition & 0 deletions evpn_connector/cmd/evpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def main():
policy_enabled=CONF.gobgp.policy_enabled,
fail_static=CONF.gobgp.fail_static,
fail_static_min_peers=CONF.gobgp.fail_static_min_peers,
restrict_tunnel_sources=CONF.ovs.restrict_tunnel_sources,
configs_dir=CONF.daemon.configs_dir,
router_mac_type5=CONF.gobgp.router_mac_type5,
anycast_status_file=CONF.anycast.anycast_status_file,
Expand Down
8 changes: 8 additions & 0 deletions evpn_connector/common/conf_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@
]

ovs_opts = [
cfg.BoolOpt(
name="restrict_tunnel_sources",
default=False,
help=(
"Accept VXLAN ingress only from next-hop addresses learned "
"in EVPN Type 2, 3 and 5 routes. Requires trusted EVPN routes."
),
),
cfg.StrOpt(
name="switch_name", required=True, help="OpenvSwitch switch name"
),
Expand Down
1 change: 1 addition & 0 deletions evpn_connector/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
INPUT_FILTER_TABLE_NUM = 0
OUTPUT_TABLE_NUM = 1
ECMP_TABLE_NUM = 2
TUNNEL_CLASSIFY_TABLE_NUM = 3
# Priority for flows
NORMAL_PRIO = 10
LOW_PRIO = 9
Expand Down
12 changes: 10 additions & 2 deletions evpn_connector/service/evpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from evpn_connector.common.services import softirq
from evpn_connector.service import objects as evpnobj


LOG = logging.getLogger(__name__)
COMMON_NAME = "local-vni-"
# Steps a session must outlive when nothing reports End-of-RIB.
Expand Down Expand Up @@ -81,6 +80,7 @@ def __init__(
policy_enabled=True,
fail_static=False,
fail_static_min_peers=0,
restrict_tunnel_sources=False,
):
super(EvpnConnectorService, self).__init__(
step_period=step_period,
Expand Down Expand Up @@ -108,6 +108,7 @@ def __init__(
# converged, retained if one is later lost.
self.fail_static = fail_static
self.fail_static_min_peers = fail_static_min_peers
self.restrict_tunnel_sources = restrict_tunnel_sources
self._peer_settle_sec = PEER_SETTLE_STEPS * step_period
self._last_good_flows = set()
self._peers_healthy = True
Expand Down Expand Up @@ -439,6 +440,10 @@ def _apply_fail_static(self, target_flows, metrics, peers_were_healthy):
return target_flows

flows_to_sync = target_flows.union(self._last_good_flows)
if self.restrict_tunnel_sources:
flows_to_sync = evpnobj.restrict_tunnel_sources(
flows_to_sync, set()
)
metrics["fail_static_active"] = 1
metrics["fail_static_retained_cnt"] = len(flows_to_sync) - len(
target_flows
Expand Down Expand Up @@ -680,18 +685,21 @@ def _step(self):
len(uni_flows),
len(bum_flows),
)
metrics["ovs_flow_cnt"] = len(uni_flows) + len(bum_flows)
duration_metrics["prep_ovs_time"] = time.time() - start_time
LOG.info(
"Prepare ovs flows done for %0.4f sec",
duration_metrics["prep_ovs_time"],
)

uni_flows = uni_flows.union(bum_flows)
if self.restrict_tunnel_sources:
sources = self.gobgp_client.vtep_addresses - {self.source_ip}
uni_flows = evpnobj.restrict_tunnel_sources(uni_flows, sources)

flows_to_sync = self._apply_fail_static(
uni_flows, metrics, peers_were_healthy
)
metrics["ovs_flow_cnt"] = len(flows_to_sync)

start_time = time.time()
LOG.debug("Sync flows in ovs")
Expand Down
43 changes: 41 additions & 2 deletions evpn_connector/service/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from evpn_connector.common import constants
from evpn_connector.ovs import common as ovs_cm


LOG = logging.getLogger(__name__)

# Whether the fabric carries a sender's group: switch-wide, set at start-up.
Expand Down Expand Up @@ -151,7 +150,6 @@ def _ovs_filter_match(
if self.port_type == constants.EVPN_EDGE_TYPE_VLAN:
res += "in_port=%d,dl_vlan=%d" % (ofport, self.tag)
elif self.port_type == constants.EVPN_EDGE_TYPE_VXLAN:
# TODO(aleks.popov): May be add remote ip filter?
res += "in_port=%d,tun_id=%d" % (ofport, self.vni)
# Type: flat
else:
Expand Down Expand Up @@ -220,6 +218,47 @@ def __lt__(self, other):
return NotImplemented


def restrict_tunnel_sources(flows, sources):
table = constants.TUNNEL_CLASSIFY_TABLE_NUM
restricted = {OvsDropFlow(table)}
sources = set(sources)
tunnel_port = "in_port=%d" % constants.VXLAN_PORT_OFPORT
gate_action = "resubmit(,%d)" % table
for flow in flows:
fields = flow.match.split(",")
if "table=0" not in fields or tunnel_port not in fields:
restricted.add(flow)
continue
source_fields = {
field
for field in fields
if field.startswith(("tun_src=", "tun_ipv6_src="))
}
sources.update(field.split("=", 1)[1] for field in source_fields)
if flow.action.split("=", 1)[1] == gate_action:
continue
restricted.add(
OvsFlow(
match=",".join(
"table=%d" % table if field == "table=0" else field
for field in fields
if field not in source_fields
),
action=flow.action,
)
)
for source in sources:
field = "tun_ipv6_src" if ":" in source else "tun_src"
restricted.add(
OvsFlow(
match="table=0,priority=%d,%s,%s=%s"
% (constants.NORMAL_PRIO, tunnel_port, field, source),
action="actions=" + gate_action,
)
)
return restricted


class OvsDropFlow(OvsFlow):
def __init__(self, table):
super(OvsDropFlow, self).__init__(
Expand Down
62 changes: 62 additions & 0 deletions evpn_connector/tests/unit/test_bgp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# under the License.

import mock
import pytest

from evpn_connector.bgp import client
from evpn_connector.bgp.generated import gobgp_pb2
from evpn_connector.common import constants
from evpn_connector.service import objects


Expand Down Expand Up @@ -231,3 +233,63 @@ def test_an_unset_uptime_is_not_trusted(self):
peer = self._peer(uptime=0)
with mock.patch("time.time", return_value=1005):
assert self._count([peer], settle_sec=10) == (1, 0)


class TestVtepSources(object):
@pytest.mark.parametrize(
"route_type",
[
constants.EVPN_MACADV_TYPE,
constants.EVPN_MULTICAST_TYPE,
constants.EVPN_PREFIX_TYPE,
],
)
def test_all_paths_supply_vtep_sources(self, route_type):
bgp = client.BGPClient("127.0.0.1:50051", 1, "02:00:00:00:00:01")
common = dict(
vni=10000,
as_number=65001,
next_hop="10.10.10.2",
rt=objects.RouteTarget([(65001, 10000)]),
)
if route_type == constants.EVPN_MULTICAST_TYPE:
route = objects.VirtNet(**common)
prepare = bgp.prepare_multicast_path
else:
common.update(
mac="02:00:00:00:00:02", ofport=65278, port_type="vxlan", tag=0
)
if route_type == constants.EVPN_MACADV_TYPE:
route = objects.ClientEdge(ip="10.100.0.1", **common)
prepare = bgp.prepare_unicast_path
else:
route = objects.ClientEdgePrefix(
prefix="10.100.0.1",
prefix_len=32,
router_mac="02:00:00:00:00:03",
**common,
)
prepare = bgp.prepare_prefix_path
first = prepare(route)
route.next_hop = "10.10.10.3"
second = prepare(route)
destination = gobgp_pb2.Destination(paths=[first, second])
response = gobgp_pb2.ListPathResponse(destination=destination)
bgp._get_paths_from_gobgp = mock.Mock(
side_effect=(
lambda prefix_type: (
[response] if prefix_type == route_type else []
)
)
)
bgp.get_paths(local_next_hop="10.10.10.1")
assert bgp.vtep_addresses == {"10.10.10.2", "10.10.10.3"}
route.next_hop = "10.10.10.4"
destination.ClearField("paths")
destination.paths.add().CopyFrom(prepare(route))
response.destination.CopyFrom(destination)
bgp.get_paths(local_next_hop="10.10.10.1")
assert bgp.vtep_addresses == {"10.10.10.4"}
bgp._get_paths_from_gobgp = mock.Mock(return_value=[])
bgp.get_paths(local_next_hop="10.10.10.1")
assert not bgp.vtep_addresses
Loading
Loading