ip: Path MTU
[vpp.git] / src / vnet / ip / ip_path_mtu.h
1 /*
2  *------------------------------------------------------------------
3  * ip_path_mtu.h
4  *
5  * Copyright (c) 2021 Graphiant.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #include <vnet/ip/ip.h>
21
22 /**
23  * @brief
24  * The Path MTU DPO. interposed in the forwarding chain of the host prefix.
25  */
26 typedef struct ip_pmtu_dpo_t_
27 {
28   /**
29    * The protocol of packets using this DPO
30    */
31   dpo_proto_t ipm_proto;
32
33   u8 __pad8;
34
35   /**
36    * Configured Path Mtu
37    */
38   u16 ipm_pmtu;
39
40   /**
41    * number of locks.
42    */
43   u16 ipm_locks;
44
45   /**
46    * Stacked DPO
47    */
48   dpo_id_t ipm_dpo;
49 } ip_pmtu_dpo_t;
50
51 /*
52  * PMTU DPOs are accessed in the data-path so they should not straddle a cache
53  * line. Align to a integer factor of a cacheline
54  */
55 STATIC_ASSERT_SIZEOF (ip_pmtu_dpo_t, 2 * sizeof (u64));
56
57 #define foreach_ip_pmtu_flag                                                  \
58   _ (ATTACHED, 0, "attached")                                                 \
59   _ (REMOTE, 1, "remote")                                                     \
60   _ (STALE, 2, "stale")
61
62 typedef enum ip_pmtu_flags_t_
63 {
64 #define _(a, b, c) IP_PMTU_FLAG_##a = (1 << b),
65   foreach_ip_pmtu_flag
66 #undef _
67 } ip_pmtu_flags_t;
68
69 /**
70  * Remote Path MTU tracking object
71  */
72 typedef struct ip_pmtu_t_
73 {
74   /** linkage into the FIB graph */
75   fib_node_t ipt_node;
76
77   /** Track fib entry */
78   fib_node_index_t ipt_fib_entry;
79   u32 ipt_sibling;
80   ip_pmtu_flags_t ipt_flags;
81
82   /** Configured MTU */
83   u16 ipt_cfg_pmtu;
84
85   /** MTU from the parent MTU */
86   u16 ipt_parent_pmtu;
87
88   /** operational MTU; the minimum value of the cfg and parent MTU */
89   u16 ipt_oper_pmtu;
90 } ip_pmtu_t;
91
92 extern int ip_path_mtu_update (const ip_address_t *nh, u32 table_id, u16 pmtu);
93
94 typedef walk_rc_t (*ip_path_mtu_walk_t) (index_t ipti, void *ctx);
95
96 extern void ip_path_mtu_walk (ip_path_mtu_walk_t fn, void *ctx);
97 extern int ip_path_mtu_replace_begin (void);
98 extern int ip_path_mtu_replace_end (void);
99
100 extern u32 ip_pmtu_get_table_id (const ip_pmtu_t *ipt);
101 extern void ip_pmtu_get_ip (const ip_pmtu_t *ipt, ip_address_t *ip);
102
103 /**
104  * Data-plane accessor functions
105  */
106 extern ip_pmtu_dpo_t *ip_pmtu_dpo_pool;
107 static_always_inline ip_pmtu_dpo_t *
108 ip_pmtu_dpo_get (index_t index)
109 {
110   return (pool_elt_at_index (ip_pmtu_dpo_pool, index));
111 }
112
113 extern ip_pmtu_t *ip_pmtu_pool;
114 static_always_inline ip_pmtu_t *
115 ip_path_mtu_get (index_t index)
116 {
117   return (pool_elt_at_index (ip_pmtu_pool, index));
118 }
119
120 /*
121  * fd.io coding-style-patch-verification: ON
122  *
123  * Local Variables:
124  * eval: (c-set-style "gnu")
125  * End:
126  */