mdlayher / raw

Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.
MIT License
425 stars 71 forks source link

Allow non-Ethernet HW addresses #57

Closed bluecmd closed 5 years ago

bluecmd commented 5 years ago

Hi,

I'm planning on using your library to send/receive Fibre Channel frames using my own netdev. It is using ARPHRD_FCFABRIC as type, and 3 byte hardware addresses as per FC-FS-5.

In my local copy I hacked in the following on the write path to test the function:

diff --git a/raw_linux.go b/raw_linux.go
index 05d515b..622c6cd 100644
--- a/raw_linux.go
+++ b/raw_linux.go
@@ -163,7 +163,7 @@ func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
 func (p *packetConn) WriteTo(b []byte, addr net.Addr) (int, error) {
        // Ensure correct Addr type.
        a, ok := addr.(*Addr)
-       if !ok || a.HardwareAddr == nil || len(a.HardwareAddr) < 6 {
+       if !ok || a.HardwareAddr == nil || len(a.HardwareAddr) < 3 {
                return 0, unix.EINVAL
        }

but clearly this is not a proper fix. I propose the check to be dropped or changed to read the length from the device.

For completeness sake, this is the output of ip link on the interface:

3: fc0: <NOARP,UP,LOWER_UP> mtu 2148 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/fcfb0 00:00:00 brd ff:ff:ff