istio

Форк
0
/
ipset.go 
72 строки · 2.0 Кб
1
// Copyright Istio Authors
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 ipset
16

17
import (
18
	"net/netip"
19
)
20

21
type IPSet struct {
22
	Name string
23
	Deps NetlinkIpsetDeps
24
}
25

26
type NetlinkIpsetDeps interface {
27
	ipsetIPPortCreate(name string) error
28
	destroySet(name string) error
29
	addIP(name string, ip netip.Addr, ipProto uint8, comment string, replace bool) error
30
	deleteIP(name string, ip netip.Addr, ipProto uint8) error
31
	flush(name string) error
32
	clearEntriesWithComment(name, comment string) error
33
	clearEntriesWithIP(name string, ip netip.Addr) error
34
	listEntriesByIP(name string) ([]netip.Addr, error)
35
}
36

37
func NewIPSet(name string, deps NetlinkIpsetDeps) (IPSet, error) {
38
	set := IPSet{
39
		Name: name,
40
		Deps: deps,
41
	}
42
	err := deps.ipsetIPPortCreate(name)
43
	return set, err
44
}
45

46
func (m *IPSet) DestroySet() error {
47
	return m.Deps.destroySet(m.Name)
48
}
49

50
func (m *IPSet) AddIP(ip netip.Addr, ipProto uint8, comment string, replace bool) error {
51
	return m.Deps.addIP(m.Name, ip, ipProto, comment, replace)
52
}
53

54
func (m *IPSet) DeleteIP(ip netip.Addr, ipProto uint8) error {
55
	return m.Deps.deleteIP(m.Name, ip, ipProto)
56
}
57

58
func (m *IPSet) Flush() error {
59
	return m.Deps.flush(m.Name)
60
}
61

62
func (m *IPSet) ClearEntriesWithComment(comment string) error {
63
	return m.Deps.clearEntriesWithComment(m.Name, comment)
64
}
65

66
func (m *IPSet) ClearEntriesWithIP(ip netip.Addr) error {
67
	return m.Deps.clearEntriesWithIP(m.Name, ip)
68
}
69

70
func (m *IPSet) ListEntriesByIP() ([]netip.Addr, error) {
71
	return m.Deps.listEntriesByIP(m.Name)
72
}
73

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.