Skip to content

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

Merged
vishvananda merged 1 commit intovishvananda:masterfrom
Cordius:master
Sep 14, 2020
Merged

rule_linux: convert IIFNAME and OIFNAME to null terminated string#559
vishvananda merged 1 commit intovishvananda:masterfrom
Cordius:master

Conversation

@Cordius
Copy link
Copy Markdown

@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
Copy Markdown
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