On Mon, 23 Mar 2026 18:37:28 +1100
David Gibson
Implement serialisation of our current forwarding rules in conf.c, deserialising it to display in the pesto client.
Signed-off-by: David Gibson
--- conf.c | 44 +++++++++++++++++++++++++++++++ fwd_rule.c | 40 ++++++++++++++++++++++++++++ fwd_rule.h | 3 +++ pesto.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 160 insertions(+), 4 deletions(-) diff --git a/conf.c b/conf.c index b878db94..7f311914 100644 --- a/conf.c +++ b/conf.c @@ -2338,6 +2338,47 @@ static int conf_send_pifs(const struct ctx *c, int fd) return 0; }
+/** + * conf_send_rules() - Send current forwarding rules to dynamic update client (pesto)
What about: * conf_send_rules() - Send forwarding rules to configuration client (pesto) ?
+ * @c: Execution context + * @fd: Socket to the client + * + * Return: 0 on success, -1 on failure + */ +static int conf_send_rules(const struct ctx *c, int fd) +{ + unsigned pif; + + for (pif = 0; pif < PIF_NUM_TYPES; pif++) { + const struct fwd_table *fwd = c->fwd[pif]; + unsigned i; + + if (!fwd) + continue; + + assert(pif); + + /* PIF id */ + if (write_u8(fd, pif)) + return -1; + + /* Number of rules */ + if (write_u32(fd, fwd->count)) + return -1; + + for (i = 0; i < fwd->count; i++) { + if (fwd_rule_write(fd, &fwd->rules[i].rule)) + return -1; + } + } + + /* Write 0 PIF id to finish */ + if (write_u8(fd, 0))
We have PIF_NONE, shouldn't we use that to make it obvious that it's an invalid value?
+ return -1; + + return 0; +}
[...]
I stopped reviewing here, the next patches in my series are anyway mine and after those I guess it doesn't make sense, yet, that I review in fine detail, as we'll probably need to change a bunch of things. -- Stefano