go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2106/proxyarp_vppcalls.go (about) 1 // Copyright (c) 2021 Cisco 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 "fmt" 19 "net" 20 21 "github.com/pkg/errors" 22 23 vpp_arp "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/arp" 24 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/interface_types" 25 ) 26 27 // EnableProxyArpInterface implements proxy arp handler. 28 func (h *ProxyArpVppHandler) EnableProxyArpInterface(ifName string) error { 29 return h.vppAddDelProxyArpInterface(ifName, true) 30 } 31 32 // DisableProxyArpInterface implements proxy arp handler. 33 func (h *ProxyArpVppHandler) DisableProxyArpInterface(ifName string) error { 34 return h.vppAddDelProxyArpInterface(ifName, false) 35 } 36 37 // AddProxyArpRange implements proxy arp handler. 38 func (h *ProxyArpVppHandler) AddProxyArpRange(firstIP, lastIP []byte, vrfID uint32) error { 39 return h.vppAddDelProxyArpRange(firstIP, lastIP, vrfID, true) 40 } 41 42 // DeleteProxyArpRange implements proxy arp handler. 43 func (h *ProxyArpVppHandler) DeleteProxyArpRange(firstIP, lastIP []byte, vrfID uint32) error { 44 return h.vppAddDelProxyArpRange(firstIP, lastIP, vrfID, false) 45 } 46 47 // vppAddDelProxyArpInterface adds or removes proxy ARP interface entry according to provided input 48 func (h *ProxyArpVppHandler) vppAddDelProxyArpInterface(ifName string, enable bool) error { 49 meta, found := h.ifIndexes.LookupByName(ifName) 50 if !found { 51 return errors.Errorf("interface %s not found", ifName) 52 } 53 54 req := &vpp_arp.ProxyArpIntfcEnableDisable{ 55 Enable: enable, 56 SwIfIndex: interface_types.InterfaceIndex(meta.SwIfIndex), 57 } 58 59 reply := &vpp_arp.ProxyArpIntfcEnableDisableReply{} 60 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 61 return err 62 } 63 64 h.log.Debugf("interface %v enabled for proxy arp: %v", req.SwIfIndex, enable) 65 66 return nil 67 } 68 69 // vppAddDelProxyArpRange adds or removes proxy ARP range according to provided input. 70 func (h *ProxyArpVppHandler) vppAddDelProxyArpRange(firstIP, lastIP []byte, vrfID uint32, isAdd bool) error { 71 validateIPBytes := func(b []byte) error { 72 ip := net.IP(b) 73 if ip.To4() == nil { 74 return fmt.Errorf("IP bytes %v are not valid IPv4 address", b) 75 } 76 return nil 77 } 78 if err := validateIPBytes(firstIP); err != nil { 79 return fmt.Errorf("bad first IP: %v", err) 80 } 81 if err := validateIPBytes(lastIP); err != nil { 82 return fmt.Errorf("bad last IP: %v", err) 83 } 84 85 proxy := vpp_arp.ProxyArp{ 86 TableID: vrfID, 87 } 88 copy(proxy.Low[:], firstIP) 89 copy(proxy.Hi[:], lastIP) 90 91 req := &vpp_arp.ProxyArpAddDel{ 92 IsAdd: isAdd, 93 Proxy: proxy, 94 } 95 96 reply := &vpp_arp.ProxyArpAddDelReply{} 97 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 98 return err 99 } 100 101 h.log.Debugf("proxy arp range: %v - %v (vrf: %d) added: %v", proxy.Low, proxy.Hi, proxy.TableID, isAdd) 102 103 return nil 104 }