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