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 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 /*
30 * This module reads and writes the stable identifier values, DUID and IAID.
31 */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <limits.h>
38 #include <fcntl.h>
39 #include <errno.h>
40 #include <libdlpi.h>
41 #include <uuid/uuid.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <net/if.h>
45 #include <netinet/dhcp6.h>
46 #include <dhcp_inittab.h>
47
48 #define DUID_FILE "/etc/dhcp/duid"
49 #define IAID_FILE "/etc/dhcp/iaid"
50
51 struct iaid_ent {
52 uint32_t ie_iaid;
53 char ie_name[LIFNAMSIZ];
54 };
55
56 /*
57 * read_stable_duid(): read the system's stable DUID, if any
58 *
59 * input: size_t *: pointer to a size_t to return the DUID length
60 * output: uchar_t *: the DUID buffer, or NULL on error (and errno is set)
61 * note: memory returned is from malloc; caller must free.
62 */
63
64 uchar_t *
65 read_stable_duid(size_t *duidlen)
66 {
126 * size_t *: pointer to a size_t to return the DUID length
127 * output: uchar_t *: the DUID buffer, or NULL on error (and errno is set)
128 * note: memory returned is from malloc; caller must free.
129 */
130
131 uchar_t *
132 make_stable_duid(const char *physintf, size_t *duidlen)
133 {
134 int len;
135 dlpi_info_t dlinfo;
136 dlpi_handle_t dh = NULL;
137 uint_t arptype;
138 duid_en_t *den;
139
140 /*
141 * Try to read the MAC layer address for the physical interface
142 * provided as a hint. If that works, we can use a DUID-LLT.
143 */
144
145 if (dlpi_open(physintf, &dh, 0) == DLPI_SUCCESS &&
146 dlpi_info(dh, &dlinfo, 0) == DLPI_SUCCESS &&
147 (len = dlinfo.di_physaddrlen) > 0 &&
148 (arptype = dlpi_arptype(dlinfo.di_mactype) != 0)) {
149 duid_llt_t *dllt;
150 time_t now;
151
152 if ((dllt = malloc(sizeof (*dllt) + len)) == NULL) {
153 dlpi_close(dh);
154 return (NULL);
155 }
156
157 (void) memcpy((dllt + 1), dlinfo.di_physaddr, len);
158 dllt->dllt_dutype = htons(DHCPV6_DUID_LLT);
159 dllt->dllt_hwtype = htons(arptype);
160 now = time(NULL) - DUID_TIME_BASE;
161 dllt->dllt_time = htonl(now);
162 *duidlen = sizeof (*dllt) + len;
163 dlpi_close(dh);
164 return ((uchar_t *)dllt);
165 }
|
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 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * This module reads and writes the stable identifier values, DUID and IAID.
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <limits.h>
36 #include <fcntl.h>
37 #include <errno.h>
38 #include <libdlpi.h>
39 #include <uuid/uuid.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <net/if.h>
43 #include <netinet/dhcp6.h>
44 #include <dhcp_inittab.h>
45 #include <sys/ethernet.h>
46
47 #define DUID_FILE "/etc/dhcp/duid"
48 #define IAID_FILE "/etc/dhcp/iaid"
49
50 struct iaid_ent {
51 uint32_t ie_iaid;
52 char ie_name[LIFNAMSIZ];
53 };
54
55 /*
56 * read_stable_duid(): read the system's stable DUID, if any
57 *
58 * input: size_t *: pointer to a size_t to return the DUID length
59 * output: uchar_t *: the DUID buffer, or NULL on error (and errno is set)
60 * note: memory returned is from malloc; caller must free.
61 */
62
63 uchar_t *
64 read_stable_duid(size_t *duidlen)
65 {
125 * size_t *: pointer to a size_t to return the DUID length
126 * output: uchar_t *: the DUID buffer, or NULL on error (and errno is set)
127 * note: memory returned is from malloc; caller must free.
128 */
129
130 uchar_t *
131 make_stable_duid(const char *physintf, size_t *duidlen)
132 {
133 int len;
134 dlpi_info_t dlinfo;
135 dlpi_handle_t dh = NULL;
136 uint_t arptype;
137 duid_en_t *den;
138
139 /*
140 * Try to read the MAC layer address for the physical interface
141 * provided as a hint. If that works, we can use a DUID-LLT.
142 */
143
144 if (dlpi_open(physintf, &dh, 0) == DLPI_SUCCESS &&
145 dlpi_bind(dh, ETHERTYPE_IPV6, NULL) == DLPI_SUCCESS &&
146 dlpi_info(dh, &dlinfo, 0) == DLPI_SUCCESS &&
147 (len = dlinfo.di_physaddrlen) > 0 &&
148 (arptype = dlpi_arptype(dlinfo.di_mactype) != 0)) {
149 duid_llt_t *dllt;
150 time_t now;
151
152 if ((dllt = malloc(sizeof (*dllt) + len)) == NULL) {
153 dlpi_close(dh);
154 return (NULL);
155 }
156
157 (void) memcpy((dllt + 1), dlinfo.di_physaddr, len);
158 dllt->dllt_dutype = htons(DHCPV6_DUID_LLT);
159 dllt->dllt_hwtype = htons(arptype);
160 now = time(NULL) - DUID_TIME_BASE;
161 dllt->dllt_time = htonl(now);
162 *duidlen = sizeof (*dllt) + len;
163 dlpi_close(dh);
164 return ((uchar_t *)dllt);
165 }
|