1- From 9286e1fd578fdb8f565a0f4aa9066b538295e1ac Mon Sep 17 00:00:00 2001
1+ From 9d26772725a18ac5fb5f7a6e22cb80d53383e4c9 Mon Sep 17 00:00:00 2001
22From: clyi <clyi@alauda.io>
3- Date: Tue, 11 Feb 2025 10:17:52 +0800
3+ Date: Thu, 15 Jan 2026 10:30:05 +0800
44Subject: [PATCH] add select local lb backend
55
66Signed-off-by: clyi <clyi@alauda.io>
77---
88 northd/lb.c | 34 ++++++++++++
99 northd/lb.h | 1 +
10- northd/northd.c | 139 +++++++++++++++++++++++++++++++++++++++++++++---
10+ northd/northd.c | 144 +++++++++++++++++++++++++++++++++++++++++++++---
1111 northd/northd.h | 10 ++++
12- 4 files changed, 177 insertions(+), 7 deletions(-)
12+ 4 files changed, 182 insertions(+), 7 deletions(-)
1313
1414diff --git a/northd/lb.c b/northd/lb.c
15- index af0c92954c..71633ae788 100644
15+ index af0c92954..f0771b88e 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,
@@ -71,7 +71,7 @@ index af0c92954c..71633ae788 100644
7171 }
7272
7373diff --git a/northd/lb.h b/northd/lb.h
74- index aa6616af41..c7a9ba90b5 100644
74+ index aa6616af4..c7a9ba90b 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 aa6616af41..c7a9ba90b5 100644
8383
8484 struct sset ips_v4;
8585diff --git a/northd/northd.c b/northd/northd.c
86- index d3b4fed086..c75f2e51de 100644
86+ index f6559c240..918016123 100644
8787--- a/northd/northd.c
8888+++ b/northd/northd.c
89- @@ -3764 ,7 +3764 ,9 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
89+ @@ -3747 ,7 +3747 ,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 d3b4fed086..c75f2e51de 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- @@ -3788 ,6 +3790 ,12 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
100+ @@ -3771 ,6 +3773 ,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 d3b4fed086..c75f2e51de 100644
110110 if (!backend_nb->health_check) {
111111 continue;
112112 }
113- @@ -3821 ,8 +3829 ,11 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
113+ @@ -3804 ,8 +3812 ,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 d3b4fed086..c75f2e51de 100644
124124 }
125125
126126 if (reject) {
127- @@ -8329 ,7 +8340 ,8 @@ build_lb_rules(struct lflow_table *lflows, struct ovn_lb_datapaths *lb_dps,
127+ @@ -8233 ,7 +8244 ,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 d3b4fed086..c75f2e51de 100644
134134 {
135135 const struct ovn_northd_lb *lb = lb_dps->lb;
136136 for (size_t i = 0; i < lb->n_vips; i++) {
137- @@ -8340 ,13 +8352,122 @@ build_lb_rules(struct lflow_table *lflows, struct ovn_lb_datapaths *lb_dps,
137+ @@ -8244 ,13 +8256,127 @@ build_lb_rules(struct lflow_table *lflows, struct ovn_lb_datapaths *lb_dps,
138138
139139 ds_clear(action);
140140 ds_clear(match);
@@ -167,7 +167,12 @@ index d3b4fed086..c75f2e51de 100644
167167+ entry->lp_array[entry->n_lps] = op;
168168+ entry->n_lps++;
169169+
170- + char *new_backend_ips = xasprintf("%s%s%s:%s", entry->backend_ips, entry->n_lps > 1 ? "," : "", backend->ip_str, backend->port_str);
170+ + char *new_backend_ips;
171+ + if (IN6_IS_ADDR_V4MAPPED(&backend->ip)) {
172+ + new_backend_ips = xasprintf("%s%s%s:%s", entry->backend_ips, entry->n_lps > 1 ? "," : "", backend->ip_str, backend->port_str);
173+ + } else {
174+ + new_backend_ips = xasprintf("%s%s[%s]:%s", entry->backend_ips, entry->n_lps > 1 ? "," : "", backend->ip_str, backend->port_str);
175+ + }
171176+ free(entry->backend_ips);
172177+ entry->backend_ips = new_backend_ips;
173178+ sset_add(&entry->logical_ports, backend_nb->logical_port);
@@ -258,7 +263,7 @@ index d3b4fed086..c75f2e51de 100644
258263
259264 ds_put_format(match, "ct.new && %s.dst == %s", ip_match,
260265 lb_vip->vip_str);
261- @@ -12423 ,7 +12544 ,7 @@ build_lrouter_nat_flows_for_lb(
266+ @@ -12252 ,7 +12378 ,7 @@ build_lrouter_nat_flows_for_lb(
262267 bool reject = build_lb_vip_actions(lb, lb_vip, vips_nb, action,
263268 lb->selection_fields, &skip_snat_act,
264269 &force_snat_act, false,
@@ -267,15 +272,15 @@ index d3b4fed086..c75f2e51de 100644
267272
268273 /* Higher priority rules are added for load-balancing in DNAT
269274 * table. For every match (on a VIP[:port]), we add two flows.
270- @@ -12581 ,6 +12702 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
275+ @@ -12410 ,6 +12536 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
271276 const struct shash *meter_groups,
272277 const struct ovn_datapaths *ls_datapaths,
273278 const struct hmap *svc_monitor_map,
274279+ struct hmap *ls_ports,
275280 struct ds *match, struct ds *action)
276281 {
277282 if (!lb_dps->n_nb_ls) {
278- @@ -12624 ,7 +12746 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
283+ @@ -12453 ,7 +12580 ,7 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
279284 * REGBIT_CONNTRACK_COMMIT. */
280285 build_lb_rules_pre_stateful(lflows, lb_dps, ls_datapaths, match, action);
281286 build_lb_rules(lflows, lb_dps, ls_datapaths, match, action,
@@ -284,23 +289,23 @@ index d3b4fed086..c75f2e51de 100644
284289 }
285290
286291 /* If there are any load balancing rules, we should send the packet to
287- @@ -18033 ,6 +18155 ,7 @@ build_lflows_thread(void *arg)
292+ @@ -17924 ,6 +18051 ,7 @@ build_lflows_thread(void *arg)
288293 lsi->meter_groups,
289294 lsi->ls_datapaths,
290295 lsi->svc_monitor_map,
291296+ lsi->ls_ports,
292297 &lsi->match, &lsi->actions);
293298 }
294299 }
295- @@ -18267 ,6 +18390 ,7 @@ build_lswitch_and_lrouter_flows(
300+ @@ -18158 ,6 +18286 ,7 @@ build_lswitch_and_lrouter_flows(
296301 build_lswitch_flows_for_lb(lb_dps, lsi.lflows, lsi.meter_groups,
297302 lsi.ls_datapaths,
298303 lsi.svc_monitor_map,
299304+ lsi.ls_ports,
300305 &lsi.match, &lsi.actions);
301306 }
302307 stopwatch_stop(LFLOWS_LBS_STOPWATCH_NAME, time_msec());
303- @@ -18636 ,6 +18760 ,7 @@ lflow_handle_northd_lb_changes(struct ovsdb_idl_txn *ovnsb_txn,
308+ @@ -18527 ,6 +18656 ,7 @@ lflow_handle_northd_lb_changes(struct ovsdb_idl_txn *ovnsb_txn,
304309 lflow_input->meter_groups,
305310 lflow_input->ls_datapaths,
306311 lflow_input->svc_monitor_map,
@@ -309,7 +314,7 @@ index d3b4fed086..c75f2e51de 100644
309314
310315 ds_destroy(&match);
311316diff --git a/northd/northd.h b/northd/northd.h
312- index 388bac6df5..d9f7eb12c0 100644
317+ index ba86ac5c9..0d53cfac6 100644
313318--- a/northd/northd.h
314319+++ b/northd/northd.h
315320@@ -813,6 +813,16 @@ find_route_outport(const struct hmap *lr_ports, const char *output_port,
@@ -329,3 +334,6 @@ index 388bac6df5..d9f7eb12c0 100644
329334 void ovnnb_db_run(struct northd_input *input_data,
330335 struct northd_data *data,
331336 struct ovsdb_idl_txn *ovnnb_txn,
337+ - -
338+ 2.34.1
339+
0 commit comments