3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 #include <sys/types.h>
26 #include <time.h>
27 #include <netinet/in.h>
28 #include <netinet/dhcp.h>
29 #include <netinet/udp.h>
30 #include <netinet/ip_var.h>
31 #include <netinet/udp_var.h>
32 #include <libinetutil.h>
33 #include <dhcpmsg.h>
34 #include <dhcp_hostconf.h>
35 #include <string.h>
36
37 #include "packet.h"
38 #include "agent.h"
39 #include "script_handler.h"
40 #include "interface.h"
41 #include "states.h"
42 #include "util.h"
445 irt = DHCPV6_REB_TIMEOUT;
446 mrt = DHCPV6_REB_MAX_RT;
447 }
448
449 /*
450 * Loop over the leases, and add an IA_NA for each and an
451 * IAADDR for each address.
452 */
453 for (dlp = dsmp->dsm_leases; dlp != NULL; dlp = dlp->dl_next) {
454 lif = dlp->dl_lifs;
455 for (nlifs = dlp->dl_nlifs; nlifs > 0;
456 nlifs--, lif = lif->lif_next) {
457 (void) add_pkt_lif(dpkt, lif,
458 DHCPV6_STAT_SUCCESS, NULL);
459 }
460 }
461
462 /* Add required Option Request option */
463 (void) add_pkt_prl(dpkt, dsmp);
464
465 return (send_pkt_v6(dsmp, dpkt, dsmp->dsm_server,
466 stop_extending, irt, mrt));
467 } else {
468 dhcp_lif_t *lif = dsmp->dsm_lif;
469 ipaddr_t server;
470
471 /* assemble the DHCPREQUEST message. */
472 dpkt = init_pkt(dsmp, REQUEST);
473 dpkt->pkt->ciaddr.s_addr = lif->lif_addr;
474
475 /*
476 * The max dhcp message size option is set to the interface
477 * max, minus the size of the udp and ip headers.
478 */
479 (void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
480 htons(lif->lif_max - sizeof (struct udpiphdr)));
481 (void) add_pkt_opt32(dpkt, CD_LEASE_TIME, htonl(DHCP_PERM));
482
483 if (class_id_len != 0) {
484 (void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id,
485 class_id_len);
486 }
487 (void) add_pkt_prl(dpkt, dsmp);
488 /*
489 * dsm_reqhost was set for this state machine in
490 * dhcp_selecting() if the REQUEST_HOSTNAME option was set and
491 * a host name was found.
492 */
493 if (dsmp->dsm_reqhost != NULL) {
494 (void) add_pkt_opt(dpkt, CD_HOSTNAME, dsmp->dsm_reqhost,
495 strlen(dsmp->dsm_reqhost));
496 }
497 (void) add_pkt_opt(dpkt, CD_END, NULL, 0);
498
499 IN6_V4MAPPED_TO_IPADDR(&dsmp->dsm_server, server);
500 return (send_pkt(dsmp, dpkt, server, stop_extending));
501 }
502 }
503
504 /*
505 * stop_extending(): decides when to stop retransmitting v4 REQUEST or v6
506 * Renew/Rebind messages. If we're renewing, then stop if
507 * T2 is soon approaching.
508 *
509 * input: dhcp_smach_t *: the state machine REQUESTs are being sent from
510 * unsigned int: the number of REQUESTs sent so far
511 * output: boolean_t: B_TRUE if retransmissions should stop
512 */
513
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
24 */
25
26 #include <sys/types.h>
27 #include <time.h>
28 #include <netinet/in.h>
29 #include <netinet/dhcp.h>
30 #include <netinet/udp.h>
31 #include <netinet/ip_var.h>
32 #include <netinet/udp_var.h>
33 #include <libinetutil.h>
34 #include <dhcpmsg.h>
35 #include <dhcp_hostconf.h>
36 #include <string.h>
37
38 #include "packet.h"
39 #include "agent.h"
40 #include "script_handler.h"
41 #include "interface.h"
42 #include "states.h"
43 #include "util.h"
446 irt = DHCPV6_REB_TIMEOUT;
447 mrt = DHCPV6_REB_MAX_RT;
448 }
449
450 /*
451 * Loop over the leases, and add an IA_NA for each and an
452 * IAADDR for each address.
453 */
454 for (dlp = dsmp->dsm_leases; dlp != NULL; dlp = dlp->dl_next) {
455 lif = dlp->dl_lifs;
456 for (nlifs = dlp->dl_nlifs; nlifs > 0;
457 nlifs--, lif = lif->lif_next) {
458 (void) add_pkt_lif(dpkt, lif,
459 DHCPV6_STAT_SUCCESS, NULL);
460 }
461 }
462
463 /* Add required Option Request option */
464 (void) add_pkt_prl(dpkt, dsmp);
465
466 /* Add FQDN if configured */
467 (void) dhcp_add_fqdn_opt(dpkt, dsmp);
468
469 return (send_pkt_v6(dsmp, dpkt, dsmp->dsm_server,
470 stop_extending, irt, mrt));
471 } else {
472 dhcp_lif_t *lif = dsmp->dsm_lif;
473 ipaddr_t server;
474
475 /* assemble the DHCPREQUEST message. */
476 dpkt = init_pkt(dsmp, REQUEST);
477 dpkt->pkt->ciaddr.s_addr = lif->lif_addr;
478
479 /*
480 * The max dhcp message size option is set to the interface
481 * max, minus the size of the udp and ip headers.
482 */
483 (void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
484 htons(lif->lif_max - sizeof (struct udpiphdr)));
485 (void) add_pkt_opt32(dpkt, CD_LEASE_TIME, htonl(DHCP_PERM));
486
487 if (class_id_len != 0) {
488 (void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id,
489 class_id_len);
490 }
491 (void) add_pkt_prl(dpkt, dsmp);
492 /*
493 * dsm_reqhost was set for this state machine in
494 * dhcp_selecting() if the REQUEST_HOSTNAME option was set and
495 * a host name was found.
496 */
497 if (dhcp_add_fqdn_opt(dpkt, dsmp) != 0 &&
498 dsmp->dsm_reqhost != NULL) {
499 (void) add_pkt_opt(dpkt, CD_HOSTNAME, dsmp->dsm_reqhost,
500 strlen(dsmp->dsm_reqhost));
501 }
502 (void) add_pkt_opt(dpkt, CD_END, NULL, 0);
503
504 IN6_V4MAPPED_TO_IPADDR(&dsmp->dsm_server, server);
505 return (send_pkt(dsmp, dpkt, server, stop_extending));
506 }
507 }
508
509 /*
510 * stop_extending(): decides when to stop retransmitting v4 REQUEST or v6
511 * Renew/Rebind messages. If we're renewing, then stop if
512 * T2 is soon approaching.
513 *
514 * input: dhcp_smach_t *: the state machine REQUESTs are being sent from
515 * unsigned int: the number of REQUESTs sent so far
516 * output: boolean_t: B_TRUE if retransmissions should stop
517 */
518
|