go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2101/arp_vppcalls.go (about) 1 // Copyright (c) 2019 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 vpp2101 16 17 import ( 18 "net" 19 20 "github.com/pkg/errors" 21 22 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/interface_types" 23 vpp_ip_neighbor "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/ip_neighbor" 24 l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 25 ) 26 27 // vppAddDelArp adds or removes ARP entry according to provided input 28 func (h *ArpVppHandler) vppAddDelArp(entry *l3.ARPEntry, delete bool) error { 29 meta, found := h.ifIndexes.LookupByName(entry.Interface) 30 if !found { 31 return errors.Errorf("interface %s not found", entry.Interface) 32 } 33 34 var flags vpp_ip_neighbor.IPNeighborFlags 35 flags |= vpp_ip_neighbor.IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY 36 if entry.Static { 37 flags |= vpp_ip_neighbor.IP_API_NEIGHBOR_FLAG_STATIC 38 } 39 40 req := &vpp_ip_neighbor.IPNeighborAddDel{ 41 IsAdd: !delete, 42 Neighbor: vpp_ip_neighbor.IPNeighbor{ 43 SwIfIndex: interface_types.InterfaceIndex(meta.SwIfIndex), 44 Flags: flags, 45 }, 46 } 47 48 var err error 49 req.Neighbor.IPAddress, err = ipToAddress(entry.IpAddress) 50 if err != nil { 51 return errors.WithStack(err) 52 } 53 54 macAddr, err := net.ParseMAC(entry.PhysAddress) 55 if err != nil { 56 return err 57 } 58 copy(req.Neighbor.MacAddress[:], macAddr) 59 60 reply := &vpp_ip_neighbor.IPNeighborAddDelReply{} 61 if err = h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 62 return err 63 } 64 65 return nil 66 } 67 68 // VppAddArp implements arp handler. 69 func (h *ArpVppHandler) VppAddArp(entry *l3.ARPEntry) error { 70 return h.vppAddDelArp(entry, false) 71 } 72 73 // VppDelArp implements arp handler. 74 func (h *ArpVppHandler) VppDelArp(entry *l3.ARPEntry) error { 75 return h.vppAddDelArp(entry, true) 76 }