~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to lib/dpif-netdev.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "netdev.h"
43
43
#include "netdev-vport.h"
44
44
#include "netlink.h"
 
45
#include "odp-execute.h"
45
46
#include "odp-util.h"
46
47
#include "ofp-print.h"
47
48
#include "ofpbuf.h"
51
52
#include "shash.h"
52
53
#include "sset.h"
53
54
#include "timeval.h"
 
55
#include "unixctl.h"
54
56
#include "util.h"
55
57
#include "vlog.h"
56
58
 
86
88
    char *name;
87
89
    int open_cnt;
88
90
    bool destroyed;
 
91
    int max_mtu;                /* Maximum MTU of any port added so far. */
89
92
 
90
93
    struct dp_netdev_queue queues[N_QUEUES];
91
94
    struct hmap flow_table;     /* Flow table. */
103
106
 
104
107
/* A port in a netdev-based datapath. */
105
108
struct dp_netdev_port {
106
 
    int port_no;                /* Index into dp_netdev's 'ports'. */
 
109
    odp_port_t port_no;         /* Index into dp_netdev's 'ports'. */
107
110
    struct list node;           /* Element in dp_netdev's 'port_list'. */
108
111
    struct netdev *netdev;
 
112
    struct netdev_saved_flags *sf;
 
113
    struct netdev_rx *rx;
109
114
    char *type;                 /* Port type as requested by user. */
110
115
};
111
116
 
135
140
/* All netdev-based datapaths. */
136
141
static struct shash dp_netdevs = SHASH_INITIALIZER(&dp_netdevs);
137
142
 
138
 
/* Maximum port MTU seen so far. */
139
 
static int max_mtu = ETH_PAYLOAD_MAX;
 
143
/* Global lock for all data. */
 
144
static struct ovs_mutex dp_netdev_mutex = OVS_MUTEX_INITIALIZER;
140
145
 
141
 
static int get_port_by_number(struct dp_netdev *, uint32_t port_no,
 
146
static int get_port_by_number(struct dp_netdev *, odp_port_t port_no,
142
147
                              struct dp_netdev_port **portp);
143
148
static int get_port_by_name(struct dp_netdev *, const char *devname,
144
149
                            struct dp_netdev_port **portp);
145
150
static void dp_netdev_free(struct dp_netdev *);
146
151
static void dp_netdev_flow_flush(struct dp_netdev *);
147
152
static int do_add_port(struct dp_netdev *, const char *devname,
148
 
                       const char *type, uint32_t port_no);
149
 
static int do_del_port(struct dp_netdev *, uint32_t port_no);
 
153
                       const char *type, odp_port_t port_no);
 
154
static int do_del_port(struct dp_netdev *, odp_port_t port_no);
150
155
static int dpif_netdev_open(const struct dpif_class *, const char *name,
151
156
                            bool create, struct dpif **);
152
157
static int dp_netdev_output_userspace(struct dp_netdev *, const struct ofpbuf *,
153
158
                                    int queue_no, const struct flow *,
154
 
                                    uint64_t arg);
 
159
                                    const struct nlattr *userdata);
155
160
static void dp_netdev_execute_actions(struct dp_netdev *,
156
161
                                      struct ofpbuf *, struct flow *,
157
162
                                      const struct nlattr *actions,
158
163
                                      size_t actions_len);
 
164
static void dp_netdev_port_input(struct dp_netdev *dp,
 
165
                                 struct dp_netdev_port *port,
 
166
                                 struct ofpbuf *packet, uint32_t skb_priority,
 
167
                                 uint32_t skb_mark, const struct flow_tnl *tnl);
159
168
 
160
169
static struct dpif_netdev *
161
170
dpif_netdev_cast(const struct dpif *dpif)
175
184
{
176
185
    struct shash_node *node;
177
186
 
 
187
    ovs_mutex_lock(&dp_netdev_mutex);
178
188
    SHASH_FOR_EACH(node, &dp_netdevs) {
179
189
        sset_add(all_dps, node->name);
180
190
    }
 
191
    ovs_mutex_unlock(&dp_netdev_mutex);
 
192
 
181
193
    return 0;
182
194
}
183
195
 
211
223
    return &dpif->dpif;
212
224
}
213
225
 
214
 
static int
 
226
/* Choose an unused, non-zero port number and return it on success.
 
227
 * Return ODPP_NONE on failure. */
 
228
static odp_port_t
215
229
choose_port(struct dp_netdev *dp, const char *name)
216
230
{
217
 
    int port_no;
 
231
    uint32_t port_no;
218
232
 
219
233
    if (dp->class != &dpif_netdev_class) {
220
234
        const char *p;
234
248
                port_no = start_no + strtol(p, NULL, 10);
235
249
                if (port_no > 0 && port_no < MAX_PORTS
236
250
                    && !dp->ports[port_no]) {
237
 
                    return port_no;
 
251
                    return u32_to_odp(port_no);
238
252
                }
239
253
                break;
240
254
            }
243
257
 
244
258
    for (port_no = 1; port_no < MAX_PORTS; port_no++) {
245
259
        if (!dp->ports[port_no]) {
246
 
            return port_no;
 
260
            return u32_to_odp(port_no);
247
261
        }
248
262
    }
249
263
 
250
 
    return -1;
 
264
    return ODPP_NONE;
251
265
}
252
266
 
253
267
static int
262
276
    dp->class = class;
263
277
    dp->name = xstrdup(name);
264
278
    dp->open_cnt = 0;
 
279
    dp->max_mtu = ETH_PAYLOAD_MAX;
265
280
    for (i = 0; i < N_QUEUES; i++) {
266
281
        dp->queues[i].head = dp->queues[i].tail = 0;
267
282
    }
268
283
    hmap_init(&dp->flow_table);
269
284
    list_init(&dp->port_list);
270
285
 
271
 
    error = do_add_port(dp, name, "internal", OVSP_LOCAL);
 
286
    error = do_add_port(dp, name, "internal", ODPP_LOCAL);
272
287
    if (error) {
273
288
        dp_netdev_free(dp);
274
289
        return error;
285
300
                 bool create, struct dpif **dpifp)
286
301
{
287
302
    struct dp_netdev *dp;
 
303
    int error;
288
304
 
 
305
    ovs_mutex_lock(&dp_netdev_mutex);
289
306
    dp = shash_find_data(&dp_netdevs, name);
290
307
    if (!dp) {
291
 
        if (!create) {
292
 
            return ENODEV;
293
 
        } else {
294
 
            int error = create_dp_netdev(name, class, &dp);
295
 
            if (error) {
296
 
                return error;
297
 
            }
298
 
            ovs_assert(dp != NULL);
299
 
        }
 
308
        error = create ? create_dp_netdev(name, class, &dp) : ENODEV;
300
309
    } else {
301
 
        if (dp->class != class) {
302
 
            return EINVAL;
303
 
        } else if (create) {
304
 
            return EEXIST;
305
 
        }
306
 
    }
 
310
        error = (dp->class != class ? EINVAL
 
311
                 : create ? EEXIST
 
312
                 : 0);
 
313
    }
 
314
    if (!error) {
 
315
        *dpifp = create_dpif_netdev(dp);
 
316
    }
 
317
    ovs_mutex_unlock(&dp_netdev_mutex);
307
318
 
308
 
    *dpifp = create_dpif_netdev(dp);
309
 
    return 0;
 
319
    return error;
310
320
}
311
321
 
312
322
static void
343
353
dpif_netdev_close(struct dpif *dpif)
344
354
{
345
355
    struct dp_netdev *dp = get_dp_netdev(dpif);
 
356
 
 
357
    ovs_mutex_lock(&dp_netdev_mutex);
 
358
 
346
359
    ovs_assert(dp->open_cnt > 0);
347
360
    if (--dp->open_cnt == 0 && dp->destroyed) {
348
361
        shash_find_and_delete(&dp_netdevs, dp->name);
349
362
        dp_netdev_free(dp);
350
363
    }
351
364
    free(dpif);
 
365
 
 
366
    ovs_mutex_unlock(&dp_netdev_mutex);
352
367
}
353
368
 
354
369
static int
355
370
dpif_netdev_destroy(struct dpif *dpif)
356
371
{
357
372
    struct dp_netdev *dp = get_dp_netdev(dpif);
 
373
 
 
374
    ovs_mutex_lock(&dp_netdev_mutex);
358
375
    dp->destroyed = true;
 
376
    ovs_mutex_unlock(&dp_netdev_mutex);
 
377
 
359
378
    return 0;
360
379
}
361
380
 
363
382
dpif_netdev_get_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
364
383
{
365
384
    struct dp_netdev *dp = get_dp_netdev(dpif);
 
385
 
 
386
    ovs_mutex_lock(&dp_netdev_mutex);
366
387
    stats->n_flows = hmap_count(&dp->flow_table);
367
388
    stats->n_hit = dp->n_hit;
368
389
    stats->n_missed = dp->n_missed;
369
390
    stats->n_lost = dp->n_lost;
 
391
    ovs_mutex_unlock(&dp_netdev_mutex);
 
392
 
370
393
    return 0;
371
394
}
372
395
 
373
396
static int
374
397
do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
375
 
            uint32_t port_no)
 
398
            odp_port_t port_no)
376
399
{
 
400
    struct netdev_saved_flags *sf;
377
401
    struct dp_netdev_port *port;
378
402
    struct netdev *netdev;
 
403
    struct netdev_rx *rx;
379
404
    const char *open_type;
380
405
    int mtu;
381
406
    int error;
391
416
    /* XXX reject loopback devices */
392
417
    /* XXX reject non-Ethernet devices */
393
418
 
394
 
    error = netdev_listen(netdev);
 
419
    error = netdev_rx_open(netdev, &rx);
395
420
    if (error
396
421
        && !(error == EOPNOTSUPP && dpif_netdev_class_is_dummy(dp->class))) {
397
422
        VLOG_ERR("%s: cannot receive packets on this network device (%s)",
398
 
                 devname, strerror(errno));
 
423
                 devname, ovs_strerror(errno));
399
424
        netdev_close(netdev);
400
425
        return error;
401
426
    }
402
427
 
403
 
    error = netdev_turn_flags_on(netdev, NETDEV_PROMISC, false);
 
428
    error = netdev_turn_flags_on(netdev, NETDEV_PROMISC, &sf);
404
429
    if (error) {
 
430
        netdev_rx_close(rx);
405
431
        netdev_close(netdev);
406
432
        return error;
407
433
    }
409
435
    port = xmalloc(sizeof *port);
410
436
    port->port_no = port_no;
411
437
    port->netdev = netdev;
 
438
    port->sf = sf;
 
439
    port->rx = rx;
412
440
    port->type = xstrdup(type);
413
441
 
414
442
    error = netdev_get_mtu(netdev, &mtu);
415
 
    if (!error) {
416
 
        max_mtu = mtu;
 
443
    if (!error && mtu > dp->max_mtu) {
 
444
        dp->max_mtu = mtu;
417
445
    }
418
446
 
419
447
    list_push_back(&dp->port_list, &port->node);
420
 
    dp->ports[port_no] = port;
 
448
    dp->ports[odp_to_u32(port_no)] = port;
421
449
    dp->serial++;
422
450
 
423
451
    return 0;
425
453
 
426
454
static int
427
455
dpif_netdev_port_add(struct dpif *dpif, struct netdev *netdev,
428
 
                     uint32_t *port_nop)
 
456
                     odp_port_t *port_nop)
429
457
{
430
458
    struct dp_netdev *dp = get_dp_netdev(dpif);
431
 
    int port_no;
 
459
    char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
 
460
    const char *dpif_port;
 
461
    odp_port_t port_no;
 
462
    int error;
432
463
 
433
 
    if (*port_nop != UINT32_MAX) {
434
 
        if (*port_nop >= MAX_PORTS) {
435
 
            return EFBIG;
436
 
        } else if (dp->ports[*port_nop]) {
437
 
            return EBUSY;
 
464
    ovs_mutex_lock(&dp_netdev_mutex);
 
465
    dpif_port = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
 
466
    if (*port_nop != ODPP_NONE) {
 
467
        uint32_t port_idx = odp_to_u32(*port_nop);
 
468
        if (port_idx >= MAX_PORTS) {
 
469
            error = EFBIG;
 
470
        } else if (dp->ports[port_idx]) {
 
471
            error = EBUSY;
 
472
        } else {
 
473
            error = 0;
 
474
            port_no = *port_nop;
438
475
        }
439
 
        port_no = *port_nop;
440
476
    } else {
441
 
        port_no = choose_port(dp, netdev_vport_get_dpif_port(netdev));
 
477
        port_no = choose_port(dp, dpif_port);
 
478
        error = port_no == ODPP_NONE ? EFBIG : 0;
442
479
    }
443
 
    if (port_no >= 0) {
 
480
    if (!error) {
444
481
        *port_nop = port_no;
445
 
        return do_add_port(dp, netdev_vport_get_dpif_port(netdev),
446
 
                           netdev_get_type(netdev), port_no);
 
482
        error = do_add_port(dp, dpif_port, netdev_get_type(netdev), port_no);
447
483
    }
448
 
    return EFBIG;
 
484
    ovs_mutex_unlock(&dp_netdev_mutex);
 
485
 
 
486
    return error;
449
487
}
450
488
 
451
489
static int
452
 
dpif_netdev_port_del(struct dpif *dpif, uint32_t port_no)
 
490
dpif_netdev_port_del(struct dpif *dpif, odp_port_t port_no)
453
491
{
454
492
    struct dp_netdev *dp = get_dp_netdev(dpif);
455
 
    return port_no == OVSP_LOCAL ? EINVAL : do_del_port(dp, port_no);
 
493
    int error;
 
494
 
 
495
    ovs_mutex_lock(&dp_netdev_mutex);
 
496
    error = port_no == ODPP_LOCAL ? EINVAL : do_del_port(dp, port_no);
 
497
    ovs_mutex_unlock(&dp_netdev_mutex);
 
498
 
 
499
    return error;
456
500
}
457
501
 
458
502
static bool
459
 
is_valid_port_number(uint32_t port_no)
 
503
is_valid_port_number(odp_port_t port_no)
460
504
{
461
 
    return port_no < MAX_PORTS;
 
505
    return odp_to_u32(port_no) < MAX_PORTS;
462
506
}
463
507
 
464
508
static int
465
509
get_port_by_number(struct dp_netdev *dp,
466
 
                   uint32_t port_no, struct dp_netdev_port **portp)
 
510
                   odp_port_t port_no, struct dp_netdev_port **portp)
467
511
{
468
512
    if (!is_valid_port_number(port_no)) {
469
513
        *portp = NULL;
470
514
        return EINVAL;
471
515
    } else {
472
 
        *portp = dp->ports[port_no];
 
516
        *portp = dp->ports[odp_to_u32(port_no)];
473
517
        return *portp ? 0 : ENOENT;
474
518
    }
475
519
}
490
534
}
491
535
 
492
536
static int
493
 
do_del_port(struct dp_netdev *dp, uint32_t port_no)
 
537
do_del_port(struct dp_netdev *dp, odp_port_t port_no)
494
538
{
495
539
    struct dp_netdev_port *port;
496
 
    char *name;
497
540
    int error;
498
541
 
499
542
    error = get_port_by_number(dp, port_no, &port);
502
545
    }
503
546
 
504
547
    list_remove(&port->node);
505
 
    dp->ports[port->port_no] = NULL;
 
548
    dp->ports[odp_to_u32(port_no)] = NULL;
506
549
    dp->serial++;
507
550
 
508
 
    name = xstrdup(netdev_vport_get_dpif_port(port->netdev));
509
551
    netdev_close(port->netdev);
 
552
    netdev_restore_flags(port->sf);
 
553
    netdev_rx_close(port->rx);
510
554
    free(port->type);
511
 
 
512
 
    free(name);
513
555
    free(port);
514
556
 
515
557
    return 0;
525
567
}
526
568
 
527
569
static int
528
 
dpif_netdev_port_query_by_number(const struct dpif *dpif, uint32_t port_no,
 
570
dpif_netdev_port_query_by_number(const struct dpif *dpif, odp_port_t port_no,
529
571
                                 struct dpif_port *dpif_port)
530
572
{
531
573
    struct dp_netdev *dp = get_dp_netdev(dpif);
532
574
    struct dp_netdev_port *port;
533
575
    int error;
534
576
 
 
577
    ovs_mutex_lock(&dp_netdev_mutex);
535
578
    error = get_port_by_number(dp, port_no, &port);
536
579
    if (!error && dpif_port) {
537
580
        answer_port_query(port, dpif_port);
538
581
    }
 
582
    ovs_mutex_unlock(&dp_netdev_mutex);
 
583
 
539
584
    return error;
540
585
}
541
586
 
547
592
    struct dp_netdev_port *port;
548
593
    int error;
549
594
 
 
595
    ovs_mutex_lock(&dp_netdev_mutex);
550
596
    error = get_port_by_name(dp, devname, &port);
551
597
    if (!error && dpif_port) {
552
598
        answer_port_query(port, dpif_port);
553
599
    }
 
600
    ovs_mutex_unlock(&dp_netdev_mutex);
 
601
 
554
602
    return error;
555
603
}
556
604
 
557
 
static int
 
605
static odp_port_t
558
606
dpif_netdev_get_max_ports(const struct dpif *dpif OVS_UNUSED)
559
607
{
560
 
    return MAX_PORTS;
 
608
    return u32_to_odp(MAX_PORTS);
561
609
}
562
610
 
563
611
static void
582
630
dpif_netdev_flow_flush(struct dpif *dpif)
583
631
{
584
632
    struct dp_netdev *dp = get_dp_netdev(dpif);
 
633
 
 
634
    ovs_mutex_lock(&dp_netdev_mutex);
585
635
    dp_netdev_flow_flush(dp);
 
636
    ovs_mutex_unlock(&dp_netdev_mutex);
 
637
 
586
638
    return 0;
587
639
}
588
640
 
589
641
struct dp_netdev_port_state {
590
 
    uint32_t port_no;
 
642
    odp_port_t port_no;
591
643
    char *name;
592
644
};
593
645
 
604
656
{
605
657
    struct dp_netdev_port_state *state = state_;
606
658
    struct dp_netdev *dp = get_dp_netdev(dpif);
607
 
    uint32_t port_no;
 
659
    uint32_t port_idx;
608
660
 
609
 
    for (port_no = state->port_no; port_no < MAX_PORTS; port_no++) {
610
 
        struct dp_netdev_port *port = dp->ports[port_no];
 
661
    ovs_mutex_lock(&dp_netdev_mutex);
 
662
    for (port_idx = odp_to_u32(state->port_no);
 
663
         port_idx < MAX_PORTS; port_idx++) {
 
664
        struct dp_netdev_port *port = dp->ports[port_idx];
611
665
        if (port) {
612
666
            free(state->name);
613
667
            state->name = xstrdup(netdev_get_name(port->netdev));
614
668
            dpif_port->name = state->name;
615
669
            dpif_port->type = port->type;
616
670
            dpif_port->port_no = port->port_no;
617
 
            state->port_no = port_no + 1;
 
671
            state->port_no = u32_to_odp(port_idx + 1);
 
672
            ovs_mutex_unlock(&dp_netdev_mutex);
 
673
 
618
674
            return 0;
619
675
        }
620
676
    }
 
677
    ovs_mutex_unlock(&dp_netdev_mutex);
 
678
 
621
679
    return EOF;
622
680
}
623
681
 
634
692
dpif_netdev_port_poll(const struct dpif *dpif_, char **devnamep OVS_UNUSED)
635
693
{
636
694
    struct dpif_netdev *dpif = dpif_netdev_cast(dpif_);
 
695
    int error;
 
696
 
 
697
    ovs_mutex_lock(&dp_netdev_mutex);
637
698
    if (dpif->dp_serial != dpif->dp->serial) {
638
699
        dpif->dp_serial = dpif->dp->serial;
639
 
        return ENOBUFS;
 
700
        error = ENOBUFS;
640
701
    } else {
641
 
        return EAGAIN;
 
702
        error = EAGAIN;
642
703
    }
 
704
    ovs_mutex_unlock(&dp_netdev_mutex);
 
705
 
 
706
    return error;
643
707
}
644
708
 
645
709
static void
646
710
dpif_netdev_port_poll_wait(const struct dpif *dpif_)
647
711
{
648
712
    struct dpif_netdev *dpif = dpif_netdev_cast(dpif_);
 
713
 
 
714
    /* XXX In a multithreaded process, there is a race window between this
 
715
     * function and the poll_block() in one thread and a change in
 
716
     * dpif->dp->serial in another thread. */
 
717
 
 
718
    ovs_mutex_lock(&dp_netdev_mutex);
649
719
    if (dpif->dp_serial != dpif->dp->serial) {
650
720
        poll_immediate_wake();
651
721
    }
 
722
    ovs_mutex_unlock(&dp_netdev_mutex);
652
723
}
653
724
 
654
725
static struct dp_netdev_flow *
677
748
dpif_netdev_flow_from_nlattrs(const struct nlattr *key, uint32_t key_len,
678
749
                              struct flow *flow)
679
750
{
 
751
    odp_port_t in_port;
 
752
 
680
753
    if (odp_flow_key_to_flow(key, key_len, flow) != ODP_FIT_PERFECT) {
681
754
        /* This should not happen: it indicates that odp_flow_key_from_flow()
682
755
         * and odp_flow_key_to_flow() disagree on the acceptable form of a
696
769
        return EINVAL;
697
770
    }
698
771
 
699
 
    if (flow->in_port < OFPP_MAX
700
 
        ? flow->in_port >= MAX_PORTS
701
 
        : flow->in_port != OFPP_LOCAL && flow->in_port != OFPP_NONE) {
 
772
    in_port = flow->in_port.odp_port;
 
773
    if (!is_valid_port_number(in_port) && in_port != ODPP_NONE) {
702
774
        return EINVAL;
703
775
    }
704
776
 
720
792
        return error;
721
793
    }
722
794
 
 
795
    ovs_mutex_lock(&dp_netdev_mutex);
723
796
    flow = dp_netdev_lookup_flow(dp, &key);
724
 
    if (!flow) {
725
 
        return ENOENT;
 
797
    if (flow) {
 
798
        if (stats) {
 
799
            get_dpif_flow_stats(flow, stats);
 
800
        }
 
801
        if (actionsp) {
 
802
            *actionsp = ofpbuf_clone_data(flow->actions, flow->actions_len);
 
803
        }
 
804
    } else {
 
805
        error = ENOENT;
726
806
    }
 
807
    ovs_mutex_unlock(&dp_netdev_mutex);
727
808
 
728
 
    if (stats) {
729
 
        get_dpif_flow_stats(flow, stats);
730
 
    }
731
 
    if (actionsp) {
732
 
        *actionsp = ofpbuf_clone_data(flow->actions, flow->actions_len);
733
 
    }
734
 
    return 0;
 
809
    return error;
735
810
}
736
811
 
737
812
static int
786
861
        return error;
787
862
    }
788
863
 
 
864
    ovs_mutex_lock(&dp_netdev_mutex);
789
865
    flow = dp_netdev_lookup_flow(dp, &key);
790
866
    if (!flow) {
791
867
        if (put->flags & DPIF_FP_CREATE) {
793
869
                if (put->stats) {
794
870
                    memset(put->stats, 0, sizeof *put->stats);
795
871
                }
796
 
                return dp_netdev_flow_add(dp, &key, put->actions,
797
 
                                          put->actions_len);
 
872
                error = dp_netdev_flow_add(dp, &key, put->actions,
 
873
                                           put->actions_len);
798
874
            } else {
799
 
                return EFBIG;
 
875
                error = EFBIG;
800
876
            }
801
877
        } else {
802
 
            return ENOENT;
 
878
            error = ENOENT;
803
879
        }
804
880
    } else {
805
881
        if (put->flags & DPIF_FP_MODIFY) {
806
 
            int error = set_flow_actions(flow, put->actions, put->actions_len);
 
882
            error = set_flow_actions(flow, put->actions, put->actions_len);
807
883
            if (!error) {
808
884
                if (put->stats) {
809
885
                    get_dpif_flow_stats(flow, put->stats);
812
888
                    clear_stats(flow);
813
889
                }
814
890
            }
815
 
            return error;
816
891
        } else {
817
 
            return EEXIST;
 
892
            error = EEXIST;
818
893
        }
819
894
    }
 
895
    ovs_mutex_unlock(&dp_netdev_mutex);
 
896
 
 
897
    return error;
820
898
}
821
899
 
822
900
static int
832
910
        return error;
833
911
    }
834
912
 
 
913
    ovs_mutex_lock(&dp_netdev_mutex);
835
914
    flow = dp_netdev_lookup_flow(dp, &key);
836
915
    if (flow) {
837
916
        if (del->stats) {
838
917
            get_dpif_flow_stats(flow, del->stats);
839
918
        }
840
919
        dp_netdev_free_flow(dp, flow);
841
 
        return 0;
842
920
    } else {
843
 
        return ENOENT;
 
921
        error = ENOENT;
844
922
    }
 
923
    ovs_mutex_unlock(&dp_netdev_mutex);
 
924
 
 
925
    return error;
845
926
}
846
927
 
847
928
struct dp_netdev_flow_state {
867
948
static int
868
949
dpif_netdev_flow_dump_next(const struct dpif *dpif, void *state_,
869
950
                           const struct nlattr **key, size_t *key_len,
 
951
                           const struct nlattr **mask, size_t *mask_len,
870
952
                           const struct nlattr **actions, size_t *actions_len,
871
953
                           const struct dpif_flow_stats **stats)
872
954
{
875
957
    struct dp_netdev_flow *flow;
876
958
    struct hmap_node *node;
877
959
 
 
960
    ovs_mutex_lock(&dp_netdev_mutex);
878
961
    node = hmap_at_position(&dp->flow_table, &state->bucket, &state->offset);
879
962
    if (!node) {
 
963
        ovs_mutex_unlock(&dp_netdev_mutex);
880
964
        return EOF;
881
965
    }
882
966
 
886
970
        struct ofpbuf buf;
887
971
 
888
972
        ofpbuf_use_stack(&buf, &state->keybuf, sizeof state->keybuf);
889
 
        odp_flow_key_from_flow(&buf, &flow->key, flow->key.in_port);
 
973
        odp_flow_key_from_flow(&buf, &flow->key, flow->key.in_port.odp_port);
890
974
 
891
975
        *key = buf.data;
892
976
        *key_len = buf.size;
893
977
    }
894
978
 
 
979
    if (mask) {
 
980
        *mask = NULL;
 
981
        *mask_len = 0;
 
982
    }
 
983
 
895
984
    if (actions) {
896
985
        free(state->actions);
897
986
        state->actions = xmemdup(flow->actions, flow->actions_len);
905
994
        *stats = &state->stats;
906
995
    }
907
996
 
 
997
    ovs_mutex_unlock(&dp_netdev_mutex);
908
998
    return 0;
909
999
}
910
1000
 
936
1026
    ofpbuf_reserve(&copy, DP_NETDEV_HEADROOM);
937
1027
    ofpbuf_put(&copy, execute->packet->data, execute->packet->size);
938
1028
 
939
 
    flow_extract(&copy, 0, 0, NULL, -1, &key);
 
1029
    flow_extract(&copy, 0, 0, NULL, NULL, &key);
940
1030
    error = dpif_netdev_flow_from_nlattrs(execute->key, execute->key_len,
941
1031
                                          &key);
942
1032
    if (!error) {
 
1033
        ovs_mutex_lock(&dp_netdev_mutex);
943
1034
        dp_netdev_execute_actions(dp, &copy, &key,
944
1035
                                  execute->actions, execute->actions_len);
 
1036
        ovs_mutex_unlock(&dp_netdev_mutex);
945
1037
    }
946
1038
 
947
1039
    ofpbuf_uninit(&copy);
981
1073
dpif_netdev_recv(struct dpif *dpif, struct dpif_upcall *upcall,
982
1074
                 struct ofpbuf *buf)
983
1075
{
984
 
    struct dp_netdev_queue *q = find_nonempty_queue(dpif);
 
1076
    struct dp_netdev_queue *q;
 
1077
    int error;
 
1078
 
 
1079
    ovs_mutex_lock(&dp_netdev_mutex);
 
1080
    q = find_nonempty_queue(dpif);
985
1081
    if (q) {
986
1082
        struct dp_netdev_upcall *u = &q->upcalls[q->tail++ & QUEUE_MASK];
987
1083
 
991
1087
        ofpbuf_uninit(buf);
992
1088
        *buf = u->buf;
993
1089
 
994
 
        return 0;
 
1090
        error = 0;
995
1091
    } else {
996
 
        return EAGAIN;
 
1092
        error = EAGAIN;
997
1093
    }
 
1094
    ovs_mutex_unlock(&dp_netdev_mutex);
 
1095
 
 
1096
    return error;
998
1097
}
999
1098
 
1000
1099
static void
1001
1100
dpif_netdev_recv_wait(struct dpif *dpif)
1002
1101
{
 
1102
    /* XXX In a multithreaded process, there is a race window between this
 
1103
     * function and the poll_block() in one thread and a packet being queued in
 
1104
     * another thread. */
 
1105
 
 
1106
    ovs_mutex_lock(&dp_netdev_mutex);
1003
1107
    if (find_nonempty_queue(dpif)) {
1004
1108
        poll_immediate_wake();
1005
 
    } else {
1006
 
        /* No messages ready to be received, and dp_wait() will ensure that we
1007
 
         * wake up to queue new messages, so there is nothing to do. */
1008
1109
    }
 
1110
    ovs_mutex_unlock(&dp_netdev_mutex);
1009
1111
}
1010
1112
 
1011
1113
static void
1012
1114
dpif_netdev_recv_purge(struct dpif *dpif)
1013
1115
{
1014
1116
    struct dpif_netdev *dpif_netdev = dpif_netdev_cast(dpif);
 
1117
    ovs_mutex_lock(&dp_netdev_mutex);
1015
1118
    dp_netdev_purge_queues(dpif_netdev->dp);
 
1119
    ovs_mutex_unlock(&dp_netdev_mutex);
1016
1120
}
1017
1121
 
1018
1122
static void
1026
1130
 
1027
1131
static void
1028
1132
dp_netdev_port_input(struct dp_netdev *dp, struct dp_netdev_port *port,
1029
 
                     struct ofpbuf *packet)
 
1133
                     struct ofpbuf *packet, uint32_t skb_priority,
 
1134
                     uint32_t skb_mark, const struct flow_tnl *tnl)
1030
1135
{
1031
1136
    struct dp_netdev_flow *flow;
1032
1137
    struct flow key;
 
1138
    union flow_in_port in_port_;
1033
1139
 
1034
1140
    if (packet->size < ETH_HEADER_LEN) {
1035
1141
        return;
1036
1142
    }
1037
 
    flow_extract(packet, 0, 0, NULL, port->port_no, &key);
 
1143
    in_port_.odp_port = port->port_no;
 
1144
    flow_extract(packet, skb_priority, skb_mark, tnl, &in_port_, &key);
1038
1145
    flow = dp_netdev_lookup_flow(dp, &key);
1039
1146
    if (flow) {
1040
1147
        dp_netdev_flow_used(flow, packet);
1043
1150
        dp->n_hit++;
1044
1151
    } else {
1045
1152
        dp->n_missed++;
1046
 
        dp_netdev_output_userspace(dp, packet, DPIF_UC_MISS, &key, 0);
 
1153
        dp_netdev_output_userspace(dp, packet, DPIF_UC_MISS, &key, NULL);
1047
1154
    }
1048
1155
}
1049
1156
 
1050
1157
static void
1051
1158
dpif_netdev_run(struct dpif *dpif)
1052
1159
{
1053
 
    struct dp_netdev *dp = get_dp_netdev(dpif);
1054
1160
    struct dp_netdev_port *port;
 
1161
    struct dp_netdev *dp;
1055
1162
    struct ofpbuf packet;
1056
1163
 
1057
 
    ofpbuf_init(&packet, DP_NETDEV_HEADROOM + VLAN_ETH_HEADER_LEN + max_mtu);
 
1164
    ovs_mutex_lock(&dp_netdev_mutex);
 
1165
    dp = get_dp_netdev(dpif);
 
1166
    ofpbuf_init(&packet,
 
1167
                DP_NETDEV_HEADROOM + VLAN_ETH_HEADER_LEN + dp->max_mtu);
1058
1168
 
1059
1169
    LIST_FOR_EACH (port, node, &dp->port_list) {
1060
1170
        int error;
1063
1173
        ofpbuf_clear(&packet);
1064
1174
        ofpbuf_reserve(&packet, DP_NETDEV_HEADROOM);
1065
1175
 
1066
 
        error = netdev_recv(port->netdev, &packet);
 
1176
        error = port->rx ? netdev_rx_recv(port->rx, &packet) : EOPNOTSUPP;
1067
1177
        if (!error) {
1068
 
            dp_netdev_port_input(dp, port, &packet);
 
1178
            dp_netdev_port_input(dp, port, &packet, 0, 0, NULL);
1069
1179
        } else if (error != EAGAIN && error != EOPNOTSUPP) {
1070
1180
            static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
 
1181
 
1071
1182
            VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
1072
 
                        netdev_get_name(port->netdev), strerror(error));
 
1183
                        netdev_get_name(port->netdev), ovs_strerror(error));
1073
1184
        }
1074
1185
    }
1075
1186
    ofpbuf_uninit(&packet);
 
1187
    ovs_mutex_unlock(&dp_netdev_mutex);
1076
1188
}
1077
1189
 
1078
1190
static void
1079
1191
dpif_netdev_wait(struct dpif *dpif)
1080
1192
{
1081
 
    struct dp_netdev *dp = get_dp_netdev(dpif);
1082
1193
    struct dp_netdev_port *port;
1083
1194
 
1084
 
    LIST_FOR_EACH (port, node, &dp->port_list) {
1085
 
        netdev_recv_wait(port->netdev);
 
1195
    /* There is a race here, if thread A calls dpif_netdev_wait(dpif) and
 
1196
     * thread B calls dpif_port_add(dpif) or dpif_port_remove(dpif) before
 
1197
     * A makes it to poll_block().
 
1198
     *
 
1199
     * But I think it doesn't matter:
 
1200
     *
 
1201
     *     - In the dpif_port_add() case, A will not wake up when a packet
 
1202
     *       arrives on the new port, but this would also happen if the
 
1203
     *       ordering were reversed.
 
1204
     *
 
1205
     *     - In the dpif_port_remove() case, A might wake up spuriously, but
 
1206
     *       that is harmless. */
 
1207
 
 
1208
    ovs_mutex_lock(&dp_netdev_mutex);
 
1209
    LIST_FOR_EACH (port, node, &get_dp_netdev(dpif)->port_list) {
 
1210
        if (port->rx) {
 
1211
            netdev_rx_wait(port->rx);
 
1212
        }
1086
1213
    }
1087
 
}
1088
 
 
1089
 
static void
1090
 
dp_netdev_set_dl(struct ofpbuf *packet, const struct ovs_key_ethernet *eth_key)
1091
 
{
1092
 
    struct eth_header *eh = packet->l2;
1093
 
 
1094
 
    memcpy(eh->eth_src, eth_key->eth_src, sizeof eh->eth_src);
1095
 
    memcpy(eh->eth_dst, eth_key->eth_dst, sizeof eh->eth_dst);
1096
 
}
1097
 
 
1098
 
static void
1099
 
dp_netdev_output_port(struct dp_netdev *dp, struct ofpbuf *packet,
1100
 
                      uint32_t out_port)
1101
 
{
 
1214
    ovs_mutex_unlock(&dp_netdev_mutex);
 
1215
}
 
1216
 
 
1217
static void
 
1218
dp_netdev_output_port(void *dp_, struct ofpbuf *packet, uint32_t out_port)
 
1219
{
 
1220
    struct dp_netdev *dp = dp_;
1102
1221
    struct dp_netdev_port *p = dp->ports[out_port];
1103
1222
    if (p) {
1104
1223
        netdev_send(p->netdev, packet);
1107
1226
 
1108
1227
static int
1109
1228
dp_netdev_output_userspace(struct dp_netdev *dp, const struct ofpbuf *packet,
1110
 
                         int queue_no, const struct flow *flow, uint64_t arg)
 
1229
                           int queue_no, const struct flow *flow,
 
1230
                           const struct nlattr *userdata)
1111
1231
{
1112
1232
    struct dp_netdev_queue *q = &dp->queues[queue_no];
1113
 
    struct dp_netdev_upcall *u;
1114
 
    struct dpif_upcall *upcall;
1115
 
    struct ofpbuf *buf;
1116
 
    size_t key_len;
1117
 
 
1118
 
    if (q->head - q->tail >= MAX_QUEUE_LEN) {
 
1233
    if (q->head - q->tail < MAX_QUEUE_LEN) {
 
1234
        struct dp_netdev_upcall *u = &q->upcalls[q->head++ & QUEUE_MASK];
 
1235
        struct dpif_upcall *upcall = &u->upcall;
 
1236
        struct ofpbuf *buf = &u->buf;
 
1237
        size_t buf_size;
 
1238
 
 
1239
        upcall->type = queue_no;
 
1240
 
 
1241
        /* Allocate buffer big enough for everything. */
 
1242
        buf_size = ODPUTIL_FLOW_KEY_BYTES + 2 + packet->size;
 
1243
        if (userdata) {
 
1244
            buf_size += NLA_ALIGN(userdata->nla_len);
 
1245
        }
 
1246
        ofpbuf_init(buf, buf_size);
 
1247
 
 
1248
        /* Put ODP flow. */
 
1249
        odp_flow_key_from_flow(buf, flow, flow->in_port.odp_port);
 
1250
        upcall->key = buf->data;
 
1251
        upcall->key_len = buf->size;
 
1252
 
 
1253
        /* Put userdata. */
 
1254
        if (userdata) {
 
1255
            upcall->userdata = ofpbuf_put(buf, userdata,
 
1256
                                          NLA_ALIGN(userdata->nla_len));
 
1257
        }
 
1258
 
 
1259
        /* Put packet.
 
1260
         *
 
1261
         * We adjust 'data' and 'size' in 'buf' so that only the packet itself
 
1262
         * is visible in 'upcall->packet'.  The ODP flow and (if present)
 
1263
         * userdata become part of the headroom. */
 
1264
        ofpbuf_put_zeros(buf, 2);
 
1265
        buf->data = ofpbuf_put(buf, packet->data, packet->size);
 
1266
        buf->size = packet->size;
 
1267
        upcall->packet = buf;
 
1268
 
 
1269
        return 0;
 
1270
    } else {
1119
1271
        dp->n_lost++;
1120
1272
        return ENOBUFS;
1121
1273
    }
1122
 
 
1123
 
    u = &q->upcalls[q->head++ & QUEUE_MASK];
1124
 
 
1125
 
    buf = &u->buf;
1126
 
    ofpbuf_init(buf, ODPUTIL_FLOW_KEY_BYTES + 2 + packet->size);
1127
 
    odp_flow_key_from_flow(buf, flow, flow->in_port);
1128
 
    key_len = buf->size;
1129
 
    ofpbuf_pull(buf, key_len);
1130
 
    ofpbuf_reserve(buf, 2);
1131
 
    ofpbuf_put(buf, packet->data, packet->size);
1132
 
 
1133
 
    upcall = &u->upcall;
1134
 
    upcall->type = queue_no;
1135
 
    upcall->packet = buf;
1136
 
    upcall->key = buf->base;
1137
 
    upcall->key_len = key_len;
1138
 
    upcall->userdata = arg;
1139
 
 
1140
 
    return 0;
1141
 
}
1142
 
 
1143
 
static void
1144
 
dp_netdev_sample(struct dp_netdev *dp,
1145
 
                 struct ofpbuf *packet, struct flow *key,
1146
 
                 const struct nlattr *action)
1147
 
{
1148
 
    const struct nlattr *subactions = NULL;
1149
 
    const struct nlattr *a;
1150
 
    size_t left;
1151
 
 
1152
 
    NL_NESTED_FOR_EACH_UNSAFE (a, left, action) {
1153
 
        int type = nl_attr_type(a);
1154
 
 
1155
 
        switch ((enum ovs_sample_attr) type) {
1156
 
        case OVS_SAMPLE_ATTR_PROBABILITY:
1157
 
            if (random_uint32() >= nl_attr_get_u32(a)) {
1158
 
                return;
1159
 
            }
1160
 
            break;
1161
 
 
1162
 
        case OVS_SAMPLE_ATTR_ACTIONS:
1163
 
            subactions = a;
1164
 
            break;
1165
 
 
1166
 
        case OVS_SAMPLE_ATTR_UNSPEC:
1167
 
        case __OVS_SAMPLE_ATTR_MAX:
1168
 
        default:
1169
 
            NOT_REACHED();
1170
 
        }
1171
 
    }
1172
 
 
1173
 
    dp_netdev_execute_actions(dp, packet, key, nl_attr_get(subactions),
1174
 
                              nl_attr_get_size(subactions));
1175
 
}
1176
 
 
1177
 
static void
1178
 
dp_netdev_action_userspace(struct dp_netdev *dp,
1179
 
                          struct ofpbuf *packet, struct flow *key,
1180
 
                          const struct nlattr *a)
1181
 
{
1182
 
    const struct nlattr *userdata_attr;
1183
 
    uint64_t userdata;
1184
 
 
1185
 
    userdata_attr = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
1186
 
    userdata = userdata_attr ? nl_attr_get_u64(userdata_attr) : 0;
 
1274
}
 
1275
 
 
1276
static void
 
1277
dp_netdev_action_userspace(void *dp, struct ofpbuf *packet,
 
1278
                           const struct flow *key,
 
1279
                           const struct nlattr *userdata)
 
1280
{
1187
1281
    dp_netdev_output_userspace(dp, packet, DPIF_UC_ACTION, key, userdata);
1188
1282
}
1189
1283
 
1190
1284
static void
1191
 
execute_set_action(struct ofpbuf *packet, const struct nlattr *a)
1192
 
{
1193
 
    enum ovs_key_attr type = nl_attr_type(a);
1194
 
    const struct ovs_key_ipv4 *ipv4_key;
1195
 
    const struct ovs_key_ipv6 *ipv6_key;
1196
 
    const struct ovs_key_tcp *tcp_key;
1197
 
    const struct ovs_key_udp *udp_key;
1198
 
 
1199
 
    switch (type) {
1200
 
    case OVS_KEY_ATTR_PRIORITY:
1201
 
    case OVS_KEY_ATTR_SKB_MARK:
1202
 
    case OVS_KEY_ATTR_TUNNEL:
1203
 
        /* not implemented */
1204
 
        break;
1205
 
 
1206
 
    case OVS_KEY_ATTR_ETHERNET:
1207
 
        dp_netdev_set_dl(packet,
1208
 
                   nl_attr_get_unspec(a, sizeof(struct ovs_key_ethernet)));
1209
 
        break;
1210
 
 
1211
 
    case OVS_KEY_ATTR_IPV4:
1212
 
        ipv4_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv4));
1213
 
        packet_set_ipv4(packet, ipv4_key->ipv4_src, ipv4_key->ipv4_dst,
1214
 
                        ipv4_key->ipv4_tos, ipv4_key->ipv4_ttl);
1215
 
        break;
1216
 
 
1217
 
    case OVS_KEY_ATTR_IPV6:
1218
 
        ipv6_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv6));
1219
 
        packet_set_ipv6(packet, ipv6_key->ipv6_proto, ipv6_key->ipv6_src,
1220
 
                        ipv6_key->ipv6_dst, ipv6_key->ipv6_tclass,
1221
 
                        ipv6_key->ipv6_label, ipv6_key->ipv6_hlimit);
1222
 
        break;
1223
 
 
1224
 
    case OVS_KEY_ATTR_TCP:
1225
 
        tcp_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_tcp));
1226
 
        packet_set_tcp_port(packet, tcp_key->tcp_src, tcp_key->tcp_dst);
1227
 
        break;
1228
 
 
1229
 
     case OVS_KEY_ATTR_UDP:
1230
 
        udp_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_udp));
1231
 
        packet_set_udp_port(packet, udp_key->udp_src, udp_key->udp_dst);
1232
 
        break;
1233
 
 
1234
 
     case OVS_KEY_ATTR_UNSPEC:
1235
 
     case OVS_KEY_ATTR_ENCAP:
1236
 
     case OVS_KEY_ATTR_ETHERTYPE:
1237
 
     case OVS_KEY_ATTR_IN_PORT:
1238
 
     case OVS_KEY_ATTR_VLAN:
1239
 
     case OVS_KEY_ATTR_ICMP:
1240
 
     case OVS_KEY_ATTR_ICMPV6:
1241
 
     case OVS_KEY_ATTR_ARP:
1242
 
     case OVS_KEY_ATTR_ND:
1243
 
     case __OVS_KEY_ATTR_MAX:
1244
 
     default:
1245
 
        NOT_REACHED();
1246
 
    }
1247
 
}
1248
 
 
1249
 
static void
1250
1285
dp_netdev_execute_actions(struct dp_netdev *dp,
1251
1286
                          struct ofpbuf *packet, struct flow *key,
1252
1287
                          const struct nlattr *actions,
1253
1288
                          size_t actions_len)
1254
1289
{
1255
 
    const struct nlattr *a;
1256
 
    unsigned int left;
1257
 
 
1258
 
    NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) {
1259
 
        int type = nl_attr_type(a);
1260
 
 
1261
 
        switch ((enum ovs_action_attr) type) {
1262
 
        case OVS_ACTION_ATTR_OUTPUT:
1263
 
            dp_netdev_output_port(dp, packet, nl_attr_get_u32(a));
1264
 
            break;
1265
 
 
1266
 
        case OVS_ACTION_ATTR_USERSPACE:
1267
 
            dp_netdev_action_userspace(dp, packet, key, a);
1268
 
            break;
1269
 
 
1270
 
        case OVS_ACTION_ATTR_PUSH_VLAN: {
1271
 
            const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
1272
 
            eth_push_vlan(packet, vlan->vlan_tci);
1273
 
            break;
1274
 
        }
1275
 
 
1276
 
        case OVS_ACTION_ATTR_POP_VLAN:
1277
 
            eth_pop_vlan(packet);
1278
 
            break;
1279
 
 
1280
 
        case OVS_ACTION_ATTR_SET:
1281
 
            execute_set_action(packet, nl_attr_get(a));
1282
 
            break;
1283
 
 
1284
 
        case OVS_ACTION_ATTR_SAMPLE:
1285
 
            dp_netdev_sample(dp, packet, key, a);
1286
 
            break;
1287
 
 
1288
 
        case OVS_ACTION_ATTR_UNSPEC:
1289
 
        case __OVS_ACTION_ATTR_MAX:
1290
 
            NOT_REACHED();
1291
 
        }
1292
 
    }
 
1290
    odp_execute_actions(dp, packet, key, actions, actions_len,
 
1291
                        dp_netdev_output_port, dp_netdev_action_userspace);
1293
1292
}
1294
1293
 
1295
1294
const struct dpif_class dpif_netdev_class = {
1330
1329
};
1331
1330
 
1332
1331
static void
 
1332
dpif_dummy_change_port_number(struct unixctl_conn *conn, int argc OVS_UNUSED,
 
1333
                              const char *argv[], void *aux OVS_UNUSED)
 
1334
{
 
1335
    struct dp_netdev_port *port;
 
1336
    struct dp_netdev *dp;
 
1337
    int port_no;
 
1338
 
 
1339
    dp = shash_find_data(&dp_netdevs, argv[1]);
 
1340
    if (!dp || !dpif_netdev_class_is_dummy(dp->class)) {
 
1341
        unixctl_command_reply_error(conn, "unknown datapath or not a dummy");
 
1342
        return;
 
1343
    }
 
1344
 
 
1345
    if (get_port_by_name(dp, argv[2], &port)) {
 
1346
        unixctl_command_reply_error(conn, "unknown port");
 
1347
        return;
 
1348
    }
 
1349
 
 
1350
    port_no = atoi(argv[3]);
 
1351
    if (port_no <= 0 || port_no >= MAX_PORTS) {
 
1352
        unixctl_command_reply_error(conn, "bad port number");
 
1353
        return;
 
1354
    }
 
1355
    if (dp->ports[port_no]) {
 
1356
        unixctl_command_reply_error(conn, "port number already in use");
 
1357
        return;
 
1358
    }
 
1359
    dp->ports[odp_to_u32(port->port_no)] = NULL;
 
1360
    dp->ports[port_no] = port;
 
1361
    port->port_no = u32_to_odp(port_no);
 
1362
    dp->serial++;
 
1363
    unixctl_command_reply(conn, NULL);
 
1364
}
 
1365
 
 
1366
static void
1333
1367
dpif_dummy_register__(const char *type)
1334
1368
{
1335
1369
    struct dpif_class *class;
1358
1392
    }
1359
1393
 
1360
1394
    dpif_dummy_register__("dummy");
 
1395
 
 
1396
    unixctl_command_register("dpif-dummy/change-port-number",
 
1397
                             "DP PORT NEW-NUMBER",
 
1398
                             3, 3, dpif_dummy_change_port_number, NULL);
1361
1399
}