lib, zebra: get gre information

the get gre information code is obtained by nhrp, via zebra.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2019-12-20 11:06:05 +01:00
parent b716ab61e2
commit d17af8dd04
3 changed files with 89 additions and 0 deletions

View file

@ -3931,6 +3931,11 @@ static int zclient_read(struct thread *thread)
(*zclient->neighbor_get)(command, zclient, length, (*zclient->neighbor_get)(command, zclient, length,
vrf_id); vrf_id);
break; break;
case ZEBRA_GRE_UPDATE:
if (zclient->gre_update)
(*zclient->gre_update)(command, zclient,
length, vrf_id);
break;
default: default:
break; break;
} }
@ -4252,3 +4257,28 @@ int zclient_neigh_ip_decode(struct stream *s, struct zapi_neigh_ip *api)
stream_failure: stream_failure:
return -1; return -1;
} }
int zclient_send_zebra_gre_request(struct zclient *client,
struct interface *ifp)
{
struct stream *s;
ifindex_t idx_local;
int ret;
if (!client || client->sock < 0) {
zlog_err("%s : zclient not ready", __func__);
return -1;
}
s = client->obuf;
stream_reset(s);
zclient_create_header(s,
ZEBRA_GRE_GET,
ifp->vrf_id);
stream_putl(s, ifp->ifindex);
stream_putw_at(s, 0, stream_get_endp(s));
zclient_send_message(client);
return 0;
stream_failure:
zlog_err("%s(): error reading response ..", __func__);
return 0;
}

View file

@ -396,6 +396,7 @@ struct zclient {
void (*neighbor_added)(ZAPI_CALLBACK_ARGS); void (*neighbor_added)(ZAPI_CALLBACK_ARGS);
void (*neighbor_removed)(ZAPI_CALLBACK_ARGS); void (*neighbor_removed)(ZAPI_CALLBACK_ARGS);
void (*neighbor_get)(ZAPI_CALLBACK_ARGS); void (*neighbor_get)(ZAPI_CALLBACK_ARGS);
void (*gre_update)(ZAPI_CALLBACK_ARGS);
}; };
/* Zebra API message flag. */ /* Zebra API message flag. */
@ -1231,6 +1232,8 @@ struct zapi_client_close_info {
extern int zapi_client_close_notify_decode(struct stream *s, extern int zapi_client_close_notify_decode(struct stream *s,
struct zapi_client_close_info *info); struct zapi_client_close_info *info);
extern int zclient_send_zebra_gre_request(struct zclient *client,
struct interface *ifp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -3240,6 +3240,61 @@ stream_failure:
return; return;
} }
static inline void zebra_gre_get(ZAPI_HANDLER_ARGS)
{
struct stream *s;
ifindex_t idx;
struct interface *ifp;
struct zebra_if *zebra_if = NULL;
struct zebra_l2info_gre *gre_info;
struct interface *ifp_link = NULL;
vrf_id_t vrf_id_link = VRF_UNKNOWN;
vrf_id_t vrf_id = zvrf->vrf->vrf_id;
s = msg;
STREAM_GETL(s, idx);
ifp = if_lookup_by_index(idx, vrf_id);
if (ifp)
zebra_if = ifp->info;
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, ZEBRA_GRE_UPDATE, vrf_id);
if (ifp && IS_ZEBRA_IF_GRE(ifp) && zebra_if) {
gre_info = &zebra_if->l2info.gre;
stream_putl(s, idx);
stream_putl(s, gre_info->ikey);
stream_putl(s, gre_info->ikey);
stream_putl(s, gre_info->ifindex_link);
ifp_link = if_lookup_by_index_per_ns(
zebra_ns_lookup(gre_info->link_nsid),
gre_info->ifindex_link);
if (ifp_link)
vrf_id_link = ifp_link->vrf_id;
stream_putl(s, vrf_id_link);
stream_putl(s, gre_info->vtep_ip.s_addr);
stream_putl(s, gre_info->vtep_ip_remote.s_addr);
} else {
stream_putl(s, idx);
stream_putl(s, 0);
stream_putl(s, 0);
stream_putl(s, IFINDEX_INTERNAL);
stream_putl(s, VRF_UNKNOWN);
stream_putl(s, 0);
}
/* Write packet size. */
stream_putw_at(s, 0, stream_get_endp(s));
zserv_send_message(client, s);
return;
stream_failure:
return;
}
static inline void zebra_configure_arp(ZAPI_HANDLER_ARGS) static inline void zebra_configure_arp(ZAPI_HANDLER_ARGS)
{ {
struct stream *s; struct stream *s;
@ -3516,6 +3571,7 @@ void (*const zserv_handlers[])(ZAPI_HANDLER_ARGS) = {
[ZEBRA_NHRP_NEIGH_REGISTER] = zebra_neigh_register, [ZEBRA_NHRP_NEIGH_REGISTER] = zebra_neigh_register,
[ZEBRA_NHRP_NEIGH_UNREGISTER] = zebra_neigh_unregister, [ZEBRA_NHRP_NEIGH_UNREGISTER] = zebra_neigh_unregister,
[ZEBRA_CONFIGURE_ARP] = zebra_configure_arp, [ZEBRA_CONFIGURE_ARP] = zebra_configure_arp,
[ZEBRA_GRE_GET] = zebra_gre_get,
[ZEBRA_GRE_SOURCE_SET] = zebra_gre_source_set, [ZEBRA_GRE_SOURCE_SET] = zebra_gre_source_set,
}; };