ofproto-dpif: add support for layer 3 ports
[sliver-openvswitch.git] / lib / netdev-vport.c
1 /*
2  * Copyright (c) 2010, 2011, 2012, 2013 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 "netdev-vport.h"
20
21 #include <errno.h>
22 #include <fcntl.h>
23 #include <sys/socket.h>
24 #include <net/if.h>
25 #include <sys/ioctl.h>
26
27 #include "byte-order.h"
28 #include "daemon.h"
29 #include "dirs.h"
30 #include "dpif.h"
31 #include "hash.h"
32 #include "hmap.h"
33 #include "list.h"
34 #include "netdev-provider.h"
35 #include "ofpbuf.h"
36 #include "packets.h"
37 #include "route-table.h"
38 #include "shash.h"
39 #include "socket-util.h"
40 #include "vlog.h"
41
42 VLOG_DEFINE_THIS_MODULE(netdev_vport);
43
44 #define VXLAN_DST_PORT 4789
45 #define LISP_DST_PORT 4341
46
47 #define DEFAULT_TTL 64
48
49 struct netdev_vport {
50     struct netdev up;
51
52     /* Protects all members below. */
53     struct ovs_mutex mutex;
54
55     unsigned int change_seq;
56     uint8_t etheraddr[ETH_ADDR_LEN];
57     struct netdev_stats stats;
58
59     /* Tunnels. */
60     struct netdev_tunnel_config tnl_cfg;
61
62     /* Patch Ports. */
63     char *peer;
64 };
65
66 struct vport_class {
67     const char *dpif_port;
68     struct netdev_class netdev_class;
69 };
70
71 static int netdev_vport_construct(struct netdev *);
72 static int get_patch_config(const struct netdev *netdev, struct smap *args);
73 static int get_tunnel_config(const struct netdev *, struct smap *args);
74 static void netdev_vport_changed(struct netdev_vport *netdev)
75     OVS_REQUIRES(netdev->mutex);
76
77 static bool
78 is_vport_class(const struct netdev_class *class)
79 {
80     return class->construct == netdev_vport_construct;
81 }
82
83 static const struct vport_class *
84 vport_class_cast(const struct netdev_class *class)
85 {
86     ovs_assert(is_vport_class(class));
87     return CONTAINER_OF(class, struct vport_class, netdev_class);
88 }
89
90 static struct netdev_vport *
91 netdev_vport_cast(const struct netdev *netdev)
92 {
93     ovs_assert(is_vport_class(netdev_get_class(netdev)));
94     return CONTAINER_OF(netdev, struct netdev_vport, up);
95 }
96
97 static const struct netdev_tunnel_config *
98 get_netdev_tunnel_config(const struct netdev *netdev)
99 {
100     return &netdev_vport_cast(netdev)->tnl_cfg;
101 }
102
103 bool
104 netdev_vport_is_patch(const struct netdev *netdev)
105 {
106     const struct netdev_class *class = netdev_get_class(netdev);
107
108     return class->get_config == get_patch_config;
109 }
110
111 bool
112 netdev_vport_is_layer3(const struct netdev *dev)
113 {
114     const char *type = netdev_get_type(dev);
115
116     return (!strcmp("lisp", type));
117 }
118
119 static bool
120 netdev_vport_needs_dst_port(const struct netdev *dev)
121 {
122     const struct netdev_class *class = netdev_get_class(dev);
123     const char *type = netdev_get_type(dev);
124
125     return (class->get_config == get_tunnel_config &&
126             (!strcmp("vxlan", type) || !strcmp("lisp", type)));
127 }
128
129 const char *
130 netdev_vport_class_get_dpif_port(const struct netdev_class *class)
131 {
132     return is_vport_class(class) ? vport_class_cast(class)->dpif_port : NULL;
133 }
134
135 const char *
136 netdev_vport_get_dpif_port(const struct netdev *netdev,
137                            char namebuf[], size_t bufsize)
138 {
139     if (netdev_vport_needs_dst_port(netdev)) {
140         const struct netdev_vport *vport = netdev_vport_cast(netdev);
141         const char *type = netdev_get_type(netdev);
142
143         /*
144          * Note: IFNAMSIZ is 16 bytes long. The maximum length of a VXLAN
145          * or LISP port name below is 15 or 14 bytes respectively. Still,
146          * assert here on the size of strlen(type) in case that changes
147          * in the future.
148          */
149         BUILD_ASSERT(NETDEV_VPORT_NAME_BUFSIZE >= IFNAMSIZ);
150         ovs_assert(strlen(type) + 10 < IFNAMSIZ);
151         snprintf(namebuf, bufsize, "%s_sys_%d", type,
152                  ntohs(vport->tnl_cfg.dst_port));
153         return namebuf;
154     } else {
155         const struct netdev_class *class = netdev_get_class(netdev);
156         const char *dpif_port = netdev_vport_class_get_dpif_port(class);
157         return dpif_port ? dpif_port : netdev_get_name(netdev);
158     }
159 }
160
161 char *
162 netdev_vport_get_dpif_port_strdup(const struct netdev *netdev)
163 {
164     char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
165
166     return xstrdup(netdev_vport_get_dpif_port(netdev, namebuf,
167                                               sizeof namebuf));
168 }
169
170 static struct netdev *
171 netdev_vport_alloc(void)
172 {
173     struct netdev_vport *netdev = xzalloc(sizeof *netdev);
174     return &netdev->up;
175 }
176
177 static int
178 netdev_vport_construct(struct netdev *netdev_)
179 {
180     struct netdev_vport *netdev = netdev_vport_cast(netdev_);
181
182     ovs_mutex_init(&netdev->mutex);
183     netdev->change_seq = 1;
184     eth_addr_random(netdev->etheraddr);
185
186     route_table_register();
187
188     return 0;
189 }
190
191 static void
192 netdev_vport_destruct(struct netdev *netdev_)
193 {
194     struct netdev_vport *netdev = netdev_vport_cast(netdev_);
195
196     route_table_unregister();
197     free(netdev->peer);
198     ovs_mutex_destroy(&netdev->mutex);
199 }
200
201 static void
202 netdev_vport_dealloc(struct netdev *netdev_)
203 {
204     struct netdev_vport *netdev = netdev_vport_cast(netdev_);
205     free(netdev);
206 }
207
208 static int
209 netdev_vport_set_etheraddr(struct netdev *netdev_,
210                            const uint8_t mac[ETH_ADDR_LEN])
211 {
212     struct netdev_vport *netdev = netdev_vport_cast(netdev_);
213
214     ovs_mutex_lock(&netdev->mutex);
215     memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
216     netdev_vport_changed(netdev);
217     ovs_mutex_unlock(&netdev->mutex);
218
219     return 0;
220 }
221
222 static int
223 netdev_vport_get_etheraddr(const struct netdev *netdev_,
224                            uint8_t mac[ETH_ADDR_LEN])
225 {
226     struct netdev_vport *netdev = netdev_vport_cast(netdev_);
227
228     ovs_mutex_lock(&netdev->mutex);
229     memcpy(mac, netdev->etheraddr, ETH_ADDR_LEN);
230     ovs_mutex_unlock(&netdev->mutex);
231
232     return 0;
233 }
234
235 static int
236 tunnel_get_status(const struct netdev *netdev_, struct smap *smap)
237 {
238     struct netdev_vport *netdev = netdev_vport_cast(netdev_);
239     char iface[IFNAMSIZ];
240     ovs_be32 route;
241
242     ovs_mutex_lock(&netdev->mutex);
243     route = netdev->tnl_cfg.ip_dst;
244     ovs_mutex_unlock(&netdev->mutex);
245
246     if (route_table_get_name(route, iface)) {
247         struct netdev *egress_netdev;
248
249         smap_add(smap, "tunnel_egress_iface", iface);
250
251         if (!netdev_open(iface, "system", &egress_netdev)) {
252             smap_add(smap, "tunnel_egress_iface_carrier",
253                      netdev_get_carrier(egress_netdev) ? "up" : "down");
254             netdev_close(egress_netdev);
255         }
256     }
257
258     return 0;
259 }
260
261 static int
262 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
263                           enum netdev_flags off,
264                           enum netdev_flags on OVS_UNUSED,
265                           enum netdev_flags *old_flagsp)
266 {
267     if (off & (NETDEV_UP | NETDEV_PROMISC)) {
268         return EOPNOTSUPP;
269     }
270
271     *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
272     return 0;
273 }
274
275 static unsigned int
276 netdev_vport_change_seq(const struct netdev *netdev)
277 {
278     return netdev_vport_cast(netdev)->change_seq;
279 }
280
281 static void
282 netdev_vport_run(void)
283 {
284     route_table_run();
285 }
286
287 static void
288 netdev_vport_wait(void)
289 {
290     route_table_wait();
291 }
292 \f
293 /* Helper functions. */
294
295 static void
296 netdev_vport_changed(struct netdev_vport *ndv)
297 {
298     ndv->change_seq++;
299     if (!ndv->change_seq) {
300         ndv->change_seq++;
301     }
302 }
303 \f
304 /* Code specific to tunnel types. */
305
306 static ovs_be64
307 parse_key(const struct smap *args, const char *name,
308           bool *present, bool *flow)
309 {
310     const char *s;
311
312     *present = false;
313     *flow = false;
314
315     s = smap_get(args, name);
316     if (!s) {
317         s = smap_get(args, "key");
318         if (!s) {
319             return 0;
320         }
321     }
322
323     *present = true;
324
325     if (!strcmp(s, "flow")) {
326         *flow = true;
327         return 0;
328     } else {
329         return htonll(strtoull(s, NULL, 0));
330     }
331 }
332
333 static int
334 set_tunnel_config(struct netdev *dev_, const struct smap *args)
335 {
336     struct netdev_vport *dev = netdev_vport_cast(dev_);
337     const char *name = netdev_get_name(dev_);
338     const char *type = netdev_get_type(dev_);
339     bool ipsec_mech_set, needs_dst_port, has_csum;
340     struct netdev_tunnel_config tnl_cfg;
341     struct smap_node *node;
342
343     has_csum = strstr(type, "gre");
344     ipsec_mech_set = false;
345     memset(&tnl_cfg, 0, sizeof tnl_cfg);
346
347     needs_dst_port = netdev_vport_needs_dst_port(dev_);
348     tnl_cfg.ipsec = strstr(type, "ipsec");
349     tnl_cfg.dont_fragment = true;
350
351     SMAP_FOR_EACH (node, args) {
352         if (!strcmp(node->key, "remote_ip")) {
353             struct in_addr in_addr;
354             if (!strcmp(node->value, "flow")) {
355                 tnl_cfg.ip_dst_flow = true;
356                 tnl_cfg.ip_dst = htonl(0);
357             } else if (lookup_ip(node->value, &in_addr)) {
358                 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
359             } else if (ip_is_multicast(in_addr.s_addr)) {
360                 VLOG_WARN("%s: multicast remote_ip="IP_FMT" not allowed",
361                           name, IP_ARGS(in_addr.s_addr));
362                 return EINVAL;
363             } else {
364                 tnl_cfg.ip_dst = in_addr.s_addr;
365             }
366         } else if (!strcmp(node->key, "local_ip")) {
367             struct in_addr in_addr;
368             if (!strcmp(node->value, "flow")) {
369                 tnl_cfg.ip_src_flow = true;
370                 tnl_cfg.ip_src = htonl(0);
371             } else if (lookup_ip(node->value, &in_addr)) {
372                 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
373             } else {
374                 tnl_cfg.ip_src = in_addr.s_addr;
375             }
376         } else if (!strcmp(node->key, "tos")) {
377             if (!strcmp(node->value, "inherit")) {
378                 tnl_cfg.tos_inherit = true;
379             } else {
380                 char *endptr;
381                 int tos;
382                 tos = strtol(node->value, &endptr, 0);
383                 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
384                     tnl_cfg.tos = tos;
385                 } else {
386                     VLOG_WARN("%s: invalid TOS %s", name, node->value);
387                 }
388             }
389         } else if (!strcmp(node->key, "ttl")) {
390             if (!strcmp(node->value, "inherit")) {
391                 tnl_cfg.ttl_inherit = true;
392             } else {
393                 tnl_cfg.ttl = atoi(node->value);
394             }
395         } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
396             tnl_cfg.dst_port = htons(atoi(node->value));
397         } else if (!strcmp(node->key, "csum") && has_csum) {
398             if (!strcmp(node->value, "true")) {
399                 tnl_cfg.csum = true;
400             }
401         } else if (!strcmp(node->key, "df_default")) {
402             if (!strcmp(node->value, "false")) {
403                 tnl_cfg.dont_fragment = false;
404             }
405         } else if (!strcmp(node->key, "peer_cert") && tnl_cfg.ipsec) {
406             if (smap_get(args, "certificate")) {
407                 ipsec_mech_set = true;
408             } else {
409                 const char *use_ssl_cert;
410
411                 /* If the "use_ssl_cert" is true, then "certificate" and
412                  * "private_key" will be pulled from the SSL table.  The
413                  * use of this option is strongly discouraged, since it
414                  * will like be removed when multiple SSL configurations
415                  * are supported by OVS.
416                  */
417                 use_ssl_cert = smap_get(args, "use_ssl_cert");
418                 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
419                     VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
420                              name);
421                     return EINVAL;
422                 }
423                 ipsec_mech_set = true;
424             }
425         } else if (!strcmp(node->key, "psk") && tnl_cfg.ipsec) {
426             ipsec_mech_set = true;
427         } else if (tnl_cfg.ipsec
428                 && (!strcmp(node->key, "certificate")
429                     || !strcmp(node->key, "private_key")
430                     || !strcmp(node->key, "use_ssl_cert"))) {
431             /* Ignore options not used by the netdev. */
432         } else if (!strcmp(node->key, "key") ||
433                    !strcmp(node->key, "in_key") ||
434                    !strcmp(node->key, "out_key")) {
435             /* Handled separately below. */
436         } else {
437             VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
438         }
439     }
440
441     /* Add a default destination port for VXLAN if none specified. */
442     if (!strcmp(type, "vxlan") && !tnl_cfg.dst_port) {
443         tnl_cfg.dst_port = htons(VXLAN_DST_PORT);
444     }
445
446     /* Add a default destination port for LISP if none specified. */
447     if (!strcmp(type, "lisp") && !tnl_cfg.dst_port) {
448         tnl_cfg.dst_port = htons(LISP_DST_PORT);
449     }
450
451     if (tnl_cfg.ipsec) {
452         static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
453         static pid_t pid = 0;
454
455         ovs_mutex_lock(&mutex);
456         if (pid <= 0) {
457             char *file_name = xasprintf("%s/%s", ovs_rundir(),
458                                         "ovs-monitor-ipsec.pid");
459             pid = read_pidfile(file_name);
460             free(file_name);
461         }
462         ovs_mutex_unlock(&mutex);
463
464         if (pid < 0) {
465             VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
466                      name);
467             return EINVAL;
468         }
469
470         if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
471             VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
472             return EINVAL;
473         }
474
475         if (!ipsec_mech_set) {
476             VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
477                      name);
478             return EINVAL;
479         }
480     }
481
482     if (!tnl_cfg.ip_dst && !tnl_cfg.ip_dst_flow) {
483         VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
484                  name, type);
485         return EINVAL;
486     }
487     if (tnl_cfg.ip_src_flow && !tnl_cfg.ip_dst_flow) {
488         VLOG_ERR("%s: %s type requires 'remote_ip=flow' with 'local_ip=flow'",
489                  name, type);
490         return EINVAL;
491     }
492     if (!tnl_cfg.ttl) {
493         tnl_cfg.ttl = DEFAULT_TTL;
494     }
495
496     tnl_cfg.in_key = parse_key(args, "in_key",
497                                &tnl_cfg.in_key_present,
498                                &tnl_cfg.in_key_flow);
499
500     tnl_cfg.out_key = parse_key(args, "out_key",
501                                &tnl_cfg.out_key_present,
502                                &tnl_cfg.out_key_flow);
503
504     ovs_mutex_lock(&dev->mutex);
505     dev->tnl_cfg = tnl_cfg;
506     netdev_vport_changed(dev);
507     ovs_mutex_unlock(&dev->mutex);
508
509     return 0;
510 }
511
512 static int
513 get_tunnel_config(const struct netdev *dev, struct smap *args)
514 {
515     struct netdev_vport *netdev = netdev_vport_cast(dev);
516     struct netdev_tunnel_config tnl_cfg;
517
518     ovs_mutex_lock(&netdev->mutex);
519     tnl_cfg = netdev->tnl_cfg;
520     ovs_mutex_unlock(&netdev->mutex);
521
522     if (tnl_cfg.ip_dst) {
523         smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(tnl_cfg.ip_dst));
524     } else if (tnl_cfg.ip_dst_flow) {
525         smap_add(args, "remote_ip", "flow");
526     }
527
528     if (tnl_cfg.ip_src) {
529         smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(tnl_cfg.ip_src));
530     } else if (tnl_cfg.ip_src_flow) {
531         smap_add(args, "local_ip", "flow");
532     }
533
534     if (tnl_cfg.in_key_flow && tnl_cfg.out_key_flow) {
535         smap_add(args, "key", "flow");
536     } else if (tnl_cfg.in_key_present && tnl_cfg.out_key_present
537                && tnl_cfg.in_key == tnl_cfg.out_key) {
538         smap_add_format(args, "key", "%"PRIu64, ntohll(tnl_cfg.in_key));
539     } else {
540         if (tnl_cfg.in_key_flow) {
541             smap_add(args, "in_key", "flow");
542         } else if (tnl_cfg.in_key_present) {
543             smap_add_format(args, "in_key", "%"PRIu64,
544                             ntohll(tnl_cfg.in_key));
545         }
546
547         if (tnl_cfg.out_key_flow) {
548             smap_add(args, "out_key", "flow");
549         } else if (tnl_cfg.out_key_present) {
550             smap_add_format(args, "out_key", "%"PRIu64,
551                             ntohll(tnl_cfg.out_key));
552         }
553     }
554
555     if (tnl_cfg.ttl_inherit) {
556         smap_add(args, "ttl", "inherit");
557     } else if (tnl_cfg.ttl != DEFAULT_TTL) {
558         smap_add_format(args, "ttl", "%"PRIu8, tnl_cfg.ttl);
559     }
560
561     if (tnl_cfg.tos_inherit) {
562         smap_add(args, "tos", "inherit");
563     } else if (tnl_cfg.tos) {
564         smap_add_format(args, "tos", "0x%x", tnl_cfg.tos);
565     }
566
567     if (tnl_cfg.dst_port) {
568         uint16_t dst_port = ntohs(tnl_cfg.dst_port);
569         const char *type = netdev_get_type(dev);
570
571         if ((!strcmp("vxlan", type) && dst_port != VXLAN_DST_PORT) ||
572             (!strcmp("lisp", type) && dst_port != LISP_DST_PORT)) {
573             smap_add_format(args, "dst_port", "%d", dst_port);
574         }
575     }
576
577     if (tnl_cfg.csum) {
578         smap_add(args, "csum", "true");
579     }
580
581     if (!tnl_cfg.dont_fragment) {
582         smap_add(args, "df_default", "false");
583     }
584
585     return 0;
586 }
587 \f
588 /* Code specific to patch ports. */
589
590 /* If 'netdev' is a patch port, returns the name of its peer as a malloc()'d
591  * string that the caller must free.
592  *
593  * If 'netdev' is not a patch port, returns NULL. */
594 char *
595 netdev_vport_patch_peer(const struct netdev *netdev_)
596 {
597     char *peer = NULL;
598
599     if (netdev_vport_is_patch(netdev_)) {
600         struct netdev_vport *netdev = netdev_vport_cast(netdev_);
601
602         ovs_mutex_lock(&netdev->mutex);
603         if (netdev->peer) {
604             peer = xstrdup(netdev->peer);
605         }
606         ovs_mutex_unlock(&netdev->mutex);
607     }
608
609     return peer;
610 }
611
612 void
613 netdev_vport_inc_rx(const struct netdev *netdev,
614                     const struct dpif_flow_stats *stats)
615 {
616     if (is_vport_class(netdev_get_class(netdev))) {
617         struct netdev_vport *dev = netdev_vport_cast(netdev);
618
619         ovs_mutex_lock(&dev->mutex);
620         dev->stats.rx_packets += stats->n_packets;
621         dev->stats.rx_bytes += stats->n_bytes;
622         ovs_mutex_unlock(&dev->mutex);
623     }
624 }
625
626 void
627 netdev_vport_inc_tx(const struct netdev *netdev,
628                     const struct dpif_flow_stats *stats)
629 {
630     if (is_vport_class(netdev_get_class(netdev))) {
631         struct netdev_vport *dev = netdev_vport_cast(netdev);
632
633         ovs_mutex_lock(&dev->mutex);
634         dev->stats.tx_packets += stats->n_packets;
635         dev->stats.tx_bytes += stats->n_bytes;
636         ovs_mutex_unlock(&dev->mutex);
637     }
638 }
639
640 static int
641 get_patch_config(const struct netdev *dev_, struct smap *args)
642 {
643     struct netdev_vport *dev = netdev_vport_cast(dev_);
644
645     ovs_mutex_lock(&dev->mutex);
646     if (dev->peer) {
647         smap_add(args, "peer", dev->peer);
648     }
649     ovs_mutex_unlock(&dev->mutex);
650
651     return 0;
652 }
653
654 static int
655 set_patch_config(struct netdev *dev_, const struct smap *args)
656 {
657     struct netdev_vport *dev = netdev_vport_cast(dev_);
658     const char *name = netdev_get_name(dev_);
659     const char *peer;
660
661     peer = smap_get(args, "peer");
662     if (!peer) {
663         VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
664         return EINVAL;
665     }
666
667     if (smap_count(args) > 1) {
668         VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
669         return EINVAL;
670     }
671
672     if (!strcmp(name, peer)) {
673         VLOG_ERR("%s: patch peer must not be self", name);
674         return EINVAL;
675     }
676
677     ovs_mutex_lock(&dev->mutex);
678     free(dev->peer);
679     dev->peer = xstrdup(peer);
680     netdev_vport_changed(dev);
681     ovs_mutex_unlock(&dev->mutex);
682
683     return 0;
684 }
685
686 static int
687 get_stats(const struct netdev *netdev, struct netdev_stats *stats)
688 {
689     struct netdev_vport *dev = netdev_vport_cast(netdev);
690
691     ovs_mutex_lock(&dev->mutex);
692     *stats = dev->stats;
693     ovs_mutex_unlock(&dev->mutex);
694
695     return 0;
696 }
697 \f
698 #define VPORT_FUNCTIONS(GET_CONFIG, SET_CONFIG,             \
699                         GET_TUNNEL_CONFIG, GET_STATUS)      \
700     NULL,                                                   \
701     netdev_vport_run,                                       \
702     netdev_vport_wait,                                      \
703                                                             \
704     netdev_vport_alloc,                                     \
705     netdev_vport_construct,                                 \
706     netdev_vport_destruct,                                  \
707     netdev_vport_dealloc,                                   \
708     GET_CONFIG,                                             \
709     SET_CONFIG,                                             \
710     GET_TUNNEL_CONFIG,                                      \
711                                                             \
712     NULL,                       /* send */                  \
713     NULL,                       /* send_wait */             \
714                                                             \
715     netdev_vport_set_etheraddr,                             \
716     netdev_vport_get_etheraddr,                             \
717     NULL,                       /* get_mtu */               \
718     NULL,                       /* set_mtu */               \
719     NULL,                       /* get_ifindex */           \
720     NULL,                       /* get_carrier */           \
721     NULL,                       /* get_carrier_resets */    \
722     NULL,                       /* get_miimon */            \
723     get_stats,                                              \
724     NULL,                       /* set_stats */             \
725                                                             \
726     NULL,                       /* get_features */          \
727     NULL,                       /* set_advertisements */    \
728                                                             \
729     NULL,                       /* set_policing */          \
730     NULL,                       /* get_qos_types */         \
731     NULL,                       /* get_qos_capabilities */  \
732     NULL,                       /* get_qos */               \
733     NULL,                       /* set_qos */               \
734     NULL,                       /* get_queue */             \
735     NULL,                       /* set_queue */             \
736     NULL,                       /* delete_queue */          \
737     NULL,                       /* get_queue_stats */       \
738     NULL,                       /* queue_dump_start */      \
739     NULL,                       /* queue_dump_next */       \
740     NULL,                       /* queue_dump_done */       \
741     NULL,                       /* dump_queue_stats */      \
742                                                             \
743     NULL,                       /* get_in4 */               \
744     NULL,                       /* set_in4 */               \
745     NULL,                       /* get_in6 */               \
746     NULL,                       /* add_router */            \
747     NULL,                       /* get_next_hop */          \
748     GET_STATUS,                                             \
749     NULL,                       /* arp_lookup */            \
750                                                             \
751     netdev_vport_update_flags,                              \
752                                                             \
753     netdev_vport_change_seq,                                \
754                                                             \
755     NULL,                   /* rx_alloc */                  \
756     NULL,                   /* rx_construct */              \
757     NULL,                   /* rx_destruct */               \
758     NULL,                   /* rx_dealloc */                \
759     NULL,                   /* rx_recv */                   \
760     NULL,                   /* rx_wait */                   \
761     NULL,                   /* rx_drain */
762
763 #define TUNNEL_CLASS(NAME, DPIF_PORT)                       \
764     { DPIF_PORT,                                            \
765         { NAME, VPORT_FUNCTIONS(get_tunnel_config,          \
766                                 set_tunnel_config,          \
767                                 get_netdev_tunnel_config,   \
768                                 tunnel_get_status) }}
769
770 void
771 netdev_vport_tunnel_register(void)
772 {
773     static const struct vport_class vport_classes[] = {
774         TUNNEL_CLASS("gre", "gre_system"),
775         TUNNEL_CLASS("ipsec_gre", "gre_system"),
776         TUNNEL_CLASS("gre64", "gre64_system"),
777         TUNNEL_CLASS("ipsec_gre64", "gre64_system"),
778         TUNNEL_CLASS("vxlan", "vxlan_system"),
779         TUNNEL_CLASS("lisp", "lisp_system")
780     };
781     static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
782
783     if (ovsthread_once_start(&once)) {
784         int i;
785
786         for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
787             netdev_register_provider(&vport_classes[i].netdev_class);
788         }
789         ovsthread_once_done(&once);
790     }
791 }
792
793 void
794 netdev_vport_patch_register(void)
795 {
796     static const struct vport_class patch_class =
797         { NULL,
798             { "patch", VPORT_FUNCTIONS(get_patch_config,
799                                        set_patch_config,
800                                        NULL,
801                                        NULL) }};
802     netdev_register_provider(&patch_class.netdev_class);
803 }