netdev-native-tnl: Introduce ip_build_header()
[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 netdev_tnl_build_header_params *params);
29
30 void
31 netdev_gre_push_header(struct dp_packet *packet,
32                        const struct ovs_action_push_tnl *data);
33 struct dp_packet *
34 netdev_gre_pop_header(struct dp_packet *packet);
35
36 void
37 netdev_tnl_push_udp_header(struct dp_packet *packet,
38                            const struct ovs_action_push_tnl *data);
39 int
40 netdev_geneve_build_header(const struct netdev *netdev,
41                            struct ovs_action_push_tnl *data,
42                            const struct netdev_tnl_build_header_params *params);
43
44 struct dp_packet *
45 netdev_geneve_pop_header(struct dp_packet *packet);
46
47 int
48 netdev_vxlan_build_header(const struct netdev *netdev,
49                           struct ovs_action_push_tnl *data,
50                           const struct netdev_tnl_build_header_params *params);
51
52 struct dp_packet *
53 netdev_vxlan_pop_header(struct dp_packet *packet);
54
55 static inline bool
56 netdev_tnl_is_header_ipv6(const void *header)
57 {
58     const struct eth_header *eth;
59     eth = header;
60     return eth->eth_type == htons(ETH_TYPE_IPV6);
61 }
62
63 static inline struct ip_header *
64 netdev_tnl_ip_hdr(void *eth)
65 {
66     return (void *)((char *)eth + sizeof (struct eth_header));
67 }
68
69 static inline struct ovs_16aligned_ip6_hdr *
70 netdev_tnl_ipv6_hdr(void *eth)
71 {
72     return (void *)((char *)eth + sizeof (struct eth_header));
73 }
74
75 void *
76 netdev_tnl_ip_build_header(struct ovs_action_push_tnl *data,
77                            const struct netdev_tnl_build_header_params *params,
78                            uint8_t next_proto);
79
80 extern uint16_t tnl_udp_port_min;
81 extern uint16_t tnl_udp_port_max;
82
83 static inline ovs_be16
84 netdev_tnl_get_src_port(struct dp_packet *packet)
85 {
86     uint32_t hash;
87
88     hash = dp_packet_get_rss_hash(packet);
89
90     return htons((((uint64_t) hash * (tnl_udp_port_max - tnl_udp_port_min)) >> 32) +
91                  tnl_udp_port_min);
92 }
93
94 void *
95 netdev_tnl_ip_extract_tnl_md(struct dp_packet *packet, struct flow_tnl *tnl,
96                              unsigned int *hlen);
97 void *
98 netdev_tnl_push_ip_header(struct dp_packet *packet,
99                           const void *header, int size, int *ip_tot_size);
100 void
101 netdev_tnl_egress_port_range(struct unixctl_conn *conn, int argc,
102                              const char *argv[], void *aux OVS_UNUSED);
103 #endif