[ovs-dev] [PATCH 1/2] datapath: Rearrange struct sw_flow_key to put optional information last.

Andrew Evans aevans at nicira.com
Wed Apr 27 01:21:33 UTC 2011


On Tue, 2011-04-26 at 16:53 -0700, Andrew Evans wrote:
> Ok. I'm inclined to put all the neighbor-discovery-related stuff into a
> struct, i.e.:

Here's an incremental patch that does this (plus the other changes you suggested):
---
index 558ed19..d7a9bce 100644
--- a/datapath/flow.c
+++ b/datapath/flow.c
@@ -330,7 +330,7 @@ static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
 			return -ENOMEM;
 
 		nd = (struct nd_msg *)skb_transport_header(skb);
-		ipv6_addr_copy(&key->ipv6.nd_target, &nd->target);
+		ipv6_addr_copy(&key->ipv6.nd.target, &nd->target);
 
 		icmp_len -= sizeof(*nd);
 		offset = 0;
@@ -347,15 +347,15 @@ static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
 			 */
 			if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LL_ADDR
 			    && opt_len == 8) {
-				if (unlikely(!is_zero_ether_addr(key->ipv6.nd_sha)))
+				if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll)))
 					goto invalid;
-				memcpy(key->ipv6.nd_sha,
+				memcpy(key->ipv6.nd.sll,
 				    &nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
 			} else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LL_ADDR
 				   && opt_len == 8) {
-				if (unlikely(!is_zero_ether_addr(key->ipv6.nd_tha)))
+				if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll)))
 					goto invalid;
-				memcpy(key->ipv6.nd_tha,
+				memcpy(key->ipv6.nd.tll,
 				    &nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
 			}
 
@@ -367,9 +367,9 @@ static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
 	return 0;
 
 invalid:
-	memset(&key->ipv6.nd_target, 0, sizeof(key->ipv6.nd_target));
-	memset(key->ipv6.nd_sha, 0, sizeof(key->ipv6.nd_sha));
-	memset(key->ipv6.nd_tha, 0, sizeof(key->ipv6.nd_tha));
+	memset(&key->ipv6.nd.target, 0, sizeof(key->ipv6.nd.target));
+	memset(key->ipv6.nd.sll, 0, sizeof(key->ipv6.nd.sll));
+	memset(key->ipv6.nd.tll, 0, sizeof(key->ipv6.nd.tll));
 
 	return 0;
 }
@@ -751,10 +751,10 @@ int flow_from_nlattrs(struct sw_flow_key *swkey, const struct nlattr *attr)
 			    && swkey->ipv6.tp.src != htons(NDISC_NEIGHBOUR_ADVERTISEMENT))
 				return -EINVAL;
 			nd_key = nla_data(nla);
-			memcpy(&swkey->ipv6.nd_target, nd_key->nd_target,
-					sizeof(swkey->ipv6.nd_target));
-			memcpy(swkey->ipv6.nd_sha, nd_key->nd_sll, ETH_ALEN);
-			memcpy(swkey->ipv6.nd_tha, nd_key->nd_tll, ETH_ALEN);
+			memcpy(&swkey->ipv6.nd.target, nd_key->nd_target,
+					sizeof(swkey->ipv6.nd.target));
+			memcpy(swkey->ipv6.nd.sll, nd_key->nd_sll, ETH_ALEN);
+			memcpy(swkey->ipv6.nd.tll, nd_key->nd_tll, ETH_ALEN);
 			break;
 
 		default:
@@ -953,10 +953,10 @@ int flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb)
 				if (!nla)
 					goto nla_put_failure;
 				nd_key = nla_data(nla);
-				memcpy(nd_key->nd_target, &swkey->ipv6.nd_target,
+				memcpy(nd_key->nd_target, &swkey->ipv6.nd.target,
 							sizeof(nd_key->nd_target));
-				memcpy(nd_key->nd_sll, swkey->ipv6.nd_sha, ETH_ALEN);
-				memcpy(nd_key->nd_tll, swkey->ipv6.nd_tha, ETH_ALEN);
+				memcpy(nd_key->nd_sll, swkey->ipv6.nd.sll, ETH_ALEN);
+				memcpy(nd_key->nd_tll, swkey->ipv6.nd.tll, ETH_ALEN);
 			}
 		}
 	}
diff --git a/datapath/flow.h b/datapath/flow.h
index a7c1f69..4d903cb 100644
--- a/datapath/flow.h
+++ b/datapath/flow.h
@@ -48,31 +48,26 @@ struct sw_flow_key {
 			union {
 				struct {
 					__be16 src; /* TCP/UDP source port. */
-					__be16 dst; /* TCP/UDP destination
-						       port. */
+					__be16 dst; /* TCP/UDP destination port. */
 				} tp;
 				struct {
-					u8 sha[ETH_ALEN]; /* ARP source hardware
-							     address. */
-					u8 tha[ETH_ALEN]; /* ARP target hardware
-							     address. */
+					u8 sha[ETH_ALEN]; /* ARP source hardware address. */
+					u8 tha[ETH_ALEN]; /* ARP target hardware address. */
 				} arp;
 			};
 		} ipv4;
 		struct {
 			struct in6_addr src; /* IPv6 source address. */
 			struct in6_addr dst; /* IPv6 destination address. */
-			union {
-				struct {
-					__be16 src; /* TCP/UDP source port. */
-					__be16 dst; /* TCP/UDP destination port.
-						     */
-				} tp;
-				struct in6_addr nd_target; /* ND target address.
-							    */
-			};
-			u8 nd_sha[ETH_ALEN]; /* ND source hardware address. */
-			u8 nd_tha[ETH_ALEN]; /* ND target hardware address. */
+			struct {
+				__be16 src; /* TCP/UDP source port. */
+				__be16 dst; /* TCP/UDP destination port. */
+			} tp;
+			struct {
+				struct in6_addr target; /* ND target address. */
+				u8 sll[ETH_ALEN]; /* ND source link layer address. */
+				u8 tll[ETH_ALEN]; /* ND target link layer address. */
+			} nd;
 		} ipv6;
 	};
 };





More information about the dev mailing list