Skip to content

Commit 99a5754

Browse files
authored
Update to go-1.24, linter v2 and satisfy new linter warnings (#33)
1 parent 5457829 commit 99a5754

File tree

20 files changed

+167
-124
lines changed

20 files changed

+167
-124
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,25 @@ jobs:
3131
- name: Check out code into the Go module directory
3232
uses: actions/checkout@v4
3333

34-
- name: Set up Go 1.23
34+
- name: Set up Go 1.24
3535
uses: actions/setup-go@v5
3636
with:
37-
go-version: "1.23"
37+
go-version: "1.24"
3838
cache: false
3939

40-
- name: make ipxe
40+
- name: fake ipxe binary
4141
run: |
42-
make ipxe
42+
mkdir -p ipxe/ipxe/bin
43+
touch ipxe/ipxe/bin/ipxe.bin
4344
4445
- name: Lint
45-
uses: golangci/golangci-lint-action@v6
46+
uses: golangci/golangci-lint-action@v7
4647
with:
47-
args: -p bugs -p unused --timeout=3m
48+
args: --timeout=3m
49+
50+
- name: remove fake ipxe binary
51+
run: |
52+
rm -rf ipxe/ipxe
4853
4954
- name: Make tag
5055
run: |

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# be aware that bookworm has a newer gcc which can not compile the older ipxe
2-
FROM golang:1.23-bullseye as builder
2+
FROM golang:1.24-bullseye AS builder
33
WORKDIR /work
44
COPY . .
55
RUN apt update \
66
&& apt install --yes --no-install-recommends \
77
liblzma-dev \
88
&& make ipxe pixie
99

10-
FROM alpine:3.20
11-
RUN apk -U add ca-certificates
10+
FROM gcr.io/distroless/static-debian12
1211
COPY --from=builder /work/build/pixie /pixie
1312
ENTRYPOINT ["/pixie"]

dhcp4/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func newPortableConn(port int) (conn, error) {
229229
}
230230
l := ipv4.NewPacketConn(c)
231231
if err = l.SetControlMessage(ipv4.FlagInterface, true); err != nil {
232-
l.Close()
232+
_ = l.Close()
233233
return nil, err
234234
}
235235
return &portableConn{l}, nil

dhcp4/conn_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ func newLinuxConn(port int) (conn, error) {
6868
}
6969
r, err := ipv4.NewRawConn(c)
7070
if err != nil {
71-
c.Close()
71+
_ = c.Close()
7272
return nil, err
7373
}
7474
if err = r.SetControlMessage(ipv4.FlagInterface, true); err != nil {
75-
c.Close()
75+
_ = c.Close()
7676
return nil, fmt.Errorf("setting packet filter: %w", err)
7777
}
7878
if err = r.SetBPF(filter); err != nil {
79-
c.Close()
79+
_ = c.Close()
8080
return nil, fmt.Errorf("setting packet filter: %w", err)
8181
}
8282

dhcp4/conn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func TestPortableConn(t *testing.T) {
127127
}
128128
port := l.LocalAddr().(*net.UDPAddr).Port
129129
addr := l.LocalAddr().String()
130-
l.Close()
130+
_ = l.Close()
131131

132132
c, err := newPortableConn(port)
133133
if err != nil {

dhcp4/packet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func Unmarshal(bs []byte) (*Packet, error) {
332332
return nil, fmt.Errorf("BOOTP message type (%d) doesn't match DHCP message type (%s", bs[0], ret.Type)
333333
}
334334
default:
335-
return nil, fmt.Errorf("Unknown DHCP message type %d", ret.Type)
335+
return nil, fmt.Errorf("unknown DHCP message type %d", ret.Type)
336336
}
337337

338338
return ret, nil

dhcp6/conn.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ func NewConn(addr, port string) (*Conn, error) {
3030
}
3131
pc := ipv6.NewPacketConn(c)
3232
if err := pc.JoinGroup(ifi, &net.UDPAddr{IP: group}); err != nil {
33-
pc.Close()
33+
_ = pc.Close()
3434
return nil, err
3535
}
3636

3737
if err := pc.SetControlMessage(ipv6.FlagSrc|ipv6.FlagDst, true); err != nil {
38-
pc.Close()
38+
_ = pc.Close()
3939
return nil, err
4040
}
4141

@@ -57,20 +57,20 @@ func (c *Conn) Close() error {
5757
func InterfaceByAddress(ifAddr string) (*net.Interface, error) {
5858
allIfis, err := net.Interfaces()
5959
if err != nil {
60-
return nil, fmt.Errorf("Error getting network interface information: %w", err)
60+
return nil, fmt.Errorf("error getting network interface information: %w", err)
6161
}
6262
for _, ifi := range allIfis {
6363
addrs, err := ifi.Addrs()
6464
if err != nil {
65-
return nil, fmt.Errorf("Error getting network interface address information: %w", err)
65+
return nil, fmt.Errorf("error getting network interface address information: %w", err)
6666
}
6767
for _, addr := range addrs {
6868
if addrToIP(addr).String() == ifAddr {
6969
return &ifi, nil
7070
}
7171
}
7272
}
73-
return nil, fmt.Errorf("Couldn't find an interface with address %s", ifAddr)
73+
return nil, fmt.Errorf("couldn't find an interface with address %s", ifAddr)
7474
}
7575

7676
func addrToIP(a net.Addr) net.IP {
@@ -116,7 +116,7 @@ func (c *Conn) SendDHCP(dst net.IP, p []byte) error {
116116
}
117117
_, err := c.conn.WriteTo(p, nil, dstAddr)
118118
if err != nil {
119-
return fmt.Errorf("Error sending a reply to %s: %w", dst.String(), err)
119+
return fmt.Errorf("error sending a reply to %s: %w", dst.String(), err)
120120
}
121121
return nil
122122
}

dhcp6/options.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ func (o Options) Marshal() ([]byte, error) {
210210
for _, o := range multipleOptions {
211211
serialized, err := o.Marshal()
212212
if err != nil {
213-
return nil, fmt.Errorf("Error serializing option value: %w", err)
213+
return nil, fmt.Errorf("error serializing option value: %w", err)
214214
}
215215
if err := binary.Write(buffer, binary.BigEndian, serialized); err != nil {
216-
return nil, fmt.Errorf("Error serializing option value: %w", err)
216+
return nil, fmt.Errorf("error serializing option value: %w", err)
217217
}
218218
}
219219
}
@@ -226,15 +226,15 @@ func (o *Option) Marshal() ([]byte, error) {
226226

227227
err := binary.Write(buffer, binary.BigEndian, o.ID)
228228
if err != nil {
229-
return nil, fmt.Errorf("Error serializing option id: %w", err)
229+
return nil, fmt.Errorf("error serializing option id: %w", err)
230230
}
231231
err = binary.Write(buffer, binary.BigEndian, o.Length)
232232
if err != nil {
233-
return nil, fmt.Errorf("Error serializing option length: %w", err)
233+
return nil, fmt.Errorf("error serializing option length: %w", err)
234234
}
235235
err = binary.Write(buffer, binary.BigEndian, o.Value)
236236
if err != nil {
237-
return nil, fmt.Errorf("Error serializing option value: %w", err)
237+
return nil, fmt.Errorf("error serializing option value: %w", err)
238238
}
239239
return buffer.Bytes(), nil
240240
}

dhcp6/packet.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (p *Packet) Marshal() ([]byte, error) {
5050
return nil, fmt.Errorf("packet has malformed options section: %w", err)
5151
}
5252

53-
ret := make([]byte, len(marshalledOptions)+4, len(marshalledOptions)+4)
53+
ret := make([]byte, len(marshalledOptions)+4)
5454
ret[0] = byte(p.Type)
5555
copy(ret[1:], p.TransactionID[:])
5656
copy(ret[4:], marshalledOptions)
@@ -71,7 +71,7 @@ func (p *Packet) ShouldDiscard(serverDuid []byte) error {
7171
case MsgRelease:
7272
return nil // FIX ME!
7373
default:
74-
return fmt.Errorf("Unknown packet")
74+
return fmt.Errorf("unknown packet")
7575
}
7676
}
7777

@@ -100,7 +100,7 @@ func shouldDiscardRequest(p *Packet, serverDuid []byte) error {
100100
if !options.HasServerID() {
101101
return fmt.Errorf("'Request' packet has no server id option")
102102
}
103-
if bytes.Compare(options.ServerID(), serverDuid) != 0 {
103+
if !bytes.Equal(options.ServerID(), serverDuid) {
104104
return fmt.Errorf("'Request' packet's server id option (%d) is different from ours (%d)", options.ServerID(), serverDuid)
105105
}
106106
return nil
@@ -114,7 +114,7 @@ func shouldDiscardInformationRequest(p *Packet, serverDuid []byte) error {
114114
if options.HasIaNa() || options.HasIaTa() {
115115
return fmt.Errorf("'Information-request' packet has an IA option present")
116116
}
117-
if options.HasServerID() && (bytes.Compare(options.ServerID(), serverDuid) != 0) {
117+
if options.HasServerID() && (!bytes.Equal(options.ServerID(), serverDuid)) {
118118
return fmt.Errorf("'Information-request' packet's server id option (%d) is different from ours (%d)", options.ServerID(), serverDuid)
119119
}
120120
return nil

dhcp6/packet_builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (b *PacketBuilder) makeMsgAdvertise(transactionID [3]byte, serverDUID, clie
6565
MakeIaAddrOption(association.IPAddress, b.PreferredLifetime, b.ValidLifetime)))
6666
}
6767
retOptions.Add(MakeOption(OptServerID, serverDUID))
68-
if 0x10 == clientArchType { // HTTPClient
68+
if clientArchType == 0x10 { // HTTPClient
6969
retOptions.Add(MakeOption(OptVendorClass, []byte{0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
7070
}
7171
retOptions.Add(MakeOption(OptBootfileURL, bootFileURL))
@@ -92,7 +92,7 @@ func (b *PacketBuilder) makeMsgReply(transactionID [3]byte, serverDUID, clientID
9292
MakeStatusOption(2, err.Error())))
9393
}
9494
retOptions.Add(MakeOption(OptServerID, serverDUID))
95-
if 0x10 == clientArchType { // HTTPClient
95+
if clientArchType == 0x10 { // HTTPClient
9696
retOptions.Add(MakeOption(OptVendorClass, []byte{0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
9797
}
9898
retOptions.Add(MakeOption(OptBootfileURL, bootFileURL))
@@ -108,7 +108,7 @@ func (b *PacketBuilder) makeMsgInformationRequestReply(transactionID [3]byte, se
108108
retOptions := make(Options)
109109
retOptions.Add(MakeOption(OptClientID, clientID))
110110
retOptions.Add(MakeOption(OptServerID, serverDUID))
111-
if 0x10 == clientArchType { // HTTPClient
111+
if clientArchType == 0x10 { // HTTPClient
112112
retOptions.Add(MakeOption(OptVendorClass, []byte{0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
113113
}
114114
retOptions.Add(MakeOption(OptBootfileURL, bootFileURL))
@@ -124,7 +124,7 @@ func (b *PacketBuilder) makeMsgReleaseReply(transactionID [3]byte, serverDUID, c
124124

125125
retOptions.Add(MakeOption(OptClientID, clientID))
126126
retOptions.Add(MakeOption(OptServerID, serverDUID))
127-
v := make([]byte, 19, 19)
127+
v := make([]byte, 19)
128128
copy(v[2:], []byte("Release received."))
129129
retOptions.Add(MakeOption(OptStatusCode, v))
130130

0 commit comments

Comments
 (0)