* GET /control/dhcp/interfaces: split IPv4 and IPv6 addresses

This commit is contained in:
Simon Zolin 2020-08-07 11:47:24 +03:00
parent 89c3926ba5
commit ec24d18f83
3 changed files with 15 additions and 7 deletions

View File

@ -444,7 +444,8 @@ Response:
"name":"iface_name",
"mtu":1500,
"hardware_address":"...",
"ip_addresses":["ipv4 addr","ipv6 addr", ...],
"ipv4_addresses":["ipv4 addr", ...],
"ipv6_addresses":["ipv6 addr", ...],
"flags":"up|broadcast|multicast"
}
...

View File

@ -202,7 +202,8 @@ type netInterfaceJSON struct {
Name string `json:"name"`
MTU int `json:"mtu"`
HardwareAddr string `json:"hardware_address"`
Addresses []string `json:"ip_addresses"`
Addrs4 []string `json:"ipv4_addresses"`
Addrs6 []string `json:"ipv6_addresses"`
Flags string `json:"flags"`
}
@ -251,9 +252,13 @@ func (s *Server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) {
if ipnet.IP.IsLinkLocalUnicast() {
continue
}
jsonIface.Addresses = append(jsonIface.Addresses, ipnet.IP.String())
if ipnet.IP.To4() != nil {
jsonIface.Addrs4 = append(jsonIface.Addrs4, ipnet.IP.String())
} else {
jsonIface.Addrs6 = append(jsonIface.Addrs6, ipnet.IP.String())
}
}
if len(jsonIface.Addresses) != 0 {
if len(jsonIface.Addrs4)+len(jsonIface.Addrs6) != 0 {
response[iface.Name] = jsonIface
}

View File

@ -1626,12 +1626,14 @@ components:
name:
type: string
example: eth0
ip_addresses:
ipv4_addresses:
type: array
items:
type: string
ipv6_addresses:
type: array
items:
type: string
example:
- 127.0.0.1
AddressInfo:
type: object
description: Port information