Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broadcast free arp when pod is setup #2638

Merged
merged 4 commits into from
Apr 12, 2023

Conversation

changluyi
Copy link
Collaborator

@changluyi changluyi commented Apr 11, 2023

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

Which issue(s) this PR fixes:

Fixes #(issue-number)

WHAT

🤖 Generated by Copilot at 4e8d30a

This pull request adds a new feature to enable or disable IP conflict detection in the kube-ovn controller, and improves the ARP handling for pod IP addresses. It introduces a new flag detectIPConflict and a new utility function BroadcastFreeArp in the util package, and modifies the configureNic and announce functions in the ovs_linux.go and ipam.go files respectively.

🤖 Generated by Copilot at 4e8d30a

BroadcastFreeArp
A new function for pods
To avoid conflict

HOW

🤖 Generated by Copilot at 4e8d30a

  • Add a new utility function to broadcast free ARP requests (link)
  • Use the new utility function to announce pod IP and MAC address after configuring the network interface (link)

@changluyi changluyi changed the title broadcase free arp when pod is setup broadcast free arp when pod is setup Apr 11, 2023
@changluyi changluyi requested a review from oilbeater April 11, 2023 13:26
@changluyi changluyi added the bug Something isn't working label Apr 11, 2023
@github-actions
Copy link
Contributor

  • The commit message is missing, it should provide a brief description of the changes made in this patch.
  • There are no potential bugs or format errors in the code patch.
  • The performance of the code patch seems fine.
  • The code patch can be improved by adding comments to explain the purpose of each function and variable.

@github-actions
Copy link
Contributor

  • The commit message is missing, it should be added to provide context and explain the changes made in this patch.
  • The code change seems to be correct, but there are some formatting issues that need to be fixed. Specifically, there are inconsistent uses of spaces around operators and commas. It would be better to follow a consistent style throughout the codebase.
  • There are no potential bugs or performance issues in this code patch.
  • The function BroadcastFreeArp could benefit from more descriptive variable names, especially for the parameters nic, ip, mac, announceNum, and announceInterval.
  • In the BroadcastFreeArp function, there is an error message logged when parsing the IP address fails, but the function still returns nil instead of returning the error. It would be better to return the error so that the caller can handle it appropriately.

pkg/util/arp.go Outdated
@@ -199,17 +199,45 @@ func ArpDetectIPConflict(nic, ip string, mac net.HardwareAddr) (net.HardwareAddr
// Announcement is identical to the ARP Probe described above,
// except that now the sender and target IP addresses are both
// set to the host's newly selected IPv4 address.
if pkt, err = arp.NewPacket(arp.OperationRequest, mac, tpa, tha, tpa); err != nil {
err = BroadcastFreeArp(nic, ip, mac, announceNum, announceInterval)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err = ...; err != nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

pkg/util/arp.go Outdated

func BroadcastFreeArp(nic, ip string, mac net.HardwareAddr, announceNum int, announceInterval time.Duration) error {
klog.Infof("broadcast free arp with nic %s , ip %s, with mac %v ", nic, ip, mac)
ifi, err := net.InterfaceByName(nic)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifi should be replaced by more meaningful name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@github-actions
Copy link
Contributor

  • The commit message is missing, please add a descriptive message explaining the changes made in this patch.
  • In the configureNic function, there is no need to check if addr.IP.To4() != nil before calling AnnounceArpAddress, as it is already being checked inside the function. This can be removed to simplify the code.
  • In the AnnounceArpAddress function, the return value is always nil, nil. This should be changed to return only an error value, as it is not used anywhere in the code.
  • In the AnnounceArpAddress function, the klog.Errorf call should be changed to klog.Warningf, as it is not a critical error and does not need to stop the execution of the program.
  • In the AnnounceArpAddress function, the dstMac variable is never used and can be removed to simplify the code.

@github-actions
Copy link
Contributor

  • The commit message is missing. It should provide a brief description of the changes made in the patch.
  • In the configureNic function, the newly added code block that broadcasts free ARP packets should be commented more clearly to explain its purpose and how it works.
  • In the AnnounceArpAddress function, the error messages should be more specific to help with debugging. For example, instead of returning "failed to parse IP address", it could return "failed to parse IP address %s: %v" to include the actual IP address and the error message.
  • In the AnnounceArpAddress function, the dstMac variable is hardcoded to broadcast to all MAC addresses. This might cause unnecessary network traffic and could be improved by broadcasting only to the target MAC address.
  • In the AnnounceArpAddress function, the client.SetDeadline call might not be necessary since the timer already limits the duration of the write operation.

@changluyi changluyi merged commit 0b5fc5d into master Apr 12, 2023
@changluyi changluyi deleted the send_free_arp_when_overlay_pod_up branch April 12, 2023 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need backport
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants