Skip to content

Commit 2082835

Browse files
sknatbganne
authored andcommitted
cnat: allow max_u16 translation backends
Type: fix Allow for 65536 backends for a translation. - use u32 instead of u8 - filter out back_walk with more than FIB_PATH_LIST_POPULAR backends - we're still limited by u16 lb_n_buckets in src/vnet/dpo/load_balance.h Change-Id: Ib37b958e59b25ef5ef9f92b82008d626860faddd Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
1 parent a5203b5 commit 2082835

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

src/plugins/cnat/cnat.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef cnat_translation
5353
vl_api_ip_proto_t ip_proto;
5454
u8 is_real_ip;
5555
u8 flags;
56-
u8 n_paths;
56+
u32 n_paths;
5757
vl_api_cnat_endpoint_tuple_t paths[n_paths];
5858
};
5959

src/plugins/cnat/cnat_api.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ vl_api_cnat_translation_update_t_handler (vl_api_cnat_translation_update_t
8888
u32 id = ~0;
8989
u8 flags;
9090
int rv = 0;
91-
u8 pi;
91+
u32 pi, n_paths;
9292

9393
rv = ip_proto_decode (mp->translation.ip_proto, &ip_proto);
9494

9595
if (rv)
9696
goto done;
9797

98-
vec_validate (paths, mp->translation.n_paths - 1);
98+
n_paths = clib_net_to_host_u32 (mp->translation.n_paths);
99+
vec_validate (paths, n_paths - 1);
99100

100-
for (pi = 0; pi < mp->translation.n_paths; pi++)
101+
for (pi = 0; pi < n_paths; pi++)
101102
{
102103
path = &paths[pi];
103104
cnat_endpoint_tuple_decode (&mp->translation.paths[pi], path);
@@ -146,7 +147,7 @@ cnat_translation_send_details (u32 cti, void *args)
146147
vl_api_cnat_endpoint_tuple_t *path;
147148
size_t msg_size;
148149
cnat_translation_t *ct;
149-
u8 n_paths;
150+
u32 n_paths;
150151

151152
ctx = args;
152153
ct = cnat_translation_get (cti);
@@ -158,8 +159,8 @@ cnat_translation_send_details (u32 cti, void *args)
158159

159160
/* fill in the message */
160161
mp->context = ctx->context;
161-
mp->translation.n_paths = n_paths;
162-
mp->translation.id = htonl (cti);
162+
mp->translation.n_paths = clib_host_to_net_u32 (n_paths);
163+
mp->translation.id = clib_host_to_net_u32 (cti);
163164
cnat_endpoint_encode (&ct->ct_vip, &mp->translation.vip);
164165
mp->translation.ip_proto = ip_proto_encode (ct->ct_proto);
165166

src/plugins/cnat/cnat_translation.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ cnat_translation_stack (cnat_translation_t * ct)
180180
fib_protocol_t fproto;
181181
cnat_ep_trk_t *trk;
182182
dpo_proto_t dproto;
183-
u8 ep_idx = 0;
183+
u32 ep_idx = 0;
184184
index_t lbi;
185185

186186
fproto = ip_address_family_to_fib_proto (ct->ct_vip.ce_ip.version);
@@ -198,6 +198,7 @@ cnat_translation_stack (cnat_translation_t * ct)
198198

199199
dpo_set (&ct->ct_lb, DPO_LOAD_BALANCE, dproto, lbi);
200200
dpo_stack (cnat_client_dpo, dproto, &ct->ct_lb, &ct->ct_lb);
201+
ct->flags |= CNAT_TRANSLATION_STACKED;
201202
}
202203

203204
int
@@ -277,6 +278,7 @@ cnat_translation_update (cnat_endpoint_t * vip,
277278
}
278279

279280
vec_reset_length (ct->ct_paths);
281+
ct->flags &= ~CNAT_TRANSLATION_STACKED;
280282

281283
u64 path_idx = 0;
282284
vec_foreach (path, paths)
@@ -457,6 +459,12 @@ cnat_translation_back_walk_notify (fib_node_t * node,
457459
*/
458460
cnat_translation_t *ct = cnat_translation_get_from_node (node);
459461

462+
/* If we have more than FIB_PATH_LIST_POPULAR paths
463+
* we might get called during path tracking
464+
* (cnat_tracker_track) */
465+
if (!(ct->flags & CNAT_TRANSLATION_STACKED))
466+
return (FIB_NODE_BACK_WALK_CONTINUE);
467+
460468
cnat_translation_stack (ct);
461469

462470
return (FIB_NODE_BACK_WALK_CONTINUE);
@@ -601,9 +609,12 @@ cnat_if_addr_add_del_backend_cb (addr_resolution_t * ar,
601609
ip_address_copy (&ep->ce_ip, address);
602610
ep->ce_flags |= CNAT_EP_FLAG_RESOLVED;
603611
}
612+
613+
ct->flags &= ~CNAT_TRANSLATION_STACKED;
604614
cnat_tracker_track (ar->cti, trk);
605615

606616
cnat_translation_stack (ct);
617+
ct->flags |= CNAT_TRANSLATION_STACKED;
607618
}
608619

609620
static void

src/plugins/cnat/cnat_translation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ typedef struct cnat_ep_trk_t_
5858

5959
typedef enum cnat_translation_flag_t_
6060
{
61+
/* Do allocate a source port */
6162
CNAT_TRANSLATION_FLAG_ALLOCATE_PORT = (1 << 0),
63+
/* Has this translation been satcked ?
64+
* this allow not being called twice when
65+
* with more then FIB_PATH_LIST_POPULAR backends */
66+
CNAT_TRANSLATION_STACKED = (1 << 1),
6267
} cnat_translation_flag_t;
6368

6469
typedef enum

0 commit comments

Comments
 (0)