2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-04 08:15:25 +00:00

flow: New function is_nd().

This simplifies a few pieces of code and will acquire another user in an
upcoming commit.

Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Ben Pfaff
2016-07-02 11:35:29 -07:00
parent 59ae5a6e4e
commit c17fcc0aed
5 changed files with 28 additions and 22 deletions

View File

@@ -18,6 +18,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/icmp6.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@@ -856,6 +857,26 @@ static inline bool is_icmpv6(const struct flow *flow,
return false; return false;
} }
static inline bool is_nd(const struct flow *flow,
struct flow_wildcards *wc)
{
if (is_icmpv6(flow, wc)) {
if (wc) {
memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
}
if (flow->tp_dst != htons(0)) {
return false;
}
if (wc) {
memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
}
return (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
flow->tp_src == htons(ND_NEIGHBOR_ADVERT));
}
return false;
}
static inline bool is_igmp(const struct flow *flow, struct flow_wildcards *wc) static inline bool is_igmp(const struct flow *flow, struct flow_wildcards *wc)
{ {
if (flow->dl_type == htons(ETH_TYPE_IP)) { if (flow->dl_type == htons(ETH_TYPE_IP)) {

View File

@@ -398,18 +398,11 @@ mf_are_prereqs_ok(const struct mf_field *mf, const struct flow *flow)
return is_icmpv6(flow, NULL); return is_icmpv6(flow, NULL);
case MFP_ND: case MFP_ND:
return (is_icmpv6(flow, NULL) return is_nd(flow, NULL);
&& flow->tp_dst == htons(0)
&& (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
flow->tp_src == htons(ND_NEIGHBOR_ADVERT)));
case MFP_ND_SOLICIT: case MFP_ND_SOLICIT:
return (is_icmpv6(flow, NULL) return is_nd(flow, NULL) && flow->tp_src == htons(ND_NEIGHBOR_SOLICIT);
&& flow->tp_dst == htons(0)
&& (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)));
case MFP_ND_ADVERT: case MFP_ND_ADVERT:
return (is_icmpv6(flow, NULL) return is_nd(flow, NULL) && flow->tp_src == htons(ND_NEIGHBOR_ADVERT);
&& flow->tp_dst == htons(0)
&& (flow->tp_src == htons(ND_NEIGHBOR_ADVERT)));
} }
OVS_NOT_REACHED(); OVS_NOT_REACHED();

View File

@@ -879,8 +879,7 @@ nxm_put_ip(struct ofpbuf *b, const struct match *match, enum ofp_version oxm)
nxm_put_8(b, MFF_ICMPV6_CODE, oxm, nxm_put_8(b, MFF_ICMPV6_CODE, oxm,
ntohs(flow->tp_dst)); ntohs(flow->tp_dst));
} }
if (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) || if (is_nd(flow, NULL)) {
flow->tp_src == htons(ND_NEIGHBOR_ADVERT)) {
nxm_put_ipv6(b, MFF_ND_TARGET, oxm, nxm_put_ipv6(b, MFF_ND_TARGET, oxm,
&flow->nd_target, &match->wc.masks.nd_target); &flow->nd_target, &match->wc.masks.nd_target);
if (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)) { if (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)) {

View File

@@ -4420,9 +4420,7 @@ odp_flow_key_from_flow__(const struct odp_flow_key_parms *parms,
icmpv6_key->icmpv6_type = ntohs(data->tp_src); icmpv6_key->icmpv6_type = ntohs(data->tp_src);
icmpv6_key->icmpv6_code = ntohs(data->tp_dst); icmpv6_key->icmpv6_code = ntohs(data->tp_dst);
if (flow->tp_dst == htons(0) if (is_nd(flow, NULL)
&& (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)
|| flow->tp_src == htons(ND_NEIGHBOR_ADVERT))
/* Even though 'tp_src' and 'tp_dst' are 16 bits wide, ICMP /* Even though 'tp_src' and 'tp_dst' are 16 bits wide, ICMP
* type and code are 8 bits wide. Therefore, an exact match * type and code are 8 bits wide. Therefore, an exact match
* looks like htons(0xff), not htons(0xffff). See * looks like htons(0xff), not htons(0xffff). See
@@ -4957,9 +4955,7 @@ parse_l2_5_onward(const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1],
flow->tp_src = htons(icmpv6_key->icmpv6_type); flow->tp_src = htons(icmpv6_key->icmpv6_type);
flow->tp_dst = htons(icmpv6_key->icmpv6_code); flow->tp_dst = htons(icmpv6_key->icmpv6_code);
expected_bit = OVS_KEY_ATTR_ICMPV6; expected_bit = OVS_KEY_ATTR_ICMPV6;
if (src_flow->tp_dst == htons(0) && if (is_nd(src_flow, NULL)) {
(src_flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
src_flow->tp_src == htons(ND_NEIGHBOR_ADVERT))) {
if (!is_mask) { if (!is_mask) {
expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ND; expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ND;
} }

View File

@@ -170,10 +170,7 @@ static int
tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc, tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc,
const char name[IFNAMSIZ]) const char name[IFNAMSIZ])
{ {
if (flow->dl_type != htons(ETH_TYPE_IPV6) || if (!is_nd(flow, NULL) || flow->tp_src != htons(ND_NEIGHBOR_ADVERT)) {
flow->nw_proto != IPPROTO_ICMPV6 ||
flow->tp_dst != htons(0) ||
flow->tp_src != htons(ND_NEIGHBOR_ADVERT)) {
return EINVAL; return EINVAL;
} }
/* - RFC4861 says Neighbor Advertisements sent in response to unicast Neighbor /* - RFC4861 says Neighbor Advertisements sent in response to unicast Neighbor