-
Notifications
You must be signed in to change notification settings - Fork 17
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
IP address and policy removal on connection update #433
Conversation
* Based on interfaces addresses, IPs in IPContext are filtered: to add/to removed Signed-off-by: Lionel Jouin <[email protected]>
toAdd := []*net.IPNet{} | ||
toRemove := []*net.IPNet{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: you can append into nil slices
toAdd := []*net.IPNet{} | |
toRemove := []*net.IPNet{} | |
var toAdd []*net.IPNet{} | |
var toRemove []*net.IPNet{} |
if !ok { | ||
counter.Inc() | ||
tableID = int(counter.Load()) | ||
ps, ok := tableIDs.Load(mechanism.GetNetNSURL()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps before that we should check if len(conn.Context.IpContext.Policies) == 0 { return nil }
so as not to create new tableID entry.
@@ -254,6 +282,8 @@ func delRule(ctx context.Context, handle *netlink.Handle, policy *networkservice | |||
return errors.WithStack(err) | |||
} | |||
|
|||
// TODO: Flush table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think that we need to delete an entry from Maps. Perhaps after deleting current NSC, a new one will come with the same mechanism.GetNetNSURL()
. It may cause an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of having mechanism.GetNetNSURL()
as key is to sync the table IDs for every connection handled by a pod, if we use, for instance, the connection ID as key, and the pod requests 2 NSM connections with policies, there might be table ID collision.
Otherwise, with the mechanism.GetNetNSURL()
as key, I am not sure when to delete the entry from the map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, got it.
I thought that we can delete here an entry from tableIDs.Load(mechanism.GetNetNSURL()).policies
And somewhere here https://github.com/networkservicemesh/sdk-kernel/blob/main/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/common.go#L246
we can check:
if len(tableIDs.Load(mechanism.GetNetNSURL()).policies) == 0 {
tableIDs.Delete(mechanism.GetNetNSURL())
}
Do I understand correctly? Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this is a good idea. And probably we could iterate over the policy routes entries in the tableIDs map instead of the ones in the connection.
Also, before implementing it, flushing the table should be done since the counter will be reset. Otherwise when the entry will be remove and a new one will be added again, and tables will contain old routes.
} | ||
ps.policies[tableID] = policy | ||
tableIDs.Store(mechanism.GetNetNSURL(), ps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add ps
to tableIDs
after loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, if for some reason, routeAdd/ruleAdd fails, the previously added rules/routes will be forgotten, so I think it is better to keep the tableIDs update whithin the loop.
@LionelJouin I've built Could you please check this test? |
@NikitaSkrynnik I just tried it:
Without the changes:
With the changes, the table 2 is missing the default route. I removed these lines: |
* Based on memory, Policies are filtered: to add/to removed * Doesn't support forwarder resiliency. If the forwarder restart, the existing policy routes are forgotten Signed-off-by: Lionel Jouin <[email protected]>
* Flush table * Remove empty ip rule entries on close * Remove unused code Signed-off-by: Lionel Jouin <[email protected]>
@NikitaSkrynnik @glazychev-art @denis-tingaikin I fixed what have been discussed. Now the tables are flushed on connection close and the entries are removed from the map if they are empty. |
Thank you @LionelJouin ! We've tested this solution, and found a problem - Example:
Next, NSC requests the NSE-2:
Since the use of 1. Fix
|
@edwarnicke @denis-tingaikin @NikitaSkrynnik |
@LionelJouin , @edwarnicke , @glazychev-art I feel we need to try option 3 |
issue: #426