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