Skip to content

Commit

Permalink
Merge pull request #15173 from louis-6wind/nhrp-noarp
Browse files Browse the repository at this point in the history
nhrpd: unset noarp flag using a zapi message
  • Loading branch information
donaldsharp authored Jan 24, 2024
2 parents 16406a3 + 6a44127 commit c3a66e5
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 22 deletions.
18 changes: 18 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -4520,6 +4520,24 @@ static void zclient_event(enum zclient_event event, struct zclient *zclient)
}
}

enum zclient_send_status zclient_interface_set_arp(struct zclient *client,
struct interface *ifp,
bool arp_enable)
{
struct stream *s;

s = client->obuf;
stream_reset(s);

zclient_create_header(s, ZEBRA_INTERFACE_SET_ARP, ifp->vrf->vrf_id);

stream_putl(s, ifp->ifindex);
stream_putc(s, arp_enable);

stream_putw_at(s, 0, stream_get_endp(s));
return zclient_send_message(client);
}

enum zclient_send_status zclient_interface_set_master(struct zclient *client,
struct interface *master,
struct interface *slave)
Expand Down
4 changes: 4 additions & 0 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ typedef enum {
ZEBRA_INTERFACE_UP,
ZEBRA_INTERFACE_DOWN,
ZEBRA_INTERFACE_SET_MASTER,
ZEBRA_INTERFACE_SET_ARP,
ZEBRA_INTERFACE_SET_PROTODOWN,
ZEBRA_ROUTE_ADD,
ZEBRA_ROUTE_DELETE,
Expand Down Expand Up @@ -1036,6 +1037,9 @@ extern int zclient_read_header(struct stream *s, int sock, uint16_t *size,
*/
extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr);

extern enum zclient_send_status zclient_interface_set_arp(struct zclient *client,
struct interface *ifp,
bool arp_enable);
extern enum zclient_send_status
zclient_interface_set_master(struct zclient *client, struct interface *master,
struct interface *slave);
Expand Down
21 changes: 0 additions & 21 deletions nhrpd/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <fcntl.h>
#include <errno.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>

#include "nhrp_protocol.h"
#include "os.h"
Expand Down Expand Up @@ -98,25 +97,6 @@ int os_recvmsg(uint8_t *buf, size_t *len, int *ifindex, uint8_t *addr,
return 0;
}

static int linux_configure_arp(const char *iface, int on)
{
struct ifreq ifr;

strlcpy(ifr.ifr_name, iface, IFNAMSIZ);
if (ioctl(nhrp_socket_fd, SIOCGIFFLAGS, &ifr))
return -1;

if (on)
ifr.ifr_flags &= ~IFF_NOARP;
else
ifr.ifr_flags |= IFF_NOARP;

if (ioctl(nhrp_socket_fd, SIOCSIFFLAGS, &ifr))
return -1;

return 0;
}

static int linux_icmp_redirect_off(const char *iface)
{
char fname[PATH_MAX];
Expand Down Expand Up @@ -144,7 +124,6 @@ int os_configure_dmvpn(unsigned int ifindex, const char *ifname, int af)
ret |= linux_icmp_redirect_off(ifname);
break;
}
ret |= linux_configure_arp(ifname, 1);

return ret;
}
1 change: 0 additions & 1 deletion nhrpd/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
extern int netlink_nflog_group;
extern int netlink_mcast_nflog_group;

int netlink_configure_arp(unsigned int ifindex, int pf);
void netlink_update_binding(struct interface *ifp, union sockunion *proto,
union sockunion *nbma);
void netlink_set_nflog_group(int nlgroup);
Expand Down
1 change: 1 addition & 0 deletions nhrpd/nhrp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ void nhrp_interface_update(struct interface *ifp)
if (!if_ad->configured) {
os_configure_dmvpn(ifp->ifindex, ifp->name,
afi2family(afi));
nhrp_interface_update_arp(ifp, true);
nhrp_send_zebra_configure_arp(ifp, afi2family(afi));
if_ad->configured = 1;
nhrp_interface_update_address(ifp, afi, 1);
Expand Down
6 changes: 6 additions & 0 deletions nhrpd/nhrp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ int nhrp_send_zebra_gre_request(struct interface *ifp)
return zclient_send_zebra_gre_request(zclient, ifp);
}

void nhrp_interface_update_arp(struct interface *ifp, bool arp_enable)
{
zclient_interface_set_arp(zclient, ifp, arp_enable);
}


void nhrp_zebra_terminate(void)
{
zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP, false);
Expand Down
1 change: 1 addition & 0 deletions nhrpd/nhrpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ int sock_open_unix(const char *path);

void nhrp_interface_init(void);
void nhrp_interface_update(struct interface *ifp);
void nhrp_interface_update_arp(struct interface *ifp, bool arp_enable);
void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi);
void nhrp_interface_update_nbma(struct interface *ifp,
struct nhrp_gre_info *gre_info);
Expand Down
21 changes: 21 additions & 0 deletions tests/topotests/nhrp_topo/test_nhrp_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ def test_protocols_convergence():
assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg

# check that the NOARP flag is removed from rX-gre0 interfaces
for rname, router in router_list.items():
if rname == "r3":
continue

expected = {
"{}-gre0".format(rname): {
"flags": "<UP,RUNNING>",
}
}
test_func = partial(
topotest.router_json_cmp,
router,
"show interface {}-gre0 json".format(rname),
expected,
)
_, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)

assertmsg = '"{}-gre0 interface flags incorrect'.format(router.name)
assert result is None, assertmsg

for rname, router in router_list.items():
if rname == "r3":
continue
Expand Down
21 changes: 21 additions & 0 deletions zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3662,6 +3662,27 @@ DEFUN (show_interface_desc_vrf_all,
return CMD_SUCCESS;
}

void if_arp(struct interface *ifp, bool enable)
{
int ret;

if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE))
return;

if (enable)
ret = if_unset_flags(ifp, IFF_NOARP);
else
ret = if_set_flags(ifp, IFF_NOARP);

if (ret < 0) {
zlog_debug("Can't %sset noarp flag on interface %s",
enable ? "" : "un", ifp->name);
return;
}

if_refresh(ifp);
}

int if_multicast_set(struct interface *ifp)
{
struct zebra_if *if_data;
Expand Down
1 change: 1 addition & 0 deletions zebra/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ extern int if_ipv6_address_install(struct interface *ifp, struct prefix *prefix,
extern int if_ip_address_uinstall(struct interface *ifp, struct prefix *prefix);
extern int if_shutdown(struct interface *ifp);
extern int if_no_shutdown(struct interface *ifp);
extern void if_arp(struct interface *ifp, bool enable);
extern int if_multicast_set(struct interface *ifp);
extern int if_multicast_unset(struct interface *ifp);
extern int if_linkdetect(struct interface *ifp, bool detect);
Expand Down
23 changes: 23 additions & 0 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3124,6 +3124,28 @@ static void zread_interface_set_master(ZAPI_HANDLER_ARGS)
}


static void zread_interface_set_arp(ZAPI_HANDLER_ARGS)
{
struct stream *s = msg;
struct interface *ifp;
bool arp_enable;
vrf_id_t vrf_id = zvrf->vrf->vrf_id;
int ifindex;

STREAM_GETL(s, ifindex);
STREAM_GETC(s, arp_enable);
ifp = if_lookup_by_index(ifindex, vrf_id);

if (!ifp)
return;

if_arp(ifp, arp_enable);

stream_failure:
return;
}


static void zread_vrf_label(ZAPI_HANDLER_ARGS)
{
struct interface *ifp;
Expand Down Expand Up @@ -3905,6 +3927,7 @@ void (*const zserv_handlers[])(ZAPI_HANDLER_ARGS) = {
[ZEBRA_REMOTE_MACIP_DEL] = zebra_vxlan_remote_macip_del,
[ZEBRA_DUPLICATE_ADDR_DETECTION] = zebra_vxlan_dup_addr_detection,
[ZEBRA_INTERFACE_SET_MASTER] = zread_interface_set_master,
[ZEBRA_INTERFACE_SET_ARP] = zread_interface_set_arp,
[ZEBRA_PW_ADD] = zread_pseudowire,
[ZEBRA_PW_DELETE] = zread_pseudowire,
[ZEBRA_PW_SET] = zread_pseudowire,
Expand Down

0 comments on commit c3a66e5

Please sign in to comment.