#include "poll-loop.h"
#include "shash.h"
#include "svec.h"
-
-#define THIS_MODULE VLM_netdev
#include "vlog.h"
+VLOG_DEFINE_THIS_MODULE(netdev)
+
static const struct netdev_class *base_netdev_classes[] = {
#ifdef HAVE_NETLINK
&netdev_linux_class,
&netdev_tap_class,
&netdev_patch_class,
&netdev_gre_class,
+ &netdev_capwap_class,
#endif
};
if (status < 0) {
int i;
-
fatal_signal_add_hook(close_all_netdevs, NULL, NULL, true);
status = 0;
netdev_register_provider(const struct netdev_class *new_class)
{
struct netdev_class *new_provider;
-
+
if (shash_find(&netdev_classes, new_class->type)) {
VLOG_WARN("attempted to register duplicate netdev provider: %s",
new_class->type);
new_args = shash_sort(args);
for (i = 0; i < dev->n_args; i++) {
- if (strcmp(dev->args[i].key, new_args[i]->name) ||
+ if (strcmp(dev->args[i].key, new_args[i]->name) ||
strcmp(dev->args[i].value, new_args[i]->data)) {
result = false;
goto finish;
netdev_class = shash_find_data(&netdev_classes, options->type);
if (!netdev_class) {
- VLOG_WARN("could not create netdev %s of unknown type %s",
- options->name, options->type);
return EAFNOSUPPORT;
}
if (!netdev_dev) {
error = create_device(options, &netdev_dev);
if (error) {
+ if (error == EAFNOSUPPORT) {
+ VLOG_WARN("could not create netdev %s of unknown type %s",
+ options->name, options->type);
+ }
return error;
}
update_device_args(netdev_dev, options->args);
return EINVAL;
}
- error = netdev_dev->netdev_class->open(netdev_dev, options->ethertype,
+ error = netdev_dev->netdev_class->open(netdev_dev, options->ethertype,
netdevp);
if (!error) {
}
}
+#ifdef THREADED
+/* Attempts to receive and process 'batch' packets from 'netdev'. */
+int
+netdev_dispatch(struct netdev *netdev, int batch, pkt_handler h, u_char *user)
+{
+ int (*dispatch)(struct netdev*, int, pkt_handler, u_char *);
+
+ dispatch = netdev_get_dev(netdev)->netdev_class->dispatch;
+ return dispatch ? dispatch(netdev, batch, h, user) : 0;
+}
+
+/* Returns the file descriptor */
+int
+netdev_get_fd(struct netdev *netdev)
+{
+ int (*get_fd)(struct netdev *);
+
+ get_fd = netdev_get_dev(netdev)->netdev_class->get_fd;
+ return get_fd ? get_fd(netdev) : 0;
+}
+#endif
+
/* Discards all packets waiting to be received from 'netdev'. */
int
netdev_drain(struct netdev *netdev)
int error;
error = (netdev_get_dev(netdev)->netdev_class->get_in4
- ? netdev_get_dev(netdev)->netdev_class->get_in4(netdev,
+ ? netdev_get_dev(netdev)->netdev_class->get_in4(netdev,
&address, &netmask)
: EOPNOTSUPP);
if (address_) {
int error;
error = (netdev_get_dev(netdev)->netdev_class->get_in6
- ? netdev_get_dev(netdev)->netdev_class->get_in6(netdev,
+ ? netdev_get_dev(netdev)->netdev_class->get_in6(netdev,
in6 ? in6 : &dummy)
: EOPNOTSUPP);
if (error && in6) {
enum netdev_flags old_flags;
int error;
- error = netdev_get_dev(netdev)->netdev_class->update_flags(netdev,
+ error = netdev_get_dev(netdev)->netdev_class->update_flags(netdev,
off & ~on, on, &old_flags);
if (error) {
VLOG_WARN_RL(&rl, "failed to %s flags for network device %s: %s",
uint32_t ip, uint8_t mac[ETH_ADDR_LEN])
{
int error = (netdev_get_dev(netdev)->netdev_class->arp_lookup
- ? netdev_get_dev(netdev)->netdev_class->arp_lookup(netdev,
+ ? netdev_get_dev(netdev)->netdev_class->arp_lookup(netdev,
ip, mac)
: EOPNOTSUPP);
if (error) {
netdev_get_carrier(const struct netdev *netdev, bool *carrier)
{
int error = (netdev_get_dev(netdev)->netdev_class->get_carrier
- ? netdev_get_dev(netdev)->netdev_class->get_carrier(netdev,
+ ? netdev_get_dev(netdev)->netdev_class->get_carrier(netdev,
carrier)
: EOPNOTSUPP);
if (error) {
uint32_t kbits_burst)
{
return (netdev_get_dev(netdev)->netdev_class->set_policing
- ? netdev_get_dev(netdev)->netdev_class->set_policing(netdev,
+ ? netdev_get_dev(netdev)->netdev_class->set_policing(netdev,
kbits_rate, kbits_burst)
: EOPNOTSUPP);
}
netdev_get_vlan_vid(const struct netdev *netdev, int *vlan_vid)
{
int error = (netdev_get_dev(netdev)->netdev_class->get_vlan_vid
- ? netdev_get_dev(netdev)->netdev_class->get_vlan_vid(netdev,
+ ? netdev_get_dev(netdev)->netdev_class->get_vlan_vid(netdev,
vlan_vid)
: ENOENT);
if (error) {
}
-/* Returns the class type of 'netdev'.
+/* Returns the class type of 'netdev'.
*
* The caller must not free the returned value. */
const char *