github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/pkg/apis/projectcalico/v3/bgpfilter.go (about)

     1  // Copyright (c) 2022-2023 Tigera, Inc. All rights reserved.
     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 v3
    16  
    17  import (
    18  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  )
    20  
    21  const (
    22  	KindBGPFilter     = "BGPFilter"
    23  	KindBGPFilterList = "BGPFilterList"
    24  )
    25  
    26  // +genclient:nonNamespaced
    27  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    28  
    29  // BGPFilterList is a list of BGPFilter resources.
    30  type BGPFilterList struct {
    31  	metav1.TypeMeta `json:",inline"`
    32  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    33  
    34  	Items []BGPFilter `json:"items" protobuf:"bytes,2,rep,name=items"`
    35  }
    36  
    37  // +genclient
    38  // +genclient:nonNamespaced
    39  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    40  
    41  type BGPFilter struct {
    42  	metav1.TypeMeta   `json:",inline"`
    43  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    44  
    45  	Spec BGPFilterSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    46  }
    47  
    48  // BGPFilterSpec contains the IPv4 and IPv6 filter rules of the BGP Filter.
    49  type BGPFilterSpec struct {
    50  	// The ordered set of IPv4 BGPFilter rules acting on exporting routes to a peer.
    51  	ExportV4 []BGPFilterRuleV4 `json:"exportV4,omitempty" validate:"omitempty,dive"`
    52  
    53  	// The ordered set of IPv4 BGPFilter rules acting on importing routes from a peer.
    54  	ImportV4 []BGPFilterRuleV4 `json:"importV4,omitempty" validate:"omitempty,dive"`
    55  
    56  	// The ordered set of IPv6 BGPFilter rules acting on exporting routes to a peer.
    57  	ExportV6 []BGPFilterRuleV6 `json:"exportV6,omitempty" validate:"omitempty,dive"`
    58  
    59  	// The ordered set of IPv6 BGPFilter rules acting on importing routes from a peer.
    60  	ImportV6 []BGPFilterRuleV6 `json:"importV6,omitempty" validate:"omitempty,dive"`
    61  }
    62  
    63  // BGPFilterRuleV4 defines a BGP filter rule consisting a single IPv4 CIDR block and a filter action for this CIDR.
    64  type BGPFilterRuleV4 struct {
    65  	CIDR string `json:"cidr,omitempty" validate:"omitempty,netv4"`
    66  
    67  	Source BGPFilterMatchSource `json:"source,omitempty" validate:"omitempty,oneof=RemotePeers"`
    68  
    69  	Interface string `json:"interface,omitempty" validate:"omitempty,bgpFilterInterface"`
    70  
    71  	MatchOperator BGPFilterMatchOperator `json:"matchOperator,omitempty" validate:"omitempty,matchOperator"`
    72  
    73  	Action BGPFilterAction `json:"action" validate:"required,filterAction"`
    74  }
    75  
    76  // BGPFilterRuleV6 defines a BGP filter rule consisting a single IPv6 CIDR block and a filter action for this CIDR.
    77  type BGPFilterRuleV6 struct {
    78  	CIDR string `json:"cidr,omitempty" validate:"omitempty,netv6"`
    79  
    80  	Source BGPFilterMatchSource `json:"source,omitempty" validate:"omitempty,oneof=RemotePeers"`
    81  
    82  	Interface string `json:"interface,omitempty" validate:"omitempty,bgpFilterInterface"`
    83  
    84  	MatchOperator BGPFilterMatchOperator `json:"matchOperator,omitempty" validate:"omitempty,matchOperator"`
    85  
    86  	Action BGPFilterAction `json:"action" validate:"required,filterAction"`
    87  }
    88  
    89  type BGPFilterMatchSource string
    90  
    91  const (
    92  	BGPFilterSourceRemotePeers BGPFilterMatchSource = "RemotePeers"
    93  )
    94  
    95  type BGPFilterMatchOperator string
    96  
    97  const (
    98  	Equal    BGPFilterMatchOperator = "Equal"
    99  	NotEqual BGPFilterMatchOperator = "NotEqual"
   100  	In       BGPFilterMatchOperator = "In"
   101  	NotIn    BGPFilterMatchOperator = "NotIn"
   102  )
   103  
   104  type BGPFilterAction string
   105  
   106  const (
   107  	Accept BGPFilterAction = "Accept"
   108  	Reject BGPFilterAction = "Reject"
   109  )
   110  
   111  // New BGPFilter creates a new (zeroed) BGPFilter struct with the TypeMetadata
   112  // initialized to the current version.
   113  func NewBGPFilter() *BGPFilter {
   114  	return &BGPFilter{
   115  		TypeMeta: metav1.TypeMeta{
   116  			Kind:       KindBGPFilter,
   117  			APIVersion: GroupVersionCurrent,
   118  		},
   119  	}
   120  }