diff options
Diffstat (limited to 'networking/udhcp/files.c')
-rw-r--r-- | networking/udhcp/files.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 7b57c6258..b22425352 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -57,33 +57,35 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg) | |||
57 | struct config_keyword { | 57 | struct config_keyword { |
58 | const char *keyword; | 58 | const char *keyword; |
59 | int (*handler)(const char *line, void *var) FAST_FUNC; | 59 | int (*handler)(const char *line, void *var) FAST_FUNC; |
60 | void *var; | 60 | unsigned ofs; |
61 | const char *def; | 61 | const char *def; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | #define OFS(field) offsetof(struct server_config_t, field) | ||
65 | |||
64 | static const struct config_keyword keywords[] = { | 66 | static const struct config_keyword keywords[] = { |
65 | /* keyword handler variable address default */ | 67 | /* keyword handler variable address default */ |
66 | {"start" , udhcp_str2nip , &server_config.start_ip , "192.168.0.20"}, | 68 | {"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"}, |
67 | {"end" , udhcp_str2nip , &server_config.end_ip , "192.168.0.254"}, | 69 | {"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"}, |
68 | {"interface" , read_str , &server_config.interface , "eth0"}, | 70 | {"interface" , read_str , OFS(interface ), "eth0"}, |
69 | /* Avoid "max_leases value not sane" warning by setting default | 71 | /* Avoid "max_leases value not sane" warning by setting default |
70 | * to default_end_ip - default_start_ip + 1: */ | 72 | * to default_end_ip - default_start_ip + 1: */ |
71 | {"max_leases" , read_u32 , &server_config.max_leases , "235"}, | 73 | {"max_leases" , read_u32 , OFS(max_leases ), "235"}, |
72 | {"auto_time" , read_u32 , &server_config.auto_time , "7200"}, | 74 | {"auto_time" , read_u32 , OFS(auto_time ), "7200"}, |
73 | {"decline_time" , read_u32 , &server_config.decline_time , "3600"}, | 75 | {"decline_time" , read_u32 , OFS(decline_time ), "3600"}, |
74 | {"conflict_time", read_u32 , &server_config.conflict_time, "3600"}, | 76 | {"conflict_time", read_u32 , OFS(conflict_time), "3600"}, |
75 | {"offer_time" , read_u32 , &server_config.offer_time , "60"}, | 77 | {"offer_time" , read_u32 , OFS(offer_time ), "60"}, |
76 | {"min_lease" , read_u32 , &server_config.min_lease_sec, "60"}, | 78 | {"min_lease" , read_u32 , OFS(min_lease_sec), "60"}, |
77 | {"lease_file" , read_str , &server_config.lease_file , LEASES_FILE}, | 79 | {"lease_file" , read_str , OFS(lease_file ), LEASES_FILE}, |
78 | {"pidfile" , read_str , &server_config.pidfile , "/var/run/udhcpd.pid"}, | 80 | {"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"}, |
79 | {"siaddr" , udhcp_str2nip , &server_config.siaddr_nip , "0.0.0.0"}, | 81 | {"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"}, |
80 | /* keywords with no defaults must be last! */ | 82 | /* keywords with no defaults must be last! */ |
81 | {"option" , udhcp_str2optset, &server_config.options , ""}, | 83 | {"option" , udhcp_str2optset, OFS(options ), ""}, |
82 | {"opt" , udhcp_str2optset, &server_config.options , ""}, | 84 | {"opt" , udhcp_str2optset, OFS(options ), ""}, |
83 | {"notify_file" , read_str , &server_config.notify_file , NULL}, | 85 | {"notify_file" , read_str , OFS(notify_file ), NULL}, |
84 | {"sname" , read_str , &server_config.sname , NULL}, | 86 | {"sname" , read_str , OFS(sname ), NULL}, |
85 | {"boot_file" , read_str , &server_config.boot_file , NULL}, | 87 | {"boot_file" , read_str , OFS(boot_file ), NULL}, |
86 | {"static_lease" , read_staticlease, &server_config.static_leases, ""}, | 88 | {"static_lease" , read_staticlease, OFS(static_leases), ""}, |
87 | }; | 89 | }; |
88 | enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 }; | 90 | enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 }; |
89 | 91 | ||
@@ -95,17 +97,17 @@ void FAST_FUNC read_config(const char *file) | |||
95 | char *token[2]; | 97 | char *token[2]; |
96 | 98 | ||
97 | for (i = 0; i < KWS_WITH_DEFAULTS; i++) | 99 | for (i = 0; i < KWS_WITH_DEFAULTS; i++) |
98 | keywords[i].handler(keywords[i].def, keywords[i].var); | 100 | keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs); |
99 | 101 | ||
100 | parser = config_open(file); | 102 | parser = config_open(file); |
101 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { | 103 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { |
102 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { | 104 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { |
103 | if (strcasecmp(token[0], k->keyword) == 0) { | 105 | if (strcasecmp(token[0], k->keyword) == 0) { |
104 | if (!k->handler(token[1], k->var)) { | 106 | if (!k->handler(token[1], (char*)&server_config + k->ofs)) { |
105 | bb_error_msg("can't parse line %u in %s", | 107 | bb_error_msg("can't parse line %u in %s", |
106 | parser->lineno, file); | 108 | parser->lineno, file); |
107 | /* reset back to the default value */ | 109 | /* reset back to the default value */ |
108 | k->handler(k->def, k->var); | 110 | k->handler(k->def, (char*)&server_config + k->ofs); |
109 | } | 111 | } |
110 | break; | 112 | break; |
111 | } | 113 | } |