1- From 9d26772725a18ac5fb5f7a6e22cb80d53383e4c9 Mon Sep 17 00:00:00 2001
1+ From fe95c6134f3827adf6017a95c8b8ec2a01a77902 Mon Sep 17 00:00:00 2001
22From: clyi <clyi@alauda.io>
3- Date: Thu, 15 Jan 2026 10:30:05 +0800
3+ Date: Thu, 22 Jan 2026 10:41:30 +0800
44Subject: [PATCH] add select local lb backend
55
66Signed-off-by: clyi <clyi@alauda.io>
77---
8- northd/lb.c | 34 ++++++++++++
8+ northd/lb.c | 34 +++++++++++
99 northd/lb.h | 1 +
10- northd/northd.c | 144 +++++++++++++++++++++++++++++++++++++++++++++---
10+ northd/northd.c | 146 +++++++++++++++++++++++++++++++++++++++++++++---
1111 northd/northd.h | 10 ++++
12- 4 files changed, 182 insertions(+), 7 deletions(-)
12+ 4 files changed, 184 insertions(+), 7 deletions(-)
1313
1414diff --git a/northd/lb.c b/northd/lb.c
15- index af0c92954..f0771b88e 100644
15+ index ef92249ce..f64a64cff 100644
1616--- a/northd/lb.c
1717+++ b/northd/lb.c
1818@@ -150,6 +150,36 @@ ovn_lb_vip_backends_health_check_init(const struct ovn_northd_lb *lb,
@@ -61,7 +61,7 @@ index af0c92954..f0771b88e 100644
6161 uint32_t affinity_timeout =
6262 smap_get_uint(&nbrec_lb->options, "affinity_timeout", 0);
6363 if (affinity_timeout > UINT16_MAX) {
64- @@ -337 ,6 +369 ,8 @@ ovn_northd_lb_init(struct ovn_northd_lb *lb,
64+ @@ -340 ,6 +372 ,8 @@ ovn_northd_lb_init(struct ovn_northd_lb *lb,
6565
6666 if (lb_vip_nb->lb_health_check) {
6767 ovn_lb_vip_backends_health_check_init(lb, lb_vip, lb_vip_nb);
@@ -71,7 +71,7 @@ index af0c92954..f0771b88e 100644
7171 }
7272
7373diff --git a/northd/lb.h b/northd/lb.h
74- index aa6616af4..c7a9ba90b 100644
74+ index 4696b4d98..4aa9e665f 100644
7575--- a/northd/lb.h
7676+++ b/northd/lb.h
7777@@ -65,6 +65,7 @@ struct ovn_northd_lb {
@@ -83,10 +83,10 @@ index aa6616af4..c7a9ba90b 100644
8383
8484 struct sset ips_v4;
8585diff --git a/northd/northd.c b/northd/northd.c
86- index f6559c240..918016123 100644
86+ index 7e8616df0..31fb61c10 100644
8787--- a/northd/northd.c
8888+++ b/northd/northd.c
89- @@ -3747 ,7 +3747 ,9 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
89+ @@ -3748 ,7 +3748 ,9 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
9090 struct ds *skip_snat_action,
9191 struct ds *force_snat_action,
9292 bool ls_dp,
@@ -97,7 +97,7 @@ index f6559c240..918016123 100644
9797 {
9898 bool reject = !lb_vip->n_backends && lb_vip->empty_backend_rej;
9999 bool drop = !lb_vip->n_backends && !lb_vip->empty_backend_rej;
100- @@ -3771 ,6 +3773 ,12 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
100+ @@ -3772 ,6 +3774 ,12 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
101101 struct ovn_northd_lb_backend *backend_nb =
102102 &lb_vip_nb->backends_nb[i];
103103
@@ -110,7 +110,7 @@ index f6559c240..918016123 100644
110110 if (!backend_nb->health_check) {
111111 continue;
112112 }
113- @@ -3804 ,8 +3812 ,11 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
113+ @@ -3805 ,8 +3813 ,11 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
114114 drop = !n_active_backends && !lb_vip->empty_backend_rej;
115115 reject = !n_active_backends && lb_vip->empty_backend_rej;
116116 } else {
@@ -124,7 +124,7 @@ index f6559c240..918016123 100644
124124 }
125125
126126 if (reject) {
127- @@ -8233 ,7 +8244 ,8 @@ build_lb_rules(struct lflow_table *lflows, struct ovn_lb_datapaths *lb_dps,
127+ @@ -8234 ,7 +8245 ,8 @@ build_lb_rules(struct lflow_table *lflows, struct ovn_lb_datapaths *lb_dps,
128128 const struct ovn_datapaths *ls_datapaths,
129129 struct ds *match, struct ds *action,
130130 const struct shash *meter_groups,
@@ -134,7 +134,7 @@ index f6559c240..918016123 100644
134134 {
135135 const struct ovn_northd_lb *lb = lb_dps->lb;
136136 for (size_t i = 0; i < lb->n_vips; i++) {
137- @@ -8244 ,13 +8256,127 @@ build_lb_rules(struct lflow_table *lflows, struct ovn_lb_datapaths *lb_dps,
137+ @@ -8245 ,13 +8257,129 @@ build_lb_rules(struct lflow_table *lflows, struct ovn_lb_datapaths *lb_dps,
138138
139139 ds_clear(action);
140140 ds_clear(match);
@@ -210,7 +210,7 @@ index f6559c240..918016123 100644
210210+ bool build_non_meter = false;
211211+ if (reject) {
212212+ size_t index;
213-
213+ +
214214+ dp_non_meter = bitmap_clone(lb_dps->nb_ls_map,
215215+ ods_size(ls_datapaths));
216216+ BITMAP_FOR_EACH_1 (index, ods_size(ls_datapaths),
@@ -245,13 +245,15 @@ index f6559c240..918016123 100644
245245+ HMAP_FOR_EACH_SAFE (entry, next, hmap_node, &chassis_lsp_map) {
246246+ free(entry->lp_array);
247247+ free(entry->backend_ips);
248+ + sset_destroy(&entry->logical_ports);
248249+ free(entry);
249250+ }
250251+ hmap_destroy(&chassis_lsp_map);
251252+ }
252253+
253254+ ds_clear(match);
254255+ ds_clear(action);
256+
255257 /* New connections in Ingress table. */
256258 const char *meter = NULL;
257259 bool reject = build_lb_vip_actions(lb, lb_vip, lb_vip_nb, action,
@@ -263,7 +265,7 @@ index f6559c240..918016123 100644
263265
264266 ds_put_format(match, "ct.new && %s.dst == %s", ip_match,
265267 lb_vip->vip_str);
266- @@ -12252 ,7 +12378 ,7 @@ build_lrouter_nat_flows_for_lb(
268+ @@ -12329 ,7 +12457 ,7 @@ build_lrouter_nat_flows_for_lb(
267269 bool reject = build_lb_vip_actions(lb, lb_vip, vips_nb, action,
268270 lb->selection_fields, &skip_snat_act,
269271 &force_snat_act, false,
@@ -272,40 +274,40 @@ index f6559c240..918016123 100644
272274
273275 /* Higher priority rules are added for load-balancing in DNAT
274276 * table. For every match (on a VIP[:port]), we add two flows.
275- @@ -12410 ,6 +12536 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
277+ @@ -12486 ,6 +12614 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
276278 const struct shash *meter_groups,
277279 const struct ovn_datapaths *ls_datapaths,
278280 const struct hmap *svc_monitor_map,
279281+ struct hmap *ls_ports,
280282 struct ds *match, struct ds *action)
281283 {
282284 if (!lb_dps->n_nb_ls) {
283- @@ -12453 ,7 +12580 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
285+ @@ -12529 ,7 +12658 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
284286 * REGBIT_CONNTRACK_COMMIT. */
285287 build_lb_rules_pre_stateful(lflows, lb_dps, ls_datapaths, match, action);
286288 build_lb_rules(lflows, lb_dps, ls_datapaths, match, action,
287289- meter_groups, svc_monitor_map);
288290+ meter_groups, svc_monitor_map, ls_ports);
289291 }
290292
291- /* If there are any load balancing rules, we should send the packet to
292- @@ -17924 ,6 +18051 ,7 @@ build_lflows_thread(void *arg)
293+ static void
294+ @@ -18042 ,6 +18171 ,7 @@ build_lflows_thread(void *arg)
293295 lsi->meter_groups,
294296 lsi->ls_datapaths,
295297 lsi->svc_monitor_map,
296298+ lsi->ls_ports,
297299 &lsi->match, &lsi->actions);
298300 }
299301 }
300- @@ -18158 ,6 +18286 ,7 @@ build_lswitch_and_lrouter_flows(
302+ @@ -18276 ,6 +18406 ,7 @@ build_lswitch_and_lrouter_flows(
301303 build_lswitch_flows_for_lb(lb_dps, lsi.lflows, lsi.meter_groups,
302304 lsi.ls_datapaths,
303305 lsi.svc_monitor_map,
304306+ lsi.ls_ports,
305307 &lsi.match, &lsi.actions);
306308 }
307309 stopwatch_stop(LFLOWS_LBS_STOPWATCH_NAME, time_msec());
308- @@ -18527 ,6 +18656 ,7 @@ lflow_handle_northd_lb_changes(struct ovsdb_idl_txn *ovnsb_txn,
310+ @@ -18645 ,6 +18776 ,7 @@ lflow_handle_northd_lb_changes(struct ovsdb_idl_txn *ovnsb_txn,
309311 lflow_input->meter_groups,
310312 lflow_input->ls_datapaths,
311313 lflow_input->svc_monitor_map,
@@ -314,7 +316,7 @@ index f6559c240..918016123 100644
314316
315317 ds_destroy(&match);
316318diff --git a/northd/northd.h b/northd/northd.h
317- index ba86ac5c9..0d53cfac6 100644
319+ index ba86ac5c9..855f5908a 100644
318320--- a/northd/northd.h
319321+++ b/northd/northd.h
320322@@ -813,6 +813,16 @@ find_route_outport(const struct hmap *lr_ports, const char *output_port,
0 commit comments