aboutsummaryrefslogtreecommitdiff
blob: c0be4c2396acedd815544d296146804b1b08ce7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
diff -up dhcp-4.2.2/client/dhclient.c.gpxe-cid dhcp-4.2.2/client/dhclient.c
--- dhcp-4.2.2/client/dhclient.c.gpxe-cid	2011-09-16 18:23:20.190453902 +0200
+++ dhcp-4.2.2/client/dhclient.c	2011-09-16 18:27:15.568463599 +0200
@@ -58,6 +58,13 @@ const char *path_dhclient_pid = NULL;
 static char path_dhclient_script_array[] = _PATH_DHCLIENT_SCRIPT;
 char *path_dhclient_script = path_dhclient_script_array;
 
+/* Default Prefix */
+static unsigned char default_prefix[12] = {
+	0xff, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x02, 0x00,
+	0x00, 0x02, 0xc9, 0x00
+};
+
 /* False (default) => we write and use a pid file */
 isc_boolean_t no_pid_file = ISC_FALSE;
 
@@ -1250,6 +1257,12 @@ int find_subnet (struct subnet **sp,
 static void setup_ib_interface(struct interface_info *ip)
 {
 	struct group *g;
+	struct hardware *hw = &ip->hw_address;
+	char client_id[64];
+	char *arg_conf = NULL;
+	int arg_conf_len = 0;
+	isc_result_t status;
+	struct parse *cfile = (struct parse *)0;
 
 	/* Set the broadcast flag */
 	ip->client->config->bootp_broadcast_always = 1;
@@ -1266,8 +1279,39 @@ static void setup_ib_interface(struct in
 		}
 	}
 
-	/* No client ID specified */
-	log_fatal("dhcp-client-identifier must be specified for InfiniBand");
+	/*
+	 * No client ID specified, make up one based on a default
+	 * "prefix" and the port GUID.
+	 *
+	 * NOTE: This is compatible with what gpxe does.
+	 */
+	sprintf(client_id, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
+		default_prefix[0], default_prefix[1], default_prefix[2],
+		default_prefix[3], default_prefix[4], default_prefix[5],
+		default_prefix[6], default_prefix[7], default_prefix[8],
+		default_prefix[9], default_prefix[10], default_prefix[11],
+		hw->hbuf[1], hw->hbuf[2], hw->hbuf[3], hw->hbuf[4],
+		hw->hbuf[5], hw->hbuf[6], hw->hbuf[7], hw->hbuf[8]);
+
+	arg_conf_len = asprintf(&arg_conf,
+				"send dhcp-client-identifier %s;",
+				client_id);
+
+	if ((arg_conf == 0) || (arg_conf_len <= 0))
+		log_fatal("Unable to send option dhcp-client-identifier");
+
+	status = new_parse(&cfile, -1, arg_conf, arg_conf_len,
+			   "Automatic Infiniband client identifier", 0);
+
+	if ((status != ISC_R_SUCCESS) || (cfile->warnings_occurred))
+		log_fatal("Failed to parse Infiniband client identifier");
+
+	parse_client_statement(cfile, NULL, ip->client->config);
+
+	if (cfile->warnings_occurred)
+		log_fatal("Failed to parse Infiniband client identifier");
+
+	end_parse(&cfile);
 }
 
 /* Individual States:
diff -up dhcp-4.2.2/common/lpf.c.gpxe-cid dhcp-4.2.2/common/lpf.c
--- dhcp-4.2.2/common/lpf.c.gpxe-cid	2011-09-16 18:23:20.183453996 +0200
+++ dhcp-4.2.2/common/lpf.c	2011-09-16 18:25:28.235804421 +0200
@@ -591,6 +591,37 @@ void maybe_setup_fallback ()
 	}
 }
 
+static unsigned char * get_ib_hw_addr(char * name)
+{
+	struct ifaddrs *ifaddrs;
+	struct ifaddrs *ifa;
+	struct sockaddr_ll *sll = NULL;
+	static unsigned char hw_addr[8];
+
+	if (getifaddrs(&ifaddrs) == -1)
+		return NULL;
+
+	for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
+		if (ifa->ifa_addr == NULL)
+			continue;
+		if (ifa->ifa_addr->sa_family != AF_PACKET)
+			continue;
+		if (ifa->ifa_flags & IFF_LOOPBACK)
+			continue;
+		if (strcmp(ifa->ifa_name, name) == 0) {
+			sll = (struct sockaddr_ll *)(void *)ifa->ifa_addr;
+			break;
+		}
+	}
+	if (sll == NULL) {
+		freeifaddrs(ifaddrs);
+		return NULL;
+	}
+	memcpy(hw_addr, &sll->sll_addr[sll->sll_halen - 8], 8);
+	freeifaddrs(ifaddrs);
+	return (unsigned char *)&hw_addr;
+}
+
 void
 get_hw_addr(struct interface_info *info)
 {
@@ -599,6 +630,7 @@ get_hw_addr(struct interface_info *info)
 	struct ifaddrs *ifaddrs;
 	struct ifaddrs *ifa;
 	struct sockaddr_ll *sll = NULL;
+	unsigned char *hw_addr;
 
 	if (getifaddrs(&ifaddrs) == -1)
 		log_fatal("Failed to get interfaces");
@@ -660,6 +692,10 @@ get_hw_addr(struct interface_info *info)
 
 			hw->hlen = 1;
 			hw->hbuf[0] = HTYPE_INFINIBAND;
+			hw_addr = get_ib_hw_addr(name);
+			if (!hw_addr)
+				log_fatal("Failed getting %s hw addr", name);
+			memcpy (&hw->hbuf [1], hw_addr, 8);
 			break;
 #if defined(ARPHRD_PPP)
 		case ARPHRD_PPP: