diff options
| author | Philippe Guibert <philippe.guibert@6wind.com> | 2021-03-17 18:12:26 +0100 |
|---|---|---|
| committer | Philippe Guibert <philippe.guibert@6wind.com> | 2021-04-13 08:58:49 +0200 |
| commit | d603c0774ebac58557d8814bdbc2ad16249c21a1 (patch) | |
| tree | d8f12549091b1b2a96d14aac67d677644c8ed677 /lib | |
| parent | 850b2b70ac49643416c664d4326db530865f91c0 (diff) | |
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>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/log.c | 4 | ||||
| -rw-r--r-- | lib/zclient.c | 56 | ||||
| -rw-r--r-- | lib/zclient.h | 16 |
3 files changed, 71 insertions, 5 deletions
@@ -470,8 +470,8 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_NHRP_NEIGH_GET), DESC_ENTRY(ZEBRA_NHRP_NEIGH_REGISTER), DESC_ENTRY(ZEBRA_NHRP_NEIGH_UNREGISTER), - DESC_ENTRY(ZEBRA_NEIGH_ADD), - DESC_ENTRY(ZEBRA_NEIGH_DEL), + DESC_ENTRY(ZEBRA_NEIGH_IP_ADD), + DESC_ENTRY(ZEBRA_NEIGH_IP_DEL), DESC_ENTRY(ZEBRA_CONFIGURE_ARP)}; #undef DESC_ENTRY diff --git a/lib/zclient.c b/lib/zclient.c index 8d94fe1aca..d613906d82 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -4196,3 +4196,59 @@ char *zclient_evpn_dump_macip_flags(uint8_t flags, char *buf, size_t len) return buf; } + +static int zclient_neigh_ip_read_entry(struct stream *s, struct ipaddr *add) +{ + uint8_t family; + + STREAM_GETC(s, family); + if (family != AF_INET && family != AF_INET6) + return -1; + + STREAM_GET(&add->ip.addr, s, family2addrsize(family)); + add->ipa_type = family; + return 0; + stream_failure: + return -1; +} + +int zclient_neigh_ip_encode(struct stream *s, + uint16_t cmd, + union sockunion *in, + union sockunion *out, + struct interface *ifp) +{ + int ret = 0; + + zclient_create_header(s, cmd, ifp->vrf_id); + stream_putc(s, sockunion_family(in)); + stream_write(s, sockunion_get_addr(in), sockunion_get_addrlen(in)); + if (out && sockunion_family(out) != AF_UNSPEC) { + stream_putc(s, sockunion_family(out)); + stream_write(s, sockunion_get_addr(out), + sockunion_get_addrlen(out)); + } else + stream_putc(s, AF_UNSPEC); + stream_putl(s, ifp->ifindex); + if (out) + stream_putl(s, ZEBRA_NEIGH_STATE_REACHABLE); + else + stream_putl(s, ZEBRA_NEIGH_STATE_FAILED); + return ret; +} + +int zclient_neigh_ip_decode(struct stream *s, struct zapi_neigh_ip *api) +{ + int ret; + + ret = zclient_neigh_ip_read_entry(s, &api->ip_in); + if (ret < 0) + return -1; + zclient_neigh_ip_read_entry(s, &api->ip_out); + + STREAM_GETL(s, api->index); + STREAM_GETL(s, api->ndm_state); + return 0; + stream_failure: + return -1; +} diff --git a/lib/zclient.h b/lib/zclient.h index 25b7103116..90240e40b2 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -229,8 +229,8 @@ typedef enum { ZEBRA_NHRP_NEIGH_GET, ZEBRA_NHRP_NEIGH_REGISTER, ZEBRA_NHRP_NEIGH_UNREGISTER, - ZEBRA_NEIGH_ADD, - ZEBRA_NEIGH_DEL, + ZEBRA_NEIGH_IP_ADD, + ZEBRA_NEIGH_IP_DEL, ZEBRA_CONFIGURE_ARP, } zebra_message_types_t; @@ -809,13 +809,23 @@ extern struct zclient_options zclient_options_default; /* link layer representation for GRE like interfaces * ip_in is the underlay IP, ip_out is the tunnel dest * index stands for the index of the interface + * ndm state stands for the NDM value in netlink */ -struct zapi_nbr { +#define ZEBRA_NEIGH_STATE_REACHABLE (0x02) +#define ZEBRA_NEIGH_STATE_FAILED (0x20) +struct zapi_neigh_ip { int cmd; struct ipaddr ip_in; struct ipaddr ip_out; ifindex_t index; + uint32_t ndm_state; }; +int zclient_neigh_ip_decode(struct stream *s, struct zapi_neigh_ip *api); +int zclient_neigh_ip_encode(struct stream *s, + uint16_t cmd, + union sockunion *in, + union sockunion *out, + struct interface *ifp); /* * We reserve the top 4 bits for l2-NHG, everything else |
