From e1c94637ad50164292fe7e76a990b5e18b7de776 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 26 Aug 2021 14:34:24 +0200 Subject: [PATCH] dhcp: Send option 121 if the default gateway is not on the assigned subnet This enables CirrOS with udhcpc to set up a route to a gateway that's not on the assigned subnet, together with: https://bugs.launchpad.net/cirros/+bug/1190372 Signed-off-by: Stefano Brivio --- dhcp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dhcp.c b/dhcp.c index 04b04af..4969eec 100644 --- a/dhcp.c +++ b/dhcp.c @@ -308,6 +308,17 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len) *(unsigned long *)opts[3].s = c->gw4; *(unsigned long *)opts[54].s = c->gw4; + /* If the gateway is not on the assigned subnet, send an option 121 + * (Classless Static Routing) adding a dummy route to it. + */ + if ((c->addr4 & c->mask4) != (c->gw4 & c->mask4)) { + /* a.b.c.d/32:0.0.0.0, 0:a.b.c.d */ + opts[121].slen = 14; + opts[121].s[0] = 32; + *(unsigned long *)&opts[121].s[1] = c->gw4; + *(unsigned long *)&opts[121].s[10] = c->gw4; + } + if (c->mtu) { opts[26].slen = 2; opts[26].s[0] = c->mtu / 256;