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