Skip to content

Commit 3191f87

Browse files
committed
Further comment fixes, better variable/function naming
Signed-off-by: vista <[email protected]>
1 parent 2b6b08d commit 3191f87

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

dhcpv4/nclient4/conn_unix.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ 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.
2426
func NewRawUDPConn(iface string, port int, vlans ...uint16) (net.PacketConn, error) {
2527
ifc, err := net.InterfaceByName(iface)
2628
if err != nil {
@@ -34,6 +36,7 @@ func NewRawUDPConn(iface string, port int, vlans ...uint16) (net.PacketConn, err
3436
etherType = etherIPv4Proto
3537
}
3638

39+
// Create a bidirectional raw socket on ifc with etherType as the filter
3740
rawConn, err := raw.ListenPacket(ifc, etherType, rawConnectionConfig)
3841
if err != nil {
3942
return nil, err
@@ -66,12 +69,12 @@ func NewBroadcastUDPConn(rawPacketConn net.PacketConn, boundAddr *net.UDPAddr, v
6669

6770
// ReadFrom implements net.PacketConn.ReadFrom.
6871
//
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.
72+
// ReadFrom reads raw Ethernet frames, parses and matches the VLAN stack (if configured),
73+
// and will try to match the remaining IP packet against upc.boundAddr.
7174
//
7275
// Any matching packets are returned via the given buffer.
7376
func (upc *BroadcastRawUDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
74-
ethHdrLen := ethHdrMinimum
77+
ethHdrLen := ethHdrBaseLen
7578
if len(upc.VLANs) > 0 {
7679
ethHdrLen += len(upc.VLANs) * vlanTagLen
7780
}

dhcpv4/nclient4/ethernet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
const (
1414
etherIPv4Proto uint16 = 0x0800
15-
ethHdrMinimum int = 14
15+
ethHdrBaseLen int = 14
1616

1717
vlanTagLen int = 4
1818
vlanMax uint16 = 0x0FFF
@@ -118,7 +118,7 @@ func createVLANTag(vlan uint16) []byte {
118118
// addEthernetHdr returns the supplied packet (in bytes) with an
119119
// added Ethernet header with the specified EtherType.
120120
func addEthernetHdr(b []byte, dstMac, srcMac net.HardwareAddr, etherProto uint16, vlans []uint16) []byte {
121-
ethHdrLen := ethHdrMinimum
121+
ethHdrLen := ethHdrBaseLen
122122
if len(vlans) > 0 {
123123
ethHdrLen += len(vlans) * vlanTagLen
124124
}

dhcpv4/nclient4/ethernet_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestProcessVLANStack(t *testing.T) {
8282
}
8383

8484
func TestCreateVLANTag(t *testing.T) {
85-
// Gopacket builds VLAN tags the other way around: first VLAN ID/TCI, then TPID, due to their different layered approach
85+
// gopacket builds VLAN tags the other way around: first VLAN ID/TCI, then TPID, due to their different layered approach
8686
// Since a VLAN tag is only 4 bytes, and the value is well-known, it makes sense to just construct the packet by hand.
8787
want := []byte{0x81, 0x00, 0x01, 0x23}
8888

@@ -135,7 +135,7 @@ func TestGetEthernetPayload(t *testing.T) {
135135
}
136136
}
137137

138-
func TestAddEthernetHdrTwo(t *testing.T) {
138+
func TestAddEthernetHdr(t *testing.T) {
139139
for _, tt := range []struct {
140140
name string
141141
testLayers []gopacket.SerializableLayer

0 commit comments

Comments
 (0)