dpif-netdev: Change pmd thread configuration in dpif_netdev_run().
[cascardo/ovs.git] / lib / netdev-native-tnl.h
1 /*
2  * Copyright (c) 2010, 2011, 2013, 2015 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef NETDEV_VPORT_NATIVE_TNL_H
18 #define NETDEV_VPORT_NATIVE_TNL_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include "compiler.h"
23 #include "unixctl.h"
24
25 int
26 netdev_gre_build_header(const struct netdev *netdev,
27                         struct ovs_action_push_tnl *data,
28                         const struct flow *tnl_flow);
29 void
30 netdev_gre_push_header(struct dp_packet *packet,
31                        const struct ovs_action_push_tnl *data);
32 struct dp_packet *
33 netdev_gre_pop_header(struct dp_packet *packet);
34
35 void
36 netdev_tnl_push_udp_header(struct dp_packet *packet,
37                            const struct ovs_action_push_tnl *data);
38 int
39 netdev_geneve_build_header(const struct netdev *netdev,
40                            struct ovs_action_push_tnl *data,
41                            const struct flow *tnl_flow);
42 struct dp_packet *
43 netdev_geneve_pop_header(struct dp_packet *packet);
44
45 int
46 netdev_vxlan_build_header(const struct netdev *netdev,
47                           struct ovs_action_push_tnl *data,
48                           const struct flow *tnl_flow);
49 struct dp_packet *
50 netdev_vxlan_pop_header(struct dp_packet *packet);
51
52 static inline bool
53 netdev_tnl_is_header_ipv6(const void *header)
54 {
55     const struct eth_header *eth;
56     eth = header;
57     return eth->eth_type == htons(ETH_TYPE_IPV6);
58 }
59
60 static inline struct ip_header *
61 netdev_tnl_ip_hdr(void *eth)
62 {
63     return (void *)((char *)eth + sizeof (struct eth_header));
64 }
65
66 static inline struct ovs_16aligned_ip6_hdr *
67 netdev_tnl_ipv6_hdr(void *eth)
68 {
69     return (void *)((char *)eth + sizeof (struct eth_header));
70 }
71
72 extern uint16_t tnl_udp_port_min;
73 extern uint16_t tnl_udp_port_max;
74
75 static inline ovs_be16
76 netdev_tnl_get_src_port(struct dp_packet *packet)
77 {
78     uint32_t hash;
79
80     hash = dp_packet_get_rss_hash(packet);
81
82     return htons((((uint64_t) hash * (tnl_udp_port_max - tnl_udp_port_min)) >> 32) +
83                  tnl_udp_port_min);
84 }
85
86 void *
87 netdev_tnl_ip_extract_tnl_md(struct dp_packet *packet, struct flow_tnl *tnl,
88                              unsigned int *hlen);
89 void *
90 netdev_tnl_push_ip_header(struct dp_packet *packet,
91                           const void *header, int size, int *ip_tot_size);
92 void
93 netdev_tnl_egress_port_range(struct unixctl_conn *conn, int argc,
94                              const char *argv[], void *aux OVS_UNUSED);
95 #endif