From 16f4b983de5509660f470992f3ce8e5cd1d59c3b Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 5 Oct 2021 21:15:01 +0200 Subject: passt: Shrink binary size by dropping static initialisers ...from 11MiB to 155KiB for 'make avx2', 95KiB with -Os and stripped. Signed-off-by: Stefano Brivio --- dhcp.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'dhcp.c') diff --git a/dhcp.c b/dhcp.c index 24194ee..7deced1 100644 --- a/dhcp.c +++ b/dhcp.c @@ -46,11 +46,8 @@ struct opt { unsigned char c[255]; }; -static struct opt opts[255] = { - [1] = { 0, 4, { 0 }, 0, { 0 }, }, /* Mask */ - [3] = { 0, 4, { 0 }, 0, { 0 }, }, /* Router */ - [51] = { 0, 4, { 0xff, 0xff, 0xff, 0xff }, 0, { 0 }, }, /* Lease time */ - [53] = { 0, 1, { 0 }, 0, { 0 }, }, /* Type */ +static struct opt opts[255]; + #define DHCPDISCOVER 1 #define DHCPOFFER 2 #define DHCPREQUEST 3 @@ -60,8 +57,21 @@ static struct opt opts[255] = { #define DHCPRELEASE 7 #define DHCPINFORM 8 #define DHCPFORCERENEW 9 - [54] = { 0, 4, { 0 }, 0, { 0 }, }, /* Server ID */ -}; + +/** + * dhcp_init() - Initialise DHCP options + */ +void dhcp_init(void) +{ + opts[1] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Mask */ + opts[3] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Router */ + opts[51] = (struct opt) { 0, 4, { 0xff, + 0xff, + 0xff, + 0xff }, 0, { 0 }, }; /* Lease time */ + opts[53] = (struct opt) { 0, 1, { 0 }, 0, { 0 }, }; /* Type */ + opts[54] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Server ID */ +} /** * struct msg - BOOTP/DHCP message -- cgit v1.2.3