Catalli's threaded switch
[sliver-openvswitch.git] / lib / netdev.c
index 38f4dd5..00ded43 100644 (file)
 #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
 };
 
@@ -73,7 +74,6 @@ netdev_initialize(void)
 
     if (status < 0) {
         int i;
-
         fatal_signal_add_hook(close_all_netdevs, NULL, NULL, true);
 
         status = 0;
@@ -121,7 +121,7 @@ int
 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);
@@ -207,7 +207,7 @@ compare_device_args(const struct netdev_dev *dev, const struct shash *args)
 
     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;
@@ -272,8 +272,6 @@ create_device(struct netdev_options *options, struct netdev_dev **netdev_devp)
 
     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;
     }
 
@@ -312,6 +310,10 @@ netdev_open(struct netdev_options *options, struct netdev **netdevp)
     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);
@@ -324,7 +326,7 @@ netdev_open(struct netdev_options *options, struct netdev **netdevp)
         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) {
@@ -502,6 +504,28 @@ netdev_recv_wait(struct netdev *netdev)
     }
 }
 
+#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)
@@ -726,7 +750,7 @@ netdev_get_in4(const 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_) {
@@ -801,7 +825,7 @@ netdev_get_in6(const struct netdev *netdev, struct in6_addr *in6)
     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) {
@@ -822,7 +846,7 @@ do_update_flags(struct netdev *netdev, enum netdev_flags off,
     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",
@@ -897,7 +921,7 @@ netdev_arp_lookup(const struct netdev *netdev,
                   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) {
@@ -912,7 +936,7 @@ int
 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) {
@@ -958,7 +982,7 @@ netdev_set_policing(struct netdev *netdev, uint32_t kbits_rate,
                     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);
 }
@@ -1251,7 +1275,7 @@ int
 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) {
@@ -1416,7 +1440,7 @@ netdev_uninit(struct netdev *netdev, bool close)
 }
 
 
-/* Returns the class type of 'netdev'.  
+/* Returns the class type of 'netdev'.
  *
  * The caller must not free the returned value. */
 const char *