Blame view
net/openvswitch/flow.h
8.2 KB
ccb1352e7 net: Add Open vSw... |
1 |
/* |
9dd7f8907 openvswitch: Add ... |
2 |
* Copyright (c) 2007-2017 Nicira, Inc. |
ccb1352e7 net: Add Open vSw... |
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
* * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA */ #ifndef FLOW_H #define FLOW_H 1 |
e298e5057 openvswitch: Per ... |
21 |
#include <linux/cache.h> |
ccb1352e7 net: Add Open vSw... |
22 23 24 25 26 27 28 29 30 31 32 |
#include <linux/kernel.h> #include <linux/netlink.h> #include <linux/openvswitch.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/rcupdate.h> #include <linux/if_ether.h> #include <linux/in6.h> #include <linux/jiffies.h> #include <linux/time.h> #include <linux/flex_array.h> |
c4b2bf6b4 openvswitch: Opti... |
33 |
#include <linux/cpumask.h> |
ccb1352e7 net: Add Open vSw... |
34 |
#include <net/inet_ecn.h> |
1d8fff907 ip_tunnel: Make o... |
35 |
#include <net/ip_tunnels.h> |
34ae932a4 openvswitch: Make... |
36 |
#include <net/dst_metadata.h> |
ccb1352e7 net: Add Open vSw... |
37 38 |
struct sk_buff; |
ccb1352e7 net: Add Open vSw... |
39 |
|
329f45bc4 openvswitch: add ... |
40 41 42 43 44 |
enum sw_flow_mac_proto { MAC_PROTO_NONE = 0, MAC_PROTO_ETHERNET, }; #define SW_FLOW_KEY_INVALID 0x80 |
f57966840 openvswitch: Add ... |
45 46 47 48 |
/* Store options at the end of the array if they are less than the * maximum size. This allows us to get the benefits of variable length * matching for small options. */ |
d91641d9b openvswitch: Rena... |
49 50 51 52 |
#define TUN_METADATA_OFFSET(opt_len) \ (FIELD_SIZEOF(struct sw_flow_key, tun_opts) - opt_len) #define TUN_METADATA_OPTS(flow_key, opt_len) \ ((void *)((flow_key)->tun_opts + TUN_METADATA_OFFSET(opt_len))) |
f57966840 openvswitch: Add ... |
53 |
|
34ae932a4 openvswitch: Make... |
54 55 56 |
struct ovs_tunnel_info { struct metadata_dst *tun_dst; }; |
018c1dda5 openvswitch: 802.... |
57 58 59 60 |
struct vlan_head { __be16 tpid; /* Vlan type. Generally 802.1q or 802.1ad.*/ __be16 tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */ }; |
8f0aad6f3 openvswitch: Exte... |
61 62 63 |
#define OVS_SW_FLOW_KEY_METADATA_SIZE \ (offsetof(struct sw_flow_key, recirc_id) + \ FIELD_SIZEOF(struct sw_flow_key, recirc_id)) |
ccb1352e7 net: Add Open vSw... |
64 |
struct sw_flow_key { |
fca5fdf67 ip_tunnels, bpf: ... |
65 |
u8 tun_opts[IP_TUNNEL_OPTS_MAX]; |
f57966840 openvswitch: Add ... |
66 |
u8 tun_opts_len; |
1d8fff907 ip_tunnel: Make o... |
67 |
struct ip_tunnel_key tun_key; /* Encapsulating tunnel key. */ |
ccb1352e7 net: Add Open vSw... |
68 69 |
struct { u32 priority; /* Packet QoS priority. */ |
39c7caebc openvswitch: add ... |
70 |
u32 skb_mark; /* SKB mark. */ |
15eac2a74 openvswitch: Incr... |
71 |
u16 in_port; /* Input switch port (or DP_MAX_PORTS). */ |
1139e241e openvswitch: Comp... |
72 |
} __packed phy; /* Safe when right after 'tun_key'. */ |
329f45bc4 openvswitch: add ... |
73 |
u8 mac_proto; /* MAC layer protocol (e.g. Ethernet). */ |
00a93babd openvswitch: add ... |
74 |
u8 tun_proto; /* Protocol of encapsulating tunnel. */ |
971427f35 openvswitch: Add ... |
75 76 |
u32 ovs_flow_hash; /* Datapath computed hash value. */ u32 recirc_id; /* Recirculation ID. */ |
ccb1352e7 net: Add Open vSw... |
77 78 79 |
struct { u8 src[ETH_ALEN]; /* Ethernet source address. */ u8 dst[ETH_ALEN]; /* Ethernet destination address. */ |
018c1dda5 openvswitch: 802.... |
80 81 |
struct vlan_head vlan; struct vlan_head cvlan; |
ccb1352e7 net: Add Open vSw... |
82 83 |
__be16 type; /* Ethernet frame type. */ } eth; |
316d4d78c openvswitch: Pack... |
84 85 86 87 88 |
/* Filling a hole of two bytes. */ u8 ct_state; u8 ct_orig_proto; /* CT original direction tuple IP * protocol. */ |
25cd9ba0a openvswitch: Add ... |
89 90 91 92 93 94 95 96 97 98 99 |
union { struct { __be32 top_lse; /* top label stack entry */ } mpls; struct { u8 proto; /* IP protocol or lower 8 bits of ARP opcode. */ u8 tos; /* IP ToS. */ u8 ttl; /* IP TTL/hop limit. */ u8 frag; /* One of OVS_FRAG_TYPE_*. */ } ip; }; |
316d4d78c openvswitch: Pack... |
100 |
u16 ct_zone; /* Conntrack zone. */ |
1139e241e openvswitch: Comp... |
101 102 103 104 105 |
struct { __be16 src; /* TCP/UDP/SCTP source port. */ __be16 dst; /* TCP/UDP/SCTP destination port. */ __be16 flags; /* TCP flags. */ } tp; |
ccb1352e7 net: Add Open vSw... |
106 107 108 109 110 111 |
union { struct { struct { __be32 src; /* IP source address. */ __be32 dst; /* IP destination address. */ } addr; |
9dd7f8907 openvswitch: Add ... |
112 113 114 115 116 117 118 119 120 121 |
union { struct { __be32 src; __be32 dst; } ct_orig; /* Conntrack original direction fields. */ struct { u8 sha[ETH_ALEN]; /* ARP source hardware address. */ u8 tha[ETH_ALEN]; /* ARP target hardware address. */ } arp; }; |
ccb1352e7 net: Add Open vSw... |
122 123 124 125 126 127 128 |
} ipv4; struct { struct { struct in6_addr src; /* IPv6 source address. */ struct in6_addr dst; /* IPv6 destination address. */ } addr; __be32 label; /* IPv6 flow label. */ |
9dd7f8907 openvswitch: Add ... |
129 130 131 132 133 134 135 136 137 138 139 |
union { struct { struct in6_addr src; struct in6_addr dst; } ct_orig; /* Conntrack original direction fields. */ struct { struct in6_addr target; /* ND target address. */ u8 sll[ETH_ALEN]; /* ND source link layer address. */ u8 tll[ETH_ALEN]; /* ND target link layer address. */ } nd; }; |
ccb1352e7 net: Add Open vSw... |
140 141 |
} ipv6; }; |
7f8a436ea openvswitch: Add ... |
142 |
struct { |
316d4d78c openvswitch: Pack... |
143 |
/* Connection tracking fields not packed above. */ |
9dd7f8907 openvswitch: Add ... |
144 145 146 147 |
struct { __be16 src; /* CT orig tuple tp src port. */ __be16 dst; /* CT orig tuple tp dst port. */ } orig_tp; |
316d4d78c openvswitch: Pack... |
148 |
u32 mark; |
33db4125e openvswitch: Rena... |
149 |
struct ovs_key_ct_labels labels; |
7f8a436ea openvswitch: Add ... |
150 |
} ct; |
0d40f75bd openvswitch: Fix ... |
151 |
} __aligned(BITS_PER_LONG/8); /* Ensure that we can do comparisons as longs. */ |
ccb1352e7 net: Add Open vSw... |
152 |
|
9dd7f8907 openvswitch: Add ... |
153 154 155 156 157 158 159 160 |
static inline bool sw_flow_key_is_nd(const struct sw_flow_key *key) { return key->eth.type == htons(ETH_P_IPV6) && key->ip.proto == NEXTHDR_ICMP && key->tp.dst == 0 && (key->tp.src == htons(NDISC_NEIGHBOUR_SOLICITATION) || key->tp.src == htons(NDISC_NEIGHBOUR_ADVERTISEMENT)); } |
e64457191 openvswitch: Rest... |
161 |
struct sw_flow_key_range { |
8f49ce113 openvswitch: Shri... |
162 163 |
unsigned short int start; unsigned short int end; |
e64457191 openvswitch: Rest... |
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
}; struct sw_flow_mask { int ref_count; struct rcu_head rcu; struct list_head list; struct sw_flow_key_range range; struct sw_flow_key key; }; struct sw_flow_match { struct sw_flow_key *key; struct sw_flow_key_range range; struct sw_flow_mask *mask; }; |
74ed7ab92 openvswitch: Add ... |
179 180 181 182 183 184 185 186 187 |
#define MAX_UFID_LENGTH 16 /* 128 bits */ struct sw_flow_id { u32 ufid_len; union { u32 ufid[MAX_UFID_LENGTH / 4]; struct sw_flow_key *unmasked_key; }; }; |
e64457191 openvswitch: Rest... |
188 189 |
struct sw_flow_actions { struct rcu_head rcu; |
8e2fed1c0 openvswitch: Seri... |
190 |
size_t orig_len; /* From flow_cmd_new netlink actions size */ |
e64457191 openvswitch: Rest... |
191 192 193 |
u32 actions_len; struct nlattr actions[]; }; |
e298e5057 openvswitch: Per ... |
194 195 196 197 198 199 200 |
struct flow_stats { u64 packet_count; /* Number of packets matched. */ u64 byte_count; /* Number of bytes matched. */ unsigned long used; /* Last used time (in jiffies). */ spinlock_t lock; /* Lock for atomic stats update. */ __be16 tcp_flags; /* Union of seen TCP flags. */ }; |
ccb1352e7 net: Add Open vSw... |
201 202 |
struct sw_flow { struct rcu_head rcu; |
74ed7ab92 openvswitch: Add ... |
203 204 205 206 |
struct { struct hlist_node node[2]; u32 hash; } flow_table, ufid_table; |
db74a3335 openvswitch: use ... |
207 |
int stats_last_writer; /* CPU id of the last writer on |
63e7959c4 openvswitch: Per ... |
208 209 |
* 'stats[0]'. */ |
ccb1352e7 net: Add Open vSw... |
210 |
struct sw_flow_key key; |
74ed7ab92 openvswitch: Add ... |
211 |
struct sw_flow_id id; |
c4b2bf6b4 openvswitch: Opti... |
212 |
struct cpumask cpu_used_mask; |
03f0d916a openvswitch: Mega... |
213 |
struct sw_flow_mask *mask; |
ccb1352e7 net: Add Open vSw... |
214 |
struct sw_flow_actions __rcu *sf_acts; |
db74a3335 openvswitch: use ... |
215 |
struct flow_stats __rcu *stats[]; /* One for each CPU. First one |
63e7959c4 openvswitch: Per ... |
216 217 218 219 |
* is allocated at flow creation time, * the rest are allocated on demand * while holding the 'stats[0].lock'. */ |
ccb1352e7 net: Add Open vSw... |
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
}; struct arp_eth_header { __be16 ar_hrd; /* format of hardware address */ __be16 ar_pro; /* format of protocol address */ unsigned char ar_hln; /* length of hardware address */ unsigned char ar_pln; /* length of protocol address */ __be16 ar_op; /* ARP opcode (command) */ /* Ethernet+IPv4 specific members. */ unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ unsigned char ar_sip[4]; /* sender IP address */ unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ unsigned char ar_tip[4]; /* target IP address */ } __packed; |
329f45bc4 openvswitch: add ... |
235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
static inline u8 ovs_key_mac_proto(const struct sw_flow_key *key) { return key->mac_proto & ~SW_FLOW_KEY_INVALID; } static inline u16 __ovs_mac_header_len(u8 mac_proto) { return mac_proto == MAC_PROTO_ETHERNET ? ETH_HLEN : 0; } static inline u16 ovs_mac_header_len(const struct sw_flow_key *key) { return __ovs_mac_header_len(ovs_key_mac_proto(key)); } |
74ed7ab92 openvswitch: Add ... |
249 250 251 252 253 254 255 256 257 |
static inline bool ovs_identifier_is_ufid(const struct sw_flow_id *sfid) { return sfid->ufid_len; } static inline bool ovs_identifier_is_key(const struct sw_flow_id *sfid) { return !ovs_identifier_is_ufid(sfid); } |
ad5520073 openvswitch: Fix ... |
258 |
void ovs_flow_stats_update(struct sw_flow *, __be16 tcp_flags, |
12eb18f71 openvswitch: Cons... |
259 |
const struct sk_buff *); |
86ec8dbae openvswitch: Fix ... |
260 |
void ovs_flow_stats_get(const struct sw_flow *, struct ovs_flow_stats *, |
e298e5057 openvswitch: Per ... |
261 |
unsigned long *used, __be16 *tcp_flags); |
86ec8dbae openvswitch: Fix ... |
262 |
void ovs_flow_stats_clear(struct sw_flow *); |
ccb1352e7 net: Add Open vSw... |
263 |
u64 ovs_flow_used_time(unsigned long flow_jiffies); |
ccb1352e7 net: Add Open vSw... |
264 |
|
971427f35 openvswitch: Add ... |
265 |
int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key); |
1d8fff907 ip_tunnel: Make o... |
266 |
int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info, |
12eb18f71 openvswitch: Cons... |
267 |
struct sk_buff *skb, |
f0b128c1e openvswitch: Wrap... |
268 |
struct sw_flow_key *key); |
83c8df26a openvswitch: refa... |
269 |
/* Extract key from packet coming from userspace. */ |
c2ac66735 openvswitch: Allo... |
270 |
int ovs_flow_key_extract_userspace(struct net *net, const struct nlattr *attr, |
83c8df26a openvswitch: refa... |
271 |
struct sk_buff *skb, |
05da5898a openvswitch: Add ... |
272 |
struct sw_flow_key *key, bool log); |
03f0d916a openvswitch: Mega... |
273 |
|
ccb1352e7 net: Add Open vSw... |
274 |
#endif /* flow.h */ |