]> git.proxmox.com Git - ovs.git/blob - lib/dpif-netdev.c
datapath: Consider tunnels to have no MTU, fixing jumbo frame support.
[ovs.git] / lib / dpif-netdev.c
1 /*
2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
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 #include "dpif.h"
19
20 #include <assert.h>
21 #include <ctype.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <inttypes.h>
25 #include <netinet/in.h>
26 #include <sys/socket.h>
27 #include <net/if.h>
28 #include <stdint.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <sys/ioctl.h>
32 #include <sys/stat.h>
33 #include <unistd.h>
34
35 #include "csum.h"
36 #include "dpif.h"
37 #include "dpif-provider.h"
38 #include "dummy.h"
39 #include "dynamic-string.h"
40 #include "flow.h"
41 #include "hmap.h"
42 #include "list.h"
43 #include "netdev.h"
44 #include "netlink.h"
45 #include "odp-util.h"
46 #include "ofp-print.h"
47 #include "ofpbuf.h"
48 #include "packets.h"
49 #include "poll-loop.h"
50 #include "shash.h"
51 #include "timeval.h"
52 #include "util.h"
53 #include "vlog.h"
54
55 VLOG_DEFINE_THIS_MODULE(dpif_netdev);
56
57 /* Configuration parameters. */
58 enum { MAX_PORTS = 256 }; /* Maximum number of ports. */
59 enum { MAX_FLOWS = 65536 }; /* Maximum number of flows in flow table. */
60
61 /* Enough headroom to add a vlan tag, plus an extra 2 bytes to allow IP
62 * headers to be aligned on a 4-byte boundary. */
63 enum { DP_NETDEV_HEADROOM = 2 + VLAN_HEADER_LEN };
64
65 /* Queues. */
66 enum { N_QUEUES = 2 }; /* Number of queues for dpif_recv(). */
67 enum { MAX_QUEUE_LEN = 128 }; /* Maximum number of packets per queue. */
68 enum { QUEUE_MASK = MAX_QUEUE_LEN - 1 };
69 BUILD_ASSERT_DECL(IS_POW2(MAX_QUEUE_LEN));
70
71 struct dp_netdev_queue {
72 struct dpif_upcall *upcalls[MAX_QUEUE_LEN];
73 unsigned int head, tail;
74 };
75
76 /* Datapath based on the network device interface from netdev.h. */
77 struct dp_netdev {
78 const struct dpif_class *class;
79 char *name;
80 int open_cnt;
81 bool destroyed;
82
83 bool drop_frags; /* Drop all IP fragments, if true. */
84 struct dp_netdev_queue queues[N_QUEUES];
85 struct hmap flow_table; /* Flow table. */
86
87 /* Statistics. */
88 long long int n_frags; /* Number of dropped IP fragments. */
89 long long int n_hit; /* Number of flow table matches. */
90 long long int n_missed; /* Number of flow table misses. */
91 long long int n_lost; /* Number of misses not passed to client. */
92
93 /* Ports. */
94 int n_ports;
95 struct dp_netdev_port *ports[MAX_PORTS];
96 struct list port_list;
97 unsigned int serial;
98 };
99
100 /* A port in a netdev-based datapath. */
101 struct dp_netdev_port {
102 int port_no; /* Index into dp_netdev's 'ports'. */
103 struct list node; /* Element in dp_netdev's 'port_list'. */
104 struct netdev *netdev;
105 bool internal; /* Internal port? */
106 };
107
108 /* A flow in dp_netdev's 'flow_table'. */
109 struct dp_netdev_flow {
110 struct hmap_node node; /* Element in dp_netdev's 'flow_table'. */
111 struct flow key;
112
113 /* Statistics. */
114 long long int used; /* Last used time, in monotonic msecs. */
115 long long int packet_count; /* Number of packets matched. */
116 long long int byte_count; /* Number of bytes matched. */
117 uint16_t tcp_ctl; /* Bitwise-OR of seen tcp_ctl values. */
118
119 /* Actions. */
120 struct nlattr *actions;
121 size_t actions_len;
122 };
123
124 /* Interface to netdev-based datapath. */
125 struct dpif_netdev {
126 struct dpif dpif;
127 struct dp_netdev *dp;
128 int listen_mask;
129 unsigned int dp_serial;
130 };
131
132 /* All netdev-based datapaths. */
133 static struct shash dp_netdevs = SHASH_INITIALIZER(&dp_netdevs);
134
135 /* Maximum port MTU seen so far. */
136 static int max_mtu = ETH_PAYLOAD_MAX;
137
138 static int get_port_by_number(struct dp_netdev *, uint16_t port_no,
139 struct dp_netdev_port **portp);
140 static int get_port_by_name(struct dp_netdev *, const char *devname,
141 struct dp_netdev_port **portp);
142 static void dp_netdev_free(struct dp_netdev *);
143 static void dp_netdev_flow_flush(struct dp_netdev *);
144 static int do_add_port(struct dp_netdev *, const char *devname,
145 const char *type, uint16_t port_no);
146 static int do_del_port(struct dp_netdev *, uint16_t port_no);
147 static int dpif_netdev_open(const struct dpif_class *, const char *name,
148 bool create, struct dpif **);
149 static int dp_netdev_output_control(struct dp_netdev *, const struct ofpbuf *,
150 int queue_no, const struct flow *,
151 uint64_t arg);
152 static int dp_netdev_execute_actions(struct dp_netdev *,
153 struct ofpbuf *, struct flow *,
154 const struct nlattr *actions,
155 size_t actions_len);
156
157 static struct dpif_class dpif_dummy_class;
158
159 static struct dpif_netdev *
160 dpif_netdev_cast(const struct dpif *dpif)
161 {
162 assert(dpif->dpif_class->open == dpif_netdev_open);
163 return CONTAINER_OF(dpif, struct dpif_netdev, dpif);
164 }
165
166 static struct dp_netdev *
167 get_dp_netdev(const struct dpif *dpif)
168 {
169 return dpif_netdev_cast(dpif)->dp;
170 }
171
172 static struct dpif *
173 create_dpif_netdev(struct dp_netdev *dp)
174 {
175 uint16_t netflow_id = hash_string(dp->name, 0);
176 struct dpif_netdev *dpif;
177
178 dp->open_cnt++;
179
180 dpif = xmalloc(sizeof *dpif);
181 dpif_init(&dpif->dpif, dp->class, dp->name, netflow_id >> 8, netflow_id);
182 dpif->dp = dp;
183 dpif->listen_mask = 0;
184 dpif->dp_serial = dp->serial;
185
186 return &dpif->dpif;
187 }
188
189 static int
190 create_dp_netdev(const char *name, const struct dpif_class *class,
191 struct dp_netdev **dpp)
192 {
193 struct dp_netdev *dp;
194 int error;
195 int i;
196
197 dp = xzalloc(sizeof *dp);
198 dp->class = class;
199 dp->name = xstrdup(name);
200 dp->open_cnt = 0;
201 dp->drop_frags = false;
202 for (i = 0; i < N_QUEUES; i++) {
203 dp->queues[i].head = dp->queues[i].tail = 0;
204 }
205 hmap_init(&dp->flow_table);
206 list_init(&dp->port_list);
207 error = do_add_port(dp, name, "internal", ODPP_LOCAL);
208 if (error) {
209 dp_netdev_free(dp);
210 return error;
211 }
212
213 shash_add(&dp_netdevs, name, dp);
214
215 *dpp = dp;
216 return 0;
217 }
218
219 static int
220 dpif_netdev_open(const struct dpif_class *class, const char *name,
221 bool create, struct dpif **dpifp)
222 {
223 struct dp_netdev *dp;
224
225 dp = shash_find_data(&dp_netdevs, name);
226 if (!dp) {
227 if (!create) {
228 return ENODEV;
229 } else {
230 int error = create_dp_netdev(name, class, &dp);
231 if (error) {
232 return error;
233 }
234 assert(dp != NULL);
235 }
236 } else {
237 if (dp->class != class) {
238 return EINVAL;
239 } else if (create) {
240 return EEXIST;
241 }
242 }
243
244 *dpifp = create_dpif_netdev(dp);
245 return 0;
246 }
247
248 static void
249 dp_netdev_purge_queues(struct dp_netdev *dp)
250 {
251 int i;
252
253 for (i = 0; i < N_QUEUES; i++) {
254 struct dp_netdev_queue *q = &dp->queues[i];
255
256 while (q->tail != q->head) {
257 struct dpif_upcall *upcall = q->upcalls[q->tail++ & QUEUE_MASK];
258
259 ofpbuf_delete(upcall->packet);
260 free(upcall);
261 }
262 }
263 }
264
265 static void
266 dp_netdev_free(struct dp_netdev *dp)
267 {
268 dp_netdev_flow_flush(dp);
269 while (dp->n_ports > 0) {
270 struct dp_netdev_port *port = CONTAINER_OF(
271 dp->port_list.next, struct dp_netdev_port, node);
272 do_del_port(dp, port->port_no);
273 }
274 dp_netdev_purge_queues(dp);
275 hmap_destroy(&dp->flow_table);
276 free(dp->name);
277 free(dp);
278 }
279
280 static void
281 dpif_netdev_close(struct dpif *dpif)
282 {
283 struct dp_netdev *dp = get_dp_netdev(dpif);
284 assert(dp->open_cnt > 0);
285 if (--dp->open_cnt == 0 && dp->destroyed) {
286 shash_find_and_delete(&dp_netdevs, dp->name);
287 dp_netdev_free(dp);
288 }
289 free(dpif);
290 }
291
292 static int
293 dpif_netdev_destroy(struct dpif *dpif)
294 {
295 struct dp_netdev *dp = get_dp_netdev(dpif);
296 dp->destroyed = true;
297 return 0;
298 }
299
300 static int
301 dpif_netdev_get_stats(const struct dpif *dpif, struct odp_stats *stats)
302 {
303 struct dp_netdev *dp = get_dp_netdev(dpif);
304 memset(stats, 0, sizeof *stats);
305 stats->n_frags = dp->n_frags;
306 stats->n_hit = dp->n_hit;
307 stats->n_missed = dp->n_missed;
308 stats->n_lost = dp->n_lost;
309 return 0;
310 }
311
312 static int
313 dpif_netdev_get_drop_frags(const struct dpif *dpif, bool *drop_fragsp)
314 {
315 struct dp_netdev *dp = get_dp_netdev(dpif);
316 *drop_fragsp = dp->drop_frags;
317 return 0;
318 }
319
320 static int
321 dpif_netdev_set_drop_frags(struct dpif *dpif, bool drop_frags)
322 {
323 struct dp_netdev *dp = get_dp_netdev(dpif);
324 dp->drop_frags = drop_frags;
325 return 0;
326 }
327
328 static int
329 do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
330 uint16_t port_no)
331 {
332 struct dp_netdev_port *port;
333 struct netdev_options netdev_options;
334 struct netdev *netdev;
335 bool internal;
336 int mtu;
337 int error;
338
339 /* XXX reject devices already in some dp_netdev. */
340 if (type[0] == '\0' || !strcmp(type, "system")) {
341 internal = false;
342 } else if (!strcmp(type, "internal")) {
343 internal = true;
344 } else {
345 VLOG_WARN("%s: unsupported port type %s", devname, type);
346 return EINVAL;
347 }
348
349 /* Open and validate network device. */
350 memset(&netdev_options, 0, sizeof netdev_options);
351 netdev_options.name = devname;
352 netdev_options.ethertype = NETDEV_ETH_TYPE_ANY;
353 if (dp->class == &dpif_dummy_class) {
354 netdev_options.type = "dummy";
355 } else if (internal) {
356 netdev_options.type = "tap";
357 }
358
359 error = netdev_open(&netdev_options, &netdev);
360 if (error) {
361 return error;
362 }
363 /* XXX reject loopback devices */
364 /* XXX reject non-Ethernet devices */
365
366 error = netdev_turn_flags_on(netdev, NETDEV_PROMISC, false);
367 if (error) {
368 netdev_close(netdev);
369 return error;
370 }
371
372 port = xmalloc(sizeof *port);
373 port->port_no = port_no;
374 port->netdev = netdev;
375 port->internal = internal;
376
377 netdev_get_mtu(netdev, &mtu);
378 if (mtu != INT_MAX && mtu > max_mtu) {
379 max_mtu = mtu;
380 }
381
382 list_push_back(&dp->port_list, &port->node);
383 dp->ports[port_no] = port;
384 dp->n_ports++;
385 dp->serial++;
386
387 return 0;
388 }
389
390 static int
391 dpif_netdev_port_add(struct dpif *dpif, struct netdev *netdev,
392 uint16_t *port_nop)
393 {
394 struct dp_netdev *dp = get_dp_netdev(dpif);
395 int port_no;
396
397 for (port_no = 0; port_no < MAX_PORTS; port_no++) {
398 if (!dp->ports[port_no]) {
399 *port_nop = port_no;
400 return do_add_port(dp, netdev_get_name(netdev),
401 netdev_get_type(netdev), port_no);
402 }
403 }
404 return EFBIG;
405 }
406
407 static int
408 dpif_netdev_port_del(struct dpif *dpif, uint16_t port_no)
409 {
410 struct dp_netdev *dp = get_dp_netdev(dpif);
411 return port_no == ODPP_LOCAL ? EINVAL : do_del_port(dp, port_no);
412 }
413
414 static bool
415 is_valid_port_number(uint16_t port_no)
416 {
417 return port_no < MAX_PORTS;
418 }
419
420 static int
421 get_port_by_number(struct dp_netdev *dp,
422 uint16_t port_no, struct dp_netdev_port **portp)
423 {
424 if (!is_valid_port_number(port_no)) {
425 *portp = NULL;
426 return EINVAL;
427 } else {
428 *portp = dp->ports[port_no];
429 return *portp ? 0 : ENOENT;
430 }
431 }
432
433 static int
434 get_port_by_name(struct dp_netdev *dp,
435 const char *devname, struct dp_netdev_port **portp)
436 {
437 struct dp_netdev_port *port;
438
439 LIST_FOR_EACH (port, node, &dp->port_list) {
440 if (!strcmp(netdev_get_name(port->netdev), devname)) {
441 *portp = port;
442 return 0;
443 }
444 }
445 return ENOENT;
446 }
447
448 static int
449 do_del_port(struct dp_netdev *dp, uint16_t port_no)
450 {
451 struct dp_netdev_port *port;
452 char *name;
453 int error;
454
455 error = get_port_by_number(dp, port_no, &port);
456 if (error) {
457 return error;
458 }
459
460 list_remove(&port->node);
461 dp->ports[port->port_no] = NULL;
462 dp->n_ports--;
463 dp->serial++;
464
465 name = xstrdup(netdev_get_name(port->netdev));
466 netdev_close(port->netdev);
467
468 free(name);
469 free(port);
470
471 return 0;
472 }
473
474 static void
475 answer_port_query(const struct dp_netdev_port *port,
476 struct dpif_port *dpif_port)
477 {
478 dpif_port->name = xstrdup(netdev_get_name(port->netdev));
479 dpif_port->type = xstrdup(port->internal ? "internal" : "system");
480 dpif_port->port_no = port->port_no;
481 }
482
483 static int
484 dpif_netdev_port_query_by_number(const struct dpif *dpif, uint16_t port_no,
485 struct dpif_port *dpif_port)
486 {
487 struct dp_netdev *dp = get_dp_netdev(dpif);
488 struct dp_netdev_port *port;
489 int error;
490
491 error = get_port_by_number(dp, port_no, &port);
492 if (!error) {
493 answer_port_query(port, dpif_port);
494 }
495 return error;
496 }
497
498 static int
499 dpif_netdev_port_query_by_name(const struct dpif *dpif, const char *devname,
500 struct dpif_port *dpif_port)
501 {
502 struct dp_netdev *dp = get_dp_netdev(dpif);
503 struct dp_netdev_port *port;
504 int error;
505
506 error = get_port_by_name(dp, devname, &port);
507 if (!error) {
508 answer_port_query(port, dpif_port);
509 }
510 return error;
511 }
512
513 static int
514 dpif_netdev_get_max_ports(const struct dpif *dpif OVS_UNUSED)
515 {
516 return MAX_PORTS;
517 }
518
519 static void
520 dp_netdev_free_flow(struct dp_netdev *dp, struct dp_netdev_flow *flow)
521 {
522 hmap_remove(&dp->flow_table, &flow->node);
523 free(flow->actions);
524 free(flow);
525 }
526
527 static void
528 dp_netdev_flow_flush(struct dp_netdev *dp)
529 {
530 struct dp_netdev_flow *flow, *next;
531
532 HMAP_FOR_EACH_SAFE (flow, next, node, &dp->flow_table) {
533 dp_netdev_free_flow(dp, flow);
534 }
535 }
536
537 static int
538 dpif_netdev_flow_flush(struct dpif *dpif)
539 {
540 struct dp_netdev *dp = get_dp_netdev(dpif);
541 dp_netdev_flow_flush(dp);
542 return 0;
543 }
544
545 struct dp_netdev_port_state {
546 uint32_t port_no;
547 char *name;
548 };
549
550 static int
551 dpif_netdev_port_dump_start(const struct dpif *dpif OVS_UNUSED, void **statep)
552 {
553 *statep = xzalloc(sizeof(struct dp_netdev_port_state));
554 return 0;
555 }
556
557 static int
558 dpif_netdev_port_dump_next(const struct dpif *dpif, void *state_,
559 struct dpif_port *dpif_port)
560 {
561 struct dp_netdev_port_state *state = state_;
562 struct dp_netdev *dp = get_dp_netdev(dpif);
563 uint32_t port_no;
564
565 for (port_no = state->port_no; port_no < MAX_PORTS; port_no++) {
566 struct dp_netdev_port *port = dp->ports[port_no];
567 if (port) {
568 free(state->name);
569 state->name = xstrdup(netdev_get_name(port->netdev));
570 dpif_port->name = state->name;
571 dpif_port->type = port->internal ? "internal" : "system";
572 dpif_port->port_no = port->port_no;
573 state->port_no = port_no + 1;
574 return 0;
575 }
576 }
577 return EOF;
578 }
579
580 static int
581 dpif_netdev_port_dump_done(const struct dpif *dpif OVS_UNUSED, void *state_)
582 {
583 struct dp_netdev_port_state *state = state_;
584 free(state->name);
585 free(state);
586 return 0;
587 }
588
589 static int
590 dpif_netdev_port_poll(const struct dpif *dpif_, char **devnamep OVS_UNUSED)
591 {
592 struct dpif_netdev *dpif = dpif_netdev_cast(dpif_);
593 if (dpif->dp_serial != dpif->dp->serial) {
594 dpif->dp_serial = dpif->dp->serial;
595 return ENOBUFS;
596 } else {
597 return EAGAIN;
598 }
599 }
600
601 static void
602 dpif_netdev_port_poll_wait(const struct dpif *dpif_)
603 {
604 struct dpif_netdev *dpif = dpif_netdev_cast(dpif_);
605 if (dpif->dp_serial != dpif->dp->serial) {
606 poll_immediate_wake();
607 }
608 }
609
610 static struct dp_netdev_flow *
611 dp_netdev_lookup_flow(const struct dp_netdev *dp, const struct flow *key)
612 {
613 struct dp_netdev_flow *flow;
614
615 HMAP_FOR_EACH_WITH_HASH (flow, node, flow_hash(key, 0), &dp->flow_table) {
616 if (flow_equal(&flow->key, key)) {
617 return flow;
618 }
619 }
620 return NULL;
621 }
622
623 static void
624 get_dpif_flow_stats(struct dp_netdev_flow *flow, struct dpif_flow_stats *stats)
625 {
626 stats->n_packets = flow->packet_count;
627 stats->n_bytes = flow->byte_count;
628 stats->used = flow->used;
629 stats->tcp_flags = TCP_FLAGS(flow->tcp_ctl);
630 }
631
632 static int
633 dpif_netdev_flow_from_nlattrs(const struct nlattr *key, uint32_t key_len,
634 struct flow *flow)
635 {
636 if (odp_flow_key_to_flow(key, key_len, flow)) {
637 /* This should not happen: it indicates that odp_flow_key_from_flow()
638 * and odp_flow_key_to_flow() disagree on the acceptable form of a
639 * flow. Log the problem as an error, with enough details to enable
640 * debugging. */
641 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
642
643 if (!VLOG_DROP_ERR(&rl)) {
644 struct ds s;
645
646 ds_init(&s);
647 odp_flow_key_format(key, key_len, &s);
648 VLOG_ERR("internal error parsing flow key %s", ds_cstr(&s));
649 ds_destroy(&s);
650 }
651
652 return EINVAL;
653 }
654
655 return 0;
656 }
657
658 static int
659 dpif_netdev_flow_get(const struct dpif *dpif,
660 const struct nlattr *nl_key, size_t nl_key_len,
661 struct ofpbuf **actionsp, struct dpif_flow_stats *stats)
662 {
663 struct dp_netdev *dp = get_dp_netdev(dpif);
664 struct dp_netdev_flow *flow;
665 struct flow key;
666 int error;
667
668 error = dpif_netdev_flow_from_nlattrs(nl_key, nl_key_len, &key);
669 if (error) {
670 return error;
671 }
672
673 flow = dp_netdev_lookup_flow(dp, &key);
674 if (!flow) {
675 return ENOENT;
676 }
677
678 if (stats) {
679 get_dpif_flow_stats(flow, stats);
680 }
681 if (actionsp) {
682 *actionsp = ofpbuf_clone_data(flow->actions, flow->actions_len);
683 }
684 return 0;
685 }
686
687 static int
688 dpif_netdev_validate_actions(const struct nlattr *actions,
689 size_t actions_len, bool *mutates)
690 {
691 const struct nlattr *a;
692 unsigned int left;
693
694 *mutates = false;
695 NL_ATTR_FOR_EACH (a, left, actions, actions_len) {
696 uint16_t type = nl_attr_type(a);
697 int len = odp_action_len(type);
698
699 if (len != nl_attr_get_size(a)) {
700 return EINVAL;
701 }
702
703 switch (type) {
704 case ODP_ACTION_ATTR_OUTPUT:
705 if (nl_attr_get_u32(a) >= MAX_PORTS) {
706 return EINVAL;
707 }
708 break;
709
710 case ODP_ACTION_ATTR_CONTROLLER:
711 case ODP_ACTION_ATTR_DROP_SPOOFED_ARP:
712 break;
713
714 case ODP_ACTION_ATTR_SET_DL_TCI:
715 *mutates = true;
716 if (nl_attr_get_be16(a) & htons(VLAN_CFI)) {
717 return EINVAL;
718 }
719 break;
720
721 case ODP_ACTION_ATTR_SET_NW_TOS:
722 *mutates = true;
723 if (nl_attr_get_u8(a) & IP_ECN_MASK) {
724 return EINVAL;
725 }
726 break;
727
728 case ODP_ACTION_ATTR_STRIP_VLAN:
729 case ODP_ACTION_ATTR_SET_DL_SRC:
730 case ODP_ACTION_ATTR_SET_DL_DST:
731 case ODP_ACTION_ATTR_SET_NW_SRC:
732 case ODP_ACTION_ATTR_SET_NW_DST:
733 case ODP_ACTION_ATTR_SET_TP_SRC:
734 case ODP_ACTION_ATTR_SET_TP_DST:
735 *mutates = true;
736 break;
737
738 case ODP_ACTION_ATTR_SET_TUNNEL:
739 case ODP_ACTION_ATTR_SET_PRIORITY:
740 case ODP_ACTION_ATTR_POP_PRIORITY:
741 default:
742 return EOPNOTSUPP;
743 }
744 }
745 return 0;
746 }
747
748 static int
749 set_flow_actions(struct dp_netdev_flow *flow,
750 const struct nlattr *actions, size_t actions_len)
751 {
752 bool mutates;
753 int error;
754
755 error = dpif_netdev_validate_actions(actions, actions_len, &mutates);
756 if (error) {
757 return error;
758 }
759
760 flow->actions = xrealloc(flow->actions, actions_len);
761 flow->actions_len = actions_len;
762 memcpy(flow->actions, actions, actions_len);
763 return 0;
764 }
765
766 static int
767 add_flow(struct dpif *dpif, const struct flow *key,
768 const struct nlattr *actions, size_t actions_len)
769 {
770 struct dp_netdev *dp = get_dp_netdev(dpif);
771 struct dp_netdev_flow *flow;
772 int error;
773
774 flow = xzalloc(sizeof *flow);
775 flow->key = *key;
776
777 error = set_flow_actions(flow, actions, actions_len);
778 if (error) {
779 free(flow);
780 return error;
781 }
782
783 hmap_insert(&dp->flow_table, &flow->node, flow_hash(&flow->key, 0));
784 return 0;
785 }
786
787 static void
788 clear_stats(struct dp_netdev_flow *flow)
789 {
790 flow->used = 0;
791 flow->packet_count = 0;
792 flow->byte_count = 0;
793 flow->tcp_ctl = 0;
794 }
795
796 static int
797 dpif_netdev_flow_put(struct dpif *dpif, enum dpif_flow_put_flags flags,
798 const struct nlattr *nl_key, size_t nl_key_len,
799 const struct nlattr *actions, size_t actions_len,
800 struct dpif_flow_stats *stats)
801 {
802 struct dp_netdev *dp = get_dp_netdev(dpif);
803 struct dp_netdev_flow *flow;
804 struct flow key;
805 int error;
806
807 error = dpif_netdev_flow_from_nlattrs(nl_key, nl_key_len, &key);
808 if (error) {
809 return error;
810 }
811
812 flow = dp_netdev_lookup_flow(dp, &key);
813 if (!flow) {
814 if (flags & DPIF_FP_CREATE) {
815 if (hmap_count(&dp->flow_table) < MAX_FLOWS) {
816 if (stats) {
817 memset(stats, 0, sizeof *stats);
818 }
819 return add_flow(dpif, &key, actions, actions_len);
820 } else {
821 return EFBIG;
822 }
823 } else {
824 return ENOENT;
825 }
826 } else {
827 if (flags & DPIF_FP_MODIFY) {
828 int error = set_flow_actions(flow, actions, actions_len);
829 if (!error) {
830 if (stats) {
831 get_dpif_flow_stats(flow, stats);
832 }
833 if (flags & DPIF_FP_ZERO_STATS) {
834 clear_stats(flow);
835 }
836 }
837 return error;
838 } else {
839 return EEXIST;
840 }
841 }
842 }
843
844 static int
845 dpif_netdev_flow_del(struct dpif *dpif,
846 const struct nlattr *nl_key, size_t nl_key_len,
847 struct dpif_flow_stats *stats)
848 {
849 struct dp_netdev *dp = get_dp_netdev(dpif);
850 struct dp_netdev_flow *flow;
851 struct flow key;
852 int error;
853
854 error = dpif_netdev_flow_from_nlattrs(nl_key, nl_key_len, &key);
855 if (error) {
856 return error;
857 }
858
859 flow = dp_netdev_lookup_flow(dp, &key);
860 if (flow) {
861 if (stats) {
862 get_dpif_flow_stats(flow, stats);
863 }
864 dp_netdev_free_flow(dp, flow);
865 return 0;
866 } else {
867 return ENOENT;
868 }
869 }
870
871 struct dp_netdev_flow_state {
872 uint32_t bucket;
873 uint32_t offset;
874 struct nlattr *actions;
875 uint32_t keybuf[ODPUTIL_FLOW_KEY_U32S];
876 struct dpif_flow_stats stats;
877 };
878
879 static int
880 dpif_netdev_flow_dump_start(const struct dpif *dpif OVS_UNUSED, void **statep)
881 {
882 struct dp_netdev_flow_state *state;
883
884 *statep = state = xmalloc(sizeof *state);
885 state->bucket = 0;
886 state->offset = 0;
887 state->actions = NULL;
888 return 0;
889 }
890
891 static int
892 dpif_netdev_flow_dump_next(const struct dpif *dpif, void *state_,
893 const struct nlattr **key, size_t *key_len,
894 const struct nlattr **actions, size_t *actions_len,
895 const struct dpif_flow_stats **stats)
896 {
897 struct dp_netdev_flow_state *state = state_;
898 struct dp_netdev *dp = get_dp_netdev(dpif);
899 struct dp_netdev_flow *flow;
900 struct hmap_node *node;
901
902 node = hmap_at_position(&dp->flow_table, &state->bucket, &state->offset);
903 if (!node) {
904 return EOF;
905 }
906
907 flow = CONTAINER_OF(node, struct dp_netdev_flow, node);
908
909 if (key) {
910 struct ofpbuf buf;
911
912 ofpbuf_use_stack(&buf, state->keybuf, sizeof state->keybuf);
913 odp_flow_key_from_flow(&buf, &flow->key);
914 assert(buf.base == state->keybuf);
915
916 *key = buf.data;
917 *key_len = buf.size;
918 }
919
920 if (actions) {
921 free(state->actions);
922 state->actions = xmemdup(flow->actions, flow->actions_len);
923
924 *actions = state->actions;
925 *actions_len = flow->actions_len;
926 }
927
928 if (stats) {
929 get_dpif_flow_stats(flow, &state->stats);
930 *stats = &state->stats;
931 }
932
933 return 0;
934 }
935
936 static int
937 dpif_netdev_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *state_)
938 {
939 struct dp_netdev_flow_state *state = state_;
940
941 free(state->actions);
942 free(state);
943 return 0;
944 }
945
946 static int
947 dpif_netdev_execute(struct dpif *dpif,
948 const struct nlattr *actions, size_t actions_len,
949 const struct ofpbuf *packet)
950 {
951 struct dp_netdev *dp = get_dp_netdev(dpif);
952 struct ofpbuf copy;
953 bool mutates;
954 struct flow key;
955 int error;
956
957 if (packet->size < ETH_HEADER_LEN || packet->size > UINT16_MAX) {
958 return EINVAL;
959 }
960
961 error = dpif_netdev_validate_actions(actions, actions_len, &mutates);
962 if (error) {
963 return error;
964 }
965
966 if (mutates) {
967 /* We need a deep copy of 'packet' since we're going to modify its
968 * data. */
969 ofpbuf_init(&copy, DP_NETDEV_HEADROOM + packet->size);
970 ofpbuf_reserve(&copy, DP_NETDEV_HEADROOM);
971 ofpbuf_put(&copy, packet->data, packet->size);
972 } else {
973 /* We still need a shallow copy of 'packet', even though we won't
974 * modify its data, because flow_extract() modifies packet->l2, etc.
975 * We could probably get away with modifying those but it's more polite
976 * if we don't. */
977 copy = *packet;
978 }
979 flow_extract(&copy, 0, -1, &key);
980 error = dp_netdev_execute_actions(dp, &copy, &key, actions, actions_len);
981 if (mutates) {
982 ofpbuf_uninit(&copy);
983 }
984 return error;
985 }
986
987 static int
988 dpif_netdev_recv_get_mask(const struct dpif *dpif, int *listen_mask)
989 {
990 struct dpif_netdev *dpif_netdev = dpif_netdev_cast(dpif);
991 *listen_mask = dpif_netdev->listen_mask;
992 return 0;
993 }
994
995 static int
996 dpif_netdev_recv_set_mask(struct dpif *dpif, int listen_mask)
997 {
998 struct dpif_netdev *dpif_netdev = dpif_netdev_cast(dpif);
999 dpif_netdev->listen_mask = listen_mask;
1000 return 0;
1001 }
1002
1003 static struct dp_netdev_queue *
1004 find_nonempty_queue(struct dpif *dpif)
1005 {
1006 struct dpif_netdev *dpif_netdev = dpif_netdev_cast(dpif);
1007 struct dp_netdev *dp = get_dp_netdev(dpif);
1008 int mask = dpif_netdev->listen_mask;
1009 int i;
1010
1011 for (i = 0; i < N_QUEUES; i++) {
1012 struct dp_netdev_queue *q = &dp->queues[i];
1013 if (q->head != q->tail && mask & (1u << i)) {
1014 return q;
1015 }
1016 }
1017 return NULL;
1018 }
1019
1020 static int
1021 dpif_netdev_recv(struct dpif *dpif, struct dpif_upcall *upcall)
1022 {
1023 struct dp_netdev_queue *q = find_nonempty_queue(dpif);
1024 if (q) {
1025 struct dpif_upcall *u = q->upcalls[q->tail++ & QUEUE_MASK];
1026 *upcall = *u;
1027 free(u);
1028
1029 return 0;
1030 } else {
1031 return EAGAIN;
1032 }
1033 }
1034
1035 static void
1036 dpif_netdev_recv_wait(struct dpif *dpif)
1037 {
1038 if (find_nonempty_queue(dpif)) {
1039 poll_immediate_wake();
1040 } else {
1041 /* No messages ready to be received, and dp_wait() will ensure that we
1042 * wake up to queue new messages, so there is nothing to do. */
1043 }
1044 }
1045
1046 static void
1047 dpif_netdev_recv_purge(struct dpif *dpif)
1048 {
1049 struct dpif_netdev *dpif_netdev = dpif_netdev_cast(dpif);
1050 dp_netdev_purge_queues(dpif_netdev->dp);
1051 }
1052 \f
1053 static void
1054 dp_netdev_flow_used(struct dp_netdev_flow *flow, struct flow *key,
1055 const struct ofpbuf *packet)
1056 {
1057 flow->used = time_msec();
1058 flow->packet_count++;
1059 flow->byte_count += packet->size;
1060 if (key->dl_type == htons(ETH_TYPE_IP) && key->nw_proto == IPPROTO_TCP) {
1061 struct tcp_header *th = packet->l4;
1062 flow->tcp_ctl |= th->tcp_ctl;
1063 }
1064 }
1065
1066 static void
1067 dp_netdev_port_input(struct dp_netdev *dp, struct dp_netdev_port *port,
1068 struct ofpbuf *packet)
1069 {
1070 struct dp_netdev_flow *flow;
1071 struct flow key;
1072
1073 if (packet->size < ETH_HEADER_LEN) {
1074 return;
1075 }
1076 if (flow_extract(packet, 0, port->port_no, &key) && dp->drop_frags) {
1077 dp->n_frags++;
1078 return;
1079 }
1080
1081 flow = dp_netdev_lookup_flow(dp, &key);
1082 if (flow) {
1083 dp_netdev_flow_used(flow, &key, packet);
1084 dp_netdev_execute_actions(dp, packet, &key,
1085 flow->actions, flow->actions_len);
1086 dp->n_hit++;
1087 } else {
1088 dp->n_missed++;
1089 dp_netdev_output_control(dp, packet, DPIF_UC_MISS, &key, 0);
1090 }
1091 }
1092
1093 static void
1094 dp_netdev_run(void)
1095 {
1096 struct shash_node *node;
1097 struct ofpbuf packet;
1098
1099 ofpbuf_init(&packet, DP_NETDEV_HEADROOM + VLAN_ETH_HEADER_LEN + max_mtu);
1100 SHASH_FOR_EACH (node, &dp_netdevs) {
1101 struct dp_netdev *dp = node->data;
1102 struct dp_netdev_port *port;
1103
1104 LIST_FOR_EACH (port, node, &dp->port_list) {
1105 int error;
1106
1107 /* Reset packet contents. */
1108 ofpbuf_clear(&packet);
1109 ofpbuf_reserve(&packet, DP_NETDEV_HEADROOM);
1110
1111 error = netdev_recv(port->netdev, &packet);
1112 if (!error) {
1113 dp_netdev_port_input(dp, port, &packet);
1114 } else if (error != EAGAIN && error != EOPNOTSUPP) {
1115 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1116 VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
1117 netdev_get_name(port->netdev), strerror(error));
1118 }
1119 }
1120 }
1121 ofpbuf_uninit(&packet);
1122 }
1123
1124 static void
1125 dp_netdev_wait(void)
1126 {
1127 struct shash_node *node;
1128
1129 SHASH_FOR_EACH (node, &dp_netdevs) {
1130 struct dp_netdev *dp = node->data;
1131 struct dp_netdev_port *port;
1132
1133 LIST_FOR_EACH (port, node, &dp->port_list) {
1134 netdev_recv_wait(port->netdev);
1135 }
1136 }
1137 }
1138
1139
1140 /* Modify the TCI field of 'packet'. If a VLAN tag is present, its TCI field
1141 * is replaced by 'tci'. If a VLAN tag is not present, one is added with the
1142 * TCI field set to 'tci'.
1143 */
1144 static void
1145 dp_netdev_set_dl_tci(struct ofpbuf *packet, uint16_t tci)
1146 {
1147 struct vlan_eth_header *veh;
1148 struct eth_header *eh;
1149
1150 eh = packet->l2;
1151 if (packet->size >= sizeof(struct vlan_eth_header)
1152 && eh->eth_type == htons(ETH_TYPE_VLAN)) {
1153 veh = packet->l2;
1154 veh->veth_tci = tci;
1155 } else {
1156 /* Insert new 802.1Q header. */
1157 struct vlan_eth_header tmp;
1158 memcpy(tmp.veth_dst, eh->eth_dst, ETH_ADDR_LEN);
1159 memcpy(tmp.veth_src, eh->eth_src, ETH_ADDR_LEN);
1160 tmp.veth_type = htons(ETH_TYPE_VLAN);
1161 tmp.veth_tci = tci;
1162 tmp.veth_next_type = eh->eth_type;
1163
1164 veh = ofpbuf_push_uninit(packet, VLAN_HEADER_LEN);
1165 memcpy(veh, &tmp, sizeof tmp);
1166 packet->l2 = (char*)packet->l2 - VLAN_HEADER_LEN;
1167 }
1168 }
1169
1170 static void
1171 dp_netdev_strip_vlan(struct ofpbuf *packet)
1172 {
1173 struct vlan_eth_header *veh = packet->l2;
1174 if (packet->size >= sizeof *veh
1175 && veh->veth_type == htons(ETH_TYPE_VLAN)) {
1176 struct eth_header tmp;
1177
1178 memcpy(tmp.eth_dst, veh->veth_dst, ETH_ADDR_LEN);
1179 memcpy(tmp.eth_src, veh->veth_src, ETH_ADDR_LEN);
1180 tmp.eth_type = veh->veth_next_type;
1181
1182 ofpbuf_pull(packet, VLAN_HEADER_LEN);
1183 packet->l2 = (char*)packet->l2 + VLAN_HEADER_LEN;
1184 memcpy(packet->data, &tmp, sizeof tmp);
1185 }
1186 }
1187
1188 static void
1189 dp_netdev_set_dl_src(struct ofpbuf *packet, const uint8_t dl_addr[ETH_ADDR_LEN])
1190 {
1191 struct eth_header *eh = packet->l2;
1192 memcpy(eh->eth_src, dl_addr, sizeof eh->eth_src);
1193 }
1194
1195 static void
1196 dp_netdev_set_dl_dst(struct ofpbuf *packet, const uint8_t dl_addr[ETH_ADDR_LEN])
1197 {
1198 struct eth_header *eh = packet->l2;
1199 memcpy(eh->eth_dst, dl_addr, sizeof eh->eth_dst);
1200 }
1201
1202 static bool
1203 is_ip(const struct ofpbuf *packet, const struct flow *key)
1204 {
1205 return key->dl_type == htons(ETH_TYPE_IP) && packet->l4;
1206 }
1207
1208 static void
1209 dp_netdev_set_nw_addr(struct ofpbuf *packet, const struct flow *key,
1210 const struct nlattr *a)
1211 {
1212 if (is_ip(packet, key)) {
1213 struct ip_header *nh = packet->l3;
1214 ovs_be32 ip = nl_attr_get_be32(a);
1215 uint16_t type = nl_attr_type(a);
1216 uint32_t *field;
1217
1218 field = type == ODP_ACTION_ATTR_SET_NW_SRC ? &nh->ip_src : &nh->ip_dst;
1219 if (key->nw_proto == IPPROTO_TCP && packet->l7) {
1220 struct tcp_header *th = packet->l4;
1221 th->tcp_csum = recalc_csum32(th->tcp_csum, *field, ip);
1222 } else if (key->nw_proto == IPPROTO_UDP && packet->l7) {
1223 struct udp_header *uh = packet->l4;
1224 if (uh->udp_csum) {
1225 uh->udp_csum = recalc_csum32(uh->udp_csum, *field, ip);
1226 if (!uh->udp_csum) {
1227 uh->udp_csum = 0xffff;
1228 }
1229 }
1230 }
1231 nh->ip_csum = recalc_csum32(nh->ip_csum, *field, ip);
1232 *field = ip;
1233 }
1234 }
1235
1236 static void
1237 dp_netdev_set_nw_tos(struct ofpbuf *packet, const struct flow *key,
1238 uint8_t nw_tos)
1239 {
1240 if (is_ip(packet, key)) {
1241 struct ip_header *nh = packet->l3;
1242 uint8_t *field = &nh->ip_tos;
1243
1244 /* Set the DSCP bits and preserve the ECN bits. */
1245 uint8_t new = nw_tos | (nh->ip_tos & IP_ECN_MASK);
1246
1247 nh->ip_csum = recalc_csum16(nh->ip_csum, htons((uint16_t)*field),
1248 htons((uint16_t) new));
1249 *field = new;
1250 }
1251 }
1252
1253 static void
1254 dp_netdev_set_tp_port(struct ofpbuf *packet, const struct flow *key,
1255 const struct nlattr *a)
1256 {
1257 if (is_ip(packet, key)) {
1258 uint16_t type = nl_attr_type(a);
1259 ovs_be16 port = nl_attr_get_be16(a);
1260 uint16_t *field;
1261
1262 if (key->nw_proto == IPPROTO_TCP && packet->l7) {
1263 struct tcp_header *th = packet->l4;
1264 field = (type == ODP_ACTION_ATTR_SET_TP_SRC
1265 ? &th->tcp_src : &th->tcp_dst);
1266 th->tcp_csum = recalc_csum16(th->tcp_csum, *field, port);
1267 *field = port;
1268 } else if (key->nw_proto == IPPROTO_UDP && packet->l7) {
1269 struct udp_header *uh = packet->l4;
1270 field = (type == ODP_ACTION_ATTR_SET_TP_SRC
1271 ? &uh->udp_src : &uh->udp_dst);
1272 uh->udp_csum = recalc_csum16(uh->udp_csum, *field, port);
1273 *field = port;
1274 } else {
1275 return;
1276 }
1277 }
1278 }
1279
1280 static void
1281 dp_netdev_output_port(struct dp_netdev *dp, struct ofpbuf *packet,
1282 uint16_t out_port)
1283 {
1284 struct dp_netdev_port *p = dp->ports[out_port];
1285 if (p) {
1286 netdev_send(p->netdev, packet);
1287 }
1288 }
1289
1290 static int
1291 dp_netdev_output_control(struct dp_netdev *dp, const struct ofpbuf *packet,
1292 int queue_no, const struct flow *flow, uint64_t arg)
1293 {
1294 struct dp_netdev_queue *q = &dp->queues[queue_no];
1295 struct dpif_upcall *upcall;
1296 struct ofpbuf *buf;
1297 size_t key_len;
1298
1299 if (q->head - q->tail >= MAX_QUEUE_LEN) {
1300 dp->n_lost++;
1301 return ENOBUFS;
1302 }
1303
1304 buf = ofpbuf_new(ODPUTIL_FLOW_KEY_BYTES + 2 + packet->size);
1305 odp_flow_key_from_flow(buf, flow);
1306 key_len = buf->size;
1307 ofpbuf_pull(buf, key_len);
1308 ofpbuf_reserve(buf, 2);
1309 ofpbuf_put(buf, packet->data, packet->size);
1310
1311 upcall = xzalloc(sizeof *upcall);
1312 upcall->type = queue_no;
1313 upcall->packet = buf;
1314 upcall->key = buf->base;
1315 upcall->key_len = key_len;
1316 upcall->userdata = arg;
1317
1318 q->upcalls[++q->head & QUEUE_MASK] = upcall;
1319
1320 return 0;
1321 }
1322
1323 /* Returns true if 'packet' is an invalid Ethernet+IPv4 ARP packet: one with
1324 * screwy or truncated header fields or one whose inner and outer Ethernet
1325 * address differ. */
1326 static bool
1327 dp_netdev_is_spoofed_arp(struct ofpbuf *packet, const struct flow *key)
1328 {
1329 struct arp_eth_header *arp;
1330 struct eth_header *eth;
1331 ptrdiff_t l3_size;
1332
1333 if (key->dl_type != htons(ETH_TYPE_ARP)) {
1334 return false;
1335 }
1336
1337 l3_size = (char *) ofpbuf_end(packet) - (char *) packet->l3;
1338 if (l3_size < sizeof(struct arp_eth_header)) {
1339 return true;
1340 }
1341
1342 eth = packet->l2;
1343 arp = packet->l3;
1344 return (arp->ar_hrd != htons(ARP_HRD_ETHERNET)
1345 || arp->ar_pro != htons(ARP_PRO_IP)
1346 || arp->ar_hln != ETH_HEADER_LEN
1347 || arp->ar_pln != 4
1348 || !eth_addr_equals(arp->ar_sha, eth->eth_src));
1349 }
1350
1351 static int
1352 dp_netdev_execute_actions(struct dp_netdev *dp,
1353 struct ofpbuf *packet, struct flow *key,
1354 const struct nlattr *actions,
1355 size_t actions_len)
1356 {
1357 const struct nlattr *a;
1358 unsigned int left;
1359
1360 NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) {
1361 switch (nl_attr_type(a)) {
1362 case ODP_ACTION_ATTR_OUTPUT:
1363 dp_netdev_output_port(dp, packet, nl_attr_get_u32(a));
1364 break;
1365
1366 case ODP_ACTION_ATTR_CONTROLLER:
1367 dp_netdev_output_control(dp, packet, DPIF_UC_ACTION,
1368 key, nl_attr_get_u64(a));
1369 break;
1370
1371 case ODP_ACTION_ATTR_SET_DL_TCI:
1372 dp_netdev_set_dl_tci(packet, nl_attr_get_be16(a));
1373 break;
1374
1375 case ODP_ACTION_ATTR_STRIP_VLAN:
1376 dp_netdev_strip_vlan(packet);
1377 break;
1378
1379 case ODP_ACTION_ATTR_SET_DL_SRC:
1380 dp_netdev_set_dl_src(packet, nl_attr_get_unspec(a, ETH_ADDR_LEN));
1381 break;
1382
1383 case ODP_ACTION_ATTR_SET_DL_DST:
1384 dp_netdev_set_dl_dst(packet, nl_attr_get_unspec(a, ETH_ADDR_LEN));
1385 break;
1386
1387 case ODP_ACTION_ATTR_SET_NW_SRC:
1388 case ODP_ACTION_ATTR_SET_NW_DST:
1389 dp_netdev_set_nw_addr(packet, key, a);
1390 break;
1391
1392 case ODP_ACTION_ATTR_SET_NW_TOS:
1393 dp_netdev_set_nw_tos(packet, key, nl_attr_get_u8(a));
1394 break;
1395
1396 case ODP_ACTION_ATTR_SET_TP_SRC:
1397 case ODP_ACTION_ATTR_SET_TP_DST:
1398 dp_netdev_set_tp_port(packet, key, a);
1399 break;
1400
1401 case ODP_ACTION_ATTR_DROP_SPOOFED_ARP:
1402 if (dp_netdev_is_spoofed_arp(packet, key)) {
1403 return 0;
1404 }
1405 }
1406 }
1407 return 0;
1408 }
1409
1410 const struct dpif_class dpif_netdev_class = {
1411 "netdev",
1412 dp_netdev_run,
1413 dp_netdev_wait,
1414 NULL, /* enumerate */
1415 dpif_netdev_open,
1416 dpif_netdev_close,
1417 dpif_netdev_destroy,
1418 dpif_netdev_get_stats,
1419 dpif_netdev_get_drop_frags,
1420 dpif_netdev_set_drop_frags,
1421 dpif_netdev_port_add,
1422 dpif_netdev_port_del,
1423 dpif_netdev_port_query_by_number,
1424 dpif_netdev_port_query_by_name,
1425 dpif_netdev_get_max_ports,
1426 dpif_netdev_port_dump_start,
1427 dpif_netdev_port_dump_next,
1428 dpif_netdev_port_dump_done,
1429 dpif_netdev_port_poll,
1430 dpif_netdev_port_poll_wait,
1431 dpif_netdev_flow_get,
1432 dpif_netdev_flow_put,
1433 dpif_netdev_flow_del,
1434 dpif_netdev_flow_flush,
1435 dpif_netdev_flow_dump_start,
1436 dpif_netdev_flow_dump_next,
1437 dpif_netdev_flow_dump_done,
1438 dpif_netdev_execute,
1439 dpif_netdev_recv_get_mask,
1440 dpif_netdev_recv_set_mask,
1441 NULL, /* get_sflow_probability */
1442 NULL, /* set_sflow_probability */
1443 NULL, /* queue_to_priority */
1444 dpif_netdev_recv,
1445 dpif_netdev_recv_wait,
1446 dpif_netdev_recv_purge,
1447 };
1448
1449 void
1450 dpif_dummy_register(void)
1451 {
1452 if (!dpif_dummy_class.type) {
1453 dpif_dummy_class = dpif_netdev_class;
1454 dpif_dummy_class.type = "dummy";
1455 dp_register_provider(&dpif_dummy_class);
1456 }
1457 }