+\f
+/* Code specific to individual vport types. */
+
+static int
+parse_tunnel_config(struct vport_info *port, const struct shash *args)
+{
+ const char *name = port->devname;
+ bool is_gre = !strcmp(port->type, "gre");
+ struct tnl_port_config *config;
+ struct shash_node *node;
+ bool ipsec_ip_set = false;
+ bool ipsec_mech_set = false;
+
+ config = port->config = xzalloc(sizeof *config);
+ config->flags |= TNL_F_PMTUD;
+ config->flags |= TNL_F_HDR_CACHE;
+
+ SHASH_FOR_EACH (node, args) {
+ if (!strcmp(node->name, "remote_ip")) {
+ struct in_addr in_addr;
+ if (lookup_ip(node->data, &in_addr)) {
+ VLOG_WARN("%s: bad %s 'remote_ip'", name, port->type);
+ } else {
+ config->daddr = in_addr.s_addr;
+ }
+ } else if (!strcmp(node->name, "local_ip")) {
+ struct in_addr in_addr;
+ if (lookup_ip(node->data, &in_addr)) {
+ VLOG_WARN("%s: bad %s 'local_ip'", name, port->type);
+ } else {
+ config->saddr = in_addr.s_addr;
+ }
+ } else if (!strcmp(node->name, "key") && is_gre) {
+ if (!strcmp(node->data, "flow")) {
+ config->flags |= TNL_F_IN_KEY_MATCH;
+ config->flags |= TNL_F_OUT_KEY_ACTION;
+ } else {
+ config->out_key = config->in_key = htonl(atoi(node->data));
+ }
+ } else if (!strcmp(node->name, "in_key") && is_gre) {
+ if (!strcmp(node->data, "flow")) {
+ config->flags |= TNL_F_IN_KEY_MATCH;
+ } else {
+ config->in_key = htonl(atoi(node->data));
+ }
+ } else if (!strcmp(node->name, "out_key") && is_gre) {
+ if (!strcmp(node->data, "flow")) {
+ config->flags |= TNL_F_OUT_KEY_ACTION;
+ } else {
+ config->out_key = htonl(atoi(node->data));
+ }
+ } else if (!strcmp(node->name, "tos")) {
+ if (!strcmp(node->data, "inherit")) {
+ config->flags |= TNL_F_TOS_INHERIT;
+ } else {
+ config->tos = atoi(node->data);
+ }
+ } else if (!strcmp(node->name, "ttl")) {
+ if (!strcmp(node->data, "inherit")) {
+ config->flags |= TNL_F_TTL_INHERIT;
+ } else {
+ config->ttl = atoi(node->data);
+ }
+ } else if (!strcmp(node->name, "csum") && is_gre) {
+ if (!strcmp(node->data, "true")) {
+ config->flags |= TNL_F_CSUM;
+ }
+ } else if (!strcmp(node->name, "pmtud")) {
+ if (!strcmp(node->data, "false")) {
+ config->flags &= ~TNL_F_PMTUD;
+ }
+ } else if (!strcmp(node->name, "header_cache")) {
+ if (!strcmp(node->data, "false")) {
+ config->flags &= ~TNL_F_HDR_CACHE;
+ }
+ } else if (!strcmp(node->name, "ipsec_local_ip")) {
+ ipsec_ip_set = true;
+ } else if (!strcmp(node->name, "ipsec_cert")
+ || !strcmp(node->name, "ipsec_psk")) {
+ ipsec_mech_set = true;
+ } else {
+ VLOG_WARN("%s: unknown %s argument '%s'",
+ name, port->type, node->name);
+ }
+ }
+
+ /* IPsec doesn't work when header caching is enabled. Disable it if the
+ * IPsec local IP address and authentication mechanism have been defined. */
+ if (ipsec_ip_set && ipsec_mech_set) {
+ VLOG_INFO("%s: header caching disabled due to use of IPsec", name);
+ config->flags &= ~TNL_F_HDR_CACHE;
+ }
+
+ if (!config->daddr) {
+ VLOG_WARN("%s: %s type requires valid 'remote_ip' argument",
+ name, port->type);
+ return EINVAL;
+ }
+
+ return 0;
+}
+
+static int
+parse_patch_config(struct vport_info *port, const struct shash *args)
+{
+ const char *name = port->devname;
+ const char *peer;
+
+ peer = shash_find_data(args, "peer");
+ if (!peer) {
+ VLOG_WARN("%s: patch type requires valid 'peer' argument", name);
+ return EINVAL;
+ }
+
+ if (shash_count(args) > 1) {
+ VLOG_WARN("%s: patch type takes only a 'peer' argument", name);
+ return EINVAL;
+ }
+
+ if (strlen(peer) >= IFNAMSIZ) {
+ VLOG_WARN("%s: patch 'peer' arg too long", name);
+ return EINVAL;
+ }
+
+ if (!strcmp(name, peer)) {
+ VLOG_WARN("%s: patch peer must not be self", name);
+ return EINVAL;
+ }
+
+ port->config = xstrdup(peer);
+
+ return 0;
+}
+\f
+#define VPORT_FUNCTIONS \
+ NULL, /* init */ \
+ NULL, /* run */ \
+ NULL, /* wait */ \
+ \
+ netdev_vport_create, \
+ netdev_vport_destroy, \
+ netdev_vport_reconfigure, \
+ \
+ netdev_vport_open, \
+ netdev_vport_close, \
+ \
+ NULL, /* enumerate */ \
+ \
+ NULL, /* recv */ \
+ NULL, /* recv_wait */ \
+ NULL, /* drain */ \
+ \
+ NULL, /* send */ \
+ NULL, /* send_wait */ \
+ \
+ netdev_vport_set_etheraddr, \
+ netdev_vport_get_etheraddr, \
+ netdev_vport_get_mtu, \
+ NULL, /* get_ifindex */ \
+ NULL, /* get_carrier */ \
+ netdev_vport_get_stats, \
+ netdev_vport_set_stats, \
+ \
+ NULL, /* get_features */ \
+ NULL, /* set_advertisements */ \
+ NULL, /* get_vlan_vid */ \
+ \
+ NULL, /* set_policing */ \
+ NULL, /* get_qos_types */ \
+ NULL, /* get_qos_capabilities */ \
+ NULL, /* get_qos */ \
+ NULL, /* set_qos */ \
+ NULL, /* get_queue */ \
+ NULL, /* set_queue */ \
+ NULL, /* delete_queue */ \
+ NULL, /* get_queue_stats */ \
+ NULL, /* dump_queues */ \
+ NULL, /* dump_queue_stats */ \
+ \
+ NULL, /* get_in4 */ \
+ NULL, /* set_in4 */ \
+ NULL, /* get_in6 */ \
+ NULL, /* add_router */ \
+ NULL, /* get_next_hop */ \
+ NULL, /* arp_lookup */ \
+ \
+ netdev_vport_update_flags, \
+ \
+ netdev_vport_poll_add, \
+ netdev_vport_poll_remove,
+
+static const struct vport_class vport_gre_class
+ = { { "gre", VPORT_FUNCTIONS }, parse_tunnel_config };
+
+static const struct vport_class vport_capwap_class
+ = { { "capwap", VPORT_FUNCTIONS }, parse_tunnel_config };
+
+static const struct vport_class vport_patch_class
+ = { { "patch", VPORT_FUNCTIONS }, parse_patch_config };
+
+void
+netdev_vport_register(void)
+{
+ netdev_register_provider(&vport_gre_class.netdev_class);
+ netdev_register_provider(&vport_capwap_class.netdev_class);
+ netdev_register_provider(&vport_patch_class.netdev_class);
+}