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