0001
0002
0003
0004
0005
0006 #ifndef FLOW_H
0007 #define FLOW_H 1
0008
0009 #include <linux/cache.h>
0010 #include <linux/kernel.h>
0011 #include <linux/netlink.h>
0012 #include <linux/openvswitch.h>
0013 #include <linux/spinlock.h>
0014 #include <linux/types.h>
0015 #include <linux/rcupdate.h>
0016 #include <linux/if_ether.h>
0017 #include <linux/in6.h>
0018 #include <linux/jiffies.h>
0019 #include <linux/time.h>
0020 #include <linux/cpumask.h>
0021 #include <net/inet_ecn.h>
0022 #include <net/ip_tunnels.h>
0023 #include <net/dst_metadata.h>
0024 #include <net/nsh.h>
0025
0026 struct sk_buff;
0027
0028 enum sw_flow_mac_proto {
0029 MAC_PROTO_NONE = 0,
0030 MAC_PROTO_ETHERNET,
0031 };
0032 #define SW_FLOW_KEY_INVALID 0x80
0033 #define MPLS_LABEL_DEPTH 3
0034
0035
0036 enum ofp12_ipv6exthdr_flags {
0037 OFPIEH12_NONEXT = 1 << 0,
0038 OFPIEH12_ESP = 1 << 1,
0039 OFPIEH12_AUTH = 1 << 2,
0040 OFPIEH12_DEST = 1 << 3,
0041 OFPIEH12_FRAG = 1 << 4,
0042 OFPIEH12_ROUTER = 1 << 5,
0043 OFPIEH12_HOP = 1 << 6,
0044 OFPIEH12_UNREP = 1 << 7,
0045 OFPIEH12_UNSEQ = 1 << 8
0046 };
0047
0048
0049
0050
0051
0052 #define TUN_METADATA_OFFSET(opt_len) \
0053 (sizeof_field(struct sw_flow_key, tun_opts) - opt_len)
0054 #define TUN_METADATA_OPTS(flow_key, opt_len) \
0055 ((void *)((flow_key)->tun_opts + TUN_METADATA_OFFSET(opt_len)))
0056
0057 struct ovs_tunnel_info {
0058 struct metadata_dst *tun_dst;
0059 };
0060
0061 struct vlan_head {
0062 __be16 tpid;
0063 __be16 tci;
0064 };
0065
0066 #define OVS_SW_FLOW_KEY_METADATA_SIZE \
0067 (offsetof(struct sw_flow_key, recirc_id) + \
0068 sizeof_field(struct sw_flow_key, recirc_id))
0069
0070 struct ovs_key_nsh {
0071 struct ovs_nsh_key_base base;
0072 __be32 context[NSH_MD1_CONTEXT_SIZE];
0073 };
0074
0075 struct sw_flow_key {
0076 u8 tun_opts[IP_TUNNEL_OPTS_MAX];
0077 u8 tun_opts_len;
0078 struct ip_tunnel_key tun_key;
0079 struct {
0080 u32 priority;
0081 u32 skb_mark;
0082 u16 in_port;
0083 } __packed phy;
0084 u8 mac_proto;
0085 u8 tun_proto;
0086 u32 ovs_flow_hash;
0087 u32 recirc_id;
0088 struct {
0089 u8 src[ETH_ALEN];
0090 u8 dst[ETH_ALEN];
0091 struct vlan_head vlan;
0092 struct vlan_head cvlan;
0093 __be16 type;
0094 } eth;
0095
0096 u8 ct_state;
0097 u8 ct_orig_proto;
0098
0099
0100 union {
0101 struct {
0102 u8 proto;
0103 u8 tos;
0104 u8 ttl;
0105 u8 frag;
0106 } ip;
0107 };
0108 u16 ct_zone;
0109 struct {
0110 __be16 src;
0111 __be16 dst;
0112 __be16 flags;
0113 } tp;
0114 union {
0115 struct {
0116 struct {
0117 __be32 src;
0118 __be32 dst;
0119 } addr;
0120 union {
0121 struct {
0122 __be32 src;
0123 __be32 dst;
0124 } ct_orig;
0125 struct {
0126 u8 sha[ETH_ALEN];
0127 u8 tha[ETH_ALEN];
0128 } arp;
0129 };
0130 } ipv4;
0131 struct {
0132 struct {
0133 struct in6_addr src;
0134 struct in6_addr dst;
0135 } addr;
0136 __be32 label;
0137 u16 exthdrs;
0138 union {
0139 struct {
0140 struct in6_addr src;
0141 struct in6_addr dst;
0142 } ct_orig;
0143 struct {
0144 struct in6_addr target;
0145 u8 sll[ETH_ALEN];
0146 u8 tll[ETH_ALEN];
0147 } nd;
0148 };
0149 } ipv6;
0150 struct {
0151 u32 num_labels_mask;
0152 __be32 lse[MPLS_LABEL_DEPTH];
0153 } mpls;
0154
0155 struct ovs_key_nsh nsh;
0156 };
0157 struct {
0158
0159 struct {
0160 __be16 src;
0161 __be16 dst;
0162 } orig_tp;
0163 u32 mark;
0164 struct ovs_key_ct_labels labels;
0165 } ct;
0166
0167 } __aligned(BITS_PER_LONG/8);
0168
0169 static inline bool sw_flow_key_is_nd(const struct sw_flow_key *key)
0170 {
0171 return key->eth.type == htons(ETH_P_IPV6) &&
0172 key->ip.proto == NEXTHDR_ICMP &&
0173 key->tp.dst == 0 &&
0174 (key->tp.src == htons(NDISC_NEIGHBOUR_SOLICITATION) ||
0175 key->tp.src == htons(NDISC_NEIGHBOUR_ADVERTISEMENT));
0176 }
0177
0178 struct sw_flow_key_range {
0179 unsigned short int start;
0180 unsigned short int end;
0181 };
0182
0183 struct sw_flow_mask {
0184 int ref_count;
0185 struct rcu_head rcu;
0186 struct sw_flow_key_range range;
0187 struct sw_flow_key key;
0188 };
0189
0190 struct sw_flow_match {
0191 struct sw_flow_key *key;
0192 struct sw_flow_key_range range;
0193 struct sw_flow_mask *mask;
0194 };
0195
0196 #define MAX_UFID_LENGTH 16
0197
0198 struct sw_flow_id {
0199 u32 ufid_len;
0200 union {
0201 u32 ufid[MAX_UFID_LENGTH / 4];
0202 struct sw_flow_key *unmasked_key;
0203 };
0204 };
0205
0206 struct sw_flow_actions {
0207 struct rcu_head rcu;
0208 size_t orig_len;
0209 u32 actions_len;
0210 struct nlattr actions[];
0211 };
0212
0213 struct sw_flow_stats {
0214 u64 packet_count;
0215 u64 byte_count;
0216 unsigned long used;
0217 spinlock_t lock;
0218 __be16 tcp_flags;
0219 };
0220
0221 struct sw_flow {
0222 struct rcu_head rcu;
0223 struct {
0224 struct hlist_node node[2];
0225 u32 hash;
0226 } flow_table, ufid_table;
0227 int stats_last_writer;
0228
0229
0230 struct sw_flow_key key;
0231 struct sw_flow_id id;
0232 struct cpumask cpu_used_mask;
0233 struct sw_flow_mask *mask;
0234 struct sw_flow_actions __rcu *sf_acts;
0235 struct sw_flow_stats __rcu *stats[];
0236
0237
0238
0239
0240 };
0241
0242 struct arp_eth_header {
0243 __be16 ar_hrd;
0244 __be16 ar_pro;
0245 unsigned char ar_hln;
0246 unsigned char ar_pln;
0247 __be16 ar_op;
0248
0249
0250 unsigned char ar_sha[ETH_ALEN];
0251 unsigned char ar_sip[4];
0252 unsigned char ar_tha[ETH_ALEN];
0253 unsigned char ar_tip[4];
0254 } __packed;
0255
0256 static inline u8 ovs_key_mac_proto(const struct sw_flow_key *key)
0257 {
0258 return key->mac_proto & ~SW_FLOW_KEY_INVALID;
0259 }
0260
0261 static inline u16 __ovs_mac_header_len(u8 mac_proto)
0262 {
0263 return mac_proto == MAC_PROTO_ETHERNET ? ETH_HLEN : 0;
0264 }
0265
0266 static inline u16 ovs_mac_header_len(const struct sw_flow_key *key)
0267 {
0268 return __ovs_mac_header_len(ovs_key_mac_proto(key));
0269 }
0270
0271 static inline bool ovs_identifier_is_ufid(const struct sw_flow_id *sfid)
0272 {
0273 return sfid->ufid_len;
0274 }
0275
0276 static inline bool ovs_identifier_is_key(const struct sw_flow_id *sfid)
0277 {
0278 return !ovs_identifier_is_ufid(sfid);
0279 }
0280
0281 void ovs_flow_stats_update(struct sw_flow *, __be16 tcp_flags,
0282 const struct sk_buff *);
0283 void ovs_flow_stats_get(const struct sw_flow *, struct ovs_flow_stats *,
0284 unsigned long *used, __be16 *tcp_flags);
0285 void ovs_flow_stats_clear(struct sw_flow *);
0286 u64 ovs_flow_used_time(unsigned long flow_jiffies);
0287
0288 int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key);
0289 int ovs_flow_key_update_l3l4(struct sk_buff *skb, struct sw_flow_key *key);
0290 int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
0291 struct sk_buff *skb,
0292 struct sw_flow_key *key);
0293
0294 int ovs_flow_key_extract_userspace(struct net *net, const struct nlattr *attr,
0295 struct sk_buff *skb,
0296 struct sw_flow_key *key, bool log);
0297
0298 #endif