diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2017-08-21 03:10:50 +0200 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2017-08-24 01:25:45 +0200 |
commit | 744899219f4214398a3078874a341000a372e29d (patch) | |
tree | b33edf26332d87c734bb68f19efb3b4d37fd5a4f /ripngd/ripng_zebra.c | |
parent | bgpd: unify ipv4/ipv6 zebra-tx functions (diff) | |
download | frr-744899219f4214398a3078874a341000a372e29d.tar.xz frr-744899219f4214398a3078874a341000a372e29d.zip |
*: use zapi_route to send/receive redistributed routes as well
Some differences compared to the old API:
* Now the redistributed routes are sent using address-family
independent messages (ZEBRA_REDISTRIBUTE_ROUTE_ADD and
ZEBRA_REDISTRIBUTE_ROUTE_DEL). This allows us to unify the ipv4/ipv6
zclient callbacks in the client daemons and thus remove a lot of
duplicate code;
* Now zebra sends all nexthops of the redistributed routes to the client
daemons, not only the first one. This shouldn't have any noticeable
performance implications and will allow us to remove an ugly exception
we had for ldpd (which needs to know all nexthops of the redistributed
routes). The other client daemons can simply ignore the nexthops if
they want or consult just the first one (e.g. ospfd/ospf6d/ripd/ripngd).
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'ripngd/ripng_zebra.c')
-rw-r--r-- | ripngd/ripng_zebra.c | 76 |
1 files changed, 18 insertions, 58 deletions
diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c index a5ed5c7b2..283d8691a 100644 --- a/ripngd/ripng_zebra.c +++ b/ripngd/ripng_zebra.c @@ -109,71 +109,31 @@ void ripng_zebra_ipv6_delete(struct route_node *rp) } /* Zebra route add and delete treatment. */ -static int ripng_zebra_read_ipv6(int command, struct zclient *zclient, - zebra_size_t length, vrf_id_t vrf_id) +static int ripng_zebra_read_route(int command, struct zclient *zclient, + zebra_size_t length, vrf_id_t vrf_id) { - struct stream *s; - struct zapi_ipv6 api; - unsigned long ifindex; + struct zapi_route api; struct in6_addr nexthop; - struct prefix_ipv6 p, src_p; - - s = zclient->ibuf; - ifindex = 0; - memset(&nexthop, 0, sizeof(struct in6_addr)); - - /* Type, flags, message. */ - api.type = stream_getc(s); - api.instance = stream_getw(s); - api.flags = stream_getl(s); - api.message = stream_getc(s); - - /* IPv6 prefix. */ - memset(&p, 0, sizeof(struct prefix_ipv6)); - p.family = AF_INET6; - p.prefixlen = MIN(IPV6_MAX_PREFIXLEN, stream_getc(s)); - stream_get(&p.prefix, s, PSIZE(p.prefixlen)); - - memset(&src_p, 0, sizeof(struct prefix_ipv6)); - src_p.family = AF_INET6; - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) { - src_p.prefixlen = stream_getc(s); - stream_get(&src_p.prefix, s, PSIZE(src_p.prefixlen)); - } + unsigned long ifindex; - if (src_p.prefixlen) - /* we completely ignore srcdest routes for now. */ - return 0; + if (zapi_route_decode(zclient->ibuf, &api) < 0) + return -1; - /* Nexthop, ifindex, distance, metric. */ - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) { - api.nexthop_num = stream_getc(s); - stream_get(&nexthop, s, 16); - } - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) { - api.ifindex_num = stream_getc(s); - ifindex = stream_getl(s); - } - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE)) - api.distance = stream_getc(s); - else - api.distance = 0; - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC)) - api.metric = stream_getl(s); - else - api.metric = 0; + /* we completely ignore srcdest routes for now. */ + if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) + return 0; - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_TAG)) - api.tag = stream_getl(s); - else - api.tag = 0; + nexthop = api.nexthops[0].gate.ipv6; + ifindex = api.nexthops[0].ifindex; - if (command == ZEBRA_REDISTRIBUTE_IPV6_ADD) - ripng_redistribute_add(api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, + if (command == ZEBRA_REDISTRIBUTE_ROUTE_ADD) + ripng_redistribute_add(api.type, RIPNG_ROUTE_REDISTRIBUTE, + (struct prefix_ipv6 *)&api.prefix, ifindex, &nexthop, api.tag); else ripng_redistribute_delete(api.type, RIPNG_ROUTE_REDISTRIBUTE, - &p, ifindex); + (struct prefix_ipv6 *)&api.prefix, + ifindex); return 0; } @@ -461,8 +421,8 @@ void zebra_init(struct thread_master *master) zclient->interface_delete = ripng_interface_delete; zclient->interface_address_add = ripng_interface_address_add; zclient->interface_address_delete = ripng_interface_address_delete; - zclient->redistribute_route_ipv6_add = ripng_zebra_read_ipv6; - zclient->redistribute_route_ipv6_del = ripng_zebra_read_ipv6; + zclient->redistribute_route_add = ripng_zebra_read_route; + zclient->redistribute_route_del = ripng_zebra_read_route; /* Install command elements to ripng node */ install_element(RIPNG_NODE, &ripng_redistribute_type_cmd); |