Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/udhcp/files.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/udhcp/files.c
r3232 r3621 58 58 const char *keyword; 59 59 int (*handler)(const char *line, void *var) FAST_FUNC; 60 void *var;60 unsigned ofs; 61 61 const char *def; 62 62 }; 63 63 64 #define OFS(field) offsetof(struct server_config_t, field) 65 64 66 static const struct config_keyword keywords[] = { 65 67 /* keyword handler variable address default */ 66 {"start" , udhcp_str2nip , &server_config.start_ip, "192.168.0.20"},67 {"end" , udhcp_str2nip , &server_config.end_ip, "192.168.0.254"},68 {"interface" , read_str , &server_config.interface, "eth0"},68 {"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"}, 69 {"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"}, 70 {"interface" , read_str , OFS(interface ), "eth0"}, 69 71 /* Avoid "max_leases value not sane" warning by setting default 70 72 * to default_end_ip - default_start_ip + 1: */ 71 {"max_leases" , read_u32 , &server_config.max_leases, "235"},72 {"auto_time" , read_u32 , &server_config.auto_time, "7200"},73 {"decline_time" , read_u32 , &server_config.decline_time, "3600"},74 {"conflict_time", read_u32 , &server_config.conflict_time, "3600"},75 {"offer_time" , read_u32 , &server_config.offer_time, "60"},76 {"min_lease" , read_u32 , &server_config.min_lease_sec, "60"},77 {"lease_file" , read_str , &server_config.lease_file, LEASES_FILE},78 {"pidfile" , read_str , &server_config.pidfile, "/var/run/udhcpd.pid"},79 {"siaddr" , udhcp_str2nip , &server_config.siaddr_nip, "0.0.0.0"},73 {"max_leases" , read_u32 , OFS(max_leases ), "235"}, 74 {"auto_time" , read_u32 , OFS(auto_time ), "7200"}, 75 {"decline_time" , read_u32 , OFS(decline_time ), "3600"}, 76 {"conflict_time", read_u32 , OFS(conflict_time), "3600"}, 77 {"offer_time" , read_u32 , OFS(offer_time ), "60"}, 78 {"min_lease" , read_u32 , OFS(min_lease_sec), "60"}, 79 {"lease_file" , read_str , OFS(lease_file ), LEASES_FILE}, 80 {"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"}, 81 {"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"}, 80 82 /* keywords with no defaults must be last! */ 81 {"option" , udhcp_str2optset, &server_config.options, ""},82 {"opt" , udhcp_str2optset, &server_config.options, ""},83 {"notify_file" , read_str , &server_config.notify_file, NULL},84 {"sname" , read_str , &server_config.sname, NULL},85 {"boot_file" , read_str , &server_config.boot_file, NULL},86 {"static_lease" , read_staticlease, &server_config.static_leases, ""},83 {"option" , udhcp_str2optset, OFS(options ), ""}, 84 {"opt" , udhcp_str2optset, OFS(options ), ""}, 85 {"notify_file" , read_str , OFS(notify_file ), NULL}, 86 {"sname" , read_str , OFS(sname ), NULL}, 87 {"boot_file" , read_str , OFS(boot_file ), NULL}, 88 {"static_lease" , read_staticlease, OFS(static_leases), ""}, 87 89 }; 88 90 enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 }; … … 96 98 97 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 102 parser = config_open(file); … … 102 104 for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { 103 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 107 bb_error_msg("can't parse line %u in %s", 106 108 parser->lineno, file); 107 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 112 break; … … 190 192 191 193 while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { 192 //FIXME: what if it matches some static lease?193 194 uint32_t y = ntohl(lease.lease_nip); 194 195 if (y >= server_config.start_ip && y <= server_config.end_ip) { 195 196 signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed; 197 uint32_t static_nip; 198 196 199 if (expires <= 0) 200 /* We keep expired leases: add_lease() will add 201 * a lease with 0 seconds remaining. 202 * Fewer IP address changes this way for mass reboot scenario. 203 */ 204 expires = 0; 205 206 /* Check if there is a different static lease for this IP or MAC */ 207 static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac); 208 if (static_nip) { 209 /* NB: we do not add lease even if static_nip == lease.lease_nip. 210 */ 197 211 continue; 212 } 213 if (is_nip_reserved(server_config.static_leases, lease.lease_nip)) 214 continue; 215 198 216 /* NB: add_lease takes "relative time", IOW, 199 217 * lease duration, not lease deadline. */ … … 211 229 } 212 230 } 213 log1(" Read %d leases", i);231 log1("read %d leases", i); 214 232 ret: 215 233 close(fd);
Note:
See TracChangeset
for help on using the changeset viewer.