Skip to content

Commit c975191

Browse files
authored
northd: set dl_src for packets redirected by router port (#6102)
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent d1c6af6 commit c975191

File tree

6 files changed

+142
-354
lines changed

6 files changed

+142
-354
lines changed

dist/images/Dockerfile.base

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ADD patches/03e35ed9c5b4de0fa8acbc2c057cdd5957a8d605.patch $SRC_DIR
6464
ADD patches/b5e2975eb65f37315545300254fc0f58a9df52b1.patch $SRC_DIR
6565
ADD patches/e7d3ba53cdcbc524bb29c54ddb07b83cc4258ed7.patch $SRC_DIR
6666
ADD patches/a9e009136a42cf6d985f97e2bf1ec41df6b5ca29.patch $SRC_DIR
67+
ADD patches/fb0108d8fc29c1bd29666f1eb2a27bf34628fa11.patch $SRC_DIR
6768

6869
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
6970
--mount=type=cache,target=/var/lib/apt,sharing=locked \
@@ -128,7 +129,9 @@ RUN cd /usr/src/ && git clone -b branch-24.03 --depth=1 https://github.com/ovn-o
128129
# skip node local dns ip conntrack when set acl
129130
git apply $SRC_DIR/e7d3ba53cdcbc524bb29c54ddb07b83cc4258ed7.patch && \
130131
# select local backend first
131-
git apply $SRC_DIR/a9e009136a42cf6d985f97e2bf1ec41df6b5ca29.patch
132+
git apply $SRC_DIR/a9e009136a42cf6d985f97e2bf1ec41df6b5ca29.patch && \
133+
# set dl_src for packets redirected by router port
134+
git apply $SRC_DIR/fb0108d8fc29c1bd29666f1eb2a27bf34628fa11.patch
132135

133136
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
134137
--mount=type=cache,target=/var/lib/apt,sharing=locked \

dist/images/patches/a9e009136a42cf6d985f97e2bf1ec41df6b5ca29.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ index af0c92954c..71633ae788 100644
4242
+ struct ovn_northd_lb_backend *backend_nb =
4343
+ &lb_vip_nb->backends_nb[j];
4444
+ backend_nb->logical_port = xstrdup(port_name);
45-
+
45+
+
4646
+ free(port_name);
4747
+ }
4848
+
@@ -184,7 +184,7 @@ index a58db7dbde..0b84ac822e 100644
184184
+ bool reject = build_lb_vip_actions(lb, lb_vip, lb_vip_nb, action,
185185
+ lb->selection_fields,
186186
+ NULL, NULL, true, features,
187-
+ svc_monitor_map,
187+
+ svc_monitor_map,
188188
+ entry->backend_ips,
189189
+ &entry->logical_ports);
190190
+
@@ -254,7 +254,7 @@ index a58db7dbde..0b84ac822e 100644
254254
lb->selection_fields,
255255
NULL, NULL, true, features,
256256
- svc_monitor_map);
257-
+ svc_monitor_map,
257+
+ svc_monitor_map,
258258
+ NULL, NULL);
259259

260260
ds_put_format(match, "ct.new && %s.dst == %s", ip_match,
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
From fb0108d8fc29c1bd29666f1eb2a27bf34628fa11 Mon Sep 17 00:00:00 2001
2+
From: zhangzujian <zhangzujian.7@gmail.com>
3+
Date: Thu, 25 Dec 2025 00:24:49 +0000
4+
Subject: [PATCH] set dl_src for packets redirected by router port
5+
6+
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
7+
---
8+
northd/northd.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
9+
1 file changed, 69 insertions(+)
10+
11+
diff --git a/northd/northd.c b/northd/northd.c
12+
index 0a9362d01..86d7084bc 100644
13+
--- a/northd/northd.c
14+
+++ b/northd/northd.c
15+
@@ -8206,6 +8206,74 @@ build_lswitch_dnat_mod_dl_dst_rules(struct ovn_port *op,
16+
}
17+
}
18+
19+
+static void
20+
+build_lswitch_mod_dl_src_rules(struct ovn_port *op,
21+
+ struct lflow_table *lflows,
22+
+ const struct hmap *lr_ports,
23+
+ struct ds *actions,
24+
+ struct ds *match)
25+
+{
26+
+ if (!op->nbsp || !op->od || !op->od->nbs ||
27+
+ !op->od->n_router_ports || !op->od->n_localnet_ports) {
28+
+ return;
29+
+ }
30+
+ if (!lsp_is_enabled(op->nbsp)) {
31+
+ return;
32+
+ }
33+
+ if (!strcmp(op->nbsp->type, "virtual") ||
34+
+ !strcmp(op->nbsp->type, "localport")) {
35+
+ return;
36+
+ }
37+
+ if (lsp_is_external(op->nbsp) || lsp_is_router(op->nbsp) ||
38+
+ op->has_unknown) {
39+
+ return;
40+
+ }
41+
+
42+
+ if (op->n_lsp_addrs != 1 || !strlen(op->lsp_addrs[0].ea_s) ||
43+
+ (!op->lsp_addrs[0].n_ipv4_addrs && !op->lsp_addrs[0].n_ipv6_addrs)) {
44+
+ return;
45+
+ }
46+
+
47+
+ ds_clear(actions);
48+
+ ds_put_format(actions, "eth.src = %s; next(pipeline=ingress, table=%d);",
49+
+ op->lsp_addrs[0].ea_s,
50+
+ ovn_stage_get_table(S_SWITCH_IN_L2_LKUP));
51+
+
52+
+ for (size_t i = 0; i < op->od->n_router_ports; i++) {
53+
+ struct ovn_port *rp = op->od->router_ports[i];
54+
+ if (!rp || !rp->nbsp) {
55+
+ continue;
56+
+ }
57+
+ struct ovn_port *peer = ovn_port_get_peer(lr_ports, rp);
58+
+ if (!peer || !peer->nbrp || peer->primary_port ||
59+
+ peer->nbrp->n_gateway_chassis || peer->nbrp->ha_chassis_group) {
60+
+ continue;
61+
+ }
62+
+
63+
+ for (size_t j = 0; j < op->lsp_addrs[0].n_ipv4_addrs; j++) {
64+
+ ds_clear(match);
65+
+ ds_put_format(match,
66+
+ "inport == %s && ip4.src == %s && eth.src != %s",
67+
+ rp->json_key, op->lsp_addrs[0].ipv4_addrs[j].addr_s,
68+
+ op->lsp_addrs[0].ea_s);
69+
+ ovn_lflow_add_with_hint(lflows, op->od, S_SWITCH_IN_L2_LKUP, 60,
70+
+ ds_cstr(match), ds_cstr(actions),
71+
+ &op->nbsp->header_, op->lflow_ref);
72+
+ }
73+
+
74+
+ for (size_t j = 0; j < op->lsp_addrs[0].n_ipv6_addrs; j++) {
75+
+ ds_clear(match);
76+
+ ds_put_format(match,
77+
+ "inport == %s && ip6.src == %s && eth.src != %s",
78+
+ rp->json_key, op->lsp_addrs[0].ipv6_addrs[j].addr_s,
79+
+ op->lsp_addrs[0].ea_s);
80+
+ ovn_lflow_add_with_hint(lflows, op->od, S_SWITCH_IN_L2_LKUP, 60,
81+
+ ds_cstr(match), ds_cstr(actions),
82+
+ &op->nbsp->header_, op->lflow_ref);
83+
+ }
84+
+ }
85+
+}
86+
+
87+
static void
88+
build_stateful(struct ovn_datapath *od,
89+
const struct chassis_features *features,
90+
@@ -16755,6 +16823,7 @@ build_lswitch_and_lrouter_iterate_by_lsp(struct ovn_port *op,
91+
build_lswitch_arp_nd_responder_known_ips(op, lflows, ls_ports,
92+
meter_groups, actions, match);
93+
build_lswitch_dnat_mod_dl_dst_rules(op, lflows, lr_ports, actions, match);
94+
+ build_lswitch_mod_dl_src_rules(op, lflows, lr_ports, actions, match);
95+
build_lswitch_arp_nd_forward_for_unknown_ips(op, lflows, actions, match);
96+
build_lswitch_dhcp_options_and_response(op, lflows, meter_groups);
97+
build_lswitch_external_port(op, lflows);
98+
--
99+
2.43.0
100+

pkg/daemon/controller.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ type Controller struct {
5454
podsLister listerv1.PodLister
5555
podsSynced cache.InformerSynced
5656
updatePodQueue workqueue.TypedRateLimitingInterface[string]
57-
deletePodQueue workqueue.TypedRateLimitingInterface[*podEvent]
5857

5958
nodesLister listerv1.NodeLister
6059
nodesSynced cache.InformerSynced
@@ -116,7 +115,6 @@ func NewController(config *Configuration, stopCh <-chan struct{}, podInformerFac
116115
podsLister: podInformer.Lister(),
117116
podsSynced: podInformer.Informer().HasSynced,
118117
updatePodQueue: newTypedRateLimitingQueue[string]("UpdatePod", nil),
119-
deletePodQueue: newTypedRateLimitingQueue[*podEvent]("DeletePod", nil),
120118

121119
nodesLister: nodeInformer.Lister(),
122120
nodesSynced: nodeInformer.Informer().HasSynced,
@@ -178,7 +176,6 @@ func NewController(config *Configuration, stopCh <-chan struct{}, podInformerFac
178176

179177
if _, err = podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
180178
UpdateFunc: controller.enqueueUpdatePod,
181-
DeleteFunc: controller.enqueueDeletePod,
182179
}); err != nil {
183180
return nil, err
184181
}
@@ -477,10 +474,6 @@ type serviceEvent struct {
477474
oldObj, newObj any
478475
}
479476

480-
type podEvent struct {
481-
oldObj any
482-
}
483-
484477
func (c *Controller) enqueueAddSubnet(obj any) {
485478
c.subnetQueue.Add(&subnetEvent{newObj: obj})
486479
}
@@ -596,37 +589,11 @@ func (c *Controller) enqueueUpdatePod(oldObj, newObj any) {
596589
}
597590
}
598591

599-
func (c *Controller) enqueueDeletePod(obj any) {
600-
var pod *v1.Pod
601-
switch t := obj.(type) {
602-
case *v1.Pod:
603-
pod = t
604-
case cache.DeletedFinalStateUnknown:
605-
p, ok := t.Obj.(*v1.Pod)
606-
if !ok {
607-
klog.Warningf("unexpected object type: %T", t.Obj)
608-
return
609-
}
610-
pod = p
611-
default:
612-
klog.Warningf("unexpected type: %T", obj)
613-
return
614-
}
615-
616-
klog.V(3).Infof("enqueue delete pod %s", pod.Name)
617-
c.deletePodQueue.Add(&podEvent{oldObj: pod})
618-
}
619-
620592
func (c *Controller) runUpdatePodWorker() {
621593
for c.processNextUpdatePodWorkItem() {
622594
}
623595
}
624596

625-
func (c *Controller) runDeletePodWorker() {
626-
for c.processNextDeletePodWorkItem() {
627-
}
628-
}
629-
630597
func (c *Controller) processNextUpdatePodWorkItem() bool {
631598
key, shutdown := c.updatePodQueue.Get()
632599
if shutdown {
@@ -649,28 +616,6 @@ func (c *Controller) processNextUpdatePodWorkItem() bool {
649616
return true
650617
}
651618

652-
func (c *Controller) processNextDeletePodWorkItem() bool {
653-
event, shutdown := c.deletePodQueue.Get()
654-
if shutdown {
655-
return false
656-
}
657-
658-
err := func(event *podEvent) error {
659-
defer c.deletePodQueue.Done(event)
660-
if err := c.handleDeletePod(event); err != nil {
661-
c.deletePodQueue.AddRateLimited(event)
662-
return fmt.Errorf("error syncing pod event: %w, requeuing", err)
663-
}
664-
c.deletePodQueue.Forget(event)
665-
return nil
666-
}(event)
667-
if err != nil {
668-
utilruntime.HandleError(err)
669-
return true
670-
}
671-
return true
672-
}
673-
674619
var lastNoPodOvsPort map[string]bool
675620

676621
func (c *Controller) markAndCleanInternalPort() error {
@@ -706,7 +651,6 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
706651
defer c.subnetQueue.ShutDown()
707652
defer c.serviceQueue.ShutDown()
708653
defer c.updatePodQueue.ShutDown()
709-
defer c.deletePodQueue.ShutDown()
710654

711655
go wait.Until(ovs.CleanLostInterface, time.Minute, stopCh)
712656
go wait.Until(recompute, 10*time.Minute, stopCh)
@@ -725,7 +669,6 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
725669
go wait.Until(c.runDeleteProviderNetworkWorker, time.Second, stopCh)
726670
go wait.Until(c.runSubnetWorker, time.Second, stopCh)
727671
go wait.Until(c.runUpdatePodWorker, time.Second, stopCh)
728-
go wait.Until(c.runDeletePodWorker, time.Second, stopCh)
729672
go wait.Until(c.runGateway, 3*time.Second, stopCh)
730673
go wait.Until(c.loopEncapIPCheck, 3*time.Second, stopCh)
731674
go wait.Until(c.ovnMetricsUpdate, 3*time.Second, stopCh)

0 commit comments

Comments
 (0)