|
|
f9ed25 |
From 042082b4410f158ec86ca8478689b34bc12518e6 Mon Sep 17 00:00:00 2001
|
|
|
f9ed25 |
From: Pavel Zhukov <pzhukov@redhat.com>
|
|
|
f9ed25 |
Date: Thu, 21 Feb 2019 10:34:21 +0100
|
|
|
f9ed25 |
Subject: [PATCH 14/27] IPoIB support (#660681)
|
|
|
f9ed25 |
Cc: pzhukov@redhat.com
|
|
|
f9ed25 |
|
|
|
f9ed25 |
(Submitted to dhcp-bugs@isc.org - [ISC-Bugs #24249])
|
|
|
f9ed25 |
---
|
|
|
f9ed25 |
client/dhclient.c | 32 ++++++
|
|
|
f9ed25 |
common/bpf.c | 32 ++++++
|
|
|
f9ed25 |
common/discover.c | 4 +-
|
|
|
f9ed25 |
common/lpf.c | 276 ++++++++++++++++++++++++++++++++++++++++++----
|
|
|
f9ed25 |
common/socket.c | 8 +-
|
|
|
f9ed25 |
includes/dhcpd.h | 6 +-
|
|
|
f9ed25 |
6 files changed, 329 insertions(+), 29 deletions(-)
|
|
|
f9ed25 |
|
|
|
f9ed25 |
diff --git a/client/dhclient.c b/client/dhclient.c
|
|
|
f9ed25 |
index 301132c..dc9080e 100644
|
|
|
f9ed25 |
--- a/client/dhclient.c
|
|
|
f9ed25 |
+++ b/client/dhclient.c
|
|
|
f9ed25 |
@@ -205,6 +205,8 @@ static const char use_v6command[] = "Command not used for DHCPv4: %s";
|
|
|
f9ed25 |
|
|
|
f9ed25 |
#define DHCLIENT_USAGEH "{--version|--help|-h}"
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+static void setup_ib_interface(struct interface_info *ip);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
static void
|
|
|
f9ed25 |
usage(const char *sfmt, const char *sarg)
|
|
|
f9ed25 |
{
|
|
|
f9ed25 |
@@ -1191,6 +1193,13 @@ main(int argc, char **argv) {
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
srandom(seed + cur_time + (unsigned)getpid());
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+ /* Setup specific Infiniband options */
|
|
|
f9ed25 |
+ for (ip = interfaces; ip; ip = ip->next) {
|
|
|
f9ed25 |
+ if (ip->client &&
|
|
|
f9ed25 |
+ (ip->hw_address.hbuf[0] == HTYPE_INFINIBAND)) {
|
|
|
f9ed25 |
+ setup_ib_interface(ip);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
|
|
|
f9ed25 |
/*
|
|
|
f9ed25 |
* Establish a default DUID. We always do so for v6 and
|
|
|
f9ed25 |
@@ -1486,6 +1495,29 @@ int find_subnet (struct subnet **sp,
|
|
|
f9ed25 |
return 0;
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+static void setup_ib_interface(struct interface_info *ip)
|
|
|
f9ed25 |
+{
|
|
|
f9ed25 |
+ struct group *g;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* Set the broadcast flag */
|
|
|
f9ed25 |
+ ip->client->config->bootp_broadcast_always = 1;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /*
|
|
|
f9ed25 |
+ * Find out if a dhcp-client-identifier option was specified either
|
|
|
f9ed25 |
+ * in the config file or on the command line
|
|
|
f9ed25 |
+ */
|
|
|
f9ed25 |
+ for (g = ip->client->config->on_transmission; g != NULL; g = g->next) {
|
|
|
f9ed25 |
+ if ((g->statements != NULL) &&
|
|
|
f9ed25 |
+ (strcmp(g->statements->data.option->option->name,
|
|
|
f9ed25 |
+ "dhcp-client-identifier") == 0)) {
|
|
|
f9ed25 |
+ return;
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* No client ID specified */
|
|
|
f9ed25 |
+ log_fatal("dhcp-client-identifier must be specified for InfiniBand");
|
|
|
f9ed25 |
+}
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
/* Individual States:
|
|
|
f9ed25 |
*
|
|
|
f9ed25 |
* Each routine is called from the dhclient_state_machine() in one of
|
|
|
f9ed25 |
diff --git a/common/bpf.c b/common/bpf.c
|
|
|
f9ed25 |
index ffbd09a..568e3d9 100644
|
|
|
f9ed25 |
--- a/common/bpf.c
|
|
|
f9ed25 |
+++ b/common/bpf.c
|
|
|
f9ed25 |
@@ -237,11 +237,43 @@ int dhcp_bpf_relay_filter_len =
|
|
|
f9ed25 |
sizeof dhcp_bpf_relay_filter / sizeof (struct bpf_insn);
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+/* Packet filter program for DHCP over Infiniband.
|
|
|
f9ed25 |
+ *
|
|
|
f9ed25 |
+ * XXX
|
|
|
f9ed25 |
+ * Changes to the filter program may require changes to the constant offsets
|
|
|
f9ed25 |
+ * used in lpf_gen_filter_setup to patch the port in the BPF program!
|
|
|
f9ed25 |
+ * XXX
|
|
|
f9ed25 |
+ */
|
|
|
f9ed25 |
+struct bpf_insn dhcp_ib_bpf_filter [] = {
|
|
|
f9ed25 |
+ /* Packet filter for Infiniband */
|
|
|
f9ed25 |
+ /* Make sure it's a UDP packet... */
|
|
|
f9ed25 |
+ BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 9),
|
|
|
f9ed25 |
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6),
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* Make sure this isn't a fragment... */
|
|
|
f9ed25 |
+ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 6),
|
|
|
f9ed25 |
+ BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0),
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* Get the IP header length... */
|
|
|
f9ed25 |
+ BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 0),
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* Make sure it's to the right port... */
|
|
|
f9ed25 |
+ BPF_STMT(BPF_LD + BPF_H + BPF_IND, 2),
|
|
|
f9ed25 |
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1),
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* If we passed all the tests, ask for the whole packet. */
|
|
|
f9ed25 |
+ BPF_STMT(BPF_RET + BPF_K, (u_int)-1),
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* Otherwise, drop it. */
|
|
|
f9ed25 |
+ BPF_STMT(BPF_RET + BPF_K, 0),
|
|
|
f9ed25 |
+};
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
#if defined (DEC_FDDI)
|
|
|
f9ed25 |
struct bpf_insn *bpf_fddi_filter = NULL;
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
|
|
|
f9ed25 |
int dhcp_bpf_filter_len = sizeof dhcp_bpf_filter / sizeof (struct bpf_insn);
|
|
|
f9ed25 |
+int dhcp_ib_bpf_filter_len = sizeof dhcp_ib_bpf_filter / sizeof (struct bpf_insn);
|
|
|
f9ed25 |
#if defined (HAVE_TR_SUPPORT)
|
|
|
f9ed25 |
struct bpf_insn dhcp_bpf_tr_filter [] = {
|
|
|
f9ed25 |
/* accept all token ring packets due to variable length header */
|
|
|
f9ed25 |
diff --git a/common/discover.c b/common/discover.c
|
|
|
f9ed25 |
index 6ef8852..65881fc 100644
|
|
|
f9ed25 |
--- a/common/discover.c
|
|
|
f9ed25 |
+++ b/common/discover.c
|
|
|
f9ed25 |
@@ -894,7 +894,7 @@ discover_interfaces(int state) {
|
|
|
f9ed25 |
if_register_send(tmp);
|
|
|
f9ed25 |
} else {
|
|
|
f9ed25 |
/* get_hw_addr() was called by register. */
|
|
|
f9ed25 |
- get_hw_addr(tmp->name, &tmp->hw_address);
|
|
|
f9ed25 |
+ get_hw_addr(tmp);
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
break;
|
|
|
f9ed25 |
#ifdef DHCPv6
|
|
|
f9ed25 |
@@ -907,7 +907,7 @@ discover_interfaces(int state) {
|
|
|
f9ed25 |
so now we have to call it explicitly
|
|
|
f9ed25 |
to not leave the hardware address unknown
|
|
|
f9ed25 |
(some code expects it cannot be. */
|
|
|
f9ed25 |
- get_hw_addr(tmp->name, &tmp->hw_address);
|
|
|
f9ed25 |
+ get_hw_addr(tmp);
|
|
|
f9ed25 |
} else {
|
|
|
f9ed25 |
if_register_linklocal6(tmp);
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
diff --git a/common/lpf.c b/common/lpf.c
|
|
|
f9ed25 |
index b0ed01c..a9e19f4 100644
|
|
|
f9ed25 |
--- a/common/lpf.c
|
|
|
f9ed25 |
+++ b/common/lpf.c
|
|
|
f9ed25 |
@@ -45,6 +45,17 @@
|
|
|
f9ed25 |
#include <sys/ioctl.h>
|
|
|
f9ed25 |
#include <sys/socket.h>
|
|
|
f9ed25 |
#include <net/if.h>
|
|
|
f9ed25 |
+#include <ifaddrs.h>
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+/* Default broadcast address for IPoIB */
|
|
|
f9ed25 |
+static unsigned char default_ib_bcast_addr[20] = {
|
|
|
f9ed25 |
+ 0x00, 0xff, 0xff, 0xff,
|
|
|
f9ed25 |
+ 0xff, 0x12, 0x40, 0x1b,
|
|
|
f9ed25 |
+ 0x00, 0x00, 0x00, 0x00,
|
|
|
f9ed25 |
+ 0x00, 0x00, 0x00, 0x00,
|
|
|
f9ed25 |
+ 0xff, 0xff, 0xff, 0xff
|
|
|
f9ed25 |
+};
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
|
|
|
f9ed25 |
#if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
|
|
|
f9ed25 |
@@ -78,10 +89,20 @@ int if_register_lpf (info)
|
|
|
f9ed25 |
struct sockaddr common;
|
|
|
f9ed25 |
} sa;
|
|
|
f9ed25 |
struct ifreq ifr;
|
|
|
f9ed25 |
+ int type;
|
|
|
f9ed25 |
+ int protocol;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ get_hw_addr(info);
|
|
|
f9ed25 |
+ if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
|
|
|
f9ed25 |
+ type = SOCK_DGRAM;
|
|
|
f9ed25 |
+ protocol = ETHERTYPE_IP;
|
|
|
f9ed25 |
+ } else {
|
|
|
f9ed25 |
+ type = SOCK_RAW;
|
|
|
f9ed25 |
+ protocol = ETH_P_ALL;
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
|
|
|
f9ed25 |
/* Make an LPF socket. */
|
|
|
f9ed25 |
- if ((sock = socket(PF_PACKET, SOCK_RAW,
|
|
|
f9ed25 |
- htons((short)ETH_P_ALL))) < 0) {
|
|
|
f9ed25 |
+ if ((sock = socket(PF_PACKET, type, htons((short)protocol))) < 0) {
|
|
|
f9ed25 |
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
|
|
|
f9ed25 |
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
|
|
|
f9ed25 |
errno == EAFNOSUPPORT || errno == EINVAL) {
|
|
|
f9ed25 |
@@ -104,6 +125,7 @@ int if_register_lpf (info)
|
|
|
f9ed25 |
/* Bind to the interface name */
|
|
|
f9ed25 |
memset (&sa, 0, sizeof sa);
|
|
|
f9ed25 |
sa.ll.sll_family = AF_PACKET;
|
|
|
f9ed25 |
+ sa.ll.sll_protocol = htons(protocol);
|
|
|
f9ed25 |
sa.ll.sll_ifindex = ifr.ifr_ifindex;
|
|
|
f9ed25 |
if (bind (sock, &sa.common, sizeof sa)) {
|
|
|
f9ed25 |
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
|
|
|
f9ed25 |
@@ -120,8 +142,6 @@ int if_register_lpf (info)
|
|
|
f9ed25 |
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
|
|
|
f9ed25 |
- get_hw_addr(info->name, &info->hw_address);
|
|
|
f9ed25 |
-
|
|
|
f9ed25 |
return sock;
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
#endif /* USE_LPF_SEND || USE_LPF_RECEIVE */
|
|
|
f9ed25 |
@@ -176,6 +196,8 @@ void if_deregister_send (info)
|
|
|
f9ed25 |
in bpf includes... */
|
|
|
f9ed25 |
extern struct sock_filter dhcp_bpf_filter [];
|
|
|
f9ed25 |
extern int dhcp_bpf_filter_len;
|
|
|
f9ed25 |
+extern struct sock_filter dhcp_ib_bpf_filter [];
|
|
|
f9ed25 |
+extern int dhcp_ib_bpf_filter_len;
|
|
|
f9ed25 |
|
|
|
f9ed25 |
#if defined(RELAY_PORT)
|
|
|
f9ed25 |
extern struct sock_filter dhcp_bpf_relay_filter [];
|
|
|
f9ed25 |
@@ -199,11 +221,12 @@ void if_register_receive (info)
|
|
|
f9ed25 |
#ifdef PACKET_AUXDATA
|
|
|
f9ed25 |
{
|
|
|
f9ed25 |
int val = 1;
|
|
|
f9ed25 |
-
|
|
|
f9ed25 |
- if (setsockopt(info->rfdesc, SOL_PACKET, PACKET_AUXDATA,
|
|
|
f9ed25 |
- &val, sizeof(val)) < 0) {
|
|
|
f9ed25 |
- if (errno != ENOPROTOOPT) {
|
|
|
f9ed25 |
- log_fatal ("Failed to set auxiliary packet data: %m");
|
|
|
f9ed25 |
+ if (info->hw_address.hbuf[0] != HTYPE_INFINIBAND) {
|
|
|
f9ed25 |
+ if (setsockopt(info->rfdesc, SOL_PACKET, PACKET_AUXDATA,
|
|
|
f9ed25 |
+ &val, sizeof(val)) < 0) {
|
|
|
f9ed25 |
+ if (errno != ENOPROTOOPT) {
|
|
|
f9ed25 |
+ log_fatal ("Failed to set auxiliary packet data: %m");
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
@@ -253,6 +276,18 @@ static void lpf_gen_filter_setup (info)
|
|
|
f9ed25 |
|
|
|
f9ed25 |
memset(&p, 0, sizeof(p));
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+ if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
|
|
|
f9ed25 |
+ p.len = dhcp_ib_bpf_filter_len;
|
|
|
f9ed25 |
+ p.filter = dhcp_ib_bpf_filter;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* Patch the server port into the LPF program...
|
|
|
f9ed25 |
+ XXX
|
|
|
f9ed25 |
+ changes to filter program may require changes
|
|
|
f9ed25 |
+ to the insn number(s) used below!
|
|
|
f9ed25 |
+ XXX */
|
|
|
f9ed25 |
+ dhcp_ib_bpf_filter[6].k = ntohs (local_port);
|
|
|
f9ed25 |
+ } else {
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
/* Set up the bpf filter program structure. This is defined in
|
|
|
f9ed25 |
bpf.c */
|
|
|
f9ed25 |
p.len = dhcp_bpf_filter_len;
|
|
|
f9ed25 |
@@ -275,6 +310,8 @@ static void lpf_gen_filter_setup (info)
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
dhcp_bpf_filter [8].k = ntohs (local_port);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
|
|
|
f9ed25 |
sizeof p) < 0) {
|
|
|
f9ed25 |
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
|
|
|
f9ed25 |
@@ -330,6 +367,54 @@ static void lpf_tr_filter_setup (info)
|
|
|
f9ed25 |
#endif /* USE_LPF_RECEIVE */
|
|
|
f9ed25 |
|
|
|
f9ed25 |
#ifdef USE_LPF_SEND
|
|
|
f9ed25 |
+ssize_t send_packet_ib(interface, packet, raw, len, from, to, hto)
|
|
|
f9ed25 |
+ struct interface_info *interface;
|
|
|
f9ed25 |
+ struct packet *packet;
|
|
|
f9ed25 |
+ struct dhcp_packet *raw;
|
|
|
f9ed25 |
+ size_t len;
|
|
|
f9ed25 |
+ struct in_addr from;
|
|
|
f9ed25 |
+ struct sockaddr_in *to;
|
|
|
f9ed25 |
+ struct hardware *hto;
|
|
|
f9ed25 |
+{
|
|
|
f9ed25 |
+ unsigned ibufp = 0;
|
|
|
f9ed25 |
+ double ih [1536 / sizeof (double)];
|
|
|
f9ed25 |
+ unsigned char *buf = (unsigned char *)ih;
|
|
|
f9ed25 |
+ ssize_t result;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ union sockunion {
|
|
|
f9ed25 |
+ struct sockaddr sa;
|
|
|
f9ed25 |
+ struct sockaddr_ll sll;
|
|
|
f9ed25 |
+ struct sockaddr_storage ss;
|
|
|
f9ed25 |
+ } su;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ assemble_udp_ip_header (interface, buf, &ibufp, from.s_addr,
|
|
|
f9ed25 |
+ to->sin_addr.s_addr, to->sin_port,
|
|
|
f9ed25 |
+ (unsigned char *)raw, len);
|
|
|
f9ed25 |
+ memcpy (buf + ibufp, raw, len);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ memset(&su, 0, sizeof(su));
|
|
|
f9ed25 |
+ su.sll.sll_family = AF_PACKET;
|
|
|
f9ed25 |
+ su.sll.sll_protocol = htons(ETHERTYPE_IP);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (!(su.sll.sll_ifindex = if_nametoindex(interface->name))) {
|
|
|
f9ed25 |
+ errno = ENOENT;
|
|
|
f9ed25 |
+ log_error ("send_packet_ib: %m - failed to get if index");
|
|
|
f9ed25 |
+ return -1;
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ su.sll.sll_hatype = htons(HTYPE_INFINIBAND);
|
|
|
f9ed25 |
+ su.sll.sll_halen = sizeof(interface->bcast_addr);
|
|
|
f9ed25 |
+ memcpy(&su.sll.sll_addr, interface->bcast_addr, 20);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ result = sendto(interface->wfdesc, buf, ibufp + len, 0,
|
|
|
f9ed25 |
+ &su.sa, sizeof(su));
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (result < 0)
|
|
|
f9ed25 |
+ log_error ("send_packet_ib: %m");
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ return result;
|
|
|
f9ed25 |
+}
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
ssize_t send_packet (interface, packet, raw, len, from, to, hto)
|
|
|
f9ed25 |
struct interface_info *interface;
|
|
|
f9ed25 |
struct packet *packet;
|
|
|
f9ed25 |
@@ -350,6 +435,11 @@ ssize_t send_packet (interface, packet, raw, len, from, to, hto)
|
|
|
f9ed25 |
return send_fallback (interface, packet, raw,
|
|
|
f9ed25 |
len, from, to, hto);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+ if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
|
|
|
f9ed25 |
+ return send_packet_ib(interface, packet, raw, len, from,
|
|
|
f9ed25 |
+ to, hto);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
if (hto == NULL && interface->anycast_mac_addr.hlen)
|
|
|
f9ed25 |
hto = &interface->anycast_mac_addr;
|
|
|
f9ed25 |
|
|
|
f9ed25 |
@@ -370,6 +460,42 @@ ssize_t send_packet (interface, packet, raw, len, from, to, hto)
|
|
|
f9ed25 |
#endif /* USE_LPF_SEND */
|
|
|
f9ed25 |
|
|
|
f9ed25 |
#ifdef USE_LPF_RECEIVE
|
|
|
f9ed25 |
+ssize_t receive_packet_ib (interface, buf, len, from, hfrom)
|
|
|
f9ed25 |
+ struct interface_info *interface;
|
|
|
f9ed25 |
+ unsigned char *buf;
|
|
|
f9ed25 |
+ size_t len;
|
|
|
f9ed25 |
+ struct sockaddr_in *from;
|
|
|
f9ed25 |
+ struct hardware *hfrom;
|
|
|
f9ed25 |
+{
|
|
|
f9ed25 |
+ int length = 0;
|
|
|
f9ed25 |
+ int offset = 0;
|
|
|
f9ed25 |
+ unsigned char ibuf [1536];
|
|
|
f9ed25 |
+ unsigned bufix = 0;
|
|
|
f9ed25 |
+ unsigned paylen;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ length = read(interface->rfdesc, ibuf, sizeof(ibuf));
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (length <= 0)
|
|
|
f9ed25 |
+ return length;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ offset = decode_udp_ip_header(interface, ibuf, bufix, from,
|
|
|
f9ed25 |
+ (unsigned)length, &paylen, 0);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (offset < 0)
|
|
|
f9ed25 |
+ return 0;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ bufix += offset;
|
|
|
f9ed25 |
+ length -= offset;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (length < paylen)
|
|
|
f9ed25 |
+ log_fatal("Internal inconsistency at %s:%d.", MDL);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* Copy out the data in the packet... */
|
|
|
f9ed25 |
+ memcpy(buf, &ibuf[bufix], paylen);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ return (ssize_t)paylen;
|
|
|
f9ed25 |
+}
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
ssize_t receive_packet (interface, buf, len, from, hfrom)
|
|
|
f9ed25 |
struct interface_info *interface;
|
|
|
f9ed25 |
unsigned char *buf;
|
|
|
f9ed25 |
@@ -408,6 +534,10 @@ ssize_t receive_packet (interface, buf, len, from, hfrom)
|
|
|
f9ed25 |
};
|
|
|
f9ed25 |
#endif /* PACKET_AUXDATA */
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+ if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
|
|
|
f9ed25 |
+ return receive_packet_ib(interface, buf, len, from, hfrom);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
length = recvmsg (interface->rfdesc, &msg, 0);
|
|
|
f9ed25 |
if (length <= 0)
|
|
|
f9ed25 |
return length;
|
|
|
f9ed25 |
@@ -521,11 +651,33 @@ void maybe_setup_fallback ()
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
|
|
|
f9ed25 |
#if defined (USE_LPF_RECEIVE) || defined (USE_LPF_HWADDR)
|
|
|
f9ed25 |
-void
|
|
|
f9ed25 |
-get_hw_addr(const char *name, struct hardware *hw) {
|
|
|
f9ed25 |
+struct sockaddr_ll *
|
|
|
f9ed25 |
+get_ll (struct ifaddrs *ifaddrs, struct ifaddrs **ifa, char *name)
|
|
|
f9ed25 |
+{
|
|
|
f9ed25 |
+ for (*ifa = ifaddrs; *ifa != NULL; *ifa = (*ifa)->ifa_next) {
|
|
|
f9ed25 |
+ if ((*ifa)->ifa_addr == NULL)
|
|
|
f9ed25 |
+ continue;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if ((*ifa)->ifa_addr->sa_family != AF_PACKET)
|
|
|
f9ed25 |
+ continue;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if ((*ifa)->ifa_flags & IFF_LOOPBACK)
|
|
|
f9ed25 |
+ continue;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (strcmp((*ifa)->ifa_name, name) == 0)
|
|
|
f9ed25 |
+ return (struct sockaddr_ll *)(void *)(*ifa)->ifa_addr;
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ *ifa = NULL;
|
|
|
f9ed25 |
+ return NULL;
|
|
|
f9ed25 |
+}
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+struct sockaddr_ll *
|
|
|
f9ed25 |
+ioctl_get_ll(char *name)
|
|
|
f9ed25 |
+{
|
|
|
f9ed25 |
int sock;
|
|
|
f9ed25 |
struct ifreq tmp;
|
|
|
f9ed25 |
- struct sockaddr *sa;
|
|
|
f9ed25 |
+ struct sockaddr *sa = NULL;
|
|
|
f9ed25 |
+ struct sockaddr_ll *sll = NULL;
|
|
|
f9ed25 |
|
|
|
f9ed25 |
if (strlen(name) >= sizeof(tmp.ifr_name)) {
|
|
|
f9ed25 |
log_fatal("Device name too long: \"%s\"", name);
|
|
|
f9ed25 |
@@ -539,16 +691,61 @@ get_hw_addr(const char *name, struct hardware *hw) {
|
|
|
f9ed25 |
memset(&tmp, 0, sizeof(tmp));
|
|
|
f9ed25 |
strcpy(tmp.ifr_name, name);
|
|
|
f9ed25 |
if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) {
|
|
|
f9ed25 |
- log_fatal("Error getting hardware address for \"%s\": %m",
|
|
|
f9ed25 |
+ log_fatal("Error getting hardware address for \"%s\": %m",
|
|
|
f9ed25 |
name);
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
+ close(sock);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
sa = &tmp.ifr_hwaddr;
|
|
|
f9ed25 |
- switch (sa->sa_family) {
|
|
|
f9ed25 |
+ // needs to be freed outside this function
|
|
|
f9ed25 |
+ sll = dmalloc (sizeof (struct sockaddr_ll), MDL);
|
|
|
f9ed25 |
+ if (!sll)
|
|
|
f9ed25 |
+ log_fatal("Unable to allocate memory for link layer address");
|
|
|
f9ed25 |
+ memcpy(&sll->sll_hatype, &sa->sa_family, sizeof (sll->sll_hatype));
|
|
|
f9ed25 |
+ memcpy(sll->sll_addr, sa->sa_data, sizeof (sll->sll_addr));
|
|
|
f9ed25 |
+ switch (sll->sll_hatype) {
|
|
|
f9ed25 |
+ case ARPHRD_INFINIBAND:
|
|
|
f9ed25 |
+ sll->sll_halen = HARDWARE_ADDR_LEN_IOCTL;
|
|
|
f9ed25 |
+ break;
|
|
|
f9ed25 |
+ default:
|
|
|
f9ed25 |
+ break;
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ return sll;
|
|
|
f9ed25 |
+}
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+void
|
|
|
f9ed25 |
+get_hw_addr(struct interface_info *info)
|
|
|
f9ed25 |
+{
|
|
|
f9ed25 |
+ struct hardware *hw = &info->hw_address;
|
|
|
f9ed25 |
+ char *name = info->name;
|
|
|
f9ed25 |
+ struct ifaddrs *ifaddrs = NULL;
|
|
|
f9ed25 |
+ struct ifaddrs *ifa = NULL;
|
|
|
f9ed25 |
+ struct sockaddr_ll *sll = NULL;
|
|
|
f9ed25 |
+ int sll_allocated = 0;
|
|
|
f9ed25 |
+ char *dup = NULL;
|
|
|
f9ed25 |
+ char *colon = NULL;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (getifaddrs(&ifaddrs) == -1)
|
|
|
f9ed25 |
+ log_fatal("Failed to get interfaces");
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if ((sll = get_ll(ifaddrs, &ifa, name)) == NULL) {
|
|
|
f9ed25 |
+ /*
|
|
|
f9ed25 |
+ * We were unable to get link-layer address for name.
|
|
|
f9ed25 |
+ * Fall back to ioctl(SIOCGIFHWADDR).
|
|
|
f9ed25 |
+ */
|
|
|
f9ed25 |
+ sll = ioctl_get_ll(name);
|
|
|
f9ed25 |
+ if (sll != NULL)
|
|
|
f9ed25 |
+ sll_allocated = 1;
|
|
|
f9ed25 |
+ else
|
|
|
f9ed25 |
+ // shouldn't happen
|
|
|
f9ed25 |
+ log_fatal("Unexpected internal error");
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ switch (sll->sll_hatype) {
|
|
|
f9ed25 |
case ARPHRD_ETHER:
|
|
|
f9ed25 |
hw->hlen = 7;
|
|
|
f9ed25 |
hw->hbuf[0] = HTYPE_ETHER;
|
|
|
f9ed25 |
- memcpy(&hw->hbuf[1], sa->sa_data, 6);
|
|
|
f9ed25 |
+ memcpy(&hw->hbuf[1], sll->sll_addr, 6);
|
|
|
f9ed25 |
break;
|
|
|
f9ed25 |
case ARPHRD_IEEE802:
|
|
|
f9ed25 |
#ifdef ARPHRD_IEEE802_TR
|
|
|
f9ed25 |
@@ -556,18 +753,50 @@ get_hw_addr(const char *name, struct hardware *hw) {
|
|
|
f9ed25 |
#endif /* ARPHRD_IEEE802_TR */
|
|
|
f9ed25 |
hw->hlen = 7;
|
|
|
f9ed25 |
hw->hbuf[0] = HTYPE_IEEE802;
|
|
|
f9ed25 |
- memcpy(&hw->hbuf[1], sa->sa_data, 6);
|
|
|
f9ed25 |
+ memcpy(&hw->hbuf[1], sll->sll_addr, 6);
|
|
|
f9ed25 |
break;
|
|
|
f9ed25 |
case ARPHRD_FDDI:
|
|
|
f9ed25 |
hw->hlen = 7;
|
|
|
f9ed25 |
hw->hbuf[0] = HTYPE_FDDI;
|
|
|
f9ed25 |
- memcpy(&hw->hbuf[1], sa->sa_data, 6);
|
|
|
f9ed25 |
+ memcpy(&hw->hbuf[1], sll->sll_addr, 6);
|
|
|
f9ed25 |
+ break;
|
|
|
f9ed25 |
+ case ARPHRD_INFINIBAND:
|
|
|
f9ed25 |
+ dup = strdup(name);
|
|
|
f9ed25 |
+ /* Aliased infiniband interface is special case where
|
|
|
f9ed25 |
+ * neither get_ll() nor ioctl_get_ll() get's correct hw
|
|
|
f9ed25 |
+ * address, so we have to truncate the :0 and run
|
|
|
f9ed25 |
+ * get_ll() again for the rest.
|
|
|
f9ed25 |
+ */
|
|
|
f9ed25 |
+ if ((colon = strchr(dup, ':')) != NULL) {
|
|
|
f9ed25 |
+ *colon = '\0';
|
|
|
f9ed25 |
+ if ((sll = get_ll(ifaddrs, &ifa, dup)) == NULL)
|
|
|
f9ed25 |
+ log_fatal("Error getting hardware address for \"%s\": %m", name);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ free (dup);
|
|
|
f9ed25 |
+ /* For Infiniband, save the broadcast address and store
|
|
|
f9ed25 |
+ * the port GUID into the hardware address.
|
|
|
f9ed25 |
+ */
|
|
|
f9ed25 |
+ if (ifa && (ifa->ifa_flags & IFF_BROADCAST)) {
|
|
|
f9ed25 |
+ struct sockaddr_ll *bll;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ bll = (struct sockaddr_ll *)ifa->ifa_broadaddr;
|
|
|
f9ed25 |
+ memcpy(&info->bcast_addr, bll->sll_addr, 20);
|
|
|
f9ed25 |
+ } else {
|
|
|
f9ed25 |
+ memcpy(&info->bcast_addr, default_ib_bcast_addr,
|
|
|
f9ed25 |
+ 20);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ hw->hlen = HARDWARE_ADDR_LEN_IOCTL + 1;
|
|
|
f9ed25 |
+ hw->hbuf[0] = HTYPE_INFINIBAND;
|
|
|
f9ed25 |
+ memcpy(&hw->hbuf[1],
|
|
|
f9ed25 |
+ &sll->sll_addr[sll->sll_halen - HARDWARE_ADDR_LEN_IOCTL],
|
|
|
f9ed25 |
+ HARDWARE_ADDR_LEN_IOCTL);
|
|
|
f9ed25 |
break;
|
|
|
f9ed25 |
#if defined(ARPHRD_PPP)
|
|
|
f9ed25 |
case ARPHRD_PPP:
|
|
|
f9ed25 |
if (local_family != AF_INET6)
|
|
|
f9ed25 |
- log_fatal("Unsupported device type %d for \"%s\"",
|
|
|
f9ed25 |
- sa->sa_family, name);
|
|
|
f9ed25 |
+ log_fatal("local_family != AF_INET6 for \"%s\"",
|
|
|
f9ed25 |
+ name);
|
|
|
f9ed25 |
hw->hlen = 0;
|
|
|
f9ed25 |
hw->hbuf[0] = HTYPE_RESERVED;
|
|
|
f9ed25 |
/* 0xdeadbeef should never occur on the wire,
|
|
|
f9ed25 |
@@ -580,10 +809,13 @@ get_hw_addr(const char *name, struct hardware *hw) {
|
|
|
f9ed25 |
break;
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
default:
|
|
|
f9ed25 |
- log_fatal("Unsupported device type %ld for \"%s\"",
|
|
|
f9ed25 |
- (long int)sa->sa_family, name);
|
|
|
f9ed25 |
+ freeifaddrs(ifaddrs);
|
|
|
f9ed25 |
+ log_fatal("Unsupported device type %hu for \"%s\"",
|
|
|
f9ed25 |
+ sll->sll_hatype, name);
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
|
|
|
f9ed25 |
- close(sock);
|
|
|
f9ed25 |
+ if (sll_allocated)
|
|
|
f9ed25 |
+ dfree(sll, MDL);
|
|
|
f9ed25 |
+ freeifaddrs(ifaddrs);
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
diff --git a/common/socket.c b/common/socket.c
|
|
|
f9ed25 |
index 483eb9c..6e1caac 100644
|
|
|
f9ed25 |
--- a/common/socket.c
|
|
|
f9ed25 |
+++ b/common/socket.c
|
|
|
f9ed25 |
@@ -350,7 +350,7 @@ void if_register_send (info)
|
|
|
f9ed25 |
info->wfdesc = if_register_socket(info, AF_INET, 0, NULL);
|
|
|
f9ed25 |
/* If this is a normal IPv4 address, get the hardware address. */
|
|
|
f9ed25 |
if (strcmp(info->name, "fallback") != 0)
|
|
|
f9ed25 |
- get_hw_addr(info->name, &info->hw_address);
|
|
|
f9ed25 |
+ get_hw_addr(info);
|
|
|
f9ed25 |
#if defined (USE_SOCKET_FALLBACK)
|
|
|
f9ed25 |
/* Fallback only registers for send, but may need to receive as
|
|
|
f9ed25 |
well. */
|
|
|
f9ed25 |
@@ -413,7 +413,7 @@ void if_register_receive (info)
|
|
|
f9ed25 |
#endif /* IP_PKTINFO... */
|
|
|
f9ed25 |
/* If this is a normal IPv4 address, get the hardware address. */
|
|
|
f9ed25 |
if (strcmp(info->name, "fallback") != 0)
|
|
|
f9ed25 |
- get_hw_addr(info->name, &info->hw_address);
|
|
|
f9ed25 |
+ get_hw_addr(info);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
if (!quiet_interface_discovery)
|
|
|
f9ed25 |
log_info ("Listening on Socket/%s%s%s",
|
|
|
f9ed25 |
@@ -567,7 +567,7 @@ if_register6(struct interface_info *info, int do_multicast) {
|
|
|
f9ed25 |
if (req_multi)
|
|
|
f9ed25 |
if_register_multicast(info);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
- get_hw_addr(info->name, &info->hw_address);
|
|
|
f9ed25 |
+ get_hw_addr(info);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
if (!quiet_interface_discovery) {
|
|
|
f9ed25 |
if (info->shared_network != NULL) {
|
|
|
f9ed25 |
@@ -623,7 +623,7 @@ if_register_linklocal6(struct interface_info *info) {
|
|
|
f9ed25 |
info->rfdesc = sock;
|
|
|
f9ed25 |
info->wfdesc = sock;
|
|
|
f9ed25 |
|
|
|
f9ed25 |
- get_hw_addr(info->name, &info->hw_address);
|
|
|
f9ed25 |
+ get_hw_addr(info);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
if (!quiet_interface_discovery) {
|
|
|
f9ed25 |
if (info->shared_network != NULL) {
|
|
|
f9ed25 |
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
|
|
|
f9ed25 |
index faa9251..0c1a0aa 100644
|
|
|
f9ed25 |
--- a/includes/dhcpd.h
|
|
|
f9ed25 |
+++ b/includes/dhcpd.h
|
|
|
f9ed25 |
@@ -485,6 +485,9 @@ struct packet {
|
|
|
f9ed25 |
|
|
|
f9ed25 |
#define HARDWARE_ADDR_LEN 20
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+/* ioctl limits hardware addresses to 8 bytes */
|
|
|
f9ed25 |
+#define HARDWARE_ADDR_LEN_IOCTL 8
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
struct hardware {
|
|
|
f9ed25 |
u_int8_t hlen;
|
|
|
f9ed25 |
u_int8_t hbuf[HARDWARE_ADDR_LEN + 1];
|
|
|
f9ed25 |
@@ -1365,6 +1368,7 @@ struct interface_info {
|
|
|
f9ed25 |
struct shared_network *shared_network;
|
|
|
f9ed25 |
/* Networks connected to this interface. */
|
|
|
f9ed25 |
struct hardware hw_address; /* Its physical address. */
|
|
|
f9ed25 |
+ u_int8_t bcast_addr[20]; /* Infiniband broadcast address */
|
|
|
f9ed25 |
struct in_addr *addresses; /* Addresses associated with this
|
|
|
f9ed25 |
* interface.
|
|
|
f9ed25 |
*/
|
|
|
f9ed25 |
@@ -2633,7 +2637,7 @@ void print_dns_status (int, struct dhcp_ddns_cb *, isc_result_t);
|
|
|
f9ed25 |
#endif
|
|
|
f9ed25 |
const char *print_time(TIME);
|
|
|
f9ed25 |
|
|
|
f9ed25 |
-void get_hw_addr(const char *name, struct hardware *hw);
|
|
|
f9ed25 |
+void get_hw_addr(struct interface_info *info);
|
|
|
f9ed25 |
char *buf_to_hex (const unsigned char *s, unsigned len,
|
|
|
f9ed25 |
const char *file, int line);
|
|
|
f9ed25 |
char *format_lease_id(const unsigned char *s, unsigned len, int format,
|
|
|
f9ed25 |
--
|
|
|
f9ed25 |
2.26.2
|
|
|
f9ed25 |
|