Skip to content

Commit eecb06e

Browse files
vista-ggidofalvy-tc
authored andcommitted
Move UDP-related functions and variables into separate file, add/fix some comments
1 parent 9b551e7 commit eecb06e

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

dhcpv4/nclient4/conn_unix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ var rawConnectionConfig = &raw.Config{
2121

2222
// NewRawUDPConn returns a UDP connection bound to the interface and port
2323
// given based on a raw packet socket. All packets are broadcasted.
24-
//
25-
// The interface can be completely unconfigured.
2624
func NewRawUDPConn(iface string, port int, vlans ...uint16) (net.PacketConn, error) {
2725
ifc, err := net.InterfaceByName(iface)
2826
if err != nil {
@@ -68,8 +66,10 @@ func NewBroadcastUDPConn(rawPacketConn net.PacketConn, boundAddr *net.UDPAddr, v
6866

6967
// ReadFrom implements net.PacketConn.ReadFrom.
7068
//
71-
// ReadFrom reads raw IP packets and will try to match them against
72-
// upc.boundAddr. Any matching packets are returned via the given buffer.
69+
// ReadFrom reads raw Ethernet packets, parses the VLAN stack (if configured)
70+
// and will try to match the IP+UDP destinations against upc.boundAddr.
71+
//
72+
// Any matching packets are returned via the given buffer.
7373
func (upc *BroadcastRawUDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
7474
ethHdrLen := ethHdrMinimum
7575
if len(upc.VLANs) > 0 {

dhcpv4/nclient4/ethernet.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ const (
1919
vlanTPID uint16 = 0x8100
2020
)
2121

22+
var (
23+
// BroadcastMac is the broadcast MAC address.
24+
//
25+
// Any UDP packet sent to this address is broadcast on the subnet.
26+
BroadcastMac = net.HardwareAddr([]byte{255, 255, 255, 255, 255, 255})
27+
)
28+
2229
// processVLANStack receives a buffer starting at the first TPID/EtherType field, and walks through
2330
// the VLAN stack until either an unexpected VLAN is found, or if an IPv4 EtherType is found.
24-
// The data from the provided buffer is consumed until the end of the Ethernet header
31+
// The data from the provided buffer is consumed until the end of the Ethernet header.
2532
//
26-
// processVLANStack returns true if the VLAN stack in the packet corresponds to the VLAN configuration, false otherwise
33+
// processVLANStack returns true if the VLAN stack in the packet corresponds to the VLAN configuration, false otherwise.
2734
func processVLANStack(buf *uio.Lexer, vlans []uint16) bool {
2835
var currentVLAN uint16
2936
var vlanStackIsCorrect bool = true

dhcpv4/nclient4/conn.go renamed to dhcpv4/nclient4/udp.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build go1.12
2+
// +build go1.12
3+
14
package nclient4
25

36
import (
@@ -7,13 +10,6 @@ import (
710
"github.com/u-root/uio/uio"
811
)
912

10-
var (
11-
// BroadcastMac is the broadcast MAC address.
12-
//
13-
// Any UDP packet sent to this address is broadcast on the subnet.
14-
BroadcastMac = net.HardwareAddr([]byte{255, 255, 255, 255, 255, 255})
15-
)
16-
1713
var (
1814
// ErrUDPAddrIsRequired is an error used when a passed argument is not of type "*net.UDPAddr".
1915
ErrUDPAddrIsRequired = errors.New("must supply UDPAddr")

0 commit comments

Comments
 (0)