7b69e54
diff -up dhcp-4.3.1b1/client/dhclient.c.bmgpWV dhcp-4.3.1b1/client/dhclient.c
7b69e54
--- dhcp-4.3.1b1/client/dhclient.c.bmgpWV	2014-07-10 17:50:26.922402550 +0200
7b69e54
+++ dhcp-4.3.1b1/client/dhclient.c	2014-07-10 17:53:43.629623477 +0200
7b69e54
@@ -114,6 +114,8 @@ static int check_domain_name_list(const
bd3a57b
 static int check_option_values(struct universe *universe, unsigned int opt,
bd3a57b
 			       const char *ptr, size_t len);
bd3a57b
 
bd3a57b
+static void setup_ib_interface(struct interface_info *ip);
bd3a57b
+
7b69e54
 #ifndef UNIT_TEST
bd3a57b
 int
bd3a57b
 main(int argc, char **argv) {
7b69e54
@@ -937,6 +939,13 @@ main(int argc, char **argv) {
bd3a57b
 	}
bd3a57b
 	srandom(seed + cur_time + (unsigned)getpid());
bd3a57b
 
bd3a57b
+	/* Setup specific Infiniband options */
bd3a57b
+	for (ip = interfaces; ip; ip = ip->next) {
bd3a57b
+		if (ip->client &&
bd3a57b
+		    (ip->hw_address.hbuf[0] == HTYPE_INFINIBAND)) {
bd3a57b
+			setup_ib_interface(ip);
bd3a57b
+		}
bd3a57b
+	}
e83fb19
 
e83fb19
 	/*
e83fb19
 	 * Establish a default DUID.  We always do so for v6 and
7b69e54
@@ -1230,6 +1239,29 @@ int find_subnet (struct subnet **sp,
bd3a57b
 	return 0;
bd3a57b
 }
bd3a57b
 
bd3a57b
+static void setup_ib_interface(struct interface_info *ip)
bd3a57b
+{
bd3a57b
+	struct group *g;
bd3a57b
+
bd3a57b
+	/* Set the broadcast flag */
bd3a57b
+	ip->client->config->bootp_broadcast_always = 1;
bd3a57b
+
bd3a57b
+	/*
bd3a57b
+	 * Find out if a dhcp-client-identifier option was specified either
bd3a57b
+	 * in the config file or on the command line
bd3a57b
+	 */
bd3a57b
+	for (g = ip->client->config->on_transmission; g != NULL; g = g->next) {
bd3a57b
+		if ((g->statements != NULL) &&
bd3a57b
+		    (strcmp(g->statements->data.option->option->name,
bd3a57b
+			    "dhcp-client-identifier") == 0)) {
bd3a57b
+			return;
bd3a57b
+		}
bd3a57b
+	}
bd3a57b
+
bd3a57b
+	/* No client ID specified */
bd3a57b
+	log_fatal("dhcp-client-identifier must be specified for InfiniBand");
bd3a57b
+}
bd3a57b
+
bd3a57b
 /* Individual States:
bd3a57b
  *
bd3a57b
  * Each routine is called from the dhclient_state_machine() in one of
7b69e54
diff -up dhcp-4.3.1b1/common/bpf.c.bmgpWV dhcp-4.3.1b1/common/bpf.c
7b69e54
--- dhcp-4.3.1b1/common/bpf.c.bmgpWV	2014-07-10 17:48:03.797424616 +0200
7b69e54
+++ dhcp-4.3.1b1/common/bpf.c	2014-07-10 17:52:57.705272295 +0200
e83fb19
@@ -199,11 +199,44 @@ struct bpf_insn dhcp_bpf_filter [] = {
bd3a57b
 	BPF_STMT(BPF_RET+BPF_K, 0),
bd3a57b
 };
bd3a57b
 
bd3a57b
+/* Packet filter program for DHCP over Infiniband.
bd3a57b
+ *
bd3a57b
+ * XXX
bd3a57b
+ * Changes to the filter program may require changes to the constant offsets
bd3a57b
+ * used in lpf_gen_filter_setup to patch the port in the BPF program!
bd3a57b
+ * XXX
bd3a57b
+ */
bd3a57b
+struct bpf_insn dhcp_ib_bpf_filter [] = {
bd3a57b
+	/* Packet filter for Infiniband */
bd3a57b
+	/* Make sure it's a UDP packet... */
bd3a57b
+	BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 9),
bd3a57b
+	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6),
bd3a57b
+
bd3a57b
+	/* Make sure this isn't a fragment... */
bd3a57b
+	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 6),
bd3a57b
+	BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0),
bd3a57b
+
bd3a57b
+	/* Get the IP header length... */
bd3a57b
+	BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 0),
bd3a57b
+
bd3a57b
+	/* Make sure it's to the right port... */
bd3a57b
+	BPF_STMT(BPF_LD + BPF_H + BPF_IND, 2),
bd3a57b
+	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1),
bd3a57b
+
bd3a57b
+	/* If we passed all the tests, ask for the whole packet. */
bd3a57b
+	BPF_STMT(BPF_RET + BPF_K, (u_int)-1),
bd3a57b
+
bd3a57b
+	/* Otherwise, drop it. */
bd3a57b
+	BPF_STMT(BPF_RET + BPF_K, 0),
bd3a57b
+};
bd3a57b
+
bd3a57b
 #if defined (DEC_FDDI)
bd3a57b
 struct bpf_insn *bpf_fddi_filter;
bd3a57b
 #endif
bd3a57b
 
bd3a57b
 int dhcp_bpf_filter_len = sizeof dhcp_bpf_filter / sizeof (struct bpf_insn);
bd3a57b
+int dhcp_ib_bpf_filter_len = sizeof dhcp_ib_bpf_filter / sizeof (struct bpf_insn);
bd3a57b
+
bd3a57b
 #if defined (HAVE_TR_SUPPORT)
bd3a57b
 struct bpf_insn dhcp_bpf_tr_filter [] = {
bd3a57b
         /* accept all token ring packets due to variable length header */
7b69e54
diff -up dhcp-4.3.1b1/common/lpf.c.bmgpWV dhcp-4.3.1b1/common/lpf.c
7b69e54
--- dhcp-4.3.1b1/common/lpf.c.bmgpWV	2014-07-10 17:48:03.797424616 +0200
7b69e54
+++ dhcp-4.3.1b1/common/lpf.c	2014-07-10 17:52:57.706272281 +0200
e83fb19
@@ -46,6 +46,17 @@
e83fb19
 #if defined (USE_LPF_RECEIVE) || defined (USE_LPF_HWADDR)
e83fb19
 #include <sys/ioctl.h>
bd3a57b
 #include <net/if.h>
bd3a57b
+#include <ifaddrs.h>
e83fb19
+
bd3a57b
+/* Default broadcast address for IPoIB */
bd3a57b
+static unsigned char default_ib_bcast_addr[20] = {
bd3a57b
+ 	0x00, 0xff, 0xff, 0xff,
bd3a57b
+	0xff, 0x12, 0x40, 0x1b,
bd3a57b
+	0x00, 0x00, 0x00, 0x00,
bd3a57b
+	0x00, 0x00, 0x00, 0x00,
bd3a57b
+	0xff, 0xff, 0xff, 0xff
bd3a57b
+};
bd3a57b
+
e83fb19
 #endif
e83fb19
 
e83fb19
 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
e83fb19
@@ -92,10 +103,21 @@ int if_register_lpf (info)
bd3a57b
 		struct sockaddr common;
bd3a57b
 	} sa;
bd3a57b
 	struct ifreq ifr;
bd3a57b
+	int type;
bd3a57b
+	int protocol;
bd3a57b
 
bd3a57b
 	/* Make an LPF socket. */
bd3a57b
-	if ((sock = socket(PF_PACKET, SOCK_RAW,
bd3a57b
-			   htons((short)ETH_P_ALL))) < 0) {
bd3a57b
+	get_hw_addr(info);
bd3a57b
+
bd3a57b
+	if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
bd3a57b
+		type = SOCK_DGRAM;
bd3a57b
+		protocol = ETHERTYPE_IP;
bd3a57b
+	} else {
bd3a57b
+		type = SOCK_RAW;
bd3a57b
+		protocol = ETH_P_ALL;
bd3a57b
+	}
bd3a57b
+
bd3a57b
+	if ((sock = socket(PF_PACKET, type, htons((short)protocol))) < 0) {
bd3a57b
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
bd3a57b
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
bd3a57b
 		    errno == EAFNOSUPPORT || errno == EINVAL) {
e83fb19
@@ -118,6 +140,7 @@ int if_register_lpf (info)
bd3a57b
 	/* Bind to the interface name */
bd3a57b
 	memset (&sa, 0, sizeof sa);
bd3a57b
 	sa.ll.sll_family = AF_PACKET;
bd3a57b
+	sa.ll.sll_protocol = htons(protocol);
bd3a57b
 	sa.ll.sll_ifindex = ifr.ifr_ifindex;
bd3a57b
 	if (bind (sock, &sa.common, sizeof sa)) {
bd3a57b
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
e83fb19
@@ -133,8 +156,6 @@ int if_register_lpf (info)
bd3a57b
 		log_fatal ("Bind socket to interface: %m");
bd3a57b
 	}
bd3a57b
 
bd3a57b
-	get_hw_addr(info->name, &info->hw_address);
bd3a57b
-
bd3a57b
 	return sock;
bd3a57b
 }
bd3a57b
 #endif /* USE_LPF_SEND || USE_LPF_RECEIVE */
e83fb19
@@ -189,6 +210,8 @@ void if_deregister_send (info)
bd3a57b
    in bpf includes... */
bd3a57b
 extern struct sock_filter dhcp_bpf_filter [];
bd3a57b
 extern int dhcp_bpf_filter_len;
bd3a57b
+extern struct sock_filter dhcp_ib_bpf_filter [];
bd3a57b
+extern int dhcp_ib_bpf_filter_len;
bd3a57b
 
bd3a57b
 #if defined (HAVE_TR_SUPPORT)
bd3a57b
 extern struct sock_filter dhcp_bpf_tr_filter [];
e83fb19
@@ -206,11 +229,13 @@ void if_register_receive (info)
bd3a57b
 	/* Open a LPF device and hang it on this interface... */
bd3a57b
 	info -> rfdesc = if_register_lpf (info);
bd3a57b
 
bd3a57b
-	val = 1;
bd3a57b
-	if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
bd3a57b
-			sizeof val) < 0) {
bd3a57b
-		if (errno != ENOPROTOOPT)
bd3a57b
-			log_fatal ("Failed to set auxiliary packet data: %m");
bd3a57b
+	if (info->hw_address.hbuf[0] != HTYPE_INFINIBAND) {
bd3a57b
+		val = 1;
bd3a57b
+		if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA,
bd3a57b
+				&val, sizeof val) < 0) {
bd3a57b
+			if (errno != ENOPROTOOPT)
bd3a57b
+				log_fatal ("Failed to set auxiliary packet data: %m");
bd3a57b
+		}
bd3a57b
 	}
bd3a57b
 
bd3a57b
 #if defined (HAVE_TR_SUPPORT)
e83fb19
@@ -256,15 +281,28 @@ static void lpf_gen_filter_setup (info)
bd3a57b
 
bd3a57b
 	memset(&p, 0, sizeof(p));
bd3a57b
 
bd3a57b
-	/* Set up the bpf filter program structure.    This is defined in
bd3a57b
-	   bpf.c */
bd3a57b
-	p.len = dhcp_bpf_filter_len;
bd3a57b
-	p.filter = dhcp_bpf_filter;
bd3a57b
-
bd3a57b
-        /* Patch the server port into the LPF  program...
bd3a57b
-	   XXX changes to filter program may require changes
bd3a57b
-	   to the insn number(s) used below! XXX */
bd3a57b
-	dhcp_bpf_filter [8].k = ntohs ((short)local_port);
bd3a57b
+	if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
bd3a57b
+		/* Set up the bpf filter program structure. */
bd3a57b
+		p.len = dhcp_ib_bpf_filter_len;
bd3a57b
+		p.filter = dhcp_ib_bpf_filter;
bd3a57b
+
bd3a57b
+		/* Patch the server port into the LPF program...
bd3a57b
+		   XXX
bd3a57b
+		   changes to filter program may require changes
bd3a57b
+		   to the insn number(s) used below!
bd3a57b
+		   XXX */
bd3a57b
+		dhcp_ib_bpf_filter[6].k = ntohs ((short)local_port);
bd3a57b
+	} else {
bd3a57b
+		/* Set up the bpf filter program structure.
bd3a57b
+		   This is defined in bpf.c */
bd3a57b
+		p.len = dhcp_bpf_filter_len;
bd3a57b
+		p.filter = dhcp_bpf_filter;
bd3a57b
+
bd3a57b
+		/* Patch the server port into the LPF  program...
bd3a57b
+		   XXX changes to filter program may require changes
bd3a57b
+		   to the insn number(s) used below! XXX */
bd3a57b
+		dhcp_bpf_filter [8].k = ntohs ((short)local_port);
bd3a57b
+	}
bd3a57b
 
bd3a57b
 	if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
bd3a57b
 			sizeof p) < 0) {
e83fb19
@@ -321,6 +359,54 @@ static void lpf_tr_filter_setup (info)
bd3a57b
 #endif /* USE_LPF_RECEIVE */
bd3a57b
 
bd3a57b
 #ifdef USE_LPF_SEND
bd3a57b
+ssize_t send_packet_ib(interface, packet, raw, len, from, to, hto)
bd3a57b
+	struct interface_info *interface;
bd3a57b
+	struct packet *packet;
bd3a57b
+	struct dhcp_packet *raw;
bd3a57b
+	size_t len;
bd3a57b
+	struct in_addr from;
bd3a57b
+	struct sockaddr_in *to;
bd3a57b
+	struct hardware *hto;
bd3a57b
+{
bd3a57b
+	unsigned ibufp = 0;
bd3a57b
+	double ih [1536 / sizeof (double)];
bd3a57b
+	unsigned char *buf = (unsigned char *)ih;
bd3a57b
+	ssize_t result;
bd3a57b
+
bd3a57b
+	union sockunion {
bd3a57b
+		struct sockaddr sa;
bd3a57b
+		struct sockaddr_ll sll;
bd3a57b
+		struct sockaddr_storage ss;
bd3a57b
+	} su;
bd3a57b
+
bd3a57b
+	assemble_udp_ip_header (interface, buf, &ibufp, from.s_addr,
bd3a57b
+				to->sin_addr.s_addr, to->sin_port,
bd3a57b
+				(unsigned char *)raw, len);
bd3a57b
+	memcpy (buf + ibufp, raw, len);
bd3a57b
+
bd3a57b
+	memset(&su, 0, sizeof(su));
bd3a57b
+	su.sll.sll_family = AF_PACKET;
bd3a57b
+	su.sll.sll_protocol = htons(ETHERTYPE_IP);
bd3a57b
+
bd3a57b
+	if (!(su.sll.sll_ifindex = if_nametoindex(interface->name))) {
bd3a57b
+		errno = ENOENT;
bd3a57b
+		log_error ("send_packet_ib: %m - failed to get if index");
bd3a57b
+		return -1;
bd3a57b
+	}
bd3a57b
+
bd3a57b
+	su.sll.sll_hatype = htons(HTYPE_INFINIBAND);
bd3a57b
+	su.sll.sll_halen = sizeof(interface->bcast_addr);
bd3a57b
+	memcpy(&su.sll.sll_addr, interface->bcast_addr, 20);
bd3a57b
+
bd3a57b
+	result = sendto(interface->wfdesc, buf, ibufp + len, 0,
bd3a57b
+			&su.sa, sizeof(su));
bd3a57b
+
bd3a57b
+	if (result < 0)
bd3a57b
+		log_error ("send_packet_ib: %m");
bd3a57b
+
bd3a57b
+	return result;
bd3a57b
+}
bd3a57b
+
bd3a57b
 ssize_t send_packet (interface, packet, raw, len, from, to, hto)
bd3a57b
 	struct interface_info *interface;
bd3a57b
 	struct packet *packet;
e83fb19
@@ -341,6 +427,11 @@ ssize_t send_packet (interface, packet,
bd3a57b
 		return send_fallback (interface, packet, raw,
bd3a57b
 				      len, from, to, hto);
bd3a57b
 
bd3a57b
+	if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
bd3a57b
+		return send_packet_ib(interface, packet, raw, len, from,
bd3a57b
+				      to, hto);
bd3a57b
+	}
bd3a57b
+
bd3a57b
 	if (hto == NULL && interface->anycast_mac_addr.hlen)
bd3a57b
 		hto = &interface->anycast_mac_addr;
bd3a57b
 
e83fb19
@@ -362,6 +453,42 @@ ssize_t send_packet (interface, packet,
bd3a57b
 #endif /* USE_LPF_SEND */
bd3a57b
 
bd3a57b
 #ifdef USE_LPF_RECEIVE
bd3a57b
+ssize_t receive_packet_ib (interface, buf, len, from, hfrom)
bd3a57b
+	struct interface_info *interface;
bd3a57b
+	unsigned char *buf;
bd3a57b
+	size_t len;
bd3a57b
+	struct sockaddr_in *from;
bd3a57b
+	struct hardware *hfrom;
bd3a57b
+{
bd3a57b
+	int length = 0;
bd3a57b
+	int offset = 0;
bd3a57b
+	unsigned char ibuf [1536];
bd3a57b
+	unsigned bufix = 0;
bd3a57b
+	unsigned paylen;
bd3a57b
+
bd3a57b
+	length = read(interface->rfdesc, ibuf, sizeof(ibuf));
bd3a57b
+
bd3a57b
+	if (length <= 0)
bd3a57b
+		return length;
bd3a57b
+
bd3a57b
+	offset = decode_udp_ip_header(interface, ibuf, bufix, from,
bd3a57b
+				       (unsigned)length, &paylen, 0);
bd3a57b
+
bd3a57b
+	if (offset < 0)
bd3a57b
+		return 0;
bd3a57b
+
bd3a57b
+	bufix += offset;
bd3a57b
+	length -= offset;
bd3a57b
+
bd3a57b
+	if (length < paylen)
bd3a57b
+		log_fatal("Internal inconsistency at %s:%d.", MDL);
bd3a57b
+
bd3a57b
+	/* Copy out the data in the packet... */
bd3a57b
+	memcpy(buf, &ibuf[bufix], paylen);
bd3a57b
+
bd3a57b
+	return (ssize_t)paylen;
bd3a57b
+}
bd3a57b
+
bd3a57b
 ssize_t receive_packet (interface, buf, len, from, hfrom)
bd3a57b
 	struct interface_info *interface;
bd3a57b
 	unsigned char *buf;
e83fb19
@@ -388,6 +515,10 @@ ssize_t receive_packet (interface, buf,
bd3a57b
 	};
bd3a57b
 	struct cmsghdr *cmsg;
bd3a57b
 
bd3a57b
+	if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
bd3a57b
+		return receive_packet_ib(interface, buf, len, from, hfrom);
bd3a57b
+	}
bd3a57b
+
bd3a57b
 	length = recvmsg (interface -> rfdesc, &msg, 0);
bd3a57b
 	if (length <= 0)
bd3a57b
 		return length;
e83fb19
@@ -469,11 +600,33 @@ void maybe_setup_fallback ()
e83fb19
 #endif
bd3a57b
 
e83fb19
 #if defined (USE_LPF_RECEIVE) || defined (USE_LPF_HWADDR)
ac22d37
-void
bd3a57b
-get_hw_addr(const char *name, struct hardware *hw) {
ac22d37
+struct sockaddr_ll *
ac22d37
+get_ll (struct ifaddrs *ifaddrs, struct ifaddrs **ifa, char *name)
bd3a57b
+{
ac22d37
+	for (*ifa = ifaddrs; *ifa != NULL; *ifa = (*ifa)->ifa_next) {
ac22d37
+		if ((*ifa)->ifa_addr == NULL)
ac22d37
+			continue;
cd552e5
+
ac22d37
+		if ((*ifa)->ifa_addr->sa_family != AF_PACKET)
ac22d37
+			continue;
ac22d37
+
ac22d37
+		if ((*ifa)->ifa_flags & IFF_LOOPBACK)
ac22d37
+			continue;
cd552e5
+
ac22d37
+		if (strcmp((*ifa)->ifa_name, name) == 0)
47fd457
+			return (struct sockaddr_ll *)(void *)(*ifa)->ifa_addr;
cd552e5
+	}
63fcbf9
+	*ifa = NULL;
ac22d37
+	return NULL;
ac22d37
+}
cd552e5
+
cd552e5
+struct sockaddr_ll *
cd552e5
+ioctl_get_ll(char *name)
cd552e5
+{
cd552e5
 	int sock;
cd552e5
 	struct ifreq tmp;
cd552e5
-	struct sockaddr *sa;
cd552e5
+	struct sockaddr *sa = NULL;
cd552e5
+	struct sockaddr_ll *sll = NULL;
bd3a57b
 
cd552e5
 	if (strlen(name) >= sizeof(tmp.ifr_name)) {
cd552e5
 		log_fatal("Device name too long: \"%s\"", name);
e83fb19
@@ -487,16 +640,62 @@ get_hw_addr(const char *name, struct har
cd552e5
 	memset(&tmp, 0, sizeof(tmp));
cd552e5
 	strcpy(tmp.ifr_name, name);
cd552e5
 	if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) {
bd3a57b
-		log_fatal("Error getting hardware address for \"%s\": %m", 
cd552e5
+		log_fatal("Error getting hardware address for \"%s\": %m",
cd552e5
 			  name);
cd552e5
 	}
344e293
+	close(sock);
cd552e5
 
cd552e5
 	sa = &tmp.ifr_hwaddr;
cd552e5
-	switch (sa->sa_family) {
344e293
+	// needs to be freed outside this function
cd552e5
+	sll = dmalloc (sizeof (struct sockaddr_ll), MDL);
cd552e5
+	if (!sll)
cd552e5
+		log_fatal("Unable to allocate memory for link layer address");
cd552e5
+	memcpy(&sll->sll_hatype, &sa->sa_family, sizeof (sll->sll_hatype));
cd552e5
+	memcpy(sll->sll_addr, sa->sa_data, sizeof (sll->sll_addr));
63fcbf9
+	switch (sll->sll_hatype) {
63fcbf9
+		case ARPHRD_INFINIBAND:
63fcbf9
+			/* ioctl limits hardware addresses to 8 bytes */
63fcbf9
+			sll->sll_halen = 8;
63fcbf9
+			break;
63fcbf9
+		default:
63fcbf9
+			break;
63fcbf9
+	}
cd552e5
+	return sll;
cd552e5
+}
cd552e5
+
ac22d37
+void
ac22d37
+get_hw_addr(struct interface_info *info)
ac22d37
+{
ac22d37
+	struct hardware *hw = &info->hw_address;
ac22d37
+	char *name = info->name;
ac22d37
+	struct ifaddrs *ifaddrs = NULL;
ac22d37
+	struct ifaddrs *ifa = NULL;
ac22d37
+	struct sockaddr_ll *sll = NULL;
344e293
+	int sll_allocated = 0;
63fcbf9
+	char *dup = NULL;
63fcbf9
+	char *colon = NULL;
ac22d37
+
ac22d37
+	if (getifaddrs(&ifaddrs) == -1)
ac22d37
+		log_fatal("Failed to get interfaces");
ac22d37
+
ac22d37
+	if ((sll = get_ll(ifaddrs, &ifa, name)) == NULL) {
ac22d37
+		/*
ac22d37
+		 * We were unable to get link-layer address for name.
cd552e5
+		 * Fall back to ioctl(SIOCGIFHWADDR).
ac22d37
+		 */
cd552e5
+		sll = ioctl_get_ll(name);
344e293
+		if (sll != NULL)
344e293
+			sll_allocated = 1;
344e293
+		else
63fcbf9
+			// shouldn't happen
344e293
+			log_fatal("Unexpected internal error");
cd552e5
+	}
cd552e5
+
bd3a57b
+	switch (sll->sll_hatype) {
bd3a57b
 		case ARPHRD_ETHER:
bd3a57b
 			hw->hlen = 7;
bd3a57b
 			hw->hbuf[0] = HTYPE_ETHER;
bd3a57b
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
bd3a57b
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
bd3a57b
 			break;
bd3a57b
 		case ARPHRD_IEEE802:
bd3a57b
 #ifdef ARPHRD_IEEE802_TR
e83fb19
@@ -504,18 +703,48 @@ get_hw_addr(const char *name, struct har
bd3a57b
 #endif /* ARPHRD_IEEE802_TR */
bd3a57b
 			hw->hlen = 7;
bd3a57b
 			hw->hbuf[0] = HTYPE_IEEE802;
bd3a57b
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
bd3a57b
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
bd3a57b
 			break;
bd3a57b
 		case ARPHRD_FDDI:
c72a792
 			hw->hlen = 7;
bd3a57b
 			hw->hbuf[0] = HTYPE_FDDI;
c72a792
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
c72a792
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
bd3a57b
+			break;
bd3a57b
+		case ARPHRD_INFINIBAND:
63fcbf9
+			dup = strdup(name);
63fcbf9
+			/* Aliased infiniband interface is special case where
63fcbf9
+			 * neither get_ll() nor ioctl_get_ll() get's correct hw
63fcbf9
+			 * address, so we have to truncate the :0 and run
63fcbf9
+			 * get_ll() again for the rest.
63fcbf9
+			*/
63fcbf9
+			if ((colon = strchr(dup, ':')) != NULL) {
63fcbf9
+				*colon = '\0';
63fcbf9
+				if ((sll = get_ll(ifaddrs, &ifa, dup)) == NULL)
63fcbf9
+					log_fatal("Error getting hardware address for \"%s\": %m", name);
63fcbf9
+			}
63fcbf9
+			free (dup);
bd3a57b
+			/* For Infiniband, save the broadcast address and store
bd3a57b
+			 * the port GUID into the hardware address.
bd3a57b
+			 */
63fcbf9
+			if (ifa && (ifa->ifa_flags & IFF_BROADCAST)) {
bd3a57b
+				struct sockaddr_ll *bll;
bd3a57b
+
bd3a57b
+				bll = (struct sockaddr_ll *)ifa->ifa_broadaddr;
bd3a57b
+				memcpy(&info->bcast_addr, bll->sll_addr, 20);
bd3a57b
+			} else {
bd3a57b
+				memcpy(&info->bcast_addr, default_ib_bcast_addr,
bd3a57b
+				       20);
bd3a57b
+			}
bd3a57b
+
bd3a57b
+			hw->hlen = 1;
bd3a57b
+			hw->hbuf[0] = HTYPE_INFINIBAND;
63fcbf9
+			memcpy(&hw->hbuf[1], &sll->sll_addr[sll->sll_halen - 8], 8);
bd3a57b
 			break;
bd3a57b
 #if defined(ARPHRD_PPP)
bd3a57b
 		case ARPHRD_PPP:
bd3a57b
 			if (local_family != AF_INET6)
bd3a57b
-				log_fatal("Unsupported device type %d for \"%s\"",
bd3a57b
-				           sa->sa_family, name);
cd552e5
+				log_fatal("local_family != AF_INET6 for \"%s\"",
cd552e5
+					  name);
bd3a57b
 			hw->hlen = 0;
bd3a57b
 			hw->hbuf[0] = HTYPE_RESERVED;
bd3a57b
 			/* 0xdeadbeef should never occur on the wire,
e83fb19
@@ -528,10 +757,13 @@ get_hw_addr(const char *name, struct har
bd3a57b
 			break;
bd3a57b
 #endif
bd3a57b
 		default:
cd552e5
-			log_fatal("Unsupported device type %ld for \"%s\"",
bd3a57b
-				  (long int)sa->sa_family, name);
cd552e5
+			freeifaddrs(ifaddrs);
24a2f1a
+			log_fatal("Unsupported device type %hu for \"%s\"",
cd552e5
+				  sll->sll_hatype, name);
bd3a57b
 	}
bd3a57b
 
bd3a57b
-	close(sock);
344e293
+	if (sll_allocated)
344e293
+		dfree(sll, MDL);
bd3a57b
+	freeifaddrs(ifaddrs);
bd3a57b
 }
bd3a57b
 #endif
7b69e54
diff -up dhcp-4.3.1b1/common/socket.c.bmgpWV dhcp-4.3.1b1/common/socket.c
7b69e54
--- dhcp-4.3.1b1/common/socket.c.bmgpWV	2014-07-02 19:58:38.000000000 +0200
7b69e54
+++ dhcp-4.3.1b1/common/socket.c	2014-07-10 17:52:57.706272281 +0200
7b69e54
@@ -322,7 +322,7 @@ void if_register_send (info)
e83fb19
 	info->wfdesc = if_register_socket(info, AF_INET, 0, NULL);
bd3a57b
 	/* If this is a normal IPv4 address, get the hardware address. */
bd3a57b
 	if (strcmp(info->name, "fallback") != 0)
bd3a57b
-		get_hw_addr(info->name, &info->hw_address);
bd3a57b
+		get_hw_addr(info);
bd3a57b
 #if defined (USE_SOCKET_FALLBACK)
bd3a57b
 	/* Fallback only registers for send, but may need to receive as
bd3a57b
 	   well. */
7b69e54
@@ -385,7 +385,7 @@ void if_register_receive (info)
bd3a57b
 #endif /* IP_PKTINFO... */
bd3a57b
 	/* If this is a normal IPv4 address, get the hardware address. */
bd3a57b
 	if (strcmp(info->name, "fallback") != 0)
bd3a57b
-		get_hw_addr(info->name, &info->hw_address);
bd3a57b
+		get_hw_addr(info);
bd3a57b
 
bd3a57b
 	if (!quiet_interface_discovery)
bd3a57b
 		log_info ("Listening on Socket/%s%s%s",
7b69e54
@@ -499,7 +499,7 @@ if_register6(struct interface_info *info
bd3a57b
 	if (req_multi)
bd3a57b
 		if_register_multicast(info);
bd3a57b
 
bd3a57b
-	get_hw_addr(info->name, &info->hw_address);
bd3a57b
+	get_hw_addr(info);
bd3a57b
 
bd3a57b
 	if (!quiet_interface_discovery) {
bd3a57b
 		if (info->shared_network != NULL) {
7b69e54
@@ -555,7 +555,7 @@ if_register_linklocal6(struct interface_
e83fb19
 	info->rfdesc = sock;
e83fb19
 	info->wfdesc = sock;
e83fb19
 
e83fb19
-	get_hw_addr(info->name, &info->hw_address);
e83fb19
+	get_hw_addr(info);
e83fb19
 
e83fb19
 	if (!quiet_interface_discovery) {
e83fb19
 		if (info->shared_network != NULL) {
7b69e54
diff -up dhcp-4.3.1b1/includes/dhcpd.h.bmgpWV dhcp-4.3.1b1/includes/dhcpd.h
7b69e54
--- dhcp-4.3.1b1/includes/dhcpd.h.bmgpWV	2014-07-10 17:50:26.923402536 +0200
7b69e54
+++ dhcp-4.3.1b1/includes/dhcpd.h	2014-07-10 17:52:57.707272266 +0200
7b69e54
@@ -1248,6 +1248,7 @@ struct interface_info {
bd3a57b
 	struct shared_network *shared_network;
bd3a57b
 				/* Networks connected to this interface. */
bd3a57b
 	struct hardware hw_address;	/* Its physical address. */
bd3a57b
+	u_int8_t bcast_addr[20];	/* Infiniband broadcast address */
bd3a57b
 	struct in_addr *addresses;	/* Addresses associated with this
bd3a57b
 					 * interface.
bd3a57b
 					 */
7b69e54
@@ -2439,7 +2440,7 @@ void print_dns_status (int, struct dhcp_
bd3a57b
 #endif
bd3a57b
 const char *print_time(TIME);
bd3a57b
 
bd3a57b
-void get_hw_addr(const char *name, struct hardware *hw);
bd3a57b
+void get_hw_addr(struct interface_info *info);
bd3a57b
 
bd3a57b
 /* socket.c */
bd3a57b
 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \