Skip to content

🐛 ipset.Check() has problem when version is v7+ #10

@catcher-Rye

Description

@catcher-Rye
  • version
> ipset --version
ipset v7.1, protocol version: 7
Warning: Kernel support protocol versions 6-6 while userspace supports protocol versions 6-7
  • this code will return more than version info
out, err := execCommand(ipsetPath, _version).CombinedOutput()

# out is like this
Warning: Kernel support protocol versions 6-6 while userspace supports protocol versions 6-7
ipset v7.1, protocol version: 7
  • this code can not get real version
func getMajorVersion(version []byte) int {
	vIndex := bytes.IndexByte(version, 'v')
	dotIndex := bytes.IndexByte(version, '.')
	var majorVersion int
	for i := vIndex + 1; i < dotIndex; i++ {
		if c := version[i]; c >= '0' && c <= '9' {
			majorVersion = majorVersion*10 + int(c-'0')
		} else {
			return 0
		}
	}

	return majorVersion
}
  • case error
ipset utility version is not supported, requiring version >= 6.0

this code can replace by regexp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions