*/
#include "includes.h"
-#include "interfaces.h"
+#include "lib/socket/interfaces.h"
+#include "librpc/gen_ndr/ioctl.h"
static struct iface_struct *probed_ifaces;
static int total_probed;
char addr[INET6_ADDRSTRLEN];
struct interface *iface;
- if (iface_find((struct sockaddr *)&ifs->ip, False)) {
+ if (iface_find((const struct sockaddr *)&ifs->ip, False)) {
DEBUG(3,("add_interface: not adding duplicate interface %s\n",
print_sockaddr(addr, sizeof(addr), &ifs->ip) ));
return;
iface->ip = ifs->ip;
iface->netmask = ifs->netmask;
iface->bcast = ifs->bcast;
+ iface->linkspeed = ifs->linkspeed;
+ iface->capability = ifs->capability;
+ iface->if_index = ifs->if_index;
DLIST_ADD(local_interfaces, iface);
&iface->netmask) ));
}
+
+static void parse_extra_info(char *key, uint64_t *speed, uint32_t *cap,
+ uint32_t *if_index)
+{
+ while (key != NULL && *key != '\0') {
+ char *next_key;
+ char *val;
+
+ next_key = strchr_m(key, ',');
+ if (next_key != NULL) {
+ *next_key++ = 0;
+ }
+
+ val = strchr_m(key, '=');
+ if (val != NULL) {
+ *val++ = 0;
+
+ if (strequal_m(key, "speed")) {
+ *speed = (uint64_t)strtoull(val, NULL, 0);
+ } else if (strequal_m(key, "capability")) {
+ if (strequal_m(val, "RSS")) {
+ *cap |= FSCTL_NET_IFACE_RSS_CAPABLE;
+ } else if (strequal(val, "RDMA")) {
+ *cap |= FSCTL_NET_IFACE_RDMA_CAPABLE;
+ } else {
+ DBG_WARNING("Capability unknown: "
+ "'%s'\n", val);
+ }
+ } else if (strequal_m(key, "if_index")) {
+ *if_index = (uint32_t)strtoul(val, NULL, 0);
+ } else {
+ DBG_DEBUG("Key unknown: '%s'\n", key);
+ }
+ }
+
+ key = next_key;
+ }
+}
+
/****************************************************************************
Interpret a single element from a interfaces= config line.
3) IP/masklen
4) ip/mask
5) bcast/mask
+
+ Additional information for an interface can be specified with
+ this extended syntax:
+
+ interface[;key1=value1[,key2=value2[...]]]
+
+ where
+ - keys known: 'speed', 'capability', 'if_index'
+ - speed is in bits per second
+ - capabilites known: 'RSS', 'RDMA'
+ - if_index should be used with care, because
+ these indexes should not conicide with indexes
+ the kernel sets...
+
****************************************************************************/
static void interpret_interface(char *token)
int i;
bool added=false;
bool goodaddr = false;
+ uint64_t speed = 0;
+ uint32_t cap = FSCTL_NET_IFACE_NONE_CAPABLE;
+ uint32_t if_index = 0;
+ bool speed_set = false;
+ bool cap_set = false;
+ bool if_index_set = false;
/* first check if it is an interface name */
for (i=0;i<total_probed;i++) {
return;
}
- /* maybe it is a DNS name */
+ /*
+ * extract speed / capability information if present
+ */
+ p = strchr_m(token, ';');
+ if (p != NULL) {
+ *p++ = 0;
+ parse_extra_info(p, &speed, &cap, &if_index);
+ if (speed != 0) {
+ speed_set = true;
+ }
+ if (cap != FSCTL_NET_IFACE_NONE_CAPABLE) {
+ cap_set = true;
+ }
+ if (if_index != 0) {
+ if_index_set = true;
+ }
+ }
+
p = strchr_m(token,'/');
if (p == NULL) {
if (!interpret_string_addr(&ss, token, 0)) {
}
for (i=0;i<total_probed;i++) {
- if (sockaddr_equal((struct sockaddr *)&ss, (struct sockaddr *)&probed_ifaces[i].ip)) {
+ if (sockaddr_equal((struct sockaddr *)&ss,
+ (struct sockaddr *)&probed_ifaces[i].ip))
+ {
+ if (speed_set) {
+ probed_ifaces[i].linkspeed = speed;
+ }
+ if (cap_set) {
+ probed_ifaces[i].capability = cap;
+ }
+ if (if_index_set) {
+ probed_ifaces[i].if_index = if_index;
+ }
add_interface(&probed_ifaces[i]);
return;
}
"config file on interface %s\n",
p,
probed_ifaces[i].name));
+ if (speed_set) {
+ probed_ifaces[i].linkspeed = speed;
+ }
+ if (cap_set) {
+ probed_ifaces[i].capability = cap;
+ }
+ if (if_index_set) {
+ probed_ifaces[i].if_index = if_index;
+ }
add_interface(&probed_ifaces[i]);
probed_ifaces[i].netmask = saved_mask;
return;
ifs.ip = ss;
ifs.netmask = ss_mask;
ifs.bcast = ss_bcast;
+ if (if_index_set) {
+ probed_ifaces[i].if_index = if_index;
+ }
+ if (speed_set) {
+ ifs.linkspeed = speed;
+ } else {
+ ifs.linkspeed = 1000 * 1000 * 1000;
+ }
+ ifs.capability = cap;
add_interface(&ifs);
}
total_probed = get_interfaces(talloc_tos(), &ifaces);
if (total_probed > 0) {
- probed_ifaces = (struct iface_struct *)memdup(ifaces,
+ probed_ifaces = (struct iface_struct *)smb_memdup(ifaces,
sizeof(ifaces[0])*total_probed);
if (!probed_ifaces) {
- DEBUG(0,("ERROR: memdup failed\n"));
+ DEBUG(0,("ERROR: smb_memdup failed\n"));
exit(1);
}
}