mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
Use HardwareAddress (MAC) for Identifing Hardware Interfaces
This commit is contained in:
parent
d9ecfae454
commit
15de5fb5bb
4 changed files with 37 additions and 7 deletions
30
internal/definitions/hardwareaddress.go
Normal file
30
internal/definitions/hardwareaddress.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package definitions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
)
|
||||
|
||||
type HardwareAddress struct {
|
||||
net.HardwareAddr
|
||||
}
|
||||
|
||||
// MarshalJSON for IPCIDR
|
||||
func (i HardwareAddress) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(i.String())
|
||||
}
|
||||
|
||||
// UnmarshalJSON for IPCIDR
|
||||
func (i *HardwareAddress) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mac, err := net.ParseMAC(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.HardwareAddr = mac
|
||||
return nil
|
||||
}
|
|
@ -5,11 +5,11 @@ import (
|
|||
)
|
||||
|
||||
type Interface struct {
|
||||
Alias string `json:"alias,omitempty" validate:"min=0,max=3"`
|
||||
Type InterfaceType `json:"type" validate:"min=0,max=3"`
|
||||
AddressingMode InterfaceAddressingMode `json:"addressing_mode" validate:"min=0,max=2"`
|
||||
Address *IPCIDR `json:"address,omitempty" validate:"excluded_unless=AddressingMode 1"`
|
||||
HardwareInterface *string `json:"hardware_interface,omitempty"`
|
||||
Alias string `json:"alias,omitempty" validate:"min=0,max=3"`
|
||||
Type InterfaceType `json:"type" validate:"min=0,max=3"`
|
||||
AddressingMode InterfaceAddressingMode `json:"addressing_mode" validate:"min=0,max=2"`
|
||||
Address *IPCIDR `json:"address,omitempty" validate:"excluded_unless=AddressingMode 1"`
|
||||
HardwareAddress *HardwareAddress `json:"hardware_address,omitempty"`
|
||||
// TODO fix Validator for int pointers with min=0,max=4094
|
||||
VlanID *uint `json:"vlan_id,omitempty"`
|
||||
VlanParent *string `json:"vlan_parent,omitempty"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue