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