Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go 1.23
- name: Set up Go 1.24
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version: "1.24"
cache: false

- name: make ipxe
- name: fake ipxe binary
run: |
make ipxe
mkdir -p ipxe/ipxe/bin
touch ipxe/ipxe/bin/ipxe.bin

- name: Lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
args: -p bugs -p unused --timeout=3m
args: --timeout=3m

- name: remove fake ipxe binary
run: |
rm -rf ipxe/ipxe

- name: Make tag
run: |
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# be aware that bookworm has a newer gcc which can not compile the older ipxe
FROM golang:1.23-bullseye as builder
FROM golang:1.24-bullseye AS builder
WORKDIR /work
COPY . .
RUN apt update \
&& apt install --yes --no-install-recommends \
liblzma-dev \
&& make ipxe pixie

FROM alpine:3.20
RUN apk -U add ca-certificates
FROM gcr.io/distroless/static-debian12
COPY --from=builder /work/build/pixie /pixie
ENTRYPOINT ["/pixie"]
2 changes: 1 addition & 1 deletion dhcp4/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func newPortableConn(port int) (conn, error) {
}
l := ipv4.NewPacketConn(c)
if err = l.SetControlMessage(ipv4.FlagInterface, true); err != nil {
l.Close()
_ = l.Close()
return nil, err
}
return &portableConn{l}, nil
Expand Down
6 changes: 3 additions & 3 deletions dhcp4/conn_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func newLinuxConn(port int) (conn, error) {
}
r, err := ipv4.NewRawConn(c)
if err != nil {
c.Close()
_ = c.Close()
return nil, err
}
if err = r.SetControlMessage(ipv4.FlagInterface, true); err != nil {
c.Close()
_ = c.Close()
return nil, fmt.Errorf("setting packet filter: %w", err)
}
if err = r.SetBPF(filter); err != nil {
c.Close()
_ = c.Close()
return nil, fmt.Errorf("setting packet filter: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion dhcp4/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestPortableConn(t *testing.T) {
}
port := l.LocalAddr().(*net.UDPAddr).Port
addr := l.LocalAddr().String()
l.Close()
_ = l.Close()

c, err := newPortableConn(port)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion dhcp4/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func Unmarshal(bs []byte) (*Packet, error) {
return nil, fmt.Errorf("BOOTP message type (%d) doesn't match DHCP message type (%s", bs[0], ret.Type)
}
default:
return nil, fmt.Errorf("Unknown DHCP message type %d", ret.Type)
return nil, fmt.Errorf("unknown DHCP message type %d", ret.Type)
}

return ret, nil
Expand Down
12 changes: 6 additions & 6 deletions dhcp6/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func NewConn(addr, port string) (*Conn, error) {
}
pc := ipv6.NewPacketConn(c)
if err := pc.JoinGroup(ifi, &net.UDPAddr{IP: group}); err != nil {
pc.Close()
_ = pc.Close()
return nil, err
}

if err := pc.SetControlMessage(ipv6.FlagSrc|ipv6.FlagDst, true); err != nil {
pc.Close()
_ = pc.Close()
return nil, err
}

Expand All @@ -57,20 +57,20 @@ func (c *Conn) Close() error {
func InterfaceByAddress(ifAddr string) (*net.Interface, error) {
allIfis, err := net.Interfaces()
if err != nil {
return nil, fmt.Errorf("Error getting network interface information: %w", err)
return nil, fmt.Errorf("error getting network interface information: %w", err)
}
for _, ifi := range allIfis {
addrs, err := ifi.Addrs()
if err != nil {
return nil, fmt.Errorf("Error getting network interface address information: %w", err)
return nil, fmt.Errorf("error getting network interface address information: %w", err)
}
for _, addr := range addrs {
if addrToIP(addr).String() == ifAddr {
return &ifi, nil
}
}
}
return nil, fmt.Errorf("Couldn't find an interface with address %s", ifAddr)
return nil, fmt.Errorf("couldn't find an interface with address %s", ifAddr)
}

func addrToIP(a net.Addr) net.IP {
Expand Down Expand Up @@ -116,7 +116,7 @@ func (c *Conn) SendDHCP(dst net.IP, p []byte) error {
}
_, err := c.conn.WriteTo(p, nil, dstAddr)
if err != nil {
return fmt.Errorf("Error sending a reply to %s: %w", dst.String(), err)
return fmt.Errorf("error sending a reply to %s: %w", dst.String(), err)
}
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions dhcp6/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ func (o Options) Marshal() ([]byte, error) {
for _, o := range multipleOptions {
serialized, err := o.Marshal()
if err != nil {
return nil, fmt.Errorf("Error serializing option value: %w", err)
return nil, fmt.Errorf("error serializing option value: %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, serialized); err != nil {
return nil, fmt.Errorf("Error serializing option value: %w", err)
return nil, fmt.Errorf("error serializing option value: %w", err)
}
}
}
Expand All @@ -226,15 +226,15 @@ func (o *Option) Marshal() ([]byte, error) {

err := binary.Write(buffer, binary.BigEndian, o.ID)
if err != nil {
return nil, fmt.Errorf("Error serializing option id: %w", err)
return nil, fmt.Errorf("error serializing option id: %w", err)
}
err = binary.Write(buffer, binary.BigEndian, o.Length)
if err != nil {
return nil, fmt.Errorf("Error serializing option length: %w", err)
return nil, fmt.Errorf("error serializing option length: %w", err)
}
err = binary.Write(buffer, binary.BigEndian, o.Value)
if err != nil {
return nil, fmt.Errorf("Error serializing option value: %w", err)
return nil, fmt.Errorf("error serializing option value: %w", err)
}
return buffer.Bytes(), nil
}
Expand Down
8 changes: 4 additions & 4 deletions dhcp6/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (p *Packet) Marshal() ([]byte, error) {
return nil, fmt.Errorf("packet has malformed options section: %w", err)
}

ret := make([]byte, len(marshalledOptions)+4, len(marshalledOptions)+4)
ret := make([]byte, len(marshalledOptions)+4)
ret[0] = byte(p.Type)
copy(ret[1:], p.TransactionID[:])
copy(ret[4:], marshalledOptions)
Expand All @@ -71,7 +71,7 @@ func (p *Packet) ShouldDiscard(serverDuid []byte) error {
case MsgRelease:
return nil // FIX ME!
default:
return fmt.Errorf("Unknown packet")
return fmt.Errorf("unknown packet")
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func shouldDiscardRequest(p *Packet, serverDuid []byte) error {
if !options.HasServerID() {
return fmt.Errorf("'Request' packet has no server id option")
}
if bytes.Compare(options.ServerID(), serverDuid) != 0 {
if !bytes.Equal(options.ServerID(), serverDuid) {
return fmt.Errorf("'Request' packet's server id option (%d) is different from ours (%d)", options.ServerID(), serverDuid)
}
return nil
Expand All @@ -114,7 +114,7 @@ func shouldDiscardInformationRequest(p *Packet, serverDuid []byte) error {
if options.HasIaNa() || options.HasIaTa() {
return fmt.Errorf("'Information-request' packet has an IA option present")
}
if options.HasServerID() && (bytes.Compare(options.ServerID(), serverDuid) != 0) {
if options.HasServerID() && (!bytes.Equal(options.ServerID(), serverDuid)) {
return fmt.Errorf("'Information-request' packet's server id option (%d) is different from ours (%d)", options.ServerID(), serverDuid)
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions dhcp6/packet_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (b *PacketBuilder) makeMsgAdvertise(transactionID [3]byte, serverDUID, clie
MakeIaAddrOption(association.IPAddress, b.PreferredLifetime, b.ValidLifetime)))
}
retOptions.Add(MakeOption(OptServerID, serverDUID))
if 0x10 == clientArchType { // HTTPClient
if clientArchType == 0x10 { // HTTPClient
retOptions.Add(MakeOption(OptVendorClass, []byte{0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
}
retOptions.Add(MakeOption(OptBootfileURL, bootFileURL))
Expand All @@ -92,7 +92,7 @@ func (b *PacketBuilder) makeMsgReply(transactionID [3]byte, serverDUID, clientID
MakeStatusOption(2, err.Error())))
}
retOptions.Add(MakeOption(OptServerID, serverDUID))
if 0x10 == clientArchType { // HTTPClient
if clientArchType == 0x10 { // HTTPClient
retOptions.Add(MakeOption(OptVendorClass, []byte{0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
}
retOptions.Add(MakeOption(OptBootfileURL, bootFileURL))
Expand All @@ -108,7 +108,7 @@ func (b *PacketBuilder) makeMsgInformationRequestReply(transactionID [3]byte, se
retOptions := make(Options)
retOptions.Add(MakeOption(OptClientID, clientID))
retOptions.Add(MakeOption(OptServerID, serverDUID))
if 0x10 == clientArchType { // HTTPClient
if clientArchType == 0x10 { // HTTPClient
retOptions.Add(MakeOption(OptVendorClass, []byte{0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
}
retOptions.Add(MakeOption(OptBootfileURL, bootFileURL))
Expand All @@ -124,7 +124,7 @@ func (b *PacketBuilder) makeMsgReleaseReply(transactionID [3]byte, serverDUID, c

retOptions.Add(MakeOption(OptClientID, clientID))
retOptions.Add(MakeOption(OptServerID, serverDUID))
v := make([]byte, 19, 19)
v := make([]byte, 19)
copy(v[2:], []byte("Release received."))
retOptions.Add(MakeOption(OptStatusCode, v))

Expand Down
7 changes: 2 additions & 5 deletions dhcp6/pool/random_address_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p *RandomAddressPool) ReserveAddresses(clientID []byte, interfaceIDs [][]b
continue
}
if uint64(len(p.usedIps)) == p.poolSize {
return ret, fmt.Errorf("No more free ip addresses are currently available in the pool")
return ret, fmt.Errorf("no more free ip addresses are currently available in the pool")
}

for {
Expand Down Expand Up @@ -134,10 +134,7 @@ func (p *RandomAddressPool) ReleaseAddresses(clientID []byte, interfaceIDs [][]b
// expireIdentityAssociations releases IP addresses in identity associations that reached the end of valid lifetime
// back into the address pool. Note it should be called from under the RandomAddressPool.lock.
func (p *RandomAddressPool) expireIdentityAssociations() {
for {
if p.identityAssociationExpirations.Size() < 1 {
break
}
for p.identityAssociationExpirations.Size() >= 1 {
expiration := p.identityAssociationExpirations.Peek().(*associationExpiration)
if p.timeNow().Before(expiration.expiresAt) {
break
Expand Down
45 changes: 22 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
module github.com/metal-stack/pixie

go 1.23.0
go 1.24

require (
github.com/metal-stack/metal-api v0.39.3-0.20241112084334-e7ae92577d45
github.com/metal-stack/metal-api v0.41.2
github.com/metal-stack/v v1.0.3
github.com/pin/tftp/v3 v3.1.0
github.com/prometheus/client_golang v1.20.5
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.20.0-alpha.6
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.29.0
golang.org/x/net v0.31.0
google.golang.org/grpc v1.68.0
github.com/prometheus/client_golang v1.22.0
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.38.0
golang.org/x/net v0.40.0
google.golang.org/grpc v1.72.2
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.60.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.64.0 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/sagikazarmark/locafero v0.9.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/cast v1.8.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/protobuf v1.35.1 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading