Home | History | Annotate | Download | only in client

Lines Matching refs:client

5    DHCP Client. */
29 * This code is based on the original client state machine that was
89 static const char message [] = "Internet Systems Consortium DHCP Client";
251 static int send_dhcpv4_query(struct client_state *client, int broadcast);
324 struct client_state *client;
353 /* Initialize client globals. */
431 log_fatal("Client can only do v4 or v6, not "
437 log_fatal("Client can only do v4 or v6, not "
668 "without a persistent DHCPv6 client");
691 /* Set up the initial client option universe. */
717 * See if we should kill off any currently running client
735 log_info("Killed old client process");
874 script_init(ip->client, "PREINIT6", NULL);
876 script_init(ip->client, "PREINIT", NULL);
877 if (ip->client->alias != NULL)
878 script_write_params(ip->client,
880 ip->client->alias);
882 script_go(ip->client);
949 for (client = ip->client ; client != NULL ;
950 client = client->next) {
952 start_release6(client);
955 unconfigure6(client, "STOP6");
962 if ((client->active_lease != NULL) &&
963 !client->active_lease->released)
964 start_confirm6(client);
966 start_init6(client);
974 for (client = ip->client ; client ;
975 client = client->next) {
977 state_stop(client);
979 do_release(client);
981 client->state = S_INIT;
1000 client, 0, 0);
1002 state_reboot(client);
1077 * \brief Run the DHCPv6 stateless client (dhclient -6 -S)
1080 * \param port DHCPv4-over-DHCPv6 client inter-process communication
1087 struct client_state *client;
1132 for (client = interfaces->client ;
1133 client != NULL ;
1134 client = client->next) {
1136 unconfigure6(client, "STOP6");
1139 start_info_request6(client);
1254 struct client_state *client = cpp;
1260 client->pending = P_REBOOT;
1265 client->pending= P_NONE;
1268 if (!client -> active ||
1269 client -> active -> is_bootp ||
1270 client -> active -> expiry <= cur_time) {
1271 state_init (client);
1276 client -> state = S_REBOOTING;
1283 client -> xid = random ();
1289 make_request (client, client -> active);
1290 client -> destination = iaddr_broadcast;
1291 client -> first_sending = cur_time;
1292 client -> interval = client -> config -> initial_interval;
1295 client -> medium = NULL;
1298 send_request (client);
1307 struct client_state *client = cpp;
1313 make_discover (client, client -> active);
1314 client -> xid = client -> packet.xid;
1315 client -> destination = iaddr_broadcast;
1316 client -> state = S_SELECTING;
1317 client -> first_sending = cur_time;
1318 client -> interval = client -> config -> initial_interval;
1322 send_discover (client);
1329 uint32_t check_v6only(packet, client)
1331 struct client_state *client;
1341 req = client->config->requested_options;
1365 if (evaluate_option_cache(&data, packet, (struct lease *)0, client,
1384 struct client_state *client = cpp;
1386 cancel_timeout(finish_v6only, client);
1387 client->state = S_INIT;
1395 void start_v6only(client, v6only_wait)
1396 struct client_state *client;
1403 client->state = S_V6ONLY;
1405 /* Run the client script. */
1406 script_init(client, "V6ONLY", NULL);
1407 if (client->active) {
1408 script_write_params(client, "old_", client->active);
1409 destroy_client_lease(client->active);
1410 client->active = NULL;
1412 script_write_requested(client);
1413 client_envadd(client, "", "v6-only-preferred", "%lu",
1415 script_go(client);
1421 add_timeout(&tv, finish_v6only, client, 0, 0);
1432 struct client_state *client = cpp;
1442 cancel_timeout (state_selecting, client);
1443 cancel_timeout (send_discover, client);
1451 for (lp = client -> offered_leases; lp; lp = next) {
1465 client -> offered_leases = NULL;
1472 client -> state = S_INIT;
1473 state_init (client);
1479 client -> new = picked;
1483 client -> new -> expiry = cur_time + 12000;
1484 client -> new -> renewal += cur_time + 8000;
1485 client -> new -> rebind += cur_time + 10000;
1487 client -> state = S_REQUESTING;
1490 bind_lease (client);
1495 client -> destination = iaddr_broadcast;
1496 client -> state = S_REQUESTING;
1497 client -> first_sending = cur_time;
1498 client -> interval = client -> config -> initial_interval;
1501 make_request (client, picked);
1502 client -> xid = client -> packet.xid;
1508 send_request (client);
1538 struct client_state *client;
1546 for (client = ip -> client; client; client = client -> next) {
1547 if (client -> xid == packet -> raw -> xid)
1550 if (!client || compare_hw_address("DHCPACK", packet) == ISC_TRUE)
1553 if (client -> state != S_REBOOTING &&
1554 client -> state != S_REQUESTING &&
1555 client -> state != S_RENEWING &&
1556 client -> state != S_REBINDING) {
1568 v6only_wait = check_v6only(packet, client);
1572 cancel_timeout(send_request, client);
1573 start_v6only(client, v6only_wait);
1577 lease = packet_to_lease (packet, client);
1583 client -> new = lease;
1586 cancel_timeout (send_request, client);
1589 oc = lookup_option (&dhcp_universe, client -> new -> options,
1593 evaluate_option_cache (&ds, packet, (struct lease *)0, client,
1594 packet -> options, client -> new -> options,
1597 client -> new -> expiry = getULong (ds.data);
1599 client -> new -> expiry = 0;
1602 client -> new -> expiry = 0;
1604 if (client->new->expiry == 0) {
1621 add_timeout(&tv, state_init, client, 0, 0);
1629 if (client->new->expiry < 0)
1630 client->new->expiry = TIME_MAX;
1633 oc = lookup_option (&dhcp_universe, client -> new -> options,
1636 evaluate_option_cache (&ds, packet, (struct lease *)0, client,
1637 packet -> options, client -> new -> options,
1640 client -> new -> renewal = getULong (ds.data);
1642 client -> new -> renewal = 0;
1645 client -> new -> renewal = 0;
1648 if (!client -> new -> renewal)
1649 client -> new -> renewal = client -> new -> expiry / 2 + 1;
1651 if (client -> new -> renewal <= 0)
1652 client -> new -> renewal = TIME_MAX;
1655 if (client->new->renewal <= ((TIME_MAX / 3) - 3))
1656 client->new->renewal = (((client->new->renewal * 3) + 3) / 4) +
1657 (((random() % client->new->renewal) + 3) / 4);
1660 oc = lookup_option (&dhcp_universe, client -> new -> options,
1663 evaluate_option_cache (&ds, packet, (struct lease *)0, client,
1664 packet -> options, client -> new -> options,
1667 client -> new -> rebind = getULong (ds.data);
1669 client -> new -> rebind = 0;
1672 client -> new -> rebind = 0;
1674 if (client -> new -> rebind <= 0) {
1675 if (client -> new -> expiry <= TIME_MAX / 7)
1676 client -> new -> rebind =
1677 client -> new -> expiry * 7 / 8;
1679 client -> new -> rebind =
1680 client -> new -> expiry / 8 * 7;
1685 if (client -> new -> renewal > client -> new -> rebind) {
1686 if (client -> new -> rebind <= TIME_MAX / 3)
1687 client -> new -> renewal =
1688 client -> new -> rebind * 3 / 4;
1690 client -> new -> renewal =
1691 client -> new -> rebind / 4 * 3;
1694 client -> new -> expiry += cur_time;
1696 if (client -> new -> expiry < cur_time)
1697 client -> new -> expiry = TIME_MAX;
1698 client -> new -> renewal += cur_time;
1699 if (client -> new -> renewal < cur_time)
1700 client -> new -> renewal = TIME_MAX;
1701 client -> new -> rebind += cur_time;
1702 if (client -> new -> rebind < cur_time)
1703 client -> new -> rebind = TIME_MAX;
1705 bind_lease (client);
1708 void bind_lease (client)
1709 struct client_state *client;
1714 client->new->medium = client->medium;
1716 /* Run the client script with the new parameters. */
1717 script_init(client, (client->state == S_REQUESTING ? "BOUND" :
1718 (client->state == S_RENEWING ? "RENEW" :
1719 (client->state == S_REBOOTING ? "REBOOT" :
1721 client->new->medium);
1722 if (client->active && client->state != S_REBOOTING)
1723 script_write_params(client, "old_", client->active);
1724 script_write_params(client, "new_", client->new);
1725 script_write_requested(client);
1726 if (client->alias)
1727 script_write_params(client, "alias_", client->alias);
1735 if (script_go(client) > 0) {
1736 make_decline(client, client->new);
1737 send_decline(client);
1738 destroy_client_lease(client->new);
1739 client->new = NULL;
1748 script_init(client, "FAIL", (struct string_list *)0);
1749 script_go(client);
1756 add_timeout(&tv, state_init, client, 0, 0);
1762 if (!client->last_write ||
1763 (cur_time - client->last_write) >= MIN_LEASE_WRITE)
1764 write_client_lease(client, client->new, 0, 1);
1767 if (client->active) {
1768 if (client->active->is_static) {
1771 add_to_tail(&client->leases, client->active);
1773 destroy_client_lease(client->active);
1777 client->active = client->new;
1778 client->new = NULL;
1781 tv.tv_sec = client->active->renewal;
1782 tv.tv_usec = ((client->active->renewal - cur_tv.tv_sec) > 1) ?
1784 add_timeout(&tv, state_bound, client, 0, 0);
1787 piaddr(client->active->address),
1788 (long)(client->active->renewal - cur_time));
1789 client->state = S_BOUND;
1793 if (client->config->do_forward_update)
1794 dhclient_schedule_updates(client, &client->active->address, 1);
1807 struct client_state *client = cpp;
1814 make_request (client, client -> active);
1815 client -> xid = client -> packet.xid;
1818 oc = lookup_option (&dhcp_universe, client -> active -> options,
1822 client, (struct option_state *)0,
1823 client -> active -> options,
1826 memcpy (client -> destination.iabuf, ds.data, 4);
1827 client -> destination.len = 4;
1829 client -> destination = iaddr_broadcast;
1833 client -> destination = iaddr_broadcast;
1835 client -> first_sending = cur_time;
1836 client -> interval = client -> config -> initial_interval;
1837 client -> state = S_RENEWING;
1840 send_request (client);
1849 struct client_state *client = cpp;
1851 client->pending = P_NONE;
1854 cancel_timeout(state_selecting, client);
1855 cancel_timeout(send_discover, client);
1856 cancel_timeout(send_request, client);
1857 cancel_timeout(state_bound, client);
1858 cancel_timeout(finish_v6only, client);
1861 if (client->active) {
1862 script_init(client, "STOP", client->active->medium);
1863 script_write_params(client, "old_", client->active);
1864 script_write_requested(client);
1865 if (client->alias)
1866 script_write_params(client, "alias_", client->alias);
1867 script_go(client);
1905 for (ap = packet -> interface -> client -> config -> reject_list;
1957 for (ap = packet -> interface -> client -> config -> reject_list;
1980 struct client_state *client;
1988 for (ap = packet->interface->client->config->reject_list ;
2028 /* Find a client state that matches the incoming XID. */
2029 for (client = packet->interface->client ; client ;
2030 client = client->next) {
2031 if (memcmp(&client->dhcpv6_transaction_id,
2033 client->v6_handler(packet, client);
2044 * \brief Forward a DHCPv4-response to the DHCPv4 client.
2045 * (DHCPv6 client function)
2047 * The DHCPv6 client receives a DHCPv4-response which is forwarded
2048 * to the DHCPv4 client.
2129 * \brief Receive a DHCPv4-response from the DHCPv6 client.
2130 * (DHCPv4 client function)
2132 * The DHCPv4 client receives a DHCPv4-response forwarded
2133 * by the DHCPv6 client (using \ref forw_dhcpv4_response())
2217 struct client_state *client;
2231 /* Find a client state that matches the xid... */
2232 for (client = ip -> client; client; client = client -> next)
2233 if (client -> xid == packet -> raw -> xid)
2238 if (!client || client -> state != S_SELECTING ||
2247 v6only_wait = check_v6only(packet, client);
2251 cancel_timeout(send_discover, client);
2252 start_v6only(client, v6only_wait);
2259 req = client->config->required_options;
2287 for (lease = client -> offered_leases; lease; lease = lease -> next) {
2296 lease = packet_to_lease (packet, client);
2311 lease -> medium = client -> medium;
2314 stop_selecting = (client -> first_sending +
2315 client -> config -> select_interval);
2319 if (lease -> address.len == client -> requested_address.len &&
2321 client -> requested_address.iabuf,
2322 client -> requested_address.len)) {
2323 lease -> next = client -> offered_leases;
2324 client -> offered_leases = lease;
2328 if (!client -> offered_leases)
2329 client -> offered_leases = lease;
2331 for (lp = client -> offered_leases; lp -> next;
2342 state_selecting (client);
2346 add_timeout(&tv, state_selecting, client, 0, 0);
2347 cancel_timeout(send_discover, client);
2354 struct client_lease *packet_to_lease (packet, client)
2356 struct client_state *client;
2386 if (client -> config -> vendor_space_name) {
2392 client -> config -> vendor_space_name &&
2394 (struct lease *)0, client,
2406 client -> config -> vendor_space_name
2420 evaluate_option_cache (&data, packet, (struct lease *)0, client,
2470 client, lease->options, lease->options,
2471 &global_scope, client->config->on_receipt,
2481 struct client_state *client;
2483 /* Find a client state that matches the xid... */
2484 for (client = ip -> client; client; client = client -> next)
2485 if (client -> xid == packet -> raw -> xid)
2490 if (!client || compare_hw_address("DHCPNAK", packet) == ISC_TRUE)
2493 if (client -> state != S_REBOOTING &&
2494 client -> state != S_REQUESTING &&
2495 client -> state != S_RENEWING &&
2496 client -> state != S_REBINDING) {
2505 if (!client -> active) {
2517 script_init(client, "EXPIRE", NULL);
2518 script_write_params(client, "old_", client->active);
2519 script_write_requested(client);
2520 if (client->alias)
2521 script_write_params(client, "alias_", client->alias);
2522 script_go(client);
2524 destroy_client_lease (client -> active);
2525 client -> active = (struct client_lease *)0;
2528 cancel_timeout (send_request, client);
2535 script_init(client, "PREINIT", NULL);
2536 if (client->alias)
2537 script_write_params(client, "alias_", client->alias);
2538 script_go(client);
2540 client -> state = S_INIT;
2541 state_init (client);
2551 struct client_state *client = cpp;
2559 interval = cur_time - client -> first_sending;
2563 if (interval > client -> config -> timeout) {
2564 state_panic (client);
2571 if (!client -> offered_leases &&
2572 client -> config -> media) {
2575 if (client -> medium) {
2576 client -> medium = client -> medium -> next;
2579 if (!client -> medium) {
2582 client -> interface -> name);
2583 client -> medium =
2584 client -> config -> media;
2589 client -> medium -> string, increase);
2590 script_init(client, "MEDIUM", client -> medium);
2591 if (script_go(client)) {
2603 if (!client->interval)
2604 client->interval = client->config->initial_interval;
2606 client->interval += random() % (2 * client->interval);
2609 if (client->interval > client->config->backoff_cutoff)
2610 client->interval = (client->config->backoff_cutoff / 2)
2611 + (random() % client->config->backoff_cutoff);
2612 } else if (!client->interval)
2613 client->interval = client->config->initial_interval;
2617 if (cur_time + client -> interval >
2618 client -> first_sending + client -> config -> timeout)
2619 client -> interval =
2620 (client -> first_sending +
2621 client -> config -> timeout) - cur_time + 1;
2625 client -> packet.secs = htons (interval);
2627 client -> packet.secs = htons (65535);
2628 client -> secs = client -> packet.secs;
2633 (long)(client -> interval));
2637 client -> name ? client -> name : client -> interface -> name,
2639 ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval));
2644 result = send_dhcpv4_query(client, 1);
2647 result = send_packet(client->interface, NULL, &client->packet,
2648 client->packet_length, inaddr_any,
2654 MDL, client->packet_length);
2658 "interface.", MDL, client->packet_length,
2659 client->interface->name);
2668 tv.tv_sec = cur_tv.tv_sec + client->interval;
2669 tv.tv_usec = client->interval > 1 ? random() % 1000000 : cur_tv.tv_usec;
2670 add_timeout(&tv, send_discover, client, 0, 0);
2770 haven't yet expired, and failing that, we call the client script and
2776 struct client_state *client = cpp;
2781 loop = lp = client -> active;
2787 if (!client -> active && client -> leases)
2791 while (client -> active) {
2792 if (client -> active -> expiry > cur_time) {
2794 (client -> active -> is_static
2796 piaddr (client -> active -> address));
2797 /* Run the client script with the existing
2799 script_init(client, "TIMEOUT",
2800 client -> active -> medium);
2801 script_write_params(client, "new_", client -> active);
2802 script_write_requested(client);
2803 if (client -> alias)
2804 script_write_params(client, "alias_",
2805 client -> alias);
2810 if (!script_go(client)) {
2811 if (cur_time < client -> active -> renewal) {
2812 client -> state = S_BOUND;
2814 (long)(client -> active -> renewal -
2816 tv.tv_sec = client->active->renewal;
2817 tv.tv_usec = ((client->active->renewal -
2821 add_timeout(&tv, state_bound, client, 0, 0);
2823 client -> state = S_BOUND;
2825 state_bound (client);
2834 if (!client -> leases) {
2835 client -> leases = client -> active;
2836 client -> active = (struct client_lease *)0;
2843 add_to_tail(&client->leases, client->active);
2845 client -> active = client -> leases;
2846 client -> leases = client -> leases -> next;
2851 if (client -> active == loop)
2854 loop = client -> active;
2868 script_init(client, "FAIL", (struct string_list *)0);
2869 script_go(client);
2875 script_init(client, "FAIL", (struct string_list *)0);
2876 if (client -> alias)
2877 script_write_params(client, "alias_", client -> alias);
2878 script_go(client);
2879 client -> state = S_INIT;
2880 tv.tv_sec = cur_tv.tv_sec + ((client->config->retry_interval + 1) / 2 +
2881 (random() % client->config->retry_interval));
2884 add_timeout(&tv, state_init, client, 0, 0);
2891 struct client_state *client = cpp;
2902 interval = cur_time - client -> first_sending;
2914 if ((client -> state == S_REBOOTING ||
2915 client -> state == S_REQUESTING) &&
2916 interval > client -> config -> reboot_timeout) {
2918 client -> state = S_INIT;
2919 cancel_timeout (send_request, client);
2920 state_init (client);
2926 if (client -> state == S_REBOOTING &&
2927 !client -> medium &&
2928 client -> active -> medium ) {
2929 script_init(client, "MEDIUM", client -> active -> medium);
2932 if (script_go(client))
2936 client -> medium = client
2941 if (client -> state != S_REQUESTING &&
2942 cur_time > client -> active -> expiry) {
2943 /* Run the client script with the new parameters. */
2944 script_init(client, "EXPIRE", (struct string_list *)0);
2945 script_write_params(client, "old_", client -> active);
2946 script_write_requested(client);
2947 if (client -> alias)
2948 script_write_params(client, "alias_",
2949 client -> alias);
2950 script_go(client);
2954 script_init(client, "PREINIT", (struct string_list *)0);
2955 if (client -> alias)
2956 script_write_params(client, "alias_",
2957 client -> alias);
2958 script_go(client);
2960 client -> state = S_INIT;
2961 state_init (client);
2966 if (!client -> interval)
2967 client -> interval = client -> config -> initial_interval;
2969 client -> interval += ((random () >> 2) %
2970 (2 * client -> interval));
2974 if (client -> interval >
2975 client -> config -> backoff_cutoff)
2976 client -> interval =
2977 ((client -> config -> backoff_cutoff / 2)
2979 client -> config -> backoff_cutoff));
2983 if (client -> state != S_REQUESTING &&
2984 cur_time + client -> interval > client -> active -> expiry)
2985 client -> interval =
2986 client -> active -> expiry - cur_time + 1;
2990 if (client -> state == S_REQUESTING ||
2991 client -> state == S_REBOOTING ||
2992 cur_time > client -> active -> rebind)
2996 client -> destination.iabuf,
3004 if (client -> state == S_RENEWING ||
3005 client -> state == S_REBINDING)
3006 memcpy (&from, client -> active -> address.iabuf,
3012 if (client -> state == S_REQUESTING)
3013 client -> packet.secs = client -> secs;
3016 client -> packet.secs = htons (interval);
3018 client -> packet.secs = htons (65535);
3027 if (client->state == S_BOUND || client->state == S_RENEWING ||
3028 client->state == S_REBINDING) {
3029 rip_str = inet_ntoa(client->packet.ciaddr);
3031 rip_str = piaddr(client->requested_address);
3036 client->name ? client->name : client->interface->name,
3045 result = send_dhcpv4_query(client, broadcast);
3048 MDL, client->packet_length);
3054 result = send_packet(fallback_interface, NULL, &client->packet,
3055 client->packet_length, from, &destination,
3060 client->packet_length,
3066 result = send_packet(client->interface, NULL, &client->packet,
3067 client->packet_length, from, &destination,
3072 client->packet_length,
3073 client->interface->name);
3077 tv.tv_sec = cur_tv.tv_sec + client->interval;
3080 add_timeout(&tv, send_request, client, 0, 0);
3086 struct client_state *client = cpp;
3096 piaddr(client->requested_address),
3097 (client->name ? client->name : client->interface->name),
3104 result = send_dhcpv4_query(client, 1);
3107 result = send_packet(client->interface, NULL, &client->packet,
3108 client->packet_length, inaddr_any,
3114 MDL, client->packet_length);
3118 " interface.", MDL, client->packet_length,
3119 client->interface->name);
3126 struct client_state *client = cpp;
3132 memcpy (&from, client -> active -> address.iabuf,
3135 client -> destination.iabuf,
3145 client -> active -> expiry =
3146 client -> active -> renewal =
3147 client -> active -> rebind = cur_time;
3148 if (!write_client_lease (client, client -> active, 1, 1)) {
3159 piaddr(client->active->address),
3160 client->name ? client->name : client->interface->name,
3169 result = send_dhcpv4_query(client, broadcast);
3172 MDL, client->packet_length);
3177 result = send_packet(fallback_interface, NULL, &client->packet,
3178 client->packet_length, from, &destination,
3183 client->packet_length,
3188 result = send_packet(client->interface, NULL, &client->packet,
3189 client->packet_length, from, &destination,
3194 client->packet_length,
3195 client->interface->name);
3203 * \brief Send a DHCPv4-query to the DHCPv6 client
3204 * (DHCPv4 client function)
3206 * The DHCPv4 client sends a DHCPv4-query to the DHCPv6 client over
3209 * \param client the DHCPv4 client state
3213 static int send_dhcpv4_query(struct client_state *client, int broadcast) {
3228 len += client->packet_length;
3252 client->packet_length);
3254 memcpy(ds.buffer->data + ofs, &client->packet, client->packet_length);
3270 * (DHCPv6 client function)
3276 struct client_state *client;
3292 for (client = ip->client; client != NULL;
3293 client = client->next) {
3294 if ((client->state != S_BOUND) &&
3295 (client->state != S_RENEWING) &&
3296 (client->state != S_REBINDING))
3298 lease = client->active_lease;
3347 make_client_options(struct client_state *client, struct client_lease *lease,
3372 client->requested_address = *rip;
3385 client->requested_address.len = 0;
3435 * If requested (duid_v4 == 1) add an RFC4361 compliant client-identifier
3436 * This can be overridden by including a client id in the configuration
3452 /* Client-identifier type : 1 byte */
3458 if (client->interface->hw_address.hlen > 4) {
3459 hw_idx = client->interface->hw_address.hlen - 4;
3463 hw_len = client->interface->hw_address.hlen;
3466 client->interface->hw_address.hbuf + hw_idx,
3480 log_error ("can't make requested client id cache..");
3489 if (client->config->on_transmission)
3490 execute_statements_in_scope(NULL, NULL, NULL, client,
3493 client->config->on_transmission,
3497 void make_discover (client, lease)
3498 struct client_state *client;
3504 memset (&client -> packet, 0, sizeof (client -> packet));
3506 make_client_options (client,
3509 client -> config -> requested_options,
3513 client -> packet_length =
3514 cons_options ((struct packet *)0, &client -> packet,
3515 (struct lease *)0, client,
3524 client -> config -> vendor_space_name);
3527 if (client -> packet_length < BOOTP_MIN_LEN)
3528 client -> packet_length = BOOTP_MIN_LEN;
3530 client -> packet.op = BOOTREQUEST;
3531 client -> packet.htype = client -> interface -> hw_address.hbuf [0];
3533 client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
3534 client -> packet.hops = 0;
3535 client -> packet.xid = random ();
3536 client -> packet.secs = 0; /* filled in by send_discover. */
3538 if (can_receive_unicast_unconfigured (client -> interface))
3539 client -> packet.flags = 0;
3541 client -> packet.flags = htons (BOOTP_BROADCAST);
3543 memset (&(client -> packet.ciaddr),
3544 0, sizeof client -> packet.ciaddr);
3545 memset (&(client -> packet.yiaddr),
3546 0, sizeof client -> packet.yiaddr);
3547 memset (&(client -> packet.siaddr),
3548 0, sizeof client -> packet.siaddr);
3549 client -> packet.giaddr = giaddr;
3550 if (client -> interface -> hw_address.hlen > 0)
3551 memcpy (client -> packet.chaddr,
3552 &client -> interface -> hw_address.hbuf [1],
3553 (unsigned)(client -> interface -> hw_address.hlen - 1));
3556 dump_raw ((unsigned char *)&client -> packet, client -> packet_length);
3561 void make_request (client, lease)
3562 struct client_state *client;
3568 memset (&client -> packet, 0, sizeof (client -> packet));
3570 if (client -> state == S_REQUESTING)
3576 if (client -> sent_options)
3577 option_state_dereference (&client -> sent_options, MDL);
3579 make_client_options (client, lease, &request, oc,
3580 ((client -> state == S_REQUESTING ||
3581 client -> state == S_REBOOTING)
3584 client -> config -> requested_options,
3585 &client -> sent_options);
3588 client -> packet_length =
3589 cons_options ((struct packet *)0, &client -> packet,
3590 (struct lease *)0, client,
3593 client -> sent_options,
3599 client -> config -> vendor_space_name);
3601 if (client -> packet_length < BOOTP_MIN_LEN)
3602 client -> packet_length = BOOTP_MIN_LEN;
3604 client -> packet.op = BOOTREQUEST;
3605 client -> packet.htype = client -> interface -> hw_address.hbuf [0];
3607 client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
3608 client -> packet.hops = 0;
3609 client -> packet.xid = client -> xid;
3610 client -> packet.secs = 0; /* Filled in by send_request. */
3614 if (client -> state == S_BOUND ||
3615 client -> state == S_RENEWING ||
3616 client -> state == S_REBINDING) {
3617 memcpy (&client -> packet.ciaddr,
3619 client -> packet.flags = 0;
3621 memset (&client -> packet.ciaddr, 0,
3622 sizeof client -> packet.ciaddr);
3623 if (can_receive_unicast_unconfigured (client -> interface))
3624 client -> packet.flags = 0;
3626 client -> packet.flags = htons (BOOTP_BROADCAST);
3629 memset (&client -> packet.yiaddr, 0,
3630 sizeof client -> packet.yiaddr);
3631 memset (&client -> packet.siaddr, 0,
3632 sizeof client -> packet.siaddr);
3633 if (client -> state != S_BOUND &&
3634 client -> state != S_RENEWING)
3635 client -> packet.giaddr = giaddr;
3637 memset (&client -> packet.giaddr, 0,
3638 sizeof client -> packet.giaddr);
3639 if (client -> interface -> hw_address.hlen > 0)
3640 memcpy (client -> packet.chaddr,
3641 &client -> interface -> hw_address.hbuf [1],
3642 (unsigned)(client -> interface -> hw_address.hlen - 1));
3645 dump_raw ((unsigned char *)&client -> packet, client -> packet_length);
3649 void make_decline (client, lease)
3650 struct client_state *client;
3661 make_client_options(client, lease, &decline, oc, &lease->address,
3665 memset (&client -> packet, 0, sizeof (client -> packet));
3666 client -> packet_length =
3667 cons_options ((struct packet *)0, &client -> packet,
3668 (struct lease *)0, client, 0,
3671 client -> config -> vendor_space_name);
3676 if (client -> packet_length < BOOTP_MIN_LEN)
3677 client -> packet_length = BOOTP_MIN_LEN;
3679 client -> packet.op = BOOTREQUEST;
3680 client -> packet.htype = client -> interface -> hw_address.hbuf [0];
3682 client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
3683 client -> packet.hops = 0;
3684 client -> packet.xid = client -> xid;
3685 client -> packet.secs = 0; /* Filled in by send_request. */
3686 if (can_receive_unicast_unconfigured (client -> interface))
3687 client -> packet.flags = 0;
3689 client -> packet.flags = htons (BOOTP_BROADCAST);
3692 memset (&client -> packet.ciaddr, 0,
3693 sizeof client -> packet.ciaddr);
3694 memset (&client -> packet.yiaddr, 0,
3695 sizeof client -> packet.yiaddr);
3696 memset (&client -> packet.siaddr, 0,
3697 sizeof client -> packet.siaddr);
3698 client -> packet.giaddr = giaddr;
3699 memcpy (client -> packet.chaddr,
3700 &client -> interface -> hw_address.hbuf [1],
3701 client -> interface -> hw_address.hlen);
3704 dump_raw ((unsigned char *)&client -> packet, client -> packet_length);
3708 void make_release (client, lease)
3709 struct client_state *client;
3717 memset (&client -> packet, 0, sizeof (client -> packet));
3721 make_client_options(client, lease, &request, oc, NULL, NULL, &options);
3724 client -> packet_length =
3725 cons_options ((struct packet *)0, &client -> packet,
3726 (struct lease *)0, client,
3735 client -> config -> vendor_space_name);
3737 if (client -> packet_length < BOOTP_MIN_LEN)
3738 client -> packet_length = BOOTP_MIN_LEN;
3741 client -> packet.op = BOOTREQUEST;
3742 client -> packet.htype = client -> interface -> hw_address.hbuf [0];
3744 client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
3745 client -> packet.hops = 0;
3746 client -> packet.xid = random ();
3747 client -> packet.secs = 0;
3748 client -> packet.flags = 0;
3749 memcpy (&client -> packet.ciaddr,
3751 memset (&client -> packet.yiaddr, 0,
3752 sizeof client -> packet.yiaddr);
3753 memset (&client -> packet.siaddr, 0,
3754 sizeof client -> packet.siaddr);
3755 client -> packet.giaddr = giaddr;
3756 memcpy (client -> packet.chaddr,
3757 &client -> interface -> hw_address.hbuf [1],
3758 client -> interface -> hw_address.hlen);
3761 dump_raw ((unsigned char *)&client -> packet, client -> packet_length);
3782 struct client_state *client;
3800 for (client = ip -> client; client; client = client -> next) {
3801 for (lp = client -> leases; lp; lp = lp -> next) {
3802 write_client_lease (client, lp, 1, 0);
3804 if (client -> active)
3805 write_client_lease (client,
3806 client -> active, 1, 0);
3808 if (client->active_lease != NULL)
3809 write_client6_lease(client,
3810 client->active_lease,
3814 client->last_write = 0;
3821 for (client = ip -> client; client; client = client -> next) {
3822 for (lp = client -> leases; lp; lp = lp -> next) {
3823 write_client_lease (client, lp, 1, 0);
3825 if (client -> active)
3826 write_client_lease (client,
3827 client -> active, 1, 0);
3829 if (client->active_lease != NULL)
3830 write_client6_lease(client,
3831 client->active_lease,
3835 client->last_write = 0;
3885 write_options(struct client_state *client, struct option_state *options,
3891 option_space_foreach(NULL, NULL, client, NULL, options,
3908 * is not how it is intended. Upcoming rearchitecting the client should
4008 write_client6_lease(struct client_state *client, struct dhc6_lease *lease,
4023 if (client == NULL || lease == NULL)
4039 client->interface->name);
4121 write_options(client, addr->options, " ");
4129 write_options(client, ia->options, " ");
4143 write_options(client, lease->options, " ");
4162 int write_client_lease (client, lease, rewrite, makesure)
4163 struct client_state *client;
4203 client -> interface -> name);
4208 if (client -> name) {
4209 fprintf (leaseFile, " name \"%s\";\n", client -> name);
4265 write_options(client, lease->options, " ");
4288 client->last_write = cur_time;
4313 * @param client variables will be stored here (if null, the whole function
4318 void script_init(struct client_state *client, const char *reason,
4323 if (client) {
4324 for (sl = client -> env; sl; sl = next) {
4328 client -> env = (struct string_list *)0;
4329 client -> envc = 0;
4331 if (client -> interface) {
4332 client_envadd (client, "", "interface", "%s",
4333 client -> interface -> name);
4335 if (client -> name)
4336 client_envadd (client,
4337 "", "client", "%s", client -> name);
4339 client_envadd (client,
4342 client_envadd (client, "", "reason", "%s", reason);
4343 client_envadd (client, "", "pid", "%ld", (long int)getpid ());
4345 client_envadd (client, "", "dad_wait_time", "%ld",
4379 client_envadd(es->client, es->prefix,
4398 * specified prefix (e.g. "old_") and added to the list stored in client.
4408 * @param client env. variables will be stored here
4412 void script_write_params(struct client_state *client, const char *prefix,
4420 es.client = client;
4423 client_envadd (client,
4429 client_envadd(client, prefix, "next_server", "%s",
4443 (struct lease *)0, client,
4463 client_envadd (client, prefix, "network_number",
4472 (struct lease *)0, client,
4478 client_envadd (client,
4492 client_envadd(client, prefix, "filename",
4505 client_envadd (client, prefix, "server_name",
4516 client, (struct option_state *)0,
4522 client_envadd (client, prefix, "expiry", "%lu",
4527 * @brief Write out the environent variable the client requested.
4529 * client requested. If the object was requested the variable will be:
4533 * @param client client structure
4535 void script_write_requested(struct client_state *client)
4540 req = client->config->requested_options;
4548 client_envadd(client, "requested_", name, "%d", 1);
4559 * @param client specifies client information (environment variables,
4565 int script_go(struct client_state *client)
4576 if (client)
4577 scriptName = client -> config -> script_name;
4581 envp = dmalloc (((client ? client -> envc : 2) +
4584 log_error ("No memory for client script environment.");
4594 if (client) {
4595 for (sp = client -> env; sp; sp = sp -> next) {
4631 if (client) {
4632 for (sp = client -> env; sp; sp = next) {
4636 client -> env = (struct string_list *)0;
4637 client -> envc = 0;
4651 void client_envadd (struct client_state *client,
4684 val -> next = client -> env;
4685 client -> env = val;
4686 client -> envc++;
4812 struct client_state *client;
4815 for (client = ip -> client; client; client = client -> next) {
4816 switch (client -> state) {
4818 cancel_timeout (send_discover, client);
4822 cancel_timeout (state_bound, client);
4828 cancel_timeout (send_request, client);
4838 client -> state = S_INIT;
4839 state_reboot (client);
4844 void do_release(client)
4845 struct client_state *client;
4854 client->pending = P_RELEASE;
4860 client -> xid = random ();
4863 if (client -> active) {
4866 make_release (client, client -> active);
4870 client -> active -> options,
4874 (struct lease *)0, client,
4876 client -> active -> options,
4879 memcpy (client -> destination.iabuf,
4881 client -> destination.len = 4;
4883 client -> destination = iaddr_broadcast;
4887 client -> destination = iaddr_broadcast;
4888 client -> first_sending = cur_time;
4889 client -> interval = client -> config -> initial_interval;
4892 client -> medium = (struct string_list *)0;
4895 send_release (client);
4897 /* Do the client script RELEASE operation. */
4898 script_init (client,
4900 if (client -> alias)
4901 script_write_params(client, "alias_",
4902 client -> alias);
4903 script_write_params(client, "old_", client -> active);
4904 script_write_requested(client);
4905 script_go(client);
4909 cancel_timeout (state_bound, client);
4910 cancel_timeout (send_discover, client);
4911 cancel_timeout (state_init, client);
4912 cancel_timeout (send_request, client);
4913 cancel_timeout (state_reboot, client);
4914 cancel_timeout (finish_v6only, client);
4915 client -> state = S_STOPPED;
4925 do_release (interface -> client);
4933 /* See if we can find the client from dummy_interfaces */
4960 /* Copy "client" to tmp */
4961 if (ip -> client) {
4962 tmp -> client = ip -> client;
4963 tmp -> client -> interface = tmp;
4976 struct client_state *client;
4998 script_init (ip -> client,
5000 if (ip -> client -> alias)
5001 script_write_params(ip -> client, "alias_",
5002 ip -> client -> alias);
5003 script_go(ip -> client);
5014 for (client = ip->client ; client ; client = client->next) {
5015 client->state = S_INIT;
5016 state_reboot(client);
5022 /* The client should never receive a relay agent information option,
5033 /* The client never sends relay agent information options. */
5058 * which has caused the client's A RR to be replaced. It may also be
5059 * that some other client has been configured with a name that matches
5060 * the name of the DHCP client, and the policy was that the last client
5062 * will no longer match the updater's notion of the client-identity of
5092 client_dns_remove(struct client_state *client,
5098 /* if we have an old ddns request for this client, cancel it */
5099 if (client->ddns_cb != NULL) {
5100 ddns_cancel(client->ddns_cb, MDL);
5101 client->ddns_cb = NULL;
5113 result = client_dns_update(client, ddns_cb);
5127 struct client_state *client;
5146 for (client = ip -> client; client; client = client -> next) {
5155 if (client -> active &&
5156 client -> active -> expiry > cur_time) {
5158 if (client->config->do_forward_update) {
5159 client_dns_remove(client,
5160 &client->active->address);
5164 do_release (client);
5169 state_stop (client);
5173 state_reboot (client);
5197 struct client_state *client = (struct client_state *)ddns_cb->lease;
5200 if ((client != NULL) &&
5201 ((client->active != NULL) ||
5202 (client->active_lease != NULL)))
5203 status = client_dns_update(client, ddns_cb);
5222 * The A RR update is now complete (and a client updater is finished,
5227 * client was the last client associated with the domain name, and that
5229 * complete (and a client updater is finished, while a server would
5234 * that the client's desired name is in use by another host. At this
5239 * client, or to replace the RRs on the name with RRs that represent
5240 * the current client. If the configured policy allows replacement of
5243 * represent the IP address and client-identity of the new client.
5311 client_dns_update(struct client_state *client, dhcp_ddns_cb_t *ddns_cb)
5322 if (!client -> sent_options)
5326 if ((client->active == NULL) && (client->active_lease == NULL))
5329 /* If we set the no client update flag, don't do the update. */
5330 if ((oc = lookup_option (&fqdn_universe, client -> sent_options,
5333 (struct lease *)0, client,
5334 client -> sent_options,
5341 if (!(oc = lookup_option (&fqdn_universe, client -> sent_options,
5344 (struct lease *)0, client,
5345 client -> sent_options,
5351 if (!(oc = lookup_option (&fqdn_universe, client -> sent_options,
5354 (struct lease *)0, client,
5355 client -> sent_options,
5382 if (client->active_lease != NULL) {
5383 /* V6 request, get the client identifier, then
5387 client->sent_options,
5390 NULL, client,
5391 client->sent_options, NULL,
5401 * V4 request, use the client id if there is one or the
5402 * mac address if there isn't. If we have a client id
5406 client->sent_options,
5409 NULL, client,
5410 client->sent_options, NULL,
5432 client->interface->hw_address.hbuf,
5433 client->interface->hw_address.hlen);
5465 dhclient_schedule_updates(struct client_state *client,
5472 if (!client->config->do_forward_update)
5476 if (client->ddns_cb != NULL) {
5477 ddns_cancel(client->ddns_cb, MDL);
5478 client->ddns_cb = NULL;
5484 ddns_cb->lease = (void *)client;
5500 client->ddns_cb = ddns_cb;
5525 use the server port, not the client port. */
5543 we're using the server port, not the client port. */
5695 list->next = packet->interface->client->config->reject_list;
5696 packet->interface->client->config->reject_list = list;
5711 struct client_state *client = (struct client_state *)ddns_cb->lease;
5712 if (client != NULL) {
5713 client->ddns_cb = NULL;
5822 * \brief Poll the DHCPv6 client
5823 * (DHCPv4 client function)
5825 * A POLL message is sent to the DHCPv6 client periodically to check
5853 * (DHCPv4 client function)
5855 * A START message was received from the DHCPv6 client so pending
5860 struct client_state *client;
5863 for (client = ip->client; client != NULL;
5864 client = client->next) {
5865 if (client->pending == P_RELEASE)
5866 do_release(client);
5867 else if (client->pending == P_REBOOT)
5868 state_reboot(client);
5874 * \brief Send a START to the DHCPv4 client
5875 * (DHCPv6 client function)
5879 * a START message to the DHCPv4 client.
5883 struct client_state *client;
5892 for (client = ip->client; client != NULL;
5893 client = client->next) {
5894 if ((client->state != S_BOUND) &&
5895 (client->state != S_RENEWING) &&
5896 (client->state != S_REBINDING))
5898 lease = client->active_lease;
5933 * Send a STOP to the DHCPv4 client
5934 * (DHCPv6 client function)
5937 * to the DHCPv4 client.