FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
nat44_ed_affinity.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * 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  * @file
17  * @brief NAT plugin client-IP based session affinity for load-balancing
18  */
19 
20 #ifndef __included_nat44_ed_affinity_h__
21 #define __included_nat44_ed_affinity_h__
22 
23 #include <vnet/ip/ip.h>
24 #include <vppinfra/bihash_16_8.h>
25 #include <vppinfra/dlist.h>
26 
27 typedef struct
28 {
29  union
30  {
31  struct
32  {
35  /* align by making this 4 octets even though its a 1 octet field */
37  /* align by making this 4 octets even though its a 2 octets field */
39  };
40  u64 as_u64[2];
41  };
43 
44 /* *INDENT-OFF* */
45 typedef CLIB_PACKED(struct
46 {
48  u32 sticky_time;
49  u32 ref_cnt;
50  u32 per_service_index;
51  u8 backend_index;
52  f64 expire;
53 }) nat_affinity_t;
54 /* *INDENT-ON* */
55 
56 typedef struct
57 {
58  nat_affinity_t *affinity_pool;
59  clib_bihash_16_8_t affinity_hash;
64 
66 
67 /**
68  * @brief Get new affinity per service list head index.
69  *
70  * @returns new affinity per service list head index.
71  */
73 
74 /**
75  * @brief Flush all service affinity data.
76  *
77  * @param affinity_per_service_list_head_index Per sevice list head index.
78  */
79 void nat_affinity_flush_service (u32 affinity_per_service_list_head_index);
80 
81 /**
82  * @brief NAT affinity enable
83  */
84 void nat_affinity_enable ();
85 
86 /**
87  * @brief NAT affinity disable
88  */
89 void nat_affinity_disable ();
90 
91 /**
92  * @brief Initialize NAT client-IP based affinity.
93  *
94  * @param vm vlib main.
95  *
96  * @return error code.
97  */
99 
100 /**
101  * @brief Find service backend index for client-IP and take a reference
102  * counting lock.
103  *
104  * @param client_addr Client IP address.
105  * @param service_addr Service IP address.
106  * @param proto IP protocol number.
107  * @param service_port Service L4 port number.
108  * @param backend_index Service backend index for client-IP if found.
109  *
110  * @return 0 on success, non-zero value otherwise.
111  */
113  ip4_address_t service_addr, u8 proto,
114  u16 service_port, u8 *backend_index);
115 
116 /**
117  * @brief Create affinity record and take reference counting lock.
118  * @param client_addr Client IP address.
119  * @param service_addr Service IP address.
120  * @param proto IP protocol number.
121  * @param service_port Service L4 port number.
122  * @param backend_index Service backend index for client-IP.
123  * @param sticky_time Affinity sticky time in seconds.
124  * @param affinity_per_service_list_head_index Per sevice list head index.
125  *
126  * @return 0 on success, non-zero value otherwise.
127  */
129  ip4_address_t service_addr, u8 proto,
130  u16 service_port, u8 backend_index,
131  u32 sticky_time,
132  u32 affinity_per_service_list_head_index);
133 /**
134  * @brief Release a reference counting lock for affinity.
135  *
136  * @param client_addr Client IP address.
137  * @param service_addr Service IP address.
138  * @param proto IP protocol number.
139  */
140 void nat_affinity_unlock (ip4_address_t client_addr,
141  ip4_address_t service_addr, u8 proto,
142  u16 service_port);
143 
144 #endif /* __included_nat44_ed_affinity_h__ */
145 
146 /*
147  * fd.io coding-style-patch-verification: ON
148  *
149  * Local Variables:
150  * eval: (c-set-style "gnu")
151  * End:
152  */
CLIB_PACKED
typedef CLIB_PACKED(struct { nat_affinity_key_t key;u32 sticky_time;u32 ref_cnt;u32 per_service_index;u8 backend_index;f64 expire;}) nat_affinity_t
nat_affinity_enable
void nat_affinity_enable()
NAT affinity enable.
Definition: nat44_ed_affinity.c:49
nat_affinity_key_t
Definition: nat44_ed_affinity.h:27
nat_affinity_key_t::proto
u32 proto
Definition: nat44_ed_affinity.h:36
nat_affinity_get_per_service_list_head_index
u32 nat_affinity_get_per_service_list_head_index(void)
Get new affinity per service list head index.
Definition: nat44_ed_affinity.c:96
nat_affinity_main_t::list_pool
dlist_elt_t * list_pool
Definition: nat44_ed_affinity.h:61
dlist.h
nat_affinity_main_t::affinity_hash
clib_bihash_16_8_t affinity_hash
Definition: nat44_ed_affinity.h:59
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
nat_affinity_main_t::vlib_main
vlib_main_t * vlib_main
Definition: nat44_ed_affinity.h:62
key
typedef key
Definition: ipsec_types.api:88
nat_affinity_flush_service
void nat_affinity_flush_service(u32 affinity_per_service_list_head_index)
Flush all service affinity data.
Definition: nat44_ed_affinity.c:112
nat_affinity_main_t::affinity_pool
nat_affinity_t * affinity_pool
Definition: nat44_ed_affinity.h:58
clib_spinlock_s
Definition: lock.h:51
nat_affinity_main
nat_affinity_main_t nat_affinity_main
Definition: nat44_ed_affinity.c:25
f64
double f64
Definition: types.h:142
dlist_elt_t
Definition: dlist.h:28
ip4_address_t
Definition: ip4_packet.h:50
nat_affinity_create_and_lock
int nat_affinity_create_and_lock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port, u8 backend_index, u32 sticky_time, u32 affinity_per_service_list_head_index)
Create affinity record and take reference counting lock.
Definition: nat44_ed_affinity.c:209
nat_affinity_main_t::affinity_lock
clib_spinlock_t affinity_lock
Definition: nat44_ed_affinity.h:60
nat_affinity_key_t::client_addr
ip4_address_t client_addr
Definition: nat44_ed_affinity.h:34
u64
unsigned long u64
Definition: types.h:89
nat_affinity_find_and_lock
int nat_affinity_find_and_lock(vlib_main_t *vm, ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port, u8 *backend_index)
Find service backend index for client-IP and take a reference counting lock.
Definition: nat44_ed_affinity.c:143
nat_affinity_init
clib_error_t * nat_affinity_init(vlib_main_t *vm)
Initialize NAT client-IP based affinity.
Definition: nat44_ed_affinity.c:74
ip.h
u32
unsigned int u32
Definition: types.h:88
as_u64
u64 as_u64
Definition: bihash_doc.h:63
bihash_16_8.h
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
nat_affinity_key_t::service_addr
ip4_address_t service_addr
Definition: nat44_ed_affinity.h:33
nat_affinity_disable
void nat_affinity_disable()
NAT affinity disable.
Definition: nat44_ed_affinity.c:63
nat_affinity_key_t::service_port
u32 service_port
Definition: nat44_ed_affinity.h:38
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
nat_affinity_unlock
void nat_affinity_unlock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port)
Release a reference counting lock for affinity.
Definition: nat44_ed_affinity.c:261
nat_affinity_main_t
Definition: nat44_ed_affinity.h:56