From 7b144f3f50e4bc68afcedbe3dc4955b50942483a Mon Sep 17 00:00:00 2001 From: Ori Shavit Date: Wed, 11 Sep 2024 17:15:22 +0200 Subject: [PATCH] add multi-arch machine to Makefile --- Makefile | 10 +++--- src/ebpf/include/filters/pci.c | 62 ---------------------------------- src/ebpf/include/filters/pci.h | 5 --- 3 files changed, 5 insertions(+), 72 deletions(-) delete mode 100644 src/ebpf/include/filters/pci.c delete mode 100644 src/ebpf/include/filters/pci.h diff --git a/Makefile b/Makefile index a24fe4dd..61e72b7d 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ OTRZ_AGENT_IMAGE_FULL_NAME = $(OTRZ_IMAGE_REGISTRY)/$(OTRZ_AGENT_IMAGE_NAME):$(O OTRZ_MAPPER_IMAGE_FULL_NAME = $(OTRZ_IMAGE_REGISTRY)/$(OTRZ_MAPPER_IMAGE_NAME):$(OTRZ_IMAGE_TAG) LIMA_K8S_TEMPLATE = ./dev/lima-k8s.yaml -LIMA_CLUSTER_NAME = k8s +LIMA_CLUSTER_NAME = k8s-$(DOCKER_TARGET_ARCH) LIMA_KUBECONFIG_PATH = $(HOME)/.kube/lima LIMA_TEMP_DIR = /tmp/lima/ DOCKER_TARGET_ARCH = arm64 @@ -46,11 +46,11 @@ lima-install: ## Installs lima if not already installed lima-k8s: ## Starts Lima with k8s template @echo "${PROMPT_COLOR}Starting Lima with the template '$(LIMA_K8S_TEMPLATE)'...${PROMPT_NC}" - limactl start $(LIMA_K8S_TEMPLATE) --arch $(LIMA_TARGET_ARCH) --name k8s + limactl start $(LIMA_K8S_TEMPLATE) --arch $(LIMA_TARGET_ARCH) --name $(LIMA_CLUSTER_NAME) lima-kubeconfig: ## Copies kubeconfig from lima to host @echo "${PROMPT_COLOR}Copying kubeconfig from Lima to host...${PROMPT_NC}" - cp $(shell limactl list k8s --format '{{.Dir}}/copied-from-guest/kubeconfig.yaml') $(LIMA_KUBECONFIG_PATH) + cp $(shell limactl list $(LIMA_CLUSTER_NAME) --format '{{.Dir}}/copied-from-guest/kubeconfig.yaml') $(LIMA_KUBECONFIG_PATH) @echo "${PROMPT_COLOR}Run 'export KUBECONFIG=$(LIMA_KUBECONFIG_PATH)' to use the kubeconfig.${PROMPT_NC}" lima-copy-images: ## Copies the images to lima @@ -60,8 +60,8 @@ lima-copy-images: ## Copies the images to lima docker save -o $(LIMA_TEMP_DIR)images/$(OTRZ_AGENT_IMAGE_NAME).tar $(OTRZ_AGENT_IMAGE_FULL_NAME) docker save -o $(LIMA_TEMP_DIR)images/$(OTRZ_MAPPER_IMAGE_NAME).tar $(OTRZ_MAPPER_IMAGE_FULL_NAME) - limactl copy $(LIMA_TEMP_DIR)images/$(OTRZ_AGENT_IMAGE_NAME).tar k8s:/tmp/$(OTRZ_AGENT_IMAGE_NAME).tar - limactl copy $(LIMA_TEMP_DIR)images/$(OTRZ_MAPPER_IMAGE_NAME).tar k8s:/tmp/$(OTRZ_MAPPER_IMAGE_NAME).tar + limactl copy $(LIMA_TEMP_DIR)images/$(OTRZ_AGENT_IMAGE_NAME).tar $(LIMA_CLUSTER_NAME):/tmp/$(OTRZ_AGENT_IMAGE_NAME).tar + limactl copy $(LIMA_TEMP_DIR)images/$(OTRZ_MAPPER_IMAGE_NAME).tar $(LIMA_CLUSTER_NAME):/tmp/$(OTRZ_MAPPER_IMAGE_NAME).tar LIMA_INSTANCE=$(LIMA_CLUSTER_NAME) lima sudo ctr -n=k8s.io images import /tmp/$(OTRZ_AGENT_IMAGE_NAME).tar LIMA_INSTANCE=$(LIMA_CLUSTER_NAME) lima sudo ctr -n=k8s.io images import /tmp/$(OTRZ_MAPPER_IMAGE_NAME).tar diff --git a/src/ebpf/include/filters/pci.c b/src/ebpf/include/filters/pci.c deleted file mode 100644 index af043bd4..00000000 --- a/src/ebpf/include/filters/pci.c +++ /dev/null @@ -1,62 +0,0 @@ - -#include "pci.h" - -// Check if the character is a digit -static __inline bool is_digit(char c) { - return c >= '0' && c <= '9'; -} - -// Luhn check to validate a card number -// Ref: https://en.wikipedia.org/wiki/Luhn_algorithm -bool luhn_check(const char *card_number, int len) { - __u32 sum = 0; - bool even = true; // Start with alternating since the check digit is not doubled - - // Process all digits except the last one (check digit) - for (int i = len - 2; i >= 0; i--) { - __u32 digit = card_number[i] - '0'; // Convert character to integer - if (digit < 0 || digit > 9) return false; // value may only contain digits - if (even) digit *= 2; // double the value - if (digit > 9) digit -= 9; - - even = !even; - sum += digit; - } - - // Add the check digit (last digit) to the sum - __u32 checksum = card_number[len - 1] - '0'; - sum += checksum; - - // If the total modulo 10 is 0, the number is valid - return (sum % 10 == 0); -} - -// Helper function to check for card-like sequences -bool detect_card_number(const char *data, int data_len) { - int digit_count = 0; - char card_number[MAX_CARD_LEN]; // Store potential card number sequence - - for (int i = 0; i < data_len; i++) { - if (is_digit(data[i])) { - card_number[digit_count] = data[i]; // Store digit - digit_count++; - - // Reset count if we exceed the maximum card number length - if (digit_count > MAX_CARD_LEN) digit_count = 0; - } else { - // Check if we have a valid card number length and validate with Luhn check - if (digit_count >= MIN_CARD_LEN && digit_count <= MAX_CARD_LEN) { - if (luhn_check(card_number, digit_count)) return true; - } - - digit_count = 0; // Reset count if non-digit found - } - } - - // Check again at the end in case the card number is at the end of the string - if (digit_count >= MIN_CARD_LEN && digit_count <= MAX_CARD_LEN) { - return luhn_check(card_number, digit_count); - } - - return false; // No valid card number detected -} diff --git a/src/ebpf/include/filters/pci.h b/src/ebpf/include/filters/pci.h deleted file mode 100644 index afc00322..00000000 --- a/src/ebpf/include/filters/pci.h +++ /dev/null @@ -1,5 +0,0 @@ - -#define MIN_CARD_LEN 13 -#define MAX_CARD_LEN 19 - -bool detect_card_number(const char *data, int data_len);