]>
git.proxmox.com Git - mirror_ovs.git/blob - include/openvswitch/flow.h
2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
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.
16 #ifndef OPENVSWITCH_FLOW_H
17 #define OPENVSWITCH_FLOW_H 1
19 #include "openflow/nicira-ext.h"
20 #include "openvswitch/packets.h"
21 #include "openvswitch/util.h"
23 /* This sequence number should be incremented whenever anything involving flows
24 * or the wildcarding of flows changes. This will cause build assertion
25 * failures in places which likely need to be updated. */
26 #define FLOW_WC_SEQ 38
28 /* Number of Open vSwitch extension 32-bit registers. */
29 #define FLOW_N_REGS 16
30 BUILD_ASSERT_DECL(FLOW_N_REGS
<= NXM_NX_MAX_REGS
);
31 BUILD_ASSERT_DECL(FLOW_N_REGS
% 4 == 0); /* Handle xxregs. */
33 /* Number of OpenFlow 1.5+ 64-bit registers.
35 * Each of these overlays a pair of Open vSwitch 32-bit registers, so there
36 * are half as many of them.*/
37 #define FLOW_N_XREGS (FLOW_N_REGS / 2)
39 /* Number of 128-bit registers.
41 * Each of these overlays four Open vSwitch 32-bit registers, so there
42 * are a quarter as many of them.*/
43 #define FLOW_N_XXREGS (FLOW_N_REGS / 4)
45 /* Used for struct flow's dl_type member for frames that have no Ethernet
46 * type, that is, pure 802.2 frames. */
47 #define FLOW_DL_TYPE_NONE 0x5ff
49 /* Fragment bits, used for IPv4 and IPv6, always zero for non-IP flows. */
50 #define FLOW_NW_FRAG_ANY (1 << 0) /* Set for any IP frag. */
51 #define FLOW_NW_FRAG_LATER (1 << 1) /* Set for IP frag with nonzero offset. */
52 #define FLOW_NW_FRAG_MASK (FLOW_NW_FRAG_ANY | FLOW_NW_FRAG_LATER)
54 BUILD_ASSERT_DECL(FLOW_NW_FRAG_ANY
== NX_IP_FRAG_ANY
);
55 BUILD_ASSERT_DECL(FLOW_NW_FRAG_LATER
== NX_IP_FRAG_LATER
);
57 BUILD_ASSERT_DECL(FLOW_TNL_F_OAM
== NX_TUN_FLAG_OAM
);
59 const char *flow_tun_flag_to_string(uint32_t flags
);
61 /* Maximum number of supported MPLS labels. */
62 #define FLOW_MAX_MPLS_LABELS 3
64 /* Maximum number of supported SAMPLE action nesting. */
65 #define FLOW_MAX_SAMPLE_NESTING 10
67 /* Maximum number of supported VLAN headers.
69 * We require this to be a multiple of 2 so that vlans[] in struct flow is a
70 * multiple of 64 bits. */
71 #define FLOW_MAX_VLAN_HEADERS 2
72 BUILD_ASSERT_DECL(FLOW_MAX_VLAN_HEADERS
% 2 == 0);
74 /* Legacy maximum VLAN headers */
75 #define LEGACY_MAX_VLAN_HEADERS 1
78 * A flow in the network.
80 * Must be initialized to all zeros to make any compiler-induced padding
81 * zeroed. Helps also in keeping unused fields (such as mutually exclusive
82 * IPv4 and IPv6 addresses) zeroed out.
84 * The meaning of 'in_port' is context-dependent. In most cases, it is a
85 * 16-bit OpenFlow 1.0 port number. In the software datapath interface (dpif)
86 * layer and its implementations (e.g. dpif-netlink, dpif-netdev), it is
87 * instead a 32-bit datapath port number.
89 * The fields are organized in four segments to facilitate staged lookup, where
90 * lower layer fields are first used to determine if the later fields need to
91 * be looked at. This enables better wildcarding for datapath flows.
93 * NOTE: Order of the fields is significant, any change in the order must be
94 * reflected in miniflow_extract()!
98 struct flow_tnl tunnel
; /* Encapsulating tunnel parameters. */
99 ovs_be64 metadata
; /* OpenFlow Metadata. */
100 uint32_t regs
[FLOW_N_REGS
]; /* Registers. */
101 uint32_t skb_priority
; /* Packet priority for QoS. */
102 uint32_t pkt_mark
; /* Packet mark. */
103 uint32_t dp_hash
; /* Datapath computed hash value. The exact
104 * computation is opaque to the user space. */
105 union flow_in_port in_port
; /* Input port.*/
106 uint32_t recirc_id
; /* Must be exact match. */
107 uint8_t ct_state
; /* Connection tracking state. */
108 uint8_t ct_nw_proto
; /* CT orig tuple IP protocol. */
109 uint16_t ct_zone
; /* Connection tracking zone. */
110 uint32_t ct_mark
; /* Connection mark.*/
111 uint8_t pad1
[4]; /* Pad to 64 bits. */
112 ovs_u128 ct_label
; /* Connection label. */
113 uint32_t conj_id
; /* Conjunction ID. */
114 ofp_port_t actset_output
; /* Output port in action set. */
116 /* L2, Order the same as in the Ethernet header! (64-bit aligned) */
117 struct eth_addr dl_dst
; /* Ethernet destination address. */
118 struct eth_addr dl_src
; /* Ethernet source address. */
119 ovs_be16 dl_type
; /* Ethernet frame type. */
120 uint8_t pad2
[2]; /* Pad to 64 bits. */
121 union flow_vlan_hdr vlans
[FLOW_MAX_VLAN_HEADERS
]; /* VLANs */
122 ovs_be32 mpls_lse
[ROUND_UP(FLOW_MAX_MPLS_LABELS
, 2)]; /* MPLS label stack
124 /* L3 (64-bit aligned) */
125 ovs_be32 nw_src
; /* IPv4 source address or ARP SPA. */
126 ovs_be32 nw_dst
; /* IPv4 destination address or ARP TPA. */
127 ovs_be32 ct_nw_src
; /* CT orig tuple IPv4 source address. */
128 ovs_be32 ct_nw_dst
; /* CT orig tuple IPv4 destination address. */
129 struct in6_addr ipv6_src
; /* IPv6 source address. */
130 struct in6_addr ipv6_dst
; /* IPv6 destination address. */
131 struct in6_addr ct_ipv6_src
; /* CT orig tuple IPv6 source address. */
132 struct in6_addr ct_ipv6_dst
; /* CT orig tuple IPv6 destination address. */
133 ovs_be32 ipv6_label
; /* IPv6 flow label. */
134 uint8_t nw_frag
; /* FLOW_FRAG_* flags. */
135 uint8_t nw_tos
; /* IP ToS (including DSCP and ECN). */
136 uint8_t nw_ttl
; /* IP TTL/Hop Limit. */
137 uint8_t nw_proto
; /* IP protocol or low 8 bits of ARP opcode. */
138 struct in6_addr nd_target
; /* IPv6 neighbor discovery (ND) target. */
139 struct eth_addr arp_sha
; /* ARP/ND source hardware address. */
140 struct eth_addr arp_tha
; /* ARP/ND target hardware address. */
141 ovs_be16 tcp_flags
; /* TCP flags. With L3 to avoid matching L4. */
142 ovs_be16 pad3
; /* Pad to 64 bits. */
144 /* L4 (64-bit aligned) */
145 ovs_be16 tp_src
; /* TCP/UDP/SCTP source port/ICMP type. */
146 ovs_be16 tp_dst
; /* TCP/UDP/SCTP destination port/ICMP code. */
147 ovs_be16 ct_tp_src
; /* CT original tuple source port/ICMP type. */
148 ovs_be16 ct_tp_dst
; /* CT original tuple dst port/ICMP code. */
149 ovs_be32 igmp_group_ip4
; /* IGMP group IPv4 address.
150 * Keep last for BUILD_ASSERT_DECL below. */
151 ovs_be32 pad4
; /* Pad to 64 bits. */
153 BUILD_ASSERT_DECL(sizeof(struct flow
) % sizeof(uint64_t) == 0);
154 BUILD_ASSERT_DECL(sizeof(struct flow_tnl
) % sizeof(uint64_t) == 0);
156 #define FLOW_U64S (sizeof(struct flow) / sizeof(uint64_t))
158 /* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */
159 BUILD_ASSERT_DECL(offsetof(struct flow
, igmp_group_ip4
) + sizeof(uint32_t)
160 == sizeof(struct flow_tnl
) + 300
161 && FLOW_WC_SEQ
== 38);
163 /* Incremental points at which flow classification may be performed in
165 * This is located here since this is dependent on the structure of the
166 * struct flow defined above:
167 * Each offset must be on a distinct, successive U64 boundary strictly
168 * within the struct flow. */
170 FLOW_SEGMENT_1_ENDS_AT
= offsetof(struct flow
, dl_dst
),
171 FLOW_SEGMENT_2_ENDS_AT
= offsetof(struct flow
, nw_src
),
172 FLOW_SEGMENT_3_ENDS_AT
= offsetof(struct flow
, tp_src
),
174 BUILD_ASSERT_DECL(FLOW_SEGMENT_1_ENDS_AT
% sizeof(uint64_t) == 0);
175 BUILD_ASSERT_DECL(FLOW_SEGMENT_2_ENDS_AT
% sizeof(uint64_t) == 0);
176 BUILD_ASSERT_DECL(FLOW_SEGMENT_3_ENDS_AT
% sizeof(uint64_t) == 0);
177 BUILD_ASSERT_DECL( 0 < FLOW_SEGMENT_1_ENDS_AT
);
178 BUILD_ASSERT_DECL(FLOW_SEGMENT_1_ENDS_AT
< FLOW_SEGMENT_2_ENDS_AT
);
179 BUILD_ASSERT_DECL(FLOW_SEGMENT_2_ENDS_AT
< FLOW_SEGMENT_3_ENDS_AT
);
180 BUILD_ASSERT_DECL(FLOW_SEGMENT_3_ENDS_AT
< sizeof(struct flow
));
182 /* Wildcards for a flow.
184 * A 1-bit in each bit in 'masks' indicates that the corresponding bit of
185 * the flow is significant (must match). A 0-bit indicates that the
186 * corresponding bit of the flow is wildcarded (need not match). */
187 struct flow_wildcards
{
191 #define WC_MASK_FIELD(WC, FIELD) \
192 memset(&(WC)->masks.FIELD, 0xff, sizeof (WC)->masks.FIELD)
193 #define WC_MASK_FIELD_MASK(WC, FIELD, MASK) \
194 ((WC)->masks.FIELD |= (MASK))
195 #define WC_UNMASK_FIELD(WC, FIELD) \
196 memset(&(WC)->masks.FIELD, 0, sizeof (WC)->masks.FIELD)
198 void flow_wildcards_init_catchall(struct flow_wildcards
*);
200 void flow_wildcards_init_for_packet(struct flow_wildcards
*,
201 const struct flow
*);
203 void flow_wildcards_clear_non_packet_fields(struct flow_wildcards
*);
205 bool flow_wildcards_is_catchall(const struct flow_wildcards
*);
207 void flow_wildcards_set_reg_mask(struct flow_wildcards
*,
208 int idx
, uint32_t mask
);
209 void flow_wildcards_set_xreg_mask(struct flow_wildcards
*,
210 int idx
, uint64_t mask
);
211 void flow_wildcards_set_xxreg_mask(struct flow_wildcards
*,
212 int idx
, ovs_u128 mask
);
214 void flow_wildcards_and(struct flow_wildcards
*dst
,
215 const struct flow_wildcards
*src1
,
216 const struct flow_wildcards
*src2
);
217 void flow_wildcards_or(struct flow_wildcards
*dst
,
218 const struct flow_wildcards
*src1
,
219 const struct flow_wildcards
*src2
);
220 bool flow_wildcards_has_extra(const struct flow_wildcards
*,
221 const struct flow_wildcards
*);
222 uint32_t flow_wildcards_hash(const struct flow_wildcards
*, uint32_t basis
);
223 bool flow_wildcards_equal(const struct flow_wildcards
*,
224 const struct flow_wildcards
*);