Lines Matching refs:ip

103 int              check_arp( struct interface_info *ip, struct client_lease *lp );
137 int check_arp( struct interface_info *ip, struct client_lease *lp ) { in check_arp() argument
174 struct interface_info *ip = ipp; in state_reboot() local
178 if (!ip->client->active || ip->client->active->is_bootp) { in state_reboot()
179 state_init(ip); in state_reboot()
184 ip->client->state = S_REBOOTING; in state_reboot()
189 ip->client->xid = RtlRandom(&foo); in state_reboot()
193 make_request(ip, ip->client->active); in state_reboot()
194 ip->client->destination = iaddr_broadcast; in state_reboot()
195 time(&ip->client->first_sending); in state_reboot()
196 ip->client->interval = ip->client->config->initial_interval; in state_reboot()
199 ip->client->medium = NULL; in state_reboot()
202 send_request(ip); in state_reboot()
212 struct interface_info *ip = ipp; in state_init() local
218 make_discover(ip, ip->client->active); in state_init()
219 ip->client->xid = ip->client->packet.xid; in state_init()
220 ip->client->destination = iaddr_broadcast; in state_init()
221 ip->client->state = S_SELECTING; in state_init()
222 time(&ip->client->first_sending); in state_init()
223 ip->client->interval = ip->client->config->initial_interval; in state_init()
227 send_discover(ip); in state_init()
237 struct interface_info *ip = ipp; in state_selecting() local
247 cancel_timeout(state_selecting, ip); in state_selecting()
248 cancel_timeout(send_discover, ip); in state_selecting()
254 for (lp = ip->client->offered_leases; lp; lp = next) { in state_selecting()
260 if( !check_arp(ip,lp) ) goto freeit; in state_selecting()
268 ip->client->offered_leases = NULL; in state_selecting()
273 ip->client->state = S_INIT; in state_selecting()
274 state_init(ip); in state_selecting()
280 ip->client->new = picked; in state_selecting()
284 ip->client->new->expiry = cur_time + 12000; in state_selecting()
285 ip->client->new->renewal += cur_time + 8000; in state_selecting()
286 ip->client->new->rebind += cur_time + 10000; in state_selecting()
288 ip->client->state = S_REQUESTING; in state_selecting()
291 bind_lease(ip); in state_selecting()
296 ip->client->destination = iaddr_broadcast; in state_selecting()
297 ip->client->state = S_REQUESTING; in state_selecting()
298 ip->client->first_sending = cur_time; in state_selecting()
299 ip->client->interval = ip->client->config->initial_interval; in state_selecting()
302 make_request(ip, picked); in state_selecting()
303 ip->client->xid = ip->client->packet.xid; in state_selecting()
309 send_request(ip); in state_selecting()
318 struct interface_info *ip = packet->interface; in dhcpack() local
332 if (ip->client->state != S_REBOOTING && in dhcpack()
333 ip->client->state != S_REQUESTING && in dhcpack()
334 ip->client->state != S_RENEWING && in dhcpack()
335 ip->client->state != S_REBINDING) in dhcpack()
346 ip->client->new = lease; in dhcpack()
349 cancel_timeout(send_request, ip); in dhcpack()
352 if (ip->client->new->options[DHO_DHCP_LEASE_TIME].data) in dhcpack()
353 ip->client->new->expiry = getULong( in dhcpack()
354 ip->client->new->options[DHO_DHCP_LEASE_TIME].data); in dhcpack()
356 ip->client->new->expiry = DHCP_DEFAULT_LEASE_TIME; in dhcpack()
359 if (ip->client->new->expiry < 0) in dhcpack()
360 ip->client->new->expiry = TIME_MAX; in dhcpack()
362 if (ip->client->new->expiry < 60) in dhcpack()
363 ip->client->new->expiry = 60; in dhcpack()
367 if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len) in dhcpack()
368 ip->client->new->renewal = getULong( in dhcpack()
369 ip->client->new->options[DHO_DHCP_RENEWAL_TIME].data); in dhcpack()
371 ip->client->new->renewal = ip->client->new->expiry / 2; in dhcpack()
374 if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len) in dhcpack()
375 ip->client->new->rebind = getULong( in dhcpack()
376 ip->client->new->options[DHO_DHCP_REBINDING_TIME].data); in dhcpack()
378 ip->client->new->rebind = ip->client->new->renewal + in dhcpack()
379 ip->client->new->renewal / 2 + ip->client->new->renewal / 4; in dhcpack()
382 ip->client->new->obtained = cur_time; in dhcpack()
384 ip->client->new->expiry += cur_time; in dhcpack()
386 if (ip->client->new->expiry < cur_time) in dhcpack()
387 ip->client->new->expiry = TIME_MAX; in dhcpack()
388 ip->client->new->renewal += cur_time; in dhcpack()
389 if (ip->client->new->renewal < cur_time) in dhcpack()
390 ip->client->new->renewal = TIME_MAX; in dhcpack()
391 ip->client->new->rebind += cur_time; in dhcpack()
392 if (ip->client->new->rebind < cur_time) in dhcpack()
393 ip->client->new->rebind = TIME_MAX; in dhcpack()
395 bind_lease(ip); in dhcpack()
580 bind_lease(struct interface_info *ip) in bind_lease() argument
583 struct client_lease *new_lease = ip->client->new; in bind_lease()
589 ip->client->new->medium = ip->client->medium; in bind_lease()
592 if (ip->client->active) in bind_lease()
593 free_client_lease(ip->client->active); in bind_lease()
594 ip->client->active = ip->client->new; in bind_lease()
595 ip->client->new = NULL; in bind_lease()
601 if( ip->client->active->renewal - cur_time ) in bind_lease()
602 add_timeout(ip->client->active->renewal, state_bound, ip); in bind_lease()
605 piaddr(ip->client->active->address), in bind_lease()
606 (long int)(ip->client->active->renewal - cur_time)); in bind_lease()
608 ip->client->state = S_BOUND; in bind_lease()
610 Adapter = AdapterFindInfo( ip ); in bind_lease()
614 warning("Could not find adapter for info %p\n", ip); in bind_lease()
630 struct interface_info *ip = ipp; in state_bound() local
635 make_request(ip, ip->client->active); in state_bound()
636 ip->client->xid = ip->client->packet.xid; in state_bound()
638 if (ip->client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) { in state_bound()
639 memcpy(ip->client->destination.iabuf, ip->client->active-> in state_bound()
641 ip->client->destination.len = 4; in state_bound()
643 ip->client->destination = iaddr_broadcast; in state_bound()
645 time(&ip->client->first_sending); in state_bound()
646 ip->client->interval = ip->client->config->initial_interval; in state_bound()
647 ip->client->state = S_RENEWING; in state_bound()
650 send_request(ip); in state_bound()
712 struct interface_info *ip = packet->interface; in dhcpoffer() local
724 if (ip->client->state != S_SELECTING || in dhcpoffer()
736 for (i = 0; ip->client->config->required_options[i]; i++) { in dhcpoffer()
737 if (!packet->options[ip->client->config-> in dhcpoffer()
745 for (lease = ip->client->offered_leases; in dhcpoffer()
767 lease->medium = ip->client->medium; in dhcpoffer()
770 if( !check_arp( ip, lease ) ) { in dhcpoffer()
777 ip->client->first_sending + ip->client->config->select_interval; in dhcpoffer()
781 if (lease->address.len == ip->client->requested_address.len && in dhcpoffer()
783 ip->client->requested_address.iabuf, in dhcpoffer()
784 ip->client->requested_address.len)) { in dhcpoffer()
785 lease->next = ip->client->offered_leases; in dhcpoffer()
786 ip->client->offered_leases = lease; in dhcpoffer()
792 if (ip->client->offered_leases && in dhcpoffer()
798 if (!ip->client->offered_leases) in dhcpoffer()
799 ip->client->offered_leases = lease; in dhcpoffer()
801 for (lp = ip->client->offered_leases; lp->next; in dhcpoffer()
818 state_selecting(ip); in dhcpoffer()
820 add_timeout(stop_selecting, state_selecting, ip); in dhcpoffer()
821 cancel_timeout(send_discover, ip); in dhcpoffer()
917 struct interface_info *ip = packet->interface; in dhcpnak() local
927 if (ip->client->state != S_REBOOTING && in dhcpnak()
928 ip->client->state != S_REQUESTING && in dhcpnak()
929 ip->client->state != S_RENEWING && in dhcpnak()
930 ip->client->state != S_REBINDING) in dhcpnak()
935 if (!ip->client->active) { in dhcpnak()
940 free_client_lease(ip->client->active); in dhcpnak()
941 ip->client->active = NULL; in dhcpnak()
944 cancel_timeout(send_request, ip); in dhcpnak()
946 ip->client->state = S_INIT; in dhcpnak()
947 state_init(ip); in dhcpnak()
957 struct interface_info *ip = ipp; in send_discover() local
961 DH_DbgPrint(MID_TRACE,("Doing discover on interface %p\n",ip)); in send_discover()
966 interval = cur_time - ip->client->first_sending; in send_discover()
970 if (interval > ip->client->config->timeout) { in send_discover()
971 state_panic(ip); in send_discover()
972 ip->client->first_sending = cur_time; in send_discover()
978 if (!ip->client->offered_leases && in send_discover()
979 ip->client->config->media) { in send_discover()
982 if (ip->client->medium) { in send_discover()
983 ip->client->medium = ip->client->medium->next; in send_discover()
986 if (!ip->client->medium) { in send_discover()
988 error("No valid media types for %s!", ip->name); in send_discover()
989 ip->client->medium = ip->client->config->media; in send_discover()
993 note("Trying medium \"%s\" %d", ip->client->medium->string, in send_discover()
1006 if (!ip->client->interval) in send_discover()
1007 ip->client->interval = in send_discover()
1008 ip->client->config->initial_interval; in send_discover()
1010 ip->client->interval += (rand() >> 2) % in send_discover()
1011 (2 * ip->client->interval); in send_discover()
1015 if (ip->client->interval > in send_discover()
1016 ip->client->config->backoff_cutoff) in send_discover()
1017 ip->client->interval = in send_discover()
1018 ((ip->client->config->backoff_cutoff / 2) in send_discover()
1020 ip->client->config->backoff_cutoff)); in send_discover()
1021 } else if (!ip->client->interval) in send_discover()
1022 ip->client->interval = in send_discover()
1023 ip->client->config->initial_interval; in send_discover()
1027 if (cur_time + ip->client->interval > in send_discover()
1028 ip->client->first_sending + ip->client->config->timeout) in send_discover()
1029 ip->client->interval = in send_discover()
1030 (ip->client->first_sending + in send_discover()
1031 ip->client->config->timeout) - cur_time + 1; in send_discover()
1035 ip->client->packet.secs = htons(interval); in send_discover()
1037 ip->client->packet.secs = htons(65535); in send_discover()
1038 ip->client->secs = ip->client->packet.secs; in send_discover()
1041 ip->name, inet_ntoa(sockaddr_broadcast.sin_addr), in send_discover()
1042 ntohs(sockaddr_broadcast.sin_port), (long int)ip->client->interval); in send_discover()
1045 (void)send_packet(ip, &ip->client->packet, ip->client->packet_length, in send_discover()
1049 cur_time, cur_time + ip->client->interval)); in send_discover()
1051 add_timeout(cur_time + ip->client->interval, send_discover, ip); in send_discover()
1063 struct interface_info *ip = ipp; in state_panic() local
1070 PDHCP_ADAPTER Adapter = AdapterFindInfo(ip); in state_panic()
1085 for (i = 0; i < ip->hw_address.hlen; i++) in state_panic()
1086 address_low += ip->hw_address.haddr[i]; in state_panic()
1115 struct interface_info *ip = ipp; in send_request() local
1124 interval = cur_time - ip->client->first_sending; in send_request()
1136 if ((ip->client->state == S_REBOOTING || in send_request()
1137 ip->client->state == S_REQUESTING) && in send_request()
1138 interval > ip->client->config->reboot_timeout) { in send_request()
1139 ip->client->state = S_INIT; in send_request()
1140 cancel_timeout(send_request, ip); in send_request()
1141 state_init(ip); in send_request()
1147 if (ip->client->state == S_REBOOTING && in send_request()
1148 !ip->client->medium && in send_request()
1149 ip->client->active->medium ) { in send_request()
1154 ip->client->medium = ip->client->active->medium; in send_request()
1159 if (ip->client->state != S_REQUESTING && in send_request()
1160 cur_time > ip->client->active->expiry) { in send_request()
1161 PDHCP_ADAPTER Adapter = AdapterFindInfo( ip ); in send_request()
1173 ip->client->state = S_INIT; in send_request()
1174 state_init(ip); in send_request()
1179 if (!ip->client->interval) in send_request()
1180 ip->client->interval = ip->client->config->initial_interval; in send_request()
1182 ip->client->interval += ((rand() >> 2) % in send_request()
1183 (2 * ip->client->interval)); in send_request()
1186 if (ip->client->interval > in send_request()
1187 ip->client->config->backoff_cutoff) in send_request()
1188 ip->client->interval = in send_request()
1189 ((ip->client->config->backoff_cutoff / 2) + in send_request()
1190 ((rand() >> 2) % ip->client->interval)); in send_request()
1194 if (ip->client->state != S_REQUESTING && in send_request()
1195 cur_time + ip->client->interval > in send_request()
1196 ip->client->active->expiry) in send_request()
1197 ip->client->interval = in send_request()
1198 ip->client->active->expiry - cur_time + 1; in send_request()
1203 if (ip->client->state == S_REQUESTING || in send_request()
1204 ip->client->state == S_REBOOTING || in send_request()
1205 cur_time > ip->client->active->rebind) in send_request()
1209 ip->client->destination.iabuf, in send_request()
1215 if (ip->client->state != S_REQUESTING) in send_request()
1216 memcpy(&from, ip->client->active->address.iabuf, in send_request()
1222 if (ip->client->state == S_REQUESTING) in send_request()
1223 ip->client->packet.secs = ip->client->secs; in send_request()
1226 ip->client->packet.secs = htons(interval); in send_request()
1228 ip->client->packet.secs = htons(65535); in send_request()
1231 note("DHCPREQUEST on %s to %s port %d", ip->name, in send_request()
1235 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length, in send_request()
1238 add_timeout(cur_time + ip->client->interval, send_request, ip); in send_request()
1244 struct interface_info *ip = ipp; in send_decline() local
1246 note("DHCPDECLINE on %s to %s port %d", ip->name, in send_decline()
1251 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length, in send_decline()
1256 make_discover(struct interface_info *ip, struct client_lease *lease) in make_discover() argument
1266 memset(&ip->client->packet, 0, sizeof(ip->client->packet)); in make_discover()
1279 options[i]->value = ip->client->config->requested_options; in make_discover()
1280 options[i]->len = ip->client->config->requested_option_count; in make_discover()
1282 ip->client->config->requested_option_count; in make_discover()
1287 ip->client->requested_address = lease->address; in make_discover()
1295 ip->client->requested_address.len = 0; in make_discover()
1300 ip->client->config->send_options[i].data) { in make_discover()
1303 ip->client->config->send_options[i].data; in make_discover()
1305 ip->client->config->send_options[i].len; in make_discover()
1307 ip->client->config->send_options[i].len; in make_discover()
1312 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, in make_discover()
1314 if (ip->client->packet_length < BOOTP_MIN_LEN) in make_discover()
1315 ip->client->packet_length = BOOTP_MIN_LEN; in make_discover()
1317 ip->client->packet.op = BOOTREQUEST; in make_discover()
1318 ip->client->packet.htype = ip->hw_address.htype; in make_discover()
1319 ip->client->packet.hlen = ip->hw_address.hlen; in make_discover()
1320 ip->client->packet.hops = 0; in make_discover()
1321 ip->client->packet.xid = RtlRandom(&foo); in make_discover()
1322 ip->client->packet.secs = 0; /* filled in by send_discover. */ in make_discover()
1323 ip->client->packet.flags = 0; in make_discover()
1325 memset(&(ip->client->packet.ciaddr), in make_discover()
1326 0, sizeof(ip->client->packet.ciaddr)); in make_discover()
1327 memset(&(ip->client->packet.yiaddr), in make_discover()
1328 0, sizeof(ip->client->packet.yiaddr)); in make_discover()
1329 memset(&(ip->client->packet.siaddr), in make_discover()
1330 0, sizeof(ip->client->packet.siaddr)); in make_discover()
1331 memset(&(ip->client->packet.giaddr), in make_discover()
1332 0, sizeof(ip->client->packet.giaddr)); in make_discover()
1333 memcpy(ip->client->packet.chaddr, in make_discover()
1334 ip->hw_address.haddr, ip->hw_address.hlen); in make_discover()
1339 make_request(struct interface_info *ip, struct client_lease * lease) in make_request() argument
1347 memset(&ip->client->packet, 0, sizeof(ip->client->packet)); in make_request()
1360 options[i]->value = ip->client->config->requested_options; in make_request()
1361 options[i]->len = ip->client->config->requested_option_count; in make_request()
1363 ip->client->config->requested_option_count; in make_request()
1368 if (ip->client->state == S_REQUESTING) { in make_request()
1377 if (ip->client->state == S_REQUESTING || in make_request()
1378 ip->client->state == S_REBOOTING) { in make_request()
1379 ip->client->requested_address = lease->address; in make_request()
1387 ip->client->requested_address.len = 0; in make_request()
1392 ip->client->config->send_options[i].data) { in make_request()
1395 ip->client->config->send_options[i].data; in make_request()
1397 ip->client->config->send_options[i].len; in make_request()
1399 ip->client->config->send_options[i].len; in make_request()
1404 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, in make_request()
1406 if (ip->client->packet_length < BOOTP_MIN_LEN) in make_request()
1407 ip->client->packet_length = BOOTP_MIN_LEN; in make_request()
1409 ip->client->packet.op = BOOTREQUEST; in make_request()
1410 ip->client->packet.htype = ip->hw_address.htype; in make_request()
1411 ip->client->packet.hlen = ip->hw_address.hlen; in make_request()
1412 ip->client->packet.hops = 0; in make_request()
1413 ip->client->packet.xid = ip->client->xid; in make_request()
1414 ip->client->packet.secs = 0; /* Filled in by send_request. */ in make_request()
1418 if (ip->client->state == S_BOUND || in make_request()
1419 ip->client->state == S_RENEWING || in make_request()
1420 ip->client->state == S_REBINDING) { in make_request()
1421 memcpy(&ip->client->packet.ciaddr, in make_request()
1423 ip->client->packet.flags = 0; in make_request()
1425 memset(&ip->client->packet.ciaddr, 0, in make_request()
1426 sizeof(ip->client->packet.ciaddr)); in make_request()
1427 ip->client->packet.flags = 0; in make_request()
1430 memset(&ip->client->packet.yiaddr, 0, in make_request()
1431 sizeof(ip->client->packet.yiaddr)); in make_request()
1432 memset(&ip->client->packet.siaddr, 0, in make_request()
1433 sizeof(ip->client->packet.siaddr)); in make_request()
1434 memset(&ip->client->packet.giaddr, 0, in make_request()
1435 sizeof(ip->client->packet.giaddr)); in make_request()
1436 memcpy(ip->client->packet.chaddr, in make_request()
1437 ip->hw_address.haddr, ip->hw_address.hlen); in make_request()
1441 make_decline(struct interface_info *ip, struct client_lease *lease) in make_decline() argument
1450 memset(&ip->client->packet, 0, sizeof(ip->client->packet)); in make_decline()
1478 if (ip->client->config->send_options[i].len) { in make_decline()
1480 options[i]->value = ip->client->config->send_options[i].data; in make_decline()
1481 options[i]->len = ip->client->config->send_options[i].len; in make_decline()
1482 options[i]->buf_size = ip->client->config->send_options[i].len; in make_decline()
1488 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, in make_decline()
1490 if (ip->client->packet_length < BOOTP_MIN_LEN) in make_decline()
1491 ip->client->packet_length = BOOTP_MIN_LEN; in make_decline()
1493 ip->client->packet.op = BOOTREQUEST; in make_decline()
1494 ip->client->packet.htype = ip->hw_address.htype; in make_decline()
1495 ip->client->packet.hlen = ip->hw_address.hlen; in make_decline()
1496 ip->client->packet.hops = 0; in make_decline()
1497 ip->client->packet.xid = ip->client->xid; in make_decline()
1498 ip->client->packet.secs = 0; /* Filled in by send_request. */ in make_decline()
1499 ip->client->packet.flags = 0; in make_decline()
1502 memset(&ip->client->packet.ciaddr, 0, in make_decline()
1503 sizeof(ip->client->packet.ciaddr)); in make_decline()
1504 memset(&ip->client->packet.yiaddr, 0, in make_decline()
1505 sizeof(ip->client->packet.yiaddr)); in make_decline()
1506 memset(&ip->client->packet.siaddr, 0, in make_decline()
1507 sizeof(ip->client->packet.siaddr)); in make_decline()
1508 memset(&ip->client->packet.giaddr, 0, in make_decline()
1509 sizeof(ip->client->packet.giaddr)); in make_decline()
1510 memcpy(ip->client->packet.chaddr, in make_decline()
1511 ip->hw_address.haddr, ip->hw_address.hlen); in make_decline()
1555 write_client_lease(struct interface_info *ip, struct client_lease *lease, in write_client_lease() argument
1564 rewrite_client_leases(ip); in write_client_lease()
1585 fprintf(leaseFile, " interface \"%s\";\n", ip->name); in write_client_lease()
1621 priv_script_init(struct interface_info *ip, char *reason, char *medium) in priv_script_init() argument
1623 if (ip) { in priv_script_init()
1629 priv_script_write_params(struct interface_info *ip, char *prefix, struct client_lease *lease) in priv_script_write_params() argument
1635 script_set_env(ip->client, prefix, "ip_address", in priv_script_write_params()
1651 script_set_env(ip->client, prefix, "network_number", in priv_script_write_params()
1658 script_set_env(ip->client, prefix, in priv_script_write_params()
1670 script_set_env(ip->client, prefix, "filename", lease->filename); in priv_script_write_params()
1672 script_set_env(ip->client, prefix, "server_name", in priv_script_write_params()
1679 if (ip->client->config->defaults[i].len) { in priv_script_write_params()
1682 ip->client->config->default_actions[i]) { in priv_script_write_params()
1689 dp = ip->client-> in priv_script_write_params()
1691 len = ip->client-> in priv_script_write_params()
1695 len = ip->client-> in priv_script_write_params()
1706 ip->client-> in priv_script_write_params()
1708 ip->client-> in priv_script_write_params()
1710 memcpy(dp + ip->client-> in priv_script_write_params()
1717 len = ip->client-> in priv_script_write_params()
1731 ip->client-> in priv_script_write_params()
1733 ip->client-> in priv_script_write_params()
1738 dp = ip->client-> in priv_script_write_params()
1740 len = ip->client-> in priv_script_write_params()
1755 script_set_env(ip->client, prefix, name, in priv_script_write_params()
1762 script_set_env(ip->client, prefix, "expiry", tbuf); in priv_script_write_params()