From 48cecbdc39ccf29e7ea98a348cd2f4664272500b Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Tue, 22 Jan 2013 19:38:32 -0800 Subject: [PATCH] packets: Create global helper is_ip_any(). Used outside of meta-flow in future patches. Signed-off-by: Ethan Jackson --- lib/match.c | 5 ++--- lib/meta-flow.c | 7 ------- lib/odp-util.c | 13 ++++--------- lib/packets.c | 6 ++---- lib/packets.h | 8 +++++++- 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/match.c b/lib/match.c index f1bf63c3f..bedb1a1d2 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 87887a897..e25103d9e 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -760,13 +760,6 @@ mf_is_mask_valid(const struct mf_field *mf, const union mf_value *mask) NOT_REACHED(); } -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) { diff --git a/lib/odp-util.c b/lib/odp-util.c index 96a952301..6767b0855 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 73dfcdc2e..fa7328237 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 7e2d4e991..8dd3ebff2 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -23,13 +23,13 @@ #include #include #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, -- 2.43.0