rule_linux: convert IIFNAME and OIFNAME to null terminated string#559
Merged
vishvananda merged 1 commit intovishvananda:masterfrom Sep 14, 2020
Cordius:master
Merged
rule_linux: convert IIFNAME and OIFNAME to null terminated string#559vishvananda merged 1 commit intovishvananda:masterfrom Cordius:master
vishvananda merged 1 commit intovishvananda:masterfrom
Cordius:master
Conversation
Strings in GO is not null-terminated while linux is written by C and strings in C is null-terminated. Request will fail if we perform rule request with not null-terminated iifname or ofiname, with error message "no such file or directory". Signed-off-by: Wu Zongyong <wuzongyong@linux.alibaba.com>
Author
|
Test Code package main
import (
"fmt"
"github.com/pkg/errors"
"github.com/vishvananda/netlink"
)
func main() {
rule := netlink.NewRule()
rule.Priority = 1000
rule.IifName = "test"
rule.Family = netlink.FAMILY_V4
rule.Table = 100
if err := netlink.RuleAdd(rule); err != nil {
fmt.Println(errors.Wrapf(err, "add rule error"))
return
}
rules, err := netlink.RuleList(netlink.FAMILY_V4)
if err != nil {
fmt.Println(errors.Wrapf(err, "list rules error"))
return
}
for _, rule := range rules {
if rule.Table == 100 {
if err := netlink.RuleDel(&rule); err != nil {
fmt.Println(errors.Wrapf(err, "delete rules error"))
return
}
fmt.Println("delete ok")
}
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Strings in GO is not null-terminated while linux is written by
C and strings in C is null-terminated. Request will fail if we
perform rule request with not null-terminated iifname or ofiname,
with error message "no such file or directory".
It has been tested on CentOS 7.x while in newer kernel version such
as 4.19 this issue doesn't exist
Signed-off-by: Wu Zongyong wuzongyong@linux.alibaba.com