Skip to content

Commit d75213d

Browse files
authored
Merge pull request #8153 from reubendowle/nhrp-multicast
nhrp, ospf: add nhrp multicast for OSPF DMVPN
2 parents 0ae24ff + 46d3c18 commit d75213d

File tree

18 files changed

+549
-46
lines changed

18 files changed

+549
-46
lines changed

doc/user/nhrpd.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,37 @@ https://git-old.alpinelinux.org/user/tteras/strongswan/
180180
Actively maintained patches are also available at:
181181
https://gitlab.alpinelinux.org/alpine/aports/-/tree/master/main/strongswan
182182

183+
.. _multicast-functionality:
184+
185+
Multicast Functionality
186+
=======================
187+
188+
nhrpd can be configured to forward multicast packets, allowing routing
189+
protocols that use multicast (such as OSPF) to be supported in the DMVPN
190+
network.
191+
192+
This support requires an iptables NFLOG rule to allow nhrpd to intercept
193+
multicast packets. A second iptables rule is also usually used to drop the
194+
original multicast packet.
195+
196+
.. code-block:: shell
197+
198+
iptables -A OUTPUT -d 224.0.0.0/24 -o gre1 -j NFLOG --nflog-group 2
199+
iptables -A OUTPUT -d 224.0.0.0/24 -o gre1 -j DROP
200+
201+
.. index:: nhrp multicast-nflog-group (1-65535)
202+
.. clicmd:: nhrp multicast-nflog-group (1-65535)
203+
204+
Sets the nflog group that nhrpd will listen on for multicast packets. This
205+
value must match the nflog-group value set in the iptables rule.
206+
207+
.. index:: ip nhrp map multicast A.B.C.D|X:X::X:X A.B.C.D|dynamic
208+
.. clicmd:: ip nhrp map multicast A.B.C.D|X:X::X:X A.B.C.D|dynamic
209+
210+
Sends multicast packets to the specified NBMA address. If dynamic is
211+
specified then destination NBMA address (or addresses) are learnt
212+
dynamically.
213+
183214
.. _nhrp-events:
184215

185216
NHRP Events

doc/user/ospfd.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,17 @@ Interfaces
587587
:clicmd:`ip ospf dead-interval minimal hello-multiplier (2-20)` is also
588588
specified for the interface.
589589

590-
.. clicmd:: ip ospf network (broadcast|non-broadcast|point-to-multipoint|point-to-point)
590+
.. clicmd:: ip ospf network (broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn])
591591

592592
When configuring a point-to-point network on an interface and the interface
593593
has a /32 address associated with then OSPF will treat the interface
594594
as being `unnumbered`. If you are doing this you *must* set the
595595
net.ipv4.conf.<interface name>.rp_filter value to 0. In order for
596596
the ospf multicast packets to be delivered by the kernel.
597597

598+
When used in a DMVPN network at a spoke, this OSPF will be configured in
599+
point-to-point, but the HUB will be a point-to-multipoint. To make this
600+
topology work, specify the optional 'dmvpn' parameter at the spoke.
598601

599602
Set explicitly network type for specified interface.
600603

nhrpd/linux.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdio.h>
1616
#include <unistd.h>
1717
#include <string.h>
18+
#include <errno.h>
1819
#include <sys/ioctl.h>
1920
#include <sys/socket.h>
2021
#include <sys/types.h>
@@ -31,6 +32,11 @@
3132
#include "os.h"
3233
#include "netlink.h"
3334

35+
#ifndef HAVE_STRLCPY
36+
size_t strlcpy(char *__restrict dest,
37+
const char *__restrict src, size_t destsize);
38+
#endif
39+
3440
static int nhrp_socket_fd = -1;
3541

3642
int os_socket(void)
@@ -42,7 +48,7 @@ int os_socket(void)
4248
}
4349

4450
int os_sendmsg(const uint8_t *buf, size_t len, int ifindex, const uint8_t *addr,
45-
size_t addrlen)
51+
size_t addrlen, uint16_t protocol)
4652
{
4753
struct sockaddr_ll lladdr;
4854
struct iovec iov = {
@@ -61,16 +67,16 @@ int os_sendmsg(const uint8_t *buf, size_t len, int ifindex, const uint8_t *addr,
6167

6268
memset(&lladdr, 0, sizeof(lladdr));
6369
lladdr.sll_family = AF_PACKET;
64-
lladdr.sll_protocol = htons(ETH_P_NHRP);
70+
lladdr.sll_protocol = htons(protocol);
6571
lladdr.sll_ifindex = ifindex;
6672
lladdr.sll_halen = addrlen;
6773
memcpy(lladdr.sll_addr, addr, addrlen);
6874

69-
status = sendmsg(nhrp_socket_fd, &msg, 0);
75+
status = sendmsg(os_socket(), &msg, 0);
7076
if (status < 0)
71-
return -1;
77+
return -errno;
7278

73-
return 0;
79+
return status;
7480
}
7581

7682
int os_recvmsg(uint8_t *buf, size_t *len, int *ifindex, uint8_t *addr,
@@ -111,7 +117,7 @@ static int linux_configure_arp(const char *iface, int on)
111117
{
112118
struct ifreq ifr;
113119

114-
strncpy(ifr.ifr_name, iface, IFNAMSIZ - 1);
120+
strlcpy(ifr.ifr_name, iface, IFNAMSIZ);
115121
if (ioctl(nhrp_socket_fd, SIOCGIFFLAGS, &ifr))
116122
return -1;
117123

nhrpd/netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ union sockunion;
1313
struct interface;
1414

1515
extern int netlink_nflog_group;
16+
extern int netlink_mcast_nflog_group;
1617
extern int netlink_req_fd;
1718

1819
void netlink_init(void);

nhrpd/nhrp_interface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static int nhrp_if_new_hook(struct interface *ifp)
4242
struct nhrp_afi_data *ad = &nifp->afi[afi];
4343
ad->holdtime = NHRPD_DEFAULT_HOLDTIME;
4444
list_init(&ad->nhslist_head);
45+
list_init(&ad->mcastlist_head);
4546
}
4647

4748
return 0;
@@ -55,6 +56,7 @@ static int nhrp_if_delete_hook(struct interface *ifp)
5556

5657
nhrp_cache_interface_del(ifp);
5758
nhrp_nhs_interface_del(ifp);
59+
nhrp_multicast_interface_del(ifp);
5860
nhrp_peer_interface_del(ifp);
5961

6062
if (nifp->ipsec_profile)

0 commit comments

Comments
 (0)