Commit graph

364 commits

Author SHA1 Message Date
Philippe Guibert dee1c6c338 nhrpd: move prototype to top of file
nhrp prototype function was not declared at top of the file.
fixing it.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
Philippe Guibert db51f0cd10 nhrp: Preserve mtu during interface up/down and tunnel source change
preserve mtu upon interface flapping and tunnel source change.

Signed-off-by:Reuben Dowle <reuben.dowle@4rf.com>
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
Philippe Guibert 372b887859 nhrpd: clean up SA warning with strncpy
strncpy is replaced by strlcpy.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
Philippe Guibert aea6c49e01 nhrpd: cleaning netlink gre information
flush netlink related dependencies with gre information.
Add some linux headers required to compile with it.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
Philippe Guibert 7f48cfa5e4 nhrpd: redirect netlink gre with zebra
as zebra has a new api to get gre and set gre source commands,
netlink gre get and netlink gre source function calls are redirected to zebra
by using the zapi interface.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
David Lamparter 642ac49da4 *: remaining zassert => assert
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-23 12:25:51 +02:00
David Lamparter 6a0eb6885b *: drop zassert.h
It's not actually working properly...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-23 12:06:35 +02:00
David Lamparter 09781197b6 build: make builddir include path consistent
... by referencing all autogenerated headers relative to the root
directory.  (90% of the changes here is `version.h`.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-21 15:42:33 +02:00
Mark Stapp f5a1fb4f32 nhrpd: fix coverity warning about os_socket()
Ensure we don't try to use an invalid fd in nhrpd, reported
by coverity.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-04-14 09:57:41 -04:00
Jafar Al-Gharaibeh d75213d260
Merge pull request #8153 from reubendowle/nhrp-multicast
nhrp, ospf: add nhrp multicast for OSPF DMVPN
2021-04-13 12:49:28 -05:00
Philippe Guibert a8807299ef nhrpd: remove useless typedef
this typedef was useless. remote it.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-13 08:58:54 +02:00
Philippe Guibert d603c0774e nhrp, zebra, lib: enforce usage of zapi_neigh_ip structure
zapi_nbr structure is renamed to zapi_neigh_ip.
Initially used to set a neighbor ip entry for gre interfaces, this
structure is used to get events from the zebra layer to nhrp layer.

The ndm state has been added, as it is needed on both sides.
The zebra dplane layer is slightly modified.

Also, to clarify what ZEBRA_NEIGH_ADD/DEL means, a rename is done:
it is called now ZEBRA_NEIGH_IP_ADD/DEL, and it signified that this
zapi interface permits to set link operations by associating ip
addresses to link addresses.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-13 08:58:49 +02:00
Philippe Guibert 850b2b70ac nhrp: avoid crashing when terminating interface contexts
avoid crashing when terminating interface contexts.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-12 19:23:57 +02:00
Philippe Guibert f468a45af2 nhrpd: add a zebra api to configure neighbor table per interface
neighbor table per interface is being configured per interface, via
zebra api.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-12 19:23:53 +02:00
Philippe Guibert 05657ec2b7 nhrp, lib, zebra: add/del neighbor entry possible from nhrp
a zebra api is extended to offer ability to add or remove neighbor
entry from daemon. Also this extension makes possible to add neigh
entry, not only between IPs and macs, but also between IPs and NBMA IPs.
This API supports configuring ipv6/ipv4 entries with ipv4/ipv6 lladdr.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-09 18:29:58 +02:00
Philippe Guibert b3b7510464 nhrpd: link layer registration to notifications
neighbor notifications are done in zebra. so, instead of relying on
nhrp, rely on zebra by using zebra api interface.
Consequently, the code originally used in nhrp for netlink neighor
notification is no more used.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-09 18:29:58 +02:00
Philippe Guibert e8263bdb77 nhrpd: use CALLOC instead of MALLOC
in order to apply a memset to a non initialised structure, use CALLOC
instead of MALLOC

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-09 18:29:58 +02:00
Philippe Guibert 4030737044 nhrpd: lookup appropriate ipsec path
lookup appropriate ipsec path. there are systems where the path where
the charon.vici file is not in standard paths. For that, 'ipsec
--piddir' may help in solving the path.

result of ipsec --piddir is as follow for example:
'
/etc/ike/ipsec.d/run
'

Note that the assumption is done that even if there are several
instances of strongswan across the vrfs, the charon.vici path file is
the same across vrfs. Consequently, as there is a thread per vrf that
performs vici initialisation, and file path retrieval is part of the
vici initialisation procedure, in order to avoid intempestive system
calls, use a boolean 'vici_charon_filepath_done' to avoid doing
unnecessary calls.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-09 18:29:58 +02:00
Reuben Dowle 46d3c1859b nhrpd: Change sockunion2str to %pSU in a few places
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-08 08:45:51 +12:00
Donald Sharp 2a1fa50ecf nhrpd: Fixup tab usage and sockunion2str usage
For some reason the usage of tabs in a string snuck in as well
as using a sockunion2str instead of %pSU.  Fix.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-04-06 10:09:48 -04:00
Reuben Dowle c2bb9917b1 nhrpd: Fix style issues
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Reuben Dowle 4946316150 nhrpd: Add missing semicolon
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Reuben Dowle 32ff81f6c9 nhrpd: Improve debug message for multicast interception
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Reuben Dowle 63c0a73559 nhrpd: Cleanup multicast nflog handler function
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Amol Lad 9084e20961 nhrpd: Introduce new - nflog mutlicast-nflog-group (1-65535) - command
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Reuben Dowle 9f7f6d3c6b nhrpd: Use ethertype defines instead of hard-coded values
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Reuben Dowle ca317495b8 nhrpd: Use strlcpy not unsafe strncpy
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Reuben Dowle 0f8595a9f4 nhrpd: Fix style violation issues
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +12:00
Reuben Dowle 4f7a37ace3 nhrpd: Use correct printf format specifier
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:22:59 +12:00
Reuben Dowle 0da7701aa2 nhrpd: Fix multicast crash due to dangling references to nhrp peers
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:22:59 +12:00
Amol Lad fa31fcf2ea nhrpd: Add support for forwarding multicast packets
Forwarding multicast is a pre-requisite for allowing multicast based routing
protocols such as OSPF to work with DMVPN

This code relies on externally adding iptables rule. For example:
iptables -A OUTPUT -d 224.0.0.0/24 -o gre1 -j NFLOG --nflog-group 224

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:22:59 +12:00
Jafar Al-Gharaibeh 283981e4a7
Merge pull request #8240 from reubendowle/fixes/nhrp-nat
nhrp: NAT fixes
2021-04-03 22:37:25 -05:00
Reuben Dowle ba113ac64e nhrpd: Fix memory leak in error path when forwarding packets
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-01 14:52:15 +13:00
Reuben Dowle d0c9d09aa9 nhrpd: Ensure invalid pointer is not used if two NAT extensions received
Also cleanup some minor style issues

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-01 14:06:24 +13:00
Philippe Guibert 0551aeadff nhrpd: Make some debug prints more informative
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-29 10:21:16 +13:00
Amold Lad bcf5673d61 nhrpd: Display post-nat NBMA for local addresses
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-29 10:17:19 +13:00
Reuben Dowle 6baf035ce3 nhrpd: Remove unecessary new line from debug messages
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-29 10:17:18 +13:00
Donatas Abraitis 37916b2b11
Merge pull request #8121 from opensourcerouting/macro-cleanup
*: require ISO C11 + semicolons after file-scope macros
2021-03-22 11:00:34 +02:00
Reuben Dowle 4ddc702ad2 nhrpd: Use %pSU instead of sockunion2str
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-19 19:10:53 +13:00
Reuben Dowle 00683a1479 nhrpd: Fix some style issues
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-19 09:31:45 +13:00
Donald Sharp dccd71c182 nhrpd: Remove newline from log message
We should not be putting new lines in log messages.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-03-18 10:32:01 -04:00
Amol Lad e8089de123 nhrpd: Set prefix length in NAT extension in resolution-reply
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Reuben Dowle 9025515c25 nhrpd: Ensure invalid NAT extension info cannot be used
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Reuben Dowle 18cc9c4293 nhrpd: Use SU_ADDRSTRLEN where appropriate
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad 611915ae89 nhrpd: populate correct prefix length in NAT extension in Reg-Reply
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad 85365e51f0 nhrpd: Add Claimed NBMA field in sh ip nhrp cache output
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad 94eae49d01 nhrpd: add NHS details in NAT Extension header
Hub uses this to check if is itself behind a NAT

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad 1bd508da17 nhrpd: copy NAT extension if present else attempt to populate
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad 9c292647a9 nhrpd: parse multiple CIEs in NAT extension header
Cisco devices send can send multiple CIEs so we must search for the correct CIE

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad 5e70e83b9e nhrpd: Add empty NAT extension header for Non Natted Spoke in Resolution-Reply
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad 1e52c95464 nhrpd: Set correct MTU in NHRP extensions
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Reuben Dowle 999a07f0d4 nhrpd: Send prefix length in NAT extension the same as is done by Cisco
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Gaurav Goyal c2cffffb37 nhrpd: Add CIE to NAT extension in resolution requests
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Gaurav Goyal b5fc78c068 nhrpd: Add NAT extension in forwarded packets
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Gaurav Goyal bb58f44259 nhrpd: Process NAT extension properly, and also fallback to IPSec NAT info
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
Amol Lad d5dc926f18 nhrpd: Add zbuf routine to peek at contents
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-18 16:35:41 +13:00
David Lamparter 80413c2073 *: require semicolon after FRR_DAEMON_INFO & co.
... again ...

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:39 +01:00
David Lamparter bf8d3d6aca *: require semicolon after DEFINE_MTYPE & co
Back when I put this together in 2015, ISO C11 was still reasonably new
and we couldn't require it just yet.  Without ISO C11, there is no
"good" way (only bad hacks) to require a semicolon after a macro that
ends with a function definition.  And if you added one anyway, you'd get
"spurious semicolon" warnings on some compilers...

With C11, `_Static_assert()` at the end of a macro will make it so that
the semicolon is properly required, consumed, and not warned about.

Consistently requiring semicolons after "file-level" macros matches
Linux kernel coding style and helps some editors against mis-syntax'ing
these macros.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:17 +01:00
David Lamparter 15c05f1edf *: require ISO C11 (or C++11)
It's 2021... time to drop some 10yo compat stuff.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:17 +01:00
Gaurav Goyal 58ef1668ae nhrpd: When IPsec profile is added or deleted, reset the vc and re-check peer
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-17 17:03:47 +13:00
Reuben Dowle 74e5ba3a3f nhrpd: Make comments clearer, fix style issues
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-17 17:02:19 +13:00
Gaurav Goyal 083bbfaebf nhrpd: Close IPSec connection when tunnel protection removed
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-17 16:56:46 +13:00
Gaurav Goyal 4cbaf956f6 nhrpd: Retry IPSec if NHRP is repeatedly failing
This prevents a failed IPSec connection from preventing DMVPN from working.
A failure situation can be reproduced using a Cisco peer, and and disabling then
re-enabling the tunnel IPSec protection (after the IPSec connection has
already been established).

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-17 16:56:46 +13:00
Gaurav Goyal 6f8817b4cf nhrpd: Set hop count to 1 in traffic indication
If hop count is 0, this causes Cisco routers to reject the traffic indication
as invalid. This appears to be a Cisco bug, and has been observed in processing
of registration packets in the past. That problem was covered in issue #951

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-03-15 10:04:43 +13:00
Quentin Young 20a92a97c2
Merge pull request #8177 from Jafaral/nhrp-ev-handler 2021-03-10 16:35:55 -05:00
Joe Maimon f0a717ce2a nhrp: enables the event system to interpret client results correctly
Signed-off-by: Joe Maimon <jmaimon@jmaimon.com>
2021-03-10 11:31:25 -06:00
Donald Sharp b6c4848171 nhrpd: Use our built-in printf functionality
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-03-10 07:25:49 -05:00
Donald Sharp 8ca7a3ed38 nhrpd: Fix clang SA about null deref
Clang was complaining when running SA that the nhrpd_privs.change
function was null.  It just does not fully understand how things
are setup.  Add a assert to make it happy.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-02-14 16:04:16 -05:00
Jafar Al-Gharaibeh b1b277fbd2
Merge pull request #7764 from pguibert6WIND/nhrp_shortcut_routes
nhrp: fix shortcut routes
2021-02-12 13:34:40 -06:00
Philippe Guibert a3e520f37b nhrpd: replace nhrp route nexthop with onlink route when prefix=nh
There are cases where nhrp wants to create a nhrp route to gre interface
with the nexthop which is the same the prefix. This is the case with
ipv6:

ipv6 route a:ff::ff:4/128 via a:ff::ff:4:/128 dev gre1

This route entry is false from zebra point of view, and to avoid that,
the nexthop is ignored in nhrp only if the prefix equals the nexthop.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-02-11 09:06:32 +01:00
Philippe Guibert ef91ff0468 nhrpd: shortcut routes installed with nexthop.
Previously, when a shortcut entry was created, its associated route was
created on system, with no nexthop, only gre device. eg:

[..]
N>* 192.168.2.0/24 [10/0] is directly connected, gre1, 00:01:04           <--- can not be resolved

[..]
Type     Prefix                   Via                      Identity
dynamic  192.168.2.0/24           10.255.255.2             				<---- correct

This situation was forcing neighbor resolution on the first outgoing packet matching the route entry. for instance 192.168.2.1 could not be resolved at link layer, and was going to fail. Instead, nhrp nexthop should have been used.
This is what this commit intends to do, that is to say that when a
shortcut is installed by nhrp, the associated nexthop entry is used.

[..]
N>* 192.168.2.0/24 [10/0] via 10.255.255.2, gre1 onlink, 00:00:31

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-02-11 09:06:28 +01:00
Mark Stapp fca58b0e4e libs,nhrpd: remove exec perm
Some source files got the exec bit set in a recent commit - undo
that.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-01-12 08:20:10 -05:00
Reuben Dowle ee72f0a0eb nhrpd: Cleanup resources when interface is deleted
Currently when an interface is deleted from configuration, associated
resources are not freed. This causes memory leaks and crashes.

To reproduce this issue:
* Connect to a DMVPN hub
* Outside of frr, delete the underlying GRE interface
* Use 'no interface xxx' to delete the interface containing nhrp configurations

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:17:13 +13:00
Gaurav Goyal 6c9ca58766 nhrpd: Only create one child sa
In some circumstances, especicially when GRE tunnel interface does not exist,
repeated child sa requests are sent. Prevent this by only sending another
request if the child sa does not exist

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:17:13 +13:00
Gaurav Goyal 659fde26e0 nhrpd: Use MTU received in registration in nhs cache
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:17:13 +13:00
Gaurav Goyal ac95bcefe4 nhrpd: Create route to private spoke-spoke network correctly
Currently when the first traffic to a private network causes a shortcut, an
on-link route to the private network is created on the gre interface, along
with the cache entry.

When connecting to a second IP in the same network, the kernel tries to resolve
the public IP for this private network via query to NHRP. nhrpd sees no entry
in the cache, so the packet is dropped.

The fix to this solution can be instead of creating an on-link route, create an
off-link route to private network, with the next-hop being the remote tunnel's
gre IP address.

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:17:13 +13:00
Gaurav Goyal ddd8d8c845 nhrpd: Clear shortcut routes properly for all protocols
Currently when nhrp shortcuts are purged they will not be recreated. This
patch fixes that by ensuring the shortcut routes get purged correctly.

This situation can be reproduced by first allowing a shortcut to be created
then clearing the shortcut:
clear ip nhrp cache
clear ip nhrp shortcuts

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:17:07 +13:00
Timo Teräs 46d380217d nhrpd: add reference to net.ipv4.ip_forward_use_pmtu=1 thread
Add a mailing list reference regard net.ipv4.ip_forward_use_pmtu=1.

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:04:13 +13:00
Timo Teräs 6cfd90f353 nhrpd: change ipsec SA count to 32-bit
Under certain misconfigurations, the SA count can be unusually high
and wrap 8-bit counter. That leads to premature free, and crash.
Make the count 32-bit to avoid crash in these rare conditions.

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:04:12 +13:00
Amol Lad f7f9a3770e nhrpd: Set correct prefix length in nhrp registration
RFC2332 section 5.2.1 states (regarding the uniqueness bit) that:

       Note that when this bit is set in an NHRP Registration Request, only a
       single CIE may be specified in the NHRP Registration Request and that
       CIE must have the Prefix Length field set to 0xFF. the prefix length is
       the widest acceptable destination protocol address prefix. However, if
       "Uniqueness" bit is set  then it must be 255

This patch implements this requirement, which fixes interoperability with Cisco
NHRP hub routers.

Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2020-12-17 10:03:14 +13:00
Mark Stapp e5773617af nhrpd: fix SA warning in nhrp_interface
Clear SA warning from recent nhrp cache code changes.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-12-08 09:10:10 -05:00
Philippe Guibert fef2ed139d nhrpd: cache config may disappear if iface not present at startup
When interface not present at config time, store separately the list of
config parameters. Then, when interface is ready and an address has been configured, the nbma setting is done. Reversely, when interface disappears,
there is no need to keep the maps present, then keep only the configuration.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-11-23 17:16:35 +00:00
Donald Sharp 0154d8ce45 bgpd, lib, nhrpd, zebra: verify return of sockunion2hostprefix
The return from sockunion2hostprefix tells us if the conversion
succeeded or not.  There are places in the code where we
always assume that it just `works`, since it can fail
notice and try to do the right thing.

Please note that failure of this function for most cases
of sockunion2hostprefix is highly highly unlikely as that
the sockunion was already created and tested elsewhere
it's just that this function can fail.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-18 11:04:27 -05:00
Donald Sharp 7df171f59a nhrpd: Fix memory leak on shutdown
On shutdown we were blantantly dropping the node->info
data.  Make it happy.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-06 20:56:02 -05:00
Mark Stapp 5047884528 *: unify thread/event cancel macros
Replace all lib/thread cancel macros, use thread_cancel()
everywhere. Only the THREAD_OFF macro and thread_cancel() api are
supported. Also adjust thread_cancel_async() to NULL caller's pointer (if
present).

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-10-23 12:16:52 -04:00
Donatas Abraitis 2dbe669bdf :* Convert prefix2str to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-22 09:07:41 +03:00
Zoran Pericic 354196c027 nhrp: Make vici socket path configurable
nhrp: Configure vici socket path using

configure --with-vici-socket=/var/run/charon.vici

If not specified default to /var/run/charon.vici

Signed-off-by: Zoran Peričić <zpericic@netst.org>
2020-10-12 19:34:53 +02:00
Renato Westphal 8b6b6b694d
Merge pull request #7222 from idryzhov/fix-debug
fix debug commands node inconsistencies
2020-10-09 21:58:24 -03:00
Igor Ryzhov d7b86ae4fe vtysh: dynamically generate the list of daemons for commands
Some daemons were actually missing from the static definitions: nhrpd,
babeld, eigrpd and bfdd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-10-02 15:06:27 +03:00
Igor Ryzhov dd73744d8c *: move "show debugging ..." commands to enable node
Use the same node for "show debugging" commands in all daemons.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-10-02 15:06:05 +03:00
Renato Westphal f267201bf5 lib: fix crashes with leafrefs that point to non-implemented modules
Whenever libyang loads a module that contains a leafref, it will
also implicitly load the module of the referring node if it's
not loaded already. That makes sense as otherwise it wouldn't be
possible to validate the leafref value correctly.

The problem is that loading a module implicitly violates the
assumption of the northbound layer that all loaded modules
are implemented (i.e. they have a northbound node associated
to each schema node). This means that loading a module that
isn't implemented can lead to crashes as the "priv" pointer
of schema nodes is no longer guaranteed to be valid. To fix this
problem, add a few null checks to ignore data nodes associated
to non-implemented modules.

The side effect of this change is harmless. If a daemon receives
configuration it doesn't support (e.g. BFD peers on staticd),
that configuration will be stored but otherwise ignored. This can
only happen when using a northbound client like gRPC, as the CLI
will never send to a daemon a command it doesn't support. This
minor problem should go away in the long run as FRR migrates to
a centralized management model, at which point the YANG-modeled
configuration of all daemons will be maintained in a single place.

Finally, update some daemons to stop implementing YANG modules
they don't need to (i.e. revert 1b741a01c and a74b47f5).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-09-11 14:42:35 -03:00
Donald Sharp 1b741a01c6 nhrpd: add frr-vrf to the list of implemented yang modules
PR #6376 introduced a VRF leafref in the frr-interface YANG module.
That change exposed a bug in the northbound layer that is causing
nhrpd to crash under certain circumstances. Even though nhrpd wasn't
converted to the new northbound model yet, make it implement the
frr-vrf module in order to work around this problem. This is a
temporary fix until a better solution is available.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-09-11 08:51:05 -04:00
Philippe Guibert b598a1458c nhrpd: ignore zebra updates about our routes being deleted/added
nhrp listens for route entries to be deleted, in case some new routes
impact the current routes installed by nhrp. To prevent from
unconfiguring nhrp shortcut route, just prevent nhrp routes to be
processed.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-07-31 13:50:57 +02:00
David Lamparter 3efd0893d0 *: un-split strings across lines
Remove mid-string line breaks, cf. workflow doc:

  .. [#tool_style_conflicts] For example, lines over 80 characters are allowed
     for text strings to make it possible to search the code for them: please
     see `Linux kernel style (breaking long lines and strings)
     <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_
     and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --unwrap `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:37:25 +02:00
Rafael Zalamena fb7f5aa8d6 *: integrate remaining daemons with filter
Don't crash when trying to `show running-config` because of missing
filter northbound integration.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-06-05 14:36:54 -03:00
David Lamparter 2768748b88 build: use VPATH for vtysh_scan
No need to put $(top_srcdir) everywhere.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-04-27 09:30:01 +02:00
Quentin Young 2b7165e76f *: use appropriate buffer sizes, specifiers
- Fix 1 byte overflow when showing GR info in bgpd
- Use PATH_MAX for path buffers
- Use unsigned specifiers for uint16_t's in zebra pbr

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-20 19:14:33 -04:00
Quentin Young 772270f3b6 *: sprintf -> snprintf
Replace sprintf with snprintf where straightforward to do so.

- sprintf's into local scope buffers of known size are replaced with the
  equivalent snprintf call
- snprintf's into local scope buffers of known size that use the buffer
  size expression now use sizeof(buffer)
- sprintf(buf + strlen(buf), ...) replaced with snprintf() into temp
  buffer followed by strlcat

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-20 19:14:33 -04:00
David Lamparter f4b8291fcb *: move CLI node names to cmd_node->name
And again for the name.  Why on earth would we centralize this, just so
people can forget to update it?

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:59 +02:00
David Lamparter 243895805a *: move CLI parent data to cmd_node->parent_node
Same as before, instead of shoving this into a big central list we can
just put the parent node in cmd_node.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter 612c2c15d8 *: remove second parameter on install_node()
There is really no reason to not put this in the cmd_node.

And while we're add it, rename from pointless ".func" to ".config_write".

[v2: fix forgotten ldpd config_write]

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter 249a771b63 *: remove cmd_node->vtysh
The only nodes that have this as 0 don't have a "->func" anyway, so the
entire thing is really just pointless.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
Donald Sharp e0a1fb2235 nhrpd: Actually allow json output
Add the correct pointer check to see if we should
be doing json output.

Discovered by SA.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-04-15 09:25:54 -04:00
Donatas Abraitis c4efd0f423 *: Do not cast to the same type
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-04-08 17:15:06 +03:00
Donatas Abraitis d03e644c2b
Merge pull request #5825 from pguibert6WIND/nhrp_vty
nhrpd: add json support to show nhrp vty commands
2020-03-22 14:21:42 +02:00
Donald Sharp fc07143bf8
Merge pull request #6043 from pguibert6WIND/nhrp_clear_cache
nhrpd: fix clear nhrp cache dynamic entries
2020-03-20 18:22:51 -04:00
Philippe Guibert db89e514c7 nhrpd: fix clear nhrp cache dynamic entries
as the helper said, the dynamic cache entries should be flushed once the
vty command 'clear ip/ipv6 nhrp cache' mentions. This was not the case.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-03-19 12:09:06 +01:00
Philippe Guibert 87b9e98203 nhrpd: add json support to show nhrp vty commands
- add json support for show nhrp vty commands.
- support for 'show dmvpn [json]' format.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-03-13 16:58:14 +01:00
Ghasem Naddaf 5f36c26c5f nhrpd: resolve formatting warnings
Signed-off-by: Ghasem Naddaf <gshirazi@infoblox.com>
2020-03-11 12:50:10 -07:00
Ghasem Naddaf 31384f929a Merge branch 'master' into nhrp_bugfix 2020-03-11 09:50:54 -07:00
Donald Sharp ac0442fccb
Merge pull request #5922 from pguibert6WIND/nhrp_override_fix
Revert "nhrpd: ignore zebra updates about our routes being deleted/ad…
2020-03-08 20:03:14 -04:00
Donatas Abraitis 0d6f7fd6fd *: Replace sizeof something to sizeof(something)
Satisfy checkpatch.pl requirements (check for sizeof without parenthesis)

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-08 21:44:53 +02:00
Philippe Guibert 43c27dd19a Revert "nhrpd: ignore zebra updates about our routes being deleted/added"
This reverts commit d0bfe25dea.
2020-03-06 12:14:59 +01:00
Quentin Young 498897d8d8
Merge pull request #5918 from ton31337/fix/__func__everywhere
__func__ everywhere
2020-03-05 17:37:03 -05:00
Donatas Abraitis 15569c58f8 *: Replace __PRETTY_FUNCTION__/__FUNCTION__ to __func__
Just keep the code cool.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-05 20:23:23 +02:00
Philippe Guibert d0bfe25dea nhrpd: ignore zebra updates about our routes being deleted/added
nhrp listens for route entries to be deleted, in case some new routes
impact the current routes installed by nhrp. To prevent from
unconfiguring nhrp shortcut route, just prevent nhrp routes to be
processed.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-03-05 16:04:53 +01:00
Ghasem Naddaf 912c556b3a nhrpd: route update support for natoa nbma
nhrp_cache_update_route, nhrp_cache_authorize_binding: Fix route update for NAT scenario. When remote_nbma_natoa is already set in the cache entry, binding should be updated to this value and not vc remote nbma, which would be different from the NATted address.

nhrp_shortcut_recv_resolution_rep: Simplify the logic for finding the natoa nbma. Also, install shortcut entries as DYNAMIC type, as suggested in Section 6.2.2 of RFC2332.

nhrp_shortcut_cache_notify: announce the installed route with the correct interface from cache.

Signed-off-by: Ghasem Naddaf <gshirazi@infoblox.com>
2020-02-27 11:37:37 -08:00
Ghasem Naddaf 47d4075766 nhrpd: add holdtime and MTU to CIE
nhrp_shortcut_send_resolution_req: Add Holding time and MTU to the resolution request CIE according to RFC2332 Sec. 5.2.1.

nhrp_handle_resolution_req: Parse Holding time and MTU from CIE and update the requestor's binding. Also, when preparing the resolution reply, copy the Holding time and MTU to the CIE according to RFC2332 Sec. 5.2.2.

Signed-off-by: Ghasem Naddaf <gshirazi@infoblox.com>
2020-02-27 10:55:47 -08:00
Ghasem Naddaf e9178b8ba3 nhrpd: fix netlink neigh message handling for lladdr
Signed-off-by: Ghasem Naddaf <gshirazi@infoblox.com>
2020-02-27 10:22:39 -08:00
Donald Sharp 8ba9026b95 nhrpd: Cleanup set but unused variables
There existed some variables set but never used.  Clean this up.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-02-27 09:41:58 -05:00
Jafar Al-Gharaibeh 29ff6b5cb6 nhrpd: allow no nhrp map cmd to match the configured cmd
Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
2020-02-14 11:49:58 -06:00
Donatas Abraitis 975a328e2e *: Replace s_addr 0 => INADDR_ANY
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-06 09:00:12 +02:00
Quentin Young b3ba5dc7fe *: don't null after XFREE; XFREE does this itself
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-02-03 11:22:13 -05:00
David Lamparter 429576883e doc: rename man pages to frr-*
The vrrpd one conflicts with the standalone vrrpd package; also we're
installing daemons to /usr/lib/frr on some systems so they're not on
PATH.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-01-15 14:05:11 +01:00
Jafar Al-Gharaibeh dea7e8d6f7
Merge pull request #5590 from qlyoung/fix-nhrp-underflow
nhrpd: offset value not checked for min size
2020-01-14 22:57:15 -06:00
Quentin Young a7051a1825 nhrpd: offset value not checked for min size
If the extension offset points to a location within the packet header,
we end up with an integer underflow leading to heap buffer read
overflow.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-01-14 18:42:12 -05:00
Donald Sharp 2003a265bb
Merge pull request #5528 from opensourcerouting/bmp-dns-fixing
BMP: improve active outbound connection details
2019-12-11 13:22:34 -05:00
David Lamparter 3286ca0750 lib,nhrpd,bgpd/bmp: pass resolver failure details
To keep the calling code agnostic of the DNS resolver libary used, pass
a strerror-style string instead of a status code that would need extra
handling.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-11 13:33:36 +01:00
David Lamparter 1c0d880814 lib: rename memory_vty.c to lib_vty.c
And memory_init() to lib_cmd_init().

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-06 15:13:29 +01:00
David Lamparter 2b64873d24 *: generously apply const
const const const your boat, merrily down the stream...

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-02 15:01:29 +01:00
David Lamparter 0d8c7a26a1 *: make frr_yang_module_info const
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-11-30 00:38:32 +01:00
Donald Sharp 721c08573a *: Convert connected_free to a double pointer
Set the connected pointer to set the pointer to NULL.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-11-02 16:13:44 -04:00
Donatas Abraitis b550350618 nhrp: Make sure no ip nhrp map <something> works as expected
We passed peer as NULL and nothing happened.

exit2-debian-9# conf
exit2-debian-9(config)# int gre1
exit2-debian-9(config-if)# ip nhrp map 1.1.1.1 local
exit2-debian-9(config-if)# ip nhrp map 2.2.2.2 3.3.3.3
exit2-debian-9(config-if)# do sh run
...
!
interface gre1
 ip nhrp map 1.1.1.1 local
 ip nhrp map 2.2.2.2 3.3.3.3
!
...
exit2-debian-9(config-if)# no ip nhrp map 1.1.1.1
exit2-debian-9(config-if)# do sh run
...
!
interface gre1
 ip nhrp map 2.2.2.2 3.3.3.3
!

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2019-10-25 13:05:49 +03:00
Mark Stapp 123ea351a4 nhrpd: clean up SA warning
Try to signal to SA/clang more clearly to clean up an SA warning
in the nhrp-specific linkedlist code.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-10-17 16:08:47 -04:00
Mark Stapp bd2b75a21e nhrpd: be more careful with linked lists
NHRPD has its own linked-list implementation, and one of the
apis is a little free and easy with pointers. Also be safer
with one list iteration operation.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-10-16 11:01:41 -04:00
Donald Sharp 3c3c325203 *: Convert zapi->interface_delete to ifp callback
Convert the callback of the interface_delete to the new
ifp callback.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
Donald Sharp b0b69e59f4 *: Convert interface_down to interface down callback
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
Donald Sharp ddbf3e6060 *: Convert from ->interface_up to the interface callback
For all the places we have a zclient->interface_up convert
them to use the interface ifp_up callback instead.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
Donald Sharp ef7bd2a3d5 *: Switch all zclient->interface_add to interface create callback
Switch the zclient->interface_add functionality to have everyone
use the interface create callback in lib/if.c

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
Donald Sharp 138c5a7450 *: Add infrastructure to support zapi interface callbacks
Start the conversion to allow zapi interface callbacks to be
controlled like vrf creation/destruction/change callbacks.

This will allow us to consolidate control into the interface.c
instead of having each daemon read the stream and react accordingly.
This will hopefully reduce a bunch of cut-n-paste stuff

Create 4 new callback functions that will be controlled by
lib/if.c

create -> A upper level protocol receives an interface creation event
The ifp is brand spanking newly created in the system.
up -> A upper level protocol receives a interface up event
This means the interface is up and ready to go.
down -> A upper level protocol receives a interface down
destroy -> A upper level protocol receives a destroy event
This means to delete the pointers associated with it.

At this point this is just boilerplate setup for future commits.
There is no new functionality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
David Lamparter fe9e7b71cf lib: split off c-ares code from nhrpd
This is useful in other places too, e.g. for BMP outbound connections.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-07-03 17:15:34 +02:00
Donald Sharp a36898e755
Revert "Ospf missing interface handling 2" 2019-06-23 19:46:39 -04:00
Philippe Guibert f11e98eca3 *: change if_lookup_by_name() api with vrf
the vrf_id parameter is replaced by struct vrf * parameter.
this impacts most of the daemons that look for an interface based on the
name and the vrf identifier.
Also, it fixes 2 lookup calls in zebra and sharpd, where the vrf_id was
ignored until now.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:54 +02:00
Mark Stapp fa3bf3a21b lib,bgpd,babeld,ripngd,nhrpd,bfdd: clean up SA warnings
Clean up several SA warnings.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-06-06 13:13:15 -04:00
Quentin Young d8b87afe7c lib: hashing functions should take const arguments
It doesn't make much sense for a hash function to modify its argument,
so const the hash input.

BGP does it in a couple places, those cast away the const. Not great but
not any worse than it was.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-14 21:23:08 +00:00
Quentin Young 121f9dee7c *: use ZAPI_CALLBACK_ARGS macro for zapi handlers
This macro:
- Marks ZAPI callbacks for readability
- Standardizes argument names
- Makes it simple to add ZAPI arguments in the future
- Ensures proper types
- Looks better
- Shortens function declarations

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-03 20:57:35 +00:00
David Lamparter 7e3a1ec742 lib: ZEBRA_NUM_OF -> array_size
The latter is widely used, e.g. in the Linux kernel.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-18 12:44:29 +02:00
Donald Sharp 9d6c33eadf bfdd, nhrpd, pimd: When deleting an interface clean up
When we delete an interface, we need to set the interface
ifindex to an internal value so that we don't end up in
a state where the re-addition of the same ifindex, due to
a rename operation, causes an infinite loop.

Fixes:#4007
Fix-Suggested-by: Saravanan K
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-03-29 12:44:05 -04:00
Quentin Young 831600c3d0 *: compare pointer types to NULL, not 0
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:46 +00:00
Tim Bray e3b78da875 *: Rename backet to bucket
Presume typo from original author

Signed-off-by: Tim Bray <tim@kooky.org>
2019-02-25 16:22:36 +00:00