go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/aclplugin/vppcalls/acl_vppcalls_api.go (about)

     1  //  Copyright (c) 2018 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 vppcalls
    16  
    17  import (
    18  	govppapi "go.fd.io/govpp/api"
    19  
    20  	"go.ligato.io/vpp-agent/v3/plugins/vpp"
    21  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx"
    22  	acl "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/acl"
    23  )
    24  
    25  // Protocol types that can occur in ACLs
    26  const (
    27  	ICMPv4Proto = 1
    28  	TCPProto    = 6
    29  	UDPProto    = 17
    30  	ICMPv6Proto = 58
    31  )
    32  
    33  // ACLDetails is combination of proto-modelled ACL data and VPP provided metadata
    34  type ACLDetails struct {
    35  	ACL  *acl.ACL `json:"acl"`
    36  	Meta *ACLMeta `json:"acl_meta"`
    37  }
    38  
    39  // ACLMeta holds VPP-specific metadata
    40  type ACLMeta struct {
    41  	Index uint32 `json:"acl_index"`
    42  	Tag   string `json:"acl_tag"`
    43  }
    44  
    45  // ACLToInterface is definition of interface and all ACLs which are bound to
    46  // the interface either as ingress or egress
    47  type ACLToInterface struct {
    48  	SwIfIdx    uint32
    49  	IngressACL []uint32
    50  	EgressACL  []uint32
    51  }
    52  
    53  // ACLVppAPI provides read/write methods required to handle VPP access lists
    54  type ACLVppAPI interface {
    55  	ACLVppRead
    56  
    57  	// AddACL create new ACL (L3/L4). Returns ACL index provided by VPP.
    58  	AddACL(rules []*acl.ACL_Rule, aclName string) (aclIdx uint32, err error)
    59  	// AddMACIPACL creates new MACIP ACL (L2). Returns ACL index provided by VPP.
    60  	AddMACIPACL(rules []*acl.ACL_Rule, aclName string) (aclIdx uint32, err error)
    61  	// ModifyACL modifies ACL (L3/L4) by updating its rules. It uses ACL index to identify ACL.
    62  	ModifyACL(aclIdx uint32, rules []*acl.ACL_Rule, aclName string) error
    63  	// ModifyMACIPACL modifies MACIP ACL (L2) by updating its rules. It uses ACL index to identify ACL.
    64  	ModifyMACIPACL(aclIdx uint32, rules []*acl.ACL_Rule, aclName string) error
    65  	// DeleteACL removes ACL (L3/L4).
    66  	DeleteACL(aclIdx uint32) error
    67  	// DeleteMACIPACL removes MACIP ACL (L2).
    68  	DeleteMACIPACL(aclIdx uint32) error
    69  	// SetACLToInterfacesAsIngress sets ACL to interfaces as ingress.
    70  	SetACLToInterfacesAsIngress(ACLIndex uint32, ifIndices []uint32) error
    71  	// RemoveACLFromInterfacesAsIngress removes ACL from interfaces as ingress.
    72  	RemoveACLFromInterfacesAsIngress(ACLIndex uint32, ifIndices []uint32) error
    73  	// SetACLToInterfacesAsEgress sets ACL to interfaces as egress.
    74  	SetACLToInterfacesAsEgress(ACLIndex uint32, ifIndices []uint32) error
    75  	// RemoveACLFromInterfacesAsEgress removes ACL from interfaces as egress.
    76  	RemoveACLFromInterfacesAsEgress(ACLIndex uint32, ifIndices []uint32) error
    77  	// SetMACIPACLToInterfaces sets MACIP ACL to interfaces.
    78  	SetMACIPACLToInterfaces(aclIndex uint32, ifIndices []uint32) error
    79  	// RemoveMACIPACLFromInterfaces removes MACIP ACL from interfaces.
    80  	RemoveMACIPACLFromInterfaces(removedACLIndex uint32, ifIndices []uint32) error
    81  	// AddACLToInterfaceAsIngress adds ACL (L3/L4) to single interface as ingress.
    82  	AddACLToInterfaceAsIngress(aclIndex uint32, ifName string) error
    83  	// AddACLToInterfaceAsEgress adds ACL (L3/L4) to single interface as egress.
    84  	AddACLToInterfaceAsEgress(aclIndex uint32, ifName string) error
    85  	// DeleteACLFromInterfaceAsIngress deletes ACL (L3/L4) from single interface as ingress.
    86  	DeleteACLFromInterfaceAsIngress(aclIndex uint32, ifName string) error
    87  	// DeleteACLFromInterfaceAsEgress deletes ACL (L3/L4) from single interface as egress.
    88  	DeleteACLFromInterfaceAsEgress(aclIndex uint32, ifName string) error
    89  	// AddMACIPACLToInterface adds MACIP ACL (L2) to single interface.
    90  	AddMACIPACLToInterface(aclIndex uint32, ifName string) error
    91  	// DeleteMACIPACLFromInterface deletes MACIP ACL (L2) from single interface.
    92  	DeleteMACIPACLFromInterface(aclIndex uint32, ifName string) error
    93  }
    94  
    95  // ACLVppRead provides read methods for ACL plugin
    96  type ACLVppRead interface {
    97  	// DumpACL dumps all ACLs (L3/L4).
    98  	DumpACL() ([]*ACLDetails, error)
    99  	// DumpMACIPACL dumps all MACIP ACLs (L2).
   100  	DumpMACIPACL() ([]*ACLDetails, error)
   101  	// DumpACLInterfaces dumps all ACLs (L3/L4) for given ACL indexes. Returns map of ACL indexes with assigned interfaces.
   102  	DumpACLInterfaces(indices []uint32) (map[uint32]*acl.ACL_Interfaces, error)
   103  	// DumpMACIPACLInterfaces dumps all ACLs (L2) for given ACL indexes. Returns map of MACIP ACL indexes with assigned interfaces.
   104  	DumpMACIPACLInterfaces(indices []uint32) (map[uint32]*acl.ACL_Interfaces, error)
   105  	// DumpInterfaceACLs finds interface in VPP and returns its ACL (L3/L4) configuration.
   106  	DumpInterfaceACLs(ifIdx uint32) ([]*acl.ACL, error)
   107  	// DumpInterfaceMACIPACLs finds interface in VPP and returns its MACIP ACL (L2) configuration.
   108  	DumpInterfaceMACIPACLs(ifIdx uint32) ([]*acl.ACL, error)
   109  }
   110  
   111  var Handler = vpp.RegisterHandler(vpp.HandlerDesc{
   112  	Name:       "acl",
   113  	HandlerAPI: (*ACLVppAPI)(nil),
   114  })
   115  
   116  type NewHandlerFunc func(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex) ACLVppAPI
   117  
   118  func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) {
   119  	Handler.AddVersion(vpp.HandlerVersion{
   120  		Version: version,
   121  		Check: func(c vpp.Client) error {
   122  			return c.CheckCompatiblity(msgs...)
   123  		},
   124  		NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI {
   125  			return h(c, a[0].(ifaceidx.IfaceMetadataIndex))
   126  		},
   127  	})
   128  }
   129  
   130  func CompatibleACLHandler(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex) ACLVppAPI {
   131  	if v := Handler.FindCompatibleVersion(c); v != nil {
   132  		return v.NewHandler(c, ifIdx).(ACLVppAPI)
   133  	}
   134  	return nil
   135  }