-
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
Add iptables4nattemplate chain element, refactor routelocalnet chain element #467
Conversation
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 think you could be instrested in this
sdk-kernel/pkg/kernel/tools/nshandle/ns_handle.go
Lines 37 to 53 in 0125eaf
func FromURL(urlString string) (handle netns.NsHandle, err error) { | |
var netNSURL *url.URL | |
netNSURL, err = url.Parse(urlString) | |
if err != nil || netNSURL.Scheme != "file" { | |
return -1, errors.Wrapf(err, "invalid url: %v", urlString) | |
} | |
handle, err = netns.GetFromPath(netNSURL.Path) | |
if err != nil { | |
return -1, errors.Wrapf(err, "failed to obtain network NS handle") | |
} | |
return handle, nil | |
} | |
// RunIn runs runner in the given net NS | |
func RunIn(current, target netns.NsHandle, runner func() error) error { |
a1aedda
to
21c1649
Compare
|
||
// NewServer - returns a new networkservice.NetworkServiceServer that modify IPTables rules | ||
// by mechanism provided template on Request and rollbacks rules changes on Close | ||
func NewServer(options ...Option) networkservice.NetworkServiceServer { |
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.
Do we really need options if dont have tests for this moment?
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 left it for the future. I agree, it is better to remove unused feature it for now. Done.
@edwarnicke , @rejmond Could we use this https://github.com/coreos/go-iptables/blob/master/iptables/iptables.go? |
@denis-tingaikin Does it simply anything? In the background I think its still just calling iptables, right? |
@edwarnicke yeah, you're right. I looked quickly and didnt check that. Exechelper is looking better to me here. |
@denis-tingaikin I had exactly the same thought you did and looked at this module over the weekend :) . But sometimes you notice details I miss, thus my question :) |
eb7f421
to
279e41b
Compare
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.
@rejmond Did we test this in real world?
//go:build linux | ||
// +build linux | ||
|
||
package applyiptables4nattemplate |
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.
package applyiptables4nattemplate | |
package applyiptables |
or
package applyiptables4nattemplate | |
package iptables |
I think it could be better.
2b53a6d
to
42c13d3
Compare
} | ||
|
||
func (m *iptableManagerImpl) Apply(rulesTemplate string) error { | ||
rules := strings.Split(rulesTemplate, ";") |
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.
rules := strings.Split(rulesTemplate, ";") | |
rules := strings.Split(rulesTemplate, "\n") |
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.
Apply
accepts rules []string
now, spliting is no longer required.
|
||
for _, rule := range rules { | ||
// Remove possible tabs and spaces from a multistring template | ||
rule = strings.Trim(rule, "\t ") |
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.
rule = strings.Trim(rule, "\t ") | |
rule = strings.TrimSpace(rule) |
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.
Removed Trim function at all.
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.
Added few comments others things are fine for the first step
} | ||
|
||
func (c *iptablesClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { | ||
ctxMap := metadata.Map(ctx, metadata.IsClient(c)) |
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.
We also should consider about closing if someting went wrong
See at example
https://github.com/networkservicemesh/sdk-kernel/blob/main/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/client.go#L69 and https://github.com/networkservicemesh/sdk-kernel/blob/main/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/client.go#L77-L84
9bd5e37
to
0023de2
Compare
@rejmond Could you please resolve conflicts? Please just run |
15f1b77
to
bac4bfb
Compare
…ernel chain * Turn routelocalnet chain element to a client element and move to cmnnectioncontextkernel chain * Add setroutelocalnet chain server element Signed-off-by: Sergey Shlyanin <sergey.shlyanin@xored.com>
…k-kernel@main PR link: networkservicemesh/sdk-kernel#467 Commit: e0f2b84 Author: Denis Tingaikin Date: 2022-05-13 12:42:28 +0300 Message: - Merge pull request #467 from rejmond/issue-463 Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k-kernel@main PR link: networkservicemesh/sdk-kernel#467 Commit: e0f2b84 Author: Denis Tingaikin Date: 2022-05-13 12:42:28 +0300 Message: - Merge pull request #467 from rejmond/issue-463 Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
Signed-off-by: Sergey Shlyanin sergey.shlyanin@xored.com
Description
iptables4nattemplate
chain client element that apply iptables nat rules onRequest
and restore them onClose
.iptables4nattemplate
is as a part ofconnectioncontextkernel
client chainroutelocalnet
to a client chain element and move it toconnectioncontextkernel
client chainsetroutelocalnet
chain server element for setting a flag to kernel mechanismIssue
#463
#464