mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-09 16:20:32 +00:00
Merge pull request #1665 from donaldsharp/nexthop_labels
Cleanup some zclient code
This commit is contained in:
commit
dd19d6a6e7
@ -572,12 +572,11 @@ static int make_prefix(int afi, struct bgp_info *ri, struct prefix *p)
|
|||||||
*/
|
*/
|
||||||
static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command)
|
static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command)
|
||||||
{
|
{
|
||||||
struct stream *s;
|
|
||||||
struct prefix *p;
|
struct prefix *p;
|
||||||
|
bool exact_match = false;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check socket. */
|
if (!zclient)
|
||||||
if (!zclient || zclient->sock < 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Don't try to register if Zebra doesn't know of this instance. */
|
/* Don't try to register if Zebra doesn't know of this instance. */
|
||||||
@ -585,32 +584,14 @@ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
p = &(bnc->node->p);
|
p = &(bnc->node->p);
|
||||||
s = zclient->obuf;
|
|
||||||
stream_reset(s);
|
|
||||||
zclient_create_header(s, command, bnc->bgp->vrf_id);
|
|
||||||
if ((command == ZEBRA_NEXTHOP_REGISTER ||
|
if ((command == ZEBRA_NEXTHOP_REGISTER ||
|
||||||
command == ZEBRA_IMPORT_ROUTE_REGISTER) &&
|
command == ZEBRA_IMPORT_ROUTE_REGISTER) &&
|
||||||
(CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED)
|
(CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED)
|
||||||
|| CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH)))
|
|| CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH)))
|
||||||
stream_putc(s, 1);
|
exact_match = true;
|
||||||
else
|
|
||||||
stream_putc(s, 0);
|
|
||||||
|
|
||||||
stream_putw(s, PREFIX_FAMILY(p));
|
ret = zclient_send_rnh(zclient, command, p,
|
||||||
stream_putc(s, p->prefixlen);
|
exact_match, bnc->bgp->vrf_id);
|
||||||
switch (PREFIX_FAMILY(p)) {
|
|
||||||
case AF_INET:
|
|
||||||
stream_put_in_addr(s, &p->u.prefix4);
|
|
||||||
break;
|
|
||||||
case AF_INET6:
|
|
||||||
stream_put(s, &(p->u.prefix6), 16);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
stream_putw_at(s, 0, stream_get_endp(s));
|
|
||||||
|
|
||||||
ret = zclient_send_message(zclient);
|
|
||||||
/* TBD: handle the failure */
|
/* TBD: handle the failure */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
zlog_warn("sendmsg_nexthop: zclient_send_message() failed");
|
zlog_warn("sendmsg_nexthop: zclient_send_message() failed");
|
||||||
|
@ -389,17 +389,18 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id)
|
|||||||
vrf_id);
|
vrf_id);
|
||||||
|
|
||||||
/* Flush all redistribute request. */
|
/* Flush all redistribute request. */
|
||||||
if (vrf_id == VRF_DEFAULT)
|
if (vrf_id == VRF_DEFAULT) {
|
||||||
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
|
||||||
for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
||||||
if (zclient->mi_redist[afi][i].enabled) {
|
if (!zclient->mi_redist[afi][i].enabled)
|
||||||
|
continue;
|
||||||
|
|
||||||
struct listnode *node;
|
struct listnode *node;
|
||||||
u_short *id;
|
u_short *id;
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO(
|
for (ALL_LIST_ELEMENTS_RO(
|
||||||
zclient->mi_redist[afi][i]
|
zclient->mi_redist[afi][i]
|
||||||
.instances,
|
.instances, node, id))
|
||||||
node, id))
|
|
||||||
if (!(i == zclient->redist_default
|
if (!(i == zclient->redist_default
|
||||||
&& *id == zclient->instance))
|
&& *id == zclient->instance))
|
||||||
zebra_redistribute_send(
|
zebra_redistribute_send(
|
||||||
@ -408,6 +409,8 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id)
|
|||||||
*id,
|
*id,
|
||||||
VRF_DEFAULT);
|
VRF_DEFAULT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Flush all redistribute request. */
|
/* Flush all redistribute request. */
|
||||||
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
||||||
@ -447,21 +450,22 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id)
|
|||||||
|
|
||||||
/* Set unwanted redistribute route. */
|
/* Set unwanted redistribute route. */
|
||||||
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
||||||
vrf_bitmap_set(zclient->redist[afi][zclient->redist_default],
|
vrf_bitmap_unset(zclient->redist[afi][zclient->redist_default],
|
||||||
vrf_id);
|
vrf_id);
|
||||||
|
|
||||||
/* Flush all redistribute request. */
|
/* Flush all redistribute request. */
|
||||||
if (vrf_id == VRF_DEFAULT)
|
if (vrf_id == VRF_DEFAULT) {
|
||||||
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
|
||||||
for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
||||||
if (zclient->mi_redist[afi][i].enabled) {
|
if (!zclient->mi_redist[afi][i].enabled)
|
||||||
|
continue;
|
||||||
|
|
||||||
struct listnode *node;
|
struct listnode *node;
|
||||||
u_short *id;
|
u_short *id;
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO(
|
for (ALL_LIST_ELEMENTS_RO(
|
||||||
zclient->mi_redist[afi][i]
|
zclient->mi_redist[afi][i]
|
||||||
.instances,
|
.instances, node, id))
|
||||||
node, id))
|
|
||||||
if (!(i == zclient->redist_default
|
if (!(i == zclient->redist_default
|
||||||
&& *id == zclient->instance))
|
&& *id == zclient->instance))
|
||||||
zebra_redistribute_send(
|
zebra_redistribute_send(
|
||||||
@ -470,6 +474,8 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id)
|
|||||||
*id,
|
*id,
|
||||||
VRF_DEFAULT);
|
VRF_DEFAULT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Flush all redistribute request. */
|
/* Flush all redistribute request. */
|
||||||
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
for (afi = AFI_IP; afi < AFI_MAX; afi++)
|
||||||
@ -608,6 +614,33 @@ static int zclient_connect(struct thread *t)
|
|||||||
return zclient_start(zclient);
|
return zclient_start(zclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int zclient_send_rnh(struct zclient *zclient, int command, struct prefix *p,
|
||||||
|
bool exact_match, vrf_id_t vrf_id)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
|
||||||
|
s = zclient->obuf;
|
||||||
|
stream_reset(s);
|
||||||
|
zclient_create_header(s, command, vrf_id);
|
||||||
|
stream_putc(s, (exact_match) ? 1 : 0);
|
||||||
|
|
||||||
|
stream_putw(s, PREFIX_FAMILY(p));
|
||||||
|
stream_putc(s, p->prefixlen);
|
||||||
|
switch (PREFIX_FAMILY(p)) {
|
||||||
|
case AF_INET:
|
||||||
|
stream_put_in_addr(s, &p->u.prefix4);
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
stream_put(s, &(p->u.prefix6), 16);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
stream_putw_at(s, 0, stream_get_endp(s));
|
||||||
|
|
||||||
|
return zclient_send_message(zclient);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "xdr_encode"-like interface that allows daemon (client) to send
|
* "xdr_encode"-like interface that allows daemon (client) to send
|
||||||
* a message to zebra server for a route that needs to be
|
* a message to zebra server for a route that needs to be
|
||||||
|
@ -484,6 +484,9 @@ extern int zapi_ipv4_route_ipv6_nexthop(u_char, struct zclient *,
|
|||||||
struct zapi_ipv6 *)
|
struct zapi_ipv6 *)
|
||||||
__attribute__((deprecated));
|
__attribute__((deprecated));
|
||||||
extern int zclient_route_send(u_char, struct zclient *, struct zapi_route *);
|
extern int zclient_route_send(u_char, struct zclient *, struct zapi_route *);
|
||||||
|
extern int zclient_send_rnh(struct zclient *zclient, int command,
|
||||||
|
struct prefix *p, bool exact_match,
|
||||||
|
vrf_id_t vrf_id);
|
||||||
extern int zapi_route_encode(u_char, struct stream *, struct zapi_route *);
|
extern int zapi_route_encode(u_char, struct stream *, struct zapi_route *);
|
||||||
extern int zapi_route_decode(struct stream *, struct zapi_route *);
|
extern int zapi_route_decode(struct stream *, struct zapi_route *);
|
||||||
bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
|
bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
|
||||||
|
@ -47,40 +47,14 @@
|
|||||||
void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient,
|
void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient,
|
||||||
struct pim_nexthop_cache *pnc, int command)
|
struct pim_nexthop_cache *pnc, int command)
|
||||||
{
|
{
|
||||||
struct stream *s;
|
|
||||||
struct prefix *p;
|
struct prefix *p;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check socket. */
|
|
||||||
if (!zclient || zclient->sock < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
p = &(pnc->rpf.rpf_addr);
|
p = &(pnc->rpf.rpf_addr);
|
||||||
s = zclient->obuf;
|
ret = zclient_send_rnh(zclient, command, p, false, pim->vrf_id);
|
||||||
stream_reset(s);
|
|
||||||
zclient_create_header(s, command, pim->vrf_id);
|
|
||||||
/* get update for all routes for a prefix */
|
|
||||||
stream_putc(s, 0);
|
|
||||||
|
|
||||||
stream_putw(s, PREFIX_FAMILY(p));
|
|
||||||
stream_putc(s, p->prefixlen);
|
|
||||||
switch (PREFIX_FAMILY(p)) {
|
|
||||||
case AF_INET:
|
|
||||||
stream_put_in_addr(s, &p->u.prefix4);
|
|
||||||
break;
|
|
||||||
case AF_INET6:
|
|
||||||
stream_put(s, &(p->u.prefix6), 16);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
stream_putw_at(s, 0, stream_get_endp(s));
|
|
||||||
|
|
||||||
ret = zclient_send_message(zclient);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
zlog_warn("sendmsg_nexthop: zclient_send_message() failed");
|
zlog_warn("sendmsg_nexthop: zclient_send_message() failed");
|
||||||
|
|
||||||
|
|
||||||
if (PIM_DEBUG_PIM_NHT) {
|
if (PIM_DEBUG_PIM_NHT) {
|
||||||
char buf[PREFIX2STR_BUFFER];
|
char buf[PREFIX2STR_BUFFER];
|
||||||
prefix2str(p, buf, sizeof(buf));
|
prefix2str(p, buf, sizeof(buf));
|
||||||
|
@ -765,8 +765,6 @@ void pim_zebra_init(void)
|
|||||||
zlog_info("zclient_init cleared redistribution request");
|
zlog_info("zclient_init cleared redistribution request");
|
||||||
}
|
}
|
||||||
|
|
||||||
zassert(zclient->redist_default == ZEBRA_ROUTE_PIM);
|
|
||||||
|
|
||||||
/* Request all redistribution */
|
/* Request all redistribution */
|
||||||
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
||||||
if (i == zclient->redist_default)
|
if (i == zclient->redist_default)
|
||||||
|
Loading…
Reference in New Issue
Block a user