Skip to content

Commit

Permalink
bgpd, lib, ospfd, zebra: Add ability to read/write tag value
Browse files Browse the repository at this point in the history
Modify zebra to pass the tag value to and from the
various protocols.

[forward ported by Cumulus]

Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
Signed-off-by: Piotr Chytla <pch@packetconsulting.pl>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Edits: Paul Jakma <paul.jakma@hpe.com> rebase conflicts in bgp_zebra.c
  • Loading branch information
pchytla authored and pjakma committed Oct 4, 2016
1 parent de24f82 commit eefddcc
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 12 deletions.
52 changes: 40 additions & 12 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,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,
api.metric, api.type);
Expand All @@ -299,12 +305,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);
}
Expand Down Expand Up @@ -358,6 +365,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;
Expand All @@ -367,12 +379,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,
api.metric, api.type);
Expand All @@ -383,12 +396,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);
}
Expand Down Expand Up @@ -680,6 +694,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
struct bgp_info *mpinfo;
size_t oldsize, newsize;
u_int32_t nhcount;
u_short tag = 0;

if (zclient->sock < 0)
return;
Expand Down Expand Up @@ -742,6 +757,12 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
api.metric = info->attr->med;

if (tag)
{
SET_FLAG (api.message, ZAPI_MESSAGE_TAG);
api.tag = tag;
}

distance = bgp_distance_apply (p, info, bgp);

if (distance)
Expand All @@ -755,11 +776,11 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
int i;
char buf[2][INET_ADDRSTRLEN];
zlog_debug("Zebra send: IPv4 route add %s/%d nexthop %s metric %u"
" count %d",
" tag %u count %d",
inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])),
p->prefixlen,
inet_ntop(AF_INET, api.nexthop[0], buf[1], sizeof(buf[1])),
api.metric, api.nexthop_num);
api.metric, api.tag, api.nexthop_num);
for (i = 1; i < api.nexthop_num; i++)
zlog_debug("Zebra send: IPv4 route add [nexthop %d] %s",
i, inet_ntop(AF_INET, api.nexthop[i], buf[1],
Expand Down Expand Up @@ -921,15 +942,22 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
api.distance = distance;
}

if (tag)
{
SET_FLAG (api.message, ZAPI_MESSAGE_TAG);
api.tag = tag;
}

if (BGP_DEBUG(zebra, ZEBRA))
{
char buf[2][INET6_ADDRSTRLEN];
zlog_debug("Zebra send: IPv6 route add %s/%d nexthop %s metric %u",
zlog_debug("Zebra send: IPv6 route add %s/%d nexthop %s metric %u"
" tag %u",
inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])),
p->prefixlen,
inet_ntop(AF_INET6, nexthop, buf[1], sizeof(buf[1])),
api.metric);
api.metric, api.tag);
}

zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient,
Expand Down
6 changes: 6 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,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
Expand Down Expand Up @@ -588,6 +590,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));
Expand Down Expand Up @@ -644,6 +648,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));
Expand Down
5 changes: 5 additions & 0 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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
Expand Down Expand Up @@ -132,6 +133,8 @@ struct zapi_ipv4

u_char distance;

u_short tag;

u_int32_t metric;

u_int32_t mtu;
Expand Down Expand Up @@ -210,6 +213,8 @@ struct zapi_ipv6

u_char distance;

u_short tag;

u_int32_t metric;

u_int32_t mtu;
Expand Down
6 changes: 6 additions & 0 deletions ospfd/ospf_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,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);

Expand All @@ -569,6 +570,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);

Expand Down Expand Up @@ -888,6 +890,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)
Expand Down
28 changes: 28 additions & 0 deletions zebra/zserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,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 */
Expand Down Expand Up @@ -1003,6 +1009,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;
Expand Down Expand Up @@ -1087,6 +1096,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;
Expand Down Expand Up @@ -1234,6 +1249,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);
Expand Down Expand Up @@ -1289,15 +1308,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);
Expand Down

0 comments on commit eefddcc

Please sign in to comment.