X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=datapath%2Ftunnel.c;h=1e402931e8f874cca1c64fb6c69e70bbb6d4981d;hb=a2973b1a8b539e0f7fbd1f9fbb090b406484c1bb;hp=cdbb4f45609ffa5bce8616bc4357e4c091f7cd45;hpb=94903c989826268a7fab3c730cd7d0b35ef423d5;p=openvswitch diff --git a/datapath/tunnel.c b/datapath/tunnel.c index cdbb4f45..1e402931 100644 --- a/datapath/tunnel.c +++ b/datapath/tunnel.c @@ -29,6 +29,7 @@ #include #include "actions.h" +#include "checksum.h" #include "datapath.h" #include "table.h" #include "tunnel.h" @@ -71,7 +72,7 @@ static struct tbl *port_table __read_mostly; static void cache_cleaner(struct work_struct *work); -DECLARE_DELAYED_WORK(cache_cleaner_wq, cache_cleaner); +static DECLARE_DELAYED_WORK(cache_cleaner_wq, cache_cleaner); /* * These are just used as an optimization: they don't require any kind of @@ -165,11 +166,11 @@ static unsigned int *find_port_pool(const struct tnl_mutable_config *mutable) } struct port_lookup_key { + const struct tnl_mutable_config *mutable; + __be64 key; u32 tunnel_type; __be32 saddr; __be32 daddr; - __be32 key; - const struct tnl_mutable_config *mutable; }; /* @@ -191,7 +192,8 @@ static int port_cmp(const struct tbl_node *node, void *target) static u32 port_hash(struct port_lookup_key *k) { - return jhash_3words(k->key, k->saddr, k->daddr, k->tunnel_type); + u32 x = jhash_3words(k->saddr, k->daddr, k->tunnel_type, 0); + return jhash_2words(k->key >> 32, k->key, x); } static u32 mutable_hash(const struct tnl_mutable_config *mutable) @@ -276,12 +278,15 @@ static int move_port(struct vport *vport, struct tnl_mutable_config *new_mutable err = tbl_insert(port_table, &tnl_vport->tbl_node, hash); if (err) { + (*find_port_pool(tnl_vport->mutable))--; check_table_empty(); return err; } table_updated: + (*find_port_pool(tnl_vport->mutable))--; assign_config_rcu(vport, new_mutable); + (*find_port_pool(tnl_vport->mutable))++; return 0; } @@ -301,7 +306,7 @@ static int del_port(struct vport *vport) return 0; } -struct vport *tnl_find_port(__be32 saddr, __be32 daddr, __be32 key, +struct vport *tnl_find_port(__be32 saddr, __be32 daddr, __be64 key, int tunnel_type, const struct tnl_mutable_config **mutable) { @@ -364,34 +369,37 @@ found: static inline void ecn_decapsulate(struct sk_buff *skb) { - u8 tos = ip_hdr(skb)->tos; - - if (INET_ECN_is_ce(tos)) { + /* This is accessing the outer IP header of the tunnel, which we've + * already validated to be OK. skb->data is currently set to the start + * of the inner Ethernet header, and we've validated ETH_HLEN. + */ + if (unlikely(INET_ECN_is_ce(ip_hdr(skb)->tos))) { __be16 protocol = skb->protocol; - unsigned int nw_header = skb_network_offset(skb); + + skb_set_network_header(skb, ETH_HLEN); if (skb->protocol == htons(ETH_P_8021Q)) { if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN))) return; protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; - nw_header += VLAN_HLEN; + skb_set_network_header(skb, VLAN_ETH_HLEN); } if (protocol == htons(ETH_P_IP)) { - if (unlikely(!pskb_may_pull(skb, nw_header + if (unlikely(!pskb_may_pull(skb, skb_network_offset(skb) + sizeof(struct iphdr)))) return; - IP_ECN_set_ce((struct iphdr *)(skb->data + nw_header)); + IP_ECN_set_ce(ip_hdr(skb)); } #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) else if (protocol == htons(ETH_P_IPV6)) { - if (unlikely(!pskb_may_pull(skb, nw_header + if (unlikely(!pskb_may_pull(skb, skb_network_offset(skb) + sizeof(struct ipv6hdr)))) return; - IP6_ECN_set_ce((struct ipv6hdr *)(skb->data + nw_header)); + IP6_ECN_set_ce(ipv6_hdr(skb)); } #endif } @@ -400,17 +408,25 @@ static inline void ecn_decapsulate(struct sk_buff *skb) /* Called with rcu_read_lock. */ void tnl_rcv(struct vport *vport, struct sk_buff *skb) { - skb->pkt_type = PACKET_HOST; - skb->protocol = eth_type_trans(skb, skb->dev); + /* Packets received by this function are in the following state: + * - skb->data points to the inner Ethernet header. + * - The inner Ethernet header is in the linear data area. + * - skb->csum does not include the inner Ethernet header. + * - The layer pointers point at the outer headers. + */ + + struct ethhdr *eh = (struct ethhdr *)skb->data; + + if (likely(ntohs(eh->h_proto) >= 1536)) + skb->protocol = eh->h_proto; + else + skb->protocol = htons(ETH_P_802_2); skb_dst_drop(skb); nf_reset(skb); secpath_reset(skb); - skb_reset_network_header(skb); ecn_decapsulate(skb); - - skb_push(skb, ETH_HLEN); compute_ip_summed(skb, false); vport_receive(vport, skb); @@ -583,7 +599,7 @@ static void ipv6_build_icmp(struct sk_buff *skb, struct sk_buff *nskb, #endif /* IPv6 */ bool tnl_frag_needed(struct vport *vport, const struct tnl_mutable_config *mutable, - struct sk_buff *skb, unsigned int mtu, __be32 flow_key) + struct sk_buff *skb, unsigned int mtu, __be64 flow_key) { unsigned int eth_hdr_len = ETH_HLEN; unsigned int total_length = 0, header_length = 0, payload_length; @@ -803,7 +819,7 @@ static void cache_cleaner(struct work_struct *work) schedule_cache_cleaner(); rcu_read_lock(); - tbl_foreach(port_table, cache_cleaner_cb, NULL); + tbl_foreach(rcu_dereference(port_table), cache_cleaner_cb, NULL); rcu_read_unlock(); } @@ -883,22 +899,17 @@ static struct tnl_cache *build_cache(struct vport *vport, #endif if (is_internal_dev(rt_dst(rt).dev)) { - int err; + struct odp_flow_key flow_key; + struct tbl_node *flow_node; struct vport *vport; - struct dp_port *dp_port; struct sk_buff *skb; bool is_frag; - struct odp_flow_key flow_key; - struct tbl_node *flow_node; + int err; vport = internal_dev_get_vport(rt_dst(rt).dev); if (!vport) goto done; - dp_port = vport_get_dp_port(vport); - if (!dp_port) - goto done; - skb = alloc_skb(cache->len, GFP_ATOMIC); if (!skb) goto done; @@ -906,13 +917,13 @@ static struct tnl_cache *build_cache(struct vport *vport, __skb_put(skb, cache->len); memcpy(skb->data, get_cached_header(cache), cache->len); - err = flow_extract(skb, dp_port->port_no, &flow_key, &is_frag); + err = flow_extract(skb, vport->port_no, &flow_key, &is_frag); kfree_skb(skb); if (err || is_frag) goto done; - flow_node = tbl_lookup(rcu_dereference(dp_port->dp->table), + flow_node = tbl_lookup(rcu_dereference(vport->dp->table), &flow_key, flow_hash(&flow_key), flow_cmp); if (flow_node) { @@ -1034,7 +1045,7 @@ static struct sk_buff *handle_offloads(struct sk_buff *skb, */ if (skb_headroom(skb) < min_headroom) { skb = check_headroom(skb, min_headroom); - if (unlikely(IS_ERR(skb))) { + if (IS_ERR(skb)) { err = PTR_ERR(skb); goto error; } @@ -1042,7 +1053,7 @@ static struct sk_buff *handle_offloads(struct sk_buff *skb, nskb = skb_gso_segment(skb, 0); kfree_skb(skb); - if (unlikely(IS_ERR(nskb))) { + if (IS_ERR(nskb)) { err = PTR_ERR(nskb); goto error; } @@ -1050,7 +1061,7 @@ static struct sk_buff *handle_offloads(struct sk_buff *skb, skb = nskb; } else { skb = check_headroom(skb, min_headroom); - if (unlikely(IS_ERR(skb))) { + if (IS_ERR(skb)) { err = PTR_ERR(skb); goto error; } @@ -1188,7 +1199,7 @@ int tnl_send(struct vport *vport, struct sk_buff *skb) /* Offloading */ skb = handle_offloads(skb, mutable, rt); - if (unlikely(IS_ERR(skb))) + if (IS_ERR(skb)) goto error; /* MTU */ @@ -1300,15 +1311,14 @@ out: return sent_len; } -static int set_config(const void __user *uconfig, const struct tnl_ops *tnl_ops, +static int set_config(const void *config, const struct tnl_ops *tnl_ops, const struct vport *cur_vport, struct tnl_mutable_config *mutable) { const struct vport *old_vport; const struct tnl_mutable_config *old_mutable; - if (copy_from_user(&mutable->port_config, uconfig, sizeof(struct tnl_port_config))) - return -EFAULT; + mutable->port_config = *(struct tnl_port_config *)config; if (mutable->port_config.daddr == 0) return -EINVAL; @@ -1353,7 +1363,7 @@ struct vport *tnl_create(const struct vport_parms *parms, int initial_frag_id; int err; - vport = vport_alloc(sizeof(struct tnl_vport), vport_ops); + vport = vport_alloc(sizeof(struct tnl_vport), vport_ops, parms); if (IS_ERR(vport)) { err = PTR_ERR(vport); goto error; @@ -1401,7 +1411,7 @@ error: return ERR_PTR(err); } -int tnl_modify(struct vport *vport, const void __user *config) +int tnl_modify(struct vport *vport, struct odp_port *port) { struct tnl_vport *tnl_vport = tnl_vport_priv(vport); struct tnl_mutable_config *mutable; @@ -1413,7 +1423,7 @@ int tnl_modify(struct vport *vport, const void __user *config) goto error; } - err = set_config(config, tnl_vport->tnl_ops, vport, mutable); + err = set_config(port->config, tnl_vport->tnl_ops, vport, mutable); if (err) goto error_free;