From 1dcb51729b4a8bd7ed21126c7e5e61bc096f8674 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 31 May 2005 08:38:50 +0000 Subject: 2005-05-31 Paul Jakma * zserv.c: (zsend_route_multipath) Fix bug if route is sent with no NEXTHOP_FLAG_FIB nexthops. As ZAPI_MESSAGE_IFINDEX and ZAPI_MESSAGE_NEXTHOP are always set, clients would try read non-existent nexthop information and hit stream assert. Zserv is still broken for multi-nexthop messages, but it always was. --- zebra/zserv.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'zebra/zserv.c') diff --git a/zebra/zserv.c b/zebra/zserv.c index c02eac89..17e7888d 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -404,9 +404,9 @@ zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p, int psize; struct stream *s; struct nexthop *nexthop; - unsigned long nhnummark = 0; + unsigned long nhnummark = 0, messmark = 0; int nhnum = 0; - u_char zapi_flags = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_IFINDEX; + u_char zapi_flags = 0; s = client->obuf; stream_reset (s); @@ -418,15 +418,10 @@ zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p, stream_putc (s, cmd); stream_putc (s, rib->type); stream_putc (s, rib->flags); - - /* - * XXX no need to set ZAPI_MESSAGE_NEXTHOP if we are going to - * send empty nexthop? - */ - if (cmd == ZEBRA_IPV4_ROUTE_ADD || ZEBRA_IPV6_ROUTE_ADD) - zapi_flags |= ZAPI_MESSAGE_METRIC; - - stream_putc (s, zapi_flags); + + /* marker for message flags field */ + messmark = stream_get_endp (s); + stream_putc (s, 0); /* Prefix. */ psize = PSIZE (p->prefixlen); @@ -442,12 +437,20 @@ zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p, * is hard-coded. */ /* Nexthop */ + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) { if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) { - nhnummark = stream_get_endp (s); - stream_putc (s, 1); /* placeholder */ + SET_FLAG (zapi_flags, ZAPI_MESSAGE_NEXTHOP); + SET_FLAG (zapi_flags, ZAPI_MESSAGE_IFINDEX); + + if (nhnummark == 0) + { + nhnummark = stream_get_endp (s); + stream_putc (s, 1); /* placeholder */ + } + nhnum++; switch(nexthop->type) @@ -488,8 +491,15 @@ zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p, } /* Metric */ - stream_putl (s, rib->metric); - + if (cmd == ZEBRA_IPV4_ROUTE_ADD || ZEBRA_IPV6_ROUTE_ADD) + { + SET_FLAG (zapi_flags, ZAPI_MESSAGE_METRIC); + stream_putl (s, rib->metric); + } + + /* write real message flags value */ + stream_putc_at (s, messmark, zapi_flags); + /* Write next-hop number */ if (nhnummark) stream_putc_at (s, nhnummark, nhnum); -- cgit v1.2.1