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 /nhrpd | |
| 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 'nhrpd')
| -rw-r--r-- | nhrpd/netlink_arp.c | 48 | ||||
| -rw-r--r-- | nhrpd/nhrp_route.c | 15 |
2 files changed, 23 insertions, 40 deletions
diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index 4cca177c9a..8eab7cd54d 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -154,31 +154,26 @@ void nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS) { union sockunion addr = {}, lladdr = {}; struct interface *ifp; - ifindex_t idx; - struct ethaddr mac; int state, ndm_state; struct nhrp_cache *c; - unsigned short l2_len; - - STREAM_GETL(zclient->ibuf, idx); - ifp = if_lookup_by_index(idx, vrf_id); - STREAM_GETW(zclient->ibuf, addr.sa.sa_family); - if (addr.sa.sa_family == AF_INET) { - STREAM_GET(&addr.sin.sin_addr.s_addr, - zclient->ibuf, IPV4_MAX_BYTELEN); - } else { - STREAM_GET(&addr.sin6.sin6_addr.s6_addr, - zclient->ibuf, IPV6_MAX_BYTELEN); - } - STREAM_GETL(zclient->ibuf, ndm_state); - - STREAM_GETL(zclient->ibuf, l2_len); - if (l2_len) { - STREAM_GET(&mac, zclient->ibuf, l2_len); - if (l2_len == IPV4_MAX_BYTELEN) - sockunion_set(&lladdr, AF_INET, (const uint8_t *)&mac, - l2_len); - } + struct zapi_neigh_ip api = {}; + + zclient_neigh_ip_decode(zclient->ibuf, &api); + if (api.ip_in.ipa_type == AF_UNSPEC) + return; + sockunion_family(&addr) = api.ip_in.ipa_type; + memcpy((uint8_t *)sockunion_get_addr(&addr), &api.ip_in.ip.addr, + family2addrsize(api.ip_in.ipa_type)); + + sockunion_family(&lladdr) = api.ip_out.ipa_type; + if (api.ip_out.ipa_type != AF_UNSPEC) + memcpy((uint8_t *)sockunion_get_addr(&lladdr), + &api.ip_out.ip.addr, + family2addrsize(api.ip_out.ipa_type)); + + ifp = if_lookup_by_index(api.index, vrf_id); + ndm_state = api.ndm_state; + if (!ifp) return; c = nhrp_cache_get(ifp, &addr, 0); @@ -205,12 +200,9 @@ void nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS) } } else { state = (cmd == ZEBRA_NHRP_NEIGH_ADDED) ? ndm_state - : NUD_FAILED; - nhrp_cache_set_used(c, state == NUD_REACHABLE); + : ZEBRA_NEIGH_STATE_FAILED; + nhrp_cache_set_used(c, state == ZEBRA_NEIGH_STATE_REACHABLE); } - return; - stream_failure: - return; } void netlink_init(void) diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c index 99f35b79de..23fa0771ef 100644 --- a/nhrpd/nhrp_route.c +++ b/nhrpd/nhrp_route.c @@ -422,18 +422,9 @@ void nhrp_send_zebra_nbr(union sockunion *in, return; s = zclient->obuf; stream_reset(s); - zclient_create_header(s, - out ? ZEBRA_NEIGH_ADD : ZEBRA_NEIGH_DEL, - ifp->vrf_id); - stream_putc(s, sockunion_family(in)); - stream_write(s, sockunion_get_addr(in), sockunion_get_addrlen(in)); - if (out) { - stream_putc(s, sockunion_family(out)); - stream_write(s, sockunion_get_addr(out), - sockunion_get_addrlen(out)); - } - stream_putl(s, ifp->ifindex); - + zclient_neigh_ip_encode(s, out ? ZEBRA_NEIGH_IP_ADD : + ZEBRA_NEIGH_IP_DEL, in, out, + ifp); stream_putw_at(s, 0, stream_get_endp(s)); zclient_send_message(zclient); } |
