diff options
| author | Roy Marples <roy@marples.name> | 2019-03-05 00:28:36 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-03-05 00:28:36 +0000 |
| commit | 59823748fea1b64f0a34125fd5a0591a34029600 (patch) | |
| tree | 25a23bc0321843a3138530c57418bb433a55226f /src/if-bsd.c | |
| parent | f1ea704ea8b1fec41299b04b40fb6ee17151299c (diff) | |
| download | dhcpcd-59823748fea1b64f0a34125fd5a0591a34029600.tar.xz | |
route: Remove kroutes and make froutes optional
This is an attempt to reduce the memory dhcpcd uses.
By removing kroutes and froutes from global context.
kroutes are generated at the start of rt_build and freed at
the end.
Diffstat (limited to 'src/if-bsd.c')
| -rw-r--r-- | src/if-bsd.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/if-bsd.c b/src/if-bsd.c index 8d281b42..20981411 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -657,15 +657,13 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, const struct rt_msghdr *rtm) } int -if_initrt(struct dhcpcd_ctx *ctx, int af) +if_initrt(struct dhcpcd_ctx *ctx, rb_tree_t *kroutes, int af) { struct rt_msghdr *rtm; int mib[6]; size_t needed; char *buf, *p, *end; - struct rt rt; - - rt_headclear(&ctx->kroutes, af); + struct rt rt, *rtn; mib[0] = CTL_NET; mib[1] = PF_ROUTE; @@ -688,10 +686,15 @@ if_initrt(struct dhcpcd_ctx *ctx, int af) end = buf + needed; for (p = buf; p < end; p += rtm->rtm_msglen) { rtm = (void *)p; - if (if_copyrt(ctx, &rt, rtm) == 0) { - rt.rt_dflags |= RTDF_INIT; - rt_recvrt(RTM_ADD, &rt); + if (if_copyrt(ctx, &rt, rtm) != 0) + continue; + if ((rtn = rt_new(rt.rt_ifp)) == NULL) { + logerr(__func__); + break; } + memcpy(rtn, &rt, sizeof(*rtn)); + if (rb_tree_insert_node(kroutes, rtn) != rtn) + rt_free(rtn); } free(buf); return 0; |
