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