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