#ifndef FLOW_H
#define FLOW_H 1
#include <linux/cache.h>
#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/cpumask.h>
#include <net/inet_ecn.h>
#include <net/ip_tunnels.h>
#include <net/dst_metadata.h>
#include <net/nsh.h>
struct sk_buff;
enum sw_flow_mac_proto {
MAC_PROTO_NONE = 0,
MAC_PROTO_ETHERNET,
};
#define SW_FLOW_KEY_INVALID 0x80
#define MPLS_LABEL_DEPTH 3
enum ofp12_ipv6exthdr_flags {
OFPIEH12_NONEXT = 1 << 0,
OFPIEH12_ESP = 1 << 1,
OFPIEH12_AUTH = 1 << 2,
OFPIEH12_DEST = 1 << 3,
OFPIEH12_FRAG = 1 << 4,
OFPIEH12_ROUTER = 1 << 5,
OFPIEH12_HOP = 1 << 6,
OFPIEH12_UNREP = 1 << 7,
OFPIEH12_UNSEQ = 1 << 8
};
#define TUN_METADATA_OFFSET(opt_len) \
(sizeof_field(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)))
struct ovs_tunnel_info {
struct metadata_dst *tun_dst;
};
struct vlan_head {
__be16 tpid;
__be16 tci;
};
#define OVS_SW_FLOW_KEY_METADATA_SIZE \
(offsetof(struct sw_flow_key, recirc_id) + \
sizeof_field(struct sw_flow_key, recirc_id))
struct ovs_key_nsh {
struct ovs_nsh_key_base base;
__be32 context[NSH_MD1_CONTEXT_SIZE];
};
struct sw_flow_key {
u8 tun_opts[IP_TUNNEL_OPTS_MAX];
u8 tun_opts_len;
struct ip_tunnel_key tun_key;
struct {
u32 priority;
u32 skb_mark;
u16 in_port;
} __packed phy;
u8 mac_proto;
u8 tun_proto;
u32 ovs_flow_hash;
u32 recirc_id;
struct {
u8 src[ETH_ALEN];
u8 dst[ETH_ALEN];
struct vlan_head vlan;
struct vlan_head cvlan;
__be16 type;
} eth;
u8 ct_state;
u8 ct_orig_proto;
union {
struct {
u8 proto;
u8 tos;
u8 ttl;
u8 frag;
} ip;
};
u16 ct_zone;
struct {
__be16 src;
__be16 dst;
__be16 flags;
} tp;
union {
struct {
struct {
__be32 src;
__be32 dst;
} addr;
union {
struct {
__be32 src;
__be32 dst;
} ct_orig;
struct {
u8 sha[ETH_ALEN];
u8 tha[ETH_ALEN];
} arp;
};
} ipv4;
struct {
struct {
struct in6_addr src;
struct in6_addr dst;
} addr;
__be32 label;
u16 exthdrs;
union {
struct {
struct in6_addr src;
struct in6_addr dst;
} ct_orig;
struct {
struct in6_addr target;
u8 sll[ETH_ALEN];
u8 tll[ETH_ALEN];
} nd;
};
} ipv6;
struct {
u32 num_labels_mask;
__be32 lse[MPLS_LABEL_DEPTH];
} mpls;
struct ovs_key_nsh nsh;
};
struct {
struct {
__be16 src;
__be16 dst;
} orig_tp;
u32 mark;
struct ovs_key_ct_labels labels;
} ct;
} __aligned(BITS_PER_LONG/8);
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));
}
struct sw_flow_key_range {
unsigned short int start;
unsigned short int end;
};
struct sw_flow_mask {
int ref_count;
struct rcu_head rcu;
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;
};
#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;
};
};
struct sw_flow_actions {
struct rcu_head rcu;
size_t orig_len;
u32 actions_len;
struct nlattr actions[];
};
struct sw_flow_stats {
u64 packet_count;
u64 byte_count;
unsigned long used;
spinlock_t lock;
__be16 tcp_flags;
};
struct sw_flow {
struct rcu_head rcu;
struct {
struct hlist_node node[2];
u32 hash;
} flow_table, ufid_table;
int stats_last_writer;
struct sw_flow_key key;
struct sw_flow_id id;
struct cpumask *cpu_used_mask;
struct sw_flow_mask *mask;
struct sw_flow_actions __rcu *sf_acts;
struct sw_flow_stats __rcu *stats[];
};
struct arp_eth_header {
__be16 ar_hrd;
__be16 ar_pro;
unsigned char ar_hln;
unsigned char ar_pln;
__be16 ar_op;
unsigned char ar_sha[ETH_ALEN];
unsigned char ar_sip[4];
unsigned char ar_tha[ETH_ALEN];
unsigned char ar_tip[4];
} __packed;
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));
}
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);
}
void ovs_flow_stats_update(struct sw_flow *, __be16 tcp_flags,
const struct sk_buff *);
void ovs_flow_stats_get(const struct sw_flow *, struct ovs_flow_stats *,
unsigned long *used, __be16 *tcp_flags);
void ovs_flow_stats_clear(struct sw_flow *);
u64 ovs_flow_used_time(unsigned long flow_jiffies);
int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key);
int ovs_flow_key_update_l3l4(struct sk_buff *skb, struct sw_flow_key *key);
int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
struct sk_buff *skb,
struct sw_flow_key *key);
int ovs_flow_key_extract_userspace(struct net *net, const struct nlattr *attr,
struct sk_buff *skb,
struct sw_flow_key *key, bool log);
#endif /* flow.h */