diff options
Diffstat (limited to 'ofproto')
-rw-r--r-- | ofproto/automake.mk | 3 | ||||
-rw-r--r-- | ofproto/ofproto-dpif-xlate.c | 189 | ||||
-rw-r--r-- | ofproto/ofproto-dpif.c | 95 | ||||
-rw-r--r-- | ofproto/ofproto-dpif.h | 1 | ||||
-rw-r--r-- | ofproto/ofproto-tnl-unixctl.man | 27 | ||||
-rw-r--r-- | ofproto/tunnel.c | 73 | ||||
-rw-r--r-- | ofproto/tunnel.h | 11 |
7 files changed, 367 insertions, 32 deletions
diff --git a/ofproto/automake.mk b/ofproto/automake.mk index 6f04852c6..f5489468e 100644 --- a/ofproto/automake.mk +++ b/ofproto/automake.mk @@ -68,7 +68,8 @@ BUILT_SOURCES += ofproto/ipfix-entities.def CLEANFILES += ofproto/ipfix-entities.def -MAN_FRAGMENTS += ofproto/ofproto-unixctl.man ofproto/ofproto-dpif-unixctl.man +MAN_FRAGMENTS += ofproto/ofproto-unixctl.man ofproto/ofproto-dpif-unixctl.man \ + ofproto/ofproto-tnl-unixctl.man # IPFIX entity definition macros generation from IANA's XML definition. EXTRA_DIST += ofproto/ipfix.xml diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 9a21f0554..6bf6d6dd7 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -17,7 +17,12 @@ #include "ofproto/ofproto-dpif-xlate.h" #include <errno.h> +#include <arpa/inet.h> +#include <net/if.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include "tnl-arp-cache.h" #include "bfd.h" #include "bitmap.h" #include "bond.h" @@ -48,6 +53,8 @@ #include "ofproto/ofproto-dpif.h" #include "ofproto/ofproto-provider.h" #include "packet-dpif.h" +#include "ovs-router.h" +#include "tnl-ports.h" #include "tunnel.h" #include "vlog.h" @@ -249,6 +256,7 @@ enum xc_type { XC_NORMAL, XC_FIN_TIMEOUT, XC_GROUP, + XC_TNL_ARP, }; /* xlate_cache entries hold enough information to perform the side effects of @@ -298,6 +306,10 @@ struct xc_entry { struct group_dpif *group; struct ofputil_bucket *bucket; } group; + struct { + char br_name[IFNAMSIZ]; + ovs_be32 d_ip; + } tnl_arp_cache; } u; }; @@ -2455,6 +2467,125 @@ process_special(struct xlate_ctx *ctx, const struct flow *flow, } } +static int +tnl_route_lookup_flow(const struct flow *oflow, + ovs_be32 *ip, struct xport **out_port) +{ + char out_dev[IFNAMSIZ]; + struct xbridge *xbridge; + struct xlate_cfg *xcfg; + ovs_be32 gw; + + if (!ovs_router_lookup(oflow->tunnel.ip_dst, out_dev, &gw)) { + return -ENOENT; + } + + if (gw) { + *ip = gw; + } else { + *ip = oflow->tunnel.ip_dst; + } + + xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp); + ovs_assert(xcfg); + + HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) { + if (!strncmp(xbridge->name, out_dev, IFNAMSIZ)) { + struct xport *port; + + HMAP_FOR_EACH (port, ofp_node, &xbridge->xports) { + if (!strncmp(netdev_get_name(port->netdev), out_dev, IFNAMSIZ)) { + *out_port = port; + return 0; + } + } + } + } + return -ENOENT; +} + +static int +xlate_flood_packet(struct xbridge *xbridge, struct ofpbuf *packet) +{ + struct ofpact_output output; + struct flow flow; + + ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output); + /* Use OFPP_NONE as the in_port to avoid special packet processing. */ + flow_extract(packet, NULL, &flow); + flow.in_port.ofp_port = OFPP_NONE; + output.port = OFPP_FLOOD; + output.max_len = 0; + + return ofproto_dpif_execute_actions(xbridge->ofproto, &flow, NULL, + &output.ofpact, sizeof output, + packet); +} + +static void +tnl_send_arp_request(const struct xport *out_dev, const uint8_t eth_src[ETH_ADDR_LEN], + ovs_be32 ip_src, ovs_be32 ip_dst) +{ + struct xbridge *xbridge = out_dev->xbridge; + struct ofpbuf packet; + + ofpbuf_init(&packet, 0); + compose_arp(&packet, eth_src, ip_src, ip_dst); + + xlate_flood_packet(xbridge, &packet); + ofpbuf_uninit(&packet); +} + +static int +build_tunnel_send(const struct xlate_ctx *ctx, const struct xport *xport, + const struct flow *flow, odp_port_t tunnel_odp_port) +{ + struct ovs_action_push_tnl tnl_push_data; + struct xport *out_dev = NULL; + ovs_be32 s_ip, d_ip = 0; + uint8_t smac[ETH_ADDR_LEN]; + uint8_t dmac[ETH_ADDR_LEN]; + int err; + + err = tnl_route_lookup_flow(flow, &d_ip, &out_dev); + if (err) { + return err; + } + + /* Use mac addr of bridge port of the peer. */ + err = netdev_get_etheraddr(out_dev->netdev, smac); + if (err) { + return err; + } + + err = netdev_get_in4(out_dev->netdev, (struct in_addr *) &s_ip, NULL); + if (err) { + return err; + } + + err = tnl_arp_lookup(out_dev->xbridge->name, d_ip, dmac); + if (err) { + tnl_send_arp_request(out_dev, smac, s_ip, d_ip); + return err; + } + if (ctx->xin->xcache) { + struct xc_entry *entry; + + entry = xlate_cache_add_entry(ctx->xin->xcache, XC_TNL_ARP); + strncpy(entry->u.tnl_arp_cache.br_name, out_dev->xbridge->name, IFNAMSIZ); + entry->u.tnl_arp_cache.d_ip = d_ip; + } + err = tnl_port_build_header(xport->ofport, flow, + dmac, smac, s_ip, &tnl_push_data); + if (err) { + return err; + } + tnl_push_data.tnl_port = odp_to_u32(tunnel_odp_port); + tnl_push_data.out_port = odp_to_u32(out_dev->odp_port); + odp_put_tnl_push_action(ctx->xout->odp_actions, &tnl_push_data); + return 0; +} + static void compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port, bool check_stp) @@ -2462,15 +2593,18 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port, const struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port); struct flow_wildcards *wc = &ctx->xout->wc; struct flow *flow = &ctx->xin->flow; + struct flow_tnl flow_tnl; ovs_be16 flow_vlan_tci; uint32_t flow_pkt_mark; uint8_t flow_nw_tos; odp_port_t out_port, odp_port; + bool tnl_push_pop_send = false; uint8_t dscp; /* If 'struct flow' gets additional metadata, we'll need to zero it out * before traversing a patch port. */ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 28); + memset(&flow_tnl, 0, sizeof flow_tnl); if (!xport) { xlate_report(ctx, "Nonexistent output port"); @@ -2580,7 +2714,7 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port, * the Logical (tunnel) Port are not visible for any further * matches, while explicit set actions on tunnel metadata are. */ - struct flow_tnl flow_tnl = flow->tunnel; + flow_tnl = flow->tunnel; odp_port = tnl_port_send(xport->ofport, flow, &ctx->xout->wc); if (odp_port == ODPP_NONE) { xlate_report(ctx, "Tunneling decided against output"); @@ -2600,9 +2734,13 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port, entry->u.dev.tx = netdev_ref(xport->netdev); } out_port = odp_port; - commit_odp_tunnel_action(flow, &ctx->base_flow, - ctx->xout->odp_actions); - flow->tunnel = flow_tnl; /* Restore tunnel metadata */ + if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) { + tnl_push_pop_send = true; + } else { + commit_odp_tunnel_action(flow, &ctx->base_flow, + ctx->xout->odp_actions); + flow->tunnel = flow_tnl; /* Restore tunnel metadata */ + } } else { odp_port = xport->odp_port; out_port = odp_port; @@ -2622,7 +2760,7 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port, if (out_port != ODPP_NONE) { ctx->xout->slow |= commit_odp_actions(flow, &ctx->base_flow, ctx->xout->odp_actions, - &ctx->xout->wc, + wc, ctx->xbridge->masked_set_action); if (ctx->use_recirc) { @@ -2640,9 +2778,34 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port, nl_msg_put_u32(ctx->xout->odp_actions, OVS_ACTION_ATTR_RECIRC, xr->recirc_id); } else { - add_ipfix_output_action(ctx, out_port); - nl_msg_put_odp_port(ctx->xout->odp_actions, OVS_ACTION_ATTR_OUTPUT, - out_port); + + if (tnl_push_pop_send) { + build_tunnel_send(ctx, xport, flow, odp_port); + flow->tunnel = flow_tnl; /* Restore tunnel metadata */ + } else { + odp_port_t odp_tnl_port = ODPP_NONE; + + /* XXX: Write better Filter for tunnel port. We can use inport + * int tunnel-port flow to avoid these checks completely. */ + if (ofp_port == OFPP_LOCAL && + ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) { + + odp_tnl_port = tnl_port_map_lookup(flow, wc); + } + + if (odp_tnl_port != ODPP_NONE) { + nl_msg_put_odp_port(ctx->xout->odp_actions, + OVS_ACTION_ATTR_TUNNEL_POP, + odp_tnl_port); + } else { + /* Tunnel push-pop action is not compatible with + * IPFIX action. */ + add_ipfix_output_action(ctx, out_port); + nl_msg_put_odp_port(ctx->xout->odp_actions, + OVS_ACTION_ATTR_OUTPUT, + out_port); + } + } } ctx->sflow_odp_port = odp_port; @@ -3604,6 +3767,9 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len, struct flow *flow = &ctx->xin->flow; const struct ofpact *a; + if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) { + tnl_arp_snoop(flow, wc, ctx->xbridge->name); + } /* dl_type already in the mask, not set below. */ OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { @@ -4464,6 +4630,7 @@ xlate_push_stats(struct xlate_cache *xcache, { struct xc_entry *entry; struct ofpbuf entries = xcache->entries; + uint8_t dmac[ETH_ADDR_LEN]; if (!stats->n_packets) { return; @@ -4505,6 +4672,10 @@ xlate_push_stats(struct xlate_cache *xcache, group_dpif_credit_stats(entry->u.group.group, entry->u.group.bucket, stats); break; + case XC_TNL_ARP: + /* Lookup arp to avoid arp timeout. */ + tnl_arp_lookup(entry->u.tnl_arp_cache.br_name, entry->u.tnl_arp_cache.d_ip, dmac); + break; default: OVS_NOT_REACHED(); } @@ -4575,6 +4746,8 @@ xlate_cache_clear(struct xlate_cache *xcache) case XC_GROUP: group_dpif_unref(entry->u.group.group); break; + case XC_TNL_ARP: + break; default: OVS_NOT_REACHED(); } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index e3eb07484..df963f8b0 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -58,8 +58,8 @@ #include "ofproto-dpif-sflow.h" #include "ofproto-dpif-upcall.h" #include "ofproto-dpif-xlate.h" -#include "ovs-router.h" #include "poll-loop.h" +#include "ovs-router.h" #include "seq.h" #include "simap.h" #include "smap.h" @@ -284,6 +284,10 @@ struct dpif_backer { /* Version string of the datapath stored in OVSDB. */ char *dp_version_string; + + /* True if the datapath supports tnl_push and pop actions. */ + bool enable_tnl_push_pop; + struct atomic_count tnl_count; }; /* All existing ofproto_backer instances, indexed by ofproto->up.type. */ @@ -345,7 +349,8 @@ struct ofproto_dpif { /* All existing ofproto_dpif instances, indexed by ->up.name. */ static struct hmap all_ofproto_dpifs = HMAP_INITIALIZER(&all_ofproto_dpifs); -static void ofproto_dpif_unixctl_init(void); +static bool ofproto_use_tnl_push_pop = true; +static void ofproto_unixctl_init(void); static inline struct ofproto_dpif * ofproto_dpif_cast(const struct ofproto *ofproto) @@ -512,7 +517,11 @@ type_run(const char *type) return 0; } - dpif_run(backer->dpif); + + if (dpif_run(backer->dpif)) { + backer->need_revalidate = REV_RECONFIGURE; + } + udpif_run(backer->udpif); /* If vswitchd started with other_config:flow_restore_wait set as "true", @@ -585,7 +594,8 @@ type_run(const char *type) iter->odp_port = node ? u32_to_odp(node->data) : ODPP_NONE; if (tnl_port_reconfigure(iter, iter->up.netdev, - iter->odp_port)) { + iter->odp_port, + ovs_native_tunneling_is_on(ofproto), dp_port)) { backer->need_revalidate = REV_RECONFIGURE; } } @@ -953,6 +963,9 @@ open_dpif_backer(const char *type, struct dpif_backer **backerp) backer->masked_set_action = check_masked_set_action(backer); backer->rid_pool = recirc_id_pool_create(); + backer->enable_tnl_push_pop = dpif_supports_tnl_push_pop(backer->dpif); + atomic_count_init(&backer->tnl_count, 0); + error = dpif_recv_set(backer->dpif, backer->recv_set_enable); if (error) { VLOG_ERR("failed to listen on datapath of type %s: %s", @@ -974,6 +987,13 @@ open_dpif_backer(const char *type, struct dpif_backer **backerp) return error; } +bool +ovs_native_tunneling_is_on(struct ofproto_dpif *ofproto) +{ + return ofproto_use_tnl_push_pop && ofproto->backer->enable_tnl_push_pop && + atomic_count_get(&ofproto->backer->tnl_count); +} + /* Tests whether 'backer''s datapath supports recirculation. Only newer * datapaths support OVS_KEY_ATTR_RECIRC_ID in keys. We need to disable some * features on older datapaths that don't support this feature. @@ -1230,7 +1250,7 @@ construct(struct ofproto *ofproto_) guarded_list_init(&ofproto->pins); - ofproto_dpif_unixctl_init(); + ofproto_unixctl_init(); ovs_router_unixctl_register(); hmap_init(&ofproto->vlandev_map); @@ -1523,7 +1543,6 @@ run(struct ofproto *ofproto_) } } } - return 0; } @@ -1675,7 +1694,9 @@ port_construct(struct ofport *port_) port->odp_port = dpif_port.port_no; if (netdev_get_tunnel_config(netdev)) { - tnl_port_add(port, port->up.netdev, port->odp_port); + atomic_count_inc(&ofproto->backer->tnl_count); + tnl_port_add(port, port->up.netdev, port->odp_port, + ovs_native_tunneling_is_on(ofproto), namebuf); port->is_tunnel = true; if (ofproto->ipfix) { dpif_ipfix_add_tunnel_port(ofproto->ipfix, port_, port->odp_port); @@ -1741,6 +1762,10 @@ port_destruct(struct ofport *port_) ovs_rwlock_unlock(&ofproto->backer->odp_to_ofport_lock); } + if (port->is_tunnel) { + atomic_count_dec(&ofproto->backer->tnl_count); + } + if (port->is_tunnel && ofproto->ipfix) { dpif_ipfix_del_tunnel_port(ofproto->ipfix, port->odp_port); } @@ -1766,26 +1791,33 @@ static void port_modified(struct ofport *port_) { struct ofport_dpif *port = ofport_dpif_cast(port_); + char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; + struct netdev *netdev = port->up.netdev; if (port->bundle && port->bundle->bond) { - bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev); + bond_slave_set_netdev(port->bundle->bond, port, netdev); } if (port->cfm) { - cfm_set_netdev(port->cfm, port->up.netdev); + cfm_set_netdev(port->cfm, netdev); } if (port->bfd) { - bfd_set_netdev(port->bfd, port->up.netdev); + bfd_set_netdev(port->bfd, netdev); } ofproto_dpif_monitor_port_update(port, port->bfd, port->cfm, port->up.pp.hw_addr); - if (port->is_tunnel && tnl_port_reconfigure(port, port->up.netdev, - port->odp_port)) { - ofproto_dpif_cast(port->up.ofproto)->backer->need_revalidate = - REV_RECONFIGURE; + netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf); + + if (port->is_tunnel) { + struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto); + + if (tnl_port_reconfigure(port, netdev, port->odp_port, + ovs_native_tunneling_is_on(ofproto), namebuf)) { + ofproto->backer->need_revalidate = REV_RECONFIGURE; + } } ofport_update_peer(port); @@ -3500,6 +3532,7 @@ ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto, execute.actions = ofpbuf_data(xout.odp_actions); execute.actions_len = ofpbuf_size(xout.odp_actions); + execute.packet = packet; execute.md = pkt_metadata_from_flow(flow); execute.needs_help = (xout.slow & SLOW_ACTION) != 0; @@ -4956,7 +4989,36 @@ ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn, } static void -ofproto_dpif_unixctl_init(void) +ofproto_revalidate_all_backers(void) +{ + const struct shash_node **backers; + int i; + + backers = shash_sort(&all_dpif_backers); + for (i = 0; i < shash_count(&all_dpif_backers); i++) { + struct dpif_backer *backer = backers[i]->data; + backer->need_revalidate = REV_RECONFIGURE; + } + free(backers); +} + +static void +disable_tnl_push_pop(struct unixctl_conn *conn OVS_UNUSED, int argc OVS_UNUSED, + const char *argv[], void *aux OVS_UNUSED) +{ + if (!strcasecmp(argv[1], "off")) { + ofproto_use_tnl_push_pop = false; + unixctl_command_reply(conn, "Tunnel push-pop off"); + ofproto_revalidate_all_backers(); + } else if (!strcasecmp(argv[1], "on")) { + ofproto_use_tnl_push_pop = true; + unixctl_command_reply(conn, "Tunnel push-pop on"); + ofproto_revalidate_all_backers(); + } +} + +static void +ofproto_unixctl_init(void) { static bool registered; if (registered) { @@ -4986,6 +5048,9 @@ ofproto_dpif_unixctl_init(void) NULL); unixctl_command_register("dpif/dump-flows", "[-m] bridge", 1, 2, ofproto_unixctl_dpif_dump_flows, NULL); + + unixctl_command_register("ofproto/tnl-push-pop", "[on]|[off]", 1, 1, + disable_tnl_push_pop, NULL); } /* Returns true if 'table' is the table used for internal rules, diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index c06db205a..48e1b30bc 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -281,4 +281,5 @@ static inline bool rule_dpif_is_internal(const struct rule_dpif *rule) #undef RULE_CAST +bool ovs_native_tunneling_is_on(struct ofproto_dpif *ofproto); #endif /* ofproto-dpif.h */ diff --git a/ofproto/ofproto-tnl-unixctl.man b/ofproto/ofproto-tnl-unixctl.man new file mode 100644 index 000000000..853b3f039 --- /dev/null +++ b/ofproto/ofproto-tnl-unixctl.man @@ -0,0 +1,27 @@ +.SS "OPENVSWITCH TUNNELING COMMANDS" +These commands query and modify OVS tunnel components. Ref to +README-native-tunneling.md for more info. +. +.IP "\fBovs/route/add ipv4_address/plen output_bridge [GW]\fR" +Adds ipv4_address/plen route to vswitchd routing table. output_bridge +needs to be OVS bridge name. This command is useful if OVS cached +routes does not look right. +. +.IP "\fBovs/route/show\fR" +Print all routes in OVS routing table, This includes routes cached +from system routing table and user configured routes. +. +.IP "\fBovs/route/del ipv4_address/plen\fR" +Delete ipv4_address/plen route from OVS routing table. +. +.IP "\fBtnl/arp/show\fR" +OVS builds ARP cache by snooping are messages. This command shows +ARP cache table. +. +.IP "\fBtnl/arp/flush\fR" +Flush ARP table. +. +.IP "\fBtnl/egress_port_range [num1] [num2]\fR" +Set range for UDP source port used for UDP based Tunnels. For +example VxLAN. If case of zero arguments this command prints +current range in use. diff --git a/ofproto/tunnel.c b/ofproto/tunnel.c index 4be539021..25df9eb2e 100644 --- a/ofproto/tunnel.c +++ b/ofproto/tunnel.c @@ -19,18 +19,26 @@ #include "byte-order.h" #include "connectivity.h" +#include "csum.h" +#include "dpif.h" #include "dynamic-string.h" #include "fat-rwlock.h" #include "hash.h" #include "hmap.h" #include "netdev.h" #include "odp-util.h" +#include "ofpbuf.h" #include "packets.h" +#include "route-table.h" #include "seq.h" #include "smap.h" #include "socket-util.h" +#include "tnl-arp-cache.h" +#include "tnl-ports.h" #include "tunnel.h" #include "vlog.h" +#include "unaligned.h" +#include "ofproto-dpif.h" VLOG_DEFINE_THIS_MODULE(tunnel); @@ -136,7 +144,7 @@ ofproto_tunnel_init(void) static bool tnl_port_add__(const struct ofport_dpif *ofport, const struct netdev *netdev, - odp_port_t odp_port, bool warn) + odp_port_t odp_port, bool warn, bool native_tnl, const char name[]) OVS_REQ_WRLOCK(rwlock) { const struct netdev_tunnel_config *cfg; @@ -185,6 +193,11 @@ tnl_port_add__(const struct ofport_dpif *ofport, const struct netdev *netdev, } hmap_insert(*map, &tnl_port->match_node, tnl_hash(&tnl_port->match)); tnl_port_mod_log(tnl_port, "adding"); + + if (native_tnl) { + tnl_port_map_insert(odp_port, tnl_port->match.ip_dst, + cfg->dst_port, name); + } return true; } @@ -193,10 +206,10 @@ tnl_port_add__(const struct ofport_dpif *ofport, const struct netdev *netdev, * tunnel. */ void tnl_port_add(const struct ofport_dpif *ofport, const struct netdev *netdev, - odp_port_t odp_port) OVS_EXCLUDED(rwlock) + odp_port_t odp_port, bool native_tnl, const char name[]) OVS_EXCLUDED(rwlock) { fat_rwlock_wrlock(&rwlock); - tnl_port_add__(ofport, netdev, odp_port, true); + tnl_port_add__(ofport, netdev, odp_port, true, native_tnl, name); fat_rwlock_unlock(&rwlock); } @@ -206,7 +219,8 @@ tnl_port_add(const struct ofport_dpif *ofport, const struct netdev *netdev, * tnl_port_add(). */ bool tnl_port_reconfigure(const struct ofport_dpif *ofport, - const struct netdev *netdev, odp_port_t odp_port) + const struct netdev *netdev, odp_port_t odp_port, + bool native_tnl, const char name[]) OVS_EXCLUDED(rwlock) { struct tnl_port *tnl_port; @@ -215,13 +229,13 @@ tnl_port_reconfigure(const struct ofport_dpif *ofport, fat_rwlock_wrlock(&rwlock); tnl_port = tnl_find_ofport(ofport); if (!tnl_port) { - changed = tnl_port_add__(ofport, netdev, odp_port, false); + changed = tnl_port_add__(ofport, netdev, odp_port, false, native_tnl, name); } else if (tnl_port->netdev != netdev || tnl_port->match.odp_port != odp_port || tnl_port->change_seq != seq_read(connectivity_seq_get())) { VLOG_DBG("reconfiguring %s", tnl_port_get_name(tnl_port)); tnl_port_del__(ofport); - tnl_port_add__(ofport, netdev, odp_port, true); + tnl_port_add__(ofport, netdev, odp_port, true, native_tnl, name); changed = true; } fat_rwlock_unlock(&rwlock); @@ -239,8 +253,11 @@ tnl_port_del__(const struct ofport_dpif *ofport) OVS_REQ_WRLOCK(rwlock) tnl_port = tnl_find_ofport(ofport); if (tnl_port) { + const struct netdev_tunnel_config *cfg = + netdev_get_tunnel_config(tnl_port->netdev); struct hmap **map; + tnl_port_map_delete(tnl_port->match.ip_dst, cfg->dst_port); tnl_port_mod_log(tnl_port, "removing"); map = tnl_match_map(&tnl_port->match); hmap_remove(*map, &tnl_port->match_node); @@ -651,3 +668,47 @@ tnl_port_get_name(const struct tnl_port *tnl_port) OVS_REQ_RDLOCK(rwlock) { return netdev_get_name(tnl_port->netdev); } + +int +tnl_port_build_header(const struct ofport_dpif *ofport, + const struct flow *tnl_flow, + uint8_t dmac[ETH_ADDR_LEN], + uint8_t smac[ETH_ADDR_LEN], + ovs_be32 ip_src, struct ovs_action_push_tnl *data) +{ + struct tnl_port *tnl_port; + struct eth_header *eth; + struct ip_header *ip; + void *l3; + int res; + + fat_rwlock_rdlock(&rwlock); + tnl_port = tnl_find_ofport(ofport); + ovs_assert(tnl_port); + + /* Build Ethernet and IP headers. */ + memset(data->header, 0, sizeof data->header); + + eth = (struct eth_header *)data->header; + memcpy(eth->eth_dst, dmac, ETH_ADDR_LEN); + memcpy(eth->eth_src, smac, ETH_ADDR_LEN); + eth->eth_type = htons(ETH_TYPE_IP); + + l3 = (eth + 1); + ip = (struct ip_header *) l3; + + ip->ip_ihl_ver = IP_IHL_VER(5, 4); + ip->ip_tos = tnl_flow->tunnel.ip_tos; + ip->ip_ttl = tnl_flow->tunnel.ip_ttl; + ip->ip_frag_off = (tnl_flow->tunnel.flags & FLOW_TNL_F_DONT_FRAGMENT) ? + htons(IP_DF) : 0; + + put_16aligned_be32(&ip->ip_src, ip_src); + put_16aligned_be32(&ip->ip_dst, tnl_flow->tunnel.ip_dst); + + res = netdev_build_header(tnl_port->netdev, data); + ip->ip_csum = csum(ip, sizeof *ip); + fat_rwlock_unlock(&rwlock); + + return res; +} diff --git a/ofproto/tunnel.h b/ofproto/tunnel.h index cdcbb7715..6181762b2 100644 --- a/ofproto/tunnel.h +++ b/ofproto/tunnel.h @@ -25,15 +25,16 @@ * These functions emulate tunnel virtual ports based on the outer * header information from the kernel. */ +struct ovs_action_push_tnl; struct ofport_dpif; struct netdev; void ofproto_tunnel_init(void); bool tnl_port_reconfigure(const struct ofport_dpif *, const struct netdev *, - odp_port_t); + odp_port_t, bool native_tnl, const char name[]); void tnl_port_add(const struct ofport_dpif *, const struct netdev *, - odp_port_t odp_port); + odp_port_t odp_port, bool native_tnl, const char name[]); void tnl_port_del(const struct ofport_dpif *); const struct ofport_dpif *tnl_port_receive(const struct flow *); @@ -49,4 +50,10 @@ tnl_port_should_receive(const struct flow *flow) return flow->tunnel.ip_dst != 0; } +int tnl_port_build_header(const struct ofport_dpif *ofport, + const struct flow *tnl_flow, + uint8_t dmac[ETH_ADDR_LEN], + uint8_t smac[ETH_ADDR_LEN], + ovs_be32 ip_src, struct ovs_action_push_tnl *data); + #endif /* tunnel.h */ |