From: Daniel Walton <[email protected]> Modify zebra to pass the tag value to and from the various protocols.
Credit ------ A huge amount of credit for this patch goes to Piotr Chytla for their 'route tags support' patch that was submitted to quagga-dev in June 2007. Signed-off-by: Daniel Walton <[email protected]> Signed-off-by: Piotr Chytla <[email protected]> Signed-off-by: Donald Sharp <[email protected]> --- bgpd/bgp_zebra.c | 51 +++++++++++++++++++++++++++++++++++++++------------ lib/zclient.c | 6 ++++++ lib/zclient.h | 5 +++++ ospfd/ospf_zebra.c | 6 ++++++ zebra/zserv.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 12 deletions(-) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 685cdba..d95e92d 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -424,17 +424,23 @@ zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, else api.metric = 0; + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG)) + api.tag = stream_getw (s); + else + api.tag = 0; + if (command == ZEBRA_IPV4_ROUTE_ADD) { if (BGP_DEBUG(zebra, ZEBRA)) { char buf[2][INET_ADDRSTRLEN]; - zlog_debug("Zebra rcvd: IPv4 route add %s %s/%d nexthop %s metric %u", + zlog_debug("Zebra rcvd: IPv4 route add %s %s/%d nexthop %s metric %u tag %d", zebra_route_string(api.type), inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), p.prefixlen, inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), - api.metric); + api.metric, + api.tag); } bgp_redistribute_add((struct prefix *)&p, &nexthop, NULL, ifindex, api.metric, api.type); @@ -445,12 +451,13 @@ zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, { char buf[2][INET_ADDRSTRLEN]; zlog_debug("Zebra rcvd: IPv4 route delete %s %s/%d " - "nexthop %s metric %u", + "nexthop %s metric %u tag %d", zebra_route_string(api.type), inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), p.prefixlen, inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), - api.metric); + api.metric, + api.tag); } bgp_redistribute_delete((struct prefix *)&p, api.type); } @@ -508,6 +515,11 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length, else api.metric = 0; + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG)) + api.tag = stream_getw (s); + else + api.tag = 0; + /* Simply ignore link-local address. */ if (IN6_IS_ADDR_LINKLOCAL (&p.prefix)) return 0; @@ -517,12 +529,13 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length, if (BGP_DEBUG(zebra, ZEBRA)) { char buf[2][INET6_ADDRSTRLEN]; - zlog_debug("Zebra rcvd: IPv6 route add %s %s/%d nexthop %s metric %u", + zlog_debug("Zebra rcvd: IPv6 route add %s %s/%d nexthop %s metric %u tag %d", zebra_route_string(api.type), inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])), p.prefixlen, inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), - api.metric); + api.metric, + api.tag); } bgp_redistribute_add ((struct prefix *)&p, NULL, &nexthop, ifindex, api.metric, api.type); @@ -533,12 +546,13 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length, { char buf[2][INET6_ADDRSTRLEN]; zlog_debug("Zebra rcvd: IPv6 route delete %s %s/%d " - "nexthop %s metric %u", + "nexthop %s metric %u tag %d", zebra_route_string(api.type), inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])), p.prefixlen, inet_ntop(AF_INET6, &nexthop, buf[1], sizeof(buf[1])), - api.metric); + api.metric, + api.tag); } bgp_redistribute_delete ((struct prefix *) &p, api.type); } @@ -896,6 +910,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, u_int32_t nhcount, metric; struct bgp_info local_info; struct bgp_info *info_cp = &local_info; + u_short tag = 0; if (zclient->sock < 0) return; @@ -1013,6 +1028,12 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); api.metric = metric; + if (tag) + { + SET_FLAG (api.message, ZAPI_MESSAGE_TAG); + api.tag = tag; + } + distance = bgp_distance_apply (p, info, bgp); if (distance) @@ -1024,10 +1045,10 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, if (BGP_DEBUG(zebra, ZEBRA)) { int i; - zlog_debug("Zebra send: IPv4 route %s %s/%d metric %u" + zlog_debug("Zebra send: IPv4 route %s %s/%d metric %u tag %d" " count %d", (valid_nh_count ? "add":"delete"), inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])), - p->prefixlen, api.metric, api.nexthop_num); + p->prefixlen, api.metric, api.tag, api.nexthop_num); for (i = 0; i < api.nexthop_num; i++) zlog_debug(" IPv4 [nexthop %d] %s", i+1, inet_ntop(AF_INET, api.nexthop[i], buf[1], sizeof(buf[1]))); @@ -1179,13 +1200,19 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); api.metric = metric; + if (tag) + { + SET_FLAG (api.message, ZAPI_MESSAGE_TAG); + api.tag = tag; + } + if (BGP_DEBUG(zebra, ZEBRA)) { int i; - zlog_debug("Zebra send: IPv6 route %s %s/%d metric %u", + zlog_debug("Zebra send: IPv6 route %s %s/%d metric %u tag %d", valid_nh_count ? "add" : "delete", inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])), - p->prefixlen, api.metric); + p->prefixlen, api.metric, api.tag); for (i = 0; i < api.nexthop_num; i++) zlog_debug(" IPv6 [nexthop %d] %s", i+1, inet_ntop(AF_INET6, api.nexthop[i], buf[1], sizeof(buf[1]))); diff --git a/lib/zclient.c b/lib/zclient.c index 8d07edc..b816614 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -506,6 +506,8 @@ zclient_connect (struct thread *t) * If ZAPI_MESSAGE_METRIC is set, the metric value is written as an 8 * byte value. * + * If ZAPI_MESSAGE_TAG is set, the tag value is written as a 2 byte value + * * XXX: No attention paid to alignment. */ int @@ -564,6 +566,8 @@ zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p, stream_putl (s, api->metric); if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU)) stream_putl (s, api->mtu); + if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG)) + stream_putw (s, api->tag); /* Put length at the first point of the stream. */ stream_putw_at (s, 0, stream_get_endp (s)); @@ -620,6 +624,8 @@ zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, stream_putl (s, api->metric); if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU)) stream_putl (s, api->mtu); + if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG)) + stream_putw (s, api->tag); /* Put length at the first point of the stream. */ stream_putw_at (s, 0, stream_get_endp (s)); diff --git a/lib/zclient.h b/lib/zclient.h index cd2621f..58d9cb8 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -100,6 +100,7 @@ struct zclient #define ZAPI_MESSAGE_DISTANCE 0x04 #define ZAPI_MESSAGE_METRIC 0x08 #define ZAPI_MESSAGE_MTU 0x10 +#define ZAPI_MESSAGE_TAG 0x20 /* Zserv protocol message header */ struct zserv_header @@ -133,6 +134,8 @@ struct zapi_ipv4 u_char distance; + u_short tag; + u_int32_t metric; u_int32_t mtu; @@ -209,6 +212,8 @@ struct zapi_ipv6 u_char distance; + u_short tag; + u_int32_t metric; u_int32_t mtu; diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index cf2ea81..127bf50 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -526,6 +526,7 @@ ospf_zebra_add_discard (struct prefix_ipv4 *p) SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); api.nexthop_num = 0; api.ifindex_num = 0; + api.tag = 0; zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api); @@ -550,6 +551,7 @@ ospf_zebra_delete_discard (struct prefix_ipv4 *p) SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); api.nexthop_num = 0; api.ifindex_num = 0; + api.tag = 0; zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api); @@ -867,6 +869,10 @@ ospf_zebra_read_ipv4 (int command, struct zclient *zclient, api.distance = stream_getc (s); if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) api.metric = stream_getl (s); + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG)) + api.tag = stream_getw (s); + else + api.tag = 0; ospf = ospf_lookup (); if (ospf == NULL) diff --git a/zebra/zserv.c b/zebra/zserv.c index ac9679e..a368ba5 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -596,6 +596,12 @@ zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p, stream_putl (s, rib->metric); SET_FLAG (zapi_flags, ZAPI_MESSAGE_MTU); stream_putl (s, rib->mtu); + /* tag */ + if (rib->tag) + { + SET_FLAG(zapi_flags, ZAPI_MESSAGE_TAG); + stream_putw(s, rib->tag); + } } /* write real message flags value */ @@ -1113,6 +1119,9 @@ zread_ipv4_add (struct zserv *client, u_short length, vrf_id_t vrf_id) if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU)) rib->mtu = stream_getl (s); + /* Tag */ + if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG)) + rib->tag = stream_getw (s); /* Table */ rib->table=zebrad.rtm_table_default; @@ -1197,6 +1206,12 @@ zread_ipv4_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) else api.metric = 0; + /* tag */ + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG)) + api.tag = stream_getw (s); + else + api.tag = 0; + rib_delete_ipv4 (api.type, api.flags, &p, nexthop_p, ifindex, vrf_id, api.safi); return 0; @@ -1344,6 +1359,10 @@ zread_ipv6_add (struct zserv *client, u_short length, vrf_id_t vrf_id) if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU)) rib->mtu = stream_getl (s); + /* Tag */ + if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG)) + rib->tag = stream_getw (s); + /* Table */ rib->table=zebrad.rtm_table_default; rib_add_ipv6_multipath (&p, rib, safi); @@ -1399,15 +1418,24 @@ zread_ipv6_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) } } + /* Distance. */ if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) api.distance = stream_getc (s); else api.distance = 0; + + /* Metric. */ if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) api.metric = stream_getl (s); else api.metric = 0; + /* tag */ + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG)) + api.tag = stream_getw (s); + else + api.tag = 0; + if (IN6_IS_ADDR_UNSPECIFIED (&nexthop)) rib_delete_ipv6 (api.type, api.flags, &p, NULL, ifindex, vrf_id, api.safi); -- 1.9.1 _______________________________________________ Quagga-dev mailing list [email protected] https://lists.quagga.net/mailman/listinfo/quagga-dev
