-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
main.go
56 lines (46 loc) · 1.23 KB
/
main.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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019-2021 Authors of Cilium
package main
import (
"fmt"
"os"
"strings"
"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/maps/eppolicymap"
"github.com/cilium/cilium/pkg/maps/sockmap"
)
type mapCreationFunc func(string) error
var mapBuilders = map[string]mapCreationFunc{
"eppolicymap": eppolicymap.CreateWithName,
"sockmap": sockmap.CreateWithName,
}
func usage() {
fmt.Fprintf(os.Stderr, "usage: %s <type> <path>\n\n", os.Args[0])
fmt.Fprintf(os.Stderr, "TYPE :=")
separator := " "
for k := range mapBuilders {
fmt.Fprintf(os.Stderr, "%s%s", separator, strings.ToUpper(k))
separator = " | "
}
fmt.Fprintf(os.Stderr, "\n")
os.Exit(1)
}
func main() {
if len(os.Args) != 3 {
usage()
}
mapType := os.Args[1]
createMap, exists := mapBuilders[strings.ToLower(mapType)]
if !exists {
fmt.Fprintf(os.Stderr, "Unrecognized map type %s\n", mapType)
usage()
}
if err := bpf.ConfigureResourceLimits(); err != nil {
fmt.Fprintf(os.Stdout, "Failed to configure resource limits: %s\n", err)
}
bpf.CheckOrMountFS("")
bpfObjPath := os.Args[2]
if err := createMap(bpfObjPath); err != nil {
fmt.Fprintf(os.Stdout, "Failed to create map: %s\n", err)
}
}