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

rule_linux: convert IIFNAME and OIFNAME to null terminated string #559

Merged
merged 1 commit into from
Sep 14, 2020
Merged

Conversation

Cordius
Copy link

@Cordius Cordius commented Aug 18, 2020

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

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>
@Cordius
Copy link
Author

Cordius commented Aug 18, 2020

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")
                }
        }

}

@vishvananda vishvananda merged commit e909d4e into vishvananda:master Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants