]> git.proxmox.com Git - mirror_ovs.git/blobdiff - lib/netdev-bsd.c
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / netdev-bsd.c
index 75a330b3d90f55fc363029d05adb2f0993bb3371..7875636cc3ccd10341bed904315f18a6e660d22b 100644 (file)
@@ -56,7 +56,7 @@
 #include "openflow/openflow.h"
 #include "ovs-thread.h"
 #include "packets.h"
-#include "poll-loop.h"
+#include "openvswitch/poll-loop.h"
 #include "openvswitch/shash.h"
 #include "socket-util.h"
 #include "svec.h"
@@ -65,7 +65,6 @@
 
 VLOG_DEFINE_THIS_MODULE(netdev_bsd);
 
-\f
 struct netdev_rxq_bsd {
     struct netdev_rxq up;
 
@@ -618,7 +617,8 @@ netdev_rxq_bsd_recv_tap(struct netdev_rxq_bsd *rxq, struct dp_packet *buffer)
 }
 
 static int
-netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch)
+netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch,
+                    int *qfill)
 {
     struct netdev_rxq_bsd *rxq = netdev_rxq_bsd_cast(rxq_);
     struct netdev *netdev = rxq->up.netdev;
@@ -630,6 +630,7 @@ netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch)
         mtu = ETH_PAYLOAD_MAX;
     }
 
+    /* Assume Ethernet port. No need to set packet_type. */
     packet = dp_packet_new_with_headroom(VLAN_ETH_HEADER_LEN + mtu,
                                            DP_NETDEV_HEADROOM);
     retval = (rxq->pcap_handle
@@ -639,9 +640,13 @@ netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch)
     if (retval) {
         dp_packet_delete(packet);
     } else {
-        batch->packets[0] = packet;
-        batch->count = 1;
+        dp_packet_batch_init_packet(batch, packet);
+    }
+
+    if (qfill) {
+        *qfill = -ENOTSUP;
     }
+
     return retval;
 }
 
@@ -679,13 +684,13 @@ netdev_bsd_rxq_drain(struct netdev_rxq *rxq_)
  */
 static int
 netdev_bsd_send(struct netdev *netdev_, int qid OVS_UNUSED,
-                struct dp_packet_batch *batch, bool may_steal,
+                struct dp_packet_batch *batch,
                 bool concurrent_txq OVS_UNUSED)
 {
     struct netdev_bsd *dev = netdev_bsd_cast(netdev_);
     const char *name = netdev_get_name(netdev_);
+    struct dp_packet *packet;
     int error;
-    int i;
 
     ovs_mutex_lock(&dev->mutex);
     if (dev->tap_fd < 0 && !dev->pcap) {
@@ -694,12 +699,9 @@ netdev_bsd_send(struct netdev *netdev_, int qid OVS_UNUSED,
         error = 0;
     }
 
-    for (i = 0; i < batch->count; i++) {
-        const void *data = dp_packet_data(batch->packets[i]);
-        size_t size = dp_packet_size(batch->packets[i]);
-
-        /* Truncate the packet if it is configured. */
-        size -= dp_packet_get_cutlen(batch->packets[i]);
+    DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
+        const void *data = dp_packet_data(packet);
+        size_t size = dp_packet_size(packet);
 
         while (!error) {
             ssize_t retval;
@@ -730,7 +732,7 @@ netdev_bsd_send(struct netdev *netdev_, int qid OVS_UNUSED,
     }
 
     ovs_mutex_unlock(&dev->mutex);
-    dp_packet_delete_batch(batch, may_steal);
+    dp_packet_delete_batch(batch, true);
 
     return error;
 }
@@ -994,7 +996,7 @@ netdev_bsd_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
     mib[3] = IFMIB_IFDATA;
     len = sizeof(ifmd);
     for (i = 1; i <= if_count; i++) {
-        mib[4] = i; //row
+        mib[4] = i; /* row */
         if (sysctl(mib, 6, &ifmd, &len, (void *)0, 0) == -1) {
             VLOG_DBG_RL(&rl, "%s: sysctl failed: %s",
                         netdev_get_name(netdev_), ovs_strerror(errno));
@@ -1357,7 +1359,11 @@ netdev_bsd_arp_lookup(const struct netdev *netdev OVS_UNUSED,
     mib[2] = 0;
     mib[3] = AF_INET;
     mib[4] = NET_RT_FLAGS;
+#ifdef RTF_LLINFO
     mib[5] = RTF_LLINFO;
+#else
+    mib[5] = 0;
+#endif
     if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1) {
         error = errno;
         goto error;
@@ -1472,90 +1478,45 @@ netdev_bsd_update_flags(struct netdev *netdev_, enum netdev_flags off,
     return error;
 }
 
-/* Linux has also different GET_STATS, SET_STATS,
- * GET_STATUS)
- */
-#define NETDEV_BSD_CLASS(NAME, CONSTRUCT,            \
-                         GET_FEATURES)               \
-{                                                    \
-    NAME,                                            \
-    false, /* is_pmd */                              \
-                                                     \
-    NULL, /* init */                                 \
-    netdev_bsd_run,                                  \
-    netdev_bsd_wait,                                 \
-    netdev_bsd_alloc,                                \
-    CONSTRUCT,                                       \
-    netdev_bsd_destruct,                             \
-    netdev_bsd_dealloc,                              \
-    NULL, /* get_config */                           \
-    NULL, /* set_config */                           \
-    NULL, /* get_tunnel_config */                    \
-    NULL, /* build header */                         \
-    NULL, /* push header */                          \
-    NULL, /* pop header */                           \
-    NULL, /* get_numa_id */                          \
-    NULL, /* set_tx_multiq */                        \
-                                                     \
-    netdev_bsd_send,                                 \
-    netdev_bsd_send_wait,                            \
-                                                     \
-    netdev_bsd_set_etheraddr,                        \
-    netdev_bsd_get_etheraddr,                        \
-    netdev_bsd_get_mtu,                              \
-    NULL, /* set_mtu */                              \
-    netdev_bsd_get_ifindex,                          \
-    netdev_bsd_get_carrier,                          \
-    NULL, /* get_carrier_resets */                   \
-    NULL, /* set_miimon_interval */                  \
-    netdev_bsd_get_stats,                            \
-                                                     \
-    GET_FEATURES,                                    \
-    NULL, /* set_advertisement */                    \
-    NULL, /* set_policing */                         \
-    NULL, /* get_qos_type */                         \
-    NULL, /* get_qos_capabilities */                 \
-    NULL, /* get_qos */                              \
-    NULL, /* set_qos */                              \
-    NULL, /* get_queue */                            \
-    NULL, /* set_queue */                            \
-    NULL, /* delete_queue */                         \
-    NULL, /* get_queue_stats */                      \
-    NULL, /* queue_dump_start */                     \
-    NULL, /* queue_dump_next */                      \
-    NULL, /* queue_dump_done */                      \
-    NULL, /* dump_queue_stats */                     \
-                                                     \
-    netdev_bsd_set_in4,                              \
-    netdev_bsd_get_addr_list,                        \
-    NULL, /* add_router */                           \
-    netdev_bsd_get_next_hop,                         \
-    NULL, /* get_status */                           \
-    netdev_bsd_arp_lookup, /* arp_lookup */          \
-                                                     \
-    netdev_bsd_update_flags,                         \
-    NULL, /* reconfigure */                          \
-                                                     \
-    netdev_bsd_rxq_alloc,                            \
-    netdev_bsd_rxq_construct,                        \
-    netdev_bsd_rxq_destruct,                         \
-    netdev_bsd_rxq_dealloc,                          \
-    netdev_bsd_rxq_recv,                             \
-    netdev_bsd_rxq_wait,                             \
-    netdev_bsd_rxq_drain,                            \
-}
+#define NETDEV_BSD_CLASS_COMMON                      \
+    .run = netdev_bsd_run,                           \
+    .wait = netdev_bsd_wait,                         \
+    .alloc = netdev_bsd_alloc,                       \
+    .destruct = netdev_bsd_destruct,                 \
+    .dealloc = netdev_bsd_dealloc,                   \
+    .send = netdev_bsd_send,                         \
+    .send_wait = netdev_bsd_send_wait,               \
+    .set_etheraddr = netdev_bsd_set_etheraddr,       \
+    .get_etheraddr = netdev_bsd_get_etheraddr,       \
+    .get_mtu = netdev_bsd_get_mtu,                   \
+    .get_ifindex = netdev_bsd_get_ifindex,           \
+    .get_carrier = netdev_bsd_get_carrier,           \
+    .get_stats = netdev_bsd_get_stats,               \
+    .get_features = netdev_bsd_get_features,         \
+    .set_in4 = netdev_bsd_set_in4,                   \
+    .get_addr_list = netdev_bsd_get_addr_list,       \
+    .get_next_hop = netdev_bsd_get_next_hop,         \
+    .arp_lookup = netdev_bsd_arp_lookup,             \
+    .update_flags = netdev_bsd_update_flags,         \
+    .rxq_alloc = netdev_bsd_rxq_alloc,               \
+    .rxq_construct = netdev_bsd_rxq_construct,       \
+    .rxq_destruct = netdev_bsd_rxq_destruct,         \
+    .rxq_dealloc = netdev_bsd_rxq_dealloc,           \
+    .rxq_recv = netdev_bsd_rxq_recv,                 \
+    .rxq_wait = netdev_bsd_rxq_wait,                 \
+    .rxq_drain = netdev_bsd_rxq_drain
+
+const struct netdev_class netdev_bsd_class = {
+    NETDEV_BSD_CLASS_COMMON,
+    .type = "system",
+    .construct = netdev_bsd_construct_system,
+};
 
-const struct netdev_class netdev_bsd_class =
-    NETDEV_BSD_CLASS(
-        "system",
-        netdev_bsd_construct_system,
-        netdev_bsd_get_features);
-
-const struct netdev_class netdev_tap_class =
-    NETDEV_BSD_CLASS(
-        "tap",
-        netdev_bsd_construct_tap,
-        netdev_bsd_get_features);
+const struct netdev_class netdev_tap_class = {
+    NETDEV_BSD_CLASS_COMMON,
+    .type = "tap",
+    .construct = netdev_bsd_construct_tap,
+};
 \f
 
 static void