]>
Commit | Line | Data |
---|---|---|
9583bc14 EJ |
1 | /* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc. |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at: | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. */ | |
14 | ||
15 | #ifndef OFPROT_DPIF_XLATE_H | |
16 | #define OFPROT_DPIF_XLATE_H 1 | |
17 | ||
18 | #include "flow.h" | |
19 | #include "meta-flow.h" | |
20 | #include "odp-util.h" | |
21 | #include "ofpbuf.h" | |
22 | #include "ofproto-dpif.h" | |
23 | #include "tag.h" | |
24 | ||
25 | /* Maximum depth of flow table recursion (due to resubmit actions) in a | |
26 | * flow translation. */ | |
27 | #define MAX_RESUBMIT_RECURSION 64 | |
28 | ||
29 | struct xlate_ctx; | |
30 | ||
31 | struct xlate_out { | |
32 | /* Wildcards relevant in translation. Any fields that were used to | |
33 | * calculate the action must be set for caching and kernel | |
34 | * wildcarding to work. For example, if the flow lookup involved | |
35 | * performing the "normal" action on IPv4 and ARP packets, 'wc' | |
36 | * would have the 'in_port' (always set), 'dl_type' (flow match), | |
37 | * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields | |
38 | * set. */ | |
39 | struct flow_wildcards wc; | |
40 | ||
41 | tag_type tags; /* Tags associated with actions. */ | |
42 | enum slow_path_reason slow; /* 0 if fast path may be used. */ | |
43 | bool has_learn; /* Actions include NXAST_LEARN? */ | |
44 | bool has_normal; /* Actions output to OFPP_NORMAL? */ | |
45 | bool has_fin_timeout; /* Actions include NXAST_FIN_TIMEOUT? */ | |
46 | uint16_t nf_output_iface; /* Output interface index for NetFlow. */ | |
47 | mirror_mask_t mirrors; /* Bitmap of associated mirrors. */ | |
48 | ||
49 | uint64_t odp_actions_stub[256 / 8]; | |
50 | struct ofpbuf odp_actions; | |
51 | }; | |
52 | ||
53 | struct xlate_in { | |
54 | struct ofproto_dpif *ofproto; | |
55 | ||
56 | /* Flow to which the OpenFlow actions apply. xlate_actions() will modify | |
57 | * this flow when actions change header fields. */ | |
58 | struct flow flow; | |
59 | ||
60 | /* The packet corresponding to 'flow', or a null pointer if we are | |
61 | * revalidating without a packet to refer to. */ | |
62 | const struct ofpbuf *packet; | |
63 | ||
64 | /* Should OFPP_NORMAL update the MAC learning table? Should "learn" | |
65 | * actions update the flow table? | |
66 | * | |
67 | * We want to update these tables if we are actually processing a packet, | |
68 | * or if we are accounting for packets that the datapath has processed, but | |
69 | * not if we are just revalidating. */ | |
70 | bool may_learn; | |
71 | ||
72 | /* The rule initiating translation or NULL. */ | |
73 | struct rule_dpif *rule; | |
74 | ||
75 | /* The actions to translate. If 'rule' is not NULL, these may be NULL. */ | |
76 | const struct ofpact *ofpacts; | |
77 | size_t ofpacts_len; | |
78 | ||
79 | /* Union of the set of TCP flags seen so far in this flow. (Used only by | |
80 | * NXAST_FIN_TIMEOUT. Set to zero to avoid updating updating rules' | |
81 | * timeouts.) */ | |
82 | uint8_t tcp_flags; | |
83 | ||
84 | /* If nonnull, flow translation calls this function just before executing a | |
85 | * resubmit or OFPP_TABLE action. In addition, disables logging of traces | |
86 | * when the recursion depth is exceeded. | |
87 | * | |
88 | * 'rule' is the rule being submitted into. It will be null if the | |
89 | * resubmit or OFPP_TABLE action didn't find a matching rule. | |
90 | * | |
91 | * This is normally null so the client has to set it manually after | |
92 | * calling xlate_in_init(). */ | |
93 | void (*resubmit_hook)(struct xlate_ctx *, struct rule_dpif *rule); | |
94 | ||
95 | /* If nonnull, flow translation calls this function to report some | |
96 | * significant decision, e.g. to explain why OFPP_NORMAL translation | |
97 | * dropped a packet. */ | |
98 | void (*report_hook)(struct xlate_ctx *, const char *s); | |
99 | ||
100 | /* If nonnull, flow translation credits the specified statistics to each | |
101 | * rule reached through a resubmit or OFPP_TABLE action. | |
102 | * | |
103 | * This is normally null so the client has to set it manually after | |
104 | * calling xlate_in_init(). */ | |
105 | const struct dpif_flow_stats *resubmit_stats; | |
106 | }; | |
107 | ||
108 | /* Context used by xlate_actions() and its callees. */ | |
109 | struct xlate_ctx { | |
110 | struct xlate_in *xin; | |
111 | struct xlate_out *xout; | |
112 | ||
113 | struct ofproto_dpif *ofproto; | |
114 | ||
115 | /* Flow at the last commit. */ | |
116 | struct flow base_flow; | |
117 | ||
118 | /* Tunnel IP destination address as received. This is stored separately | |
119 | * as the base_flow.tunnel is cleared on init to reflect the datapath | |
120 | * behavior. Used to make sure not to send tunneled output to ourselves, | |
121 | * which might lead to an infinite loop. This could happen easily | |
122 | * if a tunnel is marked as 'ip_remote=flow', and the flow does not | |
123 | * actually set the tun_dst field. */ | |
124 | ovs_be32 orig_tunnel_ip_dst; | |
125 | ||
126 | /* Stack for the push and pop actions. Each stack element is of type | |
127 | * "union mf_subvalue". */ | |
128 | union mf_subvalue init_stack[1024 / sizeof(union mf_subvalue)]; | |
129 | struct ofpbuf stack; | |
130 | ||
131 | /* The rule that we are currently translating, or NULL. */ | |
132 | struct rule_dpif *rule; | |
133 | ||
134 | int recurse; /* Recursion level, via xlate_table_action. */ | |
135 | bool max_resubmit_trigger; /* Recursed too deeply during translation. */ | |
136 | uint32_t orig_skb_priority; /* Priority when packet arrived. */ | |
137 | uint8_t table_id; /* OpenFlow table ID where flow was found. */ | |
138 | uint32_t sflow_n_outputs; /* Number of output ports. */ | |
139 | uint32_t sflow_odp_port; /* Output port for composing sFlow action. */ | |
140 | uint16_t user_cookie_offset;/* Used for user_action_cookie fixup. */ | |
141 | bool exit; /* No further actions should be processed. */ | |
142 | }; | |
143 | ||
144 | void xlate_actions(struct xlate_in *, struct xlate_out *); | |
145 | void xlate_in_init(struct xlate_in *, struct ofproto_dpif *, | |
146 | const struct flow *, struct rule_dpif *, | |
147 | uint8_t tcp_flags, const struct ofpbuf *packet); | |
148 | void xlate_out_uninit(struct xlate_out *); | |
149 | void xlate_actions_for_side_effects(struct xlate_in *); | |
150 | void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src); | |
151 | ||
152 | #endif /* ofproto-dpif-xlate.h */ |