]> git.proxmox.com Git - ovs.git/blame - datapath/flow.h
nicira-ext: Support matching IPv6 Neighbor Discovery messages.
[ovs.git] / datapath / flow.h
CommitLineData
a14bc59f 1/*
d6569377 2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
a14bc59f
BP
3 * Distributed under the terms of the GNU GPL version 2.
4 *
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
7 */
8
064af421
BP
9#ifndef FLOW_H
10#define FLOW_H 1
11
12#include <linux/kernel.h>
78d18dbb 13#include <linux/netlink.h>
064af421
BP
14#include <linux/spinlock.h>
15#include <linux/types.h>
16#include <linux/rcupdate.h>
401eeb92 17#include <linux/if_ether.h>
6bfafa55 18#include <linux/jiffies.h>
5153ef3d 19#include <linux/time.h>
064af421
BP
20
21#include "openvswitch/datapath-protocol.h"
8d5ebd83 22#include "table.h"
064af421
BP
23
24struct sk_buff;
25
26struct sw_flow_actions {
27 struct rcu_head rcu;
cdee00fd
BP
28 u32 actions_len;
29 struct nlattr actions[];
064af421
BP
30};
31
36956a7d
BP
32struct sw_flow_key {
33 __be64 tun_id; /* Encapsulating tunnel ID. */
d31f1109
JP
34 union {
35 struct {
36 __be32 ipv4_src; /* IPv4 source address. */
37 __be32 ipv4_dst; /* IPv4 destination address. */
38 };
39 struct {
40 __be32 ipv6_src[4]; /* IPv6 source address. */
41 __be32 ipv6_dst[4]; /* IPv6 source address. */
42 };
43 };
685a51a5 44 __be32 nd_target[4]; /* IPv6 ND target address. */
36956a7d
BP
45 u16 in_port; /* Input switch port. */
46 __be16 dl_tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
47 __be16 dl_type; /* Ethernet frame type. */
48 __be16 tp_src; /* TCP/UDP source port. */
49 __be16 tp_dst; /* TCP/UDP destination port. */
50 u8 dl_src[ETH_ALEN]; /* Ethernet source address. */
51 u8 dl_dst[ETH_ALEN]; /* Ethernet destination address. */
52 u8 nw_proto; /* IP protocol or lower 8 bits of ARP opcode. */
53 u8 nw_tos; /* IP ToS (DSCP field, 6 bits). */
685a51a5
JP
54 u8 arp_sha[ETH_ALEN]; /* ARP/ND source hardware address. */
55 u8 arp_tha[ETH_ALEN]; /* ARP/ND target hardware address. */
36956a7d
BP
56};
57
064af421
BP
58struct sw_flow {
59 struct rcu_head rcu;
8d5ebd83
JG
60 struct tbl_node tbl_node;
61
36956a7d 62 struct sw_flow_key key;
e1040c77 63 struct sw_flow_actions __rcu *sf_acts;
064af421 64
fb8c9347
JG
65 atomic_t refcnt;
66 bool dead;
67
064af421 68 spinlock_t lock; /* Lock for values below. */
6bfafa55 69 unsigned long used; /* Last used time (in jiffies). */
064af421
BP
70 u64 packet_count; /* Number of packets matched. */
71 u64 byte_count; /* Number of bytes matched. */
72 u8 tcp_flags; /* Union of seen TCP flags. */
73};
74
401eeb92
BP
75struct arp_eth_header
76{
77 __be16 ar_hrd; /* format of hardware address */
78 __be16 ar_pro; /* format of protocol address */
79 unsigned char ar_hln; /* length of hardware address */
80 unsigned char ar_pln; /* length of protocol address */
81 __be16 ar_op; /* ARP opcode (command) */
82
83 /* Ethernet+IPv4 specific members. */
84 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
85 unsigned char ar_sip[4]; /* sender IP address */
86 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
87 unsigned char ar_tip[4]; /* target IP address */
961703de 88} __packed;
401eeb92 89
560e8022
JG
90int flow_init(void);
91void flow_exit(void);
064af421 92
560e8022 93struct sw_flow *flow_alloc(void);
064af421 94void flow_deferred_free(struct sw_flow *);
560e8022
JG
95void flow_free_tbl(struct tbl_node *);
96
37a1300c 97struct sw_flow_actions *flow_actions_alloc(const struct nlattr *);
064af421 98void flow_deferred_free_acts(struct sw_flow_actions *);
560e8022 99
fb8c9347
JG
100void flow_hold(struct sw_flow *);
101void flow_put(struct sw_flow *);
102
36956a7d 103int flow_extract(struct sk_buff *, u16 in_port, struct sw_flow_key *, bool *is_frag);
064af421 104void flow_used(struct sw_flow *, struct sk_buff *);
ec58547a 105u64 flow_used_time(unsigned long flow_jiffies);
064af421 106
36956a7d 107u32 flow_hash(const struct sw_flow_key *);
8d5ebd83 108int flow_cmp(const struct tbl_node *, void *target);
064af421 109
36956a7d
BP
110/* By my calculations currently the longest valid nlattr-formatted flow key is
111 * 80 bytes long, so this leaves some safety margin.
112 */
113#define FLOW_BUFSIZE 96
114
d6569377
BP
115int flow_to_nlattrs(const struct sw_flow_key *, struct sk_buff *);
116int flow_from_nlattrs(struct sw_flow_key *swkey, const struct nlattr *);
36956a7d 117
9d209493
BP
118static inline struct sw_flow *flow_cast(const struct tbl_node *node)
119{
120 return container_of(node, struct sw_flow, tbl_node);
121}
122
064af421 123#endif /* flow.h */