Skip to content

Commit

Permalink
Added AlmaLinux drivekit and added RockyLinux 9
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele De Lorenzi <daniele.delorenzi@fastnetserv.net>
  • Loading branch information
dark-vex authored and poiana committed Oct 24, 2022
1 parent 78aaa91 commit 286dc4f
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 7 deletions.
76 changes: 76 additions & 0 deletions pkg/driverbuilder/builder/almalinux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package builder

import (
_ "embed"
"fmt"
"github.com/falcosecurity/driverkit/pkg/kernelrelease"
)

//go:embed templates/almalinux.sh
var almaTemplate string

// TargetTypeAlma identifies the Alma target.
const TargetTypeAlma Type = "alma"

func init() {
BuilderByTarget[TargetTypeAlma] = &alma{}
}

type almaTemplateData struct {
commonTemplateData
KernelDownloadURL string
}

// alma is a driverkit target.
type alma struct {
}

func (c *alma) Name() string {
return TargetTypeAlma.String()
}

func (c *alma) TemplateScript() string {
return almaTemplate
}

func (c *alma) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
return fetchAlmaKernelURLS(kr), nil
}

func (c *alma) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
return almaTemplateData{
commonTemplateData: cfg.toTemplateData(c, kr),
KernelDownloadURL: urls[0],
}
}

func fetchAlmaKernelURLS(kr kernelrelease.KernelRelease) []string {
almaReleases := []string{
"8",
"8.6",
"9",
"9.0",
}

urls := []string{}
for _, r := range almaReleases {
if r >= "9" {
urls = append(urls, fmt.Sprintf(
"https://repo.almalinux.org/almalinux/%s/AppStream/%s/os/Packages/kernel-devel-%s%s.rpm",
r,
kr.Architecture.ToNonDeb(),
kr.Fullversion,
kr.FullExtraversion,
))
}else{
urls = append(urls, fmt.Sprintf(
"https://repo.almalinux.org/almalinux/%s/BaseOS/%s/os/Packages/kernel-devel-%s%s.rpm",
r,
kr.Architecture.ToNonDeb(),
kr.Fullversion,
kr.FullExtraversion,
))
}
}
return urls
}
27 changes: 20 additions & 7 deletions pkg/driverbuilder/builder/rocky.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,30 @@ func fetchRockyKernelURLS(kr kernelrelease.KernelRelease) []string {
rockyReleases := []string{
"8",
"8.5",
"8.6",
"9",
"9.0",
}

urls := []string{}
for _, r := range rockyReleases {
urls = append(urls, fmt.Sprintf(
"https://download.rockylinux.org/pub/rocky/%s/BaseOS/%s/os/Packages/k/kernel-devel-%s%s.rpm",
r,
kr.Architecture.ToNonDeb(),
kr.Fullversion,
kr.FullExtraversion,
))
if r >= "9" {
urls = append(urls, fmt.Sprintf(
"https://download.rockylinux.org/pub/rocky/%s/AppStream/%s/os/Packages/k/kernel-devel-%s%s.rpm",
r,
kr.Architecture.ToNonDeb(),
kr.Fullversion,
kr.FullExtraversion,
))
}else{
urls = append(urls, fmt.Sprintf(
"https://download.rockylinux.org/pub/rocky/%s/BaseOS/%s/os/Packages/k/kernel-devel-%s%s.rpm",
r,
kr.Architecture.ToNonDeb(),
kr.Fullversion,
kr.FullExtraversion,
))
}
}
return urls
}
39 changes: 39 additions & 0 deletions pkg/driverbuilder/builder/templates/almalinux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -xeuo pipefail

rm -Rf {{ .DriverBuildDir }}
mkdir {{ .DriverBuildDir }}
rm -Rf /tmp/module-download
mkdir -p /tmp/module-download

curl --silent -SL {{ .ModuleDownloadURL }} | tar -xzf - -C /tmp/module-download
mv /tmp/module-download/*/driver/* {{ .DriverBuildDir }}

cp /driverkit/module-Makefile {{ .DriverBuildDir }}/Makefile
bash /driverkit/fill-driver-config.sh {{ .DriverBuildDir }}

# Fetch the kernel
mkdir /tmp/kernel-download
cd /tmp/kernel-download
curl --silent -o kernel-devel.rpm -SL {{ .KernelDownloadURL }}
rpm2cpio kernel-devel.rpm | cpio --extract --make-directories
rm -Rf /tmp/kernel
mkdir -p /tmp/kernel
mv usr/src/kernels/*/* /tmp/kernel

{{ if .BuildModule }}
# Build the module
cd {{ .DriverBuildDir }}
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel
mv {{ .ModuleDriverName }}.ko {{ .ModuleFullPath }}
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
{{ end }}

{{ if .BuildProbe }}
# Build the eBPF probe
cd {{ .DriverBuildDir }}/bpf
make KERNELDIR=/tmp/kernel
ls -l probe.o
{{ end }}

0 comments on commit 286dc4f

Please sign in to comment.