blob: b096e0f5c09f04970c80d20ab1179d1525c27649 [file] [log] [blame]
Neale Ranns810086d2017-11-05 16:26:46 -08001/*
Florin Corasc5df8c72019-04-08 07:42:30 -07002 * Copyright (c) 2016-2019 Cisco and/or its affiliates.
Neale Ranns810086d2017-11-05 16:26:46 -08003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __UDP_ENCAP_H__
17#define __UDP_ENCAP_H__
18
19#include <vnet/ip/ip.h>
Florin Corasb040f982020-10-20 14:59:43 -070020#include <vnet/udp/udp_packet.h>
Neale Ranns810086d2017-11-05 16:26:46 -080021#include <vnet/fib/fib_node.h>
22
23/**
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -070024 * UDP encapsulation.
Neale Ranns810086d2017-11-05 16:26:46 -080025 * A representation of the encapsulation of packets in UDP-over-IP.
26 * This is encapsulation only, there is no tunnel interface, hence
27 * it is uni-directional. For decap register a handler with the UDP port
28 * dispatcher.
29 */
30
31/**
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -070032 * Fixup behaviour. Actions performed on the encap in the data-plane
Neale Ranns810086d2017-11-05 16:26:46 -080033 */
34typedef enum udp_encap_fixup_flags_t_
35{
36 UDP_ENCAP_FIXUP_NONE = 0,
Neale Ranns6763a1d2018-08-06 09:09:24 -040037 /**
38 * UDP source port contains an entropy/hash value for load-balancing by downstream peers.
39 */
Neale Ranns810086d2017-11-05 16:26:46 -080040 UDP_ENCAP_FIXUP_UDP_SRC_PORT_ENTROPY = (1 << 0),
41} udp_encap_fixup_flags_t;
42
43/**
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -070044 * The UDP encap representation
Neale Ranns810086d2017-11-05 16:26:46 -080045 */
46typedef struct udp_encap_t_
47{
Neale Ranns6763a1d2018-08-06 09:09:24 -040048 /**
49 * The first cacheline contains the data used in the data-plane
50 */
Neale Ranns810086d2017-11-05 16:26:46 -080051 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
52
Neale Ranns6763a1d2018-08-06 09:09:24 -040053 /**
54 * The headers to paint, in packet painting order
55 */
Neale Ranns810086d2017-11-05 16:26:46 -080056 union
57 {
58 struct
59 {
60 ip4_header_t ue_ip4;
61 udp_header_t ue_udp;
62 } __attribute__ ((packed)) ip4;
63 struct
64 {
65 ip6_header_t ue_ip6;
66 udp_header_t ue_udp;
67 } __attribute__ ((packed)) ip6;
68 } __attribute__ ((packed)) ue_hdrs;
69
Neale Ranns6763a1d2018-08-06 09:09:24 -040070 /**
Neale Ranns6763a1d2018-08-06 09:09:24 -040071 * The DPO used to forward to the next node in the VLIB graph
72 */
Neale Ranns810086d2017-11-05 16:26:46 -080073 dpo_id_t ue_dpo;
74
Neale Ranns6763a1d2018-08-06 09:09:24 -040075 /**
Vadym Martsynovskyy42386fc2020-06-12 09:50:50 -070076 * Flags controlling fixup behaviour
77 */
78 udp_encap_fixup_flags_t ue_flags;
79
80 /**
Neale Ranns6763a1d2018-08-06 09:09:24 -040081 * the protocol of the IP header imposed
82 */
Neale Ranns810086d2017-11-05 16:26:46 -080083 fib_protocol_t ue_ip_proto;
84
Neale Ranns6763a1d2018-08-06 09:09:24 -040085 /**
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -070086 * The second cacheline contains control-plane data
Neale Ranns6763a1d2018-08-06 09:09:24 -040087 */
Neale Ranns810086d2017-11-05 16:26:46 -080088 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
89
Neale Ranns6763a1d2018-08-06 09:09:24 -040090 /**
91 * linkage into the FIB graph
92 */
Neale Ranns810086d2017-11-05 16:26:46 -080093 fib_node_t ue_fib_node;
94
Neale Ranns6763a1d2018-08-06 09:09:24 -040095 /**
Neale Ranns6763a1d2018-08-06 09:09:24 -040096 * Tracking information for the IP destination
97 */
Neale Ranns810086d2017-11-05 16:26:46 -080098 fib_node_index_t ue_fib_entry_index;
99 u32 ue_fib_sibling;
100
Neale Ranns6763a1d2018-08-06 09:09:24 -0400101 /**
102 * The FIB index in which the encap destination resides
103 */
Neale Ranns810086d2017-11-05 16:26:46 -0800104 index_t ue_fib_index;
105} udp_encap_t;
106
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700107extern index_t udp_encap_add_and_lock (fib_protocol_t proto,
Neale Ranns810086d2017-11-05 16:26:46 -0800108 index_t fib_index,
109 const ip46_address_t * src_ip,
110 const ip46_address_t * dst_ip,
111 u16 src_port,
112 u16 dst_port,
113 udp_encap_fixup_flags_t flags);
114
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700115extern void udp_encap_lock (index_t uei);
116extern void udp_encap_unlock (index_t uei);
Neale Ranns810086d2017-11-05 16:26:46 -0800117extern u8 *format_udp_encap (u8 * s, va_list * args);
Neale Ranns9c0a3c42018-09-07 08:57:41 -0700118extern void udp_encap_contribute_forwarding (index_t uei,
Neale Ranns810086d2017-11-05 16:26:46 -0800119 dpo_proto_t proto,
120 dpo_id_t * dpo);
121
Neale Ranns43b1f442018-03-20 01:47:35 -0700122extern void udp_encap_get_stats (index_t uei, u64 * packets, u64 * bytes);
123
124/**
125 * Callback function invoked when walking all encap objects.
126 * Return non-zero to continue the walk.
127 */
Neale Ranns586479a2018-06-07 02:08:07 -0700128typedef walk_rc_t (*udp_encap_walk_cb_t) (index_t uei, void *ctx);
Neale Ranns43b1f442018-03-20 01:47:35 -0700129
130/**
131 * Walk each of the encap objects
132 */
133extern void udp_encap_walk (udp_encap_walk_cb_t cb, void *ctx);
134
Neale Ranns810086d2017-11-05 16:26:46 -0800135/**
136 * Pool of encaps
137 */
138extern udp_encap_t *udp_encap_pool;
139
140static inline udp_encap_t *
141udp_encap_get (index_t uei)
142{
143 return (pool_elt_at_index (udp_encap_pool, uei));
144}
145
146/*
147 * fd.io coding-style-patch-verification: ON
148 *
149 * Local Variables:
150 * eval: (c-set-style "gnu")
151 * End:
152 */
153
154#endif