-
Notifications
You must be signed in to change notification settings - Fork 25
/
bgpfilter.go
120 lines (89 loc) · 4.02 KB
/
bgpfilter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2022-2023 Tigera, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v3
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
KindBGPFilter = "BGPFilter"
KindBGPFilterList = "BGPFilterList"
)
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// BGPFilterList is a list of BGPFilter resources.
type BGPFilterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []BGPFilter `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type BGPFilter struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec BGPFilterSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}
// BGPFilterSpec contains the IPv4 and IPv6 filter rules of the BGP Filter.
type BGPFilterSpec struct {
// The ordered set of IPv4 BGPFilter rules acting on exporting routes to a peer.
ExportV4 []BGPFilterRuleV4 `json:"exportV4,omitempty" validate:"omitempty,dive"`
// The ordered set of IPv4 BGPFilter rules acting on importing routes from a peer.
ImportV4 []BGPFilterRuleV4 `json:"importV4,omitempty" validate:"omitempty,dive"`
// The ordered set of IPv6 BGPFilter rules acting on exporting routes to a peer.
ExportV6 []BGPFilterRuleV6 `json:"exportV6,omitempty" validate:"omitempty,dive"`
// The ordered set of IPv6 BGPFilter rules acting on importing routes from a peer.
ImportV6 []BGPFilterRuleV6 `json:"importV6,omitempty" validate:"omitempty,dive"`
}
// BGPFilterRuleV4 defines a BGP filter rule consisting a single IPv4 CIDR block and a filter action for this CIDR.
type BGPFilterRuleV4 struct {
CIDR string `json:"cidr,omitempty" validate:"omitempty,netv4"`
Source BGPFilterMatchSource `json:"source,omitempty" validate:"omitempty,oneof=RemotePeers"`
Interface string `json:"interface,omitempty" validate:"omitempty,bgpFilterInterface"`
MatchOperator BGPFilterMatchOperator `json:"matchOperator,omitempty" validate:"omitempty,matchOperator"`
Action BGPFilterAction `json:"action" validate:"required,filterAction"`
}
// BGPFilterRuleV6 defines a BGP filter rule consisting a single IPv6 CIDR block and a filter action for this CIDR.
type BGPFilterRuleV6 struct {
CIDR string `json:"cidr,omitempty" validate:"omitempty,netv6"`
Source BGPFilterMatchSource `json:"source,omitempty" validate:"omitempty,oneof=RemotePeers"`
Interface string `json:"interface,omitempty" validate:"omitempty,bgpFilterInterface"`
MatchOperator BGPFilterMatchOperator `json:"matchOperator,omitempty" validate:"omitempty,matchOperator"`
Action BGPFilterAction `json:"action" validate:"required,filterAction"`
}
type BGPFilterMatchSource string
const (
BGPFilterSourceRemotePeers BGPFilterMatchSource = "RemotePeers"
)
type BGPFilterMatchOperator string
const (
Equal BGPFilterMatchOperator = "Equal"
NotEqual BGPFilterMatchOperator = "NotEqual"
In BGPFilterMatchOperator = "In"
NotIn BGPFilterMatchOperator = "NotIn"
)
type BGPFilterAction string
const (
Accept BGPFilterAction = "Accept"
Reject BGPFilterAction = "Reject"
)
// New BGPFilter creates a new (zeroed) BGPFilter struct with the TypeMetadata
// initialized to the current version.
func NewBGPFilter() *BGPFilter {
return &BGPFilter{
TypeMeta: metav1.TypeMeta{
Kind: KindBGPFilter,
APIVersion: GroupVersionCurrent,
},
}
}