Skip to contentSkip to conversation

netconfig: Set preferred lifetimes on DHCP addresses

PATCH In review Andrew Zaborowski 2 participants 3 messages Oct 7, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 netconfig: Set preferred lifetimes on DHCP addresses

We receive one lease lifetime value for a DHCP lease so we were setting the preferred lifetime for the RTNL address to 0 and the valid lifetime to the lease lifetime. If either value is non-zero rtnl.c will send both to the kernel and the 0 preferred lifetime is treated as literal zero and the address becomes deprecated immediately. This doesn't matter for most usages but systemd-resolved would check whether a link has a non-deprecated address before setting the link's "unicast_relevant" flag and internally wouldn't create a DNS "scope" on the link or set its "DefaultRoute" flag both of which are required for it to want to resolve names.

---
 ell/netconfig.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ell/netconfig.c +2 -2
index 76b18a7..8ded113 100644
@@ -405,8 +405,8 @@ static void netconfig_set_dhcp_lifetimes(struct l_netconfig *nc, bool updated)
 	uint64_t expiry = l_dhcp_lease_get_start_time(lease) +
 		lifetime * L_USEC_PER_SEC;
 
-	l_rtnl_address_set_lifetimes(nc->v4_address, 0, lifetime);
-	l_rtnl_address_set_expiry(nc->v4_address, 0, expiry);
+	l_rtnl_address_set_lifetimes(nc->v4_address, lifetime, lifetime);
+	l_rtnl_address_set_expiry(nc->v4_address, expiry, expiry);
 
 	if (updated && !netconfig_address_exists(nc->addresses.added,
 							nc->v4_address))
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 dhcp: Simplify check in BPF filter

Instead of separately loading and testing the low 4 bits and the high 4 bits of the IP Version+Header length byte in the DHCP frame, test both in one operation. The filter can be further shortened but with some loss of readability.

---
 ell/dhcp-transport.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
ell/dhcp-transport.c +2 -12
index c4cf0ca..41b582d 100644
@@ -389,18 +389,8 @@ static int kernel_raw_socket_open(uint32_t ifindex, uint16_t port, uint32_t xid)
 		BPF_STMT(BPF_RET + BPF_K, 0),
 		/* A <- IP version + Header length */
 		BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 0),
-		/* A <- A & 0xf0 (Mask off version */
-		BPF_STMT(BPF_ALU + BPF_AND + BPF_K, 0xf0),
-		/* A == IPVERSION (shifted left 4) ? */
-		BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPVERSION << 4, 1, 0),
-		/* ignore */
-		BPF_STMT(BPF_RET + BPF_K, 0),
-		/* A <- IP version + Header length */
-		BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 0),
-		/* A <- A & 0x0f (Mask off IP Header Length */
-		BPF_STMT(BPF_ALU + BPF_AND + BPF_K, 0x0f),
-		/* A == 5 ? */
-		BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 5, 1, 0),
+		/* IP version == IPVERSION && Header length == 5 ? */
+		BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (IPVERSION << 4) | 5, 1, 0),
 		/* ignore */
 		BPF_STMT(BPF_RET + BPF_K, 0),
 		/* A <- IP protocol */
Signature · 1 line
2.34.1
#2 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 10 lines · Andrew Zaborowski

We receive one lease lifetime value for a DHCP lease so we were setting the preferred lifetime for the RTNL address to 0 and the valid lifetime to the lease lifetime. If either value is non-zero rtnl.c will send both to the kernel and the 0 preferred lifetime is treated as literal zero and the address becomes deprecated immediately. This doesn't matter for most usages but systemd-resolved would check whether a link has a non-deprecated address before setting the link's "unicast_relevant" flag and internally wouldn't create a DNS "scope" on the link or set its "DefaultRoute" flag both of which are required for it to want to resolve names.

Quoted 4 lines
---
  ell/netconfig.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Both applied, thanks.

Regards,
-Denis