2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
3 * Distributed under the terms of the GNU GPL version 2.
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
12 #include <linux/kernel.h>
13 #include <linux/netlink.h>
14 #include <linux/spinlock.h>
15 #include <linux/types.h>
16 #include <linux/rcupdate.h>
17 #include <linux/if_ether.h>
18 #include <linux/in6.h>
19 #include <linux/jiffies.h>
20 #include <linux/time.h>
22 #include "openvswitch/datapath-protocol.h"
27 struct sw_flow_actions {
30 struct nlattr actions[];
34 __be64 tun_id; /* Encapsulating tunnel ID. */
37 __be32 ipv4_src; /* IPv4 source address. */
38 __be32 ipv4_dst; /* IPv4 destination address. */
41 struct in6_addr ipv6_src; /* IPv6 source address. */
42 struct in6_addr ipv6_dst; /* IPv6 source address. */
45 struct in6_addr nd_target; /* IPv6 ND target address. */
46 u16 in_port; /* Input switch port. */
47 __be16 dl_tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
48 __be16 dl_type; /* Ethernet frame type. */
49 __be16 tp_src; /* TCP/UDP source port. */
50 __be16 tp_dst; /* TCP/UDP destination port. */
51 u8 dl_src[ETH_ALEN]; /* Ethernet source address. */
52 u8 dl_dst[ETH_ALEN]; /* Ethernet destination address. */
53 u8 nw_proto; /* IP protocol or lower 8 bits of ARP opcode. */
54 u8 nw_tos; /* IP ToS (DSCP field, 6 bits). */
55 u8 arp_sha[ETH_ALEN]; /* ARP/ND source hardware address. */
56 u8 arp_tha[ETH_ALEN]; /* ARP/ND target hardware address. */
61 struct tbl_node tbl_node;
63 struct sw_flow_key key;
64 struct sw_flow_actions __rcu *sf_acts;
69 spinlock_t lock; /* Lock for values below. */
70 unsigned long used; /* Last used time (in jiffies). */
71 u64 packet_count; /* Number of packets matched. */
72 u64 byte_count; /* Number of bytes matched. */
73 u8 tcp_flags; /* Union of seen TCP flags. */
78 __be16 ar_hrd; /* format of hardware address */
79 __be16 ar_pro; /* format of protocol address */
80 unsigned char ar_hln; /* length of hardware address */
81 unsigned char ar_pln; /* length of protocol address */
82 __be16 ar_op; /* ARP opcode (command) */
84 /* Ethernet+IPv4 specific members. */
85 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
86 unsigned char ar_sip[4]; /* sender IP address */
87 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
88 unsigned char ar_tip[4]; /* target IP address */
94 struct sw_flow *flow_alloc(void);
95 void flow_deferred_free(struct sw_flow *);
96 void flow_free_tbl(struct tbl_node *);
98 struct sw_flow_actions *flow_actions_alloc(const struct nlattr *);
99 void flow_deferred_free_acts(struct sw_flow_actions *);
101 void flow_hold(struct sw_flow *);
102 void flow_put(struct sw_flow *);
104 int flow_extract(struct sk_buff *, u16 in_port, struct sw_flow_key *, bool *is_frag);
105 void flow_used(struct sw_flow *, struct sk_buff *);
106 u64 flow_used_time(unsigned long flow_jiffies);
108 u32 flow_hash(const struct sw_flow_key *);
109 int flow_cmp(const struct tbl_node *, void *target);
111 /* Upper bound on the length of a nlattr-formatted flow key. The longest
112 * nlattr-formatted flow key would be:
114 * struct pad nl hdr total
115 * ------ --- ------ -----
116 * ODP_KEY_ATTR_TUN_ID 8 -- 4 12
117 * ODP_KEY_ATTR_IN_PORT 4 -- 4 8
118 * ODP_KEY_ATTR_ETHERNET 12 -- 4 16
119 * ODP_KEY_ATTR_8021Q 4 -- 4 8
120 * ODP_KEY_ATTR_ETHERTYPE 2 2 4 8
121 * ODP_KEY_ATTR_IPV6 34 2 4 40
122 * ODP_KEY_ATTR_ICMPV6 2 2 4 8
123 * ODP_KEY_ATTR_ND 28 -- 4 32
124 * -------------------------------------------------
127 #define FLOW_BUFSIZE 132
129 int flow_to_nlattrs(const struct sw_flow_key *, struct sk_buff *);
130 int flow_from_nlattrs(struct sw_flow_key *swkey, const struct nlattr *);
132 static inline struct sw_flow *flow_cast(const struct tbl_node *node)
134 return container_of(node, struct sw_flow, tbl_node);