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