Commit graph

76 commits

Author SHA1 Message Date
zmw12306 7c87716482 nhrpd: Add Hop Count Validation Before Forwarding in nhrp_peer_recv()
According to [RFC 2332, Section 5.1], if an NHS receives a packet that it would normally forward and the hop count is zero, it must send an error indication back to the source and drop the packet.

Signed-off-by: zmw12306 <zmw12306@gmail.com>
2025-04-07 16:13:45 -04:00
Joshua Muthii 5718ee37c7 nhrpd: Modify NHRP authentication feature logging
Modified nhrp_connection_authorized(). Initially, when writing debug
information about incoming NHRP packets with authentication enabled,
the nhrp_connection_authorized() function would print the
passphrase of the incoming packet as if it were a null terminated
string. This meant that if the passphrase on the incoming packet
had non ASCII-complient bytes in it, it would attempt to print those
bytes anyway. There was also no check that the size of the passphrase in
the incoming packet matched the size of the passphrase on the interface.
The changes in this commit log the passphrase on the incoming packet as
well as the passphrase on interface in HEX to avoid issues with ASCII.
It also performs a check that accounts for the sizes of the two different
passphrases

Moved CISCO_PASS_LENGTH_LEN from nhrp_vty.c to nhrp_protocol.h
for easier access  to the macro in other files

Signed-off-by: Joshua Muthii <jmuthii@labn.net>
2024-10-29 13:15:43 -04:00
Denys Haryachyy 8e3c278bbc nhrpd: fixes duplicate auth extension
When an NHRP peer was forwarding a message, it was copying all
extensions from the originally received packet. The authentication
extension must be regenerated hop by hop per RFC2332.
This fix checks for the auth extension when copying extensions
and omits the original packet auth and instead regenerates a new auth extension.

Fix bug #16507

Signed-off-by: Denys Haryachyy <garyachy@gmail.com>
2024-09-12 07:28:28 +00:00
Dave LeRoy 7c20ffaaba nhrpd: fixes duplicate auth extension
When an NHRP server was forwarding a message, it was copying all
extensions from the originally received packet. The authentication
extension must be regenerated hop by hop per RFC2332. The copied
auth extension had an incorrect length. This fix checks for the
auth extension when copying extensions and omits the original
packet auth and instead regenerates a new auth extension.

Fix bug #16466

Signed-off-by: Dave LeRoy <dleroy@labn.net>
2024-07-26 14:07:20 -07:00
Dave LeRoy c531584a37 nhrpd: Fixes auth no redirect bug
The nhrp_peer_forward() routine was not explicitly handling the
Authentication Extension in the switch statement and instead fell
through to the default case which checked whether this was an
unhandled Compulsory extension and errored out, never forwarding
the Resolution Request.

Fix bug #16371

Signed-off-by: Dave LeRoy <dleroy@labn.net>
2024-07-18 13:27:40 -07:00
Dave LeRoy b5540d326b nhrpd: add cisco-authentication password support
Taking over this development from https://github.com/FRRouting/frr/pull/14788

This commit addresses 4 issues found in the previous PR

1) FRR would accept messages from a spoke without authentication when FRR NHRP had auth configured.
2) The error indication was not being sent in network byte order
3) The debug print in nhrp_connection_authorized was not correctly printing the received password
4) The addresses portion of the mandatory part of the error indication was invalid on the wire (confirmed in wireshark)

Signed-off-by: Dave LeRoy <dleroy@labn.net>
Co-authored-by: Volodymyr Huti <volodymyr.huti@gmail.com>
2024-06-10 16:39:21 -07:00
Volodymyr Huti 51f0700286 nhrp: add cisco-authentication password support
Implemented:
- handling 8 char long password, aka Cisco style.
- minimal error inidication routine
- test case, password change affects conection

Signed-off-by: Volodymyr Huti <v.huti@vyos.io>
2024-06-10 16:39:21 -07:00
Donald Sharp 02cbd97801
Merge pull request #14561 from idryzhov/implicit-fallthrough
build: add -Wimplicit-fallthrough
2023-10-13 11:51:11 -04:00
Igor Ryzhov 7d67b9ff28 build: add -Wimplicit-fallthrough
Also:
- replace all /* fallthrough */ comments with portable fallthrough;
pseudo keyword to accomodate both gcc and clang
- add missing break; statements as required by older versions of gcc
- cleanup some code to remove unnecessary fallthrough

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-10-12 21:23:18 +03:00
Keelan10 d163f89e14 nhrpd: Fix nhrp_peer leak
- Addressed memory leak by removing `&c->peer_notifier` from the notifier list on termination. Retaining it caused the notifier list to stay active, preventing the deletion of `c->cur.peer`
  thereby causing a memory leak.

- Reordered termination steps to call `vrf_terminate` before `nhrp_vc_terminate`, preventing a heap-use-after-free issue when `nhrp_vc_notify_del` is invoked in `nhrp_peer_check_delete`.

- Added an if statement to avoid passing NULL as hash to `hash_release`, which leads to a SIGSEGV.

The ASan leak log for reference:

```
***********************************************************************************
Address Sanitizer Error detected in nhrp_topo.test_nhrp_topo/r1.asan.nhrpd.20265

=================================================================
==20265==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 112 byte(s) in 1 object(s) allocated from:
    #0 0x7f80270c9b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7f8026ac1eb8 in qmalloc lib/memory.c:100
    #2 0x560fd648f0a6 in nhrp_peer_create nhrpd/nhrp_peer.c:175
    #3 0x7f8026a88d3f in hash_get lib/hash.c:147
    #4 0x560fd6490a5d in nhrp_peer_get nhrpd/nhrp_peer.c:228
    #5 0x560fd648a51a in nhrp_nhs_resolve_cb nhrpd/nhrp_nhs.c:297
    #6 0x7f80266b000f in resolver_cb_literal lib/resolver.c:234
    #7 0x7f8026b62e0e in event_call lib/event.c:1969
    #8 0x7f8026aa5437 in frr_run lib/libfrr.c:1213
    #9 0x560fd6488b4f in main nhrpd/nhrp_main.c:166
    #10 0x7f8025eb2c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 112 byte(s) leaked in 1 allocation(s).
***********************************************************************************

***********************************************************************************
Address Sanitizer Error detected in nhrp_topo.test_nhrp_topo/r2.asan.nhrpd.20400

=================================================================
==20400==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 112 byte(s) in 1 object(s) allocated from:
    #0 0x7fb6e3ca5b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7fb6e369deb8 in qmalloc lib/memory.c:100
    #2 0x562652de40a6 in nhrp_peer_create nhrpd/nhrp_peer.c:175
    #3 0x7fb6e3664d3f in hash_get lib/hash.c:147
    #4 0x562652de5a5d in nhrp_peer_get nhrpd/nhrp_peer.c:228
    #5 0x562652de1e8e in nhrp_packet_recvraw nhrpd/nhrp_packet.c:325
    #6 0x7fb6e373ee0e in event_call lib/event.c:1969
    #7 0x7fb6e3681437 in frr_run lib/libfrr.c:1213
    #8 0x562652dddb4f in main nhrpd/nhrp_main.c:166
    #9 0x7fb6e2a8ec86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 112 byte(s) leaked in 1 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
2023-10-12 18:23:09 +04:00
Donald Sharp 24a58196dd *: Convert event.h to frrevent.h
We should probably prevent any type of namespace collision
with something else.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e16d030c65 *: Convert THREAD_XXX macros to EVENT_XXX macros
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 907a2395f4 *: Convert thread_add_XXX functions to event_add_XXX
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e6685141aa *: Rename struct thread to struct event
Effectively a massive search and replace of
`struct thread` to `struct event`.  Using the
term `thread` gives people the thought that
this event system is a pthread when it is not

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp cb37cb336a *: Rename thread.[ch] to event.[ch]
This is a first in a series of commits, whose goal is to rename
the thread system in FRR to an event system.  There is a continual
problem where people are confusing `struct thread` with a true
pthread.  In reality, our entire thread.c is an event system.

In this commit rename the thread.[ch] files to event.[ch].

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:16 -04:00
Donald Sharp d8bc11a592 *: Add a hash_clean_and_free() function
Add a hash_clean_and_free() function as well as convert
the code to use it.  This function also takes a double
pointer to the hash to set it NULL.  Also it cleanly
does nothing if the pointer is NULL( as a bunch of
code tested for ).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-21 08:54:21 -04:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
Donald Sharp 7fc3f834e9 nhrpd: Use frr_weak_random()
Convert usage of rand() to frr_weak_random()

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-15 15:45:05 -04:00
Donatas Abraitis 47e1288431 *: Replace sockunion2str => %pSU
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-21 13:34:56 +03:00
Donald Sharp cc9f21da22 *: Change thread->func to return void instead of int
The int return value is never used.  Modify the code
base to just return a void instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23 19:56:04 -05:00
David Lamparter 865bf787fa nhrpd: convert notifier list to DLIST
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
Donatas Abraitis 56fb213493 nhrpd: Do not explicitly set the thread pointer to NULL
FRR should only ever use the appropriate THREAD_ON/THREAD_OFF
semantics.  This is espacially true for the functions we
end up calling the thread for.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-04 19:29:06 +03: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 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
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 0f8595a9f4 nhrpd: Fix style violation issues
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
2021-04-06 09:23:42 +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
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
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 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 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
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
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
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
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
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
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