go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2101/dhcpproxy_dump.go (about) 1 // Copyright (c) 2019 PANTHEON.tech 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package vpp2101 16 17 import ( 18 "net" 19 20 vpp_dhcp "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/dhcp" 21 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/ip_types" 22 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls" 23 l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 24 ) 25 26 func (h *DHCPProxyHandler) DumpDHCPProxy() (entry []*vppcalls.DHCPProxyDetails, err error) { 27 ipv4Entries, err := h.dumpDHCPProxyForIPVersion(false) 28 if err != nil { 29 return nil, err 30 } 31 entry = append(entry, ipv4Entries...) 32 ipv6Entries, err := h.dumpDHCPProxyForIPVersion(true) 33 if err != nil { 34 return nil, err 35 } 36 37 entry = append(entry, ipv6Entries...) 38 return entry, nil 39 } 40 41 func (h *DHCPProxyHandler) dumpDHCPProxyForIPVersion(isIPv6 bool) (entry []*vppcalls.DHCPProxyDetails, err error) { 42 reqCtx := h.callsChannel.SendMultiRequest(&vpp_dhcp.DHCPProxyDump{IsIP6: isIPv6}) 43 for { 44 dhcpProxyDetails := &vpp_dhcp.DHCPProxyDetails{} 45 stop, err := reqCtx.ReceiveReply(dhcpProxyDetails) 46 if stop { 47 break 48 } 49 if err != nil { 50 h.log.Error(err) 51 return nil, err 52 } 53 proxy := &l3.DHCPProxy{ 54 RxVrfId: dhcpProxyDetails.RxVrfID, 55 SourceIpAddress: addressToString(dhcpProxyDetails.DHCPSrcAddress), 56 } 57 58 for _, server := range dhcpProxyDetails.Servers { 59 proxyServer := &l3.DHCPProxy_DHCPServer{ 60 IpAddress: addressToString(server.DHCPServer), 61 VrfId: server.ServerVrfID, 62 } 63 proxy.Servers = append(proxy.Servers, proxyServer) 64 } 65 66 entry = append(entry, &vppcalls.DHCPProxyDetails{ 67 DHCPProxy: proxy, 68 }) 69 } 70 return 71 } 72 73 func addressToString(address ip_types.Address) string { 74 if address.Af == ip_types.ADDRESS_IP6 { 75 ipAddr := address.Un.GetIP6() 76 return net.IP(ipAddr[:]).To16().String() 77 } 78 ipAddr := address.Un.GetIP4() 79 return net.IP(ipAddr[:]).To4().String() 80 }