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

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