forked from falcosecurity/driverkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilders.go
68 lines (56 loc) · 1.82 KB
/
builders.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
package builder
import (
"fmt"
"net/http"
"path"
"github.com/sirupsen/logrus"
)
// DriverDirectory is the directory the processor uses to store the driver.
const DriverDirectory = "/tmp/driver"
// ModuleFileName is the standard file name for the kernel module.
const ModuleFileName = "module.ko"
// ProbeFileName is the standard file name for the eBPF probe.
const ProbeFileName = "probe.o"
// ModuleFullPath is the standard path for the kernel module. Builders must place the compiled module at this location.
var ModuleFullPath = path.Join(DriverDirectory, ModuleFileName)
// ProbeFullPath is the standard path for the eBPF probe. Builders must place the compiled probe at this location.
var ProbeFullPath = path.Join(DriverDirectory, "bpf", ProbeFileName)
// Config contains all the configurations needed to build the kernel module or the eBPF probe.
type Config struct {
DriverName string
DeviceName string
DownloadBaseURL string
*Build
}
// Builder represents a builder capable of generating a script for a driverkit target.
type Builder interface {
Script(c Config) (string, error)
}
// Factory returns a builder for the given target.
func Factory(target Type) (Builder, error) {
b, ok := BuilderByTarget[target]
if !ok {
return nil, fmt.Errorf("no builder found for target: %s", target)
}
return b, nil
}
func moduleDownloadURL(c Config) string {
return fmt.Sprintf("%s/%s.tar.gz", c.DownloadBaseURL, c.DriverVersion)
}
func getResolvingURLs(urls []string) ([]string, error) {
results := []string{}
for _, u := range urls {
res, err := http.Head(u)
if err != nil {
continue
}
if res.StatusCode == http.StatusOK {
results = append(results, u)
logrus.WithField("url", u).Debug("kernel header url found")
}
}
if len(results) == 0 {
return nil, fmt.Errorf("kernel not found")
}
return results, nil
}