From ec24d18f83a032446116428cb3fc2acb390b8bd2 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 7 Aug 2020 11:47:24 +0300 Subject: [PATCH] * GET /control/dhcp/interfaces: split IPv4 and IPv6 addresses --- AGHTechDoc.md | 3 ++- dhcpd/dhcp_http.go | 11 ++++++++--- openapi/openapi.yaml | 8 +++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/AGHTechDoc.md b/AGHTechDoc.md index 809b0c72..76e1171c 100644 --- a/AGHTechDoc.md +++ b/AGHTechDoc.md @@ -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" } ... diff --git a/dhcpd/dhcp_http.go b/dhcpd/dhcp_http.go index 7ae6075a..f85c00b4 100644 --- a/dhcpd/dhcp_http.go +++ b/dhcpd/dhcp_http.go @@ -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 } diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 7b29f96c..ef288f04 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -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