Blame SOURCES/dhcp-4.2.5-lpf-ib.patch

54343e
diff -up dhcp-4.2.5/client/dhclient.c.lpf-ib dhcp-4.2.5/client/dhclient.c
54343e
--- dhcp-4.2.5/client/dhclient.c.lpf-ib	2015-06-05 16:18:03.387948658 +0200
54343e
+++ dhcp-4.2.5/client/dhclient.c	2015-06-05 16:18:03.391948646 +0200
54343e
@@ -113,6 +113,8 @@ static int check_domain_name_list(const
54343e
 static int check_option_values(struct universe *universe, unsigned int opt,
54343e
 			       const char *ptr, size_t len);
54343e
 
54343e
+static void setup_ib_interface(struct interface_info *ip);
54343e
+
54343e
 int
54343e
 main(int argc, char **argv) {
54343e
 	int fd;
54343e
@@ -909,6 +911,14 @@ main(int argc, char **argv) {
54343e
 	}
54343e
 	srandom(seed + cur_time + (unsigned)getpid());
54343e
 
54343e
+	/* Setup specific Infiniband options */
54343e
+	for (ip = interfaces; ip; ip = ip->next) {
54343e
+		if (ip->client &&
54343e
+		    (ip->hw_address.hbuf[0] == HTYPE_INFINIBAND)) {
54343e
+			setup_ib_interface(ip);
54343e
+		}
54343e
+	}
54343e
+
54343e
 	/* Start a configuration state machine for each interface. */
54343e
 #ifdef DHCPv6
54343e
 	if (local_family == AF_INET6) {
54343e
@@ -1185,6 +1195,29 @@ int find_subnet (struct subnet **sp,
54343e
 	return 0;
54343e
 }
54343e
 
54343e
+static void setup_ib_interface(struct interface_info *ip)
54343e
+{
54343e
+	struct group *g;
54343e
+
54343e
+	/* Set the broadcast flag */
54343e
+	ip->client->config->bootp_broadcast_always = 1;
54343e
+
54343e
+	/*
54343e
+	 * Find out if a dhcp-client-identifier option was specified either
54343e
+	 * in the config file or on the command line
54343e
+	 */
54343e
+	for (g = ip->client->config->on_transmission; g != NULL; g = g->next) {
54343e
+		if ((g->statements != NULL) &&
54343e
+		    (strcmp(g->statements->data.option->option->name,
54343e
+			    "dhcp-client-identifier") == 0)) {
54343e
+			return;
54343e
+		}
54343e
+	}
54343e
+
54343e
+	/* No client ID specified */
54343e
+	log_fatal("dhcp-client-identifier must be specified for InfiniBand");
54343e
+}
54343e
+
54343e
 /* Individual States:
54343e
  *
54343e
  * Each routine is called from the dhclient_state_machine() in one of
54343e
diff -up dhcp-4.2.5/common/bpf.c.lpf-ib dhcp-4.2.5/common/bpf.c
54343e
--- dhcp-4.2.5/common/bpf.c.lpf-ib	2015-06-05 16:18:03.384948667 +0200
54343e
+++ dhcp-4.2.5/common/bpf.c	2015-06-05 16:18:03.392948643 +0200
54343e
@@ -198,11 +198,44 @@ struct bpf_insn dhcp_bpf_filter [] = {
54343e
 	BPF_STMT(BPF_RET+BPF_K, 0),
54343e
 };
54343e
 
54343e
+/* Packet filter program for DHCP over Infiniband.
54343e
+ *
54343e
+ * XXX
54343e
+ * Changes to the filter program may require changes to the constant offsets
54343e
+ * used in lpf_gen_filter_setup to patch the port in the BPF program!
54343e
+ * XXX
54343e
+ */
54343e
+struct bpf_insn dhcp_ib_bpf_filter [] = {
54343e
+	/* Packet filter for Infiniband */
54343e
+	/* Make sure it's a UDP packet... */
54343e
+	BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 9),
54343e
+	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6),
54343e
+
54343e
+	/* Make sure this isn't a fragment... */
54343e
+	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 6),
54343e
+	BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0),
54343e
+
54343e
+	/* Get the IP header length... */
54343e
+	BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 0),
54343e
+
54343e
+	/* Make sure it's to the right port... */
54343e
+	BPF_STMT(BPF_LD + BPF_H + BPF_IND, 2),
54343e
+	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1),
54343e
+
54343e
+	/* If we passed all the tests, ask for the whole packet. */
54343e
+	BPF_STMT(BPF_RET + BPF_K, (u_int)-1),
54343e
+
54343e
+	/* Otherwise, drop it. */
54343e
+	BPF_STMT(BPF_RET + BPF_K, 0),
54343e
+};
54343e
+
54343e
 #if defined (DEC_FDDI)
54343e
 struct bpf_insn *bpf_fddi_filter;
54343e
 #endif
54343e
 
54343e
 int dhcp_bpf_filter_len = sizeof dhcp_bpf_filter / sizeof (struct bpf_insn);
54343e
+int dhcp_ib_bpf_filter_len = sizeof dhcp_ib_bpf_filter / sizeof (struct bpf_insn);
54343e
+
54343e
 #if defined (HAVE_TR_SUPPORT)
54343e
 struct bpf_insn dhcp_bpf_tr_filter [] = {
54343e
         /* accept all token ring packets due to variable length header */
54343e
diff -up dhcp-4.2.5/common/lpf.c.lpf-ib dhcp-4.2.5/common/lpf.c
54343e
--- dhcp-4.2.5/common/lpf.c.lpf-ib	2015-06-05 16:18:03.384948667 +0200
54343e
+++ dhcp-4.2.5/common/lpf.c	2015-06-05 16:33:15.183955199 +0200
54343e
@@ -43,6 +43,7 @@
54343e
 #include "includes/netinet/udp.h"
54343e
 #include "includes/netinet/if_ether.h"
54343e
 #include <net/if.h>
54343e
+#include <ifaddrs.h>
54343e
 
54343e
 #ifndef PACKET_AUXDATA
54343e
 #define PACKET_AUXDATA 8
54343e
@@ -60,6 +61,15 @@ struct tpacket_auxdata
54343e
 /* Reinitializes the specified interface after an address change.   This
54343e
    is not required for packet-filter APIs. */
54343e
 
54343e
+/* Default broadcast address for IPoIB */
54343e
+static unsigned char default_ib_bcast_addr[20] = {
54343e
+ 	0x00, 0xff, 0xff, 0xff,
54343e
+	0xff, 0x12, 0x40, 0x1b,
54343e
+	0x00, 0x00, 0x00, 0x00,
54343e
+	0x00, 0x00, 0x00, 0x00,
54343e
+	0xff, 0xff, 0xff, 0xff
54343e
+};
54343e
+
54343e
 #ifdef USE_LPF_SEND
54343e
 void if_reinitialize_send (info)
54343e
 	struct interface_info *info;
54343e
@@ -87,10 +97,21 @@ int if_register_lpf (info)
54343e
 		struct sockaddr common;
54343e
 	} sa;
54343e
 	struct ifreq ifr;
54343e
+	int type;
54343e
+	int protocol;
54343e
 
54343e
 	/* Make an LPF socket. */
54343e
-	if ((sock = socket(PF_PACKET, SOCK_RAW,
54343e
-			   htons((short)ETH_P_ALL))) < 0) {
54343e
+	get_hw_addr(info);
54343e
+
54343e
+	if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
54343e
+		type = SOCK_DGRAM;
54343e
+		protocol = ETHERTYPE_IP;
54343e
+	} else {
54343e
+		type = SOCK_RAW;
54343e
+		protocol = ETH_P_ALL;
54343e
+	}
54343e
+
54343e
+	if ((sock = socket(PF_PACKET, type, htons((short)protocol))) < 0) {
54343e
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
54343e
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
54343e
 		    errno == EAFNOSUPPORT || errno == EINVAL) {
54343e
@@ -113,6 +134,7 @@ int if_register_lpf (info)
54343e
 	/* Bind to the interface name */
54343e
 	memset (&sa, 0, sizeof sa);
54343e
 	sa.ll.sll_family = AF_PACKET;
54343e
+	sa.ll.sll_protocol = htons(protocol);
54343e
 	sa.ll.sll_ifindex = ifr.ifr_ifindex;
54343e
 	if (bind (sock, &sa.common, sizeof sa)) {
54343e
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
54343e
@@ -128,8 +150,6 @@ int if_register_lpf (info)
54343e
 		log_fatal ("Bind socket to interface: %m");
54343e
 	}
54343e
 
54343e
-	get_hw_addr(info->name, &info->hw_address);
54343e
-
54343e
 	return sock;
54343e
 }
54343e
 #endif /* USE_LPF_SEND || USE_LPF_RECEIVE */
54343e
@@ -184,6 +204,8 @@ void if_deregister_send (info)
54343e
    in bpf includes... */
54343e
 extern struct sock_filter dhcp_bpf_filter [];
54343e
 extern int dhcp_bpf_filter_len;
54343e
+extern struct sock_filter dhcp_ib_bpf_filter [];
54343e
+extern int dhcp_ib_bpf_filter_len;
54343e
 
54343e
 #if defined (HAVE_TR_SUPPORT)
54343e
 extern struct sock_filter dhcp_bpf_tr_filter [];
54343e
@@ -201,11 +223,13 @@ void if_register_receive (info)
54343e
 	/* Open a LPF device and hang it on this interface... */
54343e
 	info -> rfdesc = if_register_lpf (info);
54343e
 
54343e
-	val = 1;
54343e
-	if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
54343e
-			sizeof val) < 0) {
54343e
-		if (errno != ENOPROTOOPT)
54343e
-			log_fatal ("Failed to set auxiliary packet data: %m");
54343e
+	if (info->hw_address.hbuf[0] != HTYPE_INFINIBAND) {
54343e
+		val = 1;
54343e
+		if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA,
54343e
+				&val, sizeof val) < 0) {
54343e
+			if (errno != ENOPROTOOPT)
54343e
+				log_fatal ("Failed to set auxiliary packet data: %m");
54343e
+		}
54343e
 	}
54343e
 
54343e
 #if defined (HAVE_TR_SUPPORT)
54343e
@@ -251,15 +275,28 @@ static void lpf_gen_filter_setup (info)
54343e
 
54343e
 	memset(&p, 0, sizeof(p));
54343e
 
54343e
-	/* Set up the bpf filter program structure.    This is defined in
54343e
-	   bpf.c */
54343e
-	p.len = dhcp_bpf_filter_len;
54343e
-	p.filter = dhcp_bpf_filter;
54343e
-
54343e
-        /* Patch the server port into the LPF  program...
54343e
-	   XXX changes to filter program may require changes
54343e
-	   to the insn number(s) used below! XXX */
54343e
-	dhcp_bpf_filter [8].k = ntohs ((short)local_port);
54343e
+	if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
54343e
+		/* Set up the bpf filter program structure. */
54343e
+		p.len = dhcp_ib_bpf_filter_len;
54343e
+		p.filter = dhcp_ib_bpf_filter;
54343e
+
54343e
+		/* Patch the server port into the LPF program...
54343e
+		   XXX
54343e
+		   changes to filter program may require changes
54343e
+		   to the insn number(s) used below!
54343e
+		   XXX */
54343e
+		dhcp_ib_bpf_filter[6].k = ntohs ((short)local_port);
54343e
+	} else {
54343e
+		/* Set up the bpf filter program structure.
54343e
+		   This is defined in bpf.c */
54343e
+		p.len = dhcp_bpf_filter_len;
54343e
+		p.filter = dhcp_bpf_filter;
54343e
+
54343e
+		/* Patch the server port into the LPF  program...
54343e
+		   XXX changes to filter program may require changes
54343e
+		   to the insn number(s) used below! XXX */
54343e
+		dhcp_bpf_filter [8].k = ntohs ((short)local_port);
54343e
+	}
54343e
 
54343e
 	if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
54343e
 			sizeof p) < 0) {
54343e
@@ -316,6 +353,54 @@ static void lpf_tr_filter_setup (info)
54343e
 #endif /* USE_LPF_RECEIVE */
54343e
 
54343e
 #ifdef USE_LPF_SEND
54343e
+ssize_t send_packet_ib(interface, packet, raw, len, from, to, hto)
54343e
+	struct interface_info *interface;
54343e
+	struct packet *packet;
54343e
+	struct dhcp_packet *raw;
54343e
+	size_t len;
54343e
+	struct in_addr from;
54343e
+	struct sockaddr_in *to;
54343e
+	struct hardware *hto;
54343e
+{
54343e
+	unsigned ibufp = 0;
54343e
+	double ih [1536 / sizeof (double)];
54343e
+	unsigned char *buf = (unsigned char *)ih;
54343e
+	ssize_t result;
54343e
+
54343e
+	union sockunion {
54343e
+		struct sockaddr sa;
54343e
+		struct sockaddr_ll sll;
54343e
+		struct sockaddr_storage ss;
54343e
+	} su;
54343e
+
54343e
+	assemble_udp_ip_header (interface, buf, &ibufp, from.s_addr,
54343e
+				to->sin_addr.s_addr, to->sin_port,
54343e
+				(unsigned char *)raw, len);
54343e
+	memcpy (buf + ibufp, raw, len);
54343e
+
54343e
+	memset(&su, 0, sizeof(su));
54343e
+	su.sll.sll_family = AF_PACKET;
54343e
+	su.sll.sll_protocol = htons(ETHERTYPE_IP);
54343e
+
54343e
+	if (!(su.sll.sll_ifindex = if_nametoindex(interface->name))) {
54343e
+		errno = ENOENT;
54343e
+		log_error ("send_packet_ib: %m - failed to get if index");
54343e
+		return -1;
54343e
+	}
54343e
+
54343e
+	su.sll.sll_hatype = htons(HTYPE_INFINIBAND);
54343e
+	su.sll.sll_halen = sizeof(interface->bcast_addr);
54343e
+	memcpy(&su.sll.sll_addr, interface->bcast_addr, 20);
54343e
+
54343e
+	result = sendto(interface->wfdesc, buf, ibufp + len, 0,
54343e
+			&su.sa, sizeof(su));
54343e
+
54343e
+	if (result < 0)
54343e
+		log_error ("send_packet_ib: %m");
54343e
+
54343e
+	return result;
54343e
+}
54343e
+
54343e
 ssize_t send_packet (interface, packet, raw, len, from, to, hto)
54343e
 	struct interface_info *interface;
54343e
 	struct packet *packet;
54343e
@@ -336,6 +421,11 @@ ssize_t send_packet (interface, packet,
54343e
 		return send_fallback (interface, packet, raw,
54343e
 				      len, from, to, hto);
54343e
 
54343e
+	if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
54343e
+		return send_packet_ib(interface, packet, raw, len, from,
54343e
+				      to, hto);
54343e
+	}
54343e
+
54343e
 	if (hto == NULL && interface->anycast_mac_addr.hlen)
54343e
 		hto = &interface->anycast_mac_addr;
54343e
 
54343e
@@ -357,6 +447,42 @@ ssize_t send_packet (interface, packet,
54343e
 #endif /* USE_LPF_SEND */
54343e
 
54343e
 #ifdef USE_LPF_RECEIVE
54343e
+ssize_t receive_packet_ib (interface, buf, len, from, hfrom)
54343e
+	struct interface_info *interface;
54343e
+	unsigned char *buf;
54343e
+	size_t len;
54343e
+	struct sockaddr_in *from;
54343e
+	struct hardware *hfrom;
54343e
+{
54343e
+	int length = 0;
54343e
+	int offset = 0;
54343e
+	unsigned char ibuf [1536];
54343e
+	unsigned bufix = 0;
54343e
+	unsigned paylen;
54343e
+
54343e
+	length = read(interface->rfdesc, ibuf, sizeof(ibuf));
54343e
+
54343e
+	if (length <= 0)
54343e
+		return length;
54343e
+
54343e
+	offset = decode_udp_ip_header(interface, ibuf, bufix, from,
54343e
+				       (unsigned)length, &paylen, 0);
54343e
+
54343e
+	if (offset < 0)
54343e
+		return 0;
54343e
+
54343e
+	bufix += offset;
54343e
+	length -= offset;
54343e
+
54343e
+	if (length < paylen)
54343e
+		log_fatal("Internal inconsistency at %s:%d.", MDL);
54343e
+
54343e
+	/* Copy out the data in the packet... */
54343e
+	memcpy(buf, &ibuf[bufix], paylen);
54343e
+
54343e
+	return (ssize_t)paylen;
54343e
+}
54343e
+
54343e
 ssize_t receive_packet (interface, buf, len, from, hfrom)
54343e
 	struct interface_info *interface;
54343e
 	unsigned char *buf;
54343e
@@ -383,6 +509,10 @@ ssize_t receive_packet (interface, buf,
54343e
 	};
54343e
 	struct cmsghdr *cmsg;
54343e
 
54343e
+	if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
54343e
+		return receive_packet_ib(interface, buf, len, from, hfrom);
54343e
+	}
54343e
+
54343e
 	length = recvmsg (interface -> rfdesc, &msg, 0);
54343e
 	if (length <= 0)
54343e
 		return length;
54343e
@@ -462,11 +592,33 @@ void maybe_setup_fallback ()
54343e
 	}
54343e
 }
54343e
 
54343e
-void
54343e
-get_hw_addr(const char *name, struct hardware *hw) {
54343e
+struct sockaddr_ll *
54343e
+get_ll (struct ifaddrs *ifaddrs, struct ifaddrs **ifa, char *name)
54343e
+{
54343e
+	for (*ifa = ifaddrs; *ifa != NULL; *ifa = (*ifa)->ifa_next) {
54343e
+		if ((*ifa)->ifa_addr == NULL)
54343e
+			continue;
54343e
+
54343e
+		if ((*ifa)->ifa_addr->sa_family != AF_PACKET)
54343e
+			continue;
54343e
+
54343e
+		if ((*ifa)->ifa_flags & IFF_LOOPBACK)
54343e
+			continue;
54343e
+
54343e
+		if (strcmp((*ifa)->ifa_name, name) == 0)
54343e
+			return (struct sockaddr_ll *)(void *)(*ifa)->ifa_addr;
54343e
+	}
54343e
+	*ifa = NULL;
54343e
+	return NULL;
54343e
+}
54343e
+
54343e
+struct sockaddr_ll *
54343e
+ioctl_get_ll(char *name)
54343e
+{
54343e
 	int sock;
54343e
 	struct ifreq tmp;
54343e
-	struct sockaddr *sa;
54343e
+	struct sockaddr *sa = NULL;
54343e
+	struct sockaddr_ll *sll = NULL;
54343e
 
54343e
 	if (strlen(name) >= sizeof(tmp.ifr_name)) {
54343e
 		log_fatal("Device name too long: \"%s\"", name);
54343e
@@ -480,16 +632,61 @@ get_hw_addr(const char *name, struct har
54343e
 	memset(&tmp, 0, sizeof(tmp));
54343e
 	strcpy(tmp.ifr_name, name);
54343e
 	if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) {
54343e
-		log_fatal("Error getting hardware address for \"%s\": %m", 
54343e
+		log_fatal("Error getting hardware address for \"%s\": %m",
54343e
 			  name);
54343e
 	}
54343e
+	close(sock);
54343e
 
54343e
 	sa = &tmp.ifr_hwaddr;
54343e
-	switch (sa->sa_family) {
54343e
+	// needs to be freed outside this function
54343e
+	sll = dmalloc (sizeof (struct sockaddr_ll), MDL);
54343e
+	if (!sll)
54343e
+		log_fatal("Unable to allocate memory for link layer address");
54343e
+	memcpy(&sll->sll_hatype, &sa->sa_family, sizeof (sll->sll_hatype));
54343e
+	memcpy(sll->sll_addr, sa->sa_data, sizeof (sll->sll_addr));
54343e
+	switch (sll->sll_hatype) {
54343e
+		case ARPHRD_INFINIBAND:
54343e
+			sll->sll_halen = HARDWARE_ADDR_LEN_IOCTL;
54343e
+			break;
54343e
+		default:
54343e
+			break;
54343e
+	}
54343e
+	return sll;
54343e
+}
54343e
+
54343e
+void
54343e
+get_hw_addr(struct interface_info *info)
54343e
+{
54343e
+	struct hardware *hw = &info->hw_address;
54343e
+	char *name = info->name;
54343e
+	struct ifaddrs *ifaddrs = NULL;
54343e
+	struct ifaddrs *ifa = NULL;
54343e
+	struct sockaddr_ll *sll = NULL;
54343e
+	int sll_allocated = 0;
54343e
+	char *dup = NULL;
54343e
+	char *colon = NULL;
54343e
+
54343e
+	if (getifaddrs(&ifaddrs) == -1)
54343e
+		log_fatal("Failed to get interfaces");
54343e
+
54343e
+	if ((sll = get_ll(ifaddrs, &ifa, name)) == NULL) {
54343e
+		/*
54343e
+		 * We were unable to get link-layer address for name.
54343e
+		 * Fall back to ioctl(SIOCGIFHWADDR).
54343e
+		 */
54343e
+		sll = ioctl_get_ll(name);
54343e
+		if (sll != NULL)
54343e
+			sll_allocated = 1;
54343e
+		else
54343e
+			// shouldn't happen
54343e
+			log_fatal("Unexpected internal error");
54343e
+	}
54343e
+
54343e
+	switch (sll->sll_hatype) {
54343e
 		case ARPHRD_ETHER:
54343e
 			hw->hlen = 7;
54343e
 			hw->hbuf[0] = HTYPE_ETHER;
54343e
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
54343e
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
54343e
 			break;
54343e
 		case ARPHRD_IEEE802:
54343e
 #ifdef ARPHRD_IEEE802_TR
54343e
@@ -497,18 +694,50 @@ get_hw_addr(const char *name, struct har
54343e
 #endif /* ARPHRD_IEEE802_TR */
54343e
 			hw->hlen = 7;
54343e
 			hw->hbuf[0] = HTYPE_IEEE802;
54343e
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
54343e
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
54343e
 			break;
54343e
 		case ARPHRD_FDDI:
54343e
 			hw->hlen = 7;
54343e
 			hw->hbuf[0] = HTYPE_FDDI;
54343e
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
54343e
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
54343e
+			break;
54343e
+		case ARPHRD_INFINIBAND:
54343e
+			dup = strdup(name);
54343e
+			/* Aliased infiniband interface is special case where
54343e
+			 * neither get_ll() nor ioctl_get_ll() get's correct hw
54343e
+			 * address, so we have to truncate the :0 and run
54343e
+			 * get_ll() again for the rest.
54343e
+			*/
54343e
+			if ((colon = strchr(dup, ':')) != NULL) {
54343e
+				*colon = '\0';
54343e
+				if ((sll = get_ll(ifaddrs, &ifa, dup)) == NULL)
54343e
+					log_fatal("Error getting hardware address for \"%s\": %m", name);
54343e
+			}
54343e
+			free (dup);
54343e
+			/* For Infiniband, save the broadcast address and store
54343e
+			 * the port GUID into the hardware address.
54343e
+			 */
54343e
+			if (ifa && (ifa->ifa_flags & IFF_BROADCAST)) {
54343e
+				struct sockaddr_ll *bll;
54343e
+
54343e
+				bll = (struct sockaddr_ll *)ifa->ifa_broadaddr;
54343e
+				memcpy(&info->bcast_addr, bll->sll_addr, 20);
54343e
+			} else {
54343e
+				memcpy(&info->bcast_addr, default_ib_bcast_addr,
54343e
+				       20);
54343e
+			}
54343e
+
54343e
+			hw->hlen = HARDWARE_ADDR_LEN_IOCTL + 1;
54343e
+			hw->hbuf[0] = HTYPE_INFINIBAND;
54343e
+			memcpy(&hw->hbuf[1],
54343e
+			       &sll->sll_addr[sll->sll_halen - HARDWARE_ADDR_LEN_IOCTL],
54343e
+			       HARDWARE_ADDR_LEN_IOCTL);
54343e
 			break;
54343e
 #if defined(ARPHRD_PPP)
54343e
 		case ARPHRD_PPP:
54343e
 			if (local_family != AF_INET6)
54343e
-				log_fatal("Unsupported device type %d for \"%s\"",
54343e
-				           sa->sa_family, name);
54343e
+				log_fatal("local_family != AF_INET6 for \"%s\"",
54343e
+					  name);
54343e
 			hw->hlen = 0;
54343e
 			hw->hbuf[0] = HTYPE_RESERVED;
54343e
 			/* 0xdeadbeef should never occur on the wire,
54343e
@@ -521,10 +750,13 @@ get_hw_addr(const char *name, struct har
54343e
 			break;
54343e
 #endif
54343e
 		default:
54343e
-			log_fatal("Unsupported device type %ld for \"%s\"",
54343e
-				  (long int)sa->sa_family, name);
54343e
+			freeifaddrs(ifaddrs);
54343e
+			log_fatal("Unsupported device type %hu for \"%s\"",
54343e
+				  sll->sll_hatype, name);
54343e
 	}
54343e
 
54343e
-	close(sock);
54343e
+	if (sll_allocated)
54343e
+		dfree(sll, MDL);
54343e
+	freeifaddrs(ifaddrs);
54343e
 }
54343e
 #endif
54343e
diff -up dhcp-4.2.5/common/socket.c.lpf-ib dhcp-4.2.5/common/socket.c
54343e
--- dhcp-4.2.5/common/socket.c.lpf-ib	2013-01-03 01:02:24.000000000 +0100
54343e
+++ dhcp-4.2.5/common/socket.c	2015-06-05 16:18:03.392948643 +0200
54343e
@@ -325,7 +325,7 @@ void if_register_send (info)
54343e
 	info->wfdesc = if_register_socket(info, AF_INET, 0);
54343e
 	/* If this is a normal IPv4 address, get the hardware address. */
54343e
 	if (strcmp(info->name, "fallback") != 0)
54343e
-		get_hw_addr(info->name, &info->hw_address);
54343e
+		get_hw_addr(info);
54343e
 #if defined (USE_SOCKET_FALLBACK)
54343e
 	/* Fallback only registers for send, but may need to receive as
54343e
 	   well. */
54343e
@@ -388,7 +388,7 @@ void if_register_receive (info)
54343e
 #endif /* IP_PKTINFO... */
54343e
 	/* If this is a normal IPv4 address, get the hardware address. */
54343e
 	if (strcmp(info->name, "fallback") != 0)
54343e
-		get_hw_addr(info->name, &info->hw_address);
54343e
+		get_hw_addr(info);
54343e
 
54343e
 	if (!quiet_interface_discovery)
54343e
 		log_info ("Listening on Socket/%s%s%s",
54343e
@@ -498,7 +498,7 @@ if_register6(struct interface_info *info
54343e
 	if (req_multi)
54343e
 		if_register_multicast(info);
54343e
 
54343e
-	get_hw_addr(info->name, &info->hw_address);
54343e
+	get_hw_addr(info);
54343e
 
54343e
 	if (!quiet_interface_discovery) {
54343e
 		if (info->shared_network != NULL) {
54343e
diff -up dhcp-4.2.5/includes/dhcpd.h.lpf-ib dhcp-4.2.5/includes/dhcpd.h
54343e
--- dhcp-4.2.5/includes/dhcpd.h.lpf-ib	2015-06-05 16:18:03.388948655 +0200
54343e
+++ dhcp-4.2.5/includes/dhcpd.h	2015-06-05 16:33:58.988803266 +0200
54343e
@@ -440,6 +440,9 @@ struct packet {
54343e
 
54343e
 #define HARDWARE_ADDR_LEN 20
54343e
 
54343e
+/* ioctl limits hardware addresses to 8 bytes */
54343e
+#define HARDWARE_ADDR_LEN_IOCTL	8
54343e
+
54343e
 struct hardware {
54343e
 	u_int8_t hlen;
54343e
 	u_int8_t hbuf[HARDWARE_ADDR_LEN + 1];
54343e
@@ -1249,6 +1252,7 @@ struct interface_info {
54343e
 	struct shared_network *shared_network;
54343e
 				/* Networks connected to this interface. */
54343e
 	struct hardware hw_address;	/* Its physical address. */
54343e
+	u_int8_t bcast_addr[20];	/* Infiniband broadcast address */
54343e
 	struct in_addr *addresses;	/* Addresses associated with this
54343e
 					 * interface.
54343e
 					 */
54343e
@@ -2372,7 +2376,7 @@ void print_dns_status (int, struct dhcp_
54343e
 #endif
54343e
 const char *print_time(TIME);
54343e
 
54343e
-void get_hw_addr(const char *name, struct hardware *hw);
54343e
+void get_hw_addr(struct interface_info *info);
54343e
 
54343e
 /* socket.c */
54343e
 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \