Blame SOURCES/dhcp-lpf-ib.patch

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