Coverage Report

Created: 2026-07-16 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openvswitch/lib/netdev-dummy.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2010, 2011, 2012, 2013, 2015, 2016, 2017 Nicira, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at:
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include <config.h>
18
19
#include "dummy.h"
20
21
#include <errno.h>
22
#include <unistd.h>
23
24
#include "dp-packet.h"
25
#include "dpif-netdev.h"
26
#include "flow.h"
27
#include "netdev-provider.h"
28
#include "netdev-vport.h"
29
#include "odp-util.h"
30
#include "openvswitch/dynamic-string.h"
31
#include "openvswitch/list.h"
32
#include "openvswitch/match.h"
33
#include "openvswitch/ofp-print.h"
34
#include "openvswitch/ofpbuf.h"
35
#include "openvswitch/vlog.h"
36
#include "ovs-atomic.h"
37
#include "packets.h"
38
#include "pcap-file.h"
39
#include "openvswitch/poll-loop.h"
40
#include "openvswitch/shash.h"
41
#include "ovs-router.h"
42
#include "sset.h"
43
#include "stream.h"
44
#include "unaligned.h"
45
#include "timeval.h"
46
#include "unixctl.h"
47
#include "userspace-tso.h"
48
#include "reconnect.h"
49
50
VLOG_DEFINE_THIS_MODULE(netdev_dummy);
51
52
0
#define C_STATS_SIZE 2
53
54
struct reconnect;
55
56
struct dummy_packet_stream {
57
    struct stream *stream;
58
    struct ovs_list txq;
59
    struct dp_packet rxbuf;
60
};
61
62
enum dummy_packet_conn_type {
63
    NONE,       /* No connection is configured. */
64
    PASSIVE,    /* Listener. */
65
    ACTIVE      /* Connect to listener. */
66
};
67
68
enum dummy_netdev_conn_state {
69
    CONN_STATE_CONNECTED,      /* Listener connected. */
70
    CONN_STATE_NOT_CONNECTED,  /* Listener not connected.  */
71
    CONN_STATE_UNKNOWN,        /* No relavent information.  */
72
};
73
74
struct dummy_packet_pconn {
75
    struct pstream *pstream;
76
    struct dummy_packet_stream **streams;
77
    size_t n_streams;
78
};
79
80
struct dummy_packet_rconn {
81
    struct dummy_packet_stream *rstream;
82
    struct reconnect *reconnect;
83
};
84
85
struct dummy_packet_conn {
86
    enum dummy_packet_conn_type type;
87
    union {
88
        struct dummy_packet_pconn pconn;
89
        struct dummy_packet_rconn rconn;
90
    };
91
};
92
93
struct pkt_list_node {
94
    struct dp_packet *pkt;
95
    struct ovs_list list_node;
96
};
97
98
struct offloaded_flow {
99
    struct hmap_node node;
100
    ovs_u128 ufid;
101
    struct match match;
102
    uint32_t mark;
103
};
104
105
struct netdev_dummy_q_stats {
106
    uint64_t bytes;
107
    uint64_t packets;
108
};
109
110
/* Protects 'dummy_list'. */
111
static struct ovs_mutex dummy_list_mutex = OVS_MUTEX_INITIALIZER;
112
113
/* Contains all 'struct dummy_dev's. */
114
static struct ovs_list dummy_list OVS_GUARDED_BY(dummy_list_mutex)
115
    = OVS_LIST_INITIALIZER(&dummy_list);
116
117
struct netdev_dummy {
118
    struct netdev up;
119
120
    /* In dummy_list. */
121
    struct ovs_list list_node OVS_GUARDED_BY(dummy_list_mutex);
122
123
    /* Protects all members below. */
124
    struct ovs_mutex mutex OVS_ACQ_AFTER(dummy_list_mutex);
125
126
    struct eth_addr hwaddr OVS_GUARDED;
127
    int mtu OVS_GUARDED;
128
    struct netdev_stats stats OVS_GUARDED;
129
    struct netdev_custom_counter custom_stats[C_STATS_SIZE] OVS_GUARDED;
130
    struct netdev_dummy_q_stats *rxq_stats OVS_GUARDED;
131
    struct netdev_dummy_q_stats *txq_stats OVS_GUARDED;
132
    enum netdev_flags flags OVS_GUARDED;
133
    int ifindex OVS_GUARDED;
134
    int numa_id OVS_GUARDED;
135
136
    struct dummy_packet_conn conn OVS_GUARDED;
137
138
    struct pcap_file *tx_pcap, *rxq_pcap OVS_GUARDED;
139
140
    struct ovs_list addrs OVS_GUARDED;
141
    struct ovs_list rxes OVS_GUARDED; /* List of child "netdev_rxq_dummy"s. */
142
143
    /* The following properties are for dummy-pmd and they cannot be changed
144
     * when a device is running, so we remember the request and update them
145
     * next time netdev_dummy_reconfigure() is called. */
146
    int requested_n_txq OVS_GUARDED;
147
    int requested_n_rxq OVS_GUARDED;
148
    int requested_numa_id OVS_GUARDED;
149
150
    /* Force IP Rx csum good. */
151
    bool ol_ip_rx_csum_set_good OVS_GUARDED;
152
    /* Force IP Rx csum bad. */
153
    bool ol_ip_rx_csum_set_bad OVS_GUARDED;
154
    /* Force IP Rx csum partial. */
155
    bool ol_ip_rx_csum_set_partial OVS_GUARDED;
156
    /* Announce netdev IP Tx csum offload. */
157
    bool ol_ip_tx_csum OVS_GUARDED;
158
    /* Disable IP Tx csum offload. */
159
    bool ol_ip_tx_csum_disabled OVS_GUARDED;
160
161
    /* Force L4 Rx csum good. */
162
    bool ol_l4_rx_csum_set_good OVS_GUARDED;
163
    /* Force L4 Rx csum bad. */
164
    bool ol_l4_rx_csum_set_bad OVS_GUARDED;
165
    /* Force L4 Rx csum partial. */
166
    bool ol_l4_rx_csum_set_partial OVS_GUARDED;
167
    /* Announce netdev L4 Tx csum offload. */
168
    bool ol_l4_tx_csum OVS_GUARDED;
169
    /* Disable L4 Tx csum offload. */
170
    bool ol_l4_tx_csum_disabled OVS_GUARDED;
171
172
    /* Announce netdev outer IP Tx csum offload. */
173
    bool ol_out_ip_tx_csum OVS_GUARDED;
174
    /* Disable outer IP Tx csum offload. */
175
    bool ol_out_ip_tx_csum_disabled OVS_GUARDED;
176
177
    /* Announce netdev outer UDP Tx csum offload. */
178
    bool ol_out_udp_tx_csum OVS_GUARDED;
179
    /* Disable outer UDP Tx csum offload. */
180
    bool ol_out_udp_tx_csum_disabled OVS_GUARDED;
181
182
    /* Set the segment size for netdev TSO support. */
183
    int ol_tso_segsz OVS_GUARDED;
184
};
185
186
/* Max 'recv_queue_len' in struct netdev_dummy. */
187
0
#define NETDEV_DUMMY_MAX_QUEUE 100
188
189
struct netdev_rxq_dummy {
190
    struct netdev_rxq up;
191
    struct ovs_list node;       /* In netdev_dummy's "rxes" list. */
192
    struct ovs_list recv_queue;
193
    int recv_queue_len;         /* ovs_list_size(&recv_queue). */
194
    struct seq *seq;            /* Reports newly queued packets. */
195
};
196
197
struct netdev_addr_dummy {
198
    struct in6_addr address;
199
    struct in6_addr netmask;
200
    struct ovs_list node;       /* In netdev_dummy's "addrs" list. */
201
};
202
203
static unixctl_cb_func netdev_dummy_set_admin_state;
204
static int netdev_dummy_construct(struct netdev *);
205
static void netdev_dummy_queue_packet(struct netdev_dummy *,
206
                                      struct dp_packet *, struct flow *, int);
207
208
static void dummy_packet_stream_close(struct dummy_packet_stream *);
209
210
static void pkt_list_delete(struct ovs_list *);
211
static void addr_list_delete(struct ovs_list *);
212
213
bool
214
is_dummy_netdev_class(const struct netdev_class *class)
215
0
{
216
0
    return class->construct == netdev_dummy_construct;
217
0
}
218
219
static struct netdev_dummy *
220
netdev_dummy_cast(const struct netdev *netdev)
221
0
{
222
0
    ovs_assert(is_dummy_netdev_class(netdev_get_class(netdev)));
223
0
    return CONTAINER_OF(netdev, struct netdev_dummy, up);
224
0
}
225
226
static struct netdev_rxq_dummy *
227
netdev_rxq_dummy_cast(const struct netdev_rxq *rx)
228
0
{
229
0
    ovs_assert(is_dummy_netdev_class(netdev_get_class(rx->netdev)));
230
0
    return CONTAINER_OF(rx, struct netdev_rxq_dummy, up);
231
0
}
232
233
static void
234
dummy_packet_stream_init(struct dummy_packet_stream *s, struct stream *stream)
235
0
{
236
0
    int rxbuf_size = stream ? 2048 : 0;
237
0
    s->stream = stream;
238
0
    dp_packet_init(&s->rxbuf, rxbuf_size);
239
0
    ovs_list_init(&s->txq);
240
0
}
241
242
static struct dummy_packet_stream *
243
dummy_packet_stream_create(struct stream *stream)
244
0
{
245
0
    struct dummy_packet_stream *s;
246
247
0
    s = xzalloc_cacheline(sizeof *s);
248
0
    dummy_packet_stream_init(s, stream);
249
250
0
    return s;
251
0
}
252
253
static void
254
dummy_packet_stream_wait(struct dummy_packet_stream *s)
255
0
{
256
0
    stream_run_wait(s->stream);
257
0
    if (!ovs_list_is_empty(&s->txq)) {
258
0
        stream_send_wait(s->stream);
259
0
    }
260
0
    stream_recv_wait(s->stream);
261
0
}
262
263
static void
264
dummy_packet_stream_send(struct dummy_packet_stream *s, const void *buffer, size_t size)
265
0
{
266
0
    if (ovs_list_size(&s->txq) < NETDEV_DUMMY_MAX_QUEUE) {
267
0
        struct dp_packet *b;
268
0
        struct pkt_list_node *node;
269
270
0
        b = dp_packet_clone_data_with_headroom(buffer, size, 2);
271
0
        put_unaligned_be16(dp_packet_push_uninit(b, 2), htons(size));
272
273
0
        node = xmalloc(sizeof *node);
274
0
        node->pkt = b;
275
0
        ovs_list_push_back(&s->txq, &node->list_node);
276
0
    }
277
0
}
278
279
static int
280
dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
281
0
{
282
0
    int error = 0;
283
0
    size_t n = 0;
284
285
0
    stream_run(s->stream);
286
287
0
    if (!ovs_list_is_empty(&s->txq)) {
288
0
        struct pkt_list_node *txbuf_node;
289
0
        struct dp_packet *txbuf;
290
0
        int retval;
291
292
0
        ASSIGN_CONTAINER(txbuf_node, ovs_list_front(&s->txq), list_node);
293
0
        txbuf = txbuf_node->pkt;
294
0
        retval = stream_send(s->stream, dp_packet_data(txbuf), dp_packet_size(txbuf));
295
296
0
        if (retval > 0) {
297
0
            dp_packet_pull(txbuf, retval);
298
0
            if (!dp_packet_size(txbuf)) {
299
0
                ovs_list_remove(&txbuf_node->list_node);
300
0
                free(txbuf_node);
301
0
                dp_packet_delete(txbuf);
302
0
            }
303
0
        } else if (retval != -EAGAIN) {
304
0
            error = -retval;
305
0
        }
306
0
    }
307
308
0
    if (!error) {
309
0
        if (dp_packet_size(&s->rxbuf) < 2) {
310
0
            n = 2 - dp_packet_size(&s->rxbuf);
311
0
        } else {
312
0
            uint16_t frame_len;
313
314
0
            frame_len = ntohs(get_unaligned_be16(dp_packet_data(&s->rxbuf)));
315
0
            if (frame_len < ETH_HEADER_LEN) {
316
0
                error = EPROTO;
317
0
                n = 0;
318
0
            } else {
319
0
                n = (2 + frame_len) - dp_packet_size(&s->rxbuf);
320
0
            }
321
0
        }
322
0
    }
323
0
    if (!error) {
324
0
        int retval;
325
326
0
        dp_packet_prealloc_tailroom(&s->rxbuf, n);
327
0
        retval = stream_recv(s->stream, dp_packet_tail(&s->rxbuf), n);
328
329
0
        if (retval > 0) {
330
0
            dp_packet_set_size(&s->rxbuf, dp_packet_size(&s->rxbuf) + retval);
331
0
            if (retval == n && dp_packet_size(&s->rxbuf) > 2) {
332
0
                dp_packet_pull(&s->rxbuf, 2);
333
0
                netdev_dummy_queue_packet(dev,
334
0
                                          dp_packet_clone(&s->rxbuf), NULL, 0);
335
0
                dp_packet_clear(&s->rxbuf);
336
0
            }
337
0
        } else if (retval != -EAGAIN) {
338
0
            error = (retval < 0 ? -retval
339
0
                     : dp_packet_size(&s->rxbuf) ? EPROTO
340
0
                     : EOF);
341
0
        }
342
0
    }
343
344
0
    return error;
345
0
}
346
347
static void
348
dummy_packet_stream_close(struct dummy_packet_stream *s)
349
0
{
350
0
    stream_close(s->stream);
351
0
    dp_packet_uninit(&s->rxbuf);
352
0
    pkt_list_delete(&s->txq);
353
0
}
354
355
static void
356
dummy_packet_conn_init(struct dummy_packet_conn *conn)
357
0
{
358
0
    memset(conn, 0, sizeof *conn);
359
0
    conn->type = NONE;
360
0
}
361
362
static void
363
dummy_packet_conn_get_config(struct dummy_packet_conn *conn, struct smap *args)
364
0
{
365
366
0
    switch (conn->type) {
367
0
    case PASSIVE:
368
0
        smap_add(args, "pstream", pstream_get_name(conn->pconn.pstream));
369
0
        break;
370
371
0
    case ACTIVE:
372
0
        smap_add(args, "stream", stream_get_name(conn->rconn.rstream->stream));
373
0
        break;
374
375
0
    case NONE:
376
0
    default:
377
0
        break;
378
0
    }
379
0
}
380
381
static void
382
dummy_packet_conn_close(struct dummy_packet_conn *conn)
383
0
{
384
0
    int i;
385
0
    struct dummy_packet_pconn *pconn = &conn->pconn;
386
0
    struct dummy_packet_rconn *rconn = &conn->rconn;
387
388
0
    switch (conn->type) {
389
0
    case PASSIVE:
390
0
        pstream_close(pconn->pstream);
391
0
        for (i = 0; i < pconn->n_streams; i++) {
392
0
            dummy_packet_stream_close(pconn->streams[i]);
393
0
            free_cacheline(pconn->streams[i]);
394
0
        }
395
0
        free(pconn->streams);
396
0
        pconn->pstream = NULL;
397
0
        pconn->streams = NULL;
398
0
        break;
399
400
0
    case ACTIVE:
401
0
        dummy_packet_stream_close(rconn->rstream);
402
0
        free_cacheline(rconn->rstream);
403
0
        rconn->rstream = NULL;
404
0
        reconnect_destroy(rconn->reconnect);
405
0
        rconn->reconnect = NULL;
406
0
        break;
407
408
0
    case NONE:
409
0
    default:
410
0
        break;
411
0
    }
412
413
0
    conn->type = NONE;
414
0
    memset(conn, 0, sizeof *conn);
415
0
}
416
417
static void
418
dummy_packet_conn_set_config(struct dummy_packet_conn *conn,
419
                             const struct smap *args)
420
0
{
421
0
    const char *pstream = smap_get(args, "pstream");
422
0
    const char *stream = smap_get(args, "stream");
423
424
0
    if (pstream && stream) {
425
0
         VLOG_WARN("Open failed: both %s and %s are configured",
426
0
                   pstream, stream);
427
0
         return;
428
0
    }
429
430
0
    switch (conn->type) {
431
0
    case PASSIVE:
432
0
        if (pstream &&
433
0
            !strcmp(pstream_get_name(conn->pconn.pstream), pstream)) {
434
0
            return;
435
0
        }
436
0
        dummy_packet_conn_close(conn);
437
0
        break;
438
0
    case ACTIVE:
439
0
        if (stream &&
440
0
            !strcmp(stream_get_name(conn->rconn.rstream->stream), stream)) {
441
0
            return;
442
0
        }
443
0
        dummy_packet_conn_close(conn);
444
0
        break;
445
0
    case NONE:
446
0
    default:
447
0
        break;
448
0
    }
449
450
0
    if (pstream) {
451
0
        int error;
452
453
0
        error = pstream_open(pstream, &conn->pconn.pstream, DSCP_DEFAULT);
454
0
        if (error) {
455
0
            VLOG_WARN("%s: open failed (%s)", pstream, ovs_strerror(error));
456
0
        } else {
457
0
            conn->type = PASSIVE;
458
0
        }
459
0
    }
460
461
0
    if (stream) {
462
0
        int error;
463
0
        struct stream *active_stream;
464
0
        struct reconnect *reconnect;
465
466
0
        reconnect = reconnect_create(time_msec());
467
0
        reconnect_set_name(reconnect, stream);
468
0
        reconnect_set_passive(reconnect, false, time_msec());
469
0
        reconnect_enable(reconnect, time_msec());
470
0
        reconnect_set_backoff(reconnect, 100, INT_MAX);
471
0
        reconnect_set_probe_interval(reconnect, 0);
472
0
        conn->rconn.reconnect = reconnect;
473
0
        conn->type = ACTIVE;
474
475
0
        error = stream_open(stream, &active_stream, DSCP_DEFAULT);
476
0
        conn->rconn.rstream = dummy_packet_stream_create(active_stream);
477
478
0
        switch (error) {
479
0
        case 0:
480
0
            reconnect_connected(reconnect, time_msec());
481
0
            break;
482
483
0
        case EAGAIN:
484
0
            reconnect_connecting(reconnect, time_msec());
485
0
            break;
486
487
0
        default:
488
0
            reconnect_connect_failed(reconnect, time_msec(), error);
489
0
            stream_close(active_stream);
490
0
            conn->rconn.rstream->stream = NULL;
491
0
            break;
492
0
        }
493
0
    }
494
0
}
495
496
static void
497
dummy_pconn_run(struct netdev_dummy *dev)
498
    OVS_REQUIRES(dev->mutex)
499
0
{
500
0
    struct stream *new_stream;
501
0
    struct dummy_packet_pconn *pconn = &dev->conn.pconn;
502
0
    int error;
503
0
    size_t i;
504
505
0
    error = pstream_accept(pconn->pstream, &new_stream);
506
0
    if (!error) {
507
0
        struct dummy_packet_stream *s;
508
509
0
        pconn->streams = xrealloc(pconn->streams,
510
0
                                ((pconn->n_streams + 1)
511
0
                                 * sizeof s));
512
0
        s = xmalloc_cacheline(sizeof *s);
513
0
        pconn->streams[pconn->n_streams++] = s;
514
0
        dummy_packet_stream_init(s, new_stream);
515
0
    } else if (error != EAGAIN) {
516
0
        VLOG_WARN("%s: accept failed (%s)",
517
0
                  pstream_get_name(pconn->pstream), ovs_strerror(error));
518
0
        pstream_close(pconn->pstream);
519
0
        pconn->pstream = NULL;
520
0
        dev->conn.type = NONE;
521
0
    }
522
523
0
    for (i = 0; i < pconn->n_streams; ) {
524
0
        struct dummy_packet_stream *s = pconn->streams[i];
525
526
0
        error = dummy_packet_stream_run(dev, s);
527
0
        if (error) {
528
0
            VLOG_DBG("%s: closing connection (%s)",
529
0
                     stream_get_name(s->stream),
530
0
                     ovs_retval_to_string(error));
531
0
            dummy_packet_stream_close(s);
532
0
            free_cacheline(s);
533
0
            pconn->streams[i] = pconn->streams[--pconn->n_streams];
534
0
        } else {
535
0
            i++;
536
0
        }
537
0
    }
538
0
}
539
540
static void
541
dummy_rconn_run(struct netdev_dummy *dev)
542
OVS_REQUIRES(dev->mutex)
543
0
{
544
0
    struct dummy_packet_rconn *rconn = &dev->conn.rconn;
545
546
0
    switch (reconnect_run(rconn->reconnect, time_msec())) {
547
0
    case RECONNECT_CONNECT:
548
0
        {
549
0
            int error;
550
551
0
            if (rconn->rstream->stream) {
552
0
                error = stream_connect(rconn->rstream->stream);
553
0
            } else {
554
0
                error = stream_open(reconnect_get_name(rconn->reconnect),
555
0
                                    &rconn->rstream->stream, DSCP_DEFAULT);
556
0
            }
557
558
0
            switch (error) {
559
0
            case 0:
560
0
                reconnect_connected(rconn->reconnect, time_msec());
561
0
                break;
562
563
0
            case EAGAIN:
564
0
                reconnect_connecting(rconn->reconnect, time_msec());
565
0
                break;
566
567
0
            default:
568
0
                reconnect_connect_failed(rconn->reconnect, time_msec(), error);
569
0
                stream_close(rconn->rstream->stream);
570
0
                rconn->rstream->stream = NULL;
571
0
                break;
572
0
            }
573
0
        }
574
0
        break;
575
576
0
    case RECONNECT_DISCONNECT:
577
0
    case RECONNECT_PROBE:
578
0
    default:
579
0
        break;
580
0
    }
581
582
0
    if (reconnect_is_connected(rconn->reconnect)) {
583
0
        int err;
584
585
0
        err = dummy_packet_stream_run(dev, rconn->rstream);
586
587
0
        if (err) {
588
0
            reconnect_disconnected(rconn->reconnect, time_msec(), err);
589
0
            stream_close(rconn->rstream->stream);
590
0
            rconn->rstream->stream = NULL;
591
0
        }
592
0
    }
593
0
}
594
595
static void
596
dummy_packet_conn_run(struct netdev_dummy *dev)
597
    OVS_REQUIRES(dev->mutex)
598
0
{
599
0
    switch (dev->conn.type) {
600
0
    case PASSIVE:
601
0
        dummy_pconn_run(dev);
602
0
        break;
603
604
0
    case ACTIVE:
605
0
        dummy_rconn_run(dev);
606
0
        break;
607
608
0
    case NONE:
609
0
    default:
610
0
        break;
611
0
    }
612
0
}
613
614
static void
615
dummy_packet_conn_wait(struct dummy_packet_conn *conn)
616
0
{
617
0
    int i;
618
0
    switch (conn->type) {
619
0
    case PASSIVE:
620
0
        pstream_wait(conn->pconn.pstream);
621
0
        for (i = 0; i < conn->pconn.n_streams; i++) {
622
0
            struct dummy_packet_stream *s = conn->pconn.streams[i];
623
0
            dummy_packet_stream_wait(s);
624
0
        }
625
0
        break;
626
0
    case ACTIVE:
627
0
        if (reconnect_is_connected(conn->rconn.reconnect)) {
628
0
            dummy_packet_stream_wait(conn->rconn.rstream);
629
0
        }
630
0
        break;
631
632
0
    case NONE:
633
0
    default:
634
0
        break;
635
0
    }
636
0
}
637
638
static void
639
dummy_packet_conn_send(struct dummy_packet_conn *conn,
640
                       const void *buffer, size_t size)
641
0
{
642
0
    int i;
643
644
0
    switch (conn->type) {
645
0
    case PASSIVE:
646
0
        for (i = 0; i < conn->pconn.n_streams; i++) {
647
0
            struct dummy_packet_stream *s = conn->pconn.streams[i];
648
649
0
            dummy_packet_stream_send(s, buffer, size);
650
0
            pstream_wait(conn->pconn.pstream);
651
0
        }
652
0
        break;
653
654
0
    case ACTIVE:
655
0
        if (reconnect_is_connected(conn->rconn.reconnect)) {
656
0
            dummy_packet_stream_send(conn->rconn.rstream, buffer, size);
657
0
            dummy_packet_stream_wait(conn->rconn.rstream);
658
0
        }
659
0
        break;
660
661
0
    case NONE:
662
0
    default:
663
0
        break;
664
0
    }
665
0
}
666
667
static enum dummy_netdev_conn_state
668
dummy_netdev_get_conn_state(struct dummy_packet_conn *conn)
669
0
{
670
0
    enum dummy_netdev_conn_state state;
671
672
0
    if (conn->type == ACTIVE) {
673
0
        if (reconnect_is_connected(conn->rconn.reconnect)) {
674
0
            state = CONN_STATE_CONNECTED;
675
0
        } else {
676
0
            state = CONN_STATE_NOT_CONNECTED;
677
0
        }
678
0
    } else {
679
0
        state = CONN_STATE_UNKNOWN;
680
0
    }
681
682
0
    return state;
683
0
}
684
685
static void
686
netdev_dummy_run(const struct netdev_class *netdev_class)
687
0
{
688
0
    struct netdev_dummy *dev;
689
690
0
    ovs_mutex_lock(&dummy_list_mutex);
691
0
    LIST_FOR_EACH (dev, list_node, &dummy_list) {
692
0
        if (netdev_get_class(&dev->up) != netdev_class) {
693
0
            continue;
694
0
        }
695
0
        ovs_mutex_lock(&dev->mutex);
696
0
        dummy_packet_conn_run(dev);
697
0
        ovs_mutex_unlock(&dev->mutex);
698
0
        dummy_netdev_hw_offload_run(&dev->up);
699
0
    }
700
0
    ovs_mutex_unlock(&dummy_list_mutex);
701
0
}
702
703
static void
704
netdev_dummy_wait(const struct netdev_class *netdev_class)
705
0
{
706
0
    struct netdev_dummy *dev;
707
708
0
    ovs_mutex_lock(&dummy_list_mutex);
709
0
    LIST_FOR_EACH (dev, list_node, &dummy_list) {
710
0
        if (netdev_get_class(&dev->up) != netdev_class) {
711
0
            continue;
712
0
        }
713
0
        ovs_mutex_lock(&dev->mutex);
714
0
        dummy_packet_conn_wait(&dev->conn);
715
0
        ovs_mutex_unlock(&dev->mutex);
716
0
    }
717
0
    ovs_mutex_unlock(&dummy_list_mutex);
718
0
}
719
720
static struct netdev *
721
netdev_dummy_alloc(void)
722
0
{
723
0
    struct netdev_dummy *netdev = xzalloc(sizeof *netdev);
724
0
    return &netdev->up;
725
0
}
726
727
static int
728
netdev_dummy_construct(struct netdev *netdev_)
729
0
{
730
0
    static atomic_count next_n = ATOMIC_COUNT_INIT(0xaa550000);
731
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
732
0
    unsigned int n;
733
734
0
    n = atomic_count_inc(&next_n);
735
736
0
    ovs_mutex_init(&netdev->mutex);
737
0
    ovs_mutex_lock(&netdev->mutex);
738
0
    netdev->hwaddr.ea[0] = 0xaa;
739
0
    netdev->hwaddr.ea[1] = 0x55;
740
0
    netdev->hwaddr.ea[2] = n >> 24;
741
0
    netdev->hwaddr.ea[3] = n >> 16;
742
0
    netdev->hwaddr.ea[4] = n >> 8;
743
0
    netdev->hwaddr.ea[5] = n;
744
0
    netdev->mtu = 1500;
745
0
    netdev->flags = NETDEV_UP;
746
0
    netdev->ifindex = -EOPNOTSUPP;
747
0
    netdev->requested_n_rxq = netdev_->n_rxq;
748
0
    netdev->requested_n_txq = netdev_->n_txq;
749
0
    netdev->numa_id = 0;
750
751
0
    memset(&netdev->custom_stats, 0, sizeof(netdev->custom_stats));
752
753
0
    ovs_strlcpy(netdev->custom_stats[0].name,
754
0
                "rx_custom_packets_1", NETDEV_CUSTOM_STATS_NAME_SIZE);
755
0
    ovs_strlcpy(netdev->custom_stats[1].name,
756
0
                "rx_custom_packets_2", NETDEV_CUSTOM_STATS_NAME_SIZE);
757
758
0
    netdev->rxq_stats = xcalloc(netdev->up.n_rxq, sizeof *netdev->rxq_stats);
759
0
    netdev->txq_stats = xcalloc(netdev->up.n_rxq, sizeof *netdev->txq_stats);
760
761
0
    dummy_packet_conn_init(&netdev->conn);
762
763
0
    ovs_list_init(&netdev->rxes);
764
0
    ovs_list_init(&netdev->addrs);
765
0
    ovs_mutex_unlock(&netdev->mutex);
766
767
0
    ovs_mutex_lock(&dummy_list_mutex);
768
0
    ovs_list_push_back(&dummy_list, &netdev->list_node);
769
0
    ovs_mutex_unlock(&dummy_list_mutex);
770
771
0
    return 0;
772
0
}
773
774
static void
775
netdev_dummy_destruct(struct netdev *netdev_)
776
0
{
777
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
778
779
0
    ovs_mutex_lock(&dummy_list_mutex);
780
0
    ovs_list_remove(&netdev->list_node);
781
0
    ovs_mutex_unlock(&dummy_list_mutex);
782
783
0
    ovs_mutex_lock(&netdev->mutex);
784
0
    free(netdev->rxq_stats);
785
0
    free(netdev->txq_stats);
786
0
    if (netdev->rxq_pcap) {
787
0
        ovs_pcap_close(netdev->rxq_pcap);
788
0
    }
789
0
    if (netdev->tx_pcap && netdev->tx_pcap != netdev->rxq_pcap) {
790
0
        ovs_pcap_close(netdev->tx_pcap);
791
0
    }
792
0
    dummy_packet_conn_close(&netdev->conn);
793
0
    netdev->conn.type = NONE;
794
795
0
    addr_list_delete(&netdev->addrs);
796
797
0
    ovs_mutex_unlock(&netdev->mutex);
798
0
    ovs_mutex_destroy(&netdev->mutex);
799
0
}
800
801
static void
802
netdev_dummy_dealloc(struct netdev *netdev_)
803
0
{
804
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
805
806
0
    free(netdev);
807
0
}
808
809
static int
810
netdev_dummy_get_config(const struct netdev *dev, struct smap *args)
811
0
{
812
0
    struct netdev_dummy *netdev = netdev_dummy_cast(dev);
813
814
0
    ovs_mutex_lock(&netdev->mutex);
815
816
0
    if (netdev->ifindex >= 0) {
817
0
        smap_add_format(args, "ifindex", "%d", netdev->ifindex);
818
0
    }
819
820
0
    dummy_packet_conn_get_config(&netdev->conn, args);
821
822
    /* pcap, rxq_pcap and tx_pcap cannot be recovered because filenames have
823
     * been discarded after opening file descriptors */
824
825
0
    if (netdev->ol_ip_rx_csum_set_good) {
826
0
        smap_add_format(args, "ol_ip_rx_csum_set_good", "%s", "true");
827
0
    }
828
0
    if (netdev->ol_ip_rx_csum_set_bad) {
829
0
        smap_add_format(args, "ol_ip_rx_csum_set_bad", "%s", "true");
830
0
    }
831
0
    if (netdev->ol_ip_rx_csum_set_partial) {
832
0
        smap_add_format(args, "ol_ip_rx_csum_set_partial", "%s", "true");
833
0
    }
834
0
    if (netdev->ol_ip_tx_csum) {
835
0
        smap_add_format(args, "ol_ip_tx_csum", "%s", "true");
836
0
        if (netdev->ol_ip_tx_csum_disabled) {
837
0
            smap_add_format(args, "ol_ip_tx_csum_disabled", "%s", "true");
838
0
        }
839
0
    }
840
841
0
    if (netdev->ol_l4_rx_csum_set_good) {
842
0
        smap_add_format(args, "ol_l4_rx_csum_set_good", "%s", "true");
843
0
    }
844
0
    if (netdev->ol_l4_rx_csum_set_bad) {
845
0
        smap_add_format(args, "ol_l4_rx_csum_set_bad", "%s", "true");
846
0
    }
847
0
    if (netdev->ol_l4_rx_csum_set_partial) {
848
0
        smap_add_format(args, "ol_l4_rx_csum_set_partial", "%s", "true");
849
0
    }
850
0
    if (netdev->ol_l4_tx_csum) {
851
0
        smap_add_format(args, "ol_l4_tx_csum", "%s", "true");
852
0
        if (netdev->ol_l4_tx_csum_disabled) {
853
0
            smap_add_format(args, "ol_l4_tx_csum_disabled", "%s", "true");
854
0
        }
855
0
    }
856
857
0
    if (netdev->ol_out_ip_tx_csum) {
858
0
        smap_add_format(args, "ol_out_ip_tx_csum", "%s", "true");
859
0
        if (netdev->ol_out_ip_tx_csum_disabled) {
860
0
            smap_add_format(args, "ol_out_ip_tx_csum_disabled", "%s", "true");
861
0
        }
862
0
    }
863
864
0
    if (netdev->ol_out_udp_tx_csum) {
865
0
        smap_add_format(args, "ol_out_udp_tx_csum", "%s", "true");
866
0
        if (netdev->ol_out_udp_tx_csum_disabled) {
867
0
            smap_add_format(args, "ol_out_udp_tx_csum_disabled", "%s", "true");
868
0
        }
869
0
    }
870
871
0
    if (netdev->ol_tso_segsz && userspace_tso_enabled()) {
872
0
        smap_add_format(args, "ol_tso_segsz", "%d", netdev->ol_tso_segsz);
873
0
    }
874
875
    /* 'dummy-pmd' specific config. */
876
0
    if (!netdev_is_pmd(dev)) {
877
0
        goto exit;
878
0
    }
879
880
0
    smap_add_format(args, "n_rxq", "%d", netdev->requested_n_rxq);
881
0
    smap_add_format(args, "n_txq", "%d", netdev->requested_n_txq);
882
0
    smap_add_format(args, "numa_id", "%d", netdev->requested_numa_id);
883
884
0
exit:
885
0
    ovs_mutex_unlock(&netdev->mutex);
886
0
    return 0;
887
0
}
888
889
static int
890
netdev_dummy_get_addr_list(const struct netdev *netdev_, struct in6_addr **paddr,
891
                           struct in6_addr **pmask, int *n_addr)
892
0
{
893
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
894
0
    int cnt = 0, i = 0, err = 0;
895
0
    struct in6_addr *addr, *mask;
896
0
    struct netdev_addr_dummy *addr_dummy;
897
898
0
    ovs_mutex_lock(&netdev->mutex);
899
900
0
    cnt = ovs_list_size(&netdev->addrs);
901
0
    if (!cnt) {
902
0
        err = EADDRNOTAVAIL;
903
0
        goto out;
904
0
    }
905
0
    addr = xmalloc(sizeof *addr * cnt);
906
0
    mask = xmalloc(sizeof *mask * cnt);
907
908
0
    LIST_FOR_EACH (addr_dummy, node, &netdev->addrs) {
909
0
        memcpy(&addr[i], &addr_dummy->address, sizeof *addr);
910
0
        memcpy(&mask[i], &addr_dummy->netmask, sizeof *mask);
911
0
        i++;
912
0
    }
913
914
0
    if (paddr) {
915
0
        *paddr = addr;
916
0
        *pmask = mask;
917
0
        *n_addr = cnt;
918
0
    } else {
919
0
        free(addr);
920
0
        free(mask);
921
0
    }
922
0
out:
923
0
    ovs_mutex_unlock(&netdev->mutex);
924
925
0
    return err;
926
0
}
927
928
static int
929
netdev_dummy_add_in4(struct netdev *netdev_, struct in_addr address,
930
                     struct in_addr netmask)
931
0
{
932
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
933
0
    struct netdev_addr_dummy *addr_dummy = xmalloc(sizeof *addr_dummy);
934
935
0
    ovs_mutex_lock(&netdev->mutex);
936
0
    in6_addr_set_mapped_ipv4(&addr_dummy->address, address.s_addr);
937
0
    in6_addr_set_mapped_ipv4(&addr_dummy->netmask, netmask.s_addr);
938
0
    ovs_list_push_back(&netdev->addrs, &addr_dummy->node);
939
0
    netdev_change_seq_changed(netdev_);
940
0
    ovs_mutex_unlock(&netdev->mutex);
941
942
0
    return 0;
943
0
}
944
945
static int
946
netdev_dummy_add_in6(struct netdev *netdev_, struct in6_addr *in6,
947
                     struct in6_addr *mask)
948
0
{
949
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
950
0
    struct netdev_addr_dummy *addr_dummy = xmalloc(sizeof *addr_dummy);
951
952
0
    ovs_mutex_lock(&netdev->mutex);
953
0
    addr_dummy->address = *in6;
954
0
    addr_dummy->netmask = *mask;
955
0
    ovs_list_push_back(&netdev->addrs, &addr_dummy->node);
956
0
    netdev_change_seq_changed(netdev_);
957
0
    ovs_mutex_unlock(&netdev->mutex);
958
959
0
    return 0;
960
0
}
961
962
0
#define DUMMY_MAX_QUEUES_PER_PORT 1024
963
964
static int
965
netdev_dummy_set_config(struct netdev *netdev_, const struct smap *args,
966
                        char **errp OVS_UNUSED)
967
0
{
968
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
969
0
    const char *pcap;
970
0
    int new_n_rxq, new_n_txq, new_numa_id;
971
972
0
    ovs_mutex_lock(&netdev->mutex);
973
0
    netdev->ifindex = smap_get_int(args, "ifindex", -EOPNOTSUPP);
974
975
0
    dummy_packet_conn_set_config(&netdev->conn, args);
976
977
0
    if (netdev->rxq_pcap) {
978
0
        ovs_pcap_close(netdev->rxq_pcap);
979
0
    }
980
0
    if (netdev->tx_pcap && netdev->tx_pcap != netdev->rxq_pcap) {
981
0
        ovs_pcap_close(netdev->tx_pcap);
982
0
    }
983
0
    netdev->rxq_pcap = netdev->tx_pcap = NULL;
984
0
    pcap = smap_get(args, "pcap");
985
0
    if (pcap) {
986
0
        netdev->rxq_pcap = netdev->tx_pcap = ovs_pcap_open(pcap, "ab");
987
0
    } else {
988
0
        const char *rxq_pcap = smap_get(args, "rxq_pcap");
989
0
        const char *tx_pcap = smap_get(args, "tx_pcap");
990
991
0
        if (rxq_pcap) {
992
0
            netdev->rxq_pcap = ovs_pcap_open(rxq_pcap, "ab");
993
0
        }
994
0
        if (tx_pcap) {
995
0
            netdev->tx_pcap = ovs_pcap_open(tx_pcap, "ab");
996
0
        }
997
0
    }
998
999
0
    netdev->ol_ip_rx_csum_set_good =
1000
0
        smap_get_bool(args, "ol_ip_rx_csum_set_good", false);
1001
0
    netdev->ol_ip_rx_csum_set_bad =
1002
0
        smap_get_bool(args, "ol_ip_rx_csum_set_bad", false);
1003
0
    netdev->ol_ip_rx_csum_set_partial =
1004
0
        smap_get_bool(args, "ol_ip_rx_csum_set_partial", false);
1005
0
    netdev->ol_ip_tx_csum = smap_get_bool(args, "ol_ip_tx_csum", false);
1006
0
    if (netdev->ol_ip_tx_csum) {
1007
0
        netdev_->ol_flags |= NETDEV_TX_OFFLOAD_IPV4_CKSUM;
1008
0
        netdev->ol_ip_tx_csum_disabled =
1009
0
            smap_get_bool(args, "ol_ip_tx_csum_disabled", false);
1010
0
    } else {
1011
0
        netdev_->ol_flags &= ~NETDEV_TX_OFFLOAD_IPV4_CKSUM;
1012
0
        netdev->ol_ip_tx_csum_disabled = true;
1013
0
    }
1014
1015
0
    netdev->ol_l4_rx_csum_set_good =
1016
0
        smap_get_bool(args, "ol_l4_rx_csum_set_good", false);
1017
0
    netdev->ol_l4_rx_csum_set_bad =
1018
0
        smap_get_bool(args, "ol_l4_rx_csum_set_bad", false);
1019
0
    netdev->ol_l4_rx_csum_set_partial =
1020
0
        smap_get_bool(args, "ol_l4_rx_csum_set_partial", false);
1021
0
    netdev->ol_l4_tx_csum = smap_get_bool(args, "ol_l4_tx_csum", false);
1022
0
    if (netdev->ol_l4_tx_csum) {
1023
0
        netdev_->ol_flags |= NETDEV_TX_OFFLOAD_TCP_CKSUM;
1024
0
        netdev_->ol_flags |= NETDEV_TX_OFFLOAD_UDP_CKSUM;
1025
0
        netdev->ol_l4_tx_csum_disabled =
1026
0
            smap_get_bool(args, "ol_l4_tx_csum_disabled", false);
1027
0
    } else {
1028
0
        netdev_->ol_flags &= ~NETDEV_TX_OFFLOAD_TCP_CKSUM;
1029
0
        netdev_->ol_flags &= ~NETDEV_TX_OFFLOAD_UDP_CKSUM;
1030
0
        netdev->ol_l4_tx_csum_disabled = true;
1031
0
    }
1032
1033
0
    netdev->ol_out_ip_tx_csum = smap_get_bool(args, "ol_out_ip_tx_csum",
1034
0
                                              false);
1035
0
    if (netdev->ol_out_ip_tx_csum) {
1036
0
        netdev_->ol_flags |= NETDEV_TX_OFFLOAD_OUTER_IP_CKSUM;
1037
0
        netdev->ol_out_ip_tx_csum_disabled =
1038
0
            smap_get_bool(args, "ol_out_ip_tx_csum_disabled", false);
1039
0
    } else {
1040
0
        netdev_->ol_flags &= ~NETDEV_TX_OFFLOAD_OUTER_IP_CKSUM;
1041
0
        netdev->ol_out_ip_tx_csum_disabled = true;
1042
0
    }
1043
1044
0
    netdev->ol_out_udp_tx_csum = smap_get_bool(args, "ol_out_udp_tx_csum",
1045
0
                                               false);
1046
0
    if (netdev->ol_out_udp_tx_csum) {
1047
0
        netdev_->ol_flags |= NETDEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
1048
0
        netdev->ol_out_udp_tx_csum_disabled =
1049
0
            smap_get_bool(args, "ol_out_udp_tx_csum_disabled", false);
1050
0
    } else {
1051
0
        netdev_->ol_flags &= ~NETDEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
1052
0
        netdev->ol_out_udp_tx_csum_disabled = true;
1053
0
    }
1054
1055
0
    if (userspace_tso_enabled()) {
1056
0
        netdev->ol_tso_segsz = smap_get_int(args, "ol_tso_segsz", 0);
1057
0
        if (netdev->ol_tso_segsz) {
1058
0
            netdev_->ol_flags |= (NETDEV_TX_OFFLOAD_TCP_TSO
1059
0
                                  | NETDEV_TX_OFFLOAD_TCP_CKSUM);
1060
0
        }
1061
0
    }
1062
1063
0
    netdev_change_seq_changed(netdev_);
1064
1065
    /* 'dummy-pmd' specific config. */
1066
0
    if (!netdev_->netdev_class->is_pmd) {
1067
0
        goto exit;
1068
0
    }
1069
1070
0
    new_n_rxq = MAX(smap_get_int(args, "n_rxq", NR_QUEUE), 1);
1071
0
    new_n_txq = MAX(smap_get_int(args, "n_txq", NR_QUEUE), 1);
1072
1073
0
    if (new_n_rxq > DUMMY_MAX_QUEUES_PER_PORT ||
1074
0
        new_n_txq > DUMMY_MAX_QUEUES_PER_PORT) {
1075
0
        VLOG_WARN("The one or both of interface %s queues"
1076
0
                  "(rxq: %d, txq: %d) exceed %d. Sets it %d.\n",
1077
0
                  netdev_get_name(netdev_),
1078
0
                  new_n_rxq,
1079
0
                  new_n_txq,
1080
0
                  DUMMY_MAX_QUEUES_PER_PORT,
1081
0
                  DUMMY_MAX_QUEUES_PER_PORT);
1082
1083
0
        new_n_rxq = MIN(DUMMY_MAX_QUEUES_PER_PORT, new_n_rxq);
1084
0
        new_n_txq = MIN(DUMMY_MAX_QUEUES_PER_PORT, new_n_txq);
1085
0
    }
1086
1087
0
    new_numa_id = smap_get_int(args, "numa_id", 0);
1088
0
    if (new_n_rxq != netdev->requested_n_rxq
1089
0
        || new_n_txq != netdev->requested_n_txq
1090
0
        || new_numa_id != netdev->requested_numa_id) {
1091
0
        netdev->requested_n_rxq = new_n_rxq;
1092
0
        netdev->requested_n_txq = new_n_txq;
1093
0
        netdev->requested_numa_id = new_numa_id;
1094
0
        netdev_request_reconfigure(netdev_);
1095
0
    }
1096
1097
0
exit:
1098
0
    ovs_mutex_unlock(&netdev->mutex);
1099
0
    return 0;
1100
0
}
1101
1102
static int
1103
netdev_dummy_get_numa_id(const struct netdev *netdev_)
1104
0
{
1105
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
1106
1107
0
    ovs_mutex_lock(&netdev->mutex);
1108
0
    int numa_id = netdev->numa_id;
1109
0
    ovs_mutex_unlock(&netdev->mutex);
1110
1111
0
    return numa_id;
1112
0
}
1113
1114
/* Sets the number of tx queues and rx queues for the dummy PMD interface. */
1115
static int
1116
netdev_dummy_reconfigure(struct netdev *netdev_)
1117
0
{
1118
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
1119
0
    int old_n_txq = netdev_->n_txq;
1120
0
    int old_n_rxq = netdev_->n_rxq;
1121
1122
0
    ovs_mutex_lock(&netdev->mutex);
1123
1124
0
    netdev_->n_txq = netdev->requested_n_txq;
1125
0
    netdev_->n_rxq = netdev->requested_n_rxq;
1126
0
    netdev->numa_id = netdev->requested_numa_id;
1127
1128
0
    if (netdev_->n_txq != old_n_txq || netdev_->n_rxq != old_n_rxq) {
1129
        /* Resize the per queue stats arrays. */
1130
0
        netdev->txq_stats = xrealloc(netdev->txq_stats,
1131
0
                                     netdev_->n_txq *
1132
0
                                     sizeof *netdev->txq_stats);
1133
0
        netdev->rxq_stats = xrealloc(netdev->rxq_stats,
1134
0
                                     netdev_->n_rxq *
1135
0
                                     sizeof *netdev->rxq_stats);
1136
1137
        /* Reset all stats for consistency between per-queue and global
1138
         * counters. */
1139
0
        memset(&netdev->stats, 0, sizeof netdev->stats);
1140
0
        netdev->custom_stats[0].value = 0;
1141
0
        netdev->custom_stats[1].value = 0;
1142
0
        memset(netdev->txq_stats, 0,
1143
0
               netdev_->n_txq * sizeof *netdev->txq_stats);
1144
0
        memset(netdev->rxq_stats, 0,
1145
0
               netdev_->n_rxq * sizeof *netdev->rxq_stats);
1146
0
    }
1147
1148
0
    ovs_mutex_unlock(&netdev->mutex);
1149
0
    return 0;
1150
0
}
1151
1152
static struct netdev_rxq *
1153
netdev_dummy_rxq_alloc(void)
1154
0
{
1155
0
    struct netdev_rxq_dummy *rx = xzalloc(sizeof *rx);
1156
0
    return &rx->up;
1157
0
}
1158
1159
static int
1160
netdev_dummy_rxq_construct(struct netdev_rxq *rxq_)
1161
0
{
1162
0
    struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
1163
0
    struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
1164
1165
0
    ovs_mutex_lock(&netdev->mutex);
1166
0
    ovs_list_push_back(&netdev->rxes, &rx->node);
1167
0
    ovs_list_init(&rx->recv_queue);
1168
0
    rx->recv_queue_len = 0;
1169
0
    rx->seq = seq_create();
1170
0
    ovs_mutex_unlock(&netdev->mutex);
1171
1172
0
    return 0;
1173
0
}
1174
1175
static void
1176
netdev_dummy_rxq_destruct(struct netdev_rxq *rxq_)
1177
0
{
1178
0
    struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
1179
0
    struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
1180
1181
0
    ovs_mutex_lock(&netdev->mutex);
1182
0
    ovs_list_remove(&rx->node);
1183
0
    pkt_list_delete(&rx->recv_queue);
1184
0
    ovs_mutex_unlock(&netdev->mutex);
1185
0
    seq_destroy(rx->seq);
1186
0
}
1187
1188
static void
1189
netdev_dummy_rxq_dealloc(struct netdev_rxq *rxq_)
1190
0
{
1191
0
    struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
1192
1193
0
    free(rx);
1194
0
}
1195
1196
static int
1197
netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch,
1198
                      int *qfill)
1199
0
{
1200
0
    struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
1201
0
    struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
1202
0
    struct dp_packet *packet;
1203
1204
0
    ovs_mutex_lock(&netdev->mutex);
1205
0
    if (!ovs_list_is_empty(&rx->recv_queue)) {
1206
0
        struct pkt_list_node *pkt_node;
1207
1208
0
        ASSIGN_CONTAINER(pkt_node, ovs_list_pop_front(&rx->recv_queue), list_node);
1209
0
        packet = pkt_node->pkt;
1210
0
        free(pkt_node);
1211
0
        rx->recv_queue_len--;
1212
0
    } else {
1213
0
        packet = NULL;
1214
0
    }
1215
0
    ovs_mutex_unlock(&netdev->mutex);
1216
1217
0
    if (!packet) {
1218
0
        if (netdev_is_pmd(&netdev->up)) {
1219
            /* If 'netdev' is a PMD device, this is called as part of the PMD
1220
             * thread busy loop.  We yield here (without quiescing) for two
1221
             * reasons:
1222
             *
1223
             * - To reduce the CPU utilization during the testsuite
1224
             * - To give valgrind a chance to switch thread. According
1225
             *   to the valgrind documentation, there's a big lock that
1226
             *   prevents multiple thread from being executed at the same
1227
             *   time.  On my system, without this sleep, the pmd threads
1228
             *   testcases fail under valgrind, because ovs-vswitchd becomes
1229
             *   unresponsive. */
1230
0
            sched_yield();
1231
0
        }
1232
0
        return EAGAIN;
1233
0
    }
1234
0
    ovs_mutex_lock(&netdev->mutex);
1235
0
    netdev->stats.rx_packets++;
1236
0
    netdev->rxq_stats[rxq_->queue_id].packets++;
1237
0
    netdev->stats.rx_bytes += dp_packet_size(packet);
1238
0
    netdev->rxq_stats[rxq_->queue_id].bytes += dp_packet_size(packet);
1239
0
    netdev->custom_stats[0].value++;
1240
0
    netdev->custom_stats[1].value++;
1241
1242
0
    if (netdev->ol_ip_rx_csum_set_good) {
1243
0
        dp_packet_ip_checksum_set_good(packet);
1244
0
    } else if (netdev->ol_ip_rx_csum_set_bad) {
1245
0
        dp_packet_ip_checksum_set_bad(packet);
1246
0
    } else if (netdev->ol_ip_rx_csum_set_partial) {
1247
0
        dp_packet_ip_checksum_set_partial(packet);
1248
0
    } else {
1249
0
        dp_packet_ip_checksum_set_unknown(packet);
1250
0
    }
1251
1252
0
    if (netdev->ol_l4_rx_csum_set_good) {
1253
0
        dp_packet_l4_checksum_set_good(packet);
1254
0
    } else if (netdev->ol_l4_rx_csum_set_bad) {
1255
0
        dp_packet_l4_checksum_set_bad(packet);
1256
0
    } else if (netdev->ol_l4_rx_csum_set_partial) {
1257
0
        dp_packet_l4_checksum_set_partial(packet);
1258
0
    } else {
1259
0
        dp_packet_l4_checksum_set_unknown(packet);
1260
0
    }
1261
1262
0
    if (userspace_tso_enabled() && netdev->ol_tso_segsz) {
1263
0
        dp_packet_set_tso_segsz(packet, netdev->ol_tso_segsz);
1264
0
    }
1265
1266
0
    if (VLOG_IS_DBG_ENABLED()) {
1267
0
        bool ip_csum_good;
1268
0
        bool l4_csum_good;
1269
0
        bool ip_csum_bad;
1270
0
        bool l4_csum_bad;
1271
1272
0
        ip_csum_good = !!(packet->offloads & DP_PACKET_OL_IP_CKSUM_GOOD);
1273
0
        ip_csum_bad = !!(packet->offloads & DP_PACKET_OL_IP_CKSUM_BAD);
1274
0
        l4_csum_good = !!(packet->offloads & DP_PACKET_OL_L4_CKSUM_GOOD);
1275
0
        l4_csum_bad = !!(packet->offloads & DP_PACKET_OL_L4_CKSUM_BAD);
1276
0
        VLOG_DBG("Rx: packet with csum IP %s, L4 %s, segsz %"PRIu16,
1277
0
                 ip_csum_good ? (ip_csum_bad ? "partial" : "good")
1278
0
                              : (ip_csum_bad ? "bad" : "unknown"),
1279
0
                 l4_csum_good ? (l4_csum_bad ? "partial" : "good")
1280
0
                              : (l4_csum_bad ? "bad" : "unknown"),
1281
0
                 dp_packet_get_tso_segsz(packet));
1282
0
    }
1283
1284
0
    ovs_mutex_unlock(&netdev->mutex);
1285
1286
0
    dp_packet_batch_reset(batch);
1287
0
    dp_packet_batch_add(batch, packet);
1288
1289
0
    if (qfill) {
1290
0
        *qfill = -ENOTSUP;
1291
0
    }
1292
1293
0
    return 0;
1294
0
}
1295
1296
static void
1297
netdev_dummy_rxq_wait(struct netdev_rxq *rxq_)
1298
0
{
1299
0
    struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
1300
0
    struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
1301
0
    uint64_t seq = seq_read(rx->seq);
1302
1303
0
    ovs_mutex_lock(&netdev->mutex);
1304
0
    if (!ovs_list_is_empty(&rx->recv_queue)) {
1305
0
        poll_immediate_wake();
1306
0
    } else {
1307
0
        seq_wait(rx->seq, seq);
1308
0
    }
1309
0
    ovs_mutex_unlock(&netdev->mutex);
1310
0
}
1311
1312
static int
1313
netdev_dummy_rxq_drain(struct netdev_rxq *rxq_)
1314
0
{
1315
0
    struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
1316
0
    struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
1317
1318
0
    ovs_mutex_lock(&netdev->mutex);
1319
0
    pkt_list_delete(&rx->recv_queue);
1320
0
    rx->recv_queue_len = 0;
1321
0
    ovs_mutex_unlock(&netdev->mutex);
1322
1323
0
    seq_change(rx->seq);
1324
1325
0
    return 0;
1326
0
}
1327
1328
static int
1329
netdev_dummy_send(struct netdev *netdev, int qid,
1330
                  struct dp_packet_batch *batch,
1331
                  bool concurrent_txq OVS_UNUSED)
1332
0
{
1333
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1334
0
    int error = 0;
1335
1336
0
    struct dp_packet *packet;
1337
0
    DP_PACKET_BATCH_FOR_EACH(i, packet, batch) {
1338
0
        const void *buffer = dp_packet_data(packet);
1339
0
        size_t size = dp_packet_size(packet);
1340
0
        uint64_t flags;
1341
0
        bool is_tso;
1342
1343
0
        ovs_mutex_lock(&dev->mutex);
1344
0
        flags = netdev->ol_flags;
1345
0
        if (!dev->ol_ip_tx_csum_disabled) {
1346
0
            flags &= ~NETDEV_TX_OFFLOAD_IPV4_CKSUM;
1347
0
        }
1348
0
        if (!dev->ol_l4_tx_csum_disabled) {
1349
0
            flags &= ~NETDEV_TX_OFFLOAD_TCP_CKSUM;
1350
0
            flags &= ~NETDEV_TX_OFFLOAD_UDP_CKSUM;
1351
0
        }
1352
0
        if (!dev->ol_out_ip_tx_csum_disabled) {
1353
0
            flags &= ~NETDEV_TX_OFFLOAD_OUTER_IP_CKSUM;
1354
0
        }
1355
0
        if (!dev->ol_out_udp_tx_csum_disabled) {
1356
0
            flags &= ~NETDEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
1357
0
        }
1358
0
        is_tso = userspace_tso_enabled() && dev->ol_tso_segsz &&
1359
0
                 dp_packet_get_tso_segsz(packet);
1360
0
        ovs_mutex_unlock(&dev->mutex);
1361
1362
0
        if (!dp_packet_is_eth(packet)) {
1363
0
            error = EPFNOSUPPORT;
1364
0
            break;
1365
0
        }
1366
1367
0
        if (size < ETH_HEADER_LEN) {
1368
0
            error = EMSGSIZE;
1369
0
            break;
1370
0
        } else {
1371
0
            const struct eth_header *eth = buffer;
1372
0
            int max_size;
1373
1374
0
            ovs_mutex_lock(&dev->mutex);
1375
0
            max_size = dev->mtu + ETH_HEADER_LEN;
1376
0
            ovs_mutex_unlock(&dev->mutex);
1377
1378
0
            if (eth->eth_type == htons(ETH_TYPE_VLAN)) {
1379
0
                max_size += VLAN_HEADER_LEN;
1380
0
            }
1381
0
            if (size > max_size && !is_tso) {
1382
0
                error = EMSGSIZE;
1383
0
                break;
1384
0
            }
1385
0
        }
1386
1387
0
        if (VLOG_IS_DBG_ENABLED()) {
1388
0
            bool inner_ip_csum_good;
1389
0
            bool inner_l4_csum_good;
1390
0
            bool inner_ip_csum_bad;
1391
0
            bool inner_l4_csum_bad;
1392
0
            const char *tunnel;
1393
0
            bool ip_csum_good;
1394
0
            bool l4_csum_good;
1395
0
            bool ip_csum_bad;
1396
0
            bool l4_csum_bad;
1397
1398
0
            ip_csum_good = !!(packet->offloads & DP_PACKET_OL_IP_CKSUM_GOOD);
1399
0
            ip_csum_bad = !!(packet->offloads & DP_PACKET_OL_IP_CKSUM_BAD);
1400
0
            l4_csum_good = !!(packet->offloads & DP_PACKET_OL_L4_CKSUM_GOOD);
1401
0
            l4_csum_bad = !!(packet->offloads & DP_PACKET_OL_L4_CKSUM_BAD);
1402
0
            inner_ip_csum_good =
1403
0
                !!(packet->offloads & DP_PACKET_OL_INNER_IP_CKSUM_GOOD);
1404
0
            inner_ip_csum_bad =
1405
0
                !!(packet->offloads & DP_PACKET_OL_INNER_IP_CKSUM_BAD);
1406
0
            inner_l4_csum_good =
1407
0
                !!(packet->offloads & DP_PACKET_OL_INNER_L4_CKSUM_GOOD);
1408
0
            inner_l4_csum_bad =
1409
0
                !!(packet->offloads & DP_PACKET_OL_INNER_L4_CKSUM_BAD);
1410
0
            tunnel = !dp_packet_tunnel(packet)         ? "none"
1411
0
                     : dp_packet_tunnel_vxlan(packet)  ? "vxlan"
1412
0
                     : dp_packet_tunnel_geneve(packet) ? "geneve"
1413
0
                     : "gre";
1414
0
            VLOG_DBG("Tx: packet with csum IP %s, L4 %s, tunnel %s, "
1415
0
                     "inner csum IP %s, inner L4 %s, segsz %"PRIu16,
1416
0
                     ip_csum_good ? (ip_csum_bad ? "partial" : "good")
1417
0
                                  : (ip_csum_bad ? "bad" : "unknown"),
1418
0
                     l4_csum_good ? (l4_csum_bad ? "partial" : "good")
1419
0
                                  : (l4_csum_bad ? "bad" : "unknown"),
1420
0
                     tunnel,
1421
0
                     inner_ip_csum_good
1422
0
                         ? (inner_ip_csum_bad ? "partial" : "good")
1423
0
                         : (inner_ip_csum_bad ? "bad" : "unknown"),
1424
0
                     inner_l4_csum_good
1425
0
                         ? (inner_l4_csum_bad ? "partial" : "good")
1426
0
                         : (inner_l4_csum_bad ? "bad" : "unknown"),
1427
0
                     dp_packet_get_tso_segsz(packet));
1428
0
        }
1429
1430
0
        if (dp_packet_ip_checksum_partial(packet)
1431
0
            || dp_packet_l4_checksum_partial(packet)
1432
0
            || dp_packet_inner_ip_checksum_partial(packet)
1433
0
            || dp_packet_inner_l4_checksum_partial(packet)) {
1434
0
            dp_packet_ol_send_prepare(packet, flags);
1435
0
        }
1436
1437
0
        ovs_mutex_lock(&dev->mutex);
1438
0
        dev->stats.tx_packets++;
1439
0
        dev->txq_stats[qid].packets++;
1440
0
        dev->stats.tx_bytes += size;
1441
0
        dev->txq_stats[qid].bytes += size;
1442
1443
0
        dummy_packet_conn_send(&dev->conn, buffer, size);
1444
1445
        /* Reply to ARP requests for 'dev''s assigned IP address. */
1446
0
        struct netdev_addr_dummy *addr_dummy;
1447
0
        LIST_FOR_EACH (addr_dummy, node, &dev->addrs) {
1448
0
            ovs_be32 address = in6_addr_get_mapped_ipv4(&addr_dummy->address);
1449
1450
0
            struct dp_packet dp;
1451
0
            struct flow flow;
1452
1453
0
            dp_packet_use_const(&dp, buffer, size);
1454
0
            flow_extract(&dp, &flow);
1455
0
            if (flow.dl_type == htons(ETH_TYPE_ARP)
1456
0
                && flow.nw_proto == ARP_OP_REQUEST
1457
0
                && flow.nw_dst == address) {
1458
0
                struct dp_packet *reply = dp_packet_new(0);
1459
0
                compose_arp(reply, ARP_OP_REPLY, dev->hwaddr, flow.dl_src,
1460
0
                            false, flow.nw_dst, flow.nw_src);
1461
0
                netdev_dummy_queue_packet(dev, reply, NULL, 0);
1462
0
                break;
1463
0
            }
1464
0
        }
1465
1466
0
        if (dev->tx_pcap) {
1467
0
            struct dp_packet dp;
1468
1469
0
            dp_packet_use_const(&dp, buffer, size);
1470
0
            ovs_pcap_write(dev->tx_pcap, &dp);
1471
0
        }
1472
1473
0
        ovs_mutex_unlock(&dev->mutex);
1474
0
    }
1475
1476
0
    dp_packet_delete_batch(batch, true);
1477
1478
0
    return error;
1479
0
}
1480
1481
static int
1482
netdev_dummy_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
1483
0
{
1484
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1485
1486
0
    ovs_mutex_lock(&dev->mutex);
1487
0
    if (!eth_addr_equals(dev->hwaddr, mac)) {
1488
0
        dev->hwaddr = mac;
1489
0
        netdev_change_seq_changed(netdev);
1490
0
    }
1491
0
    ovs_mutex_unlock(&dev->mutex);
1492
1493
0
    return 0;
1494
0
}
1495
1496
static int
1497
netdev_dummy_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
1498
0
{
1499
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1500
1501
0
    ovs_mutex_lock(&dev->mutex);
1502
0
    *mac = dev->hwaddr;
1503
0
    ovs_mutex_unlock(&dev->mutex);
1504
1505
0
    return 0;
1506
0
}
1507
1508
static int
1509
netdev_dummy_get_mtu(const struct netdev *netdev, int *mtup)
1510
0
{
1511
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1512
1513
0
    ovs_mutex_lock(&dev->mutex);
1514
0
    *mtup = dev->mtu;
1515
0
    ovs_mutex_unlock(&dev->mutex);
1516
1517
0
    return 0;
1518
0
}
1519
1520
0
#define DUMMY_MIN_MTU 68
1521
0
#define DUMMY_MAX_MTU 65535
1522
1523
static int
1524
netdev_dummy_set_mtu(struct netdev *netdev, int mtu)
1525
0
{
1526
0
    if (mtu < DUMMY_MIN_MTU || mtu > DUMMY_MAX_MTU) {
1527
0
        return EINVAL;
1528
0
    }
1529
1530
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1531
1532
0
    ovs_mutex_lock(&dev->mutex);
1533
0
    if (dev->mtu != mtu) {
1534
0
        dev->mtu = mtu;
1535
0
        netdev_change_seq_changed(netdev);
1536
0
    }
1537
0
    ovs_mutex_unlock(&dev->mutex);
1538
1539
0
    return 0;
1540
0
}
1541
1542
static int
1543
netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
1544
0
{
1545
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1546
1547
0
    ovs_mutex_lock(&dev->mutex);
1548
    /* Passing only collected counters */
1549
0
    stats->tx_packets = dev->stats.tx_packets;
1550
0
    stats->tx_bytes = dev->stats.tx_bytes;
1551
0
    stats->rx_packets = dev->stats.rx_packets;
1552
0
    stats->rx_bytes = dev->stats.rx_bytes;
1553
0
    ovs_mutex_unlock(&dev->mutex);
1554
1555
0
    return 0;
1556
0
}
1557
1558
static int
1559
netdev_dummy_get_custom_stats(const struct netdev *netdev,
1560
                             struct netdev_custom_stats *custom_stats)
1561
0
{
1562
0
    int i, j;
1563
1564
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1565
1566
0
    ovs_mutex_lock(&dev->mutex);
1567
1568
0
#define DUMMY_Q_STATS      \
1569
0
    DUMMY_Q_STAT(bytes)    \
1570
0
    DUMMY_Q_STAT(packets)
1571
1572
0
    custom_stats->size = C_STATS_SIZE;
1573
0
#define DUMMY_Q_STAT(NAME) + netdev->n_rxq
1574
0
    custom_stats->size += DUMMY_Q_STATS;
1575
0
#undef DUMMY_Q_STAT
1576
0
#define DUMMY_Q_STAT(NAME) + netdev->n_txq
1577
0
    custom_stats->size += DUMMY_Q_STATS;
1578
0
#undef DUMMY_Q_STAT
1579
1580
0
    custom_stats->counters = xcalloc(custom_stats->size,
1581
0
                                     sizeof(struct netdev_custom_counter));
1582
1583
0
    j = 0;
1584
0
    for (i = 0 ; i < C_STATS_SIZE ; i++) {
1585
0
        custom_stats->counters[j].value = dev->custom_stats[i].value;
1586
0
        ovs_strlcpy(custom_stats->counters[j++].name,
1587
0
                    dev->custom_stats[i].name,
1588
0
                    NETDEV_CUSTOM_STATS_NAME_SIZE);
1589
0
    }
1590
1591
0
    for (i = 0; i < netdev->n_rxq; i++) {
1592
0
#define DUMMY_Q_STAT(NAME) \
1593
0
        snprintf(custom_stats->counters[j].name, \
1594
0
                 NETDEV_CUSTOM_STATS_NAME_SIZE, "rx_q%d_"#NAME, i); \
1595
0
        custom_stats->counters[j++].value = dev->rxq_stats[i].NAME;
1596
0
        DUMMY_Q_STATS
1597
0
#undef DUMMY_Q_STAT
1598
0
    }
1599
1600
0
    for (i = 0; i < netdev->n_txq; i++) {
1601
0
#define DUMMY_Q_STAT(NAME) \
1602
0
        snprintf(custom_stats->counters[j].name, \
1603
0
                 NETDEV_CUSTOM_STATS_NAME_SIZE, "tx_q%d_"#NAME, i); \
1604
0
        custom_stats->counters[j++].value = dev->txq_stats[i].NAME;
1605
0
        DUMMY_Q_STATS
1606
0
#undef DUMMY_Q_STAT
1607
0
    }
1608
1609
0
    ovs_mutex_unlock(&dev->mutex);
1610
1611
0
    return 0;
1612
0
}
1613
1614
static int
1615
netdev_dummy_get_queue(const struct netdev *netdev OVS_UNUSED,
1616
                       unsigned int queue_id, struct smap *details OVS_UNUSED)
1617
0
{
1618
0
    if (queue_id == 0) {
1619
0
        return 0;
1620
0
    } else {
1621
0
        return EINVAL;
1622
0
    }
1623
0
}
1624
1625
static void
1626
netdev_dummy_init_queue_stats(struct netdev_queue_stats *stats)
1627
0
{
1628
0
    *stats = (struct netdev_queue_stats) {
1629
0
        .tx_bytes = UINT64_MAX,
1630
0
        .tx_packets = UINT64_MAX,
1631
0
        .tx_errors = UINT64_MAX,
1632
0
        .created = LLONG_MIN,
1633
0
    };
1634
0
}
1635
1636
static int
1637
netdev_dummy_get_queue_stats(const struct netdev *netdev OVS_UNUSED,
1638
                             unsigned int queue_id,
1639
                             struct netdev_queue_stats *stats)
1640
0
{
1641
0
    if (queue_id == 0) {
1642
0
        netdev_dummy_init_queue_stats(stats);
1643
0
        return 0;
1644
0
    } else {
1645
0
        return EINVAL;
1646
0
    }
1647
0
}
1648
1649
struct netdev_dummy_queue_state {
1650
    unsigned int next_queue;
1651
};
1652
1653
static int
1654
netdev_dummy_queue_dump_start(const struct netdev *netdev OVS_UNUSED,
1655
                              void **statep)
1656
0
{
1657
0
    struct netdev_dummy_queue_state *state = xmalloc(sizeof *state);
1658
0
    state->next_queue = 0;
1659
0
    *statep = state;
1660
0
    return 0;
1661
0
}
1662
1663
static int
1664
netdev_dummy_queue_dump_next(const struct netdev *netdev OVS_UNUSED,
1665
                             void *state_,
1666
                             unsigned int *queue_id,
1667
                             struct smap *details OVS_UNUSED)
1668
0
{
1669
0
    struct netdev_dummy_queue_state *state = state_;
1670
0
    if (state->next_queue == 0) {
1671
0
        *queue_id = 0;
1672
0
        state->next_queue++;
1673
0
        return 0;
1674
0
    } else {
1675
0
        return EOF;
1676
0
    }
1677
0
}
1678
1679
static int
1680
netdev_dummy_queue_dump_done(const struct netdev *netdev OVS_UNUSED,
1681
                             void *state)
1682
0
{
1683
0
    free(state);
1684
0
    return 0;
1685
0
}
1686
1687
static int
1688
netdev_dummy_dump_queue_stats(const struct netdev *netdev OVS_UNUSED,
1689
                              void (*cb)(unsigned int queue_id,
1690
                                         struct netdev_queue_stats *,
1691
                                         void *aux),
1692
                              void *aux)
1693
0
{
1694
0
    struct netdev_queue_stats stats;
1695
0
    netdev_dummy_init_queue_stats(&stats);
1696
0
    cb(0, &stats, aux);
1697
0
    return 0;
1698
0
}
1699
1700
static int
1701
netdev_dummy_get_ifindex(const struct netdev *netdev)
1702
0
{
1703
0
    struct netdev_dummy *dev = netdev_dummy_cast(netdev);
1704
0
    int ifindex;
1705
1706
0
    ovs_mutex_lock(&dev->mutex);
1707
0
    ifindex = dev->ifindex;
1708
0
    ovs_mutex_unlock(&dev->mutex);
1709
1710
0
    return ifindex;
1711
0
}
1712
1713
static int
1714
netdev_dummy_update_flags__(struct netdev_dummy *netdev,
1715
                            enum netdev_flags off, enum netdev_flags on,
1716
                            enum netdev_flags *old_flagsp)
1717
    OVS_REQUIRES(netdev->mutex)
1718
0
{
1719
0
    if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
1720
0
        return EINVAL;
1721
0
    }
1722
1723
0
    *old_flagsp = netdev->flags;
1724
0
    netdev->flags |= on;
1725
0
    netdev->flags &= ~off;
1726
0
    if (*old_flagsp != netdev->flags) {
1727
0
        netdev_change_seq_changed(&netdev->up);
1728
0
    }
1729
1730
0
    return 0;
1731
0
}
1732
1733
static int
1734
netdev_dummy_update_flags(struct netdev *netdev_,
1735
                          enum netdev_flags off, enum netdev_flags on,
1736
                          enum netdev_flags *old_flagsp)
1737
0
{
1738
0
    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
1739
0
    int error;
1740
1741
0
    ovs_mutex_lock(&netdev->mutex);
1742
0
    error = netdev_dummy_update_flags__(netdev, off, on, old_flagsp);
1743
0
    ovs_mutex_unlock(&netdev->mutex);
1744
1745
0
    return error;
1746
0
}
1747
1748
#define NETDEV_DUMMY_CLASS_COMMON                       \
1749
    .run = netdev_dummy_run,                            \
1750
    .wait = netdev_dummy_wait,                          \
1751
    .alloc = netdev_dummy_alloc,                        \
1752
    .construct = netdev_dummy_construct,                \
1753
    .destruct = netdev_dummy_destruct,                  \
1754
    .dealloc = netdev_dummy_dealloc,                    \
1755
    .get_config = netdev_dummy_get_config,              \
1756
    .set_config = netdev_dummy_set_config,              \
1757
    .get_numa_id = netdev_dummy_get_numa_id,            \
1758
    .send = netdev_dummy_send,                          \
1759
    .set_etheraddr = netdev_dummy_set_etheraddr,        \
1760
    .get_etheraddr = netdev_dummy_get_etheraddr,        \
1761
    .get_mtu = netdev_dummy_get_mtu,                    \
1762
    .set_mtu = netdev_dummy_set_mtu,                    \
1763
    .get_ifindex = netdev_dummy_get_ifindex,            \
1764
    .get_stats = netdev_dummy_get_stats,                \
1765
    .get_custom_stats = netdev_dummy_get_custom_stats,  \
1766
    .get_queue = netdev_dummy_get_queue,                \
1767
    .get_queue_stats = netdev_dummy_get_queue_stats,    \
1768
    .queue_dump_start = netdev_dummy_queue_dump_start,  \
1769
    .queue_dump_next = netdev_dummy_queue_dump_next,    \
1770
    .queue_dump_done = netdev_dummy_queue_dump_done,    \
1771
    .dump_queue_stats = netdev_dummy_dump_queue_stats,  \
1772
    .get_addr_list = netdev_dummy_get_addr_list,        \
1773
    .update_flags = netdev_dummy_update_flags,          \
1774
    .rxq_alloc = netdev_dummy_rxq_alloc,                \
1775
    .rxq_construct = netdev_dummy_rxq_construct,        \
1776
    .rxq_destruct = netdev_dummy_rxq_destruct,          \
1777
    .rxq_dealloc = netdev_dummy_rxq_dealloc,            \
1778
    .rxq_recv = netdev_dummy_rxq_recv,                  \
1779
    .rxq_wait = netdev_dummy_rxq_wait,                  \
1780
    .rxq_drain = netdev_dummy_rxq_drain
1781
1782
static const struct netdev_class dummy_class = {
1783
    NETDEV_DUMMY_CLASS_COMMON,
1784
    .type = "dummy"
1785
};
1786
1787
static const struct netdev_class dummy_internal_class = {
1788
    NETDEV_DUMMY_CLASS_COMMON,
1789
    .type = "dummy-internal"
1790
};
1791
1792
static const struct netdev_class dummy_pmd_class = {
1793
    NETDEV_DUMMY_CLASS_COMMON,
1794
    .type = "dummy-pmd",
1795
    .is_pmd = true,
1796
    .reconfigure = netdev_dummy_reconfigure
1797
};
1798
1799

1800
/* Helper functions. */
1801
1802
static void
1803
pkt_list_delete(struct ovs_list *l)
1804
0
{
1805
0
    struct pkt_list_node *pkt;
1806
1807
0
    LIST_FOR_EACH_POP(pkt, list_node, l) {
1808
0
        dp_packet_delete(pkt->pkt);
1809
0
        free(pkt);
1810
0
    }
1811
0
}
1812
1813
static void
1814
addr_list_delete(struct ovs_list *l)
1815
0
{
1816
0
    struct netdev_addr_dummy *addr_dummy;
1817
1818
0
    LIST_FOR_EACH_POP (addr_dummy, node, l) {
1819
0
        free(addr_dummy);
1820
0
    }
1821
0
}
1822
1823
static struct dp_packet *
1824
eth_from_packet(const char *s)
1825
0
{
1826
0
    struct dp_packet *packet;
1827
0
    eth_from_hex(s, &packet);
1828
0
    return packet;
1829
0
}
1830
1831
static struct dp_packet *
1832
eth_from_flow_str(const char *s, size_t packet_size,
1833
                  struct flow *flow, char **errorp)
1834
0
{
1835
0
    *errorp = NULL;
1836
1837
0
    enum odp_key_fitness fitness;
1838
0
    struct dp_packet *packet;
1839
0
    struct ofpbuf odp_key;
1840
0
    int error;
1841
1842
    /* Convert string to datapath key.
1843
     *
1844
     * It would actually be nicer to parse an OpenFlow-like flow key here, but
1845
     * the code for that currently calls exit() on parse error.  We have to
1846
     * settle for parsing a datapath key for now.
1847
     */
1848
0
    ofpbuf_init(&odp_key, 0);
1849
0
    error = odp_flow_from_string(s, NULL, &odp_key, NULL, errorp);
1850
0
    if (error) {
1851
0
        ofpbuf_uninit(&odp_key);
1852
0
        return NULL;
1853
0
    }
1854
1855
    /* Convert odp_key to flow. */
1856
0
    fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, flow, errorp);
1857
0
    if (fitness == ODP_FIT_ERROR) {
1858
0
        ofpbuf_uninit(&odp_key);
1859
0
        return NULL;
1860
0
    }
1861
1862
0
    packet = dp_packet_new(0);
1863
0
    if (packet_size) {
1864
0
        flow_compose(packet, flow, NULL, 0, false);
1865
0
        if (dp_packet_size(packet) < packet_size) {
1866
0
            packet_expand(packet, flow, packet_size);
1867
0
        } else if (dp_packet_size(packet) > packet_size){
1868
0
            dp_packet_delete(packet);
1869
0
            packet = NULL;
1870
0
        }
1871
0
    } else {
1872
0
        flow_compose(packet, flow, NULL, 64, false);
1873
0
    }
1874
1875
0
    ofpbuf_uninit(&odp_key);
1876
0
    return packet;
1877
0
}
1878
1879
static void
1880
netdev_dummy_rxq_enqueue(struct netdev_rxq_dummy *rx, struct dp_packet *packet)
1881
0
{
1882
0
    struct pkt_list_node *pkt_node = xmalloc(sizeof *pkt_node);
1883
1884
0
    pkt_node->pkt = packet;
1885
0
    ovs_list_push_back(&rx->recv_queue, &pkt_node->list_node);
1886
0
    rx->recv_queue_len++;
1887
0
    seq_change(rx->seq);
1888
0
}
1889
1890
static void
1891
netdev_dummy_queue_packet__(struct netdev_dummy *dummy,
1892
                            struct dp_packet *packet, int queue_id)
1893
    OVS_REQUIRES(dummy->mutex)
1894
0
{
1895
0
    struct netdev_rxq_dummy *rx, *prev = NULL;
1896
1897
0
    LIST_FOR_EACH (rx, node, &dummy->rxes) {
1898
0
        if (rx->up.queue_id == queue_id &&
1899
0
            rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
1900
0
            if (prev) {
1901
0
                netdev_dummy_rxq_enqueue(prev, dp_packet_clone(packet));
1902
0
            }
1903
0
            prev = rx;
1904
0
        }
1905
0
    }
1906
0
    if (prev) {
1907
0
        netdev_dummy_rxq_enqueue(prev, packet);
1908
0
    } else {
1909
0
        dp_packet_delete(packet);
1910
0
    }
1911
0
}
1912
1913
static void
1914
netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct dp_packet *packet,
1915
                          struct flow *flow, int queue_id)
1916
    OVS_REQUIRES(dummy->mutex)
1917
0
{
1918
0
    if (dummy->rxq_pcap) {
1919
0
        ovs_pcap_write(dummy->rxq_pcap, packet);
1920
0
    }
1921
1922
0
    if (dummy_netdev_simulate_offload(&dummy->up, packet,
1923
0
                                                   queue_id, flow)) {
1924
        /* Packet was stolen for full HW offload simulation. */
1925
0
        return;
1926
0
    }
1927
1928
0
    netdev_dummy_queue_packet__(dummy, packet, queue_id);
1929
0
}
1930
1931
void netdev_dummy_queue_simulate_offload_packet(const struct netdev *netdev,
1932
                                                struct dp_packet *packet,
1933
                                                int queue_id)
1934
0
{
1935
0
    struct netdev_dummy *dummy;
1936
1937
0
    if (!netdev || !is_dummy_netdev_class(netdev->netdev_class)) {
1938
0
        dp_packet_delete(packet);
1939
0
        return;
1940
0
    }
1941
1942
0
    dummy = netdev_dummy_cast(netdev);
1943
1944
0
    ovs_mutex_lock(&dummy->mutex);
1945
0
    netdev_dummy_queue_packet__(dummy, packet, queue_id);
1946
0
    ovs_mutex_unlock(&dummy->mutex);
1947
0
}
1948
1949
static void
1950
netdev_dummy_receive(struct unixctl_conn *conn,
1951
                     int argc, const char *argv[], void *aux OVS_UNUSED)
1952
0
{
1953
0
    struct netdev_dummy *dummy_dev;
1954
0
    struct netdev *netdev;
1955
0
    int i, k = 1, rx_qid = 0;
1956
1957
0
    netdev = netdev_from_name(argv[k++]);
1958
0
    if (!netdev || !is_dummy_netdev_class(netdev->netdev_class)) {
1959
0
        unixctl_command_reply_error(conn, "no such dummy netdev");
1960
0
        goto exit_netdev;
1961
0
    }
1962
0
    dummy_dev = netdev_dummy_cast(netdev);
1963
1964
0
    ovs_mutex_lock(&dummy_dev->mutex);
1965
1966
0
    if (argc > k + 1 && !strcmp(argv[k], "--qid")) {
1967
0
        rx_qid = strtol(argv[k + 1], NULL, 10);
1968
0
        if (rx_qid < 0 || rx_qid >= netdev->n_rxq) {
1969
0
            unixctl_command_reply_error(conn, "bad rx queue id.");
1970
0
            goto exit;
1971
0
        }
1972
0
        k += 2;
1973
0
    }
1974
1975
0
    for (i = k; i < argc; i++) {
1976
0
        struct dp_packet *packet;
1977
0
        struct flow flow;
1978
1979
        /* Try to parse 'argv[i]' as packet in hex. */
1980
0
        packet = eth_from_packet(argv[i]);
1981
1982
0
        if (!packet) {
1983
0
            int packet_size = 0;
1984
0
            const char *flow_str = argv[i];
1985
1986
            /* Parse optional --len argument immediately follows a 'flow'.  */
1987
0
            if (argc >= i + 2 && !strcmp(argv[i + 1], "--len")) {
1988
0
                packet_size = strtol(argv[i + 2], NULL, 10);
1989
1990
0
                if (packet_size < ETH_TOTAL_MIN) {
1991
0
                    unixctl_command_reply_error(conn, "too small packet len");
1992
0
                    goto exit;
1993
0
                }
1994
0
                i += 2;
1995
0
            }
1996
            /* Try parse 'argv[i]' as odp flow. */
1997
0
            char *error_s;
1998
0
            packet = eth_from_flow_str(flow_str, packet_size, &flow, &error_s);
1999
0
            if (!packet) {
2000
0
                unixctl_command_reply_error(conn, error_s);
2001
0
                free(error_s);
2002
0
                goto exit;
2003
0
            }
2004
0
        } else {
2005
0
            flow_extract(packet, &flow);
2006
0
        }
2007
2008
0
        netdev_dummy_queue_packet(dummy_dev, packet, &flow, rx_qid);
2009
0
    }
2010
2011
0
    unixctl_command_reply(conn, NULL);
2012
2013
0
exit:
2014
0
    ovs_mutex_unlock(&dummy_dev->mutex);
2015
0
exit_netdev:
2016
0
    netdev_close(netdev);
2017
0
}
2018
2019
static void
2020
netdev_dummy_set_admin_state__(struct netdev_dummy *dev, bool admin_state)
2021
    OVS_REQUIRES(dev->mutex)
2022
0
{
2023
0
    enum netdev_flags old_flags;
2024
2025
0
    if (admin_state) {
2026
0
        netdev_dummy_update_flags__(dev, 0, NETDEV_UP, &old_flags);
2027
0
    } else {
2028
0
        netdev_dummy_update_flags__(dev, NETDEV_UP, 0, &old_flags);
2029
0
    }
2030
0
}
2031
2032
static void
2033
netdev_dummy_set_admin_state(struct unixctl_conn *conn, int argc,
2034
                             const char *argv[], void *aux OVS_UNUSED)
2035
0
{
2036
0
    bool up;
2037
2038
0
    if (!strcasecmp(argv[argc - 1], "up")) {
2039
0
        up = true;
2040
0
    } else if ( !strcasecmp(argv[argc - 1], "down")) {
2041
0
        up = false;
2042
0
    } else {
2043
0
        unixctl_command_reply_error(conn, "Invalid Admin State");
2044
0
        return;
2045
0
    }
2046
2047
0
    if (argc > 2) {
2048
0
        struct netdev *netdev = netdev_from_name(argv[1]);
2049
0
        if (netdev && is_dummy_netdev_class(netdev->netdev_class)) {
2050
0
            struct netdev_dummy *dummy_dev = netdev_dummy_cast(netdev);
2051
2052
0
            ovs_mutex_lock(&dummy_dev->mutex);
2053
0
            netdev_dummy_set_admin_state__(dummy_dev, up);
2054
0
            ovs_mutex_unlock(&dummy_dev->mutex);
2055
2056
0
            netdev_close(netdev);
2057
0
        } else {
2058
0
            unixctl_command_reply_error(conn, "Unknown Dummy Interface");
2059
0
            netdev_close(netdev);
2060
0
            return;
2061
0
        }
2062
0
    } else {
2063
0
        struct netdev_dummy *netdev;
2064
2065
0
        ovs_mutex_lock(&dummy_list_mutex);
2066
0
        LIST_FOR_EACH (netdev, list_node, &dummy_list) {
2067
0
            ovs_mutex_lock(&netdev->mutex);
2068
0
            netdev_dummy_set_admin_state__(netdev, up);
2069
0
            ovs_mutex_unlock(&netdev->mutex);
2070
0
        }
2071
0
        ovs_mutex_unlock(&dummy_list_mutex);
2072
0
    }
2073
0
    unixctl_command_reply(conn, "OK");
2074
0
}
2075
2076
static void
2077
display_conn_state__(struct ds *s, const char *name,
2078
                     enum dummy_netdev_conn_state state)
2079
0
{
2080
0
    ds_put_format(s, "%s: ", name);
2081
2082
0
    switch (state) {
2083
0
    case CONN_STATE_CONNECTED:
2084
0
        ds_put_cstr(s, "connected\n");
2085
0
        break;
2086
2087
0
    case CONN_STATE_NOT_CONNECTED:
2088
0
        ds_put_cstr(s, "disconnected\n");
2089
0
        break;
2090
2091
0
    case CONN_STATE_UNKNOWN:
2092
0
    default:
2093
0
        ds_put_cstr(s, "unknown\n");
2094
0
        break;
2095
0
    };
2096
0
}
2097
2098
static void
2099
netdev_dummy_conn_state(struct unixctl_conn *conn, int argc,
2100
                        const char *argv[], void *aux OVS_UNUSED)
2101
0
{
2102
0
    enum dummy_netdev_conn_state state = CONN_STATE_UNKNOWN;
2103
0
    struct ds s;
2104
2105
0
    ds_init(&s);
2106
2107
0
    if (argc > 1) {
2108
0
        const char *dev_name = argv[1];
2109
0
        struct netdev *netdev = netdev_from_name(dev_name);
2110
2111
0
        if (netdev && is_dummy_netdev_class(netdev->netdev_class)) {
2112
0
            struct netdev_dummy *dummy_dev = netdev_dummy_cast(netdev);
2113
2114
0
            ovs_mutex_lock(&dummy_dev->mutex);
2115
0
            state = dummy_netdev_get_conn_state(&dummy_dev->conn);
2116
0
            ovs_mutex_unlock(&dummy_dev->mutex);
2117
2118
0
            netdev_close(netdev);
2119
0
        }
2120
0
        display_conn_state__(&s, dev_name, state);
2121
0
    } else {
2122
0
        struct netdev_dummy *netdev;
2123
2124
0
        ovs_mutex_lock(&dummy_list_mutex);
2125
0
        LIST_FOR_EACH (netdev, list_node, &dummy_list) {
2126
0
            ovs_mutex_lock(&netdev->mutex);
2127
0
            state = dummy_netdev_get_conn_state(&netdev->conn);
2128
0
            ovs_mutex_unlock(&netdev->mutex);
2129
0
            if (state != CONN_STATE_UNKNOWN) {
2130
0
                display_conn_state__(&s, netdev->up.name, state);
2131
0
            }
2132
0
        }
2133
0
        ovs_mutex_unlock(&dummy_list_mutex);
2134
0
    }
2135
2136
0
    unixctl_command_reply(conn, ds_cstr(&s));
2137
0
    ds_destroy(&s);
2138
0
}
2139
2140
static void
2141
netdev_dummy_ip4addr(struct unixctl_conn *conn, int argc OVS_UNUSED,
2142
                     const char *argv[], void *aux OVS_UNUSED)
2143
0
{
2144
0
    struct netdev *netdev = netdev_from_name(argv[1]);
2145
2146
0
    if (netdev && is_dummy_netdev_class(netdev->netdev_class)) {
2147
0
        struct in_addr ip, mask;
2148
0
        struct in6_addr ip6;
2149
0
        uint32_t plen;
2150
0
        char *error;
2151
2152
0
        error = ip_parse_cidr(argv[2], &ip.s_addr, &plen);
2153
0
        if (!error) {
2154
0
            mask.s_addr = be32_prefix_mask(plen);
2155
0
            netdev_dummy_add_in4(netdev, ip, mask);
2156
2157
0
            in6_addr_set_mapped_ipv4(&ip6, ip.s_addr);
2158
            /* Insert local route entry for the new address. */
2159
0
            ovs_router_force_insert(CLS_LOCAL, 0, &ip6, 32 + 96, argv[1],
2160
0
                                    &in6addr_any, &ip6);
2161
            /* Insert network route entry for the new address. */
2162
0
            ovs_router_force_insert(CLS_MAIN, 0, &ip6, plen + 96, argv[1],
2163
0
                                    &in6addr_any, &ip6);
2164
2165
0
            unixctl_command_reply(conn, "OK");
2166
0
        } else {
2167
0
            unixctl_command_reply_error(conn, error);
2168
0
            free(error);
2169
0
        }
2170
0
    } else {
2171
0
        unixctl_command_reply_error(conn, "Unknown Dummy Interface");
2172
0
    }
2173
2174
0
    netdev_close(netdev);
2175
0
}
2176
2177
static void
2178
netdev_dummy_ip6addr(struct unixctl_conn *conn, int argc OVS_UNUSED,
2179
                     const char *argv[], void *aux OVS_UNUSED)
2180
0
{
2181
0
    struct netdev *netdev = netdev_from_name(argv[1]);
2182
2183
0
    if (netdev && is_dummy_netdev_class(netdev->netdev_class)) {
2184
0
        struct in6_addr ip6;
2185
0
        char *error;
2186
0
        uint32_t plen;
2187
2188
0
        error = ipv6_parse_cidr(argv[2], &ip6, &plen);
2189
0
        if (!error) {
2190
0
            struct in6_addr mask;
2191
2192
0
            mask = ipv6_create_mask(plen);
2193
0
            netdev_dummy_add_in6(netdev, &ip6, &mask);
2194
2195
            /* Insert local route entry for the new address. */
2196
0
            ovs_router_force_insert(CLS_LOCAL, 0, &ip6, 128, argv[1],
2197
0
                                    &in6addr_any, &ip6);
2198
            /* Insert network route entry for the new address. */
2199
0
            ovs_router_force_insert(CLS_MAIN, 0, &ip6, plen, argv[1],
2200
0
                                    &in6addr_any, &ip6);
2201
2202
0
            unixctl_command_reply(conn, "OK");
2203
0
        } else {
2204
0
            unixctl_command_reply_error(conn, error);
2205
0
            free(error);
2206
0
        }
2207
0
    } else {
2208
0
        unixctl_command_reply_error(conn, "Unknown Dummy Interface");
2209
0
    }
2210
2211
0
    netdev_close(netdev);
2212
0
}
2213
2214
2215
static void
2216
netdev_dummy_override(const char *type)
2217
0
{
2218
0
    if (!netdev_unregister_provider(type)) {
2219
0
        struct netdev_class *class;
2220
0
        int error;
2221
2222
0
        class = xmemdup(&dummy_class, sizeof dummy_class);
2223
0
        class->type = xstrdup(type);
2224
0
        error = netdev_register_provider(class);
2225
0
        if (error) {
2226
0
            VLOG_ERR("%s: failed to register netdev provider (%s)",
2227
0
                     type, ovs_strerror(error));
2228
0
            free(CONST_CAST(char *, class->type));
2229
0
            free(class);
2230
0
        }
2231
0
    }
2232
0
}
2233
2234
void
2235
netdev_dummy_register(enum dummy_level level)
2236
0
{
2237
0
    unixctl_command_register("netdev-dummy/receive",
2238
0
                             "name [--qid queue_id] packet|flow [--len packet_len]",
2239
0
                             2, INT_MAX, netdev_dummy_receive, NULL);
2240
0
    unixctl_command_register("netdev-dummy/set-admin-state",
2241
0
                             "[netdev] up|down", 1, 2,
2242
0
                             netdev_dummy_set_admin_state, NULL);
2243
0
    unixctl_command_register("netdev-dummy/conn-state",
2244
0
                             "[netdev]", 0, 1,
2245
0
                             netdev_dummy_conn_state, NULL);
2246
0
    unixctl_command_register("netdev-dummy/ip4addr",
2247
0
                             "[netdev] ipaddr/mask-prefix-len", 2, 2,
2248
0
                             netdev_dummy_ip4addr, NULL);
2249
0
    unixctl_command_register("netdev-dummy/ip6addr",
2250
0
                             "[netdev] ip6addr", 2, 2,
2251
0
                             netdev_dummy_ip6addr, NULL);
2252
2253
0
    if (level == DUMMY_OVERRIDE_ALL) {
2254
0
        struct sset types;
2255
0
        const char *type;
2256
2257
0
        sset_init(&types);
2258
0
        netdev_enumerate_types(&types);
2259
0
        SSET_FOR_EACH (type, &types) {
2260
0
            if (strcmp(type, "patch")) {
2261
0
                netdev_dummy_override(type);
2262
0
            }
2263
0
        }
2264
0
        sset_destroy(&types);
2265
0
    } else if (level == DUMMY_OVERRIDE_SYSTEM) {
2266
0
        netdev_dummy_override("system");
2267
0
    }
2268
0
    netdev_register_provider(&dummy_class);
2269
0
    netdev_register_provider(&dummy_internal_class);
2270
0
    netdev_register_provider(&dummy_pmd_class);
2271
2272
0
    netdev_vport_tunnel_register();
2273
0
}