status = retval;
}
}
+ } else {
+ netdev_classes[j++] = class;
}
}
n_netdev_classes = j;
exit:
*netdevp = error ? NULL : netdev;
+ free(name);
return error;
}
return error;
}
+/* Returns the ifindex of 'netdev', if successful, as a positive number. On
+ * failure, returns a negative errno value.
+ *
+ * The desired semantics of the ifindex value are a combination of those
+ * specified by POSIX for if_nametoindex() and by SNMP for ifIndex. An ifindex
+ * value should be unique within a host and remain stable at least until
+ * reboot. SNMP says an ifindex "ranges between 1 and the value of ifNumber"
+ * but many systems do not follow this rule anyhow.
+ */
+int
+netdev_get_ifindex(const struct netdev *netdev)
+{
+ return netdev->class->get_ifindex(netdev);
+}
+
/* Stores the features supported by 'netdev' into each of '*current',
* '*advertised', '*supported', and '*peer' that are non-null. Each value is a
* bitmap of "enum ofp_port_features" bits, in host byte order. Returns 0 if
uint32_t *supported, uint32_t *peer)
{
uint32_t dummy[4];
- return netdev->class->get_features(netdev,
- current ? current : &dummy[0],
- advertised ? advertised : &dummy[1],
- supported ? supported : &dummy[2],
- peer ? peer : &dummy[3]);
+ int error;
+
+ if (!current) {
+ current = &dummy[0];
+ }
+ if (!advertised) {
+ advertised = &dummy[1];
+ }
+ if (!supported) {
+ supported = &dummy[2];
+ }
+ if (!peer) {
+ peer = &dummy[3];
+ }
+
+ error = netdev->class->get_features(netdev, current, advertised, supported,
+ peer);
+ if (error) {
+ *current = *advertised = *supported = *peer = 0;
+ }
+ return error;
}
/* Set the features advertised by 'netdev' to 'advertise'. Returns 0 if
: EOPNOTSUPP);
}
-/* If 'netdev' has an assigned IPv4 address, sets '*in4' to that address and
- * returns 0. Otherwise, returns a positive errno value and sets '*in4' to 0
- * (INADDR_ANY).
+/* If 'netdev' has an assigned IPv4 address, sets '*address' to that address
+ * and '*netmask' to its netmask and returns 0. Otherwise, returns a positive
+ * errno value and sets '*address' to 0 (INADDR_ANY).
*
* The following error values have well-defined meanings:
*
*
* - EOPNOTSUPP: No IPv4 network stack attached to 'netdev'.
*
- * 'in4' may be null, in which case the address itself is not reported. */
+ * 'address' or 'netmask' or both may be null, in which case the address or netmask
+ * is not reported. */
int
-netdev_get_in4(const struct netdev *netdev, struct in_addr *in4)
+netdev_get_in4(const struct netdev *netdev,
+ struct in_addr *address_, struct in_addr *netmask_)
{
- struct in_addr dummy;
+ struct in_addr address;
+ struct in_addr netmask;
int error;
error = (netdev->class->get_in4
- ? netdev->class->get_in4(netdev, in4 ? in4 : &dummy)
+ ? netdev->class->get_in4(netdev, &address, &netmask)
: EOPNOTSUPP);
- if (error && in4) {
- in4->s_addr = 0;
+ if (address_) {
+ address_->s_addr = error ? 0 : address.s_addr;
+ }
+ if (netmask_) {
+ netmask_->s_addr = error ? 0 : netmask.s_addr;
}
return error;
}
: EOPNOTSUPP);
}
+/* Looks up the next hop for 'host' for the TCP/IP stack that corresponds to
+ * 'netdev'. If a route cannot not be determined, sets '*next_hop' to 0,
+ * '*netdev_name' to null, and returns a positive errno value. Otherwise, if a
+ * next hop is found, stores the next hop gateway's address (0 if 'host' is on
+ * a directly connected network) in '*next_hop' and a copy of the name of the
+ * device to reach 'host' in '*netdev_name', and returns 0. The caller is
+ * responsible for freeing '*netdev_name' (by calling free()). */
+int
+netdev_get_next_hop(const struct netdev *netdev,
+ const struct in_addr *host, struct in_addr *next_hop,
+ char **netdev_name)
+{
+ int error = (netdev->class->get_next_hop
+ ? netdev->class->get_next_hop(host, next_hop, netdev_name)
+ : EOPNOTSUPP);
+ if (error) {
+ next_hop->s_addr = 0;
+ *netdev_name = NULL;
+ }
+ return error;
+}
+
/* If 'netdev' has an assigned IPv6 address, sets '*in6' to that address and
* returns 0. Otherwise, returns a positive errno value and sets '*in6' to
* all-zero-bits (in6addr_any).
struct in_addr dev_in4;
if (!netdev_open(name, NETDEV_ETH_TYPE_NONE, &netdev)
- && !netdev_get_in4(netdev, &dev_in4)
+ && !netdev_get_in4(netdev, &dev_in4, NULL)
&& dev_in4.s_addr == in4->s_addr) {
goto exit;
}