Skip to content

Commit

Permalink
bgpd: Allow peering via 127.0.0.0/8
Browse files Browse the repository at this point in the history
There are some specific edge-cases when is a need to run FRR and another FRR
and/or another BGP implementation on the same box. Relaxing 127.0.0.0/8 for
this case might be reasonable.

An example below peering via 127.0.0.0/8 between FRR and GoBGP:

```
% ss -ntlp | grep 179
LISTEN   0         4096              127.0.0.1:179              0.0.0.0:*
LISTEN   0         128               127.0.0.2:179              0.0.0.0:*

% grep 127.0.0.2 /etc/frr/daemons
bgpd_options="   -A 127.0.0.1 -l 127.0.0.2"

% grep local /etc/gobgp/config.toml
    local-address-list = ["127.0.0.1"]

donatas-pc# sh ip bgp summary

IPv4 Unicast Summary (VRF default):
BGP router identifier 192.168.10.17, local AS number 65001 vrf-id 0
BGP table version 0
RIB entries 0, using 0 bytes of memory
Peers 1, using 725 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
127.0.0.1       4      65002         7         7        0    0    0 00:02:02            0        0 N/A

Total number of neighbors 1
donatas-pc#
```

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Mar 21, 2023
1 parent c8cba1b commit 8eb09e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,13 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,
peer->bgp->vrf_id);
}

/* Handle peerings via loopbacks. For instance, peer between
* 127.0.0.1 and 127.0.0.2. In short, allow peering with self
* via 127.0.0.0/8.
*/
if (!ifp && cmd_allow_reserved_ranges_get())
ifp = if_get_vrf_loopback(peer->bgp->vrf_id);

if (!ifp) {
/*
* BGP views do not currently get proper data
Expand Down
4 changes: 4 additions & 0 deletions doc/user/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ Basic Config Commands
Allow using IPv4 reserved (Class E) IP ranges for daemons. E.g.: setting
IPv4 addresses for interfaces or allowing reserved ranges in BGP next-hops.

If you need multiple FRR instances (or FRR + any other daemon) running in a
single router and peering via 127.0.0.0/8, it's also possible to use this
knob if turned on.

Default: off.

.. _sample-config-file:
Expand Down
2 changes: 1 addition & 1 deletion lib/prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ bool ipv4_unicast_valid(const struct in_addr *addr)
if (IPV4_CLASS_D(ip))
return false;

if (IPV4_CLASS_E(ip)) {
if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_E(ip)) {
if (cmd_allow_reserved_ranges_get())
return true;
else
Expand Down
5 changes: 1 addition & 4 deletions lib/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,8 @@ extern int macstr2prefix_evpn(const char *str, struct prefix_evpn *p);
/* NOTE: This routine expects the address argument in network byte order. */
static inline bool ipv4_martian(const struct in_addr *addr)
{
in_addr_t ip = ntohl(addr->s_addr);

if (IPV4_NET0(ip) || IPV4_NET127(ip) || !ipv4_unicast_valid(addr)) {
if (!ipv4_unicast_valid(addr))
return true;
}
return false;
}

Expand Down

0 comments on commit 8eb09e6

Please sign in to comment.