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 <netinet/ip6.h>
27 /* The comment on each of these indicates the member in "union mf_value" used
28 * to represent its value. */
31 MFF_TUN_ID, /* be64 */
32 MFF_IN_PORT, /* be16 */
51 MFF_ETH_SRC, /* mac */
52 MFF_ETH_DST, /* mac */
53 MFF_ETH_TYPE, /* be16 */
55 MFF_VLAN_TCI, /* be16 */
56 MFF_VLAN_VID, /* be16 */
57 MFF_VLAN_PCP, /* u8 */
60 MFF_IPV4_SRC, /* be32 */
61 MFF_IPV4_DST, /* be32 */
63 MFF_IPV6_SRC, /* ipv6 */
64 MFF_IPV6_DST, /* ipv6 */
66 MFF_IP_PROTO, /* u8 (used for IPv4 or IPv6) */
67 MFF_IP_TOS, /* u8 (used for IPv4 or IPv6) */
69 MFF_ARP_OP, /* be16 */
70 MFF_ARP_SPA, /* be32 */
71 MFF_ARP_TPA, /* be32 */
72 MFF_ARP_SHA, /* mac */
73 MFF_ARP_THA, /* mac */
76 MFF_TCP_SRC, /* be16 (used for IPv4 or IPv6) */
77 MFF_TCP_DST, /* be16 (used for IPv4 or IPv6) */
79 MFF_UDP_SRC, /* be16 (used for IPv4 or IPv6) */
80 MFF_UDP_DST, /* be16 (used for IPv4 or IPv6) */
82 MFF_ICMP_TYPE, /* u8 (used for IPv4 or IPv6) */
83 MFF_ICMP_CODE, /* u8 (used for IPv4 or IPv6) */
85 /* ICMPv6 Neighbor Discovery. */
86 MFF_ND_TARGET, /* ipv6 */
93 /* Prerequisites for matching a field.
95 * A field may only be matched if the correct lower-level protocols are also
96 * matched. For example, the TCP port may be matched only if the Ethernet type
97 * matches ETH_TYPE_IP and the IP protocol matches IPPROTO_TCP. */
101 /* L2 requirements. */
107 /* L2+L3 requirements. */
108 MFP_TCP, /* On IPv4 or IPv6. */
109 MFP_UDP, /* On IPv4 or IPv6. */
113 /* L2+L3+L4 requirements. */
119 /* Forms of partial-field masking allowed for a field.
121 * Every field may be masked as a whole. */
123 MFM_NONE, /* No sub-field masking. */
124 MFM_FULLY, /* Every bit is individually maskable. */
125 MFM_CIDR, /* Contiguous low-order bits may be masked. */
126 MFM_MCAST /* Byte 0, bit 0 is separately maskable. */
129 /* How to format or parse a field's value. */
133 * The particular MFS_* constant sets the output format. On input, either
134 * decimal or hexadecimal (prefixed with 0x) is accepted. */
142 MFS_OFP_PORT /* An OpenFlow port number or name. */
146 /* Identification. */
147 enum mf_field_id id; /* MFF_*. */
148 const char *name; /* Name of this field, e.g. "eth_type". */
149 const char *extra_name; /* Alternate name, e.g. "dl_type", or NULL. */
153 * Most fields have n_bytes * 8 == n_bits. There are only two exceptions
154 * currently: "dl_vlan" is 2 bytes but only 12 bits, and "dl_vlan_pcp" is
155 * 1 byte but only 3 bits. */
156 unsigned int n_bytes; /* Width of the field in bytes. */
157 unsigned int n_bits; /* Number of significant bits in field. */
160 enum mf_maskable maskable;
161 flow_wildcards_t fww_bit; /* Either 0 or exactly one FWW_* bit. */
162 enum mf_string string;
163 enum mf_prereqs prereqs;
164 uint32_t nxm_header; /* An NXM_* constant (a few fields have 0). */
167 /* The representation of a field's value. */
173 uint8_t mac[ETH_ADDR_LEN];
174 struct in6_addr ipv6;
177 /* Finding mf_fields. */
178 const struct mf_field *mf_from_id(enum mf_field_id);
179 const struct mf_field *mf_from_name(const char *name);
181 /* Inspecting wildcarded bits. */
182 bool mf_is_all_wild(const struct mf_field *, const struct flow_wildcards *);
184 bool mf_is_mask_valid(const struct mf_field *, const union mf_value *mask);
185 void mf_get_mask(const struct mf_field *, const struct flow_wildcards *,
186 union mf_value *mask);
189 bool mf_are_prereqs_ok(const struct mf_field *, const struct flow *);
190 void mf_force_prereqs(const struct mf_field *, struct cls_rule *);
193 bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
195 void mf_get_value(const struct mf_field *, const struct flow *,
196 union mf_value *value);
197 void mf_set_value(const struct mf_field *, const union mf_value *value,
200 void mf_get(const struct mf_field *, const struct cls_rule *,
201 union mf_value *value, union mf_value *mask);
202 void mf_set(const struct mf_field *,
203 const union mf_value *value, const union mf_value *mask,
205 void mf_set_subfield(const struct mf_field *, uint64_t value, unsigned int ofs,
206 unsigned int n_bits, struct cls_rule *);
208 void mf_set_wild(const struct mf_field *, struct cls_rule *);
210 void mf_random_value(const struct mf_field *, union mf_value *value);
212 /* Parsing and formatting. */
213 char *mf_parse(const struct mf_field *, const char *,
214 union mf_value *value, union mf_value *mask);
215 char *mf_parse_value(const struct mf_field *, const char *, union mf_value *);
216 void mf_format(const struct mf_field *,
217 const union mf_value *value, const union mf_value *mask,
220 #endif /* meta-flow.h */