2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-25 15:07:05 +00:00

netdev: New function netdev_get_ifindex().

sFlow needs the ifindex of an interface, so this commit adds a function
to retrieve it.
This commit is contained in:
Ben Pfaff
2009-11-23 12:25:08 -08:00
parent d161c09927
commit 9ab3d9a3c2
4 changed files with 39 additions and 0 deletions

View File

@@ -548,6 +548,17 @@ netdev_linux_get_mtu(const struct netdev *netdev_, int *mtup)
return 0; return 0;
} }
/* Returns the ifindex of 'netdev', if successful, as a positive number.
* On failure, returns a negative errno value. */
static int
netdev_linux_get_ifindex(const struct netdev *netdev)
{
int ifindex, error;
error = get_ifindex(netdev, &ifindex);
return error ? -error : ifindex;
}
static int static int
netdev_linux_get_carrier(const struct netdev *netdev_, bool *carrier) netdev_linux_get_carrier(const struct netdev *netdev_, bool *carrier)
{ {
@@ -1388,6 +1399,7 @@ const struct netdev_class netdev_linux_class = {
netdev_linux_set_etheraddr, netdev_linux_set_etheraddr,
netdev_linux_get_etheraddr, netdev_linux_get_etheraddr,
netdev_linux_get_mtu, netdev_linux_get_mtu,
netdev_linux_get_ifindex,
netdev_linux_get_carrier, netdev_linux_get_carrier,
netdev_linux_get_stats, netdev_linux_get_stats,
@@ -1432,6 +1444,7 @@ const struct netdev_class netdev_tap_class = {
netdev_linux_set_etheraddr, netdev_linux_set_etheraddr,
netdev_linux_get_etheraddr, netdev_linux_get_etheraddr,
netdev_linux_get_mtu, netdev_linux_get_mtu,
netdev_linux_get_ifindex,
netdev_linux_get_carrier, netdev_linux_get_carrier,
netdev_linux_get_stats, netdev_linux_get_stats,

View File

@@ -164,6 +164,16 @@ struct netdev_class {
* bytes for Ethernet devices.*/ * bytes for Ethernet devices.*/
int (*get_mtu)(const struct netdev *, int *mtup); int (*get_mtu)(const struct netdev *, int *mtup);
/* 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 (*get_ifindex)(const struct netdev *);
/* Sets 'carrier' to true if carrier is active (link light is on) on /* Sets 'carrier' to true if carrier is active (link light is on) on
* 'netdev'. */ * 'netdev'. */
int (*get_carrier)(const struct netdev *netdev, bool *carrier); int (*get_carrier)(const struct netdev *netdev, bool *carrier);

View File

@@ -366,6 +366,21 @@ netdev_get_mtu(const struct netdev *netdev, int *mtup)
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', /* Stores the features supported by 'netdev' into each of '*current',
* '*advertised', '*supported', and '*peer' that are non-null. Each value is a * '*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 * bitmap of "enum ofp_port_features" bits, in host byte order. Returns 0 if

View File

@@ -90,6 +90,7 @@ int netdev_enumerate(struct svec *);
const char *netdev_get_name(const struct netdev *); const char *netdev_get_name(const struct netdev *);
int netdev_get_mtu(const struct netdev *, int *mtup); int netdev_get_mtu(const struct netdev *, int *mtup);
int netdev_get_ifindex(const struct netdev *);
int netdev_recv(struct netdev *, struct ofpbuf *); int netdev_recv(struct netdev *, struct ofpbuf *);
void netdev_recv_wait(struct netdev *); void netdev_recv_wait(struct netdev *);