Coverage for birdplan/bird_config/sections/protocols/kernel.py: 97%
31 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
1#
2# SPDX-License-Identifier: GPL-3.0-or-later
3#
4# Copyright (c) 2019-2024, AllWorldIT
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
19"""BIRD kernel protocol configuration."""
21from .base import SectionProtocolBase
23__all__ = ["ProtocolKernel"]
26class ProtocolKernel(SectionProtocolBase):
27 """BIRD kernel protocol configuration."""
29 def configure(self) -> None:
30 """Configure the kernel protocol."""
31 super().configure()
33 # Set section header
34 self._section = "Kernel Protocol"
36 # Configure the kernel protocol
37 self._configure_protocol_kernel("4")
38 self._configure_protocol_kernel("6")
40 def _configure_protocol_kernel(self, ipv: str) -> None:
41 """Protocol configuration."""
42 self.conf.add(f"protocol kernel kernel{ipv} {{")
43 self.conf.add(f' description "Kernel protocol for IPv{ipv}";')
44 self.conf.add("")
45 self.conf.add(f" vrf {self.birdconfig_globals.vrf};")
46 # If we have a routing table, add it
47 if self.birdconfig_globals.routing_table:
48 self.conf.add(f" kernel table {self.birdconfig_globals.routing_table};")
49 self.conf.add("")
50 self.conf.add(" metric 600; # Set the BIRD metric to be used when creating kernel routes to fall in line with our OS")
51 self.conf.add(" learn; # Learn routes from the kernel")
52 self.conf.add(" merge paths on; # Merge similar BGP paths into a multi-hop")
53 self.conf.add("")
54 self.conf.add(" netlink rx buffer 16777216; # Ensure our netlink buffer is big enough")
55 self.conf.add("")
56 self.conf.add(f" ipv{ipv} {{")
57 self.conf.add(f" table t_kernel{ipv};")
58 self.conf.add("")
59 self.conf.add(" export all;")
60 self.conf.add(" import all;")
61 self.conf.add(" };")
62 self.conf.add("};")
63 self.conf.add("")