From 2af780650fe8accddb9d07d037a823efd7c3d201 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 27 Jan 2025 20:26:32 +0100 Subject: [PATCH] lib, zebra: carry source prefix in route_notify When a daemon wants to know about its routes, make it possible to have that work for dst-src routes. Signed-off-by: David Lamparter --- lib/zclient.c | 12 ++++++++++++ lib/zclient.h | 3 +++ zebra/zapi_msg.c | 18 +++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/zclient.c b/lib/zclient.c index 063944fd3b..d2bd7ed045 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2015,6 +2015,15 @@ bool zapi_route_notify_decode(struct stream *s, struct prefix *p, uint32_t *tableid, enum zapi_route_notify_owner *note, afi_t *afi, safi_t *safi) +{ + struct prefix dummy; + + return zapi_route_notify_decode_srcdest(s, p, &dummy, tableid, note, afi, safi); +} + +bool zapi_route_notify_decode_srcdest(struct stream *s, struct prefix *p, struct prefix *src_p, + uint32_t *tableid, enum zapi_route_notify_owner *note, + afi_t *afi, safi_t *safi) { uint32_t t; afi_t afi_val; @@ -2025,6 +2034,9 @@ bool zapi_route_notify_decode(struct stream *s, struct prefix *p, STREAM_GETC(s, p->family); STREAM_GETC(s, p->prefixlen); STREAM_GET(&p->u.prefix, s, prefix_blen(p)); + src_p->family = p->family; + STREAM_GETC(s, src_p->prefixlen); + STREAM_GET(&src_p->u.prefix, s, prefix_blen(src_p)); STREAM_GETL(s, t); STREAM_GETC(s, afi_val); STREAM_GETC(s, safi_val); diff --git a/lib/zclient.h b/lib/zclient.h index 2385a8a219..e2bf0ce699 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -1144,6 +1144,9 @@ bool zapi_route_notify_decode(struct stream *s, struct prefix *p, uint32_t *tableid, enum zapi_route_notify_owner *note, afi_t *afi, safi_t *safi); +bool zapi_route_notify_decode_srcdest(struct stream *s, struct prefix *p, struct prefix *src_p, + uint32_t *tableid, enum zapi_route_notify_owner *note, + afi_t *afi, safi_t *safi); bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno, uint32_t *priority, uint32_t *unique, char *ifname, enum zapi_rule_notify_owner *note); diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index ab55998af0..8e5eeae1cc 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -740,6 +740,10 @@ static int route_notify_internal(const struct route_node *rn, int type, struct zserv *client; struct stream *s; uint8_t blen; + const struct prefix *p, *src_p; + struct prefix src_dummy = {}; + + srcdest_rnode_prefixes(rn, &p, &src_p); client = zserv_find_client(type, instance); if (!client || !client->notify_owner) { @@ -771,9 +775,17 @@ static int route_notify_internal(const struct route_node *rn, int type, stream_putc(s, rn->p.family); - blen = prefix_blen(&rn->p); - stream_putc(s, rn->p.prefixlen); - stream_put(s, &rn->p.u.prefix, blen); + blen = prefix_blen(p); + stream_putc(s, p->prefixlen); + stream_put(s, &p->u.prefix, blen); + + if (!src_p) { + src_dummy.family = p->family; + src_p = &src_dummy; + } + blen = prefix_blen(src_p); + stream_putc(s, src_p->prefixlen); + stream_put(s, &src_p->u.prefix, blen); stream_putl(s, table_id); -- 2.39.5