2 * Copyright (c) 2011 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
21 #include <netinet/in.h>
22 #include <netinet/ip6.h>
29 /* The comment on each of these indicates the member in "union mf_value" used
30 * to represent its value. */
33 MFF_TUN_ID, /* be64 */
34 MFF_IN_PORT, /* be16 */
56 MFF_ETH_SRC, /* mac */
57 MFF_ETH_DST, /* mac */
58 MFF_ETH_TYPE, /* be16 */
60 MFF_VLAN_TCI, /* be16 */
61 MFF_VLAN_VID, /* be16 */
62 MFF_VLAN_PCP, /* u8 */
65 MFF_IPV4_SRC, /* be32 */
66 MFF_IPV4_DST, /* be32 */
68 MFF_IPV6_SRC, /* ipv6 */
69 MFF_IPV6_DST, /* ipv6 */
70 MFF_IPV6_LABEL, /* be32 */
72 MFF_IP_PROTO, /* u8 (used for IPv4 or IPv6) */
73 MFF_IP_DSCP, /* u8 (used for IPv4 or IPv6) */
74 MFF_IP_ECN, /* u8 (used for IPv4 or IPv6) */
75 MFF_IP_TTL, /* u8 (used for IPv4 or IPv6) */
76 MFF_IP_FRAG, /* u8 (used for IPv4 or IPv6) */
78 MFF_ARP_OP, /* be16 */
79 MFF_ARP_SPA, /* be32 */
80 MFF_ARP_TPA, /* be32 */
81 MFF_ARP_SHA, /* mac */
82 MFF_ARP_THA, /* mac */
85 MFF_TCP_SRC, /* be16 (used for IPv4 or IPv6) */
86 MFF_TCP_DST, /* be16 (used for IPv4 or IPv6) */
88 MFF_UDP_SRC, /* be16 (used for IPv4 or IPv6) */
89 MFF_UDP_DST, /* be16 (used for IPv4 or IPv6) */
91 MFF_ICMP_TYPE, /* u8 (used for IPv4 or IPv6) */
92 MFF_ICMP_CODE, /* u8 (used for IPv4 or IPv6) */
94 /* ICMPv6 Neighbor Discovery. */
95 MFF_ND_TARGET, /* ipv6 */
102 /* Prerequisites for matching a field.
104 * A field may only be matched if the correct lower-level protocols are also
105 * matched. For example, the TCP port may be matched only if the Ethernet type
106 * matches ETH_TYPE_IP and the IP protocol matches IPPROTO_TCP. */
110 /* L2 requirements. */
116 /* L2+L3 requirements. */
117 MFP_TCP, /* On IPv4 or IPv6. */
118 MFP_UDP, /* On IPv4 or IPv6. */
122 /* L2+L3+L4 requirements. */
128 /* Forms of partial-field masking allowed for a field.
130 * Every field may be masked as a whole. */
132 MFM_NONE, /* No sub-field masking. */
133 MFM_FULLY, /* Every bit is individually maskable. */
134 MFM_CIDR, /* Contiguous low-order bits may be masked. */
135 MFM_MCAST /* Byte 0, bit 0 is separately maskable. */
138 /* How to format or parse a field's value. */
142 * The particular MFS_* constant sets the output format. On input, either
143 * decimal or hexadecimal (prefixed with 0x) is accepted. */
151 MFS_OFP_PORT, /* An OpenFlow port number or name. */
152 MFS_FRAG /* no, yes, first, later, not_later */
156 /* Identification. */
157 enum mf_field_id id; /* MFF_*. */
158 const char *name; /* Name of this field, e.g. "eth_type". */
159 const char *extra_name; /* Alternate name, e.g. "dl_type", or NULL. */
163 * Most fields have n_bytes * 8 == n_bits. There are a few exceptions:
165 * - "dl_vlan" is 2 bytes but only 12 bits.
166 * - "dl_vlan_pcp" is 1 byte but only 3 bits.
167 * - "is_frag" is 1 byte but only 2 bits.
168 * - "ipv6_label" is 4 bytes but only 20 bits.
170 unsigned int n_bytes; /* Width of the field in bytes. */
171 unsigned int n_bits; /* Number of significant bits in field. */
174 enum mf_maskable maskable;
175 flow_wildcards_t fww_bit; /* Either 0 or exactly one FWW_* bit. */
176 enum mf_string string;
177 enum mf_prereqs prereqs;
178 uint32_t nxm_header; /* An NXM_* constant (a few fields have 0). */
181 /* The representation of a field's value. */
187 uint8_t mac[ETH_ADDR_LEN];
188 struct in6_addr ipv6;
191 /* Finding mf_fields. */
192 const struct mf_field *mf_from_id(enum mf_field_id);
193 const struct mf_field *mf_from_name(const char *name);
195 /* Inspecting wildcarded bits. */
196 bool mf_is_all_wild(const struct mf_field *, const struct flow_wildcards *);
198 bool mf_is_mask_valid(const struct mf_field *, const union mf_value *mask);
199 void mf_get_mask(const struct mf_field *, const struct flow_wildcards *,
200 union mf_value *mask);
203 bool mf_are_prereqs_ok(const struct mf_field *, const struct flow *);
204 void mf_force_prereqs(const struct mf_field *, struct cls_rule *);
207 bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
209 void mf_get_value(const struct mf_field *, const struct flow *,
210 union mf_value *value);
211 void mf_set_value(const struct mf_field *, const union mf_value *value,
214 void mf_get(const struct mf_field *, const struct cls_rule *,
215 union mf_value *value, union mf_value *mask);
216 void mf_set(const struct mf_field *,
217 const union mf_value *value, const union mf_value *mask,
219 void mf_set_subfield(const struct mf_field *, uint64_t value, unsigned int ofs,
220 unsigned int n_bits, struct cls_rule *);
222 void mf_set_wild(const struct mf_field *, struct cls_rule *);
224 void mf_random_value(const struct mf_field *, union mf_value *value);
226 /* Parsing and formatting. */
227 char *mf_parse(const struct mf_field *, const char *,
228 union mf_value *value, union mf_value *mask);
229 char *mf_parse_value(const struct mf_field *, const char *, union mf_value *);
230 void mf_format(const struct mf_field *,
231 const union mf_value *value, const union mf_value *mask,
234 #endif /* meta-flow.h */