Commit a598dfd
datapath: Fix BPF masquerade IP selection with multiple IPs per interface
When a network device has multiple IP addresses (both public and
private), BPF masquerading was incorrectly selecting the Kubernetes
Node IP even when it was a private address and a public address was
available on the same interface.
The issue was introduced in PR #33629 which added K8s Node IP
prioritization. The code was setting both ipv4PublicIndex and
ipv4PrivateIndex to the K8s Node IP index, effectively forcing
it to be selected regardless of public/private status. This broke
the documented "prefer public over private" logic for Primary
address selection used by BPF masquerading.
The fix ensures that K8s Node IP prioritization only applies within
its own category (public or private):
- If K8s Node IP is public, it takes precedence over other public IPs
- If K8s Node IP is private, it takes precedence over other private IPs
- But public IPs still take precedence over private IPs for masquerading
This restores the correct behavior where egress traffic is masqueraded
using the public IP address when available, which is required for
proper routing in environments with both public and private IPs on
the same interface.
Fixes: #41866
Signed-off-by: Jonathan Siegel <248302+usiegj00@users.noreply.github.com>1 parent 6e3657e commit a598dfd
2 files changed
Lines changed: 46 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | | - | |
497 | | - | |
498 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
499 | 507 | | |
500 | 508 | | |
501 | 509 | | |
| |||
507 | 515 | | |
508 | 516 | | |
509 | 517 | | |
510 | | - | |
511 | | - | |
512 | | - | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
513 | 529 | | |
514 | 530 | | |
515 | 531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
219 | 223 | | |
| 224 | + | |
220 | 225 | | |
221 | | - | |
| 226 | + | |
222 | 227 | | |
223 | 228 | | |
224 | 229 | | |
225 | | - | |
| 230 | + | |
226 | 231 | | |
227 | 232 | | |
228 | 233 | | |
229 | | - | |
| 234 | + | |
230 | 235 | | |
231 | 236 | | |
| 237 | + | |
232 | 238 | | |
233 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
234 | 244 | | |
235 | 245 | | |
236 | 246 | | |
237 | | - | |
| 247 | + | |
238 | 248 | | |
239 | 249 | | |
240 | 250 | | |
| |||
244 | 254 | | |
245 | 255 | | |
246 | 256 | | |
247 | | - | |
248 | 257 | | |
| 258 | + | |
| 259 | + | |
249 | 260 | | |
250 | 261 | | |
251 | 262 | | |
| 263 | + | |
252 | 264 | | |
253 | 265 | | |
254 | | - | |
255 | | - | |
| 266 | + | |
| 267 | + | |
256 | 268 | | |
257 | 269 | | |
| 270 | + | |
258 | 271 | | |
259 | | - | |
260 | | - | |
| 272 | + | |
| 273 | + | |
261 | 274 | | |
262 | 275 | | |
263 | 276 | | |
| |||
0 commit comments