CodeSampleX

Sample

github.com/vishvananda/netlink v1.1.0: AddrList, LinkByName, LinkList

Verified sample for golang github.com/vishvananda/netlink v1.1.0: AddrList, LinkByName, LinkList. The contract ran on go 1.26 · linux alpine/x64 · docker and…

sha256:de0537148b0ea4c1ea03e8e5ea958c1767204e98f8146b72b450dbe42a0cfd25

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-27

Case

HOW
Goal
verify pkg:golang/github.com/vishvananda/netlink@v1.1.0
Packages
Symbols
  • netlink.AddrList
  • netlink.LinkByName
  • netlink.LinkList
  • netlink.ParseAddr
Created
2026-08-27T15:14:07Z

Contract

  1. netlink.LinkByName("lo") returns loopback Link with Name="lo"
  2. netlink.LinkByName returns non-nil error when link does not exist
  3. netlink.ParseAddr parses IPv4 CIDR string into Addr with correct IP and mask size
  4. netlink.ParseAddr parses IPv6 CIDR string into Addr with correct IP and mask size
  5. netlink.ParseAddr returns non-nil error for invalid CIDR string
  6. netlink.AddrList on loopback Link returns IPv4 address 127.0.0.1
  7. netlink.AddrList with FAMILY_ALL returns all configured loopback addresses
  8. netlink.LinkList returns non-empty slice of network Links including loopback

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract_test.go

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:golang/github.com/vishvananda/netlink@v1.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/vishvananda/netlink@v1.1.0
Demonstrate these symbols/APIs:
  - netlink.AddrList
  - netlink.LinkByName
  - netlink.LinkList
  - netlink.ParseAddr

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:05d67f3b81262927a637bdc445e057277b616c053e1f21ff4673b3d5bce25581","contract":["netlink.LinkByName(\"lo\") returns loopback Link with Name=\"lo\"","netlink.LinkByName returns non-nil error when link does not exist","netlink.ParseAddr parses IPv4 CIDR string into Addr with correct IP and mask size","netlink.ParseAddr parses IPv6 CIDR string into Addr with correct IP and mask size","netlink.ParseAddr returns non-nil error for invalid CIDR string","netlink.AddrList on loopback Link returns IPv4 address 127.0.0.1","netlink.AddrList with FAMILY_ALL returns all configured loopback addresses","netlink.LinkList returns non-empty slice of network Links including loopback"],"goal":"verify pkg:golang/github.com/vishvananda/netlink@v1.1.0","kind":"HOW","packages":["pkg:golang/github.com/vishvananda/netlink@v1.1.0"],"schemaVersion":1,"symbols":["netlink.AddrList","netlink.LinkByName","netlink.LinkList","netlink.ParseAddr"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/vishvananda/netlink@v1.1.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/vishvananda/netlink@v1.1.0","symbols":["netlink.AddrList","netlink.LinkByName","netlink.LinkList","netlink.ParseAddr"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/vishvananda/netlink v1.1.0

require (
	github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
	golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444 // indirect
)
go.sum
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444 h1:/d2cWp6PSamH4jDPFLyO150psQdqvtoNX8Zjg3AQ31g=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/vishvananda/netlink@v1.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/vishvananda/netlink@v1.1.0"
  ],
  "symbols": [
    "netlink.AddrList",
    "netlink.LinkByName",
    "netlink.LinkList",
    "netlink.ParseAddr"
  ]
}
test/contract_test.go
package test

import (
	"net"
	"testing"

	"github.com/vishvananda/netlink"
)

func TestNetlinkContract(t *testing.T) {
	// 1. netlink.LinkByName - retrieve loopback interface
	lo, err := netlink.LinkByName("lo")
	if err != nil {
		t.Fatalf("netlink.LinkByName('lo') failed: %v", err)
	}
	attrs := lo.Attrs()
	if attrs.Name != "lo" {
		t.Fatalf("expected link name 'lo', got '%s'", attrs.Name)
	}

	// Verify netlink.LinkByName returns error for non-existent link
	_, err = netlink.LinkByName("nonexistent_dev_99")
	if err == nil {
		t.Fatalf("expected error for non-existent link, got nil")
	}

	// 2. netlink.ParseAddr - valid IPv4 CIDR
	addrV4, err := netlink.ParseAddr("192.168.10.1/24")
	if err != nil {
		t.Fatalf("netlink.ParseAddr('192.168.10.1/24') failed: %v", err)
	}
	if addrV4.IP.String() != "192.168.10.1" {
		t.Errorf("expected IP 192.168.10.1, got %s", addrV4.IP.String())
	}
	ones, bits := addrV4.Mask.Size()
	if ones != 24 || bits != 32 {
		t.Errorf("expected /24 mask (ones=24, bits=32), got ones=%d, bits=%d", ones, bits)
	}

	// netlink.ParseAddr - valid IPv6 CIDR
	addrV6, err := netlink.ParseAddr("2001:db8::1/64")
	if err != nil {
		t.Fatalf("netlink.ParseAddr('2001:db8::1/64') failed: %v", err)
	}
	if addrV6.IP.String() != "2001:db8::1" {
		t.Errorf("expected IP 2001:db8::1, got %s", addrV6.IP.String())
	}
	ones6, bits6 := addrV6.Mask.Size()
	if ones6 != 64 || bits6 != 128 {
		t.Errorf("expected /64 mask (ones=64, bits=128), got ones=%d, bits=%d", ones6, bits6)
	}

	// netlink.ParseAddr - invalid CIDR returns error
	_, err = netlink.ParseAddr("invalid-cidr-string")
	if err == nil {
		t.Fatalf("expected error parsing invalid cidr string, got nil")
	}

	// 3. netlink.AddrList - list addresses on loopback interface
	v4Addrs, err := netlink.AddrList(lo, netlink.FAMILY_V4)
	if err != nil {
		t.Fatalf("netlink.AddrList(lo, FAMILY_V4) failed: %v", err)
	}
	foundLoopbackIPv4 := false
	for _, a := range v4Addrs {
		if a.IP.Equal(net.IPv4(127, 0, 0, 1)) {
			foundLoopbackIPv4 = true
			break
		}
	}
	if !foundLoopbackIPv4 {
		t.Errorf("expected 127.0.0.1 address in AddrList(lo, FAMILY_V4), got %v", v4Addrs)
	}

	allAddrs, err := netlink.AddrList(lo, netlink.FAMILY_ALL)
	if err != nil {
		t.Fatalf("netlink.AddrList(lo, FAMILY_ALL) failed: %v", err)
	}
	if len(allAddrs) == 0 {
		t.Errorf("expected at least 1 address in AddrList(lo, FAMILY_ALL), got 0")
	}

	// 4. netlink.LinkList - list all network links
	links, err := netlink.LinkList()
	if err != nil {
		t.Fatalf("netlink.LinkList() failed: %v", err)
	}
	if len(links) == 0 {
		t.Fatalf("expected at least 1 network link, got 0")
	}
	foundLoInList := false
	for _, l := range links {
		if l.Attrs().Name == "lo" {
			foundLoInList = true
			break
		}
	}
	if !foundLoInList {
		t.Errorf("expected loopback link in LinkList(), got %v", links)
	}
}

Origin Seeder

anonymous