libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for it

The config item is FEATURE_USE_BSS_TAIL. When it is off (default):

function                                             old     new   delta
read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
push                                                  46      44      -2
inetd_main                                          2136    2134      -2
uevent_main                                          421     418      -3
addLines                                              97      92      -5
bb_common_bufsiz1                                   8193    1024   -7169
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/5 up/down: 62/-7181)        Total: -7119 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829901	   4086	   1904	 835891	  cc133	busybox_unstripped

FEATURE_USE_BSS_TAIL=y:

read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
inetd_main                                          2136    2134      -2
bb_common_bufsiz1                                   8193       -   -8193
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 8/1 up/down: 62/-8195)        Total: -8133 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829911	   4086	    880	 834877	  cbd3d	busybox_unstripped

FIXME: setup_common_bufsiz() calls are missing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2016-04-21 16:26:30 +02:00
parent 5598bdf0d3
commit e6a2f4cc5a
91 changed files with 414 additions and 131 deletions

View File

@@ -9,6 +9,7 @@
#define UDHCP_COMMON_H 1
#include "libbb.h"
#include "common_bufsiz.h"
#include <netinet/udp.h>
#include <netinet/ip.h>

View File

@@ -57,7 +57,7 @@ struct server_config_t {
struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
} FIX_ALIASING;
#define server_config (*(struct server_config_t*)&bb_common_bufsiz1)
#define server_config (*(struct server_config_t*)bb_common_bufsiz1)
/* client_config sits in 2nd half of bb_common_bufsiz1 */
#if ENABLE_FEATURE_UDHCP_PORT

View File

@@ -33,7 +33,7 @@ struct xid_item {
struct xid_item *next;
} FIX_ALIASING;
#define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1)
#define dhcprelay_xid_list (*(struct xid_item*)bb_common_bufsiz1)
static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
{

View File

@@ -57,33 +57,35 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
struct config_keyword {
const char *keyword;
int (*handler)(const char *line, void *var) FAST_FUNC;
void *var;
unsigned ofs;
const char *def;
};
#define OFS(field) offsetof(struct server_config_t, field)
static const struct config_keyword keywords[] = {
/* keyword handler variable address default */
{"start" , udhcp_str2nip , &server_config.start_ip , "192.168.0.20"},
{"end" , udhcp_str2nip , &server_config.end_ip , "192.168.0.254"},
{"interface" , read_str , &server_config.interface , "eth0"},
{"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"},
{"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"},
{"interface" , read_str , OFS(interface ), "eth0"},
/* Avoid "max_leases value not sane" warning by setting default
* to default_end_ip - default_start_ip + 1: */
{"max_leases" , read_u32 , &server_config.max_leases , "235"},
{"auto_time" , read_u32 , &server_config.auto_time , "7200"},
{"decline_time" , read_u32 , &server_config.decline_time , "3600"},
{"conflict_time", read_u32 , &server_config.conflict_time, "3600"},
{"offer_time" , read_u32 , &server_config.offer_time , "60"},
{"min_lease" , read_u32 , &server_config.min_lease_sec, "60"},
{"lease_file" , read_str , &server_config.lease_file , LEASES_FILE},
{"pidfile" , read_str , &server_config.pidfile , "/var/run/udhcpd.pid"},
{"siaddr" , udhcp_str2nip , &server_config.siaddr_nip , "0.0.0.0"},
{"max_leases" , read_u32 , OFS(max_leases ), "235"},
{"auto_time" , read_u32 , OFS(auto_time ), "7200"},
{"decline_time" , read_u32 , OFS(decline_time ), "3600"},
{"conflict_time", read_u32 , OFS(conflict_time), "3600"},
{"offer_time" , read_u32 , OFS(offer_time ), "60"},
{"min_lease" , read_u32 , OFS(min_lease_sec), "60"},
{"lease_file" , read_str , OFS(lease_file ), LEASES_FILE},
{"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"},
{"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"},
/* keywords with no defaults must be last! */
{"option" , udhcp_str2optset, &server_config.options , ""},
{"opt" , udhcp_str2optset, &server_config.options , ""},
{"notify_file" , read_str , &server_config.notify_file , NULL},
{"sname" , read_str , &server_config.sname , NULL},
{"boot_file" , read_str , &server_config.boot_file , NULL},
{"static_lease" , read_staticlease, &server_config.static_leases, ""},
{"option" , udhcp_str2optset, OFS(options ), ""},
{"opt" , udhcp_str2optset, OFS(options ), ""},
{"notify_file" , read_str , OFS(notify_file ), NULL},
{"sname" , read_str , OFS(sname ), NULL},
{"boot_file" , read_str , OFS(boot_file ), NULL},
{"static_lease" , read_staticlease, OFS(static_leases), ""},
};
enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
@@ -95,17 +97,17 @@ void FAST_FUNC read_config(const char *file)
char *token[2];
for (i = 0; i < KWS_WITH_DEFAULTS; i++)
keywords[i].handler(keywords[i].def, keywords[i].var);
keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
parser = config_open(file);
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
if (strcasecmp(token[0], k->keyword) == 0) {
if (!k->handler(token[1], k->var)) {
if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
bb_error_msg("can't parse line %u in %s",
parser->lineno, file);
/* reset back to the default value */
k->handler(k->def, k->var);
k->handler(k->def, (char*)&server_config + k->ofs);
}
break;
}