go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/wireguardplugin/vppcalls/vpp2106/dump_vppcalls.go (about) 1 // Copyright (c) 2021 Doc.ai and/or its affiliates. 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 vpp2106 16 17 import ( 18 "encoding/base64" 19 vpp_wg "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/wireguard" 20 wg "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/wireguard" 21 ) 22 23 // DumpWgPeers implements wg handler. 24 func (h *WgVppHandler) DumpWgPeers() (peerList []*wg.Peer, err error) { 25 req := &vpp_wg.WireguardPeersDump{} 26 requestCtx := h.callsChannel.SendMultiRequest(req) 27 28 var vppPeerList []*vpp_wg.WireguardPeersDetails 29 for { 30 vppPeerDetails := &vpp_wg.WireguardPeersDetails{} 31 stop, err := requestCtx.ReceiveReply(vppPeerDetails) 32 if stop { 33 break 34 } 35 if err != nil { 36 return nil, err 37 } 38 vppPeerList = append(vppPeerList, vppPeerDetails) 39 } 40 41 for _, vppPeerDetails := range vppPeerList { 42 peerDetails := &wg.Peer{ 43 Port: uint32(vppPeerDetails.Peer.Port), 44 PersistentKeepalive: uint32(vppPeerDetails.Peer.PersistentKeepalive), 45 Flags: uint32(vppPeerDetails.Peer.Flags), 46 } 47 48 peerDetails.PublicKey = base64.StdEncoding.EncodeToString(vppPeerDetails.Peer.PublicKey) 49 50 for _, prefix := range vppPeerDetails.Peer.AllowedIps { 51 peerDetails.AllowedIps = append(peerDetails.AllowedIps, prefix.String()) 52 } 53 54 ifName, _, exists := h.ifIndexes.LookupBySwIfIndex(uint32(vppPeerDetails.Peer.SwIfIndex)) 55 if !exists { 56 h.log.Warnf("Wireguard peers dump: interface name for index %d not found", vppPeerDetails.Peer.SwIfIndex) 57 continue 58 } 59 60 peerDetails.WgIfName = ifName; 61 62 endpointAddr := vppPeerDetails.Peer.Endpoint.ToIP() 63 if !endpointAddr.IsUnspecified() { 64 peerDetails.Endpoint = endpointAddr.String() 65 } 66 67 peerList = append(peerList, peerDetails) 68 } 69 70 return 71 }