X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fmeta-flow.c;h=6ef564e2b6d89516fde66ec1450f185f6c610e10;hb=HEAD;hp=69d5140393d1b9406820dcf64af1e5e3756a036c;hpb=216a32dd505cc56bb88bf7b79541dc4a37ba8d2d;p=sliver-openvswitch.git diff --git a/lib/meta-flow.c b/lib/meta-flow.c index 69d514039..6ef564e2b 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -37,17 +37,46 @@ VLOG_DEFINE_THIS_MODULE(meta_flow); +#define FLOW_U32OFS(FIELD) \ + offsetof(struct flow, FIELD) % 4 ? -1 : offsetof(struct flow, FIELD) / 4 + #define MF_FIELD_SIZES(MEMBER) \ sizeof ((union mf_value *)0)->MEMBER, \ 8 * sizeof ((union mf_value *)0)->MEMBER -static const struct mf_field mf_fields[MFF_N_IDS] = { +extern const struct mf_field mf_fields[MFF_N_IDS]; /* Silence a warning. */ + +const struct mf_field mf_fields[MFF_N_IDS] = { /* ## -------- ## */ /* ## metadata ## */ /* ## -------- ## */ { - MFF_TUN_ID, "tun_id", NULL, + MFF_DP_HASH, "dp_hash", NULL, + MF_FIELD_SIZES(be32), + MFM_FULLY, + MFS_HEXADECIMAL, + MFP_NONE, + false, + NXM_NX_DP_HASH, "NXM_NX_DP_HASH", + NXM_NX_DP_HASH, "NXM_NX_DP_HASH", + OFPUTIL_P_NXM_OXM_ANY, + OFPUTIL_P_NXM_OXM_ANY, + -1, + }, { + MFF_RECIRC_ID, "recirc_id", NULL, + MF_FIELD_SIZES(be32), + MFM_NONE, + MFS_DECIMAL, + MFP_NONE, + false, + NXM_NX_RECIRC_ID, "NXM_NX_RECIRC_ID", + NXM_NX_RECIRC_ID, "NXM_NX_RECIRC_ID", + OFPUTIL_P_NXM_OXM_ANY, + OFPUTIL_P_NXM_OXM_ANY, + -1, + }, { + MFF_TUN_ID, "tun_id", "tunnel_id", MF_FIELD_SIZES(be64), MFM_FULLY, MFS_HEXADECIMAL, @@ -57,6 +86,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_TUNNEL_ID, "OXM_OF_TUNNEL_ID", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + FLOW_U32OFS(tunnel.tun_id), }, { MFF_TUN_SRC, "tun_src", NULL, MF_FIELD_SIZES(be32), @@ -68,6 +98,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_NX_TUN_IPV4_SRC, "NXM_NX_TUN_IPV4_SRC", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + FLOW_U32OFS(tunnel.ip_src), }, { MFF_TUN_DST, "tun_dst", NULL, MF_FIELD_SIZES(be32), @@ -79,6 +110,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_NX_TUN_IPV4_DST, "NXM_NX_TUN_IPV4_DST", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + FLOW_U32OFS(tunnel.ip_dst), }, { MFF_TUN_FLAGS, "tun_flags", NULL, MF_FIELD_SIZES(be16), @@ -90,6 +122,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { 0, NULL, OFPUTIL_P_NONE, OFPUTIL_P_NONE, + -1, }, { MFF_TUN_TTL, "tun_ttl", NULL, MF_FIELD_SIZES(u8), @@ -101,6 +134,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { 0, NULL, OFPUTIL_P_NONE, OFPUTIL_P_NONE, + -1, }, { MFF_TUN_TOS, "tun_tos", NULL, MF_FIELD_SIZES(u8), @@ -112,6 +146,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { 0, NULL, OFPUTIL_P_NONE, OFPUTIL_P_NONE, + -1, }, { MFF_METADATA, "metadata", NULL, MF_FIELD_SIZES(be64), @@ -123,6 +158,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_METADATA, "OXM_OF_METADATA", OFPUTIL_P_NXM_OF11_UP, OFPUTIL_P_NXM_OF11_UP, + -1, }, { MFF_IN_PORT, "in_port", NULL, MF_FIELD_SIZES(be16), @@ -134,6 +170,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_OF_IN_PORT, "NXM_OF_IN_PORT", OFPUTIL_P_ANY, /* OF11+ via mapping to 32 bits. */ OFPUTIL_P_NONE, + -1, }, { MFF_IN_PORT_OXM, "in_port_oxm", NULL, MF_FIELD_SIZES(be32), @@ -145,6 +182,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IN_PORT, "OXM_OF_IN_PORT", OFPUTIL_P_OF11_UP, OFPUTIL_P_NONE, + -1, }, { MFF_SKB_PRIORITY, "skb_priority", NULL, MF_FIELD_SIZES(be32), @@ -156,6 +194,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { 0, NULL, OFPUTIL_P_NONE, OFPUTIL_P_NONE, + -1, }, { MFF_PKT_MARK, "pkt_mark", NULL, MF_FIELD_SIZES(be32), @@ -167,6 +206,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_NX_PKT_MARK, "NXM_NX_PKT_MARK", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, #define REGISTER(IDX) \ @@ -181,6 +221,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_NX_REG(IDX), "NXM_NX_REG" #IDX, \ OFPUTIL_P_NXM_OXM_ANY, \ OFPUTIL_P_NXM_OXM_ANY, \ + -1, \ } #if FLOW_N_REGS > 0 REGISTER(0), @@ -225,6 +266,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ETH_SRC, "OXM_OF_ETH_SRC", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OF11_UP, /* Bitwise masking only with NXM and OF11+! */ + -1, }, { MFF_ETH_DST, "eth_dst", "dl_dst", MF_FIELD_SIZES(mac), @@ -236,6 +278,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ETH_DST, "OXM_OF_ETH_DST", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OF11_UP, /* Bitwise masking only with NXM and OF11+! */ + -1, }, { MFF_ETH_TYPE, "eth_type", "dl_type", MF_FIELD_SIZES(be16), @@ -247,6 +290,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ETH_TYPE, "OXM_OF_ETH_TYPE", OFPUTIL_P_ANY, OFPUTIL_P_NONE, + -1, }, { @@ -260,6 +304,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_OF_VLAN_TCI, "NXM_OF_VLAN_TCI", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_DL_VLAN, "dl_vlan", NULL, sizeof(ovs_be16), 12, @@ -271,6 +316,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { 0, NULL, OFPUTIL_P_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_VLAN_VID, "vlan_vid", NULL, sizeof(ovs_be16), 12, @@ -282,6 +328,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_VLAN_VID, "OXM_OF_VLAN_VID", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_DL_VLAN_PCP, "dl_vlan_pcp", NULL, 1, 3, @@ -293,6 +340,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { 0, NULL, OFPUTIL_P_ANY, /* Will be mapped to NXM and OXM. */ OFPUTIL_P_NONE, + -1, }, { MFF_VLAN_PCP, "vlan_pcp", NULL, 1, 3, @@ -304,6 +352,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_VLAN_PCP, "OXM_OF_VLAN_PCP", OFPUTIL_P_ANY, /* Will be mapped to OF10 and NXM. */ OFPUTIL_P_NONE, + -1, }, /* ## ---- ## */ @@ -320,6 +369,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_MPLS_LABEL, "OXM_OF_MPLS_LABEL", OFPUTIL_P_NXM_OF11_UP, OFPUTIL_P_NONE, + -1, }, { MFF_MPLS_TC, "mpls_tc", NULL, 1, 3, @@ -331,6 +381,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_MPLS_TC, "OXM_OF_MPLS_TC", OFPUTIL_P_NXM_OF11_UP, OFPUTIL_P_NONE, + -1, }, { MFF_MPLS_BOS, "mpls_bos", NULL, 1, 1, @@ -342,6 +393,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_MPLS_BOS, "OXM_OF_MPLS_BOS", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NONE, + -1, }, /* ## -- ## */ @@ -359,6 +411,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV4_SRC, "OXM_OF_IPV4_SRC", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OF11_UP, + FLOW_U32OFS(nw_src), }, { MFF_IPV4_DST, "ip_dst", "nw_dst", MF_FIELD_SIZES(be32), @@ -370,6 +423,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV4_DST, "OXM_OF_IPV4_DST", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OF11_UP, + FLOW_U32OFS(nw_dst), }, { @@ -383,6 +437,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV6_SRC, "OXM_OF_IPV6_SRC", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + FLOW_U32OFS(ipv6_src), }, { MFF_IPV6_DST, "ipv6_dst", NULL, MF_FIELD_SIZES(ipv6), @@ -394,6 +449,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV6_DST, "OXM_OF_IPV6_DST", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + FLOW_U32OFS(ipv6_dst), }, { MFF_IPV6_LABEL, "ipv6_label", NULL, @@ -406,10 +462,11 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV6_FLABEL, "OXM_OF_IPV6_FLABEL", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { - MFF_IP_PROTO, "nw_proto", NULL, + MFF_IP_PROTO, "nw_proto", "ip_proto", MF_FIELD_SIZES(u8), MFM_NONE, MFS_DECIMAL, @@ -419,6 +476,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IP_PROTO, "OXM_OF_IP_PROTO", OFPUTIL_P_ANY, OFPUTIL_P_NONE, + -1, }, { MFF_IP_DSCP, "nw_tos", NULL, MF_FIELD_SIZES(u8), @@ -430,9 +488,10 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_OF_IP_TOS, "NXM_OF_IP_TOS", OFPUTIL_P_ANY, /* Will be shifted for OXM. */ OFPUTIL_P_NONE, + -1, }, { - MFF_IP_DSCP_SHIFTED, "nw_tos_shifted", NULL, - MF_FIELD_SIZES(u8), + MFF_IP_DSCP_SHIFTED, "ip_dscp", NULL, + 1, 6, MFM_NONE, MFS_DECIMAL, MFP_IP_ANY, @@ -441,8 +500,9 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IP_DSCP, "OXM_OF_IP_DSCP", OFPUTIL_P_ANY, /* Will be shifted for non-OXM. */ OFPUTIL_P_NONE, + -1, }, { - MFF_IP_ECN, "nw_ecn", NULL, + MFF_IP_ECN, "nw_ecn", "ip_ecn", 1, 2, MFM_NONE, MFS_DECIMAL, @@ -452,6 +512,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IP_ECN, "OXM_OF_IP_ECN", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NONE, + -1, }, { MFF_IP_TTL, "nw_ttl", NULL, MF_FIELD_SIZES(u8), @@ -463,6 +524,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_NX_IP_TTL, "NXM_NX_IP_TTL", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NONE, + -1, }, { MFF_IP_FRAG, "ip_frag", NULL, 1, 2, @@ -474,6 +536,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { NXM_NX_IP_FRAG, "NXM_NX_IP_FRAG", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { @@ -487,6 +550,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ARP_OP, "OXM_OF_ARP_OP", OFPUTIL_P_ANY, OFPUTIL_P_NONE, + -1, }, { MFF_ARP_SPA, "arp_spa", NULL, MF_FIELD_SIZES(be32), @@ -498,6 +562,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ARP_SPA, "OXM_OF_ARP_SPA", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OF11_UP, + -1, }, { MFF_ARP_TPA, "arp_tpa", NULL, MF_FIELD_SIZES(be32), @@ -509,6 +574,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ARP_TPA, "OXM_OF_ARP_TPA", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OF11_UP, + -1, }, { MFF_ARP_SHA, "arp_sha", NULL, MF_FIELD_SIZES(mac), @@ -520,6 +586,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ARP_SHA, "OXM_OF_ARP_SHA", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_ARP_THA, "arp_tha", NULL, MF_FIELD_SIZES(mac), @@ -531,6 +598,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ARP_THA, "OXM_OF_ARP_THA", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, /* ## -- ## */ @@ -548,6 +616,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_TCP_SRC, "OXM_OF_TCP_SRC", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_TCP_DST, "tcp_dst", "tp_dst", MF_FIELD_SIZES(be16), @@ -559,6 +628,19 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_TCP_DST, "OXM_OF_TCP_DST", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, + }, { + MFF_TCP_FLAGS, "tcp_flags", NULL, + 2, 12, + MFM_FULLY, + MFS_TCP_FLAGS, + MFP_TCP, + false, + NXM_NX_TCP_FLAGS, "NXM_NX_TCP_FLAGS", + NXM_NX_TCP_FLAGS, "NXM_NX_TCP_FLAGS", + OFPUTIL_P_NXM_OXM_ANY, + OFPUTIL_P_NXM_OXM_ANY, + -1, }, { @@ -572,6 +654,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_UDP_SRC, "OXM_OF_UDP_SRC", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_UDP_DST, "udp_dst", NULL, MF_FIELD_SIZES(be16), @@ -583,6 +666,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_UDP_DST, "OXM_OF_UDP_DST", OFPUTIL_P_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { @@ -596,6 +680,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_SCTP_SRC, "OXM_OF_SCTP_SRC", OFPUTIL_P_NXM_OF11_UP, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_SCTP_DST, "sctp_dst", NULL, MF_FIELD_SIZES(be16), @@ -607,6 +692,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_SCTP_DST, "OXM_OF_SCTP_DST", OFPUTIL_P_NXM_OF11_UP, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { @@ -620,6 +706,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ICMPV4_TYPE, "OXM_OF_ICMPV4_TYPE", OFPUTIL_P_ANY, OFPUTIL_P_NONE, + -1, }, { MFF_ICMPV4_CODE, "icmp_code", NULL, MF_FIELD_SIZES(u8), @@ -631,6 +718,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ICMPV4_CODE, "OXM_OF_ICMPV4_CODE", OFPUTIL_P_ANY, OFPUTIL_P_NONE, + -1, }, { @@ -644,6 +732,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ICMPV6_TYPE, "OXM_OF_ICMPV6_TYPE", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NONE, + -1, }, { MFF_ICMPV6_CODE, "icmpv6_code", NULL, MF_FIELD_SIZES(u8), @@ -655,6 +744,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_ICMPV6_CODE, "OXM_OF_ICMPV6_CODE", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NONE, + -1, }, /* ## ---- ## */ @@ -672,6 +762,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV6_ND_TARGET, "OXM_OF_IPV6_ND_TARGET", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_ND_SLL, "nd_sll", NULL, MF_FIELD_SIZES(mac), @@ -683,6 +774,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV6_ND_SLL, "OXM_OF_IPV6_ND_SLL", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, }, { MFF_ND_TLL, "nd_tll", NULL, MF_FIELD_SIZES(mac), @@ -694,6 +786,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { OXM_OF_IPV6_ND_TLL, "OXM_OF_IPV6_ND_TLL", OFPUTIL_P_NXM_OXM_ANY, OFPUTIL_P_NXM_OXM_ANY, + -1, } }; @@ -717,14 +810,6 @@ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); const struct mf_field *mf_from_nxm_header__(uint32_t header); static void nxm_init(void); -/* Returns the field with the given 'id'. */ -const struct mf_field * -mf_from_id(enum mf_field_id id) -{ - ovs_assert((unsigned int) id < MFF_N_IDS); - return &mf_fields[id]; -} - /* Returns the field with the given 'name', or a null pointer if no field has * that name. */ const struct mf_field * @@ -818,6 +903,10 @@ bool mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) { switch (mf->id) { + case MFF_DP_HASH: + return !wc->masks.dp_hash; + case MFF_RECIRC_ID: + return !wc->masks.recirc_id; case MFF_TUN_SRC: return !wc->masks.tunnel.ip_src; case MFF_TUN_DST: @@ -865,11 +954,11 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) return !(wc->masks.vlan_tci & htons(VLAN_PCP_MASK)); case MFF_MPLS_LABEL: - return !(wc->masks.mpls_lse & htonl(MPLS_LABEL_MASK)); + return !(wc->masks.mpls_lse[0] & htonl(MPLS_LABEL_MASK)); case MFF_MPLS_TC: - return !(wc->masks.mpls_lse & htonl(MPLS_TC_MASK)); + return !(wc->masks.mpls_lse[1] & htonl(MPLS_TC_MASK)); case MFF_MPLS_BOS: - return !(wc->masks.mpls_lse & htonl(MPLS_BOS_MASK)); + return !(wc->masks.mpls_lse[2] & htonl(MPLS_BOS_MASK)); case MFF_IPV4_SRC: return !wc->masks.nw_src; @@ -919,10 +1008,12 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_ICMPV4_CODE: case MFF_ICMPV6_CODE: return !wc->masks.tp_dst; + case MFF_TCP_FLAGS: + return !wc->masks.tcp_flags; case MFF_N_IDS: default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -953,21 +1044,7 @@ mf_is_mask_valid(const struct mf_field *mf, const union mf_value *mask) return true; } - NOT_REACHED(); -} - -static bool -is_icmpv4(const struct flow *flow) -{ - return (flow->dl_type == htons(ETH_TYPE_IP) - && flow->nw_proto == IPPROTO_ICMP); -} - -static bool -is_icmpv6(const struct flow *flow) -{ - return (flow->dl_type == htons(ETH_TYPE_IPV6) - && flow->nw_proto == IPPROTO_ICMPV6); + OVS_NOT_REACHED(); } /* Returns true if 'flow' meets the prerequisites for 'mf', false otherwise. */ @@ -1018,9 +1095,49 @@ mf_are_prereqs_ok(const struct mf_field *mf, const struct flow *flow) && (flow->tp_src == htons(ND_NEIGHBOR_ADVERT))); } - NOT_REACHED(); + OVS_NOT_REACHED(); +} + +/* Set field and it's prerequisities in the mask. + * This is only ever called for writeable 'mf's, but we do not make the + * distinction here. */ +void +mf_mask_field_and_prereqs(const struct mf_field *mf, struct flow *mask) +{ + static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER; + + mf_set_flow_value(mf, &exact_match_mask, mask); + + switch (mf->prereqs) { + case MFP_ND: + case MFP_ND_SOLICIT: + case MFP_ND_ADVERT: + mask->tp_src = OVS_BE16_MAX; + mask->tp_dst = OVS_BE16_MAX; + /* Fall through. */ + case MFP_TCP: + case MFP_UDP: + case MFP_SCTP: + case MFP_ICMPV4: + case MFP_ICMPV6: + mask->nw_proto = 0xff; + /* Fall through. */ + case MFP_ARP: + case MFP_IPV4: + case MFP_IPV6: + case MFP_MPLS: + case MFP_IP_ANY: + mask->dl_type = OVS_BE16_MAX; + break; + case MFP_VLAN_VID: + mask->vlan_tci |= htons(VLAN_CFI); + break; + case MFP_NONE: + break; + } } + /* Returns true if 'value' may be a valid value *as part of a masked match*, * false otherwise. * @@ -1035,6 +1152,8 @@ bool mf_is_value_valid(const struct mf_field *mf, const union mf_value *value) { switch (mf->id) { + case MFF_DP_HASH: + case MFF_RECIRC_ID: case MFF_TUN_ID: case MFF_TUN_SRC: case MFF_TUN_DST: @@ -1088,6 +1207,8 @@ mf_is_value_valid(const struct mf_field *mf, const union mf_value *value) return !(value->u8 & ~IP_ECN_MASK); case MFF_IP_FRAG: return !(value->u8 & ~FLOW_NW_FRAG_MASK); + case MFF_TCP_FLAGS: + return !(value->be16 & ~htons(0x0fff)); case MFF_ARP_OP: return !(value->be16 & htons(0xff00)); @@ -1115,7 +1236,7 @@ mf_is_value_valid(const struct mf_field *mf, const union mf_value *value) case MFF_N_IDS: default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -1126,6 +1247,12 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow, union mf_value *value) { switch (mf->id) { + case MFF_DP_HASH: + value->be32 = htonl(flow->dp_hash); + break; + case MFF_RECIRC_ID: + value->be32 = htonl(flow->recirc_id); + break; case MFF_TUN_ID: value->be64 = flow->tunnel.tun_id; break; @@ -1197,15 +1324,15 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow, break; case MFF_MPLS_LABEL: - value->be32 = htonl(mpls_lse_to_label(flow->mpls_lse)); + value->be32 = htonl(mpls_lse_to_label(flow->mpls_lse[0])); break; case MFF_MPLS_TC: - value->u8 = mpls_lse_to_tc(flow->mpls_lse); + value->u8 = mpls_lse_to_tc(flow->mpls_lse[0]); break; case MFF_MPLS_BOS: - value->u8 = mpls_lse_to_bos(flow->mpls_lse); + value->u8 = mpls_lse_to_bos(flow->mpls_lse[0]); break; case MFF_IPV4_SRC: @@ -1286,6 +1413,10 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow, value->be16 = flow->tp_dst; break; + case MFF_TCP_FLAGS: + value->be16 = flow->tcp_flags; + break; + case MFF_ICMPV4_TYPE: case MFF_ICMPV6_TYPE: value->u8 = ntohs(flow->tp_src); @@ -1302,7 +1433,7 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow, case MFF_N_IDS: default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -1314,6 +1445,12 @@ mf_set_value(const struct mf_field *mf, const union mf_value *value, struct match *match) { switch (mf->id) { + case MFF_DP_HASH: + match_set_dp_hash(match, ntohl(value->be32)); + break; + case MFF_RECIRC_ID: + match_set_recirc_id(match, ntohl(value->be32)); + break; case MFF_TUN_ID: match_set_tun_id(match, value->be64); break; @@ -1389,15 +1526,15 @@ mf_set_value(const struct mf_field *mf, break; case MFF_MPLS_LABEL: - match_set_mpls_label(match, value->be32); + match_set_mpls_label(match, 0, value->be32); break; case MFF_MPLS_TC: - match_set_mpls_tc(match, value->u8); + match_set_mpls_tc(match, 0, value->u8); break; case MFF_MPLS_BOS: - match_set_mpls_bos(match, value->u8); + match_set_mpls_bos(match, 0, value->u8); break; case MFF_IPV4_SRC: @@ -1478,6 +1615,10 @@ mf_set_value(const struct mf_field *mf, match_set_tp_dst(match, value->be16); break; + case MFF_TCP_FLAGS: + match_set_tcp_flags(match, value->be16); + break; + case MFF_ICMPV4_TYPE: case MFF_ICMPV6_TYPE: match_set_icmp_type(match, value->u8); @@ -1494,7 +1635,25 @@ mf_set_value(const struct mf_field *mf, case MFF_N_IDS: default: - NOT_REACHED(); + OVS_NOT_REACHED(); + } +} + +/* Unwildcard 'mask' member field described by 'mf'. The caller is + * responsible for ensuring that 'mask' meets 'mf''s prerequisites. */ +void +mf_mask_field(const struct mf_field *mf, struct flow *mask) +{ + static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER; + + /* For MFF_DL_VLAN, we cannot send a all 1's to flow_set_dl_vlan() + * as that will be considered as OFP10_VLAN_NONE. So consider it as a + * special case. For the rest, calling mf_set_flow_value() is good + * enough. */ + if (mf->id == MFF_DL_VLAN) { + flow_set_dl_vlan(mask, htons(VLAN_VID_MASK)); + } else { + mf_set_flow_value(mf, &exact_match_mask, mask); } } @@ -1505,6 +1664,12 @@ mf_set_flow_value(const struct mf_field *mf, const union mf_value *value, struct flow *flow) { switch (mf->id) { + case MFF_DP_HASH: + flow->dp_hash = ntohl(value->be32); + break; + case MFF_RECIRC_ID: + flow->recirc_id = ntohl(value->be32); + break; case MFF_TUN_ID: flow->tunnel.tun_id = value->be64; break; @@ -1580,15 +1745,15 @@ mf_set_flow_value(const struct mf_field *mf, break; case MFF_MPLS_LABEL: - flow_set_mpls_label(flow, value->be32); + flow_set_mpls_label(flow, 0, value->be32); break; case MFF_MPLS_TC: - flow_set_mpls_tc(flow, value->u8); + flow_set_mpls_tc(flow, 0, value->u8); break; case MFF_MPLS_BOS: - flow_set_mpls_bos(flow, value->u8); + flow_set_mpls_bos(flow, 0, value->u8); break; case MFF_IPV4_SRC: @@ -1635,7 +1800,7 @@ mf_set_flow_value(const struct mf_field *mf, break; case MFF_IP_FRAG: - flow->nw_frag &= value->u8; + flow->nw_frag = value->u8 & FLOW_NW_FRAG_MASK; break; case MFF_ARP_OP: @@ -1672,6 +1837,10 @@ mf_set_flow_value(const struct mf_field *mf, flow->tp_dst = value->be16; break; + case MFF_TCP_FLAGS: + flow->tcp_flags = value->be16; + break; + case MFF_ICMPV4_TYPE: case MFF_ICMPV6_TYPE: flow->tp_src = htons(value->u8); @@ -1688,7 +1857,7 @@ mf_set_flow_value(const struct mf_field *mf, case MFF_N_IDS: default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -1713,6 +1882,14 @@ void mf_set_wild(const struct mf_field *mf, struct match *match) { switch (mf->id) { + case MFF_DP_HASH: + match->flow.dp_hash = 0; + match->wc.masks.dp_hash = 0; + break; + case MFF_RECIRC_ID: + match->flow.recirc_id = 0; + match->wc.masks.recirc_id = 0; + break; case MFF_TUN_ID: match_set_tun_id_masked(match, htonll(0), htonll(0)); break; @@ -1786,15 +1963,15 @@ mf_set_wild(const struct mf_field *mf, struct match *match) break; case MFF_MPLS_LABEL: - match_set_any_mpls_label(match); + match_set_any_mpls_label(match, 0); break; case MFF_MPLS_TC: - match_set_any_mpls_tc(match); + match_set_any_mpls_tc(match, 0); break; case MFF_MPLS_BOS: - match_set_any_mpls_bos(match); + match_set_any_mpls_bos(match, 0); break; case MFF_IPV4_SRC: @@ -1883,6 +2060,11 @@ mf_set_wild(const struct mf_field *mf, struct match *match) match->flow.tp_dst = htons(0); break; + case MFF_TCP_FLAGS: + match->wc.masks.tcp_flags = htons(0); + match->flow.tcp_flags = htons(0); + break; + case MFF_ND_TARGET: memset(&match->wc.masks.nd_target, 0, sizeof match->wc.masks.nd_target); @@ -1891,7 +2073,7 @@ mf_set_wild(const struct mf_field *mf, struct match *match) case MFF_N_IDS: default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -1920,6 +2102,7 @@ mf_set(const struct mf_field *mf, } switch (mf->id) { + case MFF_RECIRC_ID: case MFF_IN_PORT: case MFF_IN_PORT_OXM: case MFF_SKB_PRIORITY: @@ -1940,8 +2123,11 @@ mf_set(const struct mf_field *mf, case MFF_ICMPV4_CODE: case MFF_ICMPV6_TYPE: case MFF_ICMPV6_CODE: - NOT_REACHED(); + return OFPUTIL_P_NONE; + case MFF_DP_HASH: + match_set_dp_hash_masked(match, ntohl(value->be32), ntohl(mask->be32)); + break; case MFF_TUN_ID: match_set_tun_id_masked(match, value->be64, mask->be64); break; @@ -2053,9 +2239,13 @@ mf_set(const struct mf_field *mf, match_set_tp_dst_masked(match, value->be16, mask->be16); break; + case MFF_TCP_FLAGS: + match_set_tcp_flags_masked(match, value->be16, mask->be16); + break; + case MFF_N_IDS: default: - NOT_REACHED(); + OVS_NOT_REACHED(); } return mf->usable_protocols_bitwise; @@ -2127,111 +2317,6 @@ mf_get(const struct mf_field *mf, const struct match *match, mf_get_mask(mf, &match->wc, mask); } -/* Assigns a random value for field 'mf' to 'value'. */ -void -mf_random_value(const struct mf_field *mf, union mf_value *value) -{ - random_bytes(value, mf->n_bytes); - - switch (mf->id) { - case MFF_TUN_ID: - case MFF_TUN_SRC: - case MFF_TUN_DST: - case MFF_TUN_TOS: - case MFF_TUN_TTL: - case MFF_TUN_FLAGS: - case MFF_METADATA: - case MFF_IN_PORT: - case MFF_PKT_MARK: - case MFF_SKB_PRIORITY: - CASE_MFF_REGS: - case MFF_ETH_SRC: - case MFF_ETH_DST: - case MFF_ETH_TYPE: - case MFF_VLAN_TCI: - case MFF_IPV4_SRC: - case MFF_IPV4_DST: - case MFF_IPV6_SRC: - case MFF_IPV6_DST: - case MFF_IP_PROTO: - case MFF_IP_TTL: - case MFF_ARP_SPA: - case MFF_ARP_TPA: - case MFF_ARP_SHA: - case MFF_ARP_THA: - case MFF_TCP_SRC: - case MFF_TCP_DST: - case MFF_UDP_SRC: - case MFF_UDP_DST: - case MFF_SCTP_SRC: - case MFF_SCTP_DST: - case MFF_ICMPV4_TYPE: - case MFF_ICMPV4_CODE: - case MFF_ICMPV6_TYPE: - case MFF_ICMPV6_CODE: - case MFF_ND_TARGET: - case MFF_ND_SLL: - case MFF_ND_TLL: - break; - - case MFF_IN_PORT_OXM: - value->be32 = ofputil_port_to_ofp11(u16_to_ofp(ntohs(value->be16))); - break; - - case MFF_IPV6_LABEL: - value->be32 &= htonl(IPV6_LABEL_MASK); - break; - - case MFF_IP_DSCP: - value->u8 &= IP_DSCP_MASK; - break; - - case MFF_IP_DSCP_SHIFTED: - value->u8 &= IP_DSCP_MASK >> 2; - break; - - case MFF_IP_ECN: - value->u8 &= IP_ECN_MASK; - break; - - case MFF_IP_FRAG: - value->u8 &= FLOW_NW_FRAG_MASK; - break; - - case MFF_ARP_OP: - value->be16 &= htons(0xff); - break; - - case MFF_DL_VLAN: - value->be16 &= htons(VLAN_VID_MASK); - break; - case MFF_VLAN_VID: - value->be16 &= htons(VLAN_VID_MASK | VLAN_CFI); - break; - - case MFF_DL_VLAN_PCP: - case MFF_VLAN_PCP: - value->u8 &= 0x07; - break; - - case MFF_MPLS_LABEL: - value->be32 &= htonl(MPLS_LABEL_MASK >> MPLS_LABEL_SHIFT); - break; - - case MFF_MPLS_TC: - value->u8 &= MPLS_TC_MASK >> MPLS_TC_SHIFT; - break; - - case MFF_MPLS_BOS: - value->u8 &= MPLS_BOS_MASK >> MPLS_BOS_SHIFT; - break; - - case MFF_N_IDS: - default: - NOT_REACHED(); - } -} - static char * mf_from_integer_string(const struct mf_field *mf, const char *s, uint8_t *valuep, uint8_t *maskp) @@ -2281,15 +2366,15 @@ mf_from_ethernet_string(const struct mf_field *mf, const char *s, ovs_assert(mf->n_bytes == ETH_ADDR_LEN); n = -1; - if (sscanf(s, ETH_ADDR_SCAN_FMT"%n", ETH_ADDR_SCAN_ARGS(mac), &n) > 0 + if (ovs_scan(s, ETH_ADDR_SCAN_FMT"%n", ETH_ADDR_SCAN_ARGS(mac), &n) && n == strlen(s)) { memset(mask, 0xff, ETH_ADDR_LEN); return NULL; } n = -1; - if (sscanf(s, ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT"%n", - ETH_ADDR_SCAN_ARGS(mac), ETH_ADDR_SCAN_ARGS(mask), &n) > 0 + if (ovs_scan(s, ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT"%n", + ETH_ADDR_SCAN_ARGS(mac), ETH_ADDR_SCAN_ARGS(mask), &n) && n == strlen(s)) { return NULL; } @@ -2305,11 +2390,10 @@ mf_from_ipv4_string(const struct mf_field *mf, const char *s, ovs_assert(mf->n_bytes == sizeof *ip); - if (sscanf(s, IP_SCAN_FMT"/"IP_SCAN_FMT, - IP_SCAN_ARGS(ip), IP_SCAN_ARGS(mask)) == IP_SCAN_COUNT * 2) { + if (ovs_scan(s, IP_SCAN_FMT"/"IP_SCAN_FMT, + IP_SCAN_ARGS(ip), IP_SCAN_ARGS(mask))) { /* OK. */ - } else if (sscanf(s, IP_SCAN_FMT"/%d", - IP_SCAN_ARGS(ip), &prefix) == IP_SCAN_COUNT + 1) { + } else if (ovs_scan(s, IP_SCAN_FMT"/%d", IP_SCAN_ARGS(ip), &prefix)) { if (prefix <= 0 || prefix > 32) { return xasprintf("%s: network prefix bits not between 1 and " "32", s); @@ -2318,7 +2402,7 @@ mf_from_ipv4_string(const struct mf_field *mf, const char *s, } else { *mask = htonl(((1u << prefix) - 1) << (32 - prefix)); } - } else if (sscanf(s, IP_SCAN_FMT, IP_SCAN_ARGS(ip)) == IP_SCAN_COUNT) { + } else if (ovs_scan(s, IP_SCAN_FMT, IP_SCAN_ARGS(ip))) { *mask = OVS_BE32_MAX; } else { return xasprintf("%s: invalid IP address", s); @@ -2456,9 +2540,8 @@ parse_flow_tun_flags(const char *s_, const char *(*bit_to_string)(uint32_t), int name_len; unsigned long long int flags; uint32_t bit; - int n0; - if (sscanf(name, "%lli%n", &flags, &n0) > 0 && n0 > 0) { + if (ovs_scan(name, "%lli", &flags)) { result |= flags; continue; } @@ -2502,15 +2585,92 @@ mf_from_tun_flags_string(const char *s, ovs_be16 *valuep, ovs_be16 *maskp) } return xasprintf("%s: unknown tunnel flags (valid flags are \"df\", " - "\"csum\", \"key\"", s); + "\"csum\", \"key\")", s); } +static char * +mf_from_tcp_flags_string(const char *s, ovs_be16 *flagsp, ovs_be16 *maskp) +{ + uint16_t flags = 0; + uint16_t mask = 0; + uint16_t bit; + int n; + + if (ovs_scan(s, "%"SCNi16"/%"SCNi16"%n", &flags, &mask, &n) && !s[n]) { + *flagsp = htons(flags); + *maskp = htons(mask); + return NULL; + } + if (ovs_scan(s, "%"SCNi16"%n", &flags, &n) && !s[n]) { + *flagsp = htons(flags); + *maskp = OVS_BE16_MAX; + return NULL; + } + + while (*s != '\0') { + bool set; + int name_len; + + switch (*s) { + case '+': + set = true; + break; + case '-': + set = false; + break; + default: + return xasprintf("%s: TCP flag must be preceded by '+' (for SET) " + "or '-' (NOT SET)", s); + } + s++; + + name_len = strcspn(s,"+-"); + + for (bit = 1; bit; bit <<= 1) { + const char *fname = packet_tcp_flag_to_string(bit); + size_t len; + + if (!fname) { + continue; + } + + len = strlen(fname); + if (len != name_len) { + continue; + } + if (!strncmp(s, fname, len)) { + if (mask & bit) { + return xasprintf("%s: Each TCP flag can be specified only " + "once", s); + } + if (set) { + flags |= bit; + } + mask |= bit; + break; + } + } + + if (!bit) { + return xasprintf("%s: unknown TCP flag(s)", s); + } + s += name_len; + } + + *flagsp = htons(flags); + *maskp = htons(mask); + return NULL; +} + + /* Parses 's', a string value for field 'mf', into 'value' and 'mask'. Returns * NULL if successful, otherwise a malloc()'d string describing the error. */ char * mf_parse(const struct mf_field *mf, const char *s, union mf_value *value, union mf_value *mask) { + char *error; + if (!strcmp(s, "*")) { memset(value, 0, mf->n_bytes); memset(mask, 0, mf->n_bytes); @@ -2520,32 +2680,52 @@ mf_parse(const struct mf_field *mf, const char *s, switch (mf->string) { case MFS_DECIMAL: case MFS_HEXADECIMAL: - return mf_from_integer_string(mf, s, - (uint8_t *) value, (uint8_t *) mask); + error = mf_from_integer_string(mf, s, + (uint8_t *) value, (uint8_t *) mask); + break; case MFS_ETHERNET: - return mf_from_ethernet_string(mf, s, value->mac, mask->mac); + error = mf_from_ethernet_string(mf, s, value->mac, mask->mac); + break; case MFS_IPV4: - return mf_from_ipv4_string(mf, s, &value->be32, &mask->be32); + error = mf_from_ipv4_string(mf, s, &value->be32, &mask->be32); + break; case MFS_IPV6: - return mf_from_ipv6_string(mf, s, &value->ipv6, &mask->ipv6); + error = mf_from_ipv6_string(mf, s, &value->ipv6, &mask->ipv6); + break; case MFS_OFP_PORT: - return mf_from_ofp_port_string(mf, s, &value->be16, &mask->be16); + error = mf_from_ofp_port_string(mf, s, &value->be16, &mask->be16); + break; case MFS_OFP_PORT_OXM: - return mf_from_ofp_port_string32(mf, s, &value->be32, &mask->be32); + error = mf_from_ofp_port_string32(mf, s, &value->be32, &mask->be32); + break; case MFS_FRAG: - return mf_from_frag_string(s, &value->u8, &mask->u8); + error = mf_from_frag_string(s, &value->u8, &mask->u8); + break; case MFS_TNL_FLAGS: ovs_assert(mf->n_bytes == sizeof(ovs_be16)); - return mf_from_tun_flags_string(s, &value->be16, &mask->be16); + error = mf_from_tun_flags_string(s, &value->be16, &mask->be16); + break; + + case MFS_TCP_FLAGS: + ovs_assert(mf->n_bytes == sizeof(ovs_be16)); + error = mf_from_tcp_flags_string(s, &value->be16, &mask->be16); + break; + + default: + OVS_NOT_REACHED(); + } + + if (!error && !mf_is_mask_valid(mf, mask)) { + error = xasprintf("%s: invalid mask for field %s", s, mf->name); } - NOT_REACHED(); + return error; } /* Parses 's', a string value for field 'mf', into 'value'. Returns NULL if @@ -2624,6 +2804,13 @@ mf_format_tnl_flags_string(const ovs_be16 *valuep, struct ds *s) format_flags(s, flow_tun_flag_to_string, ntohs(*valuep), '|'); } +static void +mf_format_tcp_flags_string(ovs_be16 value, ovs_be16 mask, struct ds *s) +{ + format_flags_masked(s, NULL, packet_tcp_flag_to_string, ntohs(value), + TCP_FLAGS(mask)); +} + /* Appends to 's' a string representation of field 'mf' whose value is in * 'value' and 'mask'. 'mask' may be NULL to indicate an exact match. */ void @@ -2680,8 +2867,13 @@ mf_format(const struct mf_field *mf, mf_format_tnl_flags_string(&value->be16, s); break; + case MFS_TCP_FLAGS: + mf_format_tcp_flags_string(value->be16, + mask ? mask->be16 : OVS_BE16_MAX, s); + break; + default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -2832,9 +3024,9 @@ mf_parse_subfield__(struct mf_subfield *sf, const char **sp) } s += name_len; - if (sscanf(s, "[%d..%d]", &start, &end) == 2) { + if (ovs_scan(s, "[%d..%d]", &start, &end)) { /* Nothing to do. */ - } else if (sscanf(s, "[%d]", &start) == 1) { + } else if (ovs_scan(s, "[%d]", &start)) { end = start; } else if (!strncmp(s, "[]", 2)) { start = 0;