Skip to content

Commit

Permalink
genetlink: bump minimum version of Go to 1.18
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Layher <mdlayher@gmail.com>
  • Loading branch information
mdlayher committed Nov 12, 2022
1 parent 3a2f76c commit 68fc8ca
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 217 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# CHANGELOG

# v1.3.0

**This is the first release of package genetlink that only supports Go 1.18+.
Users on older versions of Go must use v1.2.0.**

- [Improvement]: drop support for older versions of Go so we can begin using
modern versions of `x/sys` and other dependencies.

## v1.2.0

**This is the first release of package netlink that only supports Go 1.13+.
Users on older versions of Go must use v1.1.0.**
**This is the last release of package genetlink that supports Go 1.17 and
below.**

- [Improvement]: pruned Go module dependencies via package `netlink` v1.6.0 and
removing tool version pins.
Expand Down
5 changes: 2 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
MIT License
===========
# MIT License

Copyright (C) 2016-2017 Matt Layher
Copyright (C) 2016-2022 Matt Layher

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ This package has a stable v1 API and any future breaking changes will prompt
the release of a new major version. Features and bug fixes will continue to
occur in the v1.x.x series.

In order to reduce the maintenance burden, this package is only supported on
Go 1.12+. Older versions of Go lack critical features and APIs which are
necessary for this package to function correctly.

**If you depend on this package in your applications, please use Go modules.**
This package only supports the two most recent major versions of Go, mirroring
Go's own release policy. Older versions of Go may lack critical features and bug
fixes which are necessary for this package to function correctly.
171 changes: 0 additions & 171 deletions conn_linux_integration_go1.13_test.go

This file was deleted.

158 changes: 157 additions & 1 deletion conn_linux_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//go:build linux
// +build linux

package genetlink_test

import (
"errors"
"fmt"
"net"
"os"
"sync"
"testing"
Expand Down Expand Up @@ -176,6 +176,162 @@ func TestIntegrationConnConcurrentSerializeExecute(t *testing.T) {
}
}

func TestIntegrationConnGetFamilyIsNotExist(t *testing.T) {
// Test that the documented behavior of returning an error that is compatible
// with netlink.IsNotExist is correct.
const name = "NOTEXISTS"

c, err := genetlink.Dial(nil)
if err != nil {
t.Fatalf("failed to dial generic netlink: %v", err)
}

if _, err := c.GetFamily(name); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("expected not exist error, got: %v", err)
}

if err := c.Close(); err != nil {
t.Fatalf("error closing netlink connection: %v", err)
}
}

func TestIntegrationConnGetFamily(t *testing.T) {
c, err := genetlink.Dial(nil)
if err != nil {
t.Fatalf("failed to dial generic netlink: %v", err)
}

const name = "nlctrl"
family, err := c.GetFamily(name)
if err != nil {
// nlctrl *should* always exist in order for genetlink to work at all.
if errors.Is(err, os.ErrNotExist) {
t.Fatal(errNLCtrlMissing)
}

t.Fatalf("failed to query for family: %v", err)
}

if err := c.Close(); err != nil {
t.Fatalf("error closing netlink connection: %v", err)
}

if want, got := name, family.Name; want != got {
t.Fatalf("unexpected family name:\n- want: %q\n- got: %q", want, got)
}
}

func TestIntegrationConnNL80211(t *testing.T) {
c, err := genetlink.Dial(nil)
if err != nil {
t.Fatalf("failed to dial generic netlink: %v", err)
}

const (
name = "nl80211"

nl80211CommandGetInterface = 5

nl80211AttributeInterfaceIndex = 3
nl80211AttributeInterfaceName = 4
nl80211AttributeAttributeMAC = 6
)

family, err := c.GetFamily(name)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
t.Skipf("skipping because %q family not available", name)
}

t.Fatalf("failed to query for family: %v", err)
}

req := genetlink.Message{
Header: genetlink.Header{
Command: nl80211CommandGetInterface,
Version: family.Version,
},
}

flags := netlink.Request | netlink.Dump
msgs, err := c.Execute(req, family.ID, flags)
if err != nil {
t.Fatalf("failed to execute: %v", err)
}

if err := c.Close(); err != nil {
t.Fatalf("error closing netlink connection: %v", err)
}

type ifInfo struct {
Index int
Name string
MAC net.HardwareAddr
}

var infos []ifInfo
for _, m := range msgs {
ad, err := netlink.NewAttributeDecoder(m.Data)
if err != nil {
t.Fatalf("failed to create attribute decoder: %v", err)
}

var info ifInfo
for ad.Next() {
switch ad.Type() {
case nl80211AttributeInterfaceIndex:
info.Index = int(ad.Uint32())
case nl80211AttributeInterfaceName:
info.Name = ad.String()
case nl80211AttributeAttributeMAC:
ad.Do(func(b []byte) error {
if l := len(b); l != 6 {
return fmt.Errorf("unexpected MAC length: %d", l)
}

info.MAC = net.HardwareAddr(b)
return nil
})
}
}

if err := ad.Err(); err != nil {
t.Fatalf("failed to decode attributes: %v", err)
}

infos = append(infos, info)
}

// Verify that nl80211 reported the same information as package net
for _, info := range infos {
// TODO(mdlayher): figure out why nl80211 returns a subdevice with
// an empty name on newer kernel
if info.Name == "" {
continue
}

ifi, err := net.InterfaceByName(info.Name)
if err != nil {
t.Fatalf("error retrieving interface %q: %v", info.Name, err)
}

if want, got := ifi.Index, info.Index; want != got {
t.Fatalf("unexpected interface index for %q:\n- want: %v\n- got: %v",
ifi.Name, want, got)
}

if want, got := ifi.Name, info.Name; want != got {
t.Fatalf("unexpected interface name:\n- want: %q\n- got: %q",
want, got)
}

if want, got := ifi.HardwareAddr.String(), info.MAC.String(); want != got {
t.Fatalf("unexpected interface MAC for %q:\n- want: %q\n- got: %q",
ifi.Name, want, got)
}
}
}

func panicf(format string, a ...interface{}) {
panic(fmt.Sprintf(format, a...))
}
3 changes: 0 additions & 3 deletions example_go1.13_test.go → example_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build go1.13
// +build go1.13

package genetlink_test

import (
Expand Down
Loading

0 comments on commit 68fc8ca

Please sign in to comment.