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