Skip to content

Commit

Permalink
gatekeeper: drop rte_panic() while dumping the routing table
Browse files Browse the repository at this point in the history
This patch is meant to help to collect information for issue #585,
and to allow Gatekeeper servers in production to keep running even
if they find the routing table is corrupted while dumping it.

This patch also pushes issue #572 forward.
  • Loading branch information
AltraMayor committed Jul 29, 2022
1 parent 653b720 commit 31df1a0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
46 changes: 33 additions & 13 deletions cps/rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,9 @@ put_priority(struct nlmsghdr *reply, uint32_t priority)
}

static void
rd_fill_getroute_reply(const struct cps_config *cps_conf,
struct nlmsghdr *reply, struct gk_fib *fib, int family, uint32_t seq,
uint8_t prefix_len, struct ipaddr **gw_addr)
rd_fill_getroute_reply(const void *prefix, const struct cps_config *cps_conf,
struct nlmsghdr *reply, const struct gk_fib *fib, int family,
uint32_t seq, uint8_t prefix_len, struct ipaddr **gw_addr)
{
struct rtmsg *rm;

Expand Down Expand Up @@ -677,15 +677,35 @@ rd_fill_getroute_reply(const struct cps_config *cps_conf,
*gw_addr = NULL;
break;
case GK_DROP:
put_priority(reply, fib->u.gateway.props.priority);
put_priority(reply, fib->u.drop.props.priority);
rm->rtm_protocol = fib->u.drop.props.rt_proto;
rm->rtm_type = RTN_BLACKHOLE;
*gw_addr = NULL;
break;
default:
rte_panic("Invalid FIB action (%u) in FIB while being processed by CPS block in %s\n",
fib->action, __func__);
return;
default: {
/*
* Things went bad, but keep going.
*/

char str_prefix[INET6_ADDRSTRLEN];

RTE_BUILD_BUG_ON(INET6_ADDRSTRLEN < INET_ADDRSTRLEN);

/* Enter some generic values. */
rm->rtm_protocol = RTPROT_STATIC;
rm->rtm_type = RTN_UNICAST;
*gw_addr = NULL;

if (unlikely(inet_ntop(family, prefix, str_prefix,
sizeof(str_prefix)) == NULL)) {
G_LOG(ERR, "%s(): failed to convert address of family=%i to a string (errno=%i): %s\n",
__func__, family, errno, strerror(errno));
strcpy(str_prefix, "<ERROR>");
}
G_LOG(CRIT, "%s(%s/%i): invalid FIB action (%u) in FIB",
__func__, str_prefix, prefix_len, fib->action);
break;
}
}
}

Expand Down Expand Up @@ -765,12 +785,13 @@ rd_getroute_ipv4(struct cps_config *cps_conf, struct gk_lpm *ltbl,
struct ipaddr *gw_addr;
struct nlmsghdr *reply =
mnl_nlmsg_put_header(mnl_nlmsg_batch_current(batch));
uint32_t ip = htonl(re4->ip);

rd_fill_getroute_reply(cps_conf, reply, fib,
rd_fill_getroute_reply(&ip, cps_conf, reply, fib,
AF_INET, req->nlmsg_seq, state.depth, &gw_addr);

/* Add address. */
mnl_attr_put_u32(reply, RTA_DST, htonl(re4->ip));
mnl_attr_put_u32(reply, RTA_DST, ip);

if (fib->action == GK_FWD_GRANTOR) {
unsigned int i;
Expand Down Expand Up @@ -835,12 +856,11 @@ rd_getroute_ipv6(struct cps_config *cps_conf, struct gk_lpm *ltbl,
struct nlmsghdr *reply =
mnl_nlmsg_put_header(mnl_nlmsg_batch_current(batch));

rd_fill_getroute_reply(cps_conf, reply, fib,
rd_fill_getroute_reply(re6.ip, cps_conf, reply, fib,
AF_INET6, req->nlmsg_seq, re6.depth, &gw_addr);

/* Add address. */
mnl_attr_put(reply, RTA_DST,
sizeof(struct in6_addr), re6.ip);
mnl_attr_put(reply, RTA_DST, sizeof(struct in6_addr), re6.ip);

if (fib->action == GK_FWD_GRANTOR) {
unsigned int i;
Expand Down
25 changes: 21 additions & 4 deletions gk/fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,8 +1906,13 @@ fillup_gk_fib_dump_entry_ether(struct fib_dump_addr_set *addr_set,
&addr_set->d_addr);
}

/*
* CAUTION: fields @dentry->addr and @dentry->prefix_len must be filled in
* before calling this function.
*/
static void
fillup_gk_fib_dump_entry(struct gk_fib_dump_entry *dentry, struct gk_fib *fib)
fillup_gk_fib_dump_entry(struct gk_fib_dump_entry *dentry,
const struct gk_fib *fib)
{
dentry->action = fib->action;
switch (dentry->action) {
Expand Down Expand Up @@ -1935,11 +1940,23 @@ fillup_gk_fib_dump_entry(struct gk_fib_dump_entry *dentry, struct gk_fib *fib)
case GK_DROP:
break;

default:
rte_panic("%s() at lcore %u: invalid FIB action (%u)\n",
__func__, rte_lcore_id(), fib->action);
default: {
/*
* Things went bad, but keep going.
*/

char str_prefix[INET6_ADDRSTRLEN];

RTE_BUILD_BUG_ON(INET6_ADDRSTRLEN < INET_ADDRSTRLEN);

if (unlikely(convert_ip_to_str(&dentry->addr, str_prefix,
sizeof(str_prefix)) < 0))
strcpy(str_prefix, "<ERROR>");
G_LOG(CRIT, "%s(%s/%i): invalid FIB action (%u) in FIB",
__func__, str_prefix, dentry->prefix_len, fib->action);
break;
}
}
}

#define CTYPE_STRUCT_FIB_DUMP_ENTRY_PTR "struct gk_fib_dump_entry *"
Expand Down

0 comments on commit 31df1a0

Please sign in to comment.