summaryrefslogtreecommitdiff
path: root/lib/netdev-native-tnl.h
blob: 4dad8f978cc69588c3bee3cffaebde4065cb77d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * Copyright (c) 2010, 2011, 2013, 2015 Nicira, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NETDEV_VPORT_NATIVE_TNL_H
#define NETDEV_VPORT_NATIVE_TNL_H 1

#include <stdbool.h>
#include <stddef.h>
#include "compiler.h"
#include "dp-packet.h"
#include "packets.h"
#include "unixctl.h"

struct netdev;
struct ovs_action_push_tnl;
struct netdev_tnl_build_header_params;

int
netdev_gre_build_header(const struct netdev *netdev,
                        struct ovs_action_push_tnl *data,
                        const struct netdev_tnl_build_header_params *params);

void
netdev_gre_push_header(const struct netdev *netdev,
                       struct dp_packet *packet,
                       const struct ovs_action_push_tnl *data);
struct dp_packet *
netdev_gre_pop_header(struct dp_packet *packet);

int
netdev_erspan_build_header(const struct netdev *netdev,
                           struct ovs_action_push_tnl *data,
                           const struct netdev_tnl_build_header_params *p);

void
netdev_erspan_push_header(const struct netdev *netdev,
                          struct dp_packet *packet,
                          const struct ovs_action_push_tnl *data);
struct dp_packet *
netdev_erspan_pop_header(struct dp_packet *packet);

struct dp_packet *
netdev_gtpu_pop_header(struct dp_packet *packet);

void
netdev_gtpu_push_header(const struct netdev *netdev,
                        struct dp_packet *packet,
                        const struct ovs_action_push_tnl *data);

int
netdev_gtpu_build_header(const struct netdev *netdev,
                         struct ovs_action_push_tnl *data,
                         const struct netdev_tnl_build_header_params *p);

struct dp_packet *netdev_srv6_pop_header(struct dp_packet *);

void netdev_srv6_push_header(const struct netdev *,
                             struct dp_packet *,
                             const struct ovs_action_push_tnl *);

int netdev_srv6_build_header(const struct netdev *,
                             struct ovs_action_push_tnl *,
                             const struct netdev_tnl_build_header_params *);

void
netdev_tnl_push_udp_header(const struct netdev *netdev,
                           struct dp_packet *packet,
                           const struct ovs_action_push_tnl *data);
int
netdev_geneve_build_header(const struct netdev *netdev,
                           struct ovs_action_push_tnl *data,
                           const struct netdev_tnl_build_header_params *params);

struct dp_packet *
netdev_geneve_pop_header(struct dp_packet *packet);

int
netdev_vxlan_build_header(const struct netdev *netdev,
                          struct ovs_action_push_tnl *data,
                          const struct netdev_tnl_build_header_params *params);

struct dp_packet *
netdev_vxlan_pop_header(struct dp_packet *packet);

static inline bool
netdev_tnl_is_header_ipv6(const void *header)
{
    const struct eth_header *eth;
    eth = header;
    return eth->eth_type == htons(ETH_TYPE_IPV6);
}

static inline struct ip_header *
netdev_tnl_ip_hdr(void *eth)
{
    return (void *)((char *)eth + sizeof (struct eth_header));
}

static inline struct ovs_16aligned_ip6_hdr *
netdev_tnl_ipv6_hdr(void *eth)
{
    return (void *)((char *)eth + sizeof (struct eth_header));
}

void *
netdev_tnl_ip_build_header(struct ovs_action_push_tnl *data,
                           const struct netdev_tnl_build_header_params *params,
                           uint8_t next_proto);

extern uint16_t tnl_udp_port_min;
extern uint16_t tnl_udp_port_max;

static inline ovs_be16
netdev_tnl_get_src_port(struct dp_packet *packet)
{
    uint32_t hash;

    hash = dp_packet_get_rss_hash(packet);

    return htons((((uint64_t) hash * (tnl_udp_port_max - tnl_udp_port_min)) >> 32) +
                 tnl_udp_port_min);
}

void *
netdev_tnl_ip_extract_tnl_md(struct dp_packet *packet, struct flow_tnl *tnl,
                             unsigned int *hlen);
void *
netdev_tnl_push_ip_header(struct dp_packet *packet,
                          const void *header, int size, int *ip_tot_size);
void
netdev_tnl_egress_port_range(struct unixctl_conn *conn, int argc,
                             const char *argv[], void *aux OVS_UNUSED);
#endif