summaryrefslogtreecommitdiff
path: root/babeld/kernel.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2017-08-19 21:25:12 -0300
committerRenato Westphal <renato@opensourcerouting.org>2017-08-23 17:45:17 -0300
commitbb1b9c47ca090ce4484e1f8061f17b5c33f578ee (patch)
tree0b6f114b78a84f0dffeb7de41a685d33e152879e /babeld/kernel.c
parent81c11e3feafcd20e32cb2d437f39603d645e6880 (diff)
lib: updates to zapi_route
This patch introduces the following changes to the zapi_route structure and associated code: * Use a fixed-size array to store the nexthops instead of a pointer. This makes the zapi_route() function much easier to use when we have multiple nexthops to send. It's also much more efficient to put everything on the stack rather than allocating an array in the heap every time we need to send a route to zebra; * Use the new 'zapi_nexthop' structure. This will allow the client daemons to send labeled routes without having to allocate memory for the labels (the 'nexthop' structure was designed to be memory efficient and doesn't have room for MPLS labels, only a pointer). Also, 'zapi_nexthop' is more compact and more clean from an API perspective; * Embed the route prefix inside the zapi_route structure. Since the route's prefix is sent along with its nexthops and attributes, it makes sense to pack everything inside the same structure. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'babeld/kernel.c')
-rw-r--r--babeld/kernel.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/babeld/kernel.c b/babeld/kernel.c
index 26860f3bae..105a7d0518 100644
--- a/babeld/kernel.c
+++ b/babeld/kernel.c
@@ -144,15 +144,15 @@ kernel_route_v4(int add,
const unsigned char *gate, int ifindex, unsigned int metric)
{
struct zapi_route api; /* quagga's communication system */
+ struct zapi_nexthop *api_nh; /* next router to go - no ECMP */
struct prefix quagga_prefix; /* quagga's prefix */
struct in_addr babel_prefix_addr; /* babeld's prefix addr */
- struct nexthop nexthop; /* next router to go */
- struct nexthop *nexthop_pointer = &nexthop; /* it's an array! */
+
+ api_nh = &api.nexthops[0];
/* convert to be understandable by quagga */
/* convert given addresses */
uchar_to_inaddr(&babel_prefix_addr, pref);
- uchar_to_inaddr(&nexthop.gate.ipv4, gate);
/* make prefix structure */
memset (&quagga_prefix, 0, sizeof(quagga_prefix));
@@ -168,6 +168,7 @@ kernel_route_v4(int add,
api.instance = 0;
api.safi = SAFI_UNICAST;
api.vrf_id = VRF_DEFAULT;
+ api.prefix = quagga_prefix;
SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
if(metric >= KERNEL_INFINITY) {
@@ -175,13 +176,13 @@ kernel_route_v4(int add,
api.nexthop_num = 0;
} else {
api.nexthop_num = 1;
- api.nexthop = &nexthop_pointer;
- nexthop.ifindex = ifindex;
- if (IPV4_ADDR_SAME (&nexthop.gate.ipv4, &quagga_prefix.u.prefix4) &&
+ api_nh->ifindex = ifindex;
+ uchar_to_inaddr(&api_nh->gate.ipv4, gate);
+ if (IPV4_ADDR_SAME (&api_nh->gate.ipv4, &quagga_prefix.u.prefix4) &&
quagga_prefix.prefixlen == 32) {
- nexthop.type = NEXTHOP_TYPE_IFINDEX;
+ api_nh->type = NEXTHOP_TYPE_IFINDEX;
} else {
- nexthop.type = NEXTHOP_TYPE_IPV4_IFINDEX;
+ api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
}
SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
api.metric = metric;
@@ -191,7 +192,7 @@ kernel_route_v4(int add,
add ? "adding" : "removing" );
return zapi_route (add ? ZEBRA_IPV4_ROUTE_ADD :
ZEBRA_IPV4_ROUTE_DELETE,
- zclient, &quagga_prefix, NULL, &api);
+ zclient, &api);
}
static int
@@ -199,15 +200,15 @@ kernel_route_v6(int add, const unsigned char *pref, unsigned short plen,
const unsigned char *gate, int ifindex, unsigned int metric)
{
struct zapi_route api; /* quagga's communication system */
+ struct zapi_nexthop *api_nh; /* next router to go - no ECMP */
struct prefix quagga_prefix; /* quagga's prefix */
struct in6_addr babel_prefix_addr; /* babeld's prefix addr */
- struct nexthop nexthop; /* next router to go */
- struct nexthop *nexthop_pointer = &nexthop;
+
+ api_nh = &api.nexthops[0];
/* convert to be understandable by quagga */
/* convert given addresses */
uchar_to_in6addr(&babel_prefix_addr, pref);
- uchar_to_in6addr(&nexthop.gate.ipv6, gate);
/* make prefix structure */
memset (&quagga_prefix, 0, sizeof(quagga_prefix));
@@ -223,6 +224,7 @@ kernel_route_v6(int add, const unsigned char *pref, unsigned short plen,
api.instance = 0;
api.safi = SAFI_UNICAST;
api.vrf_id = VRF_DEFAULT;
+ api.prefix = quagga_prefix;
if(metric >= KERNEL_INFINITY) {
api.flags = ZEBRA_FLAG_REJECT;
@@ -230,10 +232,10 @@ kernel_route_v6(int add, const unsigned char *pref, unsigned short plen,
} else {
SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
api.nexthop_num = 1;
- api.nexthop = &nexthop_pointer;
- nexthop.ifindex = ifindex;
+ api_nh->ifindex = ifindex;
+ uchar_to_in6addr(&api_nh->gate.ipv6, gate);
/* difference to IPv4: always leave the linklocal as nexthop */
- nexthop.type = NEXTHOP_TYPE_IPV6_IFINDEX;
+ api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
api.metric = metric;
}
@@ -242,7 +244,7 @@ kernel_route_v6(int add, const unsigned char *pref, unsigned short plen,
add ? "adding" : "removing" );
return zapi_route (add ? ZEBRA_IPV6_ROUTE_ADD :
ZEBRA_IPV6_ROUTE_DELETE,
- zclient, &quagga_prefix, NULL, &api);
+ zclient, &api);
}
int