Print this page
3087 libuuid has a lot of dependencies
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libuuid/common/etheraddr.c
+++ new/usr/src/lib/libuuid/common/etheraddr.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 + *
25 + * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 26 */
25 27
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 28 #include <stdlib.h>
29 29 #include <stdio.h>
30 30 #include <strings.h>
31 31 #include <stropts.h>
32 32 #include <unistd.h>
33 33 #include <uuid/uuid.h>
34 34 #include <sys/sockio.h>
35 -#include <libdlpi.h>
36 35 #include <sys/utsname.h>
37 36
38 37 #include <netdb.h>
39 38 #include <netinet/in.h>
40 39 #include <arpa/inet.h>
41 40
42 41 #include "etheraddr.h"
43 42
44 -static boolean_t get_etheraddr(const char *linkname, void *arg);
45 -
46 43 /*
47 44 * get an individual arp entry
48 45 */
49 -int
46 +static int
50 47 arp_get(uuid_node_t *node)
51 48 {
52 49 struct utsname name;
53 50 struct arpreq ar;
54 51 struct hostent *hp;
55 52 struct sockaddr_in *sin;
56 53 int s;
57 54
58 55 if (uname(&name) == -1) {
59 56 return (-1);
60 57 }
61 58 (void) memset(&ar, 0, sizeof (ar));
62 59 ar.arp_pa.sa_family = AF_INET;
63 60 /* LINTED pointer */
64 61 sin = (struct sockaddr_in *)&ar.arp_pa;
65 62 sin->sin_family = AF_INET;
66 63 sin->sin_addr.s_addr = inet_addr(name.nodename);
67 64 if (sin->sin_addr.s_addr == (in_addr_t)-1) {
68 65 hp = gethostbyname(name.nodename);
69 66 if (hp == NULL) {
70 67 return (-1);
71 68 }
72 69 (void) memcpy(&sin->sin_addr, hp->h_addr,
73 70 sizeof (sin->sin_addr));
74 71 }
75 72 s = socket(AF_INET, SOCK_DGRAM, 0);
76 73 if (s < 0) {
77 74 return (-1);
78 75 }
79 76 if (ioctl(s, SIOCGARP, (caddr_t)&ar) < 0) {
80 77 (void) close(s);
81 78 return (-1);
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
82 79 }
83 80 (void) close(s);
84 81 if (ar.arp_flags & ATF_COM) {
85 82 bcopy(&ar.arp_ha.sa_data, node, 6);
86 83 } else
87 84 return (-1);
88 85 return (0);
89 86 }
90 87
91 88 /*
92 - * Name: get_ethernet_address
93 - *
94 - * Description: Obtains the system ethernet address.
95 - *
96 - * Returns: 0 on success, non-zero otherwise. The system ethernet
97 - * address is copied into the passed-in variable.
89 + * Fake up a valid Ethernet address based on gethostid().
90 + * This is likely to be unique to this machine, and that's
91 + * good enough for libuuid when we can't easily get our
92 + * real Ethernet address.
98 93 */
99 -int
100 -get_ethernet_address(uuid_node_t *node)
94 +static int
95 +hostid_get(uuid_node_t *node)
101 96 {
102 - walker_arg_t state;
97 + uint32_t hostid;
103 98
104 - if (arp_get(node) == 0)
105 - return (0);
99 + if ((hostid = (uint32_t)gethostid()) == 0)
100 + return (-1);
101 + hostid = htonl(hostid);
106 102
107 103 /*
108 - * Try to get physical (ethernet) address from network interfaces.
104 + * Like gen_ethernet_address(), use prefix:
105 + * 8:0:... with the multicast bit set.
109 106 */
110 - state.wa_addrvalid = B_FALSE;
111 - dlpi_walk(get_etheraddr, &state, 0);
112 - if (state.wa_addrvalid)
113 - bcopy(state.wa_etheraddr, node, state.wa_etheraddrlen);
107 + node->nodeID[0] = 0x88;
108 + node->nodeID[1] = 0x00;
109 + (void) memcpy(node->nodeID + 2, &hostid, sizeof (hostid));
114 110
115 - return (state.wa_addrvalid ? 0 : -1);
111 + return (0);
116 112 }
117 113
118 114 /*
119 - * Get the physical address via DLPI and update the flag to true upon success.
115 + * Name: get_ethernet_address
116 + *
117 + * Description: Obtains the system ethernet address, if possible.
118 + *
119 + * Returns: 0 on success, non-zero otherwise. The system ethernet
120 + * address is copied into the passed-in variable.
121 + *
122 + * Note: This does NOT need to get the REAL Ethernet address.
123 + * This library only needs something that looks like an Ethernet
124 + * address and that's likely to be unique to this machine. Also,
125 + * we really don't want to drag in libdlpi (etc) here so this just
126 + * tries an SIOCGARP ioctl, then a hostid-derived method. If all
127 + * methods here fail, the caller generates an Ethernet address.
120 128 */
121 -static boolean_t
122 -get_etheraddr(const char *linkname, void *arg)
129 +int
130 +get_ethernet_address(uuid_node_t *node)
123 131 {
124 - int retval;
125 - dlpi_handle_t dh;
126 - walker_arg_t *statep = arg;
127 132
128 - if (dlpi_open(linkname, &dh, 0) != DLPI_SUCCESS)
129 - return (B_FALSE);
133 + if (arp_get(node) == 0)
134 + return (0);
130 135
131 - statep->wa_etheraddrlen = DLPI_PHYSADDR_MAX;
132 - retval = dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR,
133 - statep->wa_etheraddr, &(statep->wa_etheraddrlen));
136 + if (hostid_get(node) == 0)
137 + return (0);
134 138
135 - dlpi_close(dh);
136 -
137 - if (retval == DLPI_SUCCESS) {
138 - statep->wa_addrvalid = B_TRUE;
139 - return (B_TRUE);
140 - }
141 - return (B_FALSE);
139 + return (-1);
142 140 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX