Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade go and dependencies #51

Merged
merged 9 commits into from
May 16, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/after-merge-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- name: Fetch dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1.7.0
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '>=1.22'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
4 changes: 2 additions & 2 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
- name: set up go
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: "1.22"

- name: cache go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: "${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}"
restore-keys: |
${{ runner.os }}-go-

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
- name: set up go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- name: cache go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: "${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}"
restore-keys: |
${{ runner.os }}-go-

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`mdproxy4cs` is installed in our BOSH stemcell where it is used
to abstract the complexity to access the IaaS metadata from CloudStack
needed by the bosh-agent to finalise the virtual machines configuration.
needed by the bosh-agent to finalise the virtual machines' configuration.

Workflow:

Expand Down
38 changes: 18 additions & 20 deletions dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,35 @@ package main
import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/mdlayher/raw"
"github.com/mdlayher/packet"
"math/rand"
"net"
"syscall"
"time"
)

// Option -
type Option struct {
Type layers.DHCPOpt
Data []byte
}

// Client -
type Client struct {
Iface *net.Interface
xid uint32
cnx *raw.Conn
cnx *packet.Conn
}

func (client *Client) newPacket(msgType layers.DHCPMsgType) *layers.DHCPv4 {
packet := layers.DHCPv4{
dhcPv4 := layers.DHCPv4{
Operation: layers.DHCPOpRequest,
HardwareType: layers.LinkTypeEthernet,
ClientHWAddr: client.Iface.HardwareAddr,
Xid: client.xid, // Transaction ID
}

packet.Options = append(packet.Options, layers.DHCPOption{
dhcPv4.Options = append(dhcPv4.Options, layers.DHCPOption{
Type: layers.DHCPOptMessageType,
Data: []byte{byte(msgType)},
Length: 1,
})

return &packet
return &dhcPv4
}

func (client *Client) sendRequest(dhcp *layers.DHCPv4) error {
Expand Down Expand Up @@ -70,13 +65,13 @@ func (client *Client) sendRequest(dhcp *layers.DHCPv4) error {
return err
}

_, err = client.cnx.WriteTo(buf.Bytes(), &raw.Addr{HardwareAddr: eth.DstMAC})
_, err = client.cnx.WriteTo(buf.Bytes(), &packet.Addr{HardwareAddr: eth.DstMAC})
return err
}

func (client *Client) parsePacket(data []byte) *layers.DHCPv4 {
packet := gopacket.NewPacket(data, layers.LayerTypeEthernet, gopacket.Default)
dhcpLayer := packet.Layer(layers.LayerTypeDHCPv4)
newPacket := gopacket.NewPacket(data, layers.LayerTypeEthernet, gopacket.Default)
dhcpLayer := newPacket.Layer(layers.LayerTypeDHCPv4)

if dhcpLayer == nil {
return nil
Expand All @@ -85,23 +80,26 @@ func (client *Client) parsePacket(data []byte) *layers.DHCPv4 {
}

func (client *Client) readResponse(msgTypes ...layers.DHCPMsgType) (layers.DHCPMsgType, *net.IP, error) {
client.cnx.SetReadDeadline(time.Now().Add(time.Second * 5))
err := client.cnx.SetReadDeadline(time.Now().Add(time.Second * 5))
if err != nil {
return 0, nil, err
}
recvBuf := make([]byte, 1500)
for {
_, _, err := client.cnx.ReadFrom(recvBuf)
if err != nil {
return 0, nil, err
}
packet := client.parsePacket(recvBuf)
if packet == nil {
parsePacket := client.parsePacket(recvBuf)
if parsePacket == nil {
continue
}

var msgType layers.DHCPMsgType
var resIP net.IP

if packet.Xid == client.xid && packet.Operation == layers.DHCPOpReply {
for _, option := range packet.Options {
if parsePacket.Xid == client.xid && parsePacket.Operation == layers.DHCPOpReply {
for _, option := range parsePacket.Options {
switch option.Type {
case layers.DHCPOptMessageType:
if option.Length == 1 {
Expand All @@ -122,7 +120,7 @@ func (client *Client) readResponse(msgTypes ...layers.DHCPMsgType) (layers.DHCPM

// DiscoverServer -
func (client *Client) DiscoverServer() (*net.IP, error) {
cnx, err := raw.ListenPacket(client.Iface, uint16(layers.EthernetTypeIPv4), nil)
cnx, err := packet.Listen(client.Iface, packet.Datagram, syscall.ETH_P_IP, nil)
if err != nil {
return nil, err
}
Expand Down
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
module github.com/orange-cloudfoundry/mdproxy4cs

go 1.21
go 1.22.3

require (
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/google/gopacket v1.1.19
github.com/mdlayher/raw v0.1.0
github.com/mdlayher/packet v1.1.2
github.com/prometheus/common v0.53.0
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect
github.com/josharian/native v1.1.0 // indirect
github.com/mdlayher/packet v1.1.2 // indirect
github.com/mdlayher/socket v0.5.0 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
)
18 changes: 8 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtL
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY=
github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
github.com/mdlayher/raw v0.1.0 h1:K4PFMVy+AFsp0Zdlrts7yNhxc/uXoPVHi9RzRvtZF2Y=
github.com/mdlayher/raw v0.1.0/go.mod h1:yXnxvs6c0XoF/aK52/H5PjsVHmWBCFfZUfoh/Y5s9Sg=
github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI=
github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+aLCE=
Expand All @@ -36,16 +34,16 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPI
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
log.Debugf("serving response to %s: %s", r.URL.Path, string(content))
w.WriteHeader(res.StatusCode)
w.Write(content)
if _, err := w.Write(content); err != nil {
log.Errorf("writing content failed: %s", err)
}
}

func (a *App) getVrouterAddress() string {
Expand Down
9 changes: 0 additions & 9 deletions vendor/github.com/mdlayher/raw/LICENSE.md

This file was deleted.

25 changes: 0 additions & 25 deletions vendor/github.com/mdlayher/raw/README.md

This file was deleted.

Loading
Loading