Blame SOURCES/dhcp-lpf-ib.patch

26a25c
diff -up dhcp-4.3.4/client/dhclient.c.lpf-ib dhcp-4.3.4/client/dhclient.c
26a25c
--- dhcp-4.3.4/client/dhclient.c.lpf-ib	2016-05-02 14:37:36.945128001 +0200
26a25c
+++ dhcp-4.3.4/client/dhclient.c	2016-05-02 14:37:36.952128005 +0200
26a25c
@@ -163,6 +163,8 @@ static const char use_noarg[] = "No argu
26a25c
 static const char use_v6command[] = "Command not used for DHCPv4: %s";
26a25c
 #endif
26a25c
 
26a25c
+static void setup_ib_interface(struct interface_info *ip);
26a25c
+
26a25c
 static void
26a25c
 usage(const char *sfmt, const char *sarg)
26a25c
 {
26a25c
@@ -1066,6 +1068,13 @@ main(int argc, char **argv) {
26a25c
 	}
26a25c
 	srandom(seed + cur_time + (unsigned)getpid());
26a25c
 
26a25c
+	/* Setup specific Infiniband options */
26a25c
+	for (ip = interfaces; ip; ip = ip->next) {
26a25c
+		if (ip->client &&
26a25c
+		    (ip->hw_address.hbuf[0] == HTYPE_INFINIBAND)) {
26a25c
+			setup_ib_interface(ip);
26a25c
+		}
26a25c
+	}
26a25c
 
26a25c
 	/*
26a25c
 	 * Establish a default DUID.  We always do so for v6 and
26a25c
@@ -1361,6 +1370,29 @@ int find_subnet (struct subnet **sp,
26a25c
 	return 0;
26a25c
 }
26a25c
 
26a25c
+static void setup_ib_interface(struct interface_info *ip)
26a25c
+{
26a25c
+	struct group *g;
26a25c
+
26a25c
+	/* Set the broadcast flag */
26a25c
+	ip->client->config->bootp_broadcast_always = 1;
26a25c
+
26a25c
+	/*
26a25c
+	 * Find out if a dhcp-client-identifier option was specified either
26a25c
+	 * in the config file or on the command line
26a25c
+	 */
26a25c
+	for (g = ip->client->config->on_transmission; g != NULL; g = g->next) {
26a25c
+		if ((g->statements != NULL) &&
26a25c
+		    (strcmp(g->statements->data.option->option->name,
26a25c
+			    "dhcp-client-identifier") == 0)) {
26a25c
+			return;
26a25c
+		}
26a25c
+	}
26a25c
+
26a25c
+	/* No client ID specified */
26a25c
+	log_fatal("dhcp-client-identifier must be specified for InfiniBand");
26a25c
+}
26a25c
+
26a25c
 /* Individual States:
26a25c
  *
26a25c
  * Each routine is called from the dhclient_state_machine() in one of
26a25c
diff -up dhcp-4.3.4/common/bpf.c.lpf-ib dhcp-4.3.4/common/bpf.c
26a25c
--- dhcp-4.3.4/common/bpf.c.lpf-ib	2016-05-02 14:37:36.946128001 +0200
26a25c
+++ dhcp-4.3.4/common/bpf.c	2016-05-02 14:37:36.952128005 +0200
26a25c
@@ -198,11 +198,43 @@ struct bpf_insn dhcp_bpf_filter [] = {
26a25c
 	BPF_STMT(BPF_RET+BPF_K, 0),
26a25c
 };
26a25c
 
26a25c
+/* Packet filter program for DHCP over Infiniband.
26a25c
+ *
26a25c
+ * XXX
26a25c
+ * Changes to the filter program may require changes to the constant offsets
26a25c
+ * used in lpf_gen_filter_setup to patch the port in the BPF program!
26a25c
+ * XXX
26a25c
+ */
26a25c
+struct bpf_insn dhcp_ib_bpf_filter [] = {
26a25c
+	/* Packet filter for Infiniband */
26a25c
+	/* Make sure it's a UDP packet... */
26a25c
+	BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 9),
26a25c
+	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6),
26a25c
+
26a25c
+	/* Make sure this isn't a fragment... */
26a25c
+	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 6),
26a25c
+	BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0),
26a25c
+
26a25c
+	/* Get the IP header length... */
26a25c
+	BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 0),
26a25c
+
26a25c
+	/* Make sure it's to the right port... */
26a25c
+	BPF_STMT(BPF_LD + BPF_H + BPF_IND, 2),
26a25c
+	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1),
26a25c
+
26a25c
+	/* If we passed all the tests, ask for the whole packet. */
26a25c
+	BPF_STMT(BPF_RET + BPF_K, (u_int)-1),
26a25c
+
26a25c
+	/* Otherwise, drop it. */
26a25c
+	BPF_STMT(BPF_RET + BPF_K, 0),
26a25c
+};
26a25c
+
26a25c
 #if defined (DEC_FDDI)
26a25c
 struct bpf_insn *bpf_fddi_filter = NULL;
26a25c
 #endif
26a25c
 
26a25c
 int dhcp_bpf_filter_len = sizeof dhcp_bpf_filter / sizeof (struct bpf_insn);
26a25c
+int dhcp_ib_bpf_filter_len = sizeof dhcp_ib_bpf_filter / sizeof (struct bpf_insn);
26a25c
 #if defined (HAVE_TR_SUPPORT)
26a25c
 struct bpf_insn dhcp_bpf_tr_filter [] = {
26a25c
         /* accept all token ring packets due to variable length header */
26a25c
diff -up dhcp-4.3.4/common/discover.c.lpf-ib dhcp-4.3.4/common/discover.c
26a25c
--- dhcp-4.3.4/common/discover.c.lpf-ib	2016-03-22 14:16:51.000000000 +0100
26a25c
+++ dhcp-4.3.4/common/discover.c	2016-05-02 14:38:08.257147982 +0200
26a25c
@@ -1235,7 +1235,7 @@ discover_interfaces(int state) {
26a25c
 				if_register_send(tmp);
26a25c
 			} else {
26a25c
 				/* get_hw_addr() was called by register. */
26a25c
-				get_hw_addr(tmp->name, &tmp->hw_address);
26a25c
+				get_hw_addr(tmp);
26a25c
 			}
26a25c
 			break;
26a25c
 #ifdef DHCPv6
26a25c
@@ -1248,7 +1248,7 @@ discover_interfaces(int state) {
26a25c
 				   so now we have to call it explicitly
26a25c
 				   to not leave the hardware address unknown
26a25c
 				   (some code expects it cannot be. */
26a25c
-				get_hw_addr(tmp->name, &tmp->hw_address);
26a25c
+				get_hw_addr(tmp);
26a25c
 			} else {
26a25c
 				if_register_linklocal6(tmp);
26a25c
 			}
26a25c
diff -up dhcp-4.3.4/common/lpf.c.lpf-ib dhcp-4.3.4/common/lpf.c
26a25c
--- dhcp-4.3.4/common/lpf.c.lpf-ib	2016-05-02 14:37:36.947128002 +0200
26a25c
+++ dhcp-4.3.4/common/lpf.c	2016-05-02 14:37:36.953128006 +0200
26a25c
@@ -47,6 +47,17 @@
26a25c
 #include <sys/ioctl.h>
26a25c
 #include <sys/socket.h>
26a25c
 #include <net/if.h>
26a25c
+#include <ifaddrs.h>
26a25c
+
26a25c
+/* Default broadcast address for IPoIB */
26a25c
+static unsigned char default_ib_bcast_addr[20] = {
26a25c
+ 	0x00, 0xff, 0xff, 0xff,
26a25c
+	0xff, 0x12, 0x40, 0x1b,
26a25c
+	0x00, 0x00, 0x00, 0x00,
26a25c
+	0x00, 0x00, 0x00, 0x00,
26a25c
+	0xff, 0xff, 0xff, 0xff
26a25c
+};
26a25c
+
26a25c
 #endif
26a25c
 
26a25c
 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
26a25c
@@ -80,10 +91,20 @@ int if_register_lpf (info)
26a25c
 		struct sockaddr common;
26a25c
 		} sa;
26a25c
 	struct ifreq ifr;
26a25c
+	int type;
26a25c
+	int protocol;
26a25c
+
26a25c
+	get_hw_addr(info);
26a25c
+	if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
26a25c
+		type = SOCK_DGRAM;
26a25c
+		protocol = ETHERTYPE_IP;
26a25c
+	} else {
26a25c
+		type = SOCK_RAW;
26a25c
+		protocol = ETH_P_ALL;
26a25c
+	}
26a25c
 
26a25c
 	/* Make an LPF socket. */
26a25c
-	if ((sock = socket(PF_PACKET, SOCK_RAW,
26a25c
-			   htons((short)ETH_P_ALL))) < 0) {
26a25c
+	if ((sock = socket(PF_PACKET, type, htons((short)protocol))) < 0) {
26a25c
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
26a25c
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
26a25c
 		    errno == EAFNOSUPPORT || errno == EINVAL) {
26a25c
@@ -106,6 +127,7 @@ int if_register_lpf (info)
26a25c
 	/* Bind to the interface name */
26a25c
 	memset (&sa, 0, sizeof sa);
26a25c
 	sa.ll.sll_family = AF_PACKET;
26a25c
+	sa.ll.sll_protocol = htons(protocol);
26a25c
 	sa.ll.sll_ifindex = ifr.ifr_ifindex;
26a25c
 	if (bind (sock, &sa.common, sizeof sa)) {
26a25c
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
26a25c
@@ -122,8 +144,6 @@ int if_register_lpf (info)
26a25c
 
26a25c
 	}
26a25c
 
26a25c
-	get_hw_addr(info->name, &info->hw_address);
26a25c
-
26a25c
 	return sock;
26a25c
 }
26a25c
 #endif /* USE_LPF_SEND || USE_LPF_RECEIVE */
26a25c
@@ -178,6 +198,8 @@ void if_deregister_send (info)
26a25c
    in bpf includes... */
26a25c
 extern struct sock_filter dhcp_bpf_filter [];
26a25c
 extern int dhcp_bpf_filter_len;
26a25c
+extern struct sock_filter dhcp_ib_bpf_filter [];
26a25c
+extern int dhcp_ib_bpf_filter_len;
26a25c
 
26a25c
 #if defined (HAVE_TR_SUPPORT)
26a25c
 extern struct sock_filter dhcp_bpf_tr_filter [];
26a25c
@@ -196,11 +218,12 @@ void if_register_receive (info)
26a25c
 #ifdef PACKET_AUXDATA
26a25c
 	{
26a25c
 	int val = 1;
26a25c
-
26a25c
-	if (setsockopt(info->rfdesc, SOL_PACKET, PACKET_AUXDATA,
26a25c
-		       &val, sizeof(val)) < 0) {
26a25c
-		if (errno != ENOPROTOOPT) {
26a25c
-			log_fatal ("Failed to set auxiliary packet data: %m");
26a25c
+	if (info->hw_address.hbuf[0] != HTYPE_INFINIBAND) {
26a25c
+		if (setsockopt(info->rfdesc, SOL_PACKET, PACKET_AUXDATA,
26a25c
+			      &val, sizeof(val)) < 0) {
26a25c
+			if (errno != ENOPROTOOPT) {
26a25c
+				log_fatal ("Failed to set auxiliary packet data: %m");
26a25c
+			}
26a25c
 		}
26a25c
 	}
26a25c
 	}
26a25c
@@ -250,15 +273,28 @@ static void lpf_gen_filter_setup (info)
26a25c
 
26a25c
 	memset(&p, 0, sizeof(p));
26a25c
 
26a25c
-	/* Set up the bpf filter program structure.    This is defined in
26a25c
-	   bpf.c */
26a25c
-	p.len = dhcp_bpf_filter_len;
26a25c
-	p.filter = dhcp_bpf_filter;
26a25c
-
26a25c
-        /* Patch the server port into the LPF  program...
26a25c
-	   XXX changes to filter program may require changes
26a25c
-	   to the insn number(s) used below! XXX */
26a25c
-	dhcp_bpf_filter [8].k = ntohs ((short)local_port);
26a25c
+	if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
26a25c
+		/* Set up the bpf filter program structure. */
26a25c
+		p.len = dhcp_ib_bpf_filter_len;
26a25c
+		p.filter = dhcp_ib_bpf_filter;
26a25c
+
26a25c
+		/* Patch the server port into the LPF program...
26a25c
+		   XXX
26a25c
+		   changes to filter program may require changes
26a25c
+		   to the insn number(s) used below!
26a25c
+		   XXX */
26a25c
+		dhcp_ib_bpf_filter[6].k = ntohs ((short)local_port);
26a25c
+	} else {
26a25c
+		/* Set up the bpf filter program structure.
26a25c
+		   This is defined in bpf.c */
26a25c
+		p.len = dhcp_bpf_filter_len;
26a25c
+		p.filter = dhcp_bpf_filter;
26a25c
+
26a25c
+		/* Patch the server port into the LPF  program...
26a25c
+		   XXX changes to filter program may require changes
26a25c
+		   to the insn number(s) used below! XXX */
26a25c
+		dhcp_bpf_filter [8].k = ntohs ((short)local_port);
26a25c
+	}
26a25c
 
26a25c
 	if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
26a25c
 			sizeof p) < 0) {
26a25c
@@ -315,6 +351,54 @@ static void lpf_tr_filter_setup (info)
26a25c
 #endif /* USE_LPF_RECEIVE */
26a25c
 
26a25c
 #ifdef USE_LPF_SEND
26a25c
+ssize_t send_packet_ib(interface, packet, raw, len, from, to, hto)
26a25c
+	struct interface_info *interface;
26a25c
+	struct packet *packet;
26a25c
+	struct dhcp_packet *raw;
26a25c
+	size_t len;
26a25c
+	struct in_addr from;
26a25c
+	struct sockaddr_in *to;
26a25c
+	struct hardware *hto;
26a25c
+{
26a25c
+	unsigned ibufp = 0;
26a25c
+	double ih [1536 / sizeof (double)];
26a25c
+	unsigned char *buf = (unsigned char *)ih;
26a25c
+	ssize_t result;
26a25c
+
26a25c
+	union sockunion {
26a25c
+		struct sockaddr sa;
26a25c
+		struct sockaddr_ll sll;
26a25c
+		struct sockaddr_storage ss;
26a25c
+	} su;
26a25c
+
26a25c
+	assemble_udp_ip_header (interface, buf, &ibufp, from.s_addr,
26a25c
+				to->sin_addr.s_addr, to->sin_port,
26a25c
+				(unsigned char *)raw, len);
26a25c
+	memcpy (buf + ibufp, raw, len);
26a25c
+
26a25c
+	memset(&su, 0, sizeof(su));
26a25c
+	su.sll.sll_family = AF_PACKET;
26a25c
+	su.sll.sll_protocol = htons(ETHERTYPE_IP);
26a25c
+
26a25c
+	if (!(su.sll.sll_ifindex = if_nametoindex(interface->name))) {
26a25c
+		errno = ENOENT;
26a25c
+		log_error ("send_packet_ib: %m - failed to get if index");
26a25c
+		return -1;
26a25c
+	}
26a25c
+
26a25c
+	su.sll.sll_hatype = htons(HTYPE_INFINIBAND);
26a25c
+	su.sll.sll_halen = sizeof(interface->bcast_addr);
26a25c
+	memcpy(&su.sll.sll_addr, interface->bcast_addr, 20);
26a25c
+
26a25c
+	result = sendto(interface->wfdesc, buf, ibufp + len, 0,
26a25c
+			&su.sa, sizeof(su));
26a25c
+
26a25c
+	if (result < 0)
26a25c
+		log_error ("send_packet_ib: %m");
26a25c
+
26a25c
+	return result;
26a25c
+}
26a25c
+
26a25c
 ssize_t send_packet (interface, packet, raw, len, from, to, hto)
26a25c
 	struct interface_info *interface;
26a25c
 	struct packet *packet;
26a25c
@@ -335,6 +419,11 @@ ssize_t send_packet (interface, packet,
26a25c
 		return send_fallback (interface, packet, raw,
26a25c
 				      len, from, to, hto);
26a25c
 
26a25c
+	if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
26a25c
+		return send_packet_ib(interface, packet, raw, len, from,
26a25c
+				      to, hto);
26a25c
+	}
26a25c
+
26a25c
 	if (hto == NULL && interface->anycast_mac_addr.hlen)
26a25c
 		hto = &interface->anycast_mac_addr;
26a25c
 
26a25c
@@ -355,6 +444,42 @@ ssize_t send_packet (interface, packet,
26a25c
 #endif /* USE_LPF_SEND */
26a25c
 
26a25c
 #ifdef USE_LPF_RECEIVE
26a25c
+ssize_t receive_packet_ib (interface, buf, len, from, hfrom)
26a25c
+	struct interface_info *interface;
26a25c
+	unsigned char *buf;
26a25c
+	size_t len;
26a25c
+	struct sockaddr_in *from;
26a25c
+	struct hardware *hfrom;
26a25c
+{
26a25c
+	int length = 0;
26a25c
+	int offset = 0;
26a25c
+	unsigned char ibuf [1536];
26a25c
+	unsigned bufix = 0;
26a25c
+	unsigned paylen;
26a25c
+
26a25c
+	length = read(interface->rfdesc, ibuf, sizeof(ibuf));
26a25c
+
26a25c
+	if (length <= 0)
26a25c
+		return length;
26a25c
+
26a25c
+	offset = decode_udp_ip_header(interface, ibuf, bufix, from,
26a25c
+				       (unsigned)length, &paylen, 0);
26a25c
+
26a25c
+	if (offset < 0)
26a25c
+		return 0;
26a25c
+
26a25c
+	bufix += offset;
26a25c
+	length -= offset;
26a25c
+
26a25c
+	if (length < paylen)
26a25c
+		log_fatal("Internal inconsistency at %s:%d.", MDL);
26a25c
+
26a25c
+	/* Copy out the data in the packet... */
26a25c
+	memcpy(buf, &ibuf[bufix], paylen);
26a25c
+
26a25c
+	return (ssize_t)paylen;
26a25c
+}
26a25c
+
26a25c
 ssize_t receive_packet (interface, buf, len, from, hfrom)
26a25c
 	struct interface_info *interface;
26a25c
 	unsigned char *buf;
26a25c
@@ -393,6 +518,10 @@ ssize_t receive_packet (interface, buf,
26a25c
 	};
26a25c
 #endif /* PACKET_AUXDATA */
26a25c
 
26a25c
+	if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
26a25c
+		return receive_packet_ib(interface, buf, len, from, hfrom);
26a25c
+	}
26a25c
+
26a25c
 	length = recvmsg (interface->rfdesc, &msg, 0);
26a25c
 	if (length <= 0)
26a25c
 		return length;
26a25c
@@ -506,11 +635,33 @@ void maybe_setup_fallback ()
26a25c
 #endif
26a25c
 
26a25c
 #if defined (USE_LPF_RECEIVE) || defined (USE_LPF_HWADDR)
26a25c
-void
26a25c
-get_hw_addr(const char *name, struct hardware *hw) {
26a25c
+struct sockaddr_ll *
26a25c
+get_ll (struct ifaddrs *ifaddrs, struct ifaddrs **ifa, char *name)
26a25c
+{
26a25c
+	for (*ifa = ifaddrs; *ifa != NULL; *ifa = (*ifa)->ifa_next) {
26a25c
+		if ((*ifa)->ifa_addr == NULL)
26a25c
+			continue;
26a25c
+
26a25c
+		if ((*ifa)->ifa_addr->sa_family != AF_PACKET)
26a25c
+			continue;
26a25c
+
26a25c
+		if ((*ifa)->ifa_flags & IFF_LOOPBACK)
26a25c
+			continue;
26a25c
+
26a25c
+		if (strcmp((*ifa)->ifa_name, name) == 0)
26a25c
+			return (struct sockaddr_ll *)(void *)(*ifa)->ifa_addr;
26a25c
+	}
26a25c
+	*ifa = NULL;
26a25c
+	return NULL;
26a25c
+}
26a25c
+
26a25c
+struct sockaddr_ll *
26a25c
+ioctl_get_ll(char *name)
26a25c
+{
26a25c
 	int sock;
26a25c
 	struct ifreq tmp;
26a25c
-	struct sockaddr *sa;
26a25c
+	struct sockaddr *sa = NULL;
26a25c
+	struct sockaddr_ll *sll = NULL;
26a25c
 
26a25c
 	if (strlen(name) >= sizeof(tmp.ifr_name)) {
26a25c
 		log_fatal("Device name too long: \"%s\"", name);
26a25c
@@ -524,16 +675,61 @@ get_hw_addr(const char *name, struct har
26a25c
 	memset(&tmp, 0, sizeof(tmp));
26a25c
 	strcpy(tmp.ifr_name, name);
26a25c
 	if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) {
26a25c
-		log_fatal("Error getting hardware address for \"%s\": %m", 
26a25c
+		log_fatal("Error getting hardware address for \"%s\": %m",
26a25c
 			  name);
26a25c
 	}
26a25c
+	close(sock);
26a25c
 
26a25c
 	sa = &tmp.ifr_hwaddr;
26a25c
-	switch (sa->sa_family) {
26a25c
+	// needs to be freed outside this function
26a25c
+	sll = dmalloc (sizeof (struct sockaddr_ll), MDL);
26a25c
+	if (!sll)
26a25c
+		log_fatal("Unable to allocate memory for link layer address");
26a25c
+	memcpy(&sll->sll_hatype, &sa->sa_family, sizeof (sll->sll_hatype));
26a25c
+	memcpy(sll->sll_addr, sa->sa_data, sizeof (sll->sll_addr));
26a25c
+	switch (sll->sll_hatype) {
26a25c
+		case ARPHRD_INFINIBAND:
26a25c
+			sll->sll_halen = HARDWARE_ADDR_LEN_IOCTL;
26a25c
+			break;
26a25c
+		default:
26a25c
+			break;
26a25c
+	}
26a25c
+	return sll;
26a25c
+}
26a25c
+
26a25c
+void
26a25c
+get_hw_addr(struct interface_info *info)
26a25c
+{
26a25c
+	struct hardware *hw = &info->hw_address;
26a25c
+	char *name = info->name;
26a25c
+	struct ifaddrs *ifaddrs = NULL;
26a25c
+	struct ifaddrs *ifa = NULL;
26a25c
+	struct sockaddr_ll *sll = NULL;
26a25c
+	int sll_allocated = 0;
26a25c
+	char *dup = NULL;
26a25c
+	char *colon = NULL;
26a25c
+
26a25c
+	if (getifaddrs(&ifaddrs) == -1)
26a25c
+		log_fatal("Failed to get interfaces");
26a25c
+
26a25c
+	if ((sll = get_ll(ifaddrs, &ifa, name)) == NULL) {
26a25c
+		/*
26a25c
+		 * We were unable to get link-layer address for name.
26a25c
+		 * Fall back to ioctl(SIOCGIFHWADDR).
26a25c
+		 */
26a25c
+		sll = ioctl_get_ll(name);
26a25c
+		if (sll != NULL)
26a25c
+			sll_allocated = 1;
26a25c
+		else
26a25c
+			// shouldn't happen
26a25c
+			log_fatal("Unexpected internal error");
26a25c
+	}
26a25c
+
26a25c
+	switch (sll->sll_hatype) {
26a25c
 		case ARPHRD_ETHER:
26a25c
 			hw->hlen = 7;
26a25c
 			hw->hbuf[0] = HTYPE_ETHER;
26a25c
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
26a25c
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
26a25c
 			break;
26a25c
 		case ARPHRD_IEEE802:
26a25c
 #ifdef ARPHRD_IEEE802_TR
26a25c
@@ -541,18 +737,50 @@ get_hw_addr(const char *name, struct har
26a25c
 #endif /* ARPHRD_IEEE802_TR */
26a25c
 			hw->hlen = 7;
26a25c
 			hw->hbuf[0] = HTYPE_IEEE802;
26a25c
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
26a25c
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
26a25c
 			break;
26a25c
 		case ARPHRD_FDDI:
26a25c
 			hw->hlen = 7;
26a25c
 			hw->hbuf[0] = HTYPE_FDDI;
26a25c
-			memcpy(&hw->hbuf[1], sa->sa_data, 6);
26a25c
+			memcpy(&hw->hbuf[1], sll->sll_addr, 6);
26a25c
+			break;
26a25c
+		case ARPHRD_INFINIBAND:
26a25c
+			dup = strdup(name);
26a25c
+			/* Aliased infiniband interface is special case where
26a25c
+			 * neither get_ll() nor ioctl_get_ll() get's correct hw
26a25c
+			 * address, so we have to truncate the :0 and run
26a25c
+			 * get_ll() again for the rest.
26a25c
+			*/
26a25c
+			if ((colon = strchr(dup, ':')) != NULL) {
26a25c
+				*colon = '\0';
26a25c
+				if ((sll = get_ll(ifaddrs, &ifa, dup)) == NULL)
26a25c
+					log_fatal("Error getting hardware address for \"%s\": %m", name);
26a25c
+			}
26a25c
+			free (dup);
26a25c
+			/* For Infiniband, save the broadcast address and store
26a25c
+			 * the port GUID into the hardware address.
26a25c
+			 */
26a25c
+			if (ifa && (ifa->ifa_flags & IFF_BROADCAST)) {
26a25c
+				struct sockaddr_ll *bll;
26a25c
+
26a25c
+				bll = (struct sockaddr_ll *)ifa->ifa_broadaddr;
26a25c
+				memcpy(&info->bcast_addr, bll->sll_addr, 20);
26a25c
+			} else {
26a25c
+				memcpy(&info->bcast_addr, default_ib_bcast_addr,
26a25c
+				       20);
26a25c
+			}
26a25c
+
26a25c
+			hw->hlen = HARDWARE_ADDR_LEN_IOCTL + 1;
26a25c
+			hw->hbuf[0] = HTYPE_INFINIBAND;
26a25c
+			memcpy(&hw->hbuf[1],
26a25c
+			       &sll->sll_addr[sll->sll_halen - HARDWARE_ADDR_LEN_IOCTL],
26a25c
+			       HARDWARE_ADDR_LEN_IOCTL);
26a25c
 			break;
26a25c
 #if defined(ARPHRD_PPP)
26a25c
 		case ARPHRD_PPP:
26a25c
 			if (local_family != AF_INET6)
26a25c
-				log_fatal("Unsupported device type %d for \"%s\"",
26a25c
-				           sa->sa_family, name);
26a25c
+				log_fatal("local_family != AF_INET6 for \"%s\"",
26a25c
+					  name);
26a25c
 			hw->hlen = 0;
26a25c
 			hw->hbuf[0] = HTYPE_RESERVED;
26a25c
 			/* 0xdeadbeef should never occur on the wire,
26a25c
@@ -565,10 +793,13 @@ get_hw_addr(const char *name, struct har
26a25c
 			break;
26a25c
 #endif
26a25c
 		default:
26a25c
-			log_fatal("Unsupported device type %ld for \"%s\"",
26a25c
-				  (long int)sa->sa_family, name);
26a25c
+			freeifaddrs(ifaddrs);
26a25c
+			log_fatal("Unsupported device type %hu for \"%s\"",
26a25c
+				  sll->sll_hatype, name);
26a25c
 	}
26a25c
 
26a25c
-	close(sock);
26a25c
+	if (sll_allocated)
26a25c
+		dfree(sll, MDL);
26a25c
+	freeifaddrs(ifaddrs);
26a25c
 }
26a25c
 #endif
26a25c
diff -up dhcp-4.3.4/common/socket.c.lpf-ib dhcp-4.3.4/common/socket.c
26a25c
--- dhcp-4.3.4/common/socket.c.lpf-ib	2016-03-22 14:16:51.000000000 +0100
26a25c
+++ dhcp-4.3.4/common/socket.c	2016-05-02 14:37:36.953128006 +0200
26a25c
@@ -328,7 +328,7 @@ void if_register_send (info)
26a25c
 	info->wfdesc = if_register_socket(info, AF_INET, 0, NULL);
26a25c
 	/* If this is a normal IPv4 address, get the hardware address. */
26a25c
 	if (strcmp(info->name, "fallback") != 0)
26a25c
-		get_hw_addr(info->name, &info->hw_address);
26a25c
+		get_hw_addr(info);
26a25c
 #if defined (USE_SOCKET_FALLBACK)
26a25c
 	/* Fallback only registers for send, but may need to receive as
26a25c
 	   well. */
26a25c
@@ -391,7 +391,7 @@ void if_register_receive (info)
26a25c
 #endif /* IP_PKTINFO... */
26a25c
 	/* If this is a normal IPv4 address, get the hardware address. */
26a25c
 	if (strcmp(info->name, "fallback") != 0)
26a25c
-		get_hw_addr(info->name, &info->hw_address);
26a25c
+		get_hw_addr(info);
26a25c
 
26a25c
 	if (!quiet_interface_discovery)
26a25c
 		log_info ("Listening on Socket/%s%s%s",
26a25c
@@ -505,7 +505,7 @@ if_register6(struct interface_info *info
26a25c
 	if (req_multi)
26a25c
 		if_register_multicast(info);
26a25c
 
26a25c
-	get_hw_addr(info->name, &info->hw_address);
26a25c
+	get_hw_addr(info);
26a25c
 
26a25c
 	if (!quiet_interface_discovery) {
26a25c
 		if (info->shared_network != NULL) {
26a25c
@@ -561,7 +561,7 @@ if_register_linklocal6(struct interface_
26a25c
 	info->rfdesc = sock;
26a25c
 	info->wfdesc = sock;
26a25c
 
26a25c
-	get_hw_addr(info->name, &info->hw_address);
26a25c
+	get_hw_addr(info);
26a25c
 
26a25c
 	if (!quiet_interface_discovery) {
26a25c
 		if (info->shared_network != NULL) {
26a25c
diff -up dhcp-4.3.4/includes/dhcpd.h.lpf-ib dhcp-4.3.4/includes/dhcpd.h
26a25c
--- dhcp-4.3.4/includes/dhcpd.h.lpf-ib	2016-05-02 14:37:36.948128002 +0200
26a25c
+++ dhcp-4.3.4/includes/dhcpd.h	2016-05-02 14:37:36.954128006 +0200
26a25c
@@ -482,6 +482,9 @@ struct packet {
26a25c
 
26a25c
 #define HARDWARE_ADDR_LEN 20
26a25c
 
26a25c
+/* ioctl limits hardware addresses to 8 bytes */
26a25c
+#define HARDWARE_ADDR_LEN_IOCTL	8
26a25c
+
26a25c
 struct hardware {
26a25c
 	u_int8_t hlen;
26a25c
 	u_int8_t hbuf[HARDWARE_ADDR_LEN + 1];
26a25c
@@ -1343,6 +1346,7 @@ struct interface_info {
26a25c
 	struct shared_network *shared_network;
26a25c
 				/* Networks connected to this interface. */
26a25c
 	struct hardware hw_address;	/* Its physical address. */
26a25c
+	u_int8_t bcast_addr[20];	/* Infiniband broadcast address */
26a25c
 	struct in_addr *addresses;	/* Addresses associated with this
26a25c
 					 * interface.
26a25c
 					 */
26a25c
@@ -2580,7 +2584,7 @@ void print_dns_status (int, struct dhcp_
26a25c
 #endif
26a25c
 const char *print_time(TIME);
26a25c
 
26a25c
-void get_hw_addr(const char *name, struct hardware *hw);
26a25c
+void get_hw_addr(struct interface_info *info);
26a25c
 char *buf_to_hex (const unsigned char *s, unsigned len,
26a25c
                    const char *file, int line);
26a25c
 char *format_lease_id(const unsigned char *s, unsigned len, int format,