Lines Matching refs:match
94 static void update_range(struct sw_flow_match *match, in update_range() argument
102 range = &match->range; in update_range()
104 range = &match->mask->range; in update_range()
119 #define SW_FLOW_KEY_PUT(match, field, value, is_mask) \ argument
121 update_range(match, offsetof(struct sw_flow_key, field), \
122 sizeof((match)->key->field), is_mask); \
124 (match)->mask->key.field = value; \
126 (match)->key->field = value; \
129 #define SW_FLOW_KEY_MEMCPY_OFFSET(match, offset, value_p, len, is_mask) \ argument
131 update_range(match, offset, len, is_mask); \
133 memcpy((u8 *)&(match)->mask->key + offset, value_p, \
136 memcpy((u8 *)(match)->key + offset, value_p, len); \
139 #define SW_FLOW_KEY_MEMCPY(match, field, value_p, len, is_mask) \ argument
140 SW_FLOW_KEY_MEMCPY_OFFSET(match, offsetof(struct sw_flow_key, field), \
143 #define SW_FLOW_KEY_MEMSET_FIELD(match, field, value, is_mask) \ argument
145 update_range(match, offsetof(struct sw_flow_key, field), \
146 sizeof((match)->key->field), is_mask); \
148 memset((u8 *)&(match)->mask->key.field, value, \
149 sizeof((match)->mask->key.field)); \
151 memset((u8 *)&(match)->key->field, value, \
152 sizeof((match)->key->field)); \
155 static bool match_validate(const struct sw_flow_match *match, in match_validate() argument
184 if (match->key->eth.type == htons(ETH_P_ARP) in match_validate()
185 || match->key->eth.type == htons(ETH_P_RARP)) { in match_validate()
187 if (match->mask && (match->mask->key.eth.type == htons(0xffff))) in match_validate()
191 if (eth_p_mpls(match->key->eth.type)) { in match_validate()
193 if (match->mask && (match->mask->key.eth.type == htons(0xffff))) in match_validate()
197 if (match->key->eth.type == htons(ETH_P_IP)) { in match_validate()
199 if (match->mask && match->mask->key.eth.type == htons(0xffff)) { in match_validate()
204 if (match->key->ip.frag != OVS_FRAG_TYPE_LATER) { in match_validate()
205 if (match->key->ip.proto == IPPROTO_UDP) { in match_validate()
207 if (match->mask && (match->mask->key.ip.proto == 0xff)) in match_validate()
211 if (match->key->ip.proto == IPPROTO_SCTP) { in match_validate()
213 if (match->mask && (match->mask->key.ip.proto == 0xff)) in match_validate()
217 if (match->key->ip.proto == IPPROTO_TCP) { in match_validate()
220 if (match->mask && (match->mask->key.ip.proto == 0xff)) { in match_validate()
226 if (match->key->ip.proto == IPPROTO_ICMP) { in match_validate()
228 if (match->mask && (match->mask->key.ip.proto == 0xff)) in match_validate()
234 if (match->key->eth.type == htons(ETH_P_IPV6)) { in match_validate()
236 if (match->mask && match->mask->key.eth.type == htons(0xffff)) { in match_validate()
241 if (match->key->ip.frag != OVS_FRAG_TYPE_LATER) { in match_validate()
242 if (match->key->ip.proto == IPPROTO_UDP) { in match_validate()
244 if (match->mask && (match->mask->key.ip.proto == 0xff)) in match_validate()
248 if (match->key->ip.proto == IPPROTO_SCTP) { in match_validate()
250 if (match->mask && (match->mask->key.ip.proto == 0xff)) in match_validate()
254 if (match->key->ip.proto == IPPROTO_TCP) { in match_validate()
257 if (match->mask && (match->mask->key.ip.proto == 0xff)) { in match_validate()
263 if (match->key->ip.proto == IPPROTO_ICMPV6) { in match_validate()
265 if (match->mask && (match->mask->key.ip.proto == 0xff)) in match_validate()
268 if (match->key->tp.src == in match_validate()
270 match->key->tp.src == htons(NDISC_NEIGHBOUR_ADVERTISEMENT)) { in match_validate()
278 if (match->mask && (match->mask->key.tp.src == htons(0xff))) in match_validate()
285 if (match->key->eth.type == htons(ETH_P_NSH)) { in match_validate()
287 if (match->mask && in match_validate()
288 match->mask->key.eth.type == htons(0xffff)) { in match_validate()
535 struct sw_flow_match *match, bool is_mask, in genev_tun_opt_from_nlattr() argument
540 if (nla_len(a) > sizeof(match->key->tun_opts)) { in genev_tun_opt_from_nlattr()
542 nla_len(a), sizeof(match->key->tun_opts)); in genev_tun_opt_from_nlattr()
557 SW_FLOW_KEY_PUT(match, tun_opts_len, nla_len(a), in genev_tun_opt_from_nlattr()
570 if (match->key->tun_opts_len != nla_len(a)) { in genev_tun_opt_from_nlattr()
572 match->key->tun_opts_len, nla_len(a)); in genev_tun_opt_from_nlattr()
576 SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true); in genev_tun_opt_from_nlattr()
580 SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, nla_data(a), in genev_tun_opt_from_nlattr()
586 struct sw_flow_match *match, bool is_mask, in vxlan_tun_opt_from_nlattr() argument
594 BUILD_BUG_ON(sizeof(opts) > sizeof(match->key->tun_opts)); in vxlan_tun_opt_from_nlattr()
631 SW_FLOW_KEY_PUT(match, tun_opts_len, sizeof(opts), false); in vxlan_tun_opt_from_nlattr()
633 SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true); in vxlan_tun_opt_from_nlattr()
636 SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, &opts, sizeof(opts), in vxlan_tun_opt_from_nlattr()
642 struct sw_flow_match *match, bool is_mask, in erspan_tun_opt_from_nlattr() argument
648 sizeof(match->key->tun_opts)); in erspan_tun_opt_from_nlattr()
650 if (nla_len(a) > sizeof(match->key->tun_opts)) { in erspan_tun_opt_from_nlattr()
652 nla_len(a), sizeof(match->key->tun_opts)); in erspan_tun_opt_from_nlattr()
657 SW_FLOW_KEY_PUT(match, tun_opts_len, in erspan_tun_opt_from_nlattr()
660 SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true); in erspan_tun_opt_from_nlattr()
663 SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, nla_data(a), in erspan_tun_opt_from_nlattr()
669 struct sw_flow_match *match, bool is_mask, in ip_tun_from_nlattr() argument
698 SW_FLOW_KEY_PUT(match, tun_key.tun_id, in ip_tun_from_nlattr()
703 SW_FLOW_KEY_PUT(match, tun_key.u.ipv4.src, in ip_tun_from_nlattr()
708 SW_FLOW_KEY_PUT(match, tun_key.u.ipv4.dst, in ip_tun_from_nlattr()
713 SW_FLOW_KEY_PUT(match, tun_key.u.ipv6.src, in ip_tun_from_nlattr()
718 SW_FLOW_KEY_PUT(match, tun_key.u.ipv6.dst, in ip_tun_from_nlattr()
723 SW_FLOW_KEY_PUT(match, tun_key.tos, in ip_tun_from_nlattr()
727 SW_FLOW_KEY_PUT(match, tun_key.ttl, in ip_tun_from_nlattr()
738 SW_FLOW_KEY_PUT(match, tun_key.tp_src, in ip_tun_from_nlattr()
742 SW_FLOW_KEY_PUT(match, tun_key.tp_dst, in ip_tun_from_nlattr()
754 err = genev_tun_opt_from_nlattr(a, match, is_mask, log); in ip_tun_from_nlattr()
767 err = vxlan_tun_opt_from_nlattr(a, match, is_mask, log); in ip_tun_from_nlattr()
782 err = erspan_tun_opt_from_nlattr(a, match, is_mask, in ip_tun_from_nlattr()
801 SW_FLOW_KEY_PUT(match, tun_key.tun_flags, tun_flags, is_mask); in ip_tun_from_nlattr()
803 SW_FLOW_KEY_MEMSET_FIELD(match, tun_proto, 0xff, true); in ip_tun_from_nlattr()
805 SW_FLOW_KEY_PUT(match, tun_proto, ipv6 ? AF_INET6 : AF_INET, in ip_tun_from_nlattr()
826 if (match->key->tun_key.u.ipv4.src || in ip_tun_from_nlattr()
827 match->key->tun_key.u.ipv4.dst || in ip_tun_from_nlattr()
828 match->key->tun_key.tp_src || in ip_tun_from_nlattr()
829 match->key->tun_key.tp_dst || in ip_tun_from_nlattr()
830 match->key->tun_key.ttl || in ip_tun_from_nlattr()
831 match->key->tun_key.tos || in ip_tun_from_nlattr()
836 } else if (!match->key->tun_key.u.ipv4.dst) { in ip_tun_from_nlattr()
841 if (ipv6 && ipv6_addr_any(&match->key->tun_key.u.ipv6.dst)) { in ip_tun_from_nlattr()
975 static int encode_vlan_from_nlattrs(struct sw_flow_match *match, in encode_vlan_from_nlattrs() argument
989 SW_FLOW_KEY_PUT(match, eth.vlan.tpid, tpid, is_mask); in encode_vlan_from_nlattrs()
990 SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask); in encode_vlan_from_nlattrs()
992 SW_FLOW_KEY_PUT(match, eth.cvlan.tpid, tpid, is_mask); in encode_vlan_from_nlattrs()
993 SW_FLOW_KEY_PUT(match, eth.cvlan.tci, tci, is_mask); in encode_vlan_from_nlattrs()
998 static int validate_vlan_from_nlattrs(const struct sw_flow_match *match, in validate_vlan_from_nlattrs() argument
1036 static int validate_vlan_mask_from_nlattrs(const struct sw_flow_match *match, in validate_vlan_mask_from_nlattrs() argument
1042 bool encap_valid = !!(match->key->eth.vlan.tci & in validate_vlan_mask_from_nlattrs()
1044 bool i_encap_valid = !!(match->key->eth.cvlan.tci & in validate_vlan_mask_from_nlattrs()
1078 static int __parse_vlan_from_nlattrs(struct sw_flow_match *match, in __parse_vlan_from_nlattrs() argument
1087 err = validate_vlan_from_nlattrs(match, *key_attrs, inner, in __parse_vlan_from_nlattrs()
1090 err = validate_vlan_mask_from_nlattrs(match, *key_attrs, inner, in __parse_vlan_from_nlattrs()
1095 err = encode_vlan_from_nlattrs(match, a, is_mask, inner); in __parse_vlan_from_nlattrs()
1113 static int parse_vlan_from_nlattrs(struct sw_flow_match *match, in parse_vlan_from_nlattrs() argument
1120 err = __parse_vlan_from_nlattrs(match, key_attrs, false, a, in parse_vlan_from_nlattrs()
1125 encap_valid = !!(match->key->eth.vlan.tci & htons(VLAN_CFI_MASK)); in parse_vlan_from_nlattrs()
1127 err = __parse_vlan_from_nlattrs(match, key_attrs, true, a, in parse_vlan_from_nlattrs()
1136 static int parse_eth_type_from_nlattrs(struct sw_flow_match *match, in parse_eth_type_from_nlattrs() argument
1152 SW_FLOW_KEY_PUT(match, eth.type, eth_type, is_mask); in parse_eth_type_from_nlattrs()
1157 static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, in metadata_from_nlattrs() argument
1166 SW_FLOW_KEY_PUT(match, ovs_flow_hash, hash_val, is_mask); in metadata_from_nlattrs()
1173 SW_FLOW_KEY_PUT(match, recirc_id, recirc_id, is_mask); in metadata_from_nlattrs()
1178 SW_FLOW_KEY_PUT(match, phy.priority, in metadata_from_nlattrs()
1194 SW_FLOW_KEY_PUT(match, phy.in_port, in_port, is_mask); in metadata_from_nlattrs()
1197 SW_FLOW_KEY_PUT(match, phy.in_port, DP_MAX_PORTS, is_mask); in metadata_from_nlattrs()
1203 SW_FLOW_KEY_PUT(match, phy.skb_mark, mark, is_mask); in metadata_from_nlattrs()
1207 if (ip_tun_from_nlattr(a[OVS_KEY_ATTR_TUNNEL], match, in metadata_from_nlattrs()
1223 SW_FLOW_KEY_PUT(match, ct_state, ct_state, is_mask); in metadata_from_nlattrs()
1230 SW_FLOW_KEY_PUT(match, ct_zone, ct_zone, is_mask); in metadata_from_nlattrs()
1237 SW_FLOW_KEY_PUT(match, ct.mark, mark, is_mask); in metadata_from_nlattrs()
1245 SW_FLOW_KEY_MEMCPY(match, ct.labels, cl->ct_labels, in metadata_from_nlattrs()
1254 SW_FLOW_KEY_PUT(match, ipv4.ct_orig.src, ct->ipv4_src, is_mask); in metadata_from_nlattrs()
1255 SW_FLOW_KEY_PUT(match, ipv4.ct_orig.dst, ct->ipv4_dst, is_mask); in metadata_from_nlattrs()
1256 SW_FLOW_KEY_PUT(match, ct.orig_tp.src, ct->src_port, is_mask); in metadata_from_nlattrs()
1257 SW_FLOW_KEY_PUT(match, ct.orig_tp.dst, ct->dst_port, is_mask); in metadata_from_nlattrs()
1258 SW_FLOW_KEY_PUT(match, ct_orig_proto, ct->ipv4_proto, is_mask); in metadata_from_nlattrs()
1266 SW_FLOW_KEY_MEMCPY(match, ipv6.ct_orig.src, &ct->ipv6_src, in metadata_from_nlattrs()
1267 sizeof(match->key->ipv6.ct_orig.src), in metadata_from_nlattrs()
1269 SW_FLOW_KEY_MEMCPY(match, ipv6.ct_orig.dst, &ct->ipv6_dst, in metadata_from_nlattrs()
1270 sizeof(match->key->ipv6.ct_orig.dst), in metadata_from_nlattrs()
1272 SW_FLOW_KEY_PUT(match, ct.orig_tp.src, ct->src_port, is_mask); in metadata_from_nlattrs()
1273 SW_FLOW_KEY_PUT(match, ct.orig_tp.dst, ct->dst_port, is_mask); in metadata_from_nlattrs()
1274 SW_FLOW_KEY_PUT(match, ct_orig_proto, ct->ipv6_proto, is_mask); in metadata_from_nlattrs()
1286 SW_FLOW_KEY_PUT(match, mac_proto, is_mask ? 0xff : mac_proto, is_mask); in metadata_from_nlattrs()
1289 return parse_eth_type_from_nlattrs(match, attrs, a, is_mask, in metadata_from_nlattrs()
1390 struct sw_flow_match *match, bool is_mask, in nsh_key_put_from_nlattr() argument
1432 SW_FLOW_KEY_PUT(match, nsh.base.flags, in nsh_key_put_from_nlattr()
1434 SW_FLOW_KEY_PUT(match, nsh.base.ttl, in nsh_key_put_from_nlattr()
1436 SW_FLOW_KEY_PUT(match, nsh.base.mdtype, in nsh_key_put_from_nlattr()
1438 SW_FLOW_KEY_PUT(match, nsh.base.np, in nsh_key_put_from_nlattr()
1440 SW_FLOW_KEY_PUT(match, nsh.base.path_hdr, in nsh_key_put_from_nlattr()
1449 SW_FLOW_KEY_PUT(match, nsh.context[i], in nsh_key_put_from_nlattr()
1510 static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match, in ovs_key_from_nlattrs() argument
1516 err = metadata_from_nlattrs(net, match, &attrs, a, is_mask, log); in ovs_key_from_nlattrs()
1524 SW_FLOW_KEY_MEMCPY(match, eth.src, in ovs_key_from_nlattrs()
1526 SW_FLOW_KEY_MEMCPY(match, eth.dst, in ovs_key_from_nlattrs()
1539 err = parse_eth_type_from_nlattrs(match, &attrs, a, is_mask, in ovs_key_from_nlattrs()
1544 SW_FLOW_KEY_PUT(match, eth.type, htons(ETH_P_802_2), is_mask); in ovs_key_from_nlattrs()
1546 } else if (!match->key->eth.type) { in ovs_key_from_nlattrs()
1560 SW_FLOW_KEY_PUT(match, ip.proto, in ovs_key_from_nlattrs()
1562 SW_FLOW_KEY_PUT(match, ip.tos, in ovs_key_from_nlattrs()
1564 SW_FLOW_KEY_PUT(match, ip.ttl, in ovs_key_from_nlattrs()
1566 SW_FLOW_KEY_PUT(match, ip.frag, in ovs_key_from_nlattrs()
1568 SW_FLOW_KEY_PUT(match, ipv4.addr.src, in ovs_key_from_nlattrs()
1570 SW_FLOW_KEY_PUT(match, ipv4.addr.dst, in ovs_key_from_nlattrs()
1591 SW_FLOW_KEY_PUT(match, ipv6.label, in ovs_key_from_nlattrs()
1593 SW_FLOW_KEY_PUT(match, ip.proto, in ovs_key_from_nlattrs()
1595 SW_FLOW_KEY_PUT(match, ip.tos, in ovs_key_from_nlattrs()
1597 SW_FLOW_KEY_PUT(match, ip.ttl, in ovs_key_from_nlattrs()
1599 SW_FLOW_KEY_PUT(match, ip.frag, in ovs_key_from_nlattrs()
1601 SW_FLOW_KEY_MEMCPY(match, ipv6.addr.src, in ovs_key_from_nlattrs()
1603 sizeof(match->key->ipv6.addr.src), in ovs_key_from_nlattrs()
1605 SW_FLOW_KEY_MEMCPY(match, ipv6.addr.dst, in ovs_key_from_nlattrs()
1607 sizeof(match->key->ipv6.addr.dst), in ovs_key_from_nlattrs()
1618 SW_FLOW_KEY_PUT(match, ipv6.exthdrs, in ovs_key_from_nlattrs()
1634 SW_FLOW_KEY_PUT(match, ipv4.addr.src, in ovs_key_from_nlattrs()
1636 SW_FLOW_KEY_PUT(match, ipv4.addr.dst, in ovs_key_from_nlattrs()
1638 SW_FLOW_KEY_PUT(match, ip.proto, in ovs_key_from_nlattrs()
1640 SW_FLOW_KEY_MEMCPY(match, ipv4.arp.sha, in ovs_key_from_nlattrs()
1642 SW_FLOW_KEY_MEMCPY(match, ipv4.arp.tha, in ovs_key_from_nlattrs()
1649 if (nsh_key_put_from_nlattr(a[OVS_KEY_ATTR_NSH], match, in ovs_key_from_nlattrs()
1671 SW_FLOW_KEY_PUT(match, mpls.lse[i], in ovs_key_from_nlattrs()
1674 SW_FLOW_KEY_PUT(match, mpls.num_labels_mask, in ovs_key_from_nlattrs()
1684 SW_FLOW_KEY_PUT(match, tp.src, tcp_key->tcp_src, is_mask); in ovs_key_from_nlattrs()
1685 SW_FLOW_KEY_PUT(match, tp.dst, tcp_key->tcp_dst, is_mask); in ovs_key_from_nlattrs()
1690 SW_FLOW_KEY_PUT(match, tp.flags, in ovs_key_from_nlattrs()
1700 SW_FLOW_KEY_PUT(match, tp.src, udp_key->udp_src, is_mask); in ovs_key_from_nlattrs()
1701 SW_FLOW_KEY_PUT(match, tp.dst, udp_key->udp_dst, is_mask); in ovs_key_from_nlattrs()
1709 SW_FLOW_KEY_PUT(match, tp.src, sctp_key->sctp_src, is_mask); in ovs_key_from_nlattrs()
1710 SW_FLOW_KEY_PUT(match, tp.dst, sctp_key->sctp_dst, is_mask); in ovs_key_from_nlattrs()
1718 SW_FLOW_KEY_PUT(match, tp.src, in ovs_key_from_nlattrs()
1720 SW_FLOW_KEY_PUT(match, tp.dst, in ovs_key_from_nlattrs()
1729 SW_FLOW_KEY_PUT(match, tp.src, in ovs_key_from_nlattrs()
1731 SW_FLOW_KEY_PUT(match, tp.dst, in ovs_key_from_nlattrs()
1740 SW_FLOW_KEY_MEMCPY(match, ipv6.nd.target, in ovs_key_from_nlattrs()
1742 sizeof(match->key->ipv6.nd.target), in ovs_key_from_nlattrs()
1744 SW_FLOW_KEY_MEMCPY(match, ipv6.nd.sll, in ovs_key_from_nlattrs()
1746 SW_FLOW_KEY_MEMCPY(match, ipv6.nd.tll, in ovs_key_from_nlattrs()
1799 int ovs_nla_get_match(struct net *net, struct sw_flow_match *match, in ovs_nla_get_match() argument
1814 err = parse_vlan_from_nlattrs(match, &key_attrs, a, false, log); in ovs_nla_get_match()
1818 err = ovs_key_from_nlattrs(net, match, key_attrs, a, false, log); in ovs_nla_get_match()
1822 if (match->mask) { in ovs_nla_get_match()
1845 if (match->key->tun_proto) in ovs_nla_get_match()
1846 SW_FLOW_KEY_MEMSET_FIELD(match, tun_key, in ovs_nla_get_match()
1857 SW_FLOW_KEY_PUT(match, eth.vlan.tci, htons(0xffff), true); in ovs_nla_get_match()
1858 SW_FLOW_KEY_PUT(match, eth.cvlan.tci, htons(0xffff), true); in ovs_nla_get_match()
1860 err = parse_vlan_from_nlattrs(match, &mask_attrs, a, true, log); in ovs_nla_get_match()
1864 err = ovs_key_from_nlattrs(net, match, mask_attrs, a, true, in ovs_nla_get_match()
1870 if (!match_validate(match, key_attrs, mask_attrs, log)) in ovs_nla_get_match()
1955 struct sw_flow_match match; in ovs_nla_get_flow_metadata() local
1957 memset(&match, 0, sizeof(match)); in ovs_nla_get_flow_metadata()
1958 match.key = key; in ovs_nla_get_flow_metadata()
1969 return metadata_from_nlattrs(net, &match, &attrs, a, false, log); in ovs_nla_get_flow_metadata()
2714 void ovs_match_init(struct sw_flow_match *match, in ovs_match_init() argument
2719 memset(match, 0, sizeof(*match)); in ovs_match_init()
2720 match->key = key; in ovs_match_init()
2721 match->mask = mask; in ovs_match_init()
2763 struct sw_flow_match match; in validate_and_copy_set_tun() local
2773 ovs_match_init(&match, &key, true, NULL); in validate_and_copy_set_tun()
2774 opts_type = ip_tun_from_nlattr(nla_data(attr), &match, false, log); in validate_and_copy_set_tun()
2844 struct sw_flow_match match; in validate_nsh() local
2848 ovs_match_init(&match, &key, true, NULL); in validate_nsh()
2849 ret = nsh_key_put_from_nlattr(attr, &match, is_mask, in validate_nsh()