aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2013-01-22 19:38:32 -0800
committerEthan Jackson <ethan@nicira.com>2013-01-28 19:09:58 -0800
commit48cecbdc39ccf29e7ea98a348cd2f4664272500b (patch)
tree5086b26deffb8d3191f13116932c1e59c58c5651
parentadd90f6f205a65c2569bb240683c0a70cc249c6b (diff)
packets: Create global helper is_ip_any().
Used outside of meta-flow in future patches. Signed-off-by: Ethan Jackson <ethan@nicira.com>
-rw-r--r--lib/match.c5
-rw-r--r--lib/meta-flow.c7
-rw-r--r--lib/odp-util.c13
-rw-r--r--lib/packets.c6
-rw-r--r--lib/packets.h8
5 files changed, 15 insertions, 24 deletions
diff --git a/lib/match.c b/lib/match.c
index f1bf63c3..bedb1a1d 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,8 +106,7 @@ match_wc_init(struct match *match, const struct flow *flow)
memset(&wc->masks.arp_tha, 0xff, sizeof wc->masks.arp_tha);
}
- if (flow->dl_type == htons(ETH_TYPE_IPV6) ||
- flow->dl_type == htons(ETH_TYPE_IP)) {
+ if (is_ip_any(flow)) {
memset(&wc->masks.nw_tos, 0xff, sizeof wc->masks.nw_tos);
memset(&wc->masks.nw_ttl, 0xff, sizeof wc->masks.nw_ttl);
}
diff --git a/lib/meta-flow.c b/lib/meta-flow.c
index 87887a89..e25103d9 100644
--- a/lib/meta-flow.c
+++ b/lib/meta-flow.c
@@ -761,13 +761,6 @@ mf_is_mask_valid(const struct mf_field *mf, const union mf_value *mask)
}
static bool
-is_ip_any(const struct flow *flow)
-{
- return (flow->dl_type == htons(ETH_TYPE_IP) ||
- flow->dl_type == htons(ETH_TYPE_IPV6));
-}
-
-static bool
is_icmpv4(const struct flow *flow)
{
return (flow->dl_type == htons(ETH_TYPE_IP)
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 96a95230..6767b085 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1526,10 +1526,7 @@ odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow,
memcpy(arp_key->arp_tha, flow->arp_tha, ETH_ADDR_LEN);
}
- if ((flow->dl_type == htons(ETH_TYPE_IP)
- || flow->dl_type == htons(ETH_TYPE_IPV6))
- && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
-
+ if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
if (flow->nw_proto == IPPROTO_TCP) {
struct ovs_key_tcp *tcp_key;
@@ -1790,8 +1787,7 @@ parse_l3_onward(const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1],
}
if (flow->nw_proto == IPPROTO_TCP
- && (flow->dl_type == htons(ETH_TYPE_IP) ||
- flow->dl_type == htons(ETH_TYPE_IPV6))
+ && is_ip_any(flow)
&& !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_TCP;
if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_TCP)) {
@@ -1802,8 +1798,7 @@ parse_l3_onward(const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1],
flow->tp_dst = tcp_key->tcp_dst;
}
} else if (flow->nw_proto == IPPROTO_UDP
- && (flow->dl_type == htons(ETH_TYPE_IP) ||
- flow->dl_type == htons(ETH_TYPE_IPV6))
+ && is_ip_any(flow)
&& !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_UDP;
if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_UDP)) {
diff --git a/lib/packets.c b/lib/packets.c
index 73dfcdc2..fa732823 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -710,9 +710,7 @@ packet_set_udp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
uint8_t
packet_get_tcp_flags(const struct ofpbuf *packet, const struct flow *flow)
{
- if ((flow->dl_type == htons(ETH_TYPE_IP) ||
- flow->dl_type == htons(ETH_TYPE_IPV6)) &&
- flow->nw_proto == IPPROTO_TCP && packet->l7) {
+ if (is_ip_any(flow) && flow->nw_proto == IPPROTO_TCP && packet->l7) {
const struct tcp_header *tcp = packet->l4;
return TCP_FLAGS(tcp->tcp_ctl);
} else {
diff --git a/lib/packets.h b/lib/packets.h
index 7e2d4e99..8dd3ebff 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -23,13 +23,13 @@
#include <stdint.h>
#include <string.h>
#include "compiler.h"
+#include "flow.h"
#include "openvswitch/types.h"
#include "random.h"
#include "util.h"
struct ofpbuf;
struct ds;
-struct flow;
bool dpid_from_string(const char *s, uint64_t *dpidp);
@@ -468,6 +468,12 @@ static inline bool ipv6_mask_is_exact(const struct in6_addr *mask) {
return ipv6_addr_equals(mask, &in6addr_exact);
}
+static inline bool is_ip_any(const struct flow *flow)
+{
+ return flow->dl_type == htons(ETH_TYPE_IP)
+ || flow->dl_type == htons(ETH_TYPE_IPV6);
+}
+
void format_ipv6_addr(char *addr_str, const struct in6_addr *addr);
void print_ipv6_addr(struct ds *string, const struct in6_addr *addr);
void print_ipv6_masked(struct ds *string, const struct in6_addr *addr,